Commit b39e0175 authored by Aikaterini's avatar Aikaterini

update ethernet library wrt changes in openair0_device - add packet sequence number

parent fafee950
......@@ -52,7 +52,7 @@
#include "common_lib.h"
#include "ethernet_lib.h"
#define DEBUG 1
#define DEBUG 0
struct sockaddr_ll dest_addr[MAX_INST];
struct sockaddr_ll local_addr[MAX_INST];
......@@ -275,7 +275,7 @@ int eth_set_dev_conf_raw(openair0_device *device) {
memcpy(msg,(void*)&eh,MAC_HEADER_SIZE_BYTES);
memcpy((msg+MAC_HEADER_SIZE_BYTES),(void*)&device->openair0_cfg,sizeof(openair0_config_t));
memcpy((msg+MAC_HEADER_SIZE_BYTES),(void*)device->openair0_cfg,sizeof(openair0_config_t));
if (send(eth->sockfd[Mod_id],
msg,
......@@ -311,7 +311,8 @@ int eth_get_dev_conf_raw(openair0_device *device) {
/* RRH stores the remote MAC address */
memcpy(eh.ether_dhost,(msg+ETH_ALEN),ETH_ALEN);
memcpy((void*)&device->openair0_cfg,(msg + MAC_HEADER_SIZE_BYTES), sizeof(openair0_config_t));
//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,eh.ether_shost[0],eh.ether_shost[1],eh.ether_shost[2],eh.ether_shost[3],eh.ether_shost[4],eh.ether_shost[5],eh.ether_dhost[0],eh.ether_dhost[1],eh.ether_dhost[2],eh.ether_dhost[3],eh.ether_dhost[4],eh.ether_dhost[5]);
return 0;
......
......@@ -48,6 +48,7 @@
#include <netinet/ether.h>
#include <unistd.h>
#include <errno.h>
#include "vcd_signal_dumper.h"
#include "common_lib.h"
#include "ethernet_lib.h"
......@@ -58,6 +59,10 @@ struct sockaddr_in local_addr[MAX_INST];
int addr_len[MAX_INST];
uint16_t pck_seq_num = 1;
uint16_t pck_seq_num_cur=0;
uint16_t pck_seq_num_prev=0;
int eth_socket_init_udp(openair0_device *device) {
int i = 0;
......@@ -122,9 +127,6 @@ int addr_len[MAX_INST];
exit(0);
}
/* apply additional configuration */
//ethernet_tune (device,MTU_SIZE,UDP_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet));
/* want to receive -> so bind */
if (bind(eth->sockfd[Mod_id],(struct sockaddr *)&local_addr[Mod_id],addr_len[Mod_id])<0) {
perror("ETHERNET: Cannot bind to socket");
......@@ -133,8 +135,6 @@ int addr_len[MAX_INST];
printf("[%s] binding mod_%d to %s:%d\n","RRH",Mod_id,str_local,ntohs(local_addr[Mod_id].sin_port));
}
printf("ssssssssssssssss\n");
return 0;
}
......@@ -159,10 +159,15 @@ int trx_eth_write_udp(openair0_device *device, openair0_timestamp timestamp, voi
bytes_sent = 0;
*(int16_t *)(buff2 + sizeof(int16_t))=1+(i<<1);
/* constract application header */
// eth->pck_header.seq_num = pck_seq_num;
//eth->pck_header.antenna_id = 1+(i<<1);
//eth->pck_header.timestamp = timestamp;
*(uint16_t *)buff2 = pck_seq_num;
*(uint16_t *)(buff2 + sizeof(uint16_t)) = 1+(i<<1);
*(openair0_timestamp *)(buff2 + sizeof(int32_t)) = timestamp;
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_TX_SEQ_NUM, pck_seq_num);
while(bytes_sent < UDP_PACKET_SIZE_BYTES(nsamps)) {
#if DEBUG
printf("------- TX ------: buff2 current position=%d remaining_bytes=%d bytes_sent=%d \n",
......@@ -193,6 +198,8 @@ int trx_eth_write_udp(openair0_device *device, openair0_timestamp timestamp, voi
#endif
eth->tx_actual_nsamps=bytes_sent>>2;
eth->tx_count++;
pck_seq_num++;
if ( pck_seq_num > MAX_PACKET_SEQ_NUM(nsamps,76800) ) pck_seq_num = 1;
}
}
/* tx buffer values restored */
......@@ -278,19 +285,28 @@ int trx_eth_read_udp(openair0_device *device, openair0_timestamp *timestamp, voi
bytes_received);
dump_packet((device->host_type == BBU_HOST)? "BBU":"RRH", buff2, UDP_PACKET_SIZE_BYTES(nsamps),RX_FLAG);
#endif
/* store the timestamp value from packet's header */
if (prev_timestamp == -1) {
prev_timestamp = *(openair0_timestamp *)(buff2 + sizeof(int32_t));
*timestamp = *(openair0_timestamp *)(buff2 + sizeof(int32_t));
/* store the sequence number of the previous packet received */
if (pck_seq_num_cur == 0) {
pck_seq_num_prev = *(uint16_t *)buff2;
} else {
prev_timestamp =timestamp;
pck_seq_num_prev = pck_seq_num_cur;
}
/* store the timestamp value from packet's header */
*timestamp = *(openair0_timestamp *)(buff2 + sizeof(int32_t));
eth->rx_actual_nsamps=bytes_received>>2;
eth->rx_count++;
}
}
/* 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==75) && (pck_seq_num_cur==1 ))){
printf("out of order packet received1! %d|%d|%d\n",pck_seq_num_cur,pck_seq_num_prev, *timestamp);
}
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_RX_SEQ_NUM,pck_seq_num_cur);
VCD_SIGNAL_DUMPER_DUMP_VARIABLE_BY_NAME( VCD_SIGNAL_DUMPER_VARIABLES_RX_SEQ_NUM_PRV,pck_seq_num_prev);
eth->rx_actual_nsamps=bytes_received>>2;
eth->rx_count++;
}
}
/* tx buffer values restored */
*(int32_t *)buff2 = temp0;
*(openair0_timestamp *)(buff2 + sizeof(int32_t)) = temp1;
......@@ -316,7 +332,7 @@ 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);
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: ");
......@@ -338,7 +354,7 @@ int eth_get_dev_conf_udp(openair0_device *device) {
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, &(dest_addr[Mod_id].sin_addr), str1, INET_ADDRSTRLEN);
/* RRH receives from BBU openair0_config_t */
if (recvfrom(eth->sockfd[Mod_id],
......@@ -350,7 +366,7 @@ int eth_get_dev_conf_udp(openair0_device *device) {
perror("ETHERNET: ");
exit(0);
}
memcpy((void*)&device->openair0_cfg,msg,msg_len);
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); */
......
......@@ -82,9 +82,12 @@ int trx_eth_start(openair0_device *device) {
if(eth_get_dev_conf_udp(device)!=0) return -1;
}
/* adjust MTU wrt number of samples per packet */
if(ethernet_tune (device,MTU_SIZE,UDP_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0) return -1;
//if(ethernet_tune (device,MTU_SIZE,UDP_PACKET_SIZE_BYTES(device->openair0_cfg->samples_per_packet))!=0) return -1;
}
/* apply additional configuration */
if(ethernet_tune (device, SND_BUF_SIZE,2000000000)!=0) return -1;
if(ethernet_tune (device, RCV_BUF_SIZE,2000000000)!=0) return -1;
return 0;
}
......@@ -335,13 +338,17 @@ int ethernet_tune(openair0_device *device, unsigned int option, int value) {
int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, char *cfgfile) {
int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, eth_params_t * eth_params ) {
eth_state_t *eth = (eth_state_t*)malloc(sizeof(eth_state_t));
memset(eth, 0, sizeof(eth_state_t));
eth->flags = ETH_RAW_MODE;
if (eth_params->transp_preference == 1) {
eth->flags = ETH_RAW_MODE;
} else {
eth->flags = ETH_UDP_MODE;
}
printf("[ETHERNET]: Initializing openair0_device for %s ...\n", ((device->host_type == BBU_HOST) ? "BBU": "RRH"));
device->Mod_id = num_devices_eth++;
device->transp_type = ETHERNET_TP;
......@@ -362,13 +369,53 @@ int transport_init(openair0_device *device, openair0_config_t *openair0_cfg, cha
device->trx_write_func = trx_eth_write_udp;
device->trx_read_func = trx_eth_read_udp;
}
/*hardcoded!!!!*/
eth->if_name[device->Mod_id] = "eth0";
device->priv = eth;
openair0_cfg->iq_txshift = 5;
openair0_cfg->iq_rxrescale = 15;
memcpy((void*)device->openair0_cfg,(void*)openair0_cfg,sizeof(openair0_config_t));
eth->if_name[device->Mod_id] = eth_params->local_if_name;
device->priv = eth;
/* device specific */
openair0_cfg[0].iq_txshift = 5;
openair0_cfg[0].iq_rxrescale = 15;
openair0_cfg[0].txlaunch_wait = 0;
openair0_cfg[0].txlaunch_wait_slotcount = 0;
/* RRH does not have any information to make this configuration atm */
if (device->host_type == BBU_HOST) {
/*Note scheduling advance values valid only for case 7680000 */
switch ((int)openair0_cfg[0].sample_rate) {
case 30720000:
openair0_cfg[0].samples_per_packet = 4096;
openair0_cfg[0].tx_sample_advance = 0;
openair0_cfg[0].tx_scheduling_advance = 22*openair0_cfg[0].samples_per_packet;
break;
case 23040000:
openair0_cfg[0].samples_per_packet = 2048;
openair0_cfg[0].tx_sample_advance = 0;
openair0_cfg[0].tx_scheduling_advance = 16*openair0_cfg[0].samples_per_packet;
break;
case 15360000:
openair0_cfg[0].samples_per_packet = 2048;
openair0_cfg[0].tx_sample_advance = 0;
openair0_cfg[0].tx_scheduling_advance = 10*openair0_cfg[0].samples_per_packet;
break;
case 7680000:
openair0_cfg[0].samples_per_packet = 1024;
openair0_cfg[0].tx_sample_advance = 0;
openair0_cfg[0].tx_scheduling_advance = 10*openair0_cfg[0].samples_per_packet;
break;
case 1920000:
openair0_cfg[0].samples_per_packet = 256;
openair0_cfg[0].tx_sample_advance = 0;
openair0_cfg[0].tx_scheduling_advance = 16*openair0_cfg[0].samples_per_packet;
break;
default:
printf("Error: unknown sampling rate %f\n",openair0_cfg[0].sample_rate);
exit(-1);
break;
}
}
device->openair0_cfg=&openair0_cfg[0];
return 0;
}
......@@ -414,8 +461,7 @@ void dump_dev(openair0_device *device) {
device->openair0_cfg->tx_num_channels,device->openair0_cfg->rx_num_channels);
printf(" Running flags: %s %s %s\n",
((eth->flags & ETH_RAW_MODE) ? "RAW socket mode - ":""),
((eth->flags & ETH_UDP_MODE) ? "UDP socket mode - ":""),
((eth->flags & ETH_LOOP_MODE) ? "loopback mode - ":""));
((eth->flags & ETH_UDP_MODE) ? "UDP socket mode - ":""));
printf(" Number of iqs dumped when displaying packets: %i\n\n",eth->iqdumpcnt);
}
......
......@@ -53,33 +53,18 @@
#define DEFAULT_IF "lo"
#define ETH_RAW_MODE 1
#define ETH_UDP_MODE (1<<1)
#define ETH_LOOP_MODE (1<<2)
#define ETH_UDP_MODE 0
#define TX_FLAG 1
#define RX_FLAG 0
#define MAX_PACKET_SEQ_NUM(spp,spf) (spf/spp)
#define MAC_HEADER_SIZE_BYTES (sizeof(struct ether_header))
#define APP_HEADER_SIZE_BYTES (sizeof(int32_t) + sizeof(openair0_timestamp))
#define PAYLOAD_SIZE_BYTES(nsamps) (nsamps<<2)
#define UDP_PACKET_SIZE_BYTES(nsamps) (APP_HEADER_SIZE_BYTES + PAYLOAD_SIZE_BYTES(nsamps))
#define RAW_PACKET_SIZE_BYTES(nsamps) (APP_HEADER_SIZE_BYTES + MAC_HEADER_SIZE_BYTES + PAYLOAD_SIZE_BYTES(nsamps))
/*
#define RRH_DEST_MAC0 0x74
#define RRH_DEST_MAC1 0xd4
#define RRH_DEST_MAC2 0x35
#define RRH_DEST_MAC3 0xcc
#define RRH_DEST_MAC4 0x88
#define RRH_DEST_MAC5 0x45
#define BBU_DEST_MAC0 0xd4
#define BBU_DEST_MAC1 0xbe
#define BBU_DEST_MAC2 0xd9
#define BBU_DEST_MAC3 0x22
#define BBU_DEST_MAC4 0x0a
#define BBU_DEST_MAC5 0xac
*/
/*!\brief opaque ethernet data structure */
typedef struct {
......@@ -142,12 +127,12 @@ typedef struct {
/*!\brief packet header */
typedef struct {
/*!\brief packet sequence number max value=packets per frame*/
uint16_t seq_num ;
/*!\brief antenna port used to resynchronize */
uint16_t antenna_id;
/*!\brief packet's timestamp */
openair0_timestamp timestamp;
/*!\brief variable declared for alignment purposes (sample size=32 bit) */
int16_t not_used;
/*!\brief antenna port used to resynchronize */
int16_t antenna_id;
} header_t;
/*!\brief different options for ethernet tuning in socket and driver level */
......
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