Commit cdca2aba authored by liuyu's avatar liuyu

udp send begin

parent b7712a1a
...@@ -135,6 +135,7 @@ int main(int argc, char** argv) { ...@@ -135,6 +135,7 @@ int main(int argc, char** argv) {
udp_server_coop udp_uplink_(inet_ntoa(smf_cfg.sbi.addr4),20001); udp_server_coop udp_uplink_(inet_ntoa(smf_cfg.sbi.addr4),20001);
udp_server_coop udp_downlink_(inet_ntoa(smf_cfg.sbi.addr4),20004); udp_server_coop udp_downlink_(inet_ntoa(smf_cfg.sbi.addr4),20004);
udp_server_coop udp_smf_(inet_ntoa(smf_cfg.sbi.addr4),2023);
// SMF Pistache API server (HTTP1) // SMF Pistache API server (HTTP1)
Pistache::Address addr( Pistache::Address addr(
......
...@@ -64,6 +64,10 @@ ...@@ -64,6 +64,10 @@
#include "fqdn.hpp" #include "fqdn.hpp"
#include "smf_config.hpp" #include "smf_config.hpp"
#include "smf_pfcp_association.hpp" #include "smf_pfcp_association.hpp"
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <signal.h>
extern "C" { extern "C" {
#include "dynamic_memory_check.h" #include "dynamic_memory_check.h"
...@@ -84,6 +88,29 @@ extern itti_mw* itti_inst; ...@@ -84,6 +88,29 @@ extern itti_mw* itti_inst;
void smf_app_task(void*); void smf_app_task(void*);
int clientSocket;
void UdpSend_smf(nlohmann::json aggregation,string ip,int port){
std::string jsonData = aggregation.dump();
struct timeval time;
//1. 创建socket 参数一: 协议类型(版本) 参数二: 通信媒介 参数三: 保护方式
clientSocket = socket(AF_INET,SOCK_DGRAM,0);
//2. 创建服务器协议地址簇
struct sockaddr_in cAddr = {0};
const char* ipAddr = ip.c_str();
cAddr.sin_family = AF_INET; //协议类型 和socket函数第一个参数一致
cAddr.sin_addr.s_addr = inet_addr(ipAddr); //将字符串转整数
cAddr.sin_port = htons(port); //整数转整数 小端转大端
int r;
int len = sizeof cAddr;
int sendNum;
sendNum = sendto(clientSocket,jsonData.c_str(), jsonData.length(),0,
(struct sockaddr*)&cAddr,len);
close(clientSocket);
Logger::smf_app().info("udpsend smfcontext complete\n");
}
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
int smf_app::apply_config(const smf_config& cfg) { int smf_app::apply_config(const smf_config& cfg) {
Logger::smf_app().info("Apply config..."); Logger::smf_app().info("Apply config...");
......
...@@ -85,7 +85,7 @@ using namespace smf; ...@@ -85,7 +85,7 @@ using namespace smf;
extern itti_mw* itti_inst; extern itti_mw* itti_inst;
extern smf::smf_app* smf_app_inst; extern smf::smf_app* smf_app_inst;
extern smf::smf_config smf_cfg; extern smf::smf_config smf_cfg;
extern void UdpSend_smf(nlohmann::json aggregation,string ip,int port);
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
void smf_pdu_session::get_pdu_session_id(uint32_t& psi) const { void smf_pdu_session::get_pdu_session_id(uint32_t& psi) const {
psi = pdu_session_id; psi = pdu_session_id;
...@@ -4957,6 +4957,12 @@ void smf_context::send_pdu_session_create_response( ...@@ -4957,6 +4957,12 @@ void smf_context::send_pdu_session_create_response(
// HTTP version // HTTP version
resp->http_version = smf_cfg.http_version; resp->http_version = smf_cfg.http_version;
nlohmann::json udpsmfcontext;
udpsmfcontext["scid"] = "2";
udpsmfcontext["pdu_session_id"] = "2";
UdpSend_smf(udpsmfcontext,"10.103.239.31", 2023);
// Fill the json part // Fill the json part
nlohmann::json json_data = {}; nlohmann::json json_data = {};
......
...@@ -737,6 +737,14 @@ smf_procedure_code session_create_sm_context_procedure::run( ...@@ -737,6 +737,14 @@ smf_procedure_code session_create_sm_context_procedure::run(
// Get next UPF for the first N4 session establishment // Get next UPF for the first N4 session establishment
get_next_upf(dl_edges, ul_edges, upf); get_next_upf(dl_edges, ul_edges, upf);
Logger::smf_app().info("-----------------udpsend",sm_context_req->scid);
// nlohmann::json udpsmfcontext;
// udpsmfcontext["scid"] = "2";
// udpsmfcontext["pdu_session_id"] = "2";
// UdpSend_smf(udpsmfcontext,"10.103.239.31", 2023);
// extern void UdpSend_downlink(nlohmann::json aggregation,string ip,int port);
return send_n4_session_establishment_request(); return send_n4_session_establishment_request();
} }
......
...@@ -6,7 +6,7 @@ ...@@ -6,7 +6,7 @@
#include <stdlib.h> #include <stdlib.h>
#include <sys/time.h> #include <sys/time.h>
#include <unistd.h> #include <unistd.h>
// #include "amf_sbi.hpp" #include "smf_app.hpp"
#include <stdio.h> #include <stdio.h>
#include <unistd.h> #include <unistd.h>
#include <stdlib.h> #include <stdlib.h>
...@@ -21,12 +21,14 @@ ...@@ -21,12 +21,14 @@
#include <thread> #include <thread>
#include "bstrlib.h" #include "bstrlib.h"
#include "sstream" #include "sstream"
// extern "C" { // extern "C" {
// #include "Ngap_InitiatingMessage.h" // #include "Ngap_InitiatingMessage.h"
// #include "Ngap_NGAP-PDU.h" // #include "Ngap_NGAP-PDU.h"
// } // }
using namespace smf;
extern smf::smf_app* smf_app_inst;
// extern smf::smf_config smf_cfg;
void UdpSend(uint8_t buffer[],int n,string ip,int port){ void UdpSend(uint8_t buffer[],int n,string ip,int port){
//signal(SIGINT,hand); //signal(SIGINT,hand);
...@@ -105,6 +107,11 @@ void udp_server_coop::start_receive(udp_server_coop* udp, uint16_t udp_port_num) ...@@ -105,6 +107,11 @@ void udp_server_coop::start_receive(udp_server_coop* udp, uint16_t udp_port_num)
thread_ = std::thread(&udp_server_coop::udp_read_from_socket_to_center,this); thread_ = std::thread(&udp_server_coop::udp_read_from_socket_to_center,this);
thread_.detach(); thread_.detach();
} }
if (udp_port_num == 2023)
{
thread_ = std::thread(&udp_server_coop::udp_read_from_peer_smf,this);
thread_.detach();
}
else{ else{
thread_ = std::thread(&udp_server_coop::udp_read_from_socket_from_center,this); thread_ = std::thread(&udp_server_coop::udp_read_from_socket_from_center,this);
thread_.detach(); thread_.detach();
...@@ -119,6 +126,53 @@ int udp_server_coop::getPpid(){ ...@@ -119,6 +126,53 @@ int udp_server_coop::getPpid(){
return ppid; return ppid;
} }
int udp_server_coop::udp_read_from_peer_smf() {
//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;
struct timeval time;
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("smf receive context from ground smf\n");
std::string received_data(reinterpret_cast<char*>(udp_recv), bytes_received);
nlohmann::json smfcontext = nlohmann::json::parse(received_data);
scid_t scid = smfcontext["scid"];
std::shared_ptr<smf_context_ref> scf = {};
if (smf_app_inst->is_scid_2_smf_context(scid)) {
scf = smf_app_inst->scid_2_smf_context(scid);
} else {
Logger::smf_app().warn("SM Context associated with this id " SCID_FMT " does not exit!", scid);
std::shared_ptr<smf_context_ref> scf = std::shared_ptr<smf_context_ref>(new smf_context_ref());
// supi_t supi = smreq->req.get_supi();
// scf.get()->supi = smfcontext["supi"];
scf.get()->pdu_session_id = smfcontext["pdu_session_id"];
smf_app_inst->set_scid_2_smf_context(scid, scf);
}
}
}
return 0;
}
int udp_server_coop::udp_read_from_socket_to_center() { int udp_server_coop::udp_read_from_socket_to_center() {
//4.通信 //4.通信
uint8_t udp_recv[UDP_RECV_BUFFER_SIZE]; uint8_t udp_recv[UDP_RECV_BUFFER_SIZE];
......
...@@ -44,6 +44,7 @@ class udp_server_coop{ ...@@ -44,6 +44,7 @@ class udp_server_coop{
void start_receive(udp_server_coop* udp, uint16_t udp_port_num); void start_receive(udp_server_coop* udp, uint16_t udp_port_num);
void handle_receive(); void handle_receive();
static void* udp_receiver_thread(void* arg); static void* udp_receiver_thread(void* arg);
int udp_read_from_peer_smf();
int udp_read_from_socket_from_center(); int udp_read_from_socket_from_center();
int udp_read_from_socket_to_center(); int udp_read_from_socket_to_center();
void handle_receive_udp(int r,uint8_t udp_recv[]); void handle_receive_udp(int r,uint8_t udp_recv[]);
......
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