conntrack: timer reset in reply traffic causes performance impact
[samplevnf.git] / tools / vnf_build.sh
1 #! /bin/bash
2 #
3 # Copyright (c) 2017 Intel Corporation
4 #
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
8 #
9 #      http://www.apache.org/licenses/LICENSE-2.0
10 #
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.
16 #
17
18 cd $(dirname ${BASH_SOURCE[0]})/..
19 export VNF_CORE=$PWD
20 echo "------------------------------------------------------------------------------"
21 echo " VNF_CORE exported as $VNF_CORE"
22 echo "------------------------------------------------------------------------------"
23
24 HUGEPGSZ=`cat /proc/meminfo  | grep Hugepagesize | cut -d : -f 2 | tr -d ' '`
25 MODPROBE="/sbin/modprobe"
26 INSMOD="/sbin/insmod"
27 DPDK_DOWNLOAD="http://dpdk.org/browse/dpdk/snapshot/dpdk-16.04.zip"
28 DPDK_DIR=$VNF_CORE/dpdk
29
30 #
31 # Sets QUIT variable so script will finish.
32 #
33 quit()
34 {
35         QUIT=$1
36 }
37
38 # Shortcut for quit.
39 q()
40 {
41         quit
42 }
43
44 setup_http_proxy()
45 {
46         while true; do
47                 echo
48                 read -p "Enter Proxy : " proxy
49                 export http_proxy=$proxy
50                 export https_proxy=$proxy
51                 echo "Acquire::http::proxy \"$http_proxy\";" | sudo tee -a /etc/apt/apt.conf > /dev/null
52                 echo "Acquire::https::proxy \"$http_proxy\";" | sudo tee -a /etc/apt/apt.conf > /dev/null
53
54                 wget -T 20 -t 3 --spider http://www.google.com > /dev/null 2>&1
55                 if [ "$?" != 0 ]; then
56                         echo -e "No Internet connection. Proxy incorrect? Try again"
57                         echo -e "eg: http://<proxy>:<port>"
58                         exit 1
59                 fi
60         return
61         done
62         echo "Network connectivity successful."
63 }
64
65 step_1()
66 {
67         TITLE="Environment setup."
68         CONFIG_NUM=1
69         TEXT[1]="Check OS and network connection"
70         FUNC[1]="setup_env"
71 }
72 setup_env()
73 {
74         # a. Check for OS dependencies
75         source /etc/os-release
76         if [[ $VERSION_ID != "16.04" ]] ; then
77                 echo "WARNING: It is recommended to use Ubuntu 16.04..Your version is "$VERSION_ID
78         else
79                 echo "Ubuntu 16.04 OS requirement met..."
80         fi
81         echo
82         echo "Checking network connectivity..."
83         # b. Check for internet connections
84         wget -T 20 -t 3 --spider http://www.google.com > /dev/null 2>&1
85         if [ "$?" != 0 ]; then
86                 while true; do
87                         read -p "No Internet connection. Are you behind a proxy (y/n)? " yn
88                         case $yn in
89                                 [Yy]* ) $SETUP_PROXY ; return;;
90                                 [Nn]* ) echo "Please check your internet connection..." ; exit;;
91                                 * ) "Please answer yes or no.";;
92                         esac
93                 done
94         fi
95         echo "Network connectivity successful."
96 }
97
98 step_2()
99 {
100         TITLE="Download and Install"
101         CONFIG_NUM=1
102         TEXT[1]="Agree to download"
103         FUNC[1]="get_agreement_download"
104         TEXT[2]="Download packages"
105         FUNC[2]="install_libs"
106         TEXT[3]="Download DPDK zip"
107         FUNC[3]="download_dpdk_zip"
108         TEXT[4]="Build and Install DPDK"
109         FUNC[4]="install_dpdk"
110         TEXT[5]="Setup hugepages"
111         FUNC[5]="setup_hugepages"
112 }
113 get_agreement_download()
114 {
115         echo
116         echo "List of packages needed for VNFs build and installation:"
117         echo "-------------------------------------------------------"
118         echo "1. DPDK version 16.04"
119         echo "2. build-essential"
120         echo "3. linux-headers-generic"
121         echo "4. git"
122         echo "5. unzip"
123         echo "6. libpcap-dev"
124         echo "7. make"
125         echo "8. and other library dependencies"
126         while true; do
127                 read -p "We need download above mentioned package. Press (y/n) to continue? " yn
128                 case $yn in
129                         [Yy]* )
130                                 touch .agree
131                                 return;;
132                         [Nn]* ) exit;;
133                         * ) "Please answer yes or no.";;
134                 esac
135         done
136 }
137
138 install_libs()
139 {
140         echo "Install libs needed to build and run VNFs..."
141         file_name=".agree"
142         if [ ! -e "$file_name" ]; then
143                 echo "Please choose option '2.Agree to download' first"
144                 return
145         fi
146         file_name=".download"
147         if [ -e "$file_name" ]; then
148                 clear
149                 return
150         fi
151         sudo apt-get update
152         sudo apt-get -y install build-essential linux-headers-$(uname -r) git unzip libpcap0.8-dev gcc \
153                 make libc6 libc6-dev g++-multilib libzmq3-dev libcurl4-openssl-dev
154         touch .download
155 }
156
157 download_dpdk_zip()
158 {
159         echo "Download DPDK zip"
160         file_name=".agree"
161         if [ ! -e "$file_name" ]; then
162                 echo "Please choose option '2.Agree to download' first"
163                 return
164         fi
165         rm -rf $DPDK_DIR
166         if [ ! -e ${DPDK_DOWNLOAD##*/} ] ; then
167                 wget ${DPDK_DOWNLOAD}
168         fi
169         unzip -o ${DPDK_DOWNLOAD##*/}
170         mv $VNF_CORE/dpdk-16.04 $VNF_CORE/dpdk
171 }
172
173 install_dpdk()
174 {
175         echo "Build DPDK"
176
177         if [ ! -d "$DPDK_DIR" ]; then
178      echo "Please choose option '4 Download DPDK zip'"
179      return
180         fi
181
182         export RTE_TARGET=x86_64-native-linuxapp-gcc
183
184         pushd $DPDK_DIR
185         echo "Apply dpdk custom patches..."
186         patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-management.patch
187         patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-Rx-hang-when-disable-LLDP.patch
188         patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-link-status-change-interrupt.patch
189         patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/i40e-fix-VF-bonded-device-link-down.patch
190
191         make -j install T=$RTE_TARGET
192         if [ $? -ne 0 ] ; then
193                 echo "Failed to build dpdk, please check the errors."
194                 return
195         fi
196         sudo modinfo igb_uio
197         if [ $? -ne 0 ] ; then
198                 sudo $MODPROBE -v uio
199                 sudo $INSMOD $RTE_TARGET/kmod/igb_uio.ko
200                 sudo cp -f $RTE_TARGET/kmod/igb_uio.ko /lib/modules/$(uname -r)
201                 echo "uio" | sudo tee -a /etc/modules
202                 echo "igb_uio" | sudo tee -a /etc/modules
203                 sudo depmod
204         fi
205         popd
206 }
207
208 setup_hugepages()
209 {
210         #----
211         Pages=16
212         if [[ "$HUGEPGSZ" = "2048kB" ]] ; then
213                 Pages=8192
214         fi
215         if [ ! "`grep nr_hugepages /etc/sysctl.conf`" ] ; then
216                 echo "vm.nr_hugepages=$Pages" | sudo tee /etc/sysctl.conf
217         fi
218         sudo sysctl -p
219
220         sudo service procps start
221
222         grep -s '/dev/hugepages' /proc/mounts
223         if [ $? -ne 0 ] ; then
224                 echo "Creating /mnt/huge and mounting as hugetlbfs"
225                 sudo mkdir -p /mnt/huge
226                 sudo mount -t hugetlbfs nodev /mnt/huge
227                 echo "nodev /mnt/huge hugetlbfs defaults 0 0" | sudo tee -a /etc/fstab > /dev/null
228         fi
229 }
230
231 step_3()
232 {
233         TITLE="Build VNFs"
234         CONFIG_NUM=1
235                                 TEXT[1]="Build all VNFs (vACL, vCGNAPT, vFW, UDP_Replay)"
236         FUNC[1]="build_vnfs"
237 }
238
239 build_vnfs()
240 {
241
242         if [ ! -d "$DPDK_DIR" ]; then
243      echo "Please choose option '4 Download DPDK zip'"
244      return
245         fi
246
247         if [ ! -d "$DPDK_DIR/x86_64-native-linuxapp-gcc" ]; then
248      echo "Please choose option '5 Build and Install DPDK'"
249      return
250         fi
251
252         export RTE_SDK=$DPDK_DIR
253         export RTE_TARGET=x86_64-native-linuxapp-gcc
254         pushd $VNF_CORE
255         make clean
256         make || { echo -e "\nVNF: Make failed\n"; }
257         popd
258 }
259
260 #--- Add non intractive option to build vnfs
261 if [[ "$1" = "--silient" ]];then
262     pushd $VNF_CORE
263
264     echo "Setup proxy if needed..."
265     http_proxy=$2
266     https_proxy=$3
267     if [[ "$http_proxy" != "" ]]; then
268          export http_proxy=$http_proxy
269          export https_proxy=$http_proxy
270     fi
271
272     if [[ "$https_proxy" != "" ]]; then
273          export https_proxy=$https_proxy
274     fi
275
276     echo "Install required libraries..."
277     touch .agree
278     install_libs
279
280     echo "Download dpdk for VNF build..."
281     download_dpdk_zip
282
283     echo "Build dpdk..."
284     install_dpdk
285
286     echo "Setup hugepages..."
287     setup_hugepages
288
289     echo "build VNFS..."
290     build_vnfs
291
292     popd
293     exit
294 fi
295
296 SETUP_PROXY="setup_http_proxy"
297 STEPS[1]="step_1"
298 STEPS[2]="step_2"
299 STEPS[3]="step_3"
300
301 QUIT=0
302
303 clear
304
305 echo -n "Checking for user permission.. "
306 sudo -n true
307 if [ $? -ne 0 ]; then
308    echo "Password-less sudo user must run this script" 1>&2
309    exit 1
310 fi
311 echo "Done"
312 clear
313
314 while [ "$QUIT" == "0" ]; do
315         OPTION_NUM=1
316         for s in $(seq ${#STEPS[@]}) ; do
317                 ${STEPS[s]}
318
319                 echo "----------------------------------------------------------"
320                 echo " Step $s: ${TITLE}"
321                 echo "----------------------------------------------------------"
322
323                 for i in $(seq ${#TEXT[@]}) ; do
324                         echo "[$OPTION_NUM] ${TEXT[i]}"
325                         OPTIONS[$OPTION_NUM]=${FUNC[i]}
326                         let "OPTION_NUM+=1"
327                 done
328
329                 # Clear TEXT and FUNC arrays before next step
330                 unset TEXT
331                 unset FUNC
332
333                 echo ""
334         done
335
336         echo "[$OPTION_NUM] Exit Script"
337         OPTIONS[$OPTION_NUM]="quit"
338         echo ""
339         echo -n "Option: "
340         read our_entry
341         echo ""
342         ${OPTIONS[our_entry]} ${our_entry}
343
344         if [ "$QUIT" == "0" ] ; then
345                 echo
346                 echo -n "Press enter to continue ..."; read
347                 clear
348                 continue
349                 exit
350         fi
351         echo "Installation successfully complete."
352 done