-
Notifications
You must be signed in to change notification settings - Fork 136
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
noahchin
committed
Jun 21, 2021
1 parent
4bcb953
commit 0c6a4b2
Showing
4 changed files
with
311 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
# openNetVM | ||
# https://github.com/sdnfv/openNetVM | ||
# | ||
# BSD LICENSE | ||
# | ||
# Copyright(c) | ||
# 2015-2017 George Washington University | ||
# 2015-2017 University of California Riverside | ||
# All rights reserved. | ||
# | ||
# Redistribution and use in source and binary forms, with or without | ||
# modification, are permitted provided that the following conditions | ||
# are met: | ||
# | ||
# Redistributions of source code must retain the above copyright | ||
# notice, this list of conditions and the following disclaimer. | ||
# Redistributions in binary form must reproduce the above copyright | ||
# notice, this list of conditions and the following disclaimer in | ||
# the documentation and/or other materials provided with the | ||
# distribution. | ||
# The name of the author may not be used to endorse or promote | ||
# products derived from this software without specific prior | ||
# written permission. | ||
# | ||
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
|
||
ifeq ($(RTE_SDK),) | ||
$(error "Please define RTE_SDK environment variable") | ||
endif | ||
|
||
|
||
# Default target, can be overriden by command line or environment | ||
include $(RTE_SDK)/mk/rte.vars.mk | ||
RTE_TARGET ?= x86_64-native-linuxapp-gcc | ||
|
||
# binary name | ||
APP = test_messaging | ||
|
||
# all source are stored in SRCS-y | ||
SRCS-y := test_messaging.c | ||
|
||
ONVM= $(SRCDIR)/../../onvm | ||
|
||
CFLAGS += $(WERROR_FLAGS) -O3 $(USER_FLAGS) | ||
|
||
CFLAGS += -I$(ONVM)/onvm_nflib | ||
CFLAGS += -I$(ONVM)/lib | ||
LDFLAGS += $(ONVM)/onvm_nflib/$(RTE_TARGET)/libonvm.a | ||
LDFLAGS += $(ONVM)/lib/$(RTE_TARGET)/lib/libonvmhelper.a -lm | ||
|
||
# workaround for a gcc bug with noreturn attribute | ||
# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603 | ||
ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) | ||
CFLAGS_main.o += -Wno-return-type | ||
endif | ||
|
||
include $(RTE_SDK)/mk/rte.extapp.mk |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
Basic Message Test | ||
== | ||
This is an example NF that acts as a unit test for sending messsages from an NF to itself. | ||
|
||
Compilation and Execution | ||
-- | ||
``` | ||
cd examples | ||
make | ||
cd basic_msg_test | ||
./go.sh SERVICE_ID [PRINT_DELAY] | ||
OR | ||
./go.sh -F CONFIG_FILE -- -- [-p PRINT_DELAY] | ||
OR | ||
sudo ./build/basic_msg_test -l CORELIST -n 3 --proc-type=secondary -- -r SERVICE_ID -- [-p PRINT_DELAY] | ||
``` | ||
|
||
App Specific Arguments | ||
-- | ||
- `-p <print_delay>`: number of packets between each print, e.g. `-p 1` prints every packet. | ||
|
||
Config File Support | ||
-- | ||
This NF supports the NF generating arguments from a config file. For | ||
additional reading, see [Examples.md](../../docs/Examples.md) | ||
|
||
See `../example_config.json` for all possible options that can be set. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
#!/bin/bash | ||
|
||
#The go.sh script is a convinient way to run start_nf.sh without specifying NF_NAME | ||
|
||
NF_DIR=${PWD##*/} | ||
|
||
if [ ! -f ../start_nf.sh ]; then | ||
echo "ERROR: The ./go.sh script can only be used from the NF folder" | ||
echo "If running from other directory use examples/start_nf.sh" | ||
exit 1 | ||
fi | ||
|
||
# only check for running manager if not in Docker | ||
if [[ -z $(pgrep -u root -f "/onvm/onvm_mgr/.*/onvm_mgr") ]] && ! grep -q "docker" /proc/1/cgroup | ||
then | ||
echo "NF cannot start without a running manager" | ||
exit 1 | ||
fi | ||
|
||
../start_nf.sh "$NF_DIR" "$@" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,193 @@ | ||
/********************************************************************* | ||
* openNetVM | ||
* https://sdnfv.github.io | ||
* | ||
* BSD LICENSE | ||
* | ||
* Copyright(c) | ||
* 2015-2019 George Washington University | ||
* 2015-2019 University of California Riverside | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions | ||
* are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright | ||
* notice, this list of conditions and the following disclaimer. | ||
* * Redistributions in binary form must reproduce the above copyright | ||
* notice, this list of conditions and the following disclaimer in | ||
* the documentation and/or other materials provided with the | ||
* distribution. | ||
* * The name of the author may not be used to endorse or promote | ||
* products derived from this software without specific prior | ||
* written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | ||
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | ||
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | ||
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | ||
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | ||
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | ||
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | ||
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | ||
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | ||
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
* | ||
* test_messaging.c - unit test to ensure NFs can send messages to itself | ||
********************************************************************/ | ||
|
||
#include <errno.h> | ||
#include <getopt.h> | ||
#include <inttypes.h> | ||
#include <stdarg.h> | ||
#include <stdint.h> | ||
#include <stdio.h> | ||
#include <stdlib.h> | ||
#include <string.h> | ||
#include <sys/queue.h> | ||
#include <unistd.h> | ||
|
||
#include <rte_common.h> | ||
#include <rte_ip.h> | ||
#include <rte_mbuf.h> | ||
#include <rte_mempool.h> | ||
#include <rte_ring.h> | ||
#include <rte_malloc.h> | ||
|
||
#include "onvm_nflib.h" | ||
#include "onvm_pkt_helper.h" | ||
|
||
#define NF_TAG "basic_msg_test" | ||
|
||
/* number of package between each print */ | ||
static uint32_t print_delay = 1000000; | ||
|
||
static uint16_t destination; | ||
|
||
void | ||
nf_setup(struct onvm_nf_local_ctx *nf_local_ctx); | ||
|
||
void | ||
nf_msg_handler(void *msg_data, struct onvm_nf_local_ctx *nf_local_ctx); | ||
|
||
/* | ||
* Print a usage message | ||
*/ | ||
static void | ||
usage(const char *progname) { | ||
printf("Usage:\n"); | ||
printf("%s [EAL args] -- [NF_LIB args] -- -p <print_delay>\n", progname); | ||
printf("%s -F <CONFIG_FILE.json> [EAL args] -- [NF_LIB args] -- [NF args]\n\n", progname); | ||
printf("Flags:\n"); | ||
printf(" - `-p <print_delay>`: number of packets between each print, e.g. `-p 1` prints every packets.\n"); | ||
} | ||
|
||
/* | ||
* Parse the application arguments. | ||
*/ | ||
static int | ||
parse_app_args(int argc, char *argv[], const char *progname) { | ||
int c; | ||
|
||
while ((c = getopt(argc, argv, "p:")) != -1) { | ||
switch (c) { | ||
case 'p': | ||
print_delay = strtoul(optarg, NULL, 10); | ||
RTE_LOG(INFO, APP, "print_delay = %d\n", print_delay); | ||
break; | ||
case '?': | ||
usage(progname); | ||
if (optopt == 'p') | ||
RTE_LOG(INFO, APP, "Option -%c requires an argument.\n", optopt); | ||
else if (isprint(optopt)) | ||
RTE_LOG(INFO, APP, "Unknown option `-%c'.\n", optopt); | ||
else | ||
RTE_LOG(INFO, APP, "Unknown option character `\\x%x'.\n", optopt); | ||
return -1; | ||
default: | ||
usage(progname); | ||
return -1; | ||
} | ||
} | ||
return optind; | ||
} | ||
|
||
void | ||
nf_setup(__attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx) { | ||
struct rte_mempool *pktmbuf_pool; | ||
|
||
pktmbuf_pool = rte_mempool_lookup(PKTMBUF_POOL_NAME); | ||
if (pktmbuf_pool == NULL) { | ||
onvm_nflib_stop(nf_local_ctx); | ||
rte_exit(EXIT_FAILURE, "Cannot find mbuf pool!\n"); | ||
} | ||
|
||
uint16_t address = nf_local_ctx->nf->service_id; | ||
|
||
int ret = onvm_nflib_send_msg_to_nf(address, NULL); | ||
printf("%d\n", ret); | ||
|
||
} | ||
|
||
void | ||
nf_msg_handler(void *msg_data, __attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx){ | ||
|
||
uint16_t address = nf_local_ctx->nf->service_id; | ||
|
||
int ret = onvm_nflib_send_msg_to_nf(address, msg_data); | ||
printf("%d\n", ret); | ||
|
||
} | ||
|
||
static int | ||
packet_handler(__attribute__((unused)) struct rte_mbuf *pkt, struct onvm_pkt_meta *meta, | ||
__attribute__((unused)) struct onvm_nf_local_ctx *nf_local_ctx) { | ||
|
||
meta->destination = destination; | ||
meta->action = ONVM_NF_ACTION_TONF; | ||
|
||
return 0; | ||
} | ||
|
||
int | ||
main(int argc, char *argv[]) { | ||
int arg_offset; | ||
struct onvm_nf_local_ctx *nf_local_ctx; | ||
struct onvm_nf_function_table *nf_function_table; | ||
const char *progname = argv[0]; | ||
|
||
nf_local_ctx = onvm_nflib_init_nf_local_ctx(); | ||
onvm_nflib_start_signal_handler(nf_local_ctx, NULL); | ||
|
||
nf_function_table = onvm_nflib_init_nf_function_table(); | ||
nf_function_table->pkt_handler = &packet_handler; | ||
nf_function_table->setup = &nf_setup; | ||
nf_function_table->msg_handler = &nf_msg_handler; | ||
|
||
if ((arg_offset = onvm_nflib_init(argc, argv, NF_TAG, nf_local_ctx, nf_function_table)) < 0) { | ||
onvm_nflib_stop(nf_local_ctx); | ||
if (arg_offset == ONVM_SIGNAL_TERMINATION) { | ||
printf("Exiting due to user termination\n"); | ||
return 0; | ||
} else { | ||
rte_exit(EXIT_FAILURE, "Failed ONVM init\n"); | ||
} | ||
} | ||
|
||
argc -= arg_offset; | ||
argv += arg_offset; | ||
|
||
if (parse_app_args(argc, argv, progname) < 0) { | ||
onvm_nflib_stop(nf_local_ctx); | ||
rte_exit(EXIT_FAILURE, "Invalid command-line arguments\n"); | ||
} | ||
|
||
onvm_nflib_run(nf_local_ctx); | ||
|
||
onvm_nflib_stop(nf_local_ctx); | ||
|
||
printf("If we reach here, program is ending\n"); | ||
return 0; | ||
} |