Commit fd73dd63 authored by liuyu's avatar liuyu

add gnb_context from json and test ok

parent 7d22ef45
This diff is collapsed.
This diff is collapsed.
...@@ -54,7 +54,7 @@ class amf_n2 : public ngap::ngap_app{ ...@@ -54,7 +54,7 @@ class amf_n2 : public ngap::ngap_app{
bool verifyPlmn(std::vector<SupportedItem_t> list); bool verifyPlmn(std::vector<SupportedItem_t> list);
std::vector<SupportedItem_t> get_common_plmn(std::vector<SupportedItem_t> list); std::vector<SupportedItem_t> get_common_plmn(std::vector<SupportedItem_t> list);
void curl_http_client_udsf(std::string remoteUri,std::string jsonData,std::string http_mothed,nlohmann::json &udsf_response) ; bool curl_http_client_udsf(std::string remoteUri,std::string jsonData,std::string http_mothed,nlohmann::json &udsf_response) ;
private: private:
std::map<uint32_t, std::shared_ptr<ue_ngap_context>> ranid2uecontext;// ran ue ngap id std::map<uint32_t, std::shared_ptr<ue_ngap_context>> ranid2uecontext;// ran ue ngap id
......
...@@ -35,6 +35,7 @@ include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka) ...@@ -35,6 +35,7 @@ include_directories(${SRC_TOP_DIR}/secu_algorithms/5gaka)
include_directories(${SRC_TOP_DIR}/secu_algorithms/nas_enc_int) include_directories(${SRC_TOP_DIR}/secu_algorithms/nas_enc_int)
include_directories(${SRC_TOP_DIR}/utils) include_directories(${SRC_TOP_DIR}/utils)
include_directories(${SRC_TOP_DIR}/utils/bstr) include_directories(${SRC_TOP_DIR}/utils/bstr)
include_directories(${SRC_TOP_DIR}/sbi/amf_server/model)
add_library (CONTEXTS STATIC add_library (CONTEXTS STATIC
${CMAKE_CURRENT_SOURCE_DIR}/gNB_context.cpp ${CMAKE_CURRENT_SOURCE_DIR}/gNB_context.cpp
......
...@@ -27,4 +27,154 @@ ...@@ -27,4 +27,154 @@
*/ */
#include "gNB_context.hpp" #include "gNB_context.hpp"
#include <nlohmann/json.hpp>
#include "logger.hpp"
#include "Record.h"
using namespace std;
using namespace oai::amf::model;
bool get_value_string(const nlohmann::json &j, const string & nm, string &value){
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == nm)
{
//if((it_block->at("Content-Type") == "varhcar")
value = it_block->at("content");
return true;
}
block_set.erase(it_block++);
}
return false;
}
// bool get_value_int(const nlohmann::json &j, const string & nm, long &value){
// Record record;
// nlohmann::json::parse(j.dump()).get_to(record);
// std::set<nlohmann::json> block_set = record.getBlocks();
// std::set<nlohmann::json>::iterator it_block;
// for(it_block=block_set.begin();it_block!=block_set.end();)
// {
// if(it_block->at("Content-ID") == nm)
// {
// string s = it_block->at("content");
// value = atoi(s.c_str());
// return true;
// }
// block_set.erase(it_block++);
// }
// return false;
// }
long gnb_context::gnb_context_globalRanNodeId_from_json(nlohmann::json j)
{
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == "globalRanNodeId")
{
string s = it_block->at("content");
return atoi(s.c_str());
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value from json is error");
// long a;
// if(!get_value_int(j,"globalRanNodeId",a))
// Logger::amf_server().error("get_value from json is error");
// return a;
}
std::string gnb_context::gnb_context_gnb_name_from_json(nlohmann::json j)
{
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == "gnb_name")
{
string s = it_block->at("content");
return s;
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value from json is error");
}
int gnb_context::gnb_context_ng_state_from_json(nlohmann::json j)
{
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == "ng_state")
{
string s = it_block->at("content");
return atoi(s.c_str());
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value from json is error");
}
sctp_stream_id_t gnb_context::gnb_context_next_sctp_stream_from_json(nlohmann::json j)
{
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == "next_sctp_stream")
{
string s = it_block->at("content");
return atoi(s.c_str());
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value from json is error");
}
sctp_stream_id_t gnb_context::gnb_context_instreams_from_json(nlohmann::json j)
{
Record record;
nlohmann::json::parse(j.dump()).get_to(record);
std::set<nlohmann::json> block_set = record.getBlocks();
std::set<nlohmann::json>::iterator it_block;
for(it_block=block_set.begin();it_block!=block_set.end();)
{
if(it_block->at("Content-ID") == "instreams")
{
string s = it_block->at("content");
return atoi(s.c_str());
}
block_set.erase(it_block++);
}
Logger::amf_server().error("get_value from json is error");
}
bool gnb_context::gnb_context_from_json(nlohmann::json j)
{
//std::shared_ptr<gnb_context> gc1;
globalRanNodeId = gnb_context_globalRanNodeId_from_json(j);
gnb_name = gnb_context_gnb_name_from_json(j);
ng_state = amf_ng_gnb_state_s(gnb_context_ng_state_from_json(j));
next_sctp_stream = gnb_context_next_sctp_stream_from_json(j);
next_sctp_stream = gnb_context_instreams_from_json(j);
// printf("gnbname-%s\n",gnb_name.c_str());
// printf("globalgnbid-%d\n",globalRanNodeId);
// printf("next stream-%d\n",next_sctp_stream);
return true;
}
\ No newline at end of file
...@@ -32,7 +32,7 @@ ...@@ -32,7 +32,7 @@
#include <stdint.h> #include <stdint.h>
#include <string> #include <string>
#include <vector> #include <vector>
#include <nlohmann/json.hpp>
#include "sctp_server.hpp" #include "sctp_server.hpp"
#include "NgapIEsStruct.hpp" #include "NgapIEsStruct.hpp"
...@@ -43,6 +43,7 @@ extern "C" { ...@@ -43,6 +43,7 @@ extern "C" {
using namespace sctp; using namespace sctp;
using namespace ngap; using namespace ngap;
using namespace std;
enum amf_ng_gnb_state_s { enum amf_ng_gnb_state_s {
NGAP_INIT, NGAP_INIT,
...@@ -52,6 +53,12 @@ enum amf_ng_gnb_state_s { ...@@ -52,6 +53,12 @@ enum amf_ng_gnb_state_s {
}; };
class gnb_context { class gnb_context {
public: public:
long gnb_context_globalRanNodeId_from_json(nlohmann::json j);
std::string gnb_context_gnb_name_from_json(nlohmann::json j);
int gnb_context_ng_state_from_json(nlohmann::json j);
sctp_stream_id_t gnb_context_next_sctp_stream_from_json(nlohmann::json j);
sctp_stream_id_t gnb_context_instreams_from_json(nlohmann::json j);
bool gnb_context_from_json(nlohmann::json j);
enum amf_ng_gnb_state_s ng_state; enum amf_ng_gnb_state_s ng_state;
std::string gnb_name; std::string gnb_name;
......
...@@ -426,6 +426,7 @@ void sctp_server::curl_http_client_Plugin(sctp_assoc_id_t assoc_id, sctp_stream_ ...@@ -426,6 +426,7 @@ void sctp_server::curl_http_client_Plugin(sctp_assoc_id_t assoc_id, sctp_stream_
// std::string(CURL_MIME_BOUNDARY); // std::string(CURL_MIME_BOUNDARY);
// headers = curl_slist_append(headers, content_type.c_str()); // headers = curl_slist_append(headers, content_type.c_str());
headers = curl_slist_append(headers, "content-type: application/json"); headers = curl_slist_append(headers, "content-type: application/json");
headers = curl_slist_append(headers, "Expect:");
curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers); curl_easy_setopt(curl, CURLOPT_HTTPHEADER, headers);
curl_easy_setopt(curl, CURLOPT_URL, url.c_str()); curl_easy_setopt(curl, CURLOPT_URL, url.c_str());
curl_easy_setopt(curl, CURLOPT_HTTPGET, 1); curl_easy_setopt(curl, CURLOPT_HTTPGET, 1);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment