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 CIVETWEB_DOWNLOAD="Not initialized"
29 DPDK_DIR=$VNF_CORE/dpdk
33 # Sets QUIT variable so script will finish.
50 read -p "Enter Proxy : " proxy
51 export http_proxy=$proxy
52 export https_proxy=$proxy
53 echo "Acquire::http::proxy \"$http_proxy\";" | sudo tee -a /etc/apt/apt.conf > /dev/null
54 echo "Acquire::https::proxy \"$http_proxy\";" | sudo tee -a /etc/apt/apt.conf > /dev/null
56 wget -T 20 -t 3 --spider http://www.google.com > /dev/null 2>&1
57 if [ "$?" != 0 ]; then
58 echo -e "No Internet connection. Proxy incorrect? Try again"
59 echo -e "eg: http://<proxy>:<port>"
64 echo "Network connectivity successful."
69 TITLE="Environment setup."
71 TEXT[1]="Check OS and network connection"
73 TEXT[2]="Select DPDK RTE version"
74 FUNC[2]="select_dpdk_rte_ver"
78 # a. Check for OS dependencies
79 source /etc/os-release
80 if [[ $VERSION_ID != "16.04" ]] ; then
81 echo "WARNING: It is recommended to use Ubuntu 16.04..Your version is "$VERSION_ID
83 echo "Ubuntu 16.04 OS requirement met..."
86 echo "Checking network connectivity..."
87 # b. Check for internet connections
88 wget -T 20 -t 3 --spider http://www.google.com > /dev/null 2>&1
89 if [ "$?" != 0 ]; then
91 read -p "No Internet connection. Are you behind a proxy (y/n)? " yn
93 [Yy]* ) $SETUP_PROXY ; return;;
94 [Nn]* ) echo "Please check your internet connection..." ; exit;;
95 * ) "Please answer yes or no.";;
99 echo "Network connectivity successful."
101 select_dpdk_rte_ver()
104 TITLE="Select the DPDK RTE version"
106 echo "[1] DPDK 16.04"
107 echo "[2] DPDK 16.11"
108 echo "[3] DPDK 17.02"
109 echo "[4] DPDK 17.05"
113 read -p "Select DPDK version to be used: " yn
115 [1]* ) DPDK_RTE_VER=16.04 ; return;;
116 [2]* ) DPDK_RTE_VER=16.11 ; return;;
117 [3]* ) DPDK_RTE_VER=17.02 ; return;;
118 [4]* ) DPDK_RTE_VER=17.05 ; return;;
119 * ) echo " Invalid selection...";;
126 TITLE="Download and Install"
128 TEXT[1]="Agree to download"
129 FUNC[1]="get_agreement_download"
130 TEXT[2]="Download packages"
131 FUNC[2]="install_libs"
132 TEXT[3]="Download DPDK zip"
133 FUNC[3]="download_dpdk_zip"
134 TEXT[4]="Build and Install DPDK"
135 FUNC[4]="install_dpdk"
136 TEXT[5]="Setup hugepages"
137 FUNC[5]="setup_hugepages"
138 TEXT[6]="Download and Build civetweb"
139 FUNC[6]="download_civetweb_zip"
141 get_agreement_download()
144 echo "List of packages needed for VNFs build and installation:"
145 echo "-------------------------------------------------------"
146 echo "1. DPDK version $DPDK_RTE_VER"
147 echo "2. build-essential"
148 echo "3. linux-headers-generic"
151 echo "6. libpcap-dev"
153 echo "8. and other library dependencies"
155 read -p "We need download above mentioned package. Press (y/n) to continue? " yn
161 * ) "Please answer yes or no.";;
168 echo "Install libs needed to build and run VNFs..."
170 if [ ! -e "$file_name" ]; then
171 echo "Please choose option '2.Agree to download' first"
174 file_name=".download"
175 if [ -e "$file_name" ]; then
180 sudo apt-get -y install build-essential linux-headers-$(uname -r) git unzip libpcap0.8-dev gcc \
181 make libc6 libc6-dev g++-multilib libzmq3-dev libcurl4-openssl-dev net-tools wget gcc unzip \
182 libpcap-dev libncurses-dev libedit-dev pciutils liblua5.2-dev libncursesw5-dev libjson-c-dev libssl-dev
188 echo "Download DPDK zip"
190 if [ ! -e "$file_name" ]; then
191 echo "Please choose option '2.Agree to download' first"
194 DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-$DPDK_RTE_VER.zip"
196 if [ ! -e ${DPDK_DOWNLOAD##*/} ] ; then
197 wget ${DPDK_DOWNLOAD}
199 unzip -o ${DPDK_DOWNLOAD##*/}
200 mv $VNF_CORE/dpdk-$DPDK_RTE_VER $VNF_CORE/dpdk
203 download_civetweb_zip()
205 echo "Download CIVETWEB zip"
206 CIVETWEB_DOWNLOAD="https://sourceforge.net/projects/civetweb/files/1.9/CivetWeb_V1.9.zip"
207 if [ ! -e ${CIVETWEB_DOWNLOAD##*/} ] ; then
208 wget ${CIVETWEB_DOWNLOAD}
210 unzip -o ${CIVETWEB_DOWNLOAD##*/}
211 mv $VNF_CORE/civetweb-master $VNF_CORE/civetweb
212 pushd $VNF_CORE/civetweb
221 if [ ! -d "$DPDK_DIR" ]; then
222 echo "Please choose option '4 Download DPDK zip'"
226 export RTE_TARGET=x86_64-native-linuxapp-gcc
230 if [ $DPDK_RTE_VER == "16.04" ] ; then
231 echo "Apply dpdk custom patches..."
232 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-management.patch
233 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-Rx-hang-when-disable-LLDP.patch
234 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-status-change-interrupt.patch
235 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-VF-bonded-device-link-down.patch
236 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/disable-acl-debug-logs.patch
237 patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/set-log-level-to-info.patch
240 make -j16 install T=$RTE_TARGET
241 if [ $? -ne 0 ] ; then
242 echo "Failed to build dpdk, please check the errors."
246 if [ $? -ne 0 ] ; then
247 sudo $MODPROBE -v uio
248 sudo $INSMOD $RTE_TARGET/kmod/igb_uio.ko
249 sudo cp -f $RTE_TARGET/kmod/igb_uio.ko /lib/modules/$(uname -r)
250 echo "uio" | sudo tee -a /etc/modules
251 echo "igb_uio" | sudo tee -a /etc/modules
254 if [ -d "dpdk/usertools/" ]; then
255 cp usertools/dpdk-devbind.py /usr/sbin/dpdk-devbind
257 cp tools/dpdk_nic_bind.py /usr/sbin/dpdk-devbind
266 if [[ "$HUGEPGSZ" = "2048kB" ]] ; then
269 if [ ! "`grep nr_hugepages /etc/sysctl.conf`" ] ; then
270 echo "vm.nr_hugepages=$Pages" | sudo tee /etc/sysctl.conf
274 sudo service procps start
276 grep -s '/dev/hugepages' /proc/mounts
277 if [ $? -ne 0 ] ; then
278 echo "Creating /mnt/huge and mounting as hugetlbfs"
279 sudo mkdir -p /mnt/huge
280 sudo mount -t hugetlbfs nodev /mnt/huge
281 echo "nodev /mnt/huge hugetlbfs defaults 0 0" | sudo tee -a /etc/fstab > /dev/null
289 TEXT[1]="Build all VNFs (vACL, vCGNAPT, vFW, UDP_Replay)"
296 if [ ! -d "$DPDK_DIR" ]; then
297 echo "Please choose option '4 Download DPDK zip'"
301 if [ ! -d "$DPDK_DIR/x86_64-native-linuxapp-gcc" ]; then
302 echo "Please choose option '5 Build and Install DPDK'"
306 export RTE_SDK=$DPDK_DIR
307 export RTE_TARGET=x86_64-native-linuxapp-gcc
310 make || { echo -e "\nVNF: Make failed\n"; }
316 #--- Add non intractive option to build vnfs
317 if [[ "$1" = "true" ]];then
318 DPDK_VER=("" "16.04" "16.11" "17.02" "17.05")
320 for item in "${DPDK_VER[@]}"; do
321 if [[ "$member" == "$item" ]]; then
322 DPDK_RTE_VER="$member"
327 echo "Install required libraries..."
331 echo "Download dpdk for VNF build..."
334 echo "Download civetweb for VNF build..."
335 download_civetweb_zip
340 echo "Setup hugepages..."
353 SETUP_PROXY="setup_http_proxy"
360 while [ "$QUIT" == "0" ]; do
362 for s in $(seq ${#STEPS[@]}) ; do
365 echo "----------------------------------------------------------"
366 echo " Step $s: ${TITLE}"
367 echo "----------------------------------------------------------"
369 for i in $(seq ${#TEXT[@]}) ; do
370 echo "[$OPTION_NUM] ${TEXT[i]}"
371 OPTIONS[$OPTION_NUM]=${FUNC[i]}
375 # Clear TEXT and FUNC arrays before next step
382 echo "[$OPTION_NUM] Exit Script"
383 OPTIONS[$OPTION_NUM]="quit"
388 ${OPTIONS[our_entry]} ${our_entry}
390 if [ "$QUIT" == "0" ] ; then
392 echo -n "Press enter to continue ..."; read
397 echo "Installation successfully complete."
404 if [ $? -ne 0 ]; then
405 echo -n "Checking for user permission.. "
406 echo "Password-less sudo user must run this script" 1>&2
410 NON_INTERACTIVE=false
412 DPDK_VERSION=$DPDK_RTE_VER
425 export http_proxy="${i#*=}"
426 export https_proxy="${i#*=}"
429 DPDK_VERSION="${i#*=}"
432 echo "CommandLine options:"
433 echo "===================="
434 echo "1. Intractive mode:"
435 echo "./tools/vnf_build.sh or ./tools/vnf_build.sh -i"
437 echo "1. Non-Intractive mode:"
438 echo "./tools/vnf_build.sh -s [Default dpdk 17.02]"
439 echo "If system is behind proxy use -p=<proxy> and to use different dpdk version use -d=<dpdk>"
440 echo "eg: ./tools/vnf_build.sh -s -p=http://proxy.com -d=17.05"
441 echo 'Note:- supported dpdk version ("16.04" "16.11" "17.02" "17.05")'
453 if [[ "$INTERACTIVE" == "true" ]]; then
458 if [[ "$NON_INTERACTIVE" == "true" ]]; then
459 non_interactive $NON_INTERACTIVE $DPDK_VERSION