From 3a8b1b01c87ede23390657b906f14a49d89624f6 Mon Sep 17 00:00:00 2001 From: Swarup Nayak Date: Thu, 19 Apr 2018 11:03:19 +0530 Subject: Simple test setup using VM User can test their app. Steps at: https://wiki.fd.io/view/DMM Change-Id: I0ff33b60cea34a441e91253ae918e1a5720fbaf8 Signed-off-by: Swarup Nayak Signed-off-by: Yalei Wang Signed-off-by: yinzhongyi --- CMakeLists.txt | 10 +-- doc/Build_DMM.md | 6 +- resources/extras/Vagrantfile | 64 +++++++++++++ resources/extras/env.sh | 7 ++ resources/extras/install_prereq.sh | 39 ++++++++ scripts/build.sh | 178 ++++++++++++++++++++++++++----------- scripts/build_dpdk.sh | 16 +++- 7 files changed, 261 insertions(+), 59 deletions(-) create mode 100644 resources/extras/Vagrantfile create mode 100644 resources/extras/env.sh create mode 100644 resources/extras/install_prereq.sh mode change 100644 => 100755 scripts/build_dpdk.sh diff --git a/CMakeLists.txt b/CMakeLists.txt index 590a5a5..7016a70 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -98,9 +98,9 @@ SET(JSON_C_SRC ${CMAKE_CURRENT_LIST_DIR}/thirdparty/json/json-c-0.12.1) if(EXISTS "${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1.tar.gz") SET(JSON_DOWNLOAD_CMD tar -xvf ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1.tar.gz -C ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1 --strip-components 1) else() - SET(JSON_DOWNLOAD_CMD wget --no-check-certificate -O json-c-0.12.1.tar.gz ${JSON_C_URL} && tar -xvf ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1.tar.gz -C ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1 --strip-components 1) + SET(JSON_DOWNLOAD_CMD wget --no-check-certificate -O json-c-0.12.1.tar.gz ${JSON_C_URL} || rm -f json-c-0.12.1.tar.gz && tar -xvf ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1.tar.gz -C ${JSON_C_DOWNLOAD_DIR}/json-c-0.12.1 --strip-components 1) endif() -INCLUDE(ExternalProject) +INCLUDE(ExternalProject) ExternalProject_Add( JSON DOWNLOAD_DIR ${JSON_C_DOWNLOAD_DIR} @@ -116,19 +116,19 @@ SET(SECUREC_SRC ${CMAKE_CURRENT_LIST_DIR}/thirdparty/SecureC/src) SET(SECUREC_SRC_H ${CMAKE_CURRENT_LIST_DIR}/thirdparty/SecureC/include) if(WITH_SECUREC_LIB) -INCLUDE(ExternalProject) +INCLUDE(ExternalProject) ExternalProject_Add( SECUREC SOURCE_DIR ${SECUREC_SRC} BUILD_IN_SOURCE 1 - CONFIGURE_COMMAND "" + CONFIGURE_COMMAND "" BUILD_COMMAND COMMAND make -j 8 INSTALL_COMMAND cp -f ${SECUREC_SRC}/../lib/libsecurec.so ${LIB_PATH_SHARED}/ ) endif() SET(GLOG_SRC ${CMAKE_CURRENT_LIST_DIR}/thirdparty/glog/glog-0.3.4) -INCLUDE(ExternalProject) +INCLUDE(ExternalProject) ExternalProject_Add( GLOG SOURCE_DIR ${GLOG_SRC} diff --git a/doc/Build_DMM.md b/doc/Build_DMM.md index abb5313..bda16b0 100644 --- a/doc/Build_DMM.md +++ b/doc/Build_DMM.md @@ -1,6 +1,10 @@ # 1. Introduction: This document purpose is to build the DMM and run applications on it. +Note: + + Users can easily build the DMM by running DMM/scripts/build.sh, which contains following steps. + # 2. Build DPDK: DPDK need to be built first for DMM RTE memory dependency. @@ -10,7 +14,7 @@ ``` #wget http://static.dpdk.org/rel/dpdk-16.04.tar.xz #tar xvf dpdk-16.04.tar.xz - #vi dpdk-16.04/config/common_base //make CONFIG_RTE_BUILD_SHARED_LIB=y + #vi dpdk-16.04/config/common_base //make CONFIG_RTE_BUILD_SHARED_LIB=y CONFIG_RTE_EXEC_ENV=y CONFIG_RTE_LIBRTE_EAL=y #cd dpdk-16.04 #make install T=x86_64-native-linuxapp-gcc DESTDIR=/root/dpdk_build/tmp2 #cd x86_64-native-linuxapp-gcc diff --git a/resources/extras/Vagrantfile b/resources/extras/Vagrantfile new file mode 100644 index 0000000..70c0d78 --- /dev/null +++ b/resources/extras/Vagrantfile @@ -0,0 +1,64 @@ +# -*- 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" + #config.vm.box = "centos/7" + #config.vm.box_version = "1708.01" + #config.ssh.insert_key = false + else + config.vm.box = "fdio-csit/ubuntu-14.04.4_2016-05-25_1.0" + end + config.vm.box_check_update = false + + # Create DMM client and server VM's + config.vm.define "dmm-test-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__),"../../scripts/build.sh"), :args => "/dmm vagrant" + end + config.vm.define "dmm-test-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__),"../../scripts/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" + 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'] || 4096) + + 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/resources/extras/env.sh b/resources/extras/env.sh new file mode 100644 index 0000000..96ad346 --- /dev/null +++ b/resources/extras/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/resources/extras/install_prereq.sh b/resources/extras/install_prereq.sh new file mode 100644 index 0000000..29e9cf2 --- /dev/null +++ b/resources/extras/install_prereq.sh @@ -0,0 +1,39 @@ +#!/bin/bash -x +log_file="/dmm/resources/extras/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 diff --git a/scripts/build.sh b/scripts/build.sh index 9da32dd..d09df32 100755 --- a/scripts/build.sh +++ b/scripts/build.sh @@ -12,11 +12,27 @@ # See the License for the specific language governing permissions and # limitations under the License. ######################################################################### -#!/bin/bash +#!/bin/bash -x -DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" -BUILD_DIR=${DIR}/../build -LIB_PATH=${DIR}/../release/lib64 +log_file="/dmm/scripts/build_log.txt-`date +'%Y-%m-%d_%H-%M-%S'`" +exec 1> >(tee -a "$log_file") 2>&1 + +# Get Command Line arguements if present +DMM_DIR=$1 +if [ "x$1" != "x" ]; then + DMM_DIR=$1 +else + DMM_DIR=`dirname $0`/../ +fi + +echo 0:$0 +echo 1:$1 +echo 2:$2 +echo DMM_DIR: $DMM_DIR + +#DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )" +BUILD_DIR=${DMM_DIR}/build +LIB_PATH=${DMM_DIR}/release/lib64 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') @@ -41,39 +57,44 @@ DPDK_INSTALL_PATH=/usr #set and check the environment for Linux #set env if [ "$OS_ID" == "ubuntu" ]; then - apt-get install git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump + 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" == "debian" ]; then - apt-get install git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump + 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 - yum install git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump + 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 - yum install git cmake gcc g++ automake libtool wget lsof lshw pciutils net-tools tcpdump + 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 #check env -isInFile=$(cat /etc/default/grub | grep -c "default_hugepagesz=1G hugepagesz=1G hugepages=8") -if [ $isInFile -eq 0 ]; then - echo "hugepage need to be set, set it by doing" - echo "1. vi /etc/default/grub " - echo "2. add the line GRUB_CMDLINE_LINUX_DEFAULT="default_hugepagesz=1G hugepagesz=1G hugepages=8" " - echo "3. perform " update-grub " in ubuntu " grub2-mkconfig -o /boot/grub2/grub.cfg " in centos " - echo "4. reboot" - exit -else - echo "hugepage has been set already....." +sudo sysctl -w vm.nr_hugepages=1024 +HUGEPAGES=`sysctl -n vm.nr_hugepages` +if [ $HUGEPAGES != 1024 ]; then + echo "ERROR: Unable to get 1024 hugepages, only got $HUGEPAGES. Cannot finish." + exit fi #DPDK will be having dependancy on linux headers if [ "$OS_ID" == "ubuntu" ]; then - apt-get install git build-essential linux-headers-`uname -r` + apt-get -y install git build-essential linux-headers-`uname -r` elif [ "$OS_ID" == "debian" ]; then - apt-get install git build-essential linux-headers-`uname -r` + apt-get -y install git build-essential linux-headers-`uname -r` elif [ "$OS_ID" == "centos" ]; then - yum groupinstall "Development Tools" - yum install kernel-headers + sudo yum groupinstall -y "Development Tools" + sudo yum install -y kernel-headers elif [ "$OS_ID" == "opensuse" ]; then - yum groupinstall "Development Tools" - yum install kernel-headers + sudo yum groupinstall -y "Development Tools" + sudo yum install -y kernel-headers fi hugepageTotal=$(cat /proc/meminfo | grep -c "HugePages_Total: 0") @@ -94,37 +115,35 @@ if [ $hugepageSize -ne 0 ]; then exit fi -pdpe1gbFlag=$(cat /proc/cpuinfo | grep -c "pdpe1gb") -if [ $pdpe1gbFlag -eq 0 ]; then - echo "/proc/cpuinfo doesn't include pdpe1gb to make hugepage work" - exit -fi mkdir /mnt/nstackhuge -p -sudo mount -t hugetlbfs -o pagesize=1G none /mnt/nstackhuge/ - +sudo mount -t hugetlbfs -o pagesize=2M none /mnt/nstackhuge/ sudo mkdir -p /var/run/ip_module/ #===========build DPDK================ if [ "$OS_ID" == "centos" ]; then - ./build_dpdk.sh + bash -x $DMM_DIR/scripts/build_dpdk.sh else - mkdir -p $DPDK_DOWNLOAD_PATH - cd $DPDK_DOWNLOAD_PATH - rm -rf dpdk-16.04/ - wget https://fast.dpdk.org/rel/dpdk-16.04.tar.xz - tar xvf dpdk-16.04.tar.xz - cd dpdk-16.04/ + if [ ! -d $DPDK_DOWNLOAD_PATH ]; then + mkdir -p $DPDK_DOWNLOAD_PATH + + cd $DPDK_DOWNLOAD_PATH + rm -rf dpdk-16.04/ + wget https://fast.dpdk.org/rel/dpdk-16.04.tar.xz --no-check-certificate + tar xvf dpdk-16.04.tar.xz + cd dpdk-16.04/ + + 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_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 + make install T=x86_64-native-linuxapp-gcc DESTDIR=${DPDK_INSTALL_PATH} -j 4 + cd x86_64-native-linuxapp-gcc + make - make install T=x86_64-native-linuxapp-gcc DESTDIR=${DPDK_INSTALL_PATH} - cd x86_64-native-linuxapp-gcc - make + fi fi export LD_LIBRARY_PATH=$LIB_PATH @@ -132,15 +151,72 @@ export NSTACK_LOG_ON=DBG #===========build DMM================= echo "DMM build started....." -cd $LIB_PATH -sudo rm -rf * +#cd $LIB_PATH && rm -rf * -cd ../../thirdparty/glog/glog-0.3.4/ -sudo autoreconf -ivf +cd $DMM_DIR/thirdparty/glog/glog-0.3.4/ && sudo autoreconf -ivf cd $BUILD_DIR -sudo rm -rf * -sudo cmake .. -sudo make -j 8 +rm -rf * +cmake .. +make -j 8 + +############### Preapre APP test directory +echo -e "\e[41m Preapring APP test directory.....\e[0m" + + +sudo mkdir -p $DMM_DIR/config/app_test +cd $DMM_DIR/config/app_test + +if [ "$OS_ID" == "ubuntu" ]; then + ifaddress1=$(ifconfig eth1 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}') + echo $ifaddress1 + ifaddress2=$(ifconfig eth2 | grep 'inet addr' | cut -d: -f2 | awk '{print $1}') + echo $ifaddress2 +elif [ "$OS_ID" == "centos" ]; then + ifaddress1=$(ifconfig enp0s8 | grep 'inet' | cut -d: -f2 | awk '{print $2}') + echo $ifaddress1 + ifaddress2=$(ifconfig enp0s9 | grep 'inet' | cut -d: -f2 | awk '{print $2}') + echo $ifaddress2 +fi + +echo '{ + "default_stack_name": "kernel", + "module_list": [ + { + "stack_name": "kernel", + "function_name": "kernel_stack_register", + "libname": "./", + "loadtype": "static", + "deploytype": "1", + "maxfd": "1024", + "minfd": "0", + "priorty": "1", + "stackid": "0", + }, + ] +}' | sudo tee module_config.json + +echo '{ + "ip_route": [ + { + "subnet": "'$ifaddress1'/24", + "type": "nstack-kernel", + }, + { + "subnet": "'$ifaddress2'/24", + "type": "nstack-kernel", + }, + ], + "prot_route": [ + { + "proto_type": "1", + "type": "nstack-kernel", + }, + { + "proto_type": "2", + "type": "nstack-kernel", + } + ], +}' | sudo tee rd_config.json echo "DMM build finished....." diff --git a/scripts/build_dpdk.sh b/scripts/build_dpdk.sh old mode 100644 new mode 100755 index be5fc2c..80a78b6 --- a/scripts/build_dpdk.sh +++ b/scripts/build_dpdk.sh @@ -13,7 +13,7 @@ # See the License for the specific language governing permissions and # limitations under the License. ######################################################################### -#!/bin/sh +#!/bin/bash -x echo "check whether dpdk installed" cur_directory=${PWD} @@ -30,7 +30,10 @@ cd ~ mkdir -p rpmbuild/SOURCES cd ~/rpmbuild/SOURCES + +if [ ! -s dpdk-16.04.tar.gz ]; then wget http://dpdk.org/browse/dpdk/snapshot/dpdk-16.04.tar.gz +fi tar xzvf dpdk-16.04.tar.gz cp dpdk-16.04/pkg/dpdk.spec ~/rpmbuild/SOURCES/ @@ -61,10 +64,19 @@ sed -i '77a sed -i 's!CONFIG_RTE_BUILD_SHARED_LIB=.*!CONFIG_RTE_BUILD_SHARED_LIB sed -i '78a sed -i 's!CONFIG_RTE_LIBRTE_EAL=.*!CONFIG_RTE_LIBRTE_EAL=y!1' config/common_base' dpdk.spec echo "build the dependence" -sudo yum-builddep -y dpdk.spec +#sudo yum-builddep -y dpdk.spec + +sudo yum install -y libpcap-devel python-sphinx inkscape + echo "generate the rpm package" rpmbuild -ba dpdk.spec --define "_sourcedir ${PWD}" +if [ $? -eq 0 ]; then + echo "rpm build success" +else + echo "rpm build error" + exit +fi echo "install the rpm" cd ../RPMS/x86_64/ -- cgit 1.2.3-korg