From 9f683fadb09aaea5a07f4673f8bbc3a7ddd38afc Mon Sep 17 00:00:00 2001 From: rainbow_0206 Date: Tue, 14 Aug 2018 20:04:16 +0800 Subject: Feat: integrate VPP hoststack into dmm Change-Id: I64c361cc93e02ed89ed40eb4440c36326d2dfa03 Signed-off-by: Qing Chang Signed-off-by: Yalei Wang Signed-off-by: rainbow_0206 --- CMakeLists.txt | 4 + scripts/build_vpp.sh | 29 +++ src/nSocket/nstack_rd/nstack_rd_init.c | 1 + stacks/vpp/adapt/dmm_vcl.h | 36 ++++ stacks/vpp/adapt/dmm_vcl_adpt.c | 172 ++++++++++++++++ stacks/vpp/configure/module_config.json | 30 +++ stacks/vpp/configure/rd_config.json | 26 +++ stacks/vpp/configure/startup.conf | 21 ++ stacks/vpp/configure/vpp_config | 6 + stacks/vpp/doc/README.md | 115 +++++++++++ .../0001-Fix-modify-makefile-to-adapt-dmm.patch | 72 +++++++ stacks/vpp/vagrant/Vagrantfile | 63 ++++++ stacks/vpp/vagrant/build.sh | 224 +++++++++++++++++++++ stacks/vpp/vagrant/env.sh | 7 + stacks/vpp/vagrant/install_prereq.sh | 39 ++++ 15 files changed, 845 insertions(+) create mode 100755 scripts/build_vpp.sh create mode 100644 stacks/vpp/adapt/dmm_vcl.h create mode 100644 stacks/vpp/adapt/dmm_vcl_adpt.c create mode 100644 stacks/vpp/configure/module_config.json create mode 100644 stacks/vpp/configure/rd_config.json create mode 100644 stacks/vpp/configure/startup.conf create mode 100644 stacks/vpp/configure/vpp_config create mode 100644 stacks/vpp/doc/README.md create mode 100644 stacks/vpp/patch/0001-Fix-modify-makefile-to-adapt-dmm.patch create mode 100644 stacks/vpp/vagrant/Vagrantfile create mode 100644 stacks/vpp/vagrant/build.sh create mode 100644 stacks/vpp/vagrant/env.sh create mode 100644 stacks/vpp/vagrant/install_prereq.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index a261306..2f5e9f0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -149,6 +149,10 @@ ADD_DEPENDENCIES(DPDK dmm_api) ADD_CUSTOM_TARGET(pkg-rpm COMMAND sh ../scripts/generate_dmm_rpm.sh) ADD_CUSTOM_TARGET(pkg-deb COMMAND sh ../scripts/generate_dmm_deb.sh) + +ADD_CUSTOM_TARGET(vpp-stack COMMAND sh ../scripts/build_vpp.sh) +ADD_DEPENDENCIES(vpp-stack DPDK) + ADD_CUSTOM_TARGET(checkstyle COMMAND bash ${CMAKE_CURRENT_LIST_DIR}/scripts/checkstyle.sh -c) ADD_CUSTOM_TARGET(fixstyle diff --git a/scripts/build_vpp.sh b/scripts/build_vpp.sh new file mode 100755 index 0000000..555aa9f --- /dev/null +++ b/scripts/build_vpp.sh @@ -0,0 +1,29 @@ +#!/bin/bash +######################################################################### +# +# 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. +######################################################################### + +set -x + +cd ../stacks/vpp + +git clone https://gerrit.fd.io/r/vpp + +cd vpp +git checkout origin/stable/1804 -b vpp_1804_br +cp ../adapt/* src/vcl/ +git am ../patch/* +make UNATTENDED=yes install-dep +make build diff --git a/src/nSocket/nstack_rd/nstack_rd_init.c b/src/nSocket/nstack_rd/nstack_rd_init.c index c9d7f7d..b3d4158 100644 --- a/src/nSocket/nstack_rd/nstack_rd_init.c +++ b/src/nSocket/nstack_rd/nstack_rd_init.c @@ -41,6 +41,7 @@ rd_stack_plane_map g_nstack_plane_info[] = { {{RD_LINUX_NAME}, {RD_LINUX_PLANENAME}, -1}, {"rsocket", "nstack-rsocket", -1}, {{RD_STACKX_NAME}, {RD_STACKX_PLANENAME}, -1}, + {"vpp_hoststack", "nstack-vpp", -1}, }; /* *INDENT-ON* */ 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..1b2b9a9 --- /dev/null +++ b/stacks/vpp/adapt/dmm_vcl_adpt.c @@ -0,0 +1,172 @@ +/* + * 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 +#include +#include +#include "dmm_vcl.h" +#include "nstack_dmm_api.h" // nstack_socket_ops* +#include // 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; +} + +#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_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..49b7ca9 --- /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": "vpp_hoststack", + "function_name": "vpphs_stack_register", + "libname": "../lib64/libdmm_vcl.so", + "loadtype": "dynmic", + "deploytype": "4", + "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..2ea10d1 --- /dev/null +++ b/stacks/vpp/configure/rd_config.json @@ -0,0 +1,26 @@ +{ + "ip_route": [ + { + "subnet": "192.168.1.1/24", + "type": "nstack-vpp", + }, + { + "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-vpp", + }, + { + "proto_type": "2", + "type": "nstack-kernel", + } + ], +} diff --git a/stacks/vpp/configure/startup.conf b/stacks/vpp/configure/startup.conf new file mode 100644 index 0000000..ada7fdf --- /dev/null +++ b/stacks/vpp/configure/startup.conf @@ -0,0 +1,21 @@ +unix { + interactive + log /var/log/vpp/vpp.log + cli-listen localhost:5002 + full-coredump + exec /etc/vpp/vpp_config +} + +api-trace { + on +} + +cpu { + main-core 2 +} + +dpdk { + socket-mem 1024 + uio-driver igb_uio + dev 0000:00:09.0 +} diff --git a/stacks/vpp/configure/vpp_config b/stacks/vpp/configure/vpp_config new file mode 100644 index 0000000..56d80b5 --- /dev/null +++ b/stacks/vpp/configure/vpp_config @@ -0,0 +1,6 @@ +set int state GigabitEthernet0/9/0 up +set int ip addr GigabitEthernet0/9/0 192.168.1.1/24 +show version +show version verbose +show cpu +show int diff --git a/stacks/vpp/doc/README.md b/stacks/vpp/doc/README.md new file mode 100644 index 0000000..e09aefe --- /dev/null +++ b/stacks/vpp/doc/README.md @@ -0,0 +1,115 @@ +# 1. What is VPP Host Stack +VPP's host stack is a user space implementation of a number of transport, +session and application layer protocols that leverages VPP's existing +protocol stack. + +# 2. How to use VPP Host Stack + +## How to integrate VPP Host Stack into DMM +The file CMakeList.txt defined the compiling process, including downloading +the vpp code and patch it. The patch will modify the makefile to adapt dmm. + +Target 'libdmm_vcl' could not be get automatically unless you run +'make vpp-stack' manually. It will compile the adaption code and link the +libraries of vpp and finally generate the library of "libdmm_vcl.so". + + +## Compile +```sh + #cd dmm/build && cmake .. + #make vpp-statck +``` +Note: + After these processes, libdmm_vcl.so library would be generated in +vpp/build-root/install-vpp_debug-native/vpp/lib64/. + +##Start VPP Host Stack +- Steps 1: copy the plugins to /usr/lib/. +```sh + #cp -r vpp/build-root/install-vpp_debug-native/vpp/lib64/vpp_plugins /usr/lib/ +``` + +- Steps 2: load dpdk network card driver manually. +```sh + #cd dpdk-18.02/x86_64-native-linuxapp-gcc/kmod/ + #modprobe uio + #insmod igb_uio.ko +``` + +- Steps 3: choose a network card that is not in use and down it. +```sh + #ifconfig eth1 down +``` +- Steps 4: copy the config file and start vpp +```sh + #cp dmm/stacks/vpp/configure/startup.conf /etc/vpp/ + #cp dmm/stacks/vpp/configure/vpp_config /etc/vpp/ + #cd vpp/build-root/install-vpp_debug-native/vpp/bin + #./vpp -c /etc/vpp/startup.conf +``` +Note: + 1.modify the dev of dpdk in startup.conf. + 2.modify the interface name and ip in vpp_config. + +## Test app +Note: + Before testing, we should anotation the dmm code that "close (listenFd);" in + function process_server_accept_thread for server. Otherwize the app can + not send and recieve packets. + +- Steps 1: copy the libdmm_vcl.so to dmm/release/lib64/ +- Steps 2: copy the config file from dmm/stacks/vpp/configure/*.json to + dmm/release/bin and modify the rd_config.json. +```sh + #vim rd_config.json + //set "subnet": "192.168.21.1/24" +``` +Note: + Means dmm will hijack data from subnet 192.168.21.* + +- Steps 3: Communication test between machine A(as server) with machine B + (as client) + +##### Run in machine A +```sh + #cd dmm/release/bin/ + #./vs_epoll -p 20000 -d 192.168.21.180 -a 10000 -s 192.168.21.181 -l 1000 -t 500000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 50000 -e 10 -x 1 +``` +Note: + Means the current machine would be server, and it's +destination address is 192.168.21.180 (client address), +source address is 192.168.21.181(server address) + +##### Run in machine B +``` + #cd dmm/release/bin/ + #./vc_common -p 20000 -d 192.168.21.181 -a 10000 -s 192.168.21.180 -l 1000 -t 500000 -i 0 -f 1 -r 20000 -n 1 -w 10 -u 50000 -e 10 -x 1 +``` +Note: + Means the current machine would be client, and it's +destination address is 192.168.21.181 (server address), +source address is 192.168.21.180(client address) + +# 3. Document description + +(dmm/stacks/vpp/) + +## configure folder +##### module_config.json +- module_config.json is for configuring dmm protocol stack module + +##### rd_config.json +- rd_config.json is to choose which module is better to go through. It will go + through vpp host protocol stack when RD type is nstack-vpp + +## patch folder +- modify the makefile to compile the adapt code. + +## adapt folder +##### dmm_vcl_adpt.c && dmm_vcl.h +- vpp host stack adaptation code, including initialization and adaptation functions. + +# 4. More Information +- https://wiki.fd.io/view/DMM +- https://wiki.fd.io/view/VPP +- https://wiki.fd.io/view/VPP/HostStack 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 +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 + diff --git a/stacks/vpp/vagrant/Vagrantfile b/stacks/vpp/vagrant/Vagrantfile new file mode 100644 index 0000000..5cf102c --- /dev/null +++ b/stacks/vpp/vagrant/Vagrantfile @@ -0,0 +1,63 @@ +# -*- mode: ruby -*- +# vi: set ft=ruby : + +Vagrant.configure(2) do |config| + + # Pick the right distro and bootstrap, default is ubuntu1604 + distro = ( ENV['DMM_VAGRANT_DISTRO'] || "ubuntu") + if distro == 'centos7' + config.vm.box = "puppetlabs/centos-7.2-64-nocm" + else + config.vm.box = "puppetlabs/ubuntu-16.04-64-nocm" + end + config.vm.box_check_update = false + + # Create DMM client and server VM's + config.vm.define "dmm-vpp-server" do |server| + server.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"install_prereq.sh") + server.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh"), :args => "/dmm vagrant" + end + config.vm.define "dmm-vpp-client" do |client| + client.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"install_prereq.sh") + client.vm.provision :shell, :path => File.join(File.dirname(__FILE__),"build.sh"), :args => "/dmm vagrant" + end + + + # vagrant-cachier caches apt/yum etc to speed subsequent + # vagrant up + # to enable, run + # vagrant plugin install vagrant-cachier + # + if Vagrant.has_plugin?("vagrant-cachier") + config.cache.scope = :box + end + + # Define some physical ports for your VMs to be used by DPDK + nics = (ENV['DMM_VAGRANT_NICS'] || "2").to_i(10) + for i in 1..nics + config.vm.network "private_network", type: "dhcp" + # config.vm.network "private_network", ip: "172.28.128.200" + # config.vm.network "private_network", ip: "172.28.128.201" + end + + # use http proxy if avaiable + if ENV['http_proxy'] && Vagrant.has_plugin?("vagrant-proxyconf") + config.proxy.http = ENV['http_proxy'] + config.proxy.https = ENV['https_proxy'] + config.proxy.no_proxy = "localhost,127.0.0.1" + end + + vmcpu=(ENV['DMM_VAGRANT_VMCPU'] || 4) + vmram=(ENV['DMM_VAGRANT_VMRAM'] || 5120) + + config.ssh.forward_agent = true + config.ssh.forward_x11 = true + + config.vm.provider "virtualbox" do |vb| + vb.customize ["modifyvm", :id, "--ioapic", "on"] + vb.memory = "#{vmram}" + vb.cpus = "#{vmcpu}" + + config.vm.synced_folder "../../../", "/dmm", type: "rsync" + end +end diff --git a/stacks/vpp/vagrant/build.sh b/stacks/vpp/vagrant/build.sh new file mode 100644 index 0000000..1ed343b --- /dev/null +++ b/stacks/vpp/vagrant/build.sh @@ -0,0 +1,224 @@ +#!/bin/bash -x +######################################################################### +# 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. +######################################################################### + +set -x + +TIMESTAMP=$(date +%Y-%m-%d_%H-%M-%S) +log_file="/tmp/build_log.txt-$TIMESTAMP" +exec 1> >(tee -a "$log_file") 2>&1 + +# Get Command Line arguements if present +TEMP_DIR=$1 +if [ "x$1" != "x" ]; then + TEMP_DIR=$1 + DMM_BUILD_DIR=${TEMP_DIR}/build + DPDK_BUILD_SCRIPT_DIR=${DMM_BUILD_DIR}/../scripts + VPP_BUILD_DIR=${TEMP_DIR}/stacks/vpp/vpp/ +else + TEMP_DIR=`dirname $(readlink -f $0)`/.. + DMM_BUILD_DIR=${TEMP_DIR}/../../build + DPDK_BUILD_SCRIPT_DIR=${DMM_BUILD_DIR}/../scripts + VPP_BUILD_DIR=${TEMP_DIR} +fi + +echo 0:$0 +echo 1:$1 +echo 2:$2 +echo TEMP_DIR: $TEMP_DIR +echo DMM_BUILD_DIR: $DMM_BUILD_DIR +echo DPDK_BUILD_SCRIPT_DIR: $DPDK_BUILD_SCRIPT_DIR +echo VPP_BUILD_DIR: $VPP_BUILD_DIR + +OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') +OS_VERSION_ID=$(grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') +KERNEL_OS=`uname -o` +KERNEL_MACHINE=`uname -m` +KERNEL_RELEASE=`uname -r` +KERNEL_VERSION=`uname -v` + +echo KERNEL_OS: $KERNEL_OS +echo KERNEL_MACHINE: $KERNEL_MACHINE +echo KERNEL_RELEASE: $KERNEL_RELEASE +echo KERNEL_VERSION: $KERNEL_VERSION +echo OS_ID: $OS_ID +echo OS_VERSION_ID: $OS_ID + +#DPDK download path +DPDK_DOWNLOAD_PATH=/tmp/dpdk + +#dpdk installation path +DPDK_INSTALL_PATH=/usr + +#set and check the environment for Linux +if [ "$OS_ID" == "ubuntu" ]; then + export DEBIAN_FRONTEND=noninteractive + export DEBCONF_NONINTERACTIVE_SEEN=true + + APT_OPTS="--assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" + sudo apt-get update ${APT_OPTS} + sudo DEBIAN_FRONTEND=noninteractive apt-get install -yq git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump libpcre3 libpcre3-dev zlibc zlib1g zlib1g-dev vim ethtool unzip +elif [ "$OS_ID" == "debian" ]; then + echo "not tested for debian and exit" + exit 1 + export DEBIAN_FRONTEND=noninteractive + export DEBCONF_NONINTERACTIVE_SEEN=true + + APT_OPTS="--assume-yes --no-install-suggests --no-install-recommends -o Dpkg::Options::=\"--force-confdef\" -o Dpkg::Options::=\"--force-confold\"" + sudo apt-get update ${APT_OPTS} + sudo DEBIAN_FRONTEND=noninteractive apt-get install -yq git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump libpcre3 libpcre3-dev zlibc zlib1g zlib1g-dev vim +elif [ "$OS_ID" == "centos" ]; then + sudo yum install -y git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump vim sudo yum-utils pcre-devel zlib-devel +elif [ "$OS_ID" == "opensuse" ]; then + echo "not tested for opensuse and exit" + exit 1 + sudo yum install -y git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump vim sudo yum-utils pcre-devel zlib-devel +fi + +#DPDK will be having dependancy on linux headers +if [ "$OS_ID" == "ubuntu" ]; then + sudo apt-get -y install git build-essential linux-headers-`uname -r` + sudo apt-get -y install libnuma-dev +elif [ "$OS_ID" == "debian" ]; then + sudo apt-get -y install git build-essential linux-headers-`uname -r` +elif [ "$OS_ID" == "centos" ]; then + sudo yum groupinstall -y "Development Tools" + sudo yum install -y kernel-headers + sudo yum install -y numactl-devel +elif [ "$OS_ID" == "opensuse" ]; then + sudo yum groupinstall -y "Development Tools" + sudo yum install -y kernel-headers +fi +#===========build DPDK================ + +if [ ! -d /usr/include/dpdk ] || [ ! -d /usr/share/dpdk ] || [ ! -d /usr/lib/modules/4.4.0-31-generic/extra/dpdk ]; then + mkdir -p $DPDK_DOWNLOAD_PATH + + cd $DPDK_DOWNLOAD_PATH + wget -N https://fast.dpdk.org/rel/dpdk-18.02.tar.xz --no-check-certificate + tar xvf dpdk-18.02.tar.xz + cd dpdk-18.02/ + + + sed -i 's!CONFIG_RTE_EXEC_ENV=.*!CONFIG_RTE_EXEC_ENV=y!1' config/common_base + sed -i 's!CONFIG_RTE_BUILD_SHARED_LIB=.*!CONFIG_RTE_BUILD_SHARED_LIB=y!1' config/common_base + sed -i 's!CONFIG_RTE_LIBRTE_EAL=.*!CONFIG_RTE_LIBRTE_EAL=y!1' config/common_base + sed -i 's!CONFIG_RTE_EAL_PMD_PATH=.*!CONFIG_RTE_EAL_PMD_PATH="/tmp/dpdk/drivers/"!1' config/common_base + + sudo make install T=x86_64-native-linuxapp-gcc DESTDIR=${DPDK_INSTALL_PATH} -j 4 + + mkdir -p /tmp/dpdk/drivers/ + cp -f /usr/lib/librte_mempool_ring.so /tmp/dpdk/drivers/ +fi + +#===========check running env ================= +hugepagesize=$(cat /proc/meminfo | grep Hugepagesize | awk -F " " {'print$2'}) +if [ "$hugepagesize" == "2048" ]; then + pages=2560 +elif [ "$hugepagesize" == "1048576" ]; then + pages=5 +fi +sudo sysctl -w vm.nr_hugepages=$pages +HUGEPAGES=`sysctl -n vm.nr_hugepages` +if [ $HUGEPAGES != $pages ]; then + echo "ERROR: Unable to get $pages hugepages, only got $HUGEPAGES. Cannot finish." + exit +fi + + +hugepageTotal=$(cat /proc/meminfo | grep -c "HugePages_Total: 0") +if [ $hugepageTotal -ne 0 ]; then + echo "HugePages_Total is zero" + exit +fi + +hugepageFree=$(cat /proc/meminfo | grep -c "HugePages_Free: 0") +if [ $hugepageFree -ne 0 ]; then + echo "HugePages_Free is zero" + exit +fi + +hugepageSize=$(cat /proc/meminfo | grep -c "Hugepagesize: 0 kB") +if [ $hugepageSize -ne 0 ]; then + echo "Hugepagesize is zero" + exit +fi + + +sudo mkdir /mnt/nstackhuge -p +if [ "$hugepagesize" == "2048" ]; then +sudo mount -t hugetlbfs -o pagesize=2M none /mnt/nstackhuge/ +elif [ "$hugepagesize" == "1048576" ]; then + sudo mount -t hugetlbfs -o pagesize=1G none /mnt/nstackhuge/ +fi + +#===========build DMM================= +echo "DMM build started....." + +cd $DMM_BUILD_DIR +ldconfig +rm -rf * +cmake .. +make -j 8 +if [ $? -eq 0 ]; then + echo "DMM build is SUCCESS" +else + echo "DMM build has FAILED" + exit 1 +fi +echo "DMM build finished....." + +git config --global http.sslVerify false +#===========build vpp=========== +echo "vpp build started....." +make vpp-stack +if [ $? -eq 0 ]; then + echo "vpp build is SUCCESS" +else + echo "vpp build has FAILED" + exit 1 +fi +echo "vpp build finished....." + +#===========set environment=========== +sudo mkdir -p /etc/vpp/ +cp /dmm/stacks/vpp/configure/startup.conf /etc/vpp/ +cp /dmm/stacks/vpp/configure/vpp_config /etc/vpp/ + +sudo cp -r /dmm/stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/lib64/vpp_plugins/ /usr/lib/ + +sudo modprobe uio +sudo insmod ${DPDK_DOWNLOAD_PATH}/dpdk-18.02/x86_64-native-linuxapp-gcc/kmod/igb_uio.ko + +sudo ifconfig enp0s9 down + +if [ "$OS_ID" == "centos" ]; then + ifaddress1=$(ifconfig enp0s9 | grep 'inet' | cut -d: -f2 | awk '{print $2}') + echo $ifaddress1 + ifaddresscut=$(ifconfig enp0s9 | grep 'inet' | head -n 1 | awk -F " " '{print $2}' | awk -F "." '{print $1"."$2"."$3}') + echo $ifaddresscut +elif [ "$OS_ID" == "ubuntu" ]; then + ifaddress1=$(ifconfig enp0s9 | grep 'inet' | head -n 1 | cut -d: -f2 | awk '{print $1}') + echo $ifaddress1 +fi + +cd /etc/vpp/ + +sudo sed -i 's!192.168.1.1!'$ifaddress1'!1' vpp_config + +cd $DMM_BUILD_DIR/../release/bin +sudo cp ../../stacks/vpp/configure/*.json ./ +sudo cp ../../stacks/vpp/vpp/build-root/install-vpp_debug-native/vpp/lib64/libdmm_vcl.so ../lib64/ +sudo sed -i 's!192.168.1.1!'$ifaddresscut'.0!1' rd_config.json diff --git a/stacks/vpp/vagrant/env.sh b/stacks/vpp/vagrant/env.sh new file mode 100644 index 0000000..96ad346 --- /dev/null +++ b/stacks/vpp/vagrant/env.sh @@ -0,0 +1,7 @@ +#!/usr/bin/env bash + +#export DMM_VAGRANT_DISTRO="ubuntu1604" +export DMM_VAGRANT_DISTRO="centos7" +export DMM_VAGRANT_NICS=2 +export DMM_VAGRANT_VMCPU=4 +export DMM_VAGRANT_VMRAM=8192 diff --git a/stacks/vpp/vagrant/install_prereq.sh b/stacks/vpp/vagrant/install_prereq.sh new file mode 100644 index 0000000..2e636c2 --- /dev/null +++ b/stacks/vpp/vagrant/install_prereq.sh @@ -0,0 +1,39 @@ +#!/bin/bash -x +log_file="/tmp/pre_install_log.txt-`date +'%Y-%m-%d_%H-%M-%S'`" +exec 1> >(tee -a "$log_file") 2>&1 + +if [ "$(uname)" <> "Darwin" ]; then + OS_ID=$(grep '^ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') + OS_VERSION_ID=$(grep '^VERSION_ID=' /etc/os-release | cut -f2- -d= | sed -e 's/\"//g') +fi + +if [ "$OS_ID" == "ubuntu" ]; then + # Standard update + upgrade dance + cat << EOF >> /etc/apt/sources.list + deb http://in.archive.ubuntu.com/ubuntu/ trusty main restricted + deb-src http://in.archive.ubuntu.com/ubuntu/ trusty main restricted + deb http://in.archive.ubuntu.com/ubuntu/ trusty-updates main restricted + deb-src http://in.archive.ubuntu.com/ubuntu/ trusty-updates main restricted + deb http://in.archive.ubuntu.com/ubuntu/ trusty universe + deb-src http://in.archive.ubuntu.com/ubuntu/ trusty universe + deb http://in.archive.ubuntu.com/ubuntu/ trusty-updates universe + deb-src http://in.archive.ubuntu.com/ubuntu/ trusty-updates universe + deb http://in.archive.ubuntu.com/ubuntu/ trusty multiverse + deb-src http://in.archive.ubuntu.com/ubuntu/ trusty multiverse + deb http://in.archive.ubuntu.com/ubuntu/ trusty-updates multiverse + deb-src http://in.archive.ubuntu.com/ubuntu/ trusty-updates multiverse + deb http://in.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse + deb-src http://in.archive.ubuntu.com/ubuntu/ trusty-backports main restricted universe multiverse + deb http://security.ubuntu.com/ubuntu trusty-security main restricted + deb-src http://security.ubuntu.com/ubuntu trusty-security main restricted + deb http://security.ubuntu.com/ubuntu trusty-security universe + deb-src http://security.ubuntu.com/ubuntu trusty-security universe + deb http://security.ubuntu.com/ubuntu trusty-security multiverse + deb-src http://security.ubuntu.com/ubuntu trusty-security multiverse + deb http://extras.ubuntu.com/ubuntu trusty main + deb-src http://extras.ubuntu.com/ubuntu trusty main +EOF +elif [ "$OS_ID" == "centos" ]; then + + echo centos +fi -- cgit 1.2.3-korg