aboutsummaryrefslogtreecommitdiffstats
path: root/stacks/vpp
diff options
context:
space:
mode:
Diffstat (limited to 'stacks/vpp')
-rw-r--r--stacks/vpp/adapt/dmm_vcl.h36
-rw-r--r--stacks/vpp/adapt/dmm_vcl_adpt.c184
-rw-r--r--stacks/vpp/configure/module_config.json30
-rw-r--r--stacks/vpp/configure/rd_config.json26
-rw-r--r--stacks/vpp/patch/0001-Fix-modify-makefile-to-adapt-dmm.patch72
5 files changed, 348 insertions, 0 deletions
diff --git a/stacks/vpp/adapt/dmm_vcl.h b/stacks/vpp/adapt/dmm_vcl.h
new file mode 100644
index 0000000..f0d8c85
--- /dev/null
+++ b/stacks/vpp/adapt/dmm_vcl.h
@@ -0,0 +1,36 @@
+/*
+ * Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#ifndef included_dmm_vcl_h
+#define included_dmm_vcl_h
+
+#include "nstack_dmm_api.h"
+
+#define DMM_VCL_ENV_DEBUG "DMM_VCL_DEBUG"
+
+typedef struct dmm_vcl
+{
+ int epfd;
+ long unsigned int epoll_threadid;
+ nstack_event_cb regVal;
+ int (*p_epoll_create) (int size);
+ unsigned int (*p_epoll_ctl) (int epFD, int proFD, int ctl_ops,
+ struct epoll_event * events);
+ unsigned int (*p_epoll_wait) (int epfd, struct epoll_event * events,
+ int maxevents, int timeout);
+ int (*p_close) (int fd);
+} dmm_vcl_t;
+
+#endif /* included_dmm_vcl_h */
diff --git a/stacks/vpp/adapt/dmm_vcl_adpt.c b/stacks/vpp/adapt/dmm_vcl_adpt.c
new file mode 100644
index 0000000..ca737fa
--- /dev/null
+++ b/stacks/vpp/adapt/dmm_vcl_adpt.c
@@ -0,0 +1,184 @@
+/*
+ * Copyright (c) 2018 Huawei Technologies Co.,Ltd.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#define _GNU_SOURCE
+#include <pthread.h>
+#include <dlfcn.h>
+#include <sys/epoll.h>
+#include "dmm_vcl.h"
+#include "nstack_dmm_api.h" // nstack_socket_ops*
+#include <vppinfra/error.h> // clib_warning()
+
+#define DMM_VCL_ADPT_DEBUG dmm_vcl_debug
+static unsigned int dmm_vcl_debug;
+dmm_vcl_t g_dmm_vcl;
+
+unsigned int
+vpphs_ep_ctl_ops (int epFD, int proFD, int ctl_ops,
+ struct epoll_event *events, void *pdata)
+{
+ struct epoll_event tmpEvt;
+ int ret = 0;
+ int dmm_epfd;
+
+ tmpEvt.data.ptr = pdata;
+ tmpEvt.events = events->events;
+
+ if (DMM_VCL_ADPT_DEBUG > 0)
+ clib_warning ("DMM VCL ADPT<%d>: epfd=%d,fd=%d,ops=%d, events=%u",
+ getpid (), epFD, proFD, ctl_ops, events->events);
+
+ dmm_epfd = g_dmm_vcl.epfd;
+ switch (ctl_ops)
+ {
+ case nstack_ep_triggle_add:
+ ret = g_dmm_vcl.p_epoll_ctl (dmm_epfd, EPOLL_CTL_ADD, proFD, &tmpEvt);
+ break;
+ case nstack_ep_triggle_mod:
+ ret = g_dmm_vcl.p_epoll_ctl (dmm_epfd, EPOLL_CTL_MOD, proFD, &tmpEvt);
+ break;
+ case nstack_ep_triggle_del:
+ ret = g_dmm_vcl.p_epoll_ctl (dmm_epfd, EPOLL_CTL_DEL, proFD, &tmpEvt);
+ break;
+ default:
+ ret = -1;
+ break;
+ }
+ return ret;
+}
+
+/*check whether some events exist really */
+unsigned int
+vpphs_ep_getEvt (int epFD, int profd, unsigned int events)
+{
+#if 0
+ uint32_t revent = rr_rs_poll (proFD, epi->revents);
+ epi->revents = revent & epi->event.events;
+#endif
+ return 0;
+}
+
+#define DMM_VCL_MAX_EP_EVENT 1024
+
+static void *
+dmm_vcl_epoll_thread (void *arg)
+{
+ int num, i;
+
+ struct epoll_event events[DMM_VCL_MAX_EP_EVENT];
+
+ while (1)
+ {
+ num =
+ g_dmm_vcl.p_epoll_wait (g_dmm_vcl.epfd, events, DMM_VCL_MAX_EP_EVENT,
+ 100);
+
+ for (i = 0; i < num; ++i)
+ {
+ if (DMM_VCL_ADPT_DEBUG > 0)
+ clib_warning
+ ("DMM_VCL_ADPT<%d>: dmm_vcl_epoll i[%d] events=%u, epfd=%d, ptr=%d",
+ getpid (), i, events[i].events, events[i].data.fd,
+ events[i].data.ptr);
+
+ g_dmm_vcl.regVal.event_cb (events[i].data.ptr, events[i].events);
+
+ }
+ }
+
+ return NULL;
+}
+
+int
+dmm_vpphs_init ()
+{
+ char *env_var_str;
+ int rv = 0;
+
+ env_var_str = getenv (DMM_VCL_ENV_DEBUG);
+ if (env_var_str)
+ {
+ u32 tmp;
+ if (sscanf (env_var_str, "%u", &tmp) != 1)
+ clib_warning
+ ("DMM_VCL_ADPT<%d>: WARNING: Invalid debug level specified "
+ "in the environment variable " DMM_VCL_ENV_DEBUG " (%s)!\n",
+ getpid (), env_var_str);
+ else
+ {
+ dmm_vcl_debug = tmp;
+ if (DMM_VCL_ADPT_DEBUG > 0)
+ clib_warning
+ ("DMM_VCL_ADPT<%d>: configured DMM VCL ADPT debug (%u) from "
+ "DMM_VCL_ENV_DEBUG ", getpid (), dmm_vcl_debug);
+ }
+ }
+
+ g_dmm_vcl.epfd = g_dmm_vcl.p_epoll_create (1000);
+ if (g_dmm_vcl.epfd < 0)
+ return g_dmm_vcl.epfd;
+
+ rv =
+ pthread_create (&g_dmm_vcl.epoll_threadid, NULL, dmm_vcl_epoll_thread,
+ NULL);
+ if (rv != 0)
+ {
+ clib_warning ("dmm vcl epoll thread create fail, errno:%d!", errno);
+ g_dmm_vcl.p_close (g_dmm_vcl.epfd);
+ g_dmm_vcl.epfd = -1;
+ return rv;
+ }
+
+ rv = pthread_setname_np (g_dmm_vcl.epoll_threadid, "dmm_vcl_epoll");
+ if (rv != 0)
+ {
+ clib_warning
+ ("pthread_setname_np failed for dmm_vcl_epoll, rv=%d, errno:%d",
+ rv, errno);
+ }
+
+ return rv;
+}
+
+int
+vpphs_stack_register (nstack_proc_cb * ops, nstack_event_cb * val)
+{
+
+#undef NSTACK_MK_DECL
+#define NSTACK_MK_DECL(ret, fn, args) \
+ (ops->socket_ops).pf ## fn = (typeof(((nstack_socket_ops*)0)->pf ## fn))dlsym(val->handle, # fn);
+#include "declare_syscalls.h"
+ (ops->socket_ops).pfepoll_create = NULL;
+
+ g_dmm_vcl.p_epoll_ctl = dlsym (val->handle, "epoll_ctl");
+ g_dmm_vcl.p_epoll_create = dlsym (val->handle, "epoll_create1");
+ g_dmm_vcl.p_epoll_wait = dlsym (val->handle, "epoll_wait");
+ g_dmm_vcl.p_close = dlsym (val->handle, "close");
+ g_dmm_vcl.regVal = *val;
+
+ ops->extern_ops.module_init = dmm_vpphs_init;
+ ops->extern_ops.fork_init_child = NULL;
+ ops->extern_ops.fork_parent_fd = NULL;
+ ops->extern_ops.fork_child_fd = NULL;
+ ops->extern_ops.fork_free_fd = NULL;
+ ops->extern_ops.ep_ctl = vpphs_ep_ctl_ops;
+ ops->extern_ops.ep_getevt = vpphs_ep_getEvt;
+ ops->extern_ops.ep_prewait_proc = NULL;
+ ops->extern_ops.stack_fd_check = NULL;
+ ops->extern_ops.stack_alloc_fd = NULL;
+ ops->extern_ops.peak = NULL;
+
+ return 0;
+}
diff --git a/stacks/vpp/configure/module_config.json b/stacks/vpp/configure/module_config.json
new file mode 100644
index 0000000..fa4d5ff
--- /dev/null
+++ b/stacks/vpp/configure/module_config.json
@@ -0,0 +1,30 @@
+{
+ "default_stack_name": "kernel", /*when rd can't be find maybe choose the defualt one*/
+ "module_list": [
+ {
+ "stack_name": "kernel", /*stack name*/
+ "function_name": "kernel_stack_register", /*function name*/
+ "libname": "./", /*library name, if loadtype is static, this maybe
+ null, else must give a library name*/
+ "loadtype": "static", /*library load type: static or dynamic*/
+ "deploytype": "1", /*deploy model type:model type1, model type2,
+ model type3. Indicating single or multi process
+ deployment. Used during shared memory initialization.*/
+ "maxfd": "1024", /*the max fd supported*/
+ "minfd": "0", /*the min fd supported*/
+ "priorty": "1", /*priorty when executing, reserv*/
+ "stackid": "0", /*stack id, this must be ordered and not be repeated*/
+ },
+ {
+ "stack_name": "stackx",
+ "function_name": "vpphs_stack_register",
+ "libname": "../lib64/libdmm_vcl.so",
+ "loadtype": "dynmic",
+ "deploytype": "1",
+ "maxfd": "1024",
+ "minfd": "0",
+ "priorty": "1",
+ "stackid": "1",
+ },
+ ]
+}
diff --git a/stacks/vpp/configure/rd_config.json b/stacks/vpp/configure/rd_config.json
new file mode 100644
index 0000000..ab57d25
--- /dev/null
+++ b/stacks/vpp/configure/rd_config.json
@@ -0,0 +1,26 @@
+{
+ "ip_route": [
+ {
+ "subnet": "192.168.122.1/24",
+ "type": "nstack-dpdk",
+ },
+ {
+ "subnet": "10.145.240.1/24",
+ "type": "nstack-kernel",
+ },
+ {
+ "subnet": "192.166.1.1/24",
+ "type": "nstack-kernel",
+ }
+ ],
+ "prot_route": [
+ {
+ "proto_type": "1",
+ "type": "nstack-dpdk",
+ },
+ {
+ "proto_type": "2",
+ "type": "nstack-kernel",
+ }
+ ],
+}
diff --git a/stacks/vpp/patch/0001-Fix-modify-makefile-to-adapt-dmm.patch b/stacks/vpp/patch/0001-Fix-modify-makefile-to-adapt-dmm.patch
new file mode 100644
index 0000000..bb3eca7
--- /dev/null
+++ b/stacks/vpp/patch/0001-Fix-modify-makefile-to-adapt-dmm.patch
@@ -0,0 +1,72 @@
+From deb61897f0505a82bd26e7fa35b6923c1455732d Mon Sep 17 00:00:00 2001
+From: Jiang Wenjiang <jiangwenjiang@huawei.com>
+Date: Thu, 9 Aug 2018 08:22:24 +0800
+Subject: [PATCH] Fix: modify makefile to adapt dmm
+
+---
+ src/vcl.am | 17 +++++++++++++++--
+ src/vcl/ldp.c | 2 +-
+ 2 files changed, 16 insertions(+), 3 deletions(-)
+
+diff --git a/src/vcl.am b/src/vcl.am
+index 89e1841..b09cacb 100644
+--- a/src/vcl.am
++++ b/src/vcl.am
+@@ -11,13 +11,18 @@
+ # See the License for the specific language governing permissions and
+ # limitations under the License.
+
+-lib_LTLIBRARIES += libvppcom.la libvcl_ldpreload.la
++lib_LTLIBRARIES += libvppcom.la libvcl_ldpreload.la libdmm_vcl.la
+
+ libvppcom_la_SOURCES =
+ libvcl_ldpreload_la_SOURCES =
++libdmm_vcl_la_SOURCES =
+ libvppcom_la_DEPENDENCIES = \
+ libsvm.la \
+ libvlibmemoryclient.la
++libdmm_vcl_la_DEPENDENCIES = \
++ libsvm.la \
++ libvlibmemoryclient.la \
++ libvcl_ldpreload.la
+
+ libvppcom_la_LIBADD = $(libvppcom_la_DEPENDENCIES) -lpthread -lrt -ldl
+
+@@ -40,12 +45,20 @@ libvcl_ldpreload_la_SOURCES += \
+ vcl/ldp.c \
+ $(libvppcom_la_SOURCES)
+
++libdmm_vcl_la_CPPFLAGS = $(AM_CPPFLAGS) -I$(top_srcdir)/../../../../release/include
++
++libdmm_vcl_la_LIBADD = $(libdmm_vcl_la_DEPENDENCIES) -lpthread -lrt -ldl
++
++libdmm_vcl_la_SOURCES += \
++ vcl/dmm_vcl_adpt.c \
++ $(libvcl_ldpreload_la_SOURCES)
++
+ nobase_include_HEADERS += \
+ vcl/ldp_socket_wrapper.h \
+ vcl/ldp_glibc_socket.h \
+ vcl/ldp.h
+
+-noinst_PROGRAMS += \
++bin_PROGRAMS += \
+ vcl_test_server \
+ vcl_test_client \
+ sock_test_server \
+diff --git a/src/vcl/ldp.c b/src/vcl/ldp.c
+index d31cd2c..e386855 100644
+--- a/src/vcl/ldp.c
++++ b/src/vcl/ldp.c
+@@ -1669,7 +1669,7 @@ send (int fd, const void *buf, size_t n, int flags)
+ getpid (), fd, fd, func_str, sid, sid, buf, n, flags);
+
+ size = vppcom_session_sendto (sid, (void *) buf, n, flags, NULL);
+- if (size != VPPCOM_OK)
++ if (size <= VPPCOM_OK)
+ {
+ errno = -size;
+ size = -1;
+--
+1.8.3.1
+