Commit db8c2a05 authored by Raymond Knopp's avatar Raymond Knopp

update of ETHERNET interfaces (removal of global variables).

parent 5affbe38
......@@ -54,16 +54,14 @@
#define DEBUG 0
struct sockaddr_ll dest_addr[MAX_INST];
struct sockaddr_ll local_addr[MAX_INST];
int addr_len[MAX_INST];
struct ifreq if_index[MAX_INST];
//struct sockaddr_ll dest_addr[MAX_INST];
//struct sockaddr_ll local_addr[MAX_INST];
//int addr_len[MAX_INST];
//struct ifreq if_index[MAX_INST];
int eth_socket_init_raw(openair0_device *device) {
int i = 0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
const char *local_mac, *remote_mac;
int sock_dom=0;
int sock_type=0;
......@@ -85,30 +83,29 @@ int eth_socket_init_raw(openair0_device *device) {
sock_dom=AF_PACKET;
sock_type=SOCK_RAW;
sock_proto=IPPROTO_RAW;
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 RAW socket");
exit(0);
}
/* initialize destination address */
for (i=0; i< MAX_INST; i++) {
bzero((void *)&(local_addr[i]), sizeof(struct sockaddr_ll));
bzero((void *)&(if_index[i]), sizeof(struct ifreq));
}
bzero((void *)&(eth->local_addr_ll), sizeof(struct sockaddr_ll));
bzero((void *)&(eth->if_index), sizeof(struct ifreq));
/* Get the index of the interface to send on */
strcpy(if_index[Mod_id].ifr_name,eth->if_name[Mod_id]);
if (ioctl(eth->sockfd[Mod_id], SIOCGIFINDEX, &(if_index[Mod_id])) < 0)
strcpy(eth->if_index.ifr_name,eth->if_name);
if (ioctl(eth->sockfd, SIOCGIFINDEX, &(eth->if_index)) < 0)
perror("SIOCGIFINDEX");
local_addr[Mod_id].sll_family = AF_PACKET;
local_addr[Mod_id].sll_ifindex = if_index[Mod_id].ifr_ifindex;
eth->local_addr_ll.sll_family = AF_PACKET;
eth->local_addr_ll.sll_ifindex = eth->if_index.ifr_ifindex;
/* hear traffic from specific protocol*/
local_addr[Mod_id].sll_protocol = htons((short)device->openair0_cfg->my_port);
local_addr[Mod_id].sll_halen = ETH_ALEN;
local_addr[Mod_id].sll_pkttype = PACKET_OTHERHOST;
addr_len[Mod_id] = sizeof(struct sockaddr_ll);
eth->local_addr_ll.sll_protocol = htons((short)device->openair0_cfg->my_port);
eth->local_addr_ll.sll_halen = ETH_ALEN;
eth->local_addr_ll.sll_pkttype = PACKET_OTHERHOST;
eth->addr_len = sizeof(struct sockaddr_ll);
if (bind(eth->sockfd[Mod_id],(struct sockaddr *)&local_addr[Mod_id],addr_len[Mod_id])<0) {
if (bind(eth->sockfd,(struct sockaddr *)&eth->local_addr_ll,eth->addr_len)<0) {
perror("ETHERNET: Cannot bind to socket");
exit(0);
}
......@@ -121,7 +118,7 @@ int eth_socket_init_raw(openair0_device *device) {
} else {
eth->eh.ether_type = htons((short)device->openair0_cfg->my_port);
}
printf("[%s] binding mod_%d to hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"),Mod_id,eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5]);
printf("[%s] binding to hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"),eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5]);
return 0;
}
......@@ -131,7 +128,6 @@ int trx_eth_write_raw(openair0_device *device, openair0_timestamp timestamp, voi
int bytes_sent=0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
int sendto_flag =0;
int i=0;
//sendto_flag|=flags;
......@@ -164,7 +160,7 @@ int trx_eth_write_raw(openair0_device *device, openair0_timestamp timestamp, voi
bytes_sent);
#endif
/* Send packet */
bytes_sent += send(eth->sockfd[Mod_id],
bytes_sent += send(eth->sockfd,
buff2,
RAW_PACKET_SIZE_BYTES(nsamps),
sendto_flag);
......@@ -202,7 +198,6 @@ int trx_eth_write_raw_IF4p5(openair0_device *device, openair0_timestamp timestam
int bytes_sent = 0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
ssize_t packet_size;
......@@ -221,7 +216,7 @@ int trx_eth_write_raw_IF4p5(openair0_device *device, openair0_timestamp timestam
memcpy(buff[0], (void*)&eth->eh, MAC_HEADER_SIZE_BYTES);
bytes_sent = send(eth->sockfd[Mod_id],
bytes_sent = send(eth->sockfd,
buff[0],
packet_size,
0);
......@@ -245,7 +240,6 @@ int trx_eth_read_raw(openair0_device *device, openair0_timestamp *timestamp, voi
int bytes_received=0;
int i=0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
int rcvfrom_flag =0;
eth->rx_nsamps=nsamps;
......@@ -263,7 +257,7 @@ int trx_eth_read_raw(openair0_device *device, openair0_timestamp *timestamp, voi
bytes_received=0;
while(bytes_received < RAW_PACKET_SIZE_BYTES(nsamps)) {
bytes_received +=recv(eth->sockfd[Mod_id],
bytes_received +=recv(eth->sockfd,
buff2,
RAW_PACKET_SIZE_BYTES(nsamps),
rcvfrom_flag);
......@@ -306,13 +300,15 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
int nblocks = nsamps;
int bytes_received=0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
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);
#endif
bytes_received = recv(eth->sockfd[Mod_id],
bytes_received = recv(eth->sockfd,
buff[0],
packet_size,
MSG_PEEK);
......@@ -321,7 +317,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) {
......@@ -334,7 +335,7 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
while(bytes_received < packet_size) {
bytes_received = recv(eth->sockfd[Mod_id],
bytes_received = recv(eth->sockfd,
buff[0],
packet_size,
0);
......@@ -356,7 +357,6 @@ int trx_eth_read_raw_IF4p5(openair0_device *device, openair0_timestamp *timestam
int eth_set_dev_conf_raw(openair0_device *device) {
int Mod_id = device->Mod_id;
eth_state_t *eth = (eth_state_t*)device->priv;
void *msg;
ssize_t msg_len;
......@@ -372,7 +372,7 @@ int eth_set_dev_conf_raw(openair0_device *device) {
memcpy(msg,(void*)&eth->eh,MAC_HEADER_SIZE_BYTES);
memcpy((msg+MAC_HEADER_SIZE_BYTES),(void*)device->openair0_cfg,sizeof(openair0_config_t));
if (send(eth->sockfd[Mod_id],
if (send(eth->sockfd,
msg,
msg_len,
0)==-1) {
......@@ -388,7 +388,6 @@ int eth_set_dev_conf_raw(openair0_device *device) {
int eth_set_dev_conf_raw_IF4p5(openair0_device *device) {
// use for cc_id info
int Mod_id = device->Mod_id;
eth_state_t *eth = (eth_state_t*)device->priv;
void *msg;
ssize_t msg_len;
......@@ -404,7 +403,7 @@ int eth_set_dev_conf_raw_IF4p5(openair0_device *device) {
memcpy(msg,(void*)&eth->eh,MAC_HEADER_SIZE_BYTES);
memcpy((msg+MAC_HEADER_SIZE_BYTES),(void*)device->openair0_cfg,sizeof(openair0_config_t));
if (send(eth->sockfd[Mod_id],
if (send(eth->sockfd,
msg,
msg_len,
0)==-1) {
......@@ -419,7 +418,6 @@ int eth_set_dev_conf_raw_IF4p5(openair0_device *device) {
int eth_get_dev_conf_raw(openair0_device *device) {
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
void *msg;
ssize_t msg_len;
......@@ -427,7 +425,7 @@ int eth_get_dev_conf_raw(openair0_device *device) {
msg_len = MAC_HEADER_SIZE_BYTES + sizeof(openair0_config_t);
/* RRH receives from BBU openair0_config_t */
if (recv(eth->sockfd[Mod_id],
if (recv(eth->sockfd,
msg,
msg_len,
0)==-1) {
......@@ -439,7 +437,7 @@ int eth_get_dev_conf_raw(openair0_device *device) {
memcpy(eth->eh.ether_dhost,(msg+ETH_ALEN),ETH_ALEN);
//memcpy((void*)&device->openair0_cfg,(msg + MAC_HEADER_SIZE_BYTES), sizeof(openair0_config_t));
device->openair0_cfg=(openair0_config_t *)(msg + MAC_HEADER_SIZE_BYTES);
printf("[%s] binding mod_%d to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"),Mod_id,eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5],eth->eh.ether_dhost[0],eth->eh.ether_dhost[1],eth->eh.ether_dhost[2],eth->eh.ether_dhost[3],eth->eh.ether_dhost[4],eth->eh.ether_dhost[5]);
printf("[%s] binding mod to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"),eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5],eth->eh.ether_dhost[0],eth->eh.ether_dhost[1],eth->eh.ether_dhost[2],eth->eh.ether_dhost[3],eth->eh.ether_dhost[4],eth->eh.ether_dhost[5]);
return 0;
}
......@@ -449,7 +447,6 @@ int eth_get_dev_conf_raw_IF4p5(openair0_device *device) {
// use for cc_id info
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
void *msg;
ssize_t msg_len;
......@@ -457,7 +454,7 @@ int eth_get_dev_conf_raw_IF4p5(openair0_device *device) {
msg_len = MAC_HEADER_SIZE_BYTES + sizeof(openair0_config_t);
/* RRH receives from BBU openair0_config_t */
if (recv(eth->sockfd[Mod_id],
if (recv(eth->sockfd,
msg,
msg_len,
0)==-1) {
......@@ -469,7 +466,7 @@ int eth_get_dev_conf_raw_IF4p5(openair0_device *device) {
memcpy(eth->eh.ether_dhost,(msg+ETH_ALEN),ETH_ALEN);
//memcpy((void*)&device->openair0_cfg,(msg + MAC_HEADER_SIZE_BYTES), sizeof(openair0_config_t));
//device->openair0_cfg=(openair0_config_t *)(msg + MAC_HEADER_SIZE_BYTES);
printf("[%s] binding mod_%d to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"),Mod_id,eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5],eth->eh.ether_dhost[0],eth->eh.ether_dhost[1],eth->eh.ether_dhost[2],eth->eh.ether_dhost[3],eth->eh.ether_dhost[4],eth->eh.ether_dhost[5]);
printf("[%s] binding mod to hardware address %x:%x:%x:%x:%x:%x hardware address %x:%x:%x:%x:%x:%x\n",((device->host_type == BBU_HOST) ? "BBU": "RRH"),eth->eh.ether_shost[0],eth->eh.ether_shost[1],eth->eh.ether_shost[2],eth->eh.ether_shost[3],eth->eh.ether_shost[4],eth->eh.ether_shost[5],eth->eh.ether_dhost[0],eth->eh.ether_dhost[1],eth->eh.ether_dhost[2],eth->eh.ether_dhost[3],eth->eh.ether_dhost[4],eth->eh.ether_dhost[5]);
return 0;
}
......@@ -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;
......@@ -65,9 +65,7 @@ uint16_t pck_seq_num_prev=0;
int eth_socket_init_udp(openair0_device *device) {
int i = 0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
char str_local[INET_ADDRSTRLEN];
char str_remote[INET_ADDRSTRLEN];
const char *local_ip, *remote_ip;
......@@ -96,43 +94,42 @@ 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);
}
/* initialize addresses */
for (i=0; i< MAX_INST; i++) {
bzero((void *)&(dest_addr[i]), sizeof(dest_addr[i]));
bzero((void *)&(local_addr[i]), sizeof(local_addr[i]));
}
bzero((void *)&(eth->dest_addr), sizeof(eth->dest_addr));
bzero((void *)&(eth->local_addr), sizeof(eth->local_addr));
addr_len[Mod_id] = sizeof(struct sockaddr_in);
eth->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->dest_addr.sin_family = AF_INET;
inet_pton(AF_INET,remote_ip,&(eth->dest_addr.sin_addr.s_addr));
eth->dest_addr.sin_port=htons(remote_port);
inet_ntop(AF_INET, &(eth->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);
eth->local_addr.sin_family = AF_INET;
inet_pton(AF_INET,local_ip,&(eth->local_addr.sin_addr.s_addr));
eth->local_addr.sin_port=htons(local_port);
inet_ntop(AF_INET, &(eth->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->local_addr,eth->addr_len)<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 to %s:%d\n","RRH",str_local,ntohs(eth->local_addr.sin_port));
}
return 0;
......@@ -144,8 +141,7 @@ int trx_eth_read_udp_IF4p5(openair0_device *device, openair0_timestamp *timestam
int nblocks = nsamps;
int bytes_received=-1;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
ssize_t packet_size = sizeof_IF4p5_header_t;
IF4p5_header_t *test_header = (IF4p5_header_t*)(buff[0]);
......@@ -155,12 +151,12 @@ 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],
(socklen_t *)&addr_len[Mod_id]);
(struct sockaddr *)&eth->dest_addr,
(socklen_t *)&eth->addr_len);
if (bytes_received ==-1) {
eth->num_rx_errors++;
if (errno == EAGAIN) {
......@@ -206,7 +202,6 @@ int trx_eth_write_udp_IF4p5(openair0_device *device, openair0_timestamp timestam
int bytes_sent = 0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
ssize_t packet_size;
......@@ -223,12 +218,12 @@ 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],
addr_len[Mod_id]);
(struct sockaddr*)&eth->dest_addr,
eth->addr_len);
if (bytes_sent == -1) {
eth->num_tx_errors++;
......@@ -246,7 +241,6 @@ int trx_eth_write_udp(openair0_device *device, openair0_timestamp timestamp, voi
int bytes_sent=0;
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
int sendto_flag =0;
int i=0;
//sendto_flag|=flags;
......@@ -280,12 +274,12 @@ 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],
addr_len[Mod_id]);
(struct sockaddr*)&eth->dest_addr,
eth->addr_len);
if ( bytes_sent == -1) {
eth->num_tx_errors++;
......@@ -321,7 +315,6 @@ int trx_eth_read_udp(openair0_device *device, openair0_timestamp *timestamp, voi
int bytes_received=0;
eth_state_t *eth = (eth_state_t*)device->priv;
// openair0_timestamp prev_timestamp = -1;
int Mod_id = device->Mod_id;
int rcvfrom_flag =0;
int block_cnt=0;
int again_cnt=0;
......@@ -350,12 +343,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->dest_addr,
(socklen_t *)&eth->addr_len);
if (bytes_received ==-1) {
eth->num_rx_errors++;
......@@ -401,7 +394,7 @@ int trx_eth_read_udp(openair0_device *device, openair0_timestamp *timestamp, voi
/* get the packet sequence number from packet's header */
pck_seq_num_cur = *(uint16_t *)buff2;
//printf("cur=%d prev=%d buff=%d\n",pck_seq_num_cur,pck_seq_num_prev,*(uint16_t *)(buff2));
if ( ( pck_seq_num_cur != (pck_seq_num_prev + 1) ) && !((pck_seq_num_prev==MAX_PACKET_SEQ_NUM(nsamps,device->openair0_cfg->samples_per_frame)) && (pck_seq_num_cur==1 )) && !((pck_seq_num_prev==1) && (pck_seq_num_cur==1))) {
if ( ( pck_seq_num_cur != (pck_seq_num_prev + 1) ) && !((pck_seq_num_prev==MAX_PACKET_SEQ_NUM(nsamps,device->openair0_cfg->samples_per_frame)) && (pck_seq_num_cur==1 )) && !((pck_seq_num_prev==1) && (pck_seq_num_cur==1))) {
printf("out of order packet received1! %d|%d|%d\n",pck_seq_num_cur,pck_seq_num_prev,(int)*timestamp);
}
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_RX_SEQ_NUM,pck_seq_num_cur);
......@@ -424,7 +417,6 @@ int trx_eth_read_udp(openair0_device *device, openair0_timestamp *timestamp, voi
int eth_set_dev_conf_udp(openair0_device *device) {
int Mod_id = device->Mod_id;
eth_state_t *eth = (eth_state_t*)device->priv;
void *msg;
ssize_t msg_len;
......@@ -437,9 +429,10 @@ 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);
if (sendto(eth->sockfd[Mod_id],msg,msg_len,0,(struct sockaddr *)&dest_addr[Mod_id],addr_len[Mod_id])==-1) {
perror("ETHERNET: ");
if (sendto(eth->sockfd,msg,msg_len,0,(struct sockaddr *)&eth->dest_addr,eth->addr_len)==-1) {
perror("ETHERNET: sendto conf_udp");
printf("addr_len : %d, msg_len %d\n",eth->addr_len,msg_len);
exit(0);
}
......@@ -449,7 +442,6 @@ int eth_set_dev_conf_udp(openair0_device *device) {
int eth_get_dev_conf_udp(openair0_device *device) {
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
char str1[INET_ADDRSTRLEN],str[INET_ADDRSTRLEN];
void *msg;
ssize_t msg_len;
......@@ -457,31 +449,31 @@ 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->local_addr.sin_addr), str, INET_ADDRSTRLEN);
inet_ntop(AF_INET, &(eth->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],
(socklen_t *)&addr_len[Mod_id])==-1) {
perror("ETHERNET: ");
(struct sockaddr *)&eth->dest_addr,
(socklen_t *)&eth->addr_len)==-1) {
perror("ETHERNET: recv_from conf_udp");
exit(0);
}
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->dest_addr.sin_addr), str1, INET_ADDRSTRLEN); */
/* device->openair0_cfg->remote_port =ntohs(eth->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->local_addr.sin_addr), str, INET_ADDRSTRLEN); */
/* device->openair0_cfg->my_port =ntohs(eth->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) {
......@@ -119,13 +119,12 @@ int trx_eth_start(openair0_device *device) {
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 {
printf("[%s] socket for mod_id %d has been successfully closed.\n",(device->host_type == BBU_HOST)? "BBU":"RRH",Mod_id);
printf("[%s] socket has been successfully closed.\n",(device->host_type == BBU_HOST)? "BBU":"RRH");
}
}
......@@ -133,15 +132,15 @@ void trx_eth_end(openair0_device *device) {
int trx_eth_request(openair0_device *device, void *msg, ssize_t msg_len) {
int Mod_id = device->Mod_id;
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) {
if (sendto(eth->sockfd,msg,msg_len,0,(struct sockaddr *)&eth->dest_addr,eth->addr_len)==-1) {
perror("ETHERNET: ");
exit(0);
}
return 0;
}
......@@ -149,19 +148,21 @@ int trx_eth_request(openair0_device *device, void *msg, ssize_t msg_len) {
int trx_eth_reply(openair0_device *device, void *msg, ssize_t msg_len) {
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id = device->Mod_id;
/* RRH receives from BBU a message */
if (recvfrom(eth->sockfd[Mod_id],
if (recvfrom(eth->sockfd,
msg,
msg_len,
0,
(struct sockaddr *)&dest_addr[Mod_id],
(socklen_t *)&dest_addr_len[Mod_id])==-1) {
perror("ETHERNET: ");
exit(0);
}
(struct sockaddr *)&eth->dest_addr,
(socklen_t *)&eth->addr_len)==-1) {
perror("ETHERNET: recv_from in trx_eth_reply ");
exit(0);
}
return 0;
}
......@@ -191,7 +192,6 @@ int trx_eth_reset_stats(openair0_device* device) {
int ethernet_tune(openair0_device *device, unsigned int option, int value) {
eth_state_t *eth = (eth_state_t*)device->priv;
int Mod_id=device->Mod_id;
struct timeval timeout;
struct ifreq ifr;
char system_cmd[256];
......@@ -204,7 +204,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 +215,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 +228,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 +241,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))) {
......@@ -255,27 +255,27 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
/******************* interface level options *************************/
case MTU_SIZE: /* change MTU of the eth interface */
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name,eth->if_name[Mod_id], sizeof(ifr.ifr_name));
strncpy(ifr.ifr_name,eth->if_name, 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);
printf("[ETHERNET] %s MTU size has changed to %d\n",eth->if_name,ifr.ifr_mtu);
break;
case TX_Q_LEN: /* change TX queue length of eth interface */
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name,eth->if_name[Mod_id], sizeof(ifr.ifr_name));
strncpy(ifr.ifr_name,eth->if_name, 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);
printf("[ETHERNET] %s txqueuelen size has changed to %d\n",eth->if_name,ifr.ifr_qlen);
break;
/******************* device level options *************************/
case COALESCE_PAR:
ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name[Mod_id],value);
ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -C %s rx-usecs %d",eth->if_name,value);
if (ret > 0) {
ret=system(system_cmd);
if (ret == -1) {
......@@ -290,8 +290,8 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
break;
case PAUSE_PAR:
if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name[Mod_id]);
else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name[Mod_id]);
if (value==1) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg off rx off tx off",eth->if_name);
else if (value==0) ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -A %s autoneg on rx on tx on",eth->if_name);
else break;
if (ret > 0) {
ret=system(system_cmd);
......@@ -307,7 +307,7 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
break;
case RING_PAR:
ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name[Mod_id],value);
ret=snprintf(system_cmd,sizeof(system_cmd),"ethtool -G %s val %d",eth->if_name,value);
if (ret > 0) {
ret=system(system_cmd);
if (ret == -1) {
......@@ -351,7 +351,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;
......@@ -383,7 +383,7 @@ int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth
//device->trx_read_func = trx_eth_read_udp_IF4p5;
}
eth->if_name[device->Mod_id] = eth_params->local_if_name;
eth->if_name = eth_params->local_if_name;
device->priv = eth;
/* device specific */
......
......@@ -62,11 +62,23 @@
typedef struct {
/*!\brief socket file desc */
int sockfd[MAX_INST];
int sockfd;
/*!\brief interface name */
char *if_name[MAX_INST];
char *if_name;
/*!\brief buffer size */
unsigned int buffer_size;
/*!\brief destination address for UDP socket*/
struct sockaddr_in dest_addr;
/*!\brief local address for UDP socket*/
struct sockaddr_in local_addr;
/*!\brief address length for both UDP and RAW socket*/
int addr_len;
/*!\brief destination address for RAW socket*/
struct sockaddr_ll dest_addr_ll;
/*!\brief local address for RAW socket*/
struct sockaddr_ll local_addr_ll;
/*!\brief inteface index for RAW socket*/
struct ifreq if_index;
/*!\brief timeout ms */
unsigned int rx_timeout_ms;
/*!\brief timeout ms */
......
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