Commit 610210c8 authored by Joanne Hugé's avatar Joanne Hugé

Update trx driver with DPDK

parent 48754dba
# SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation
CC=gcc -m64 -msse4.1 CC=gcc -m64 -msse4.1
CXX=g++ -m64 -msse4.1 CXX=g++ -m64 -msse4.1
CFLAGS=-O2 -fno-strict-aliasing CFLAGS=-O2 -fno-strict-aliasing -Wall -pedantic -std=gnu17
CFLAGS+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE CFLAGS+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
CFLAGS+=-MMD -g CFLAGS+=-MMD -g
CXXFLAGS=$(CFLAGS) CXXFLAGS=$(CFLAGS)
PROGS= trx_ecpri.so # binary name
APP = trx_ecpri_dpdk
LIB = lib$(APP).so
all: $(PROGS) # all source are stored in SRCS-y
SRCS-y := $(APP).c
clean: PKGCONF ?= pkg-config
rm -f $(PROGS) *.lo *~ *.d
# Build using pkg-config variables if possible
ifneq ($(shell $(PKGCONF) --exists libdpdk && echo 0),0)
$(error "no installation of DPDK found")
endif
all: $(LIB)
$(LIB): $(APP).o
$(CC) -shared $(LDFLAGS) $(LDFLAGS_SHARED) -o $@ $<
trx_ecpri.so: trx_ecpri.lo .PHONY: shared
$(CC) -shared $(LDFLAGS) -o $@ $< -lm shared: build/$(APP)-shared
ln -sf $(APP)-shared build/$(APP)
%.lo: %.c PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
$(CC) $(CFLAGS) -fpic -c -o $@ $< CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk) -lpthread -lm
-include $(wildcard *.d) CFLAGS += -DALLOW_EXPERIMENTAL_API
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
%.o: %.c
$(CC) $(CFLAGS) $(SRCS-y) -fpic -c -o $@
build:
@mkdir -p $@
.PHONY: clean
clean:
rm -rf build
rm -rf $(LIB)
rm -f *.o *.d *.so
# SPDX-License-Identifier: BSD-3-Clause # SPDX-License-Identifier: BSD-3-Clause
# Copyright(c) 2010-2014 Intel Corporation # Copyright(c) 2010-2014 Intel Corporation
CC=gcc -m64 -msse4.1
CXX=g++ -m64 -msse4.1
CFLAGS=-O2 -fno-strict-aliasing
CFLAGS+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
CFLAGS+=-MMD -g
CXXFLAGS=$(CFLAGS)
# binary name # binary name
APP = dpdk-recv-send APP = dpdk-recv-send
...@@ -15,29 +22,29 @@ $(error "no installation of DPDK found") ...@@ -15,29 +22,29 @@ $(error "no installation of DPDK found")
endif endif
all: shared all: shared
.PHONY: shared static .PHONY: shared
shared: build/$(APP)-shared shared: build/$(APP)-shared
ln -sf $(APP)-shared build/$(APP) ln -sf $(APP)-shared build/$(APP)
static: build/$(APP)-static
ln -sf $(APP)-static build/$(APP) dpdk-recv-send.so: dpdk-recv-send.o
$(CC) -shared $(LDFLAGS) $(LDFLAGS_SHARED) -o $@ $<
PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null) PC_FILE := $(shell $(PKGCONF) --path libdpdk 2>/dev/null)
CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk) CFLAGS += -O3 $(shell $(PKGCONF) --cflags libdpdk)
LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk) -lpthread LDFLAGS_SHARED = $(shell $(PKGCONF) --libs libdpdk) -lpthread -lm
LDFLAGS_STATIC = $(shell $(PKGCONF) --static --libs libdpdk)
CFLAGS += -DALLOW_EXPERIMENTAL_API CFLAGS += -DALLOW_EXPERIMENTAL_API
build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build build/$(APP)-shared: $(SRCS-y) Makefile $(PC_FILE) | build
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED) $(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_SHARED)
build/$(APP)-static: $(SRCS-y) Makefile $(PC_FILE) | build %.o: %.c
$(CC) $(CFLAGS) $(SRCS-y) -o $@ $(LDFLAGS) $(LDFLAGS_STATIC) $(CC) $(CFLAGS) $(SRCS-y) -fpic -c -o $@
build: build:
@mkdir -p $@ @mkdir -p $@
.PHONY: clean .PHONY: clean
clean: clean:
rm -f build/$(APP) build/$(APP)-static build/$(APP)-shared rm -rf build
test -d build && rmdir -p build || true rm -f *.o *.d *.so
#define _GNU_SOURCE /* See feature_test_macros(7) */ //#define _GNU_SOURCE /* See feature_test_macros(7) */
#include <arpa/inet.h> #include <arpa/inet.h>
#include <assert.h> #include <assert.h>
#include <errno.h> #include <errno.h>
...@@ -98,10 +98,9 @@ static int64_t calcdiff_ns(struct timespec t1, struct timespec t2) { ...@@ -98,10 +98,9 @@ static int64_t calcdiff_ns(struct timespec t1, struct timespec t2) {
return diff; return diff;
} }
#define DATA_SIZE 244
#define BURST_SIZE 16 #define BURST_SIZE 16
//#define NB_PACKETS (1 * 1000000)
#define NB_PACKETS 64
#define DATA_LEN 244
#define MEMPOOL_CACHE_SIZE 256 #define MEMPOOL_CACHE_SIZE 256
#define RTE_TEST_RX_DESC_DEFAULT 1024 #define RTE_TEST_RX_DESC_DEFAULT 1024
#define RTE_TEST_TX_DESC_DEFAULT 1024 #define RTE_TEST_TX_DESC_DEFAULT 1024
...@@ -110,8 +109,7 @@ static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT; ...@@ -110,8 +109,7 @@ static uint16_t nb_txd = RTE_TEST_TX_DESC_DEFAULT;
struct rte_mempool *mbuf_pool; struct rte_mempool *mbuf_pool;
struct rte_ether_addr s_addr = {{0xb8,0xce,0xf6,0x4b,0x00,0x22}}; struct rte_ether_addr s_addr = {{0xb8,0xce,0xf6,0x4b,0x00,0x22}};
struct rte_ether_addr d_addr = {{0xb8,0xce,0xf6,0x4b,0x00,0x23}}; struct rte_ether_addr d_addr = {{0xb8,0xce,0xf6,0x4b,0x00,0x23}};
uint8_t data[BURST_SIZE][DATA_LEN]; int8_t data[BURST_SIZE][DATA_SIZE];
static const struct rte_eth_conf port_conf_default = { static const struct rte_eth_conf port_conf_default = {
.rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN } .rxmode = { .max_rx_pkt_len = RTE_ETHER_MAX_LEN }
}; };
...@@ -126,10 +124,6 @@ static inline int port_init(int portid, struct rte_mempool *mbuf_pool) { ...@@ -126,10 +124,6 @@ static inline int port_init(int portid, struct rte_mempool *mbuf_pool) {
if (retval != 0) if (retval != 0)
return retval; return retval;
//ret = rte_eth_dev_adjust_nb_rx_tx_desc(1, &nb_rxd, &nb_txd);
//if (ret < 0)
// rte_exit(EXIT_FAILURE, "Cannot adjust number of descriptors: err=%d, port=%u\n", ret, 1);
/* Allocate and set up 1 RX queue per Ethernet port. */ /* Allocate and set up 1 RX queue per Ethernet port. */
for (q = 0; q < rx_rings; q++) { for (q = 0; q < rx_rings; q++) {
retval = rte_eth_rx_queue_setup(portid, q, nb_rxd, retval = rte_eth_rx_queue_setup(portid, q, nb_rxd,
...@@ -176,7 +170,6 @@ static void init_dpdk(int argc, char ** argv) { ...@@ -176,7 +170,6 @@ static void init_dpdk(int argc, char ** argv) {
if (port_init(1, mbuf_pool) != 0) if (port_init(1, mbuf_pool) != 0)
rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n", 1); rte_exit(EXIT_FAILURE, "Cannot init port %"PRIu8 "\n", 1);
} }
static void send_packets(int port) { static void send_packets(int port) {
struct rte_mbuf * pkt[BURST_SIZE]; struct rte_mbuf * pkt[BURST_SIZE];
struct rte_ether_hdr *eth_hdr; struct rte_ether_hdr *eth_hdr;
...@@ -193,8 +186,8 @@ static void send_packets(int port) { ...@@ -193,8 +186,8 @@ static void send_packets(int port) {
eth_hdr->s_addr = s_addr; eth_hdr->s_addr = s_addr;
} }
eth_hdr->ether_type = 0x0a00; eth_hdr->ether_type = 0x0a00;
memcpy(rte_pktmbuf_mtod_offset(pkt[i], uint8_t *, sizeof(struct rte_ether_hdr)), data[i], DATA_LEN); memcpy(rte_pktmbuf_mtod_offset(pkt[i], uint8_t *, sizeof(struct rte_ether_hdr)), data[i], DATA_SIZE);
pkt_size = DATA_LEN + sizeof(struct rte_ether_hdr); pkt_size = DATA_SIZE + sizeof(struct rte_ether_hdr);
pkt[i]->data_len = pkt_size; pkt[i]->data_len = pkt_size;
pkt[i]->pkt_len = pkt_size; pkt[i]->pkt_len = pkt_size;
} }
...@@ -209,7 +202,6 @@ static void send_packets(int port) { ...@@ -209,7 +202,6 @@ static void send_packets(int port) {
exit(EXIT_FAILURE); exit(EXIT_FAILURE);
} }
} }
static int recv_packets(int port) { static int recv_packets(int port) {
struct rte_mbuf * pkt[BURST_SIZE]; struct rte_mbuf * pkt[BURST_SIZE];
//if(port == 0) log_info("PORT0", "Init"); //if(port == 0) log_info("PORT0", "Init");
...@@ -244,7 +236,7 @@ void * send_thread(void * p) { ...@@ -244,7 +236,7 @@ void * send_thread(void * p) {
log_info("SEND_THREAD", "Init %d", *port); log_info("SEND_THREAD", "Init %d", *port);
for(int i = 0; i < BURST_SIZE; i++) { for(int i = 0; i < BURST_SIZE; i++) {
for(int j = 0; j < DATA_LEN; j++) { for(int j = 0; j < DATA_SIZE; j++) {
data[i][j] = 0xfe; data[i][j] = 0xfe;
} }
} }
......
...@@ -3,30 +3,28 @@ ...@@ -3,30 +3,28 @@
CC=gcc -m64 -msse4.1 CC=gcc -m64 -msse4.1
CXX=g++ -m64 -msse4.1 CXX=g++ -m64 -msse4.1
CFLAGS=-O2 -fno-strict-aliasing -Wall -pedantic #CFLAGS=-O2 -Wall -pedantic -std=gnu17
CFLAGS+=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE CFLAGS=-O2 -fno-strict-aliasing -Wall -pedantic -std=gnu17
CFLAGS+=-MMD -g CFLAGS +=-D_GNU_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE
CFLAGS += -DALLOW_EXPERIMENTAL_API
CXXFLAGS=$(CFLAGS) CXXFLAGS=$(CFLAGS)
LIB=trx_ecpri_dpdk
LIBDIR=/root/ecpri/trx-ecpri-priv
LDFLAGS=-l$(LIB)
LDFLAGS+=-L/usr/local/lib/x86_64-linux-gnu -Wl,--as-needed -lrte_node -lrte_graph -lrte_bpf -lrte_flow_classify -lrte_pipeline -lrte_table -lrte_port -lrte_fib -lrte_ipsec -lrte_vhost -lrte_stack -lrte_security -lrte_sched -lrte_reorder -lrte_rib -lrte_regexdev -lrte_rawdev -lrte_pdump -lrte_power -lrte_member -lrte_lpm -lrte_latencystats -lrte_kni -lrte_jobstats -lrte_ip_frag -lrte_gso -lrte_gro -lrte_eventdev -lrte_efd -lrte_distributor -lrte_cryptodev -lrte_compressdev -lrte_cfgfile -lrte_bitratestats -lrte_bbdev -lrte_acl -lrte_timer -lrte_hash -lrte_metrics -lrte_cmdline -lrte_pci -lrte_ethdev -lrte_meter -lrte_net -lrte_mbuf -lrte_mempool -lrte_rcu -lrte_ring -lrte_eal -lrte_telemetry -lrte_kvargs -lbsd -lpthread -lm
SRCCLIENT=trx_ecpri.c client.c PROG=test-dpdk-ecpri
SRCSERVER=trx_ecpri.c server.c
OBJCLIENT=$(SRCCLIENT:%.c=%.o)
OBJSERVER=$(SRCSERVER:%.c=%.o)
CLIENT=client
SERVER=server
all: $(SERVER) $(CLIENT) all: $(PROG)
clean: $(PROG): $(PROG).o
rm -f $(SERVER) $(CLIENT) *.o *~ *.d $(CC) -o $@ $< $(LDFLAGS)
$(SERVER): $(OBJSERVER)
$(CC) $(LDFLAGS) -o $@ $^ -lm -lpthread
$(CLIENT): $(OBJCLIENT)
$(CC) $(LDFLAGS) -o $@ $^ -lm -lpthread
%.o: %.c %.o: %.c
$(CC) $(CFLAGS) -fpic -c -o $@ $< $(CC) $(CFLAGS) -c -o $@ $<
clean:
rm -f $(PROG) *.o *~ *.d
-include $(wildcard *.d) -include $(wildcard *.d)
#include <arpa/inet.h>
#include <assert.h>
#include <errno.h>
#include <error.h>
#include <fcntl.h>
#include <getopt.h>
#include <immintrin.h>
#include <inttypes.h>
#include <limits.h>
#include <linux/if_packet.h>
#include <math.h>
#include <netdb.h>
#include <netinet/ether.h>
#include <netinet/in.h>
#include <net/if.h>
#include <pthread.h>
#include <sched.h>
#include <semaphore.h>
#include <signal.h>
#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/ioctl.h>
#include <sys/mman.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <sys/time.h>
#include <sys/types.h>
#include <time.h>
#include <unistd.h>
typedef struct {
const char * re_mac;
const char * rec_mac;
const char * rec_if;
int recv_affinity;
int send_affinity;
int prepare_affinity;
int decompress_affinity;
int statistic_affinity;
int ecpri_period;
int flow_id;
int sample_rate;
} TRXEcpriState;
static void log_error(const char * section, const char * msg, ...) {
time_t t;
struct tm ts;
char line[256];
va_list arglist;
time(&t);
ts = *localtime(&t);
strftime(line, 80, "%m-%d %H:%M:%S", &ts);
sprintf(line + strlen(line), " ERROR [%s] ", section);
va_start(arglist, msg);
vsprintf(line + strlen(line), msg, arglist);
va_end(arglist);
puts(line);
exit(EXIT_FAILURE);
}
static void log_info(const char * section, const char * msg, ...) {
time_t t;
struct tm ts;
char line[256];
va_list arglist;
time(&t);
ts = *localtime(&t);
strftime(line, 80, "%m-%d %H:%M:%S", &ts);
sprintf(line + strlen(line), " INFO [%s] ", section);
va_start(arglist, msg);
vsprintf(line + strlen(line), msg, arglist);
va_end(arglist);
puts(line);
}
int startdpdk(TRXEcpriState * s);
int main(int argc, char * argv[]) {
(void) argc;
(void) argv;
TRXEcpriState *s;
s = malloc(sizeof(TRXEcpriState));
memset(s, 0, sizeof(*s));
#if 0
s->rec_mac = "80:fa:5b:92:39:c3";
s->re_mac = "00:e0:4c:90:20:d3";
s->rec_if = "enp53s0";
#else
s->rec_mac = "b8:ce:f6:4b:00:22";
s->re_mac = "b8:ce:f6:4b:00:23";
s->rec_if = "ens5f0np0";
#endif
s->recv_affinity = 39;
s->send_affinity = 38;
s->prepare_affinity = 37;
s->decompress_affinity = 36;
s->statistic_affinity = 35;
s->ecpri_period = 800;
s->flow_id = 0;
s->sample_rate = 122880000;
log_info("TEST-DPDK-ECPRI", "Starting test...\n");
log_info("TEST-DPDK-ECPRI", "rec-mac: %s, re-mac: %s, rec-if: %s", s->rec_mac, s->re_mac, s->rec_if);
startdpdk(s);
for(int i = 0; i < 1000; i++) {
sleep(1);
}
}
#!/bin/bash
cd ..;
make;
cd ecpri-tests;
make all;
./test-dpdk-ecpri
This diff is collapsed.
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