Commit f255cff5 authored by Joanne Hugé's avatar Joanne Hugé

Fix seg fault, remove hardcoded packet sizes

parent c9e7e866
......@@ -51,9 +51,7 @@
//#define DEBUG // Enables / deactivates log_debug
//#define STAT_SHOW_COUNTERS
#define PPS_UPDATE_PERIOD INT64_C(1500000000)
#define TX_PACKET_SIZE 262
#define RX_MAX_PACKET_SIZE 262
#define TX_ECPRI_PACKET_SIZE (TX_PACKET_SIZE - 14)
#define MAX_PACKET_SIZE 1024
#define N_SAMPLES (32)
#define TRX_MAX_GROUP 1500
#define STAT_INT_LEN "8"
......@@ -416,44 +414,10 @@ static void log_exit(const char * section, const char * msg, ...) {
#define BURST_SIZE 16
#define TX_POOL_SIZE 16
int8_t tx_data[BURST_SIZE][TX_PACKET_SIZE];
#ifdef DPDK
#include "dpdk.c"
static void send_packets(int port) {
struct rte_mbuf * pkt[TX_POOL_SIZE];
struct rte_ether_hdr *eth_hdr;
uint16_t nb_tx = 0;
for(int i = 0; i < TX_POOL_SIZE; i++) {
int pkt_size;
pkt[i] = rte_pktmbuf_alloc(tx_mbuf_pool);
eth_hdr = rte_pktmbuf_mtod(pkt[i], struct rte_ether_hdr*);
if(port) {
eth_hdr->d_addr = s_addr;
eth_hdr->s_addr = d_addr;
} else {
eth_hdr->d_addr = d_addr;
eth_hdr->s_addr = s_addr;
}
eth_hdr->ether_type = htons(0xaefe);
memcpy(rte_pktmbuf_mtod_offset(pkt[i], uint8_t *, sizeof(struct rte_ether_hdr)), tx_data[i], TX_ECPRI_PACKET_SIZE);
pkt_size = TX_PACKET_SIZE;
pkt[i]->data_len = pkt_size;
pkt[i]->pkt_len = pkt_size;
}
while(nb_tx < TX_POOL_SIZE) {
int64_t x = TX_POOL_SIZE - nb_tx;
nb_tx += rte_eth_tx_burst(port, 0, pkt + nb_tx, x > BURST_SIZE ? BURST_SIZE : x);
}
/* Free any unsent packets. */
if (nb_tx < BURST_SIZE) {
uint16_t buf;
for (buf = nb_tx; buf < BURST_SIZE; buf++)
rte_pktmbuf_free(pkt[buf]);
log_exit("SEND_THREAD", "Sent %d packets instead of %d", nb_tx, BURST_SIZE);
}
}
/* DPDK */
......@@ -677,6 +641,8 @@ static void *recv_thread(void *p) {
}
}
if((pkt[i + k])->data_len != rx_rbuf.len)
log_error("RECV", "Packet data length (%d) != RX buffer len (%d)", pkt[i + k]->data_len, rx_rbuf.len);
memcpy(buf + i * rx_rbuf.len, rtebuf, rx_rbuf.len);
#else
//memcpy(buf + i * rx_rbuf.len, pkt_frame_full, rx_rbuf.len);
......@@ -720,12 +686,41 @@ static void *send_thread(void *p) {
for(int j = 0; j < nb_burst; j++) {
for(int k = 0; k < BURST_SIZE; k++) {
memcpy(tx_data[k], RBUF_READ0(tx_rbuf, uint8_t), tx_rbuf.len);
#ifdef DPDK
struct rte_mbuf * pkt[TX_POOL_SIZE];
struct rte_ether_hdr *eth_hdr;
uint16_t nb_tx = 0;
for(int i = 0; i < TX_POOL_SIZE; i++) {
int pkt_size;
pkt[i] = rte_pktmbuf_alloc(tx_mbuf_pool);
eth_hdr = rte_pktmbuf_mtod(pkt[i], struct rte_ether_hdr*);
if(port) {
eth_hdr->d_addr = s_addr;
eth_hdr->s_addr = d_addr;
} else {
eth_hdr->d_addr = d_addr;
eth_hdr->s_addr = s_addr;
}
eth_hdr->ether_type = htons(0xaefe);
memcpy(rte_pktmbuf_mtod_offset(pkt[i], uint8_t *, sizeof(struct rte_ether_hdr)), RBUF_READ0(tx_rbuf, uint8_t), 8 + s->tx_n_channel * 60);
rbuf_update_read_index(&tx_rbuf);
pkt_size = 22 + s->tx_n_channel * 60;
pkt[i]->data_len = pkt_size;
pkt[i]->pkt_len = pkt_size;
}
while(nb_tx < TX_POOL_SIZE) {
int64_t x = TX_POOL_SIZE - nb_tx;
nb_tx += rte_eth_tx_burst(port, 0, pkt + nb_tx, x > BURST_SIZE ? BURST_SIZE : x);
}
/* Free any unsent packets. */
if (nb_tx < BURST_SIZE) {
uint16_t buf;
for (buf = nb_tx; buf < BURST_SIZE; buf++)
rte_pktmbuf_free(pkt[buf]);
log_exit("SEND_THREAD", "Sent %d packets instead of %d", nb_tx, BURST_SIZE);
}
#ifdef DPDK
send_packets(0);
#else
for(int i = 0; i < 3000; i++)
asm("NOP");
......@@ -1204,7 +1199,7 @@ static int start_threads(TRXEcpriState * s) {
}
int startdpdk(TRXEcpriState * s) {
uint8_t ecpri_message[TX_ECPRI_PACKET_SIZE];
uint8_t ecpri_message[MAX_PACKET_SIZE];
int argc = 1;
int k = 1;
......@@ -1257,8 +1252,8 @@ int startdpdk(TRXEcpriState * s) {
init_counter(&sent_counter);
init_counter(&empty_encode_counter);
RBUF_INIT(rx_rbuf, "RX ring buffer", s->txrx_buf_size, RX_MAX_PACKET_SIZE + s->tdd_frame_start + s->timestamp_frames * sizeof(uint64_t), uint8_t);
RBUF_INIT(tx_rbuf, "TX ring buffer", s->txrx_buf_size, TX_ECPRI_PACKET_SIZE + s->tdd_frame_start + s->timestamp_frames * sizeof(uint64_t), uint8_t);
RBUF_INIT(rx_rbuf, "RX ring buffer", s->txrx_buf_size, s->rx_n_channel * 60 + 22 + s->tdd_frame_start + s->timestamp_frames * sizeof(uint64_t), uint8_t);
RBUF_INIT(tx_rbuf, "TX ring buffer", s->txrx_buf_size, s->tx_n_channel * 60 + 8 + s->tdd_frame_start + s->timestamp_frames * sizeof(uint64_t), uint8_t);
for(int i = 0; i < s->tx_n_channel; i++) {
char name[256];
sprintf(name, "TRXWrite Ring Buffer %d", i);
......@@ -1273,7 +1268,7 @@ int startdpdk(TRXEcpriState * s) {
RBUF_INIT(one_way_rbuf, "One-way ring buffer", 1024, 1, int64_t);
memset((uint8_t *) ecpri_message, 0, TX_ECPRI_PACKET_SIZE);
memset((uint8_t *) ecpri_message, 0, MAX_PACKET_SIZE);
#ifdef DPDK
if(sscanf((char *) s->re_mac, "%hhx:%hhx:%hhx:%hhx:%hhx:%hhx%*c",
......
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