Updating release notes for OPNFV Euphrates 5.1
[samplevnf.git] / tools / vnf_build.sh
index 342ac11..0a085a6 100755 (executable)
@@ -24,8 +24,10 @@ echo "--------------------------------------------------------------------------
 HUGEPGSZ=`cat /proc/meminfo  | grep Hugepagesize | cut -d : -f 2 | tr -d ' '`
 MODPROBE="/sbin/modprobe"
 INSMOD="/sbin/insmod"
-DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-16.04.zip"
+DPDK_DOWNLOAD="Not initialized"
+CIVETWEB_DOWNLOAD="Not initialized"
 DPDK_DIR=$VNF_CORE/dpdk
+DPDK_RTE_VER="17.02"
 
 #
 # Sets QUIT variable so script will finish.
@@ -68,6 +70,8 @@ step_1()
         CONFIG_NUM=1
         TEXT[1]="Check OS and network connection"
         FUNC[1]="setup_env"
+        TEXT[2]="Select DPDK RTE version"
+        FUNC[2]="select_dpdk_rte_ver"
 }
 setup_env()
 {
@@ -94,6 +98,28 @@ setup_env()
        fi
        echo "Network connectivity successful."
 }
+select_dpdk_rte_ver()
+{
+
+       TITLE="Select the DPDK RTE version"
+       CONFIG_NUM=1
+       echo "[1] DPDK 16.04"
+       echo "[2] DPDK 16.11"
+       echo "[3] DPDK 17.02"
+       echo "[4] DPDK 17.05"
+       echo
+
+       while true; do
+               read -p "Select DPDK version to be used: " yn
+                       case $yn in
+                               [1]* ) DPDK_RTE_VER=16.04 ; return;;
+                               [2]* ) DPDK_RTE_VER=16.11 ; return;;
+                               [3]* ) DPDK_RTE_VER=17.02 ; return;;
+                               [4]* ) DPDK_RTE_VER=17.05 ; return;;
+                               * ) echo " Invalid selection...";;
+                       esac
+       done
+}
 
 step_2()
 {
@@ -109,13 +135,15 @@ step_2()
        FUNC[4]="install_dpdk"
        TEXT[5]="Setup hugepages"
        FUNC[5]="setup_hugepages"
+       TEXT[6]="Download and Build civetweb"
+       FUNC[6]="download_civetweb_zip"
 }
 get_agreement_download()
 {
        echo
        echo "List of packages needed for VNFs build and installation:"
        echo "-------------------------------------------------------"
-       echo "1. DPDK version 16.04"
+       echo "1. DPDK version $DPDK_RTE_VER"
        echo "2. build-essential"
        echo "3. linux-headers-generic"
        echo "4. git"
@@ -150,7 +178,9 @@ install_libs()
        fi
        sudo apt-get update
        sudo apt-get -y install build-essential linux-headers-$(uname -r) git unzip libpcap0.8-dev gcc \
-               make libc6 libc6-dev g++-multilib libzmq3-dev libcurl4-openssl-dev
+               make libc6 libc6-dev g++-multilib libzmq3-dev libcurl4-openssl-dev net-tools wget gcc unzip \
+                libpcap-dev libncurses-dev libedit-dev pciutils liblua5.2-dev libncursesw5-dev libjson0 \
+               libjson0-dev libssl-dev
        touch .download
 }
 
@@ -162,12 +192,27 @@ download_dpdk_zip()
                echo "Please choose option '2.Agree to download' first"
                return
        fi
+       DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-$DPDK_RTE_VER.zip"
        rm -rf $DPDK_DIR
        if [ ! -e ${DPDK_DOWNLOAD##*/} ] ; then
                wget ${DPDK_DOWNLOAD}
        fi
        unzip -o ${DPDK_DOWNLOAD##*/}
-       mv $VNF_CORE/dpdk-16.04 $VNF_CORE/dpdk
+       mv $VNF_CORE/dpdk-$DPDK_RTE_VER $VNF_CORE/dpdk
+}
+
+download_civetweb_zip()
+{
+       echo "Download CIVETWEB zip"
+       CIVETWEB_DOWNLOAD="https://sourceforge.net/projects/civetweb/files/1.9/CivetWeb_V1.9.zip"
+       if [ ! -e ${CIVETWEB_DOWNLOAD##*/} ] ; then
+               wget ${CIVETWEB_DOWNLOAD}
+       fi
+       unzip -o ${CIVETWEB_DOWNLOAD##*/}
+       mv $VNF_CORE/civetweb-master $VNF_CORE/civetweb
+       pushd $VNF_CORE/civetweb
+       make lib
+       popd
 }
 
 install_dpdk()
@@ -182,14 +227,18 @@ install_dpdk()
        export RTE_TARGET=x86_64-native-linuxapp-gcc
 
        pushd $DPDK_DIR
-       echo "Apply dpdk custom patches..."
-       patch -p0 < $VNF_CORE/patches/dpdk_custom_patch/rte_pipeline.patch
-       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-management.patch
-       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-Rx-hang-when-disable-LLDP.patch
-       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-status-change-interrupt.patch
-       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-VF-bonded-device-link-down.patch
-
-       make -j install T=$RTE_TARGET
+
+       if [ $DPDK_RTE_VER == "16.04" ] ; then
+               echo "Apply dpdk custom patches..."
+                       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-management.patch
+                       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-Rx-hang-when-disable-LLDP.patch
+                       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-status-change-interrupt.patch
+                       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-VF-bonded-device-link-down.patch
+                       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/disable-acl-debug-logs.patch
+                       patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/set-log-level-to-info.patch
+       fi
+
+       make -j16 install T=$RTE_TARGET
        if [ $? -ne 0 ] ; then
                echo "Failed to build dpdk, please check the errors."
                return
@@ -203,6 +252,11 @@ install_dpdk()
                echo "igb_uio" | sudo tee -a /etc/modules
                sudo depmod
        fi
+  if [ -d "dpdk/usertools/" ]; then
+           cp usertools/dpdk-devbind.py /usr/sbin/dpdk-devbind
+       else
+           cp tools/dpdk_nic_bind.py /usr/sbin/dpdk-devbind
+  fi
        popd
 }
 
@@ -233,7 +287,7 @@ step_3()
 {
         TITLE="Build VNFs"
         CONFIG_NUM=1
-                               TEXT[1]="Build all VNFs (vACL, vCGNAPT, vFW)"
+                               TEXT[1]="Build all VNFs (vACL, vCGNAPT, vFW, UDP_Replay)"
         FUNC[1]="build_vnfs"
 }
 
@@ -258,22 +312,19 @@ build_vnfs()
        popd
 }
 
-#--- Add non intractive option to build vnfs
-if [[ "$1" = "--silient" ]];then
+non_interactive()
+{
+  #--- Add non intractive option to build vnfs
+  if [[ "$1" = "true" ]];then
+                 DPDK_VER=("" "16.04" "16.11" "17.02" "17.05")
+                 member="$2"
+                 for item in "${DPDK_VER[@]}"; do
+                          if [[ "$member" == "$item" ]]; then
+                     DPDK_RTE_VER="$member"
+                   fi
+    done
     pushd $VNF_CORE
 
-    echo "Setup proxy if needed..."
-    http_proxy=$2
-    https_proxy=$3
-    if [[ "$http_proxy" != "" ]]; then
-         export http_proxy=$http_proxy
-         export https_proxy=$http_proxy
-    fi
-
-    if [[ "$https_proxy" != "" ]]; then
-         export https_proxy=$https_proxy
-    fi
-
     echo "Install required libraries..."
     touch .agree
     install_libs
@@ -281,6 +332,9 @@ if [[ "$1" = "--silient" ]];then
     echo "Download dpdk for VNF build..."
     download_dpdk_zip
 
+    echo "Download civetweb for VNF build..."
+    download_civetweb_zip
+
     echo "Build dpdk..."
     install_dpdk
 
@@ -292,62 +346,117 @@ if [[ "$1" = "--silient" ]];then
 
     popd
     exit
-fi
-
-SETUP_PROXY="setup_http_proxy"
-STEPS[1]="step_1"
-STEPS[2]="step_2"
-STEPS[3]="step_3"
+  fi
+}
 
-QUIT=0
+interactive()
+{
+  SETUP_PROXY="setup_http_proxy"
+  STEPS[1]="step_1"
+  STEPS[2]="step_2"
+  STEPS[3]="step_3"
+
+  QUIT=0
+
+  while [ "$QUIT" == "0" ]; do
+    OPTION_NUM=1
+    for s in $(seq ${#STEPS[@]}) ; do
+      ${STEPS[s]}
+
+      echo "----------------------------------------------------------"
+      echo " Step $s: ${TITLE}"
+      echo "----------------------------------------------------------"
+
+      for i in $(seq ${#TEXT[@]}) ; do
+              echo "[$OPTION_NUM] ${TEXT[i]}"
+              OPTIONS[$OPTION_NUM]=${FUNC[i]}
+              let "OPTION_NUM+=1"
+      done
+
+      # Clear TEXT and FUNC arrays before next step
+      unset TEXT
+      unset FUNC
+
+      echo ""
+    done
+
+    echo "[$OPTION_NUM] Exit Script"
+    OPTIONS[$OPTION_NUM]="quit"
+    echo ""
+    echo -n "Option: "
+    read our_entry
+    echo ""
+    ${OPTIONS[our_entry]} ${our_entry}
+
+    if [ "$QUIT" == "0" ] ; then
+      echo
+      echo -n "Press enter to continue ..."; read
+      clear
+      continue
+      exit
+    fi
+    echo "Installation successfully complete."
+  done
+}
 
+# -- main script
 clear
-
-echo -n "Checking for user permission.. "
 sudo -n true
 if [ $? -ne 0 ]; then
-   echo "Password-less sudo user must run this script" 1>&2
-   exit 1
+  echo -n "Checking for user permission.. "
+  echo "Password-less sudo user must run this script" 1>&2
+  exit 1
 fi
-echo "Done"
-clear
 
-while [ "$QUIT" == "0" ]; do
-        OPTION_NUM=1
-        for s in $(seq ${#STEPS[@]}) ; do
-                ${STEPS[s]}
-
-                echo "----------------------------------------------------------"
-                echo " Step $s: ${TITLE}"
-                echo "----------------------------------------------------------"
-
-                for i in $(seq ${#TEXT[@]}) ; do
-                        echo "[$OPTION_NUM] ${TEXT[i]}"
-                        OPTIONS[$OPTION_NUM]=${FUNC[i]}
-                        let "OPTION_NUM+=1"
-                done
-
-                # Clear TEXT and FUNC arrays before next step
-                unset TEXT
-                unset FUNC
-
-                echo ""
-        done
-
-        echo "[$OPTION_NUM] Exit Script"
-        OPTIONS[$OPTION_NUM]="quit"
-        echo ""
-        echo -n "Option: "
-        read our_entry
-        echo ""
-        ${OPTIONS[our_entry]} ${our_entry}
-
-        if [ "$QUIT" == "0" ] ; then
-                echo
-                echo -n "Press enter to continue ..."; read
-                clear
-                continue
-                exit
-        fi
-        echo "Installation successfully complete."
+NON_INTERACTIVE=false
+INTERACTIVE=true
+DPDK_VERSION=$DPDK_RTE_VER
+
+for i in "$@"
+do
+case $i in
+               -s|--silient)
+               NON_INTERACTIVE=true
+  INTERACTIVE=false
+               ;;
+               -i|--interactive)
+               INTERACTIVE=true
+               ;;
+               -p=*|--proxy=*)
+               export http_proxy="${i#*=}"
+               export https_proxy="${i#*=}"
+               ;;
+               -d=*|--dpdk=*)
+               DPDK_VERSION="${i#*=}"
+               ;;
+               -h|--help)
+               echo "CommandLine options:"
+               echo "===================="
+               echo "1. Intractive mode:"
+               echo "./tools/vnf_build.sh or ./tools/vnf_build.sh -i"
+               echo
+               echo "1. Non-Intractive mode:"
+               echo "./tools/vnf_build.sh -s [Default dpdk 17.02]"
+               echo "If system is behind proxy use -p=<proxy> and to use different dpdk version use -d=<dpdk>"
+               echo "eg: ./tools/vnf_build.sh -s -p=http://proxy.com -d=17.05"
+               echo 'Note:- supported dpdk version ("16.04" "16.11" "17.02" "17.05")'
+               echo
+               exit
+               ;;
+               --default)
+               INTERACTIVE=true
+               ;;
+               *)
+  ;;
+esac
 done
+
+if [[ "$INTERACTIVE" == "true" ]]; then
+                       interactive
+                       exit
+fi
+
+if [[ "$NON_INTERACTIVE" == "true" ]]; then
+                       non_interactive $NON_INTERACTIVE $DPDK_VERSION
+                       exit
+fi