updates for udp IF4p5

This commit is contained in:
luhan wang
2016-10-27 09:45:56 +02:00
parent 3c7ec4e416
commit 727cdb4a87
7 changed files with 113 additions and 67 deletions
@@ -311,6 +311,9 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
ssize_t packet_size = MAC_HEADER_SIZE_BYTES + sizeof_IF4p5_header_t;
IF4p5_header_t *test_header = (IF4p5_header_t*)(buff[0] + MAC_HEADER_SIZE_BYTES);
#ifdef DEBUG
printf("Reading from device %p, eth %p, sockfd %d\n",device,eth,eth->sockfd[Mod_id]);
#endif
bytes_received = recv(eth->sockfd[Mod_id],
buff[0],
@@ -321,7 +324,12 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
perror("ETHERNET IF4p5 READ (header): ");
exit(-1);
}
#ifdef DEBUG
for (int i=0;i<packet_size;i++)
printf("%2x.",((uint8_t*)buff[0])[i]);
printf("\n");
#endif
*timestamp = test_header->sub_type;
if (test_header->sub_type == IF4p5_PDLFFT) {
+39 -35
View File
@@ -54,9 +54,9 @@
#include "ethernet_lib.h"
#define DEBUG 0
struct sockaddr_in dest_addr[MAX_INST];
struct sockaddr_in local_addr[MAX_INST];
int addr_len[MAX_INST];
//struct sockaddr_in dest_addr[MAX_INST];
//struct sockaddr_in local_addr[MAX_INST];
//int addr_len[MAX_INST];
uint16_t pck_seq_num = 1;
@@ -96,7 +96,7 @@ int eth_socket_init_udp(openair0_device *device) {
sock_type=SOCK_DGRAM;
sock_proto=IPPROTO_UDP;
if ((eth->sockfd[Mod_id] = socket(sock_dom, sock_type, sock_proto)) == -1) {
if ((eth->sockfd = socket(sock_dom, sock_type, sock_proto)) == -1) {
perror("ETHERNET: Error opening socket");
exit(0);
}
@@ -107,32 +107,32 @@ int eth_socket_init_udp(openair0_device *device) {
bzero((void *)&(local_addr[i]), sizeof(local_addr[i]));
}
addr_len[Mod_id] = sizeof(struct sockaddr_in);
eth->udp.addr_len = sizeof(struct sockaddr_in);
dest_addr[Mod_id].sin_family = AF_INET;
inet_pton(AF_INET,remote_ip,&(dest_addr[Mod_id].sin_addr.s_addr));
dest_addr[Mod_id].sin_port=htons(remote_port);
inet_ntop(AF_INET, &(dest_addr[Mod_id].sin_addr), str_remote, INET_ADDRSTRLEN);
eth->udp.dest_addr.sin_family = AF_INET;
inet_pton(AF_INET,remote_ip,&(dest_addr.sin_addr.s_addr));
eth->udp.dest_addr.sin_port=htons(remote_port);
inet_ntop(AF_INET, &(eth->udp.dest_addr.sin_addr), str_remote, INET_ADDRSTRLEN);
local_addr[Mod_id].sin_family = AF_INET;
inet_pton(AF_INET,local_ip,&(local_addr[Mod_id].sin_addr.s_addr));
local_addr[Mod_id].sin_port=htons(local_port);
inet_ntop(AF_INET, &(local_addr[Mod_id].sin_addr), str_local, INET_ADDRSTRLEN);
device->local_addr.sin_family = AF_INET;
inet_pton(AF_INET,local_ip,&(device->local_addr.sin_addr.s_addr));
device->local_addr.sin_port=htons(local_port);
inet_ntop(AF_INET, &(device->local_addr.sin_addr), str_local, INET_ADDRSTRLEN);
/* set reuse address flag */
if (setsockopt(eth->sockfd[Mod_id], SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int))) {
if (setsockopt(eth->sockfd, SOL_SOCKET, SO_REUSEADDR, &enable, sizeof(int))) {
perror("ETHERNET: Cannot set SO_REUSEADDR option on socket");
exit(0);
}
/* want to receive -> so bind */
if (bind(eth->sockfd[Mod_id],(struct sockaddr *)&local_addr[Mod_id],addr_len[Mod_id])<0) {
if (bind(eth->sockfd,(struct sockaddr *)&eth->udp.local_addr,addr_len[Mod_id])<0) {
perror("ETHERNET: Cannot bind to socket");
exit(0);
} else {
printf("[%s] binding mod_%d to %s:%d\n","RRH",Mod_id,str_local,ntohs(local_addr[Mod_id].sin_port));
printf("[%s] binding mod_%d to %s:%d\n","RRH",Mod_id,str_local,ntohs(eth->udp.local_addr.sin_port));
}
return 0;
@@ -155,11 +155,11 @@ int trx_eth_read_udp_IF4p5(openair0_device *device, openair0_timestamp *timestam
while(bytes_received == -1) {
again:
bytes_received = recvfrom(eth->sockfd[Mod_id],
bytes_received = recvfrom(eth->sockfd,
buff[0],
packet_size,
0,
(struct sockaddr *)&dest_addr[Mod_id],
(struct sockaddr *)&eth->udp.dest_addr,
(socklen_t *)&addr_len[Mod_id]);
if (bytes_received ==-1) {
eth->num_rx_errors++;
@@ -223,11 +223,11 @@ int trx_eth_write_udp_IF4p5(openair0_device *device, openair0_timestamp timestam
eth->tx_nsamps = nblocks;
bytes_sent = sendto(eth->sockfd[Mod_id],
bytes_sent = sendto(eth->sockfd,
buff[0],
packet_size,
0,
(struct sockaddr*)&dest_addr[Mod_id],
(struct sockaddr*)&eth->udp.dest_addr,
addr_len[Mod_id]);
if (bytes_sent == -1) {
@@ -280,11 +280,11 @@ int trx_eth_write_udp(openair0_device *device, openair0_timestamp timestamp, voi
bytes_sent);
#endif
/* Send packet */
bytes_sent += sendto(eth->sockfd[Mod_id],
bytes_sent += sendto(eth->sockfd,
buff2,
UDP_PACKET_SIZE_BYTES(nsamps),
sendto_flag,
(struct sockaddr*)&dest_addr[Mod_id],
(struct sockaddr*)&eth->udp.dest_addr,
addr_len[Mod_id]);
if ( bytes_sent == -1) {
@@ -350,12 +350,12 @@ int trx_eth_read_udp(openair0_device *device, openair0_timestamp *timestamp, voi
UDP_PACKET_SIZE_BYTES(nsamps) - bytes_received,
bytes_received);
#endif
bytes_received +=recvfrom(eth->sockfd[Mod_id],
bytes_received +=recvfrom(eth->sockfd,
buff2,
UDP_PACKET_SIZE_BYTES(nsamps),
rcvfrom_flag,
(struct sockaddr *)&dest_addr[Mod_id],
(socklen_t *)&addr_len[Mod_id]);
(struct sockaddr *)&eth->udp.dest_addr,
(socklen_t *)&device->udp.addr_len);
if (bytes_received ==-1) {
eth->num_rx_errors++;
@@ -437,9 +437,13 @@ int eth_set_dev_conf_udp(openair0_device *device) {
msg=malloc(sizeof(openair0_config_t));
msg_len=sizeof(openair0_config_t);
memcpy(msg,(void*)device->openair0_cfg,msg_len);
printf("Sending configuration to device %p (%d.%d.%d.%d)\n",device,
eth->udp.dest_addr[3],eth->udp.dest_addr[2],eth->udp.dest_addr[1],eth->udp.dest_addr[0],msg_len);
if (sendto(eth->sockfd[Mod_id],msg,msg_len,0,(struct sockaddr *)&dest_addr[Mod_id],addr_len[Mod_id])==-1) {
if (sendto(eth->sockfd,msg,msg_len,0,(struct sockaddr *)&eth->udp.dest_addr,device->udp.addr_len)==-1) {
perror("ETHERNET: ");
printf("addr_len[%d] : %d, msg_len %d\n",Mod_id,device->udp.addr_len,msg_len);
exit(0);
}
@@ -457,15 +461,15 @@ int eth_get_dev_conf_udp(openair0_device *device) {
msg=malloc(sizeof(openair0_config_t));
msg_len=sizeof(openair0_config_t);
inet_ntop(AF_INET, &(local_addr[Mod_id].sin_addr), str, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(dest_addr[Mod_id].sin_addr), str1, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(eth->udp.local_addr.sin_addr), str, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(eth->udp.dest_addr.sin_addr), str1, INET_ADDRSTRLEN);
/* RRH receives from BBU openair0_config_t */
if (recvfrom(eth->sockfd[Mod_id],
if (recvfrom(eth->sockfd,
msg,
msg_len,
0,
(struct sockaddr *)&dest_addr[Mod_id],
(struct sockaddr *)&eth->udp.dest_addr,
(socklen_t *)&addr_len[Mod_id])==-1) {
perror("ETHERNET: ");
exit(0);
@@ -473,15 +477,15 @@ int eth_get_dev_conf_udp(openair0_device *device) {
device->openair0_cfg=(openair0_config_t *)msg;
/* get remote ip address and port */
/* inet_ntop(AF_INET, &(dest_addr[Mod_id].sin_addr), str1, INET_ADDRSTRLEN); */
/* device->openair0_cfg->remote_port =ntohs(dest_addr[Mod_id].sin_port); */
/* inet_ntop(AF_INET, &(eth->udp.dest_addr.sin_addr), str1, INET_ADDRSTRLEN); */
/* device->openair0_cfg->remote_port =ntohs(eth->udp.dest_addr.sin_port); */
/* device->openair0_cfg->remote_addr =str1; */
/* /\* restore local ip address and port *\/ */
/* inet_ntop(AF_INET, &(local_addr[Mod_id].sin_addr), str, INET_ADDRSTRLEN); */
/* device->openair0_cfg->my_port =ntohs(local_addr[Mod_id].sin_port); */
/* inet_ntop(AF_INET, &(eth->udp.local_addr.sin_addr), str, INET_ADDRSTRLEN); */
/* device->openair0_cfg->my_port =ntohs(eth->udp.local_addr.sin_port); */
/* device->openair0_cfg->my_addr =str; */
/* printf("[RRH] mod_%d socket %d connected to BBU %s:%d %s:%d\n", Mod_id, eth->sockfd[Mod_id],str1, device->openair0_cfg->remote_port, str, device->openair0_cfg->my_port); */
/* printf("[RRH] mod_%d socket %d connected to BBU %s:%d %s:%d\n", Mod_id, eth->sockfd,str1, device->openair0_cfg->remote_port, str, device->openair0_cfg->my_port); */
return 0;
}
@@ -52,9 +52,9 @@
#include "common_lib.h"
#include "ethernet_lib.h"
int num_devices_eth = 0;
struct sockaddr_in dest_addr[MAX_INST];
int dest_addr_len[MAX_INST];
//int num_devices_eth = 0;
//struct sockaddr_in dest_addr[MAX_INST];
//int dest_addr_len[MAX_INST];
int trx_eth_start(openair0_device *device) {
@@ -121,7 +121,7 @@ void trx_eth_end(openair0_device *device) {
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
/* destroys socket only for the processes that call the eth_end fuction-- shutdown() for beaking the pipe */
if ( close(eth->sockfd[Mod_id]) <0 ) {
if ( close(eth->sockfd) <0 ) {
perror("ETHERNET: Failed to close socket");
exit(0);
} else {
@@ -137,10 +137,17 @@ int trx_eth_request(openair0_device *device, void *msg, ssize_t msg_len) {
eth_state_t *eth = (eth_state_t*)device->priv;
/* BBU sends a message to RRH */
if (sendto(eth->sockfd[Mod_id],msg,msg_len,0,(struct sockaddr *)&dest_addr[Mod_id],dest_addr_len[Mod_id])==-1) {
perror("ETHERNET: ");
exit(0);
}
if ((eth->flags == ETH_RAW_MODE) || (eth->flags == ETH_RAW_IF4p5_MODE))
if (sendto(eth->sockfd,msg,msg_len,0,(struct sockaddr *)&eth->raw.dest_addr,eth->raw.dest_addr_len)==-1) {
perror("ETHERNET: ");
exit(0);
}
else
if (sendto(eth->sockfd,msg,msg_len,0,(struct sockaddr *)&eth->udp.dest_addr,eth->udp.dest_addr_len)==-1) {
perror("ETHERNET: ");
exit(0);
}
return 0;
}
@@ -152,16 +159,33 @@ int trx_eth_reply(openair0_device *device, void *msg, ssize_t msg_len) {
int Mod_id = device->Mod_id;
/* RRH receives from BBU a message */
if (recvfrom(eth->sockfd[Mod_id],
msg,
msg_len,
0,
(struct sockaddr *)&dest_addr[Mod_id],
(socklen_t *)&dest_addr_len[Mod_id])==-1) {
perror("ETHERNET: ");
exit(0);
}
if ((eth->flags == ETH_RAW_MODE) || (eth->flags == ETH_RAW_IF4p5_MODE)) {
if (recvfrom(eth->sockfd,
msg,
msg_len,
0,
(struct sockaddr *)&eth->raw.dest_addr,
(socklen_t *)&eth->raw.dest_addr_len)==-1) {
perror("ETHERNET: ");
exit(0);
}
}
else {
if (recvfrom(eth->sockfd,
msg,
msg_len,
0,
(struct sockaddr *)&eth->udp.dest_addr,
(socklen_t *)&eth->udp.dest_addr_len)==-1) {
perror("ETHERNET: ");
exit(0);
}
}
return 0;
}
@@ -204,7 +228,7 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
/****************** socket level options ************************/
switch(option) {
case SND_BUF_SIZE: /* transmit socket buffer size */
if (setsockopt(eth->sockfd[Mod_id],
if (setsockopt(eth->sockfd,
SOL_SOCKET,
SO_SNDBUF,
&value,sizeof(value))) {
@@ -215,7 +239,7 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
break;
case RCV_BUF_SIZE: /* receive socket buffer size */
if (setsockopt(eth->sockfd[Mod_id],
if (setsockopt(eth->sockfd,
SOL_SOCKET,
SO_RCVBUF,
&value,sizeof(value))) {
@@ -228,7 +252,7 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
case RCV_TIMEOUT:
timeout.tv_sec = value/1000000;
timeout.tv_usec = value%1000000;//less than rt_period?
if (setsockopt(eth->sockfd[Mod_id],
if (setsockopt(eth->sockfd,
SOL_SOCKET,
SO_RCVTIMEO,
(char *)&timeout,sizeof(timeout))) {
@@ -241,7 +265,7 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
case SND_TIMEOUT:
timeout.tv_sec = value/1000000000;
timeout.tv_usec = value%1000000000;//less than rt_period?
if (setsockopt(eth->sockfd[Mod_id],
if (setsockopt(eth->sockfd,
SOL_SOCKET,
SO_SNDTIMEO,
(char *)&timeout,sizeof(timeout))) {
@@ -257,7 +281,7 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name,eth->if_name[Mod_id], sizeof(ifr.ifr_name));
ifr.ifr_mtu =value;
if (ioctl(eth->sockfd[Mod_id],SIOCSIFMTU,(caddr_t)&ifr) < 0 )
if (ioctl(eth->sockfd,SIOCSIFMTU,(caddr_t)&ifr) < 0 )
perror ("[ETHERNET] Can't set the MTU");
else
printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name[Mod_id],ifr.ifr_mtu);
@@ -267,7 +291,7 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name,eth->if_name[Mod_id], sizeof(ifr.ifr_name));
ifr.ifr_qlen =value;
if (ioctl(eth->sockfd[Mod_id],SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 )
if (ioctl(eth->sockfd,SIOCSIFTXQLEN,(caddr_t)&ifr) < 0 )
perror ("[ETHERNET] Can't set the txqueuelen");
else
printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name[Mod_id],ifr.ifr_qlen);
@@ -351,7 +375,7 @@ int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth
}
printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == BBU_HOST) ? "BBU": "RRH"));
device->Mod_id = num_devices_eth++;
device->Mod_id = 0;//num_devices_eth++;
device->transp_type = ETHERNET_TP;
device->trx_start_func = trx_eth_start;
device->trx_request_func = trx_eth_request;