Commit b7a1e824 authored by 陈纪航's avatar 陈纪航

111

parent 707543e2
{
"files.associations": {
"*.ipp": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"memory": "cpp",
"future": "cpp",
"istream": "cpp",
"functional": "cpp",
"tuple": "cpp",
"utility": "cpp",
"cctype": "cpp",
"clocale": "cpp",
"cmath": "cpp",
"csignal": "cpp",
"cstdarg": "cpp",
"cstddef": "cpp",
"cstdio": "cpp",
"cstdlib": "cpp",
"cstring": "cpp",
"ctime": "cpp",
"cwchar": "cpp",
"cwctype": "cpp",
"atomic": "cpp",
"strstream": "cpp",
"bitset": "cpp",
"chrono": "cpp",
"codecvt": "cpp",
"complex": "cpp",
"condition_variable": "cpp",
"cstdint": "cpp",
"deque": "cpp",
"forward_list": "cpp",
"list": "cpp",
"unordered_map": "cpp",
"unordered_set": "cpp",
"vector": "cpp",
"exception": "cpp",
"algorithm": "cpp",
"iterator": "cpp",
"map": "cpp",
"memory_resource": "cpp",
"numeric": "cpp",
"optional": "cpp",
"random": "cpp",
"ratio": "cpp",
"regex": "cpp",
"set": "cpp",
"string": "cpp",
"string_view": "cpp",
"system_error": "cpp",
"type_traits": "cpp",
"fstream": "cpp",
"initializer_list": "cpp",
"iomanip": "cpp",
"iosfwd": "cpp",
"iostream": "cpp",
"limits": "cpp",
"mutex": "cpp",
"new": "cpp",
"ostream": "cpp",
"shared_mutex": "cpp",
"sstream": "cpp",
"stdexcept": "cpp",
"streambuf": "cpp",
"thread": "cpp",
"cfenv": "cpp",
"cinttypes": "cpp",
"typeindex": "cpp",
"typeinfo": "cpp",
"valarray": "cpp",
"*.h++": "cpp"
}
}
\ No newline at end of file
......@@ -98,7 +98,7 @@ void amf_app_task(void*) {
itti_inst->notify_task_ready(task_id);
// nlohmann::json udsf_response2;
// std::string record_id = "RECORD_ID=\'" + to_string(1221) + "\'";
// std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/"+ std::string("nas_context/records/") + record_id;
// std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/"+ std::string("nas_context/records/") + record_id;
// while(1)
// {amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response2);}
do {
......@@ -340,7 +340,7 @@ void amf_app::handle_itti_message(
/********************** hxs add *******************************/
std::string record_id = "amf_ue_ngap_id=\'" + to_string(amf_ue_ngap_id) + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("ue_context/records/") + record_id ;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("ue_context/records/") + record_id ;
nlohmann::json udsf_ue_context;
nlohmann::json cgi;
cgi["Content-ID"] = "cgi";
......@@ -369,8 +369,9 @@ void amf_app::handle_itti_message(
std::string json_part = udsf_ue_context.dump();
//amf_n2_inst->curl_http_client_udsf(udsf_url,json_part,"PUT",udsf_ue_context);
nlohmann::json udsf_response;
cout<<"start to put"<<endl;
amf_n2_inst->curl_http_client_udsf(udsf_url,json_part,"PUT",udsf_response);
// udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("gnb_context/records/") + std::to_string(itti_msg.assoc_id) ;
// udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("gnb_context/records/") + std::to_string(itti_msg.assoc_id) ;
// if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
// Logger::amf_n2().error("No existing gNG context with assoc_id (%d)", itti_msg.assoc_id);
// return;
......@@ -381,7 +382,7 @@ void amf_app::handle_itti_message(
// gc1->gnb_context_from_json(udsf_response);
// gc2 = std::shared_ptr<gnb_context>(gc1);
// udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("ue_context/records/") + std::to_string(uc.get()->ran_ue_ngap_id) ;
// udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("ue_context/records/") + std::to_string(uc.get()->ran_ue_ngap_id) ;
// if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
// Logger::amf_n2().error("No existing gNG context with assoc_id (%d)", uc.get()->ran_ue_ngap_id);
// return;
......@@ -432,7 +433,7 @@ bool amf_app::generate_5g_guti(
std::shared_ptr<ue_context> uc = std::shared_ptr<ue_context>(new ue_context());
nlohmann::json udsf_response;
std::string record_id = "RECORD_ID=\'" + ue_context_key + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("ue_context/records/") + record_id;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("ue_context/records/") + record_id;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_n2().error("No existing gNG context with assoc_id");
return false;
......
This diff is collapsed.
......@@ -169,7 +169,7 @@ void amf_n11::handle_itti_message(
nlohmann::json udsf_response;
std::shared_ptr<nas_context> nc = std::shared_ptr<nas_context>(new nas_context());
std::string record_id_nas = "amf_ue_ngap_id=\'" + to_string(itti_msg.amf_ue_ngap_id) + "\'";
std::string udsf_url_nas = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("nas_context/records/") +record_id_nas ;
std::string udsf_url_nas = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("nas_context/records/") +record_id_nas ;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url_nas,"","GET",udsf_response)){
Logger::amf_n2().error("No existing pdu_session_context with assoc_id ");
return ;
......@@ -185,7 +185,7 @@ void amf_n11::handle_itti_message(
supi.c_str(), itti_msg.pdu_session_id);
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_n2().error("No existing pdu_session_context with assoc_id ");
return ;
......@@ -268,13 +268,14 @@ void amf_n11::handle_itti_message(itti_smf_services_consumer& smf) {
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response) ){
Logger::amf_n2().error("No existing pdu_session_context with assoc_id ");
psc = std::shared_ptr<pdu_session_context>(new pdu_session_context());
}
else if(udsf_response.dump().length() < 8)
{
{
Logger::amf_n2().debug("udsf_response: %s", udsf_response.dump().c_str());
Logger::amf_n2().error("No existing pdu_session_context with assoc_id----length = %d ",udsf_response.dump().length());
Logger::amf_n2().error("No existing pdu_session_context with assoc_id 2222");
psc = std::shared_ptr<pdu_session_context>(new pdu_session_context());
......@@ -430,7 +431,7 @@ void amf_n11::handle_pdu_session_initial_request(
//send udsf to storage us_ngap_context recordid=ran+ue_ngap_id
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_put_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
std::string udsf_put_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
nlohmann::json udsf_pdu_session_context;
// nlohmann::json udsf_response;
udsf_pdu_session_context["meta"] ["tags"] = {
......@@ -479,7 +480,7 @@ void amf_n11::handle_pdu_session_initial_request(
// TODO: Remove hardcoded values
std::string remote_uri =
smf_addr + "/nsmf-pdusession/v2/sm-contexts"; // TODO
"http://" + smf_addr + "/nsmf-pdusession/v1/sm-contexts"; // TODO
nlohmann::json pdu_session_establishment_request;
pdu_session_establishment_request["supi"] = supi.c_str();
pdu_session_establishment_request["pei"] = "imei-200000000000001";
......@@ -531,7 +532,7 @@ void amf_n11::handle_itti_message(
nlohmann::json udsf_response;
std::string record_id = "RECORD_ID=\'" +itti_msg.supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_n2().error("No existing pdu_session_context with assoc_id ");
}
......@@ -643,7 +644,7 @@ void amf_n11::curl_http_client(
//***************************stateless
nlohmann::json udsf_response;
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_n2().error("No existing pdu_session_context with assoc_id ");
return;
......@@ -735,7 +736,7 @@ void amf_n11::curl_http_client(
curl_slist_free_all(headers);
curl_easy_cleanup(curl);
psc.get()->smf_context_location =
"/nsmf-pdusession/v2/sm-contexts/1"; // try to fix bugs for
"/nsmf-pdusession/v1/sm-contexts/1"; // try to fix bugs for
// no-response from SMF when
// requesting
// /nsmf-pdusession/v2/sm-contexts
......@@ -804,7 +805,7 @@ void amf_n11::curl_http_client(
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_put_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
std::string udsf_put_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
nlohmann::json udsf_put_pdu_session_context;
udsf_put_pdu_session_context["meta"] ["tags"] = {
{"RECORD_ID",nlohmann::json::array({supi})},
......
This diff is collapsed.
......@@ -127,6 +127,25 @@ uint32_t ue_ngap_context::ue_ngap_context_ran_ue_ngap_id_from_json(nlohmann::jso
Logger::amf_server().error("get_value from json is error");
}
uint32_t ue_ngap_context::ue_ngap_context_amf_ue_ngap_id_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") == "amf_ue_ngap_id")
{
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");
}
uint32_t ue_ngap_context::ue_ngap_context_gnb_assoc_id_from_json(nlohmann::json j)
{
Record record;
......@@ -177,6 +196,7 @@ bool ue_ngap_context::ue_ngap_context_from_json(nlohmann::json j)
gnb_assoc_id = ue_ngap_context_gnb_assoc_id_from_json( j);
ng_ue_state = ng_ue_state_t(ue_ngap_context_ng_ue_state_from_json(j));
ran_ue_ngap_id = ue_ngap_context_ran_ue_ngap_id_from_json(j);
amf_ue_ngap_id = ue_ngap_context_amf_ue_ngap_id_from_json(j);
// printf("gnbname-%s\n",gnb_name.c_str());
// printf("globalgnbid-%d\n",globalRanNodeId);
// printf("next stream-%d\n",next_sctp_stream);
......
......@@ -48,6 +48,7 @@ class ue_ngap_context {
public:
sctp_assoc_id_t ue_ngap_context_ran_ue_ngap_id_from_json(nlohmann::json j);
uint32_t ue_ngap_context_gnb_assoc_id_from_json(nlohmann::json j);
uint32_t ue_ngap_context_amf_ue_ngap_id_from_json(nlohmann::json j);
int ue_ngap_context_ng_ue_state_from_json(nlohmann::json j);
bool ue_ngap_context_from_json(nlohmann::json j);
uint32_t ran_ue_ngap_id; // 32bits
......
This diff is collapsed.
......@@ -40,11 +40,13 @@ using namespace sctp;
namespace ngap {
static const char* const ng_gnb_state_str[] = {"NGAP_INIT", "NGAP_RESETTING",
"NGAP_READY", "NGAP_SHUTDOWN"};
static const std::vector<std::string> ng_gnb_state_str = {
"NGAP_INIT", "NGAP_RESETTING", "NGAP_READY", "NGAP_SHUTDOWN"};
#define AMF_CURL_TIMEOUT_MS 0.0001L
class ngap_app : public sctp_application {
public:
//ngap_app();
ngap_app(const std::string& address, const uint16_t port_num);
~ngap_app();
uint32_t getPpid();
......@@ -52,6 +54,13 @@ class ngap_app : public sctp_application {
void handle_receive(
bstring payload, sctp_assoc_id_t assoc_id, sctp_stream_id_t stream,
sctp_stream_id_t instreams, sctp_stream_id_t outstreams);
/*
* Handle new SCTP TNL Association (clause 8.7.1.1, 3gpp ts38.413)
* @param [sctp_assoc_id_t] assoc_id: gNB association ID
* @param [sctp_stream_id_t] instreams: instreams
* @param [sctp_stream_id_t] outstreams: outstreams
* @return void:
*/
void handle_sctp_new_association(
sctp_assoc_id_t assoc_id, sctp_stream_id_t instreams,
sctp_stream_id_t outstreams);
......
......@@ -395,7 +395,7 @@ std::shared_ptr<pdu_session_context> psc = std::shared_ptr<pdu_session_context>(
nlohmann::json udsf_response;
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_n2().error("No existing pdu_session_context with assoc_id ");
return 0 ;
......@@ -419,7 +419,7 @@ std::shared_ptr<pdu_session_context> psc = std::shared_ptr<pdu_session_context>(
record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_put_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
std::string udsf_put_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
nlohmann::json udsf_put_pdu_session_context;
//nlohmann::json udsf_response;
udsf_put_pdu_session_context["meta"] ["tags"] = {
......
#include "ngap_app.hpp"
#include "logger.hpp"
#include <nlohmann/json.hpp>
#include <curl/curl.h>
#include <stdio.h>
#include <stdlib.h>
#include <sys/time.h>
#include <unistd.h>
#include "amf_n11.hpp"
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <string>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <signal.h>
#include <iostream>
#include "udp.hpp"
#include <thread>
#include "bstrlib.h"
#include "sstream"
extern "C" {
#include "Ngap_InitiatingMessage.h"
#include "Ngap_NGAP-PDU.h"
}
using namespace std;
udp_server::udp_server(const char* udp_address,uint16_t udp_port_num){
cout<<"start create socket"<<endl;
create_socket(udp_address,udp_port_num);
cout<<"start receive"<<endl;
start_receive(udp_);
}
udp_server::~udp_server(){}
int udp_server::create_socket(const char* udp_address,uint16_t udp_port_num){
//1. 创建socket 参数一: 协议类型(版本) 参数二: 通信媒介 参数三: 保护方式
cout<<"start"<<endl;
serverSocket = socket(AF_INET,SOCK_DGRAM,IPPROTO_UDP);
if(-1 == serverSocket) printf("创建socket失败:%m\n"),exit(-1);
printf("创建socket成功!\n");
//2. 创建服务器协议地址簇
struct sockaddr_in sAddr = {0};
//uint16_t port = 8000;
//const char* ip_address= "10.103.239.21";
sAddr.sin_family = AF_INET; //协议类型 和socket函数第一个参数一致
sAddr.sin_addr.s_addr = inet_addr(udp_address); //将字符串转整数
sAddr.sin_port = htons(udp_port_num); //整数转整数 小端转大端
//3.绑定
int r = bind(serverSocket,(struct sockaddr*)&sAddr,sizeof sAddr);
if(-1 == r) printf("绑定失败:%m\n"),close(serverSocket),exit(-2);
printf("绑定成功!\n");
return serverSocket;
// struct sockaddr_in addr = {};
// int sd = 0;
// /*
// * Create UDP socket
// */
// if ((sd = socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) {
// /*
// * Socket creation has failed...
// */
// printf("Socket creation failed (%s)\n", strerror(errno));
// return errno;
// }
// addr.sin_family = AF_INET;
// addr.sin_port = htons(udp_port_num);
// addr.sin_addr.s_addr = inet_addr(udp_address);
// std::string ipv4 = udp_address;
// printf(
// "Creating new listen socket on address %s and port %" PRIu16 " ",
// ipv4.c_str(), udp_port_num);
// if (bind(sd, (struct sockaddr*) &addr, sizeof(struct sockaddr_in)) < 0) {
// /*
// * Bind failed
// */
// printf(
// "Socket bind failed (%s) for address %s and port %" PRIu16 " \n",
// strerror(errno), ipv4.c_str(), udp_port_num);
// close(sd);
// return errno;
// }
}
void udp_server::start_receive(udp_server* udp){
udp_ = udp;
//pthread_create(&udp_thread, NULL, udp_receiver_thread, (void*) this);
//pthread_exit(NULL);
thread_ = std::thread(&udp_server::udp_read_from_socket,this);
thread_.detach();
}
// void* udp_server::udp_receiver_thread(void* arg) {
// udp_server* ptr = (udp_server*) arg;
// //Logger::udp().info("Create pthread to receive udp message");
// ptr->udp_read_from_socket();
// }
int udp_server::getSocket(){
return serverSocket;
}
int udp_server::getPpid(){
return ppid;
}
int udp_server::udp_read_from_socket() {
//4.通信
uint8_t udp_recv[UDP_RECV_BUFFER_SIZE];
//bstring udp_recv;
//struct sockaddr_in cAddr = {0};
//socklen_t len = sizeof(cAddr);
endpoint r_endpoint = {};
//socklen_t addr_len;
int udp_len;
size_t bytes_received = 0;
cout<<"start receive"<<endl;
assoc_id = 0;
stream = 0;
while(1){
r_endpoint.addr_storage_len=sizeof(struct sockaddr_storage);
//如果还需要向客户端发送东西用recvfrom
//udp精髓 向一个协议地址簇发东西
//收消息
//r = recvfrom(serverSocket,udp_recv,udp_len,0,(struct sockaddr*)&cAddr,&len);
bytes_received = recvfrom(serverSocket, (void *)udp_recv, UDP_RECV_BUFFER_SIZE , 0, (struct sockaddr*)&r_endpoint.addr_storage, &r_endpoint.addr_storage_len);
//bytes_received = recvfrom(serverSocket, udp_recv, UDP_RECV_BUFFER_SIZE , 0, (struct sockaddr*)&r_endpoint.addr_storage, &r_endpoint.addr_storage_len);
if(bytes_received > 0){
printf("receive udp success\n");
cout<<"bytes"<<bytes_received<<endl;
cout<<"content:"<<udp_recv<<endl;
// string udp_recv_str(&udp_recv[0],&udp_recv[strlen(udp_recv)]);
// cout<<"content:"<<udp_recv_str<<endl;
handle_receive_udp(bytes_received,udp_recv);
// assoc_id++;
// stream++;
//ngap_app("0",0).handle_receive(udp_recv_str,assoc_id,stream,0,0);
}
}
return 0;
}
vector<string> SplitString(string s, string c){
string::size_type pos1, pos2;
vector<string> v;
pos2 = s.find(c);
pos1 = 0;
while(string::npos != pos2)
{
v.push_back(s.substr(pos1, pos2-pos1));
pos1 = pos2 + c.size();
pos2 = s.find(c, pos1);
}
if(pos1 != s.length())
v.push_back(s.substr(pos1));
return v;
}
void udp_server::handle_receive_udp(int r,uint8_t udp_recv[]){
stringstream ngap_msg_stream;
sctp_stream_id_t stream;
sctp_assoc_id_t assoc_id;
vector<string> MsgVec;
uint8_t buffer[2048];
//拆分字符串分出连接号
// ngap_msg_stream<<udp_recv;
// ngap_msg_stream>>ngap_msg;
//MsgVec = SplitString(ngap_msg,"|");
//数组赋值
for(int i=0;i<r-2;i++){
buffer[i] = udp_recv[i];
}
int _assoc_id = udp_recv[r-2];
int _stream = udp_recv[r-1];
//打印buffer检查数据
// for(int i = 0; i < r-2; i++)
// {
// std::stringstream data;
// data << std::hex << (int)buffer[i];
// std::cout << data.str() << std::endl;
// }
assoc_id = _assoc_id;
bstring payload=blk2bstr(buffer,r-2);
//bstring udp_recv_bstr=bfromcstr(content.c_str());
cout<<"data:"<<payload->data<<endl;
cout<<"slen"<<payload->slen<<endl;
cout<<"mlen"<<payload->mlen<<endl;
cout<<"start handle"<<endl;
ngap_app("0",0).handle_receive(payload,assoc_id,stream,0,0);
// Ngap_NGAP_PDU_t* ngap_msg_pdu =
// (Ngap_NGAP_PDU_t*) calloc(1, sizeof(Ngap_NGAP_PDU_t));
// Logger::udp().info("start decode");
// asn_dec_rval_t rc = asn_decode(
// NULL, ATS_ALIGNED_CANONICAL_PER, &asn_DEF_Ngap_NGAP_PDU,
// (void**) &ngap_msg_pdu, bdata(udp_recv_bstr), blength(udp_recv_bstr));
// Logger::udp().debug(
// "Decoded UDP message, procedure code %d, present %d",
// ngap_msg_pdu->choice.initiatingMessage->procedureCode,
// ngap_msg_pdu->present);
// asn_fprint(stderr, &asn_DEF_Ngap_NGAP_PDU, ngap_msg_pdu);
// (*messages_callback[ngap_msg_pdu->choice.initiatingMessage->procedureCode]
// [ngap_msg_pdu->present - 1])(
// assoc_id, stream, ngap_msg_pdu);
}
#ifndef __UDP_H
#define __UDP_H
#include "gNB_context.hpp"
#include "sctp_server.hpp"
#include <iostream>
#include <string>
#include <vector>
#include <thread>
#define UDP_RECV_BUFFER_SIZE 8192
using namespace std;
class udp_server{
private:
void* udp_recv;
struct sockaddr_in cAddr = {0};
socklen_t len = sizeof(cAddr);
int udp_len;
uint16_t m_port;
const char* m_address;
int serverSocket;
sctp_assoc_id_t assoc_id;
sctp_stream_id_t stream;
udp_server* udp_;
pthread_t udp_thread;
uint32_t ppid;
std::thread thread_;
public:
udp_server(const char* address,uint16_t port_num);
virtual ~udp_server();
int create_socket(const char* address,uint16_t port_num);
void start_receive(udp_server* udp);
void handle_receive();
static void* udp_receiver_thread(void* arg);
int udp_read_from_socket();
void handle_receive_udp(int r,uint8_t udp_recv[]);
int getSocket();
int getPpid();
//void SplitString(string s, vector<string>& v, string c);
};
#endif
\ No newline at end of file
......@@ -49,6 +49,8 @@ extern void print_buffer(
const std::string app, const std::string commit, uint8_t* buf, int len);
extern void ue_gnb_simulator();
#include "udp.hpp"
using namespace config;
using namespace amf_application;
......@@ -58,6 +60,8 @@ itti_mw* itti_inst = nullptr;
amf_app* amf_app_inst = nullptr;
statistics stacs;
//------------------------------------------------------------------------------
int main(int argc, char** argv) {
srand(time(NULL));
......@@ -81,16 +85,24 @@ int main(int argc, char** argv) {
amf_app_inst = new amf_app(amf_cfg);
amf_app_inst->allRegistredModulesInit(modules);
//udp_server udp_("10.103.239.21",8000);
// udp_.start_receive(&udp_);
Logger::amf_app().debug("Initiating AMF server endpoints");
Pistache::Address addr(
std::string(inet_ntoa(*((struct in_addr*) &amf_cfg.n11.addr4))),
Pistache::Port(amf_cfg.n11.port));
AMFApiServer amfApiServer(addr, amf_app_inst);
AMFApiServer amfApiServer(addr, amf_app_inst);
amfApiServer.init(2);
std::thread amf_api_manager(&AMFApiServer::start, amfApiServer);
Logger::amf_app().debug("Initiating Done!");
udp_server udp_("10.103.239.58",9000);
Logger::amf_app().debug("Initiation Done!");
pause();
return 0;
}
......@@ -94,7 +94,7 @@ std::shared_ptr<pdu_session_context> psc = std::shared_ptr<pdu_session_context>(
nlohmann::json udsf_response;
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
if(!amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_n2().error("No existing pdu_session_context with assoc_id ");
}
......@@ -131,7 +131,7 @@ std::shared_ptr<pdu_session_context> psc = std::shared_ptr<pdu_session_context>(
record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_put_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
std::string udsf_put_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
nlohmann::json udsf_put_pdu_session_context;
//nlohmann::json udsf_response;
udsf_put_pdu_session_context["meta"] ["tags"] = {
......
......@@ -39,7 +39,7 @@ std::shared_ptr<pdu_session_context> psc = std::shared_ptr<pdu_session_context>(
nlohmann::json udsf_response;
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id ;
if(amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_server().debug("udsf_response: %s", udsf_response.dump().c_str());
psc.get()->pdu_session_context_from_json(udsf_response);
......@@ -106,7 +106,7 @@ std::shared_ptr<pdu_session_context> psc = std::shared_ptr<pdu_session_context>(
nlohmann::json udsf_response;
std::string record_id = "RECORD_ID=\'" +supi + "\'";
std::string udsf_url = "http://10.112.202.24:7123/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
std::string udsf_url = "http://10.103.239.58:8081/nudsf-dr/v1/amfdata/" + std::string("pdu_session_context/records/") + record_id;
if(amf_n2_inst->curl_http_client_udsf(udsf_url,"","GET",udsf_response)){
Logger::amf_server().debug("udsf_response: %s", udsf_response.dump().c_str());
psc.get()->pdu_session_context_from_json(udsf_response);
......
......@@ -88,6 +88,7 @@ int sctp_server::create_socket(const char* address, const uint16_t port_num) {
socket_, IPPROTO_SCTP, SCTP_EVENTS, &events_,
sizeof(struct sctp_event_subscribe));
listen(socket_, 5);
return 0;
}
//------------------------------------------------------------------------------
......@@ -204,6 +205,7 @@ int sctp_server::sctp_read_from_socket(int sd, uint32_t ppid) {
"on stream %d, PPID %d ****",
sinfo.sinfo_assoc_id, sd, n, ntohs(addr.sin6_port), sinfo.sinfo_stream,
ntohl(sinfo.sinfo_ppid));
std::cout<<"buffer:"<<buffer<<std::endl;
bstring payload = blk2bstr(buffer, n);
// handle payload
app_->handle_receive(
......@@ -437,7 +439,7 @@ static std::size_t callback(
}
void sctp_server::curl_http_client_Plugin(sctp_assoc_id_t assoc_id, sctp_stream_id_t stream,bstring payload)
{
printf("使用http发送到pluginf\n");
printf("use http send to pluginf\n");
std::string ngapmsg;
octet_stream_2_hex_stream((uint8_t*) bdata(payload), blength(payload), ngapmsg);
......@@ -450,7 +452,7 @@ void sctp_server::curl_http_client_Plugin(sctp_assoc_id_t assoc_id, sctp_stream_
std::string url =
"http://" + std::string("10.112.202.24") +
"http://" + std::string("10.103.239.21") +
":" + std::to_string(38414) + "/nplugin-dr/v1/" +
to_string (assoc_id ) + "/" + to_string (stream) ;
......
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