Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Update] Add Messaging Unit Tests and Fix Issue #293 Message Memory Leak #296

Merged
merged 60 commits into from
Aug 31, 2021
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
60 commits
Select commit Hold shift + click to select a range
1086843
[Update] Fixed Issue #293
Jun 18, 2021
25650cc
[Update] Deleted dead code
Jun 18, 2021
1a1b0b7
[Update] Abstracted SID so that it works with whatever SID given
Jun 18, 2021
4bcb953
[Update] Changed name
Jun 21, 2021
0c6a4b2
[Update] Changed dir name
Jun 21, 2021
9fbd366
[Update] Changed code in regards to PR #296 comments
Jun 21, 2021
894811f
[Update] Drop packets
Jun 21, 2021
def7da0
[Update] Sends more than one msg
Jun 22, 2021
7f77210
[Update] Working on making output cleaner as well as creating a struc…
Jun 22, 2021
d296564
[Update] Added checking of memory
Jun 23, 2021
23f3037
[Update] Added working struct. Working on cleaner output and automati…
Jun 23, 2021
b4dc99d
[Update] Added first Test
Jun 24, 2021
d27bf56
[Update] Working on Unit Tests
Jun 25, 2021
9a2730a
[Update] Verson 1 of Tests. Looking at messaging code now
Jun 28, 2021
74350ec
[Update] Testing fixed. Changing Verbosity
Jun 28, 2021
8183ad4
Delete Makefile
NoahChinitz Jun 28, 2021
f494289
Delete README.md
NoahChinitz Jun 28, 2021
9f3f557
Delete go.sh
NoahChinitz Jun 28, 2021
74eca8c
Delete test_messaging.c
NoahChinitz Jun 28, 2021
25fc063
[Update] Ready for Review.
Jun 29, 2021
2ae757f
debug files
elliotthenne Jun 30, 2021
23d7c55
[Update] Test Version 3.0
Jun 30, 2021
85ecb0d
restored old go.sh file
elliotthenne Jun 30, 2021
76e6be9
[Update] Version 3.1 of Tests. Added destroy funciton
Jul 1, 2021
87cf62b
[Update] Fixed destroy function. Added NF to examples/Makefile. Still…
Jul 6, 2021
438c880
Hanging occurs when IID != SID
Jul 6, 2021
7d4bc26
Update launch.json
elliotthenne Jul 6, 2021
2babee7
Merge branch 'vscode-debug' of https://github.com/elliotthenne/openNetVM
Jul 7, 2021
5379bc0
- Added GDB configuration for VSCode.
Jul 7, 2021
d0b7a37
Added function comments
Jul 7, 2021
9582113
[Update] fixed file according to PR comments
Jul 27, 2021
4832b0f
Delete launch.json
NoahChinitz Jul 27, 2021
5b9896e
Delete tasks.json
NoahChinitz Jul 27, 2021
3018dbb
Delete gdb.sh
NoahChinitz Jul 27, 2021
b648a13
[Update] Deleted unnecessary files
Jul 27, 2021
58243bf
Changed test making sure all messages have been dequeued
Aug 17, 2021
fd0ded8
[Update] cleaned up the tests
Aug 18, 2021
6ad66aa
[Update] Ran Linter and finalized tests
Aug 19, 2021
8ac16b8
[Update] Print out socket ID information for manager and network func…
Aug 19, 2021
be80138
Revert "[Update] Print out socket ID information for manager and netw…
Aug 19, 2021
f5213ff
[Update] Print out socket ID information for manager and network func…
Aug 19, 2021
b3381e8
[Updated] Fixed tests
Aug 19, 2021
46da274
[Update] added 4th test phase
Aug 19, 2021
0508402
Merge pull request #1 from NoahChinitzGWU/socket
NoahChinitz Aug 19, 2021
0ade136
Revert "[Update] Print out socket ID information for manager and netw…
NoahChinitz Aug 19, 2021
43ed023
Merge pull request #2 from NoahChinitzGWU/revert-1-socket
NoahChinitz Aug 19, 2021
b1df4b2
[Update] Changing Workflow
Aug 20, 2021
bf65e7e
Merge branch 'master' of https://github.com/NoahChinitzGWU/openNetVM
Aug 20, 2021
8b31047
[Update] Fixed Workflow to be cleaner and more organized
Aug 23, 2021
ad23d44
Update onvm/onvm_nflib/onvm_nflib.c
NoahChinitz Aug 24, 2021
34c0d5c
Update examples/test_messaging/test_messaging.c
NoahChinitz Aug 24, 2021
20bf351
Update examples/test_messaging/test_messaging.c
NoahChinitz Aug 24, 2021
75045aa
Update examples/test_messaging/test_messaging.c
NoahChinitz Aug 24, 2021
f4160b9
Update examples/test_messaging/test_messaging.c
NoahChinitz Aug 24, 2021
7f4f0c8
Update examples/test_messaging/test_messaging.c
NoahChinitz Aug 24, 2021
d5bbf68
[Update] Small fixes for merge
Aug 25, 2021
4aaeef6
deleted sleep call
Aug 26, 2021
e25f6e0
Merge branch 'develop' of https://github.com/sdnfv/openNetVM
Aug 26, 2021
466aa90
Update examples/test_messaging/README.md
NoahChinitz Aug 27, 2021
3f89851
Update examples/test_messaging/README.md
twood02 Aug 27, 2021
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
67 changes: 67 additions & 0 deletions examples/basic_msg_test/Makefile
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 = basic_msg_test

# all source are stored in SRCS-y
SRCS-y := basic_msg_test.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
31 changes: 31 additions & 0 deletions examples/basic_msg_test/README.md
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.
193 changes: 193 additions & 0 deletions examples/basic_msg_test/basic_msg_test.c
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.
*
* basic_msg_test.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"
NoahChinitz marked this conversation as resolved.
Show resolved Hide resolved

/* 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);
NoahChinitz marked this conversation as resolved.
Show resolved Hide resolved
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;
NoahChinitz marked this conversation as resolved.
Show resolved Hide resolved

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;
}
20 changes: 20 additions & 0 deletions examples/basic_msg_test/go.sh
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" "$@"
11 changes: 10 additions & 1 deletion onvm/onvm_nflib/onvm_nflib.c
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -727,7 +727,16 @@ onvm_nflib_send_msg_to_nf(uint16_t dest, void *msg_data) {
msg->msg_type = MSG_FROM_NF;
msg->msg_data = msg_data;

return rte_ring_enqueue(nfs[dest].msg_q, (void*)msg);
ret = rte_ring_enqueue(nfs[dest].msg_q, (void*)msg);
if(ret != 0){
RTE_LOG(INFO, APP, "Destination NF ring is full! Unable to enqueue msg to ring\n");
NoahChinitz marked this conversation as resolved.
Show resolved Hide resolved
rte_mempool_put(nf_msg_pool, (void*)msg);
return ret;
}
else{
return rte_ring_enqueue(nfs[dest].msg_q, (void*)msg);
}
NoahChinitz marked this conversation as resolved.
Show resolved Hide resolved
return 0;
}

void
Expand Down