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) {
exit(-EDEADLK);
}
udp_server_coop udp_uplink_("10.103.239.31",20001);
udp_server_coop udp_downlink_("10.103.239.31",20004);
udp_server_coop udp_uplink_(inet_ntoa(smf_cfg.sbi.addr4),20001);
udp_server_coop udp_downlink_(inet_ntoa(smf_cfg.sbi.addr4),20004);
// SMF Pistache API server (HTTP1)
Pistache::Address addr(
......
......@@ -67,7 +67,7 @@ udp_server_coop::udp_server_coop(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_);
start_receive(udp_,udp_port_num);
}
udp_server_coop::~udp_server_coop(){}
......@@ -92,61 +92,25 @@ int udp_server_coop::create_socket(const char* udp_address,uint16_t udp_port_num
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_coop::start_receive(udp_server_coop* udp){
void udp_server_coop::start_receive(udp_server_coop* udp, uint16_t udp_port_num){
udp_ = udp;
//pthread_create(&udp_thread, NULL, udp_receiver_thread, (void*) this);
//pthread_exit(NULL);
thread_ = std::thread(&udp_server_coop::udp_read_from_socket,this);
printf("绑定成功!5555 %d\n", udp_port_num);
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(){
return serverSocket;
}
......@@ -155,7 +119,7 @@ int udp_server_coop::getPpid(){
return ppid;
}
int udp_server_coop::udp_read_from_socket() {
int udp_server_coop::udp_read_from_socket_to_center() {
//4.通信
uint8_t udp_recv[UDP_RECV_BUFFER_SIZE];
//bstring udp_recv;
......@@ -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);
if(bytes_received > 0){
printf("smf receive udp success from amf\n");
printf("smf receive udp success from satellite 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;
......@@ -187,7 +151,49 @@ int udp_server_coop::udp_read_from_socket() {
// cout<<"content:"<<udp_recv_str<<endl;
// handle_receive_udp(bytes_received,udp_recv);
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++;
// stream++;
......
......@@ -41,10 +41,11 @@ class udp_server_coop{
udp_server_coop(const char* address,uint16_t port_num);
virtual ~udp_server_coop();
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();
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[]);
int getSocket();
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