3 # Copyright (c) 2017 Intel Corporation
5 # Licensed under the Apache License, Version 2.0 (the "License");
6 # you may not use this file except in compliance with the License.
7 # You may obtain a copy of the License at
9 # http://www.apache.org/licenses/LICENSE-2.0
11 # Unless required by applicable law or agreed to in writing, software
12 # distributed under the License is distributed on an "AS IS" BASIS,
13 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 # See the License for the specific language governing permissions and
15 # limitations under the License.
18 cd $(dirname ${BASH_SOURCE[0]})/..
20 echo "------------------------------------------------------------------------------"
21 echo " VNF_CORE exported as $VNF_CORE"
22 echo "------------------------------------------------------------------------------"
24 HUGEPGSZ=`cat /proc/meminfo | grep Hugepagesize | cut -d : -f 2 | tr -d ' '`
25 MODPROBE="/sbin/modprobe"
27 DPDK_DOWNLOAD="Not initialized"
28 DPDK_DIR=$VNF_CORE/dpdk
32 # Sets QUIT variable so script will finish.
49 read -p "Enter Proxy : " proxy
50 export http_proxy=$proxy
51 export https_proxy=$proxy
52 echo "Acquire::http::proxy \"$http_proxy\";" | sudo tee -a /etc/apt/apt.conf > /dev/null
53 echo "Acquire::https::proxy \"$http_proxy\";" | sudo tee -a /etc/apt/apt.conf > /dev/null
55 wget -T 20 -t 3 --spider http://www.google.com > /dev/null 2>&1
56 if [ "$?" != 0 ]; then
57 echo -e "No Internet connection. Proxy incorrect? Try again"
58 echo -e "eg: http://<proxy>:<port>"
63 echo "Network connectivity successful."
68 TITLE="Environment setup."
70 TEXT[1]="Check OS and network connection"
72 TEXT[2]="Select DPDK RTE version"
73 FUNC[2]="select_dpdk_rte_ver"
77 # a. Check for OS dependencies
78 source /etc/os-release
79 if [[ $VERSION_ID != "16.04" ]] ; then
80 echo "WARNING: It is recommended to use Ubuntu 16.04..Your version is "$VERSION_ID
82 echo "Ubuntu 16.04 OS requirement met..."
85 echo "Checking network connectivity..."
86 # b. Check for internet connections
87 wget -T 20 -t 3 --spider http://www.google.com > /dev/null 2>&1
88 if [ "$?" != 0 ]; then
90 read -p "No Internet connection. Are you behind a proxy (y/n)? " yn
92 [Yy]* ) $SETUP_PROXY ; return;;
93 [Nn]* ) echo "Please check your internet connection..." ; exit;;
94 * ) "Please answer yes or no.";;
98 echo "Network connectivity successful."
100 select_dpdk_rte_ver()
103 TITLE="Select the DPDK RTE version"
105 echo "[1] DPDK 16.04"
106 echo "[2] DPDK 16.11"
107 echo "[3] DPDK 17.02"
108 echo "[4] DPDK 17.05"
112 read -p "Select DPDK version to be used: " yn
114 [1]* ) DPDK_RTE_VER=16.04 ; return;;
115 [2]* ) DPDK_RTE_VER=16.11 ; return;;
116 [3]* ) DPDK_RTE_VER=17.02 ; return;;
117 [4]* ) DPDK_RTE_VER=17.05 ; return;;
118 * ) echo " Invalid selection...";;
125 TITLE="Download and Install"
127 TEXT[1]="Agree to download"
128 FUNC[1]="get_agreement_download"
129 TEXT[2]="Download packages"
130 FUNC[2]="install_libs"
131 TEXT[3]="Download DPDK zip"
132 FUNC[3]="download_dpdk_zip"
133 TEXT[4]="Build and Install DPDK"
134 FUNC[4]="install_dpdk"
135 TEXT[5]="Setup hugepages"
136 FUNC[5]="setup_hugepages"
138 get_agreement_download()
141 echo "List of packages needed for VNFs build and installation:"
142 echo "-------------------------------------------------------"
143 echo "1. DPDK version $DPDK_RTE_VER"
144 echo "2. build-essential"
145 echo "3. linux-headers-generic"
148 echo "6. libpcap-dev"
150 echo "8. and other library dependencies"
152 read -p "We need download above mentioned package. Press (y/n) to continue? " yn
158 * ) "Please answer yes or no.";;
165 echo "Install libs needed to build and run VNFs..."
167 if [ ! -e "$file_name" ]; then
168 echo "Please choose option '2.Agree to download' first"
171 file_name=".download"
172 if [ -e "$file_name" ]; then
177 sudo apt-get -y install build-essential linux-headers-$(uname -r) git unzip libpcap0.8-dev gcc \
178 make libc6 libc6-dev g++-multilib libzmq3-dev libcurl4-openssl-dev net-tools wget gcc unzip \
179 libpcap-dev libncurses-dev libedit-dev pciutils liblua5.2-dev libncursesw5-dev
185 echo "Download DPDK zip"
187 if [ ! -e "$file_name" ]; then
188 echo "Please choose option '2.Agree to download' first"
191 DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-$DPDK_RTE_VER.zip"
193 if [ ! -e ${DPDK_DOWNLOAD##*/} ] ; then
194 wget ${DPDK_DOWNLOAD}
196 unzip -o ${DPDK_DOWNLOAD##*/}
197 mv $VNF_CORE/dpdk-$DPDK_RTE_VER $VNF_CORE/dpdk
204 if [ ! -d "$DPDK_DIR" ]; then
205 echo "Please choose option '4 Download DPDK zip'"
209 export RTE_TARGET=x86_64-native-linuxapp-gcc
213 if [ $DPDK_RTE_VER == "16.04" ] ; then
214 echo "Apply dpdk custom patches..."
215 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-management.patch
216 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-Rx-hang-when-disable-LLDP.patch
217 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-status-change-interrupt.patch
218 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-VF-bonded-device-link-down.patch
219 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/disable-acl-debug-logs.patch
220 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/set-log-level-to-info.patch
223 make -j install T=$RTE_TARGET
224 if [ $? -ne 0 ] ; then
225 echo "Failed to build dpdk, please check the errors."
229 if [ $? -ne 0 ] ; then
230 sudo $MODPROBE -v uio
231 sudo $INSMOD $RTE_TARGET/kmod/igb_uio.ko
232 sudo cp -f $RTE_TARGET/kmod/igb_uio.ko /lib/modules/$(uname -r)
233 echo "uio" | sudo tee -a /etc/modules
234 echo "igb_uio" | sudo tee -a /etc/modules
244 if [[ "$HUGEPGSZ" = "2048kB" ]] ; then
247 if [ ! "`grep nr_hugepages /etc/sysctl.conf`" ] ; then
248 echo "vm.nr_hugepages=$Pages" | sudo tee /etc/sysctl.conf
252 sudo service procps start
254 grep -s '/dev/hugepages' /proc/mounts
255 if [ $? -ne 0 ] ; then
256 echo "Creating /mnt/huge and mounting as hugetlbfs"
257 sudo mkdir -p /mnt/huge
258 sudo mount -t hugetlbfs nodev /mnt/huge
259 echo "nodev /mnt/huge hugetlbfs defaults 0 0" | sudo tee -a /etc/fstab > /dev/null
267 TEXT[1]="Build all VNFs (vACL, vCGNAPT, vFW, UDP_Replay)"
274 if [ ! -d "$DPDK_DIR" ]; then
275 echo "Please choose option '4 Download DPDK zip'"
279 if [ ! -d "$DPDK_DIR/x86_64-native-linuxapp-gcc" ]; then
280 echo "Please choose option '5 Build and Install DPDK'"
284 export RTE_SDK=$DPDK_DIR
285 export RTE_TARGET=x86_64-native-linuxapp-gcc
288 make || { echo -e "\nVNF: Make failed\n"; }
294 #--- Add non intractive option to build vnfs
295 if [[ "$1" = "true" ]];then
296 DPDK_VER=("" "16.04" "16.11" "17.02" "17.05")
298 for item in "${DPDK_VER[@]}"; do
299 if [[ "$member" == "$item" ]]; then
300 DPDK_RTE_VER="$member"
305 echo "Install required libraries..."
309 echo "Download dpdk for VNF build..."
315 echo "Setup hugepages..."
328 SETUP_PROXY="setup_http_proxy"
335 while [ "$QUIT" == "0" ]; do
337 for s in $(seq ${#STEPS[@]}) ; do
340 echo "----------------------------------------------------------"
341 echo " Step $s: ${TITLE}"
342 echo "----------------------------------------------------------"
344 for i in $(seq ${#TEXT[@]}) ; do
345 echo "[$OPTION_NUM] ${TEXT[i]}"
346 OPTIONS[$OPTION_NUM]=${FUNC[i]}
350 # Clear TEXT and FUNC arrays before next step
357 echo "[$OPTION_NUM] Exit Script"
358 OPTIONS[$OPTION_NUM]="quit"
363 ${OPTIONS[our_entry]} ${our_entry}
365 if [ "$QUIT" == "0" ] ; then
367 echo -n "Press enter to continue ..."; read
372 echo "Installation successfully complete."
379 if [ $? -ne 0 ]; then
380 echo -n "Checking for user permission.. "
381 echo "Password-less sudo user must run this script" 1>&2
385 NON_INTERACTIVE=false
387 DPDK_VERSION=$DPDK_RTE_VER
400 export http_proxy="${i#*=}"
401 export https_proxy="${i#*=}"
404 DPDK_VERSION="${i#*=}"
407 echo "CommandLine options:"
408 echo "===================="
409 echo "1. Intractive mode:"
410 echo "./tools/vnf_build.sh or ./tools/vnf_build.sh -i"
412 echo "1. Non-Intractive mode:"
413 echo "./tools/vnf_build.sh -s [Default dpdk 17.02]"
414 echo "If system is behind proxy use -p=<proxy> and to use different dpdk version use -d=<dpdk>"
415 echo "eg: ./tools/vnf_build.sh -s -p=http://proxy.com -d=17.05"
416 echo 'Note:- supported dpdk version ("16.04" "16.11" "17.02" "17.05")'
428 if [[ "$INTERACTIVE" == "true" ]]; then
433 if [[ "$NON_INTERACTIVE" == "true" ]]; then
434 non_interactive $NON_INTERACTIVE $DPDK_VERSION