tools: Adding patches for disabling the DEBUG logs in DPDK
[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         patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/disable-acl-debug-logs.patch
191         patch -p1 < $VNF_CORE/patches/dpdk_custom_patch/set-log-level-to-info.patch
192
193         make -j install T=$RTE_TARGET
194         if [ $? -ne 0 ] ; then
195                 echo "Failed to build dpdk, please check the errors."
196                 return
197         fi
198         sudo modinfo igb_uio
199         if [ $? -ne 0 ] ; then
200                 sudo $MODPROBE -v uio
201                 sudo $INSMOD $RTE_TARGET/kmod/igb_uio.ko
202                 sudo cp -f $RTE_TARGET/kmod/igb_uio.ko /lib/modules/$(uname -r)
203                 echo "uio" | sudo tee -a /etc/modules
204                 echo "igb_uio" | sudo tee -a /etc/modules
205                 sudo depmod
206         fi
207         popd
208 }
209
210 setup_hugepages()
211 {
212         #----
213         Pages=16
214         if [[ "$HUGEPGSZ" = "2048kB" ]] ; then
215                 Pages=8192
216         fi
217         if [ ! "`grep nr_hugepages /etc/sysctl.conf`" ] ; then
218                 echo "vm.nr_hugepages=$Pages" | sudo tee /etc/sysctl.conf
219         fi
220         sudo sysctl -p
221
222         sudo service procps start
223
224         grep -s '/dev/hugepages' /proc/mounts
225         if [ $? -ne 0 ] ; then
226                 echo "Creating /mnt/huge and mounting as hugetlbfs"
227                 sudo mkdir -p /mnt/huge
228                 sudo mount -t hugetlbfs nodev /mnt/huge
229                 echo "nodev /mnt/huge hugetlbfs defaults 0 0" | sudo tee -a /etc/fstab > /dev/null
230         fi
231 }
232
233 step_3()
234 {
235         TITLE="Build VNFs"
236         CONFIG_NUM=1
237                                 TEXT[1]="Build all VNFs (vACL, vCGNAPT, vFW, UDP_Replay)"
238         FUNC[1]="build_vnfs"
239 }
240
241 build_vnfs()
242 {
243
244         if [ ! -d "$DPDK_DIR" ]; then
245      echo "Please choose option '4 Download DPDK zip'"
246      return
247         fi
248
249         if [ ! -d "$DPDK_DIR/x86_64-native-linuxapp-gcc" ]; then
250      echo "Please choose option '5 Build and Install DPDK'"
251      return
252         fi
253
254         export RTE_SDK=$DPDK_DIR
255         export RTE_TARGET=x86_64-native-linuxapp-gcc
256         pushd $VNF_CORE
257         make clean
258         make || { echo -e "\nVNF: Make failed\n"; }
259         popd
260 }
261
262 #--- Add non intractive option to build vnfs
263 if [[ "$1" = "--silient" ]];then
264     pushd $VNF_CORE
265
266     echo "Setup proxy if needed..."
267     http_proxy=$2
268     https_proxy=$3
269     if [[ "$http_proxy" != "" ]]; then
270          export http_proxy=$http_proxy
271          export https_proxy=$http_proxy
272     fi
273
274     if [[ "$https_proxy" != "" ]]; then
275          export https_proxy=$https_proxy
276     fi
277
278     echo "Install required libraries..."
279     touch .agree
280     install_libs
281
282     echo "Download dpdk for VNF build..."
283     download_dpdk_zip
284
285     echo "Build dpdk..."
286     install_dpdk
287
288     echo "Setup hugepages..."
289     setup_hugepages
290
291     echo "build VNFS..."
292     build_vnfs
293
294     popd
295     exit
296 fi
297
298 SETUP_PROXY="setup_http_proxy"
299 STEPS[1]="step_1"
300 STEPS[2]="step_2"
301 STEPS[3]="step_3"
302
303 QUIT=0
304
305 clear
306
307 echo -n "Checking for user permission.. "
308 sudo -n true
309 if [ $? -ne 0 ]; then
310    echo "Password-less sudo user must run this script" 1>&2
311    exit 1
312 fi
313 echo "Done"
314 clear
315
316 while [ "$QUIT" == "0" ]; do
317         OPTION_NUM=1
318         for s in $(seq ${#STEPS[@]}) ; do
319                 ${STEPS[s]}
320
321                 echo "----------------------------------------------------------"
322                 echo " Step $s: ${TITLE}"
323                 echo "----------------------------------------------------------"
324
325                 for i in $(seq ${#TEXT[@]}) ; do
326                         echo "[$OPTION_NUM] ${TEXT[i]}"
327                         OPTIONS[$OPTION_NUM]=${FUNC[i]}
328                         let "OPTION_NUM+=1"
329                 done
330
331                 # Clear TEXT and FUNC arrays before next step
332                 unset TEXT
333                 unset FUNC
334
335                 echo ""
336         done
337
338         echo "[$OPTION_NUM] Exit Script"
339         OPTIONS[$OPTION_NUM]="quit"
340         echo ""
341         echo -n "Option: "
342         read our_entry
343         echo ""
344         ${OPTIONS[our_entry]} ${our_entry}
345
346         if [ "$QUIT" == "0" ] ; then
347                 echo
348                 echo -n "Press enter to continue ..."; read
349                 clear
350                 continue
351                 exit
352         fi
353         echo "Installation successfully complete."
354 done