Commit b7712a1a authored by liuyu's avatar liuyu

edge amf->dege smf-> center amf->edge smf -> edge amf is ok

parent 297e09ea
...@@ -133,8 +133,8 @@ int main(int argc, char** argv) { ...@@ -133,8 +133,8 @@ int main(int argc, char** argv) {
exit(-EDEADLK); exit(-EDEADLK);
} }
udp_server_coop udp_uplink_("10.103.239.31",20001); udp_server_coop udp_uplink_(inet_ntoa(smf_cfg.sbi.addr4),20001);
udp_server_coop udp_downlink_("10.103.239.31",20004); udp_server_coop udp_downlink_(inet_ntoa(smf_cfg.sbi.addr4),20004);
// SMF Pistache API server (HTTP1) // SMF Pistache API server (HTTP1)
Pistache::Address addr( Pistache::Address addr(
......
...@@ -67,7 +67,7 @@ udp_server_coop::udp_server_coop(const char* udp_address,uint16_t udp_port_num){ ...@@ -67,7 +67,7 @@ udp_server_coop::udp_server_coop(const char* udp_address,uint16_t udp_port_num){
cout<<"start create socket"<<endl; cout<<"start create socket"<<endl;
create_socket(udp_address,udp_port_num); create_socket(udp_address,udp_port_num);
cout<<"start receive"<<endl; cout<<"start receive"<<endl;
start_receive(udp_); start_receive(udp_,udp_port_num);
} }
udp_server_coop::~udp_server_coop(){} udp_server_coop::~udp_server_coop(){}
...@@ -91,62 +91,26 @@ int udp_server_coop::create_socket(const char* udp_address,uint16_t udp_port_num ...@@ -91,62 +91,26 @@ int udp_server_coop::create_socket(const char* udp_address,uint16_t udp_port_num
int r = bind(serverSocket,(struct sockaddr*)&sAddr,sizeof sAddr); int r = bind(serverSocket,(struct sockaddr*)&sAddr,sizeof sAddr);
if(-1 == r) printf("绑定失败:%m\n"),close(serverSocket),exit(-2); if(-1 == r) printf("绑定失败:%m\n"),close(serverSocket),exit(-2);
printf("绑定成功!\n"); printf("绑定成功!\n");
return serverSocket; 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_coop::start_receive(udp_server_coop* udp){ void udp_server_coop::start_receive(udp_server_coop* udp, uint16_t udp_port_num){
udp_ = udp; udp_ = udp;
//pthread_create(&udp_thread, NULL, udp_receiver_thread, (void*) this); //pthread_create(&udp_thread, NULL, udp_receiver_thread, (void*) this);
//pthread_exit(NULL); //pthread_exit(NULL);
thread_ = std::thread(&udp_server_coop::udp_read_from_socket,this); printf("绑定成功!5555 %d\n", udp_port_num);
thread_.detach(); if(udp_port_num == 20001)
{
thread_ = std::thread(&udp_server_coop::udp_read_from_socket_to_center,this);
thread_.detach();
}
else{
thread_ = std::thread(&udp_server_coop::udp_read_from_socket_from_center,this);
thread_.detach();
}
} }
// void* udp_server_coop::udp_receiver_thread(void* arg) {
// udp_server_coop* ptr = (udp_server_coop*) arg;
// //Logger::udp().info("Create pthread to receive udp message");
// ptr->udp_read_from_socket();
// }
int udp_server_coop::getSocket(){ int udp_server_coop::getSocket(){
return serverSocket; return serverSocket;
} }
...@@ -155,7 +119,7 @@ int udp_server_coop::getPpid(){ ...@@ -155,7 +119,7 @@ int udp_server_coop::getPpid(){
return ppid; return ppid;
} }
int udp_server_coop::udp_read_from_socket() { 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];
//bstring udp_recv; //bstring udp_recv;
...@@ -178,7 +142,7 @@ int udp_server_coop::udp_read_from_socket() { ...@@ -178,7 +142,7 @@ int udp_server_coop::udp_read_from_socket() {
//bytes_received = recvfrom(serverSocket, 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){ if(bytes_received > 0){
printf("smf receive udp success from amf\n"); printf("smf receive udp success from satellite amf\n");
gettimeofday(&time, NULL); gettimeofday(&time, NULL);
// std::cout<<"receive from plugin, ms: "<<(time.tv_sec*1000 + time.tv_usec/1000)<<std::endl; // std::cout<<"receive from plugin, ms: "<<(time.tv_sec*1000 + time.tv_usec/1000)<<std::endl;
// cout<<"bytes"<<bytes_received<<endl; // cout<<"bytes"<<bytes_received<<endl;
...@@ -187,7 +151,49 @@ int udp_server_coop::udp_read_from_socket() { ...@@ -187,7 +151,49 @@ int udp_server_coop::udp_read_from_socket() {
// cout<<"content:"<<udp_recv_str<<endl; // cout<<"content:"<<udp_recv_str<<endl;
// handle_receive_udp(bytes_received,udp_recv); // handle_receive_udp(bytes_received,udp_recv);
printf("smf send udp to center amf\n"); printf("smf send udp to center amf\n");
UdpSend(udp_recv,bytes_received,"10.103.238.72",20003); UdpSend(udp_recv,bytes_received,"10.103.239.47",20003);
// assoc_id++;
// stream++;
//ngap_app("0",0).handle_receive(udp_recv_str,assoc_id,stream,0,0);
}
}
return 0;
}
int udp_server_coop::udp_read_from_socket_from_center() {
//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 udp success from center amf\n");
gettimeofday(&time, NULL);
// std::cout<<"receive from plugin, ms: "<<(time.tv_sec*1000 + time.tv_usec/1000)<<std::endl;
// 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);
printf("smf send udp to satellite amf\n");
UdpSend(udp_recv,bytes_received,"10.103.239.31",20002);
// assoc_id++; // assoc_id++;
// stream++; // stream++;
......
...@@ -41,10 +41,11 @@ class udp_server_coop{ ...@@ -41,10 +41,11 @@ class udp_server_coop{
udp_server_coop(const char* address,uint16_t port_num); udp_server_coop(const char* address,uint16_t port_num);
virtual ~udp_server_coop(); virtual ~udp_server_coop();
int create_socket(const char* address,uint16_t port_num); int create_socket(const char* address,uint16_t port_num);
void start_receive(udp_server_coop* udp); 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_socket(); int udp_read_from_socket_from_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[]);
int getSocket(); int getSocket();
int getPpid(); int getPpid();
......
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