Skip to content

Commit

Permalink
ONVM library (#157)
Browse files Browse the repository at this point in the history
These changes build the ONVM code as a library which can more easily be included with NFs.

Commit log:

* Create proper library for onvm_nflib, rename common.h to be less common.
* Include all shared files in the library, rename library libonvm.a.
* Make dequeing from NF rings simpler.
* Syntax cleanup
* Updating AES NF's Makefiles to use library
  • Loading branch information
nks5295 committed Nov 15, 2016
1 parent 1ac620f commit c51e2f6
Show file tree
Hide file tree
Showing 30 changed files with 64 additions and 85 deletions.
5 changes: 2 additions & 3 deletions examples/aes_decrypt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ ONVM= $(SRCDIR)/../../onvm
CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/x86_64-native-linuxapp-gcc/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/x86_64-native-linuxapp-gcc/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_common.o

# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Expand Down
5 changes: 2 additions & 3 deletions examples/aes_encrypt/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,10 +56,9 @@ ONVM= $(SRCDIR)/../../onvm
CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/x86_64-native-linuxapp-gcc/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/x86_64-native-linuxapp-gcc/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_common.o

# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Expand Down
5 changes: 2 additions & 3 deletions examples/basic_monitor/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,8 @@ ONVM= $(SRCDIR)/../../onvm
CFLAGS += $(WERROR_FLAGS) -O3

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_common.o

include $(RTE_SDK)/mk/rte.extapp.mk
5 changes: 2 additions & 3 deletions examples/bridge/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,9 @@ ONVM= $(SRCDIR)/../../onvm
CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_common.o

# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Expand Down
7 changes: 1 addition & 6 deletions examples/flow_table/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,12 +55,7 @@ ONVM ?= $(SRCDIR)/../../onvm
CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/x86_64-native-linuxapp-gcc/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_sc_common.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_flow_table.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_flow_dir.o
LDFLAGS += -L$(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/ -lonvm

# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Expand Down
2 changes: 1 addition & 1 deletion examples/flow_table/sdn.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@

#include "sdn.h"
#include "sdn_pkt_list.h"
#include "common.h"
#include "onvm_common.h"
#include "onvm_nflib.h"
#include "onvm_flow_table.h"
#include "setupconn.h"
Expand Down
7 changes: 3 additions & 4 deletions examples/simple_forward/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ ONVM= $(SRCDIR)/../../onvm
CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/x86_64-native-linuxapp-gcc/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_nflib.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_common.o

# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Expand Down
5 changes: 2 additions & 3 deletions examples/speed_tester/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,9 @@ ONVM ?= $(SRCDIR)/../../onvm
CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_common.o

# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Expand Down
8 changes: 1 addition & 7 deletions examples/test_flow_dir/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,7 @@ CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)

CFLAGS += -I$(ONVM)/onvm_nflib
CFLAGS += -I$(ONVM)/onvm_mgr
CFLAGS += -I$(ONVM)/shared
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/x86_64-native-linuxapp-gcc/onvm_nflib.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_pkt_helper.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_sc_common.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_sc_mgr.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_flow_table.o
LDFLAGS += $(ONVM)/shared/shared/x86_64-native-linuxapp-gcc/onvm_flow_dir.o
LDFLAGS += $(ONVM)/onvm_nflib/onvm_nflib/$(RTE_TARGET)/libonvm.a

# workaround for a gcc bug with noreturn attribute
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603
Expand Down
3 changes: 1 addition & 2 deletions onvm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@ RTE_TARGET ?= x86_64-native-linuxapp-gcc

include $(RTE_SDK)/mk/rte.vars.mk

DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += shared
DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += onvm_mgr
DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += onvm_nflib
DIRS-$(CONFIG_RTE_EXEC_ENV_LINUXAPP) += onvm_mgr

include $(RTE_SDK)/mk/rte.extsubdir.mk
12 changes: 6 additions & 6 deletions onvm/onvm_mgr/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -58,12 +58,12 @@ SRCS-y := main.c onvm_init.c onvm_args.c onvm_stats.c onvm_pkt.c onvm_nf.c
INC := onvm_mgr.h onvm_init.h onvm_args.h onvm_stats.h onvm_nf.h onvm_pkt.h

CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)
CFLAGS += -I$(SRCDIR)/../
LDFLAGS += $(SRCDIR)/../shared/shared/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(SRCDIR)/../shared/shared/$(RTE_TARGET)/onvm_sc_mgr.o
LDFLAGS += $(SRCDIR)/../shared/shared/$(RTE_TARGET)/onvm_flow_table.o
LDFLAGS += $(SRCDIR)/../shared/shared/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(SRCDIR)/../shared/shared/$(RTE_TARGET)/onvm_flow_dir.o
CFLAGS += -I$(SRCDIR)/../ -I$(SRCDIR)/../onvm_nflib/
LDFLAGS += $(SRCDIR)/../onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_common.o
LDFLAGS += $(SRCDIR)/../onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_sc_mgr.o
LDFLAGS += $(SRCDIR)/../onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_flow_table.o
LDFLAGS += $(SRCDIR)/../onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(SRCDIR)/../onvm_nflib/onvm_nflib/$(RTE_TARGET)/onvm_flow_dir.o

# for newer gcc, e.g. 4.4, no-strict-aliasing may not be necessary
# and so the next line can be removed in those cases.
Expand Down
12 changes: 4 additions & 8 deletions onvm/onvm_mgr/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
* 2015-2016 George Washington University
* 2015-2016 University of California Riverside
* 2010-2014 Intel Corporation. All rights reserved.
* 2016 Hewlett Packard Enterprise Development LP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -141,17 +142,12 @@ tx_thread_main(void *arg) {
for (;;) {
/* Read packets from the client's tx queue and process them as needed */
for (i = tx->first_cl; i < tx->last_cl; i++) {
tx_count = PACKET_READ_SIZE;
cl = &clients[i];
if (!onvm_nf_is_valid(cl))
continue;
/* try dequeuing max possible packets first, if that fails, get the
* most we can. Loop body should only execute once, maximum */
while (tx_count > 0 &&
unlikely(rte_ring_dequeue_bulk(cl->tx_q, (void **) pkts, tx_count) != 0)) {
tx_count = (uint16_t)RTE_MIN(rte_ring_count(cl->tx_q),
PACKET_READ_SIZE);
}

/* Dequeue all packets in ring up to max possible. */
tx_count = rte_ring_dequeue_burst(cl->tx_q, (void **) pkts, PACKET_READ_SIZE);

/* Now process the Client packets read */
if (likely(tx_count > 0)) {
Expand Down
2 changes: 1 addition & 1 deletion onvm/onvm_mgr/onvm_args.h
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@

#include "getopt.h"

#include "shared/onvm_includes.h"
#include "onvm_includes.h"
#include "onvm_mgr/onvm_init.h"

#define DEFAULT_SERVICE_ID 1
Expand Down
12 changes: 6 additions & 6 deletions onvm/onvm_mgr/onvm_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,12 +68,12 @@


#include "onvm_mgr/onvm_args.h"
#include "shared/onvm_includes.h"
#include "shared/common.h"
#include "shared/onvm_sc_mgr.h"
#include "shared/onvm_sc_common.h"
#include "shared/onvm_flow_table.h"
#include "shared/onvm_flow_dir.h"
#include "onvm_includes.h"
#include "onvm_common.h"
#include "onvm_sc_mgr.h"
#include "onvm_sc_common.h"
#include "onvm_flow_table.h"
#include "onvm_flow_dir.h"


/***********************************Macros************************************/
Expand Down
8 changes: 4 additions & 4 deletions onvm/onvm_mgr/onvm_mgr.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,10 +76,10 @@

#include "onvm_mgr/onvm_args.h"
#include "onvm_mgr/onvm_init.h"
#include "shared/onvm_includes.h"
#include "shared/onvm_sc_mgr.h"
#include "shared/onvm_flow_table.h"
#include "shared/onvm_flow_dir.h"
#include "onvm_includes.h"
#include "onvm_sc_mgr.h"
#include "onvm_flow_table.h"
#include "onvm_flow_dir.h"


/***********************************Macros************************************/
Expand Down
13 changes: 7 additions & 6 deletions onvm/onvm_nflib/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
# 2015-2016 George Washington University
# 2015-2016 University of California Riverside
# 2010-2014 Intel Corporation.
# 2016 Hewlett Packard Enterprise Development LP
# All rights reserved.
#
# Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -44,13 +45,13 @@ include $(RTE_SDK)/mk/rte.vars.mk

RTE_TARGET ?= x86_64-native-linuxapp-gcc

# binary name
LIB = libonvm.a

# all source are stored in SRCS-y
SRCS-y := onvm_nflib.c
SRCS-y := onvm_pkt_helper.c onvm_sc_common.c onvm_sc_mgr.c onvm_flow_table.c onvm_flow_dir.c onvm_nflib.c

CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS)
CFLAGS += -I$(SRCDIR)/../shared

LDFLAGS += $(SRCDIR)/../shared/shared/$(RTE_TARGET)/onvm_pkt_helper.o
LDFLAGS += $(SRCDIR)/../shared/shared/$(RTE_TARGET)/onvm_sc_common.o
#CFLAGS += -I$(SRCDIR)/../shared

include $(RTE_SDK)/mk/rte.extobj.mk
include $(RTE_SDK)/mk/rte.extlib.mk
2 changes: 1 addition & 1 deletion onvm/shared/common.h → onvm/onvm_nflib/onvm_common.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* common.h - shared data between host and NFs
* onvm_common.h - shared data between host and NFs
********************************************************************/

#ifndef _COMMON_H_
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@
#include <rte_memzone.h>
#include <rte_mbuf.h>
#include <rte_malloc.h>
#include "common.h"
#include "onvm_common.h"
#include "onvm_flow_table.h"
#include "onvm_flow_dir.h"

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
#ifndef _ONVM_FLOW_DIR_H_
#define _ONVM_FLOW_DIR_H_

#include "common.h"
#include "onvm_common.h"
#include "onvm_flow_table.h"

extern struct onvm_ft *sdn_ft;
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@
#include <rte_udp.h>
#include <rte_thash.h>
#include "onvm_pkt_helper.h"
#include "common.h"
#include "onvm_common.h"

extern uint8_t rss_symmetric_key[40];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,6 @@
/******************************Internal headers*******************************/


#include "common.h"
#include "onvm_common.h"

#endif // _ONVM_INCLUDES_H_
20 changes: 10 additions & 10 deletions onvm/onvm_nflib/onvm_nflib.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
* Copyright(c)
* 2015-2016 George Washington University
* 2015-2016 University of California Riverside
* 2016 Hewlett Packard Enterprise Development LP
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -67,7 +68,7 @@


// Number of packets to attempt to read from queue
#define PKT_READ_SIZE ((uint16_t)32)
#define PKT_READ_SIZE ((uint16_t)32)


/******************************Global Variables*******************************/
Expand Down Expand Up @@ -273,8 +274,10 @@ onvm_nflib_init(int argc, char *argv[], const char *nf_tag) {
int
onvm_nflib_run(
struct onvm_nf_info* info,
int(*handler)(struct rte_mbuf* pkt, struct onvm_pkt_meta* meta)
) {
int(*handler)(struct rte_mbuf* pkt,
struct onvm_pkt_meta* meta)
)
{
void *pkts[PKT_READ_SIZE];
struct onvm_pkt_meta* meta;

Expand All @@ -286,18 +289,15 @@ onvm_nflib_run(
signal(SIGTERM, onvm_nflib_handle_signal);

for (; keep_running;) {
uint16_t i, j, nb_pkts = PKT_READ_SIZE;
uint16_t i, j, nb_pkts;
void *pktsTX[PKT_READ_SIZE];
int tx_batch_size = 0;
int ret_act;

/* try dequeuing max possible packets first, if that fails, get the
* most we can. Loop body should only execute once, maximum */
while (nb_pkts > 0 &&
unlikely(rte_ring_dequeue_bulk(rx_ring, pkts, nb_pkts) != 0))
nb_pkts = (uint16_t)RTE_MIN(rte_ring_count(rx_ring), PKT_READ_SIZE);
/* Dequeue all packets in ring up to max possible. */
nb_pkts = rte_ring_dequeue_burst(rx_ring, pkts, PKT_READ_SIZE);

if(nb_pkts == 0) {
if(unlikely(nb_pkts == 0)) {
continue;
}
/* Give each packet to the user proccessing function */
Expand Down
2 changes: 1 addition & 1 deletion onvm/onvm_nflib/onvm_nflib.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@
#ifndef _ONVM_NFLIB_H_
#define _ONVM_NFLIB_H_
#include <rte_mbuf.h>
#include "common.h"
#include "onvm_common.h"

/************************************API**************************************/

Expand Down
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@

#include <inttypes.h>
#include <errno.h>
#include "common.h"
#include "onvm_common.h"
#include "onvm_sc_common.h"

int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define _SC_COMMON_H_

#include <inttypes.h>
#include "common.h"
#include "onvm_common.h"

/* append a entry to serivce chain, 0 means appending successful, 1 means failed*/
int onvm_sc_append_entry(struct onvm_service_chain *chain, uint8_t action, uint16_t destination);
Expand Down
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
#define _SC_MGR_H_

#include <rte_mbuf.h>
#include "common.h"
#include "onvm_common.h"

static inline uint8_t
onvm_next_action(struct onvm_service_chain* chain, uint16_t cur_nf) {
Expand Down

0 comments on commit c51e2f6

Please sign in to comment.