Fix "code nested too deep error" introduced by commit 843ca042
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / openstackrapid / deploycentos.sh
1 #!/usr/bin/env bash
2 ##
3 ## Copyright (c) 2010-2019 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 BUILD_DIR="/opt/openstackrapid"
19 COPY_DIR="/home/centos" # Directory where the packer tool has copied some files
20 DPDK_VERSION="18.08"
21 PROX_COMMIT="af95b812"
22 export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}"
23 export RTE_TARGET="x86_64-native-linuxapp-gcc"
24
25 function os_pkgs_install()
26 {
27         # NASM repository for AESNI MB library
28         sudo yum-config-manager --add-repo http://www.nasm.us/nasm.repo
29
30         sudo yum install -y deltarpm
31         sudo yum update -y
32         sudo yum install -y git wget gcc unzip libpcap-devel ncurses-devel \
33                          libedit-devel lua-devel kernel-devel iperf3 pciutils \
34                          numactl-devel vim tuna openssl-devel nasm
35 }
36
37 function os_cfg()
38 {
39         # Enabling root ssh access
40         sudo sed -i '/disable_root: 1/c\disable_root: 0' /etc/cloud/cloud.cfg
41
42         # Mounting huge pages to be used by DPDK, mounting already done by CentOS
43         # sudo mkdir -p /mnt/huge
44         # sudo umount `awk '/hugetlbfs/ { print $2 }' /proc/mounts` >/dev/null 2>&1
45         # sudo mount -t hugetlbfs nodev /mnt/huge/
46         sudo sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
47
48         # Enabling tuned with the realtime-virtual-guest profile
49         pushd ${BUILD_DIR} > /dev/null 2>&1
50         wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm
51         wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm
52         # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however
53         # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future
54         sudo rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps
55         sudo rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps
56         # Although we do no know how many cores the VM will have when begin deployed for real testing, we already put a number for the
57         # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail.
58         # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM 
59         # and update the realtime-virtual-guest-variables.conf accordingly.
60         echo "isolated_cores=1" | sudo tee -a /etc/tuned/realtime-virtual-guest-variables.conf
61         sudo tuned-adm profile realtime-virtual-guest
62
63         # Install the check_tuned_params service to make sure that the grub cmd line has the right cpus in isolcpu. The actual number of cpu's
64         # assigned to this VM depends on the flavor used. We don't know at this time what that will be.
65         sudo chmod +x ${COPY_DIR}/check_prox_system_setup.sh
66         sudo cp -r ${COPY_DIR}/check_prox_system_setup.sh /usr/local/libexec/
67         sudo cp -r ${COPY_DIR}/check-prox-system-setup.service /etc/systemd/system/
68         sudo systemctl daemon-reload
69         sudo systemctl enable check-prox-system-setup.service
70
71         popd > /dev/null 2>&1
72 }
73
74 function mblib_install()
75 {
76         export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-0.50"
77
78         # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
79         pushd ${BUILD_DIR} > /dev/null 2>&1
80         wget https://github.com/01org/intel-ipsec-mb/archive/v0.50.zip
81         unzip v0.50.zip
82         pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
83         make -j`getconf _NPROCESSORS_ONLN`
84         sudo make install
85         popd > /dev/null 2>&1
86         popd > /dev/null 2>&1
87 }
88
89 function dpdk_install()
90 {
91         # Build DPDK for the latest kernel installed
92         LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
93         export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
94
95         # Get and compile DPDK
96         pushd ${BUILD_DIR} > /dev/null 2>&1
97         wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
98         tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
99         popd > /dev/null 2>&1
100
101         # Runtime scripts are assuming /root as the directory for PROX
102         sudo ln -s ${RTE_SDK} /root/dpdk
103
104         pushd ${RTE_SDK} > /dev/null 2>&1
105         make config T=${RTE_TARGET}
106         # The next sed lines make sure that we can compile DPDK 17.11 with a relatively new OS. Using a newer DPDK (18.5) should also resolve this issue
107         #sudo sed -i '/CONFIG_RTE_LIBRTE_KNI=y/c\CONFIG_RTE_LIBRTE_KNI=n' ${RTE_SDK}/build/.config
108         #sudo sed -i '/CONFIG_RTE_LIBRTE_PMD_KNI=y/c\CONFIG_RTE_LIBRTE_PMD_KNI=n' ${RTE_SDK}/build/.config
109         #sudo sed -i '/CONFIG_RTE_KNI_KMOD=y/c\CONFIG_RTE_KNI_KMOD=n' ${RTE_SDK}/build/.config
110         #sudo sed -i '/CONFIG_RTE_KNI_PREEMPT_DEFAULT=y/c\CONFIG_RTE_KNI_PREEMPT_DEFAULT=n' ${RTE_SDK}/build/.config
111         # Compile with MB library
112         sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
113         make -j`getconf _NPROCESSORS_ONLN`
114         ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
115         popd > /dev/null 2>&1
116 }
117
118 function prox_install()
119 {
120         # Clone and compile PROX
121         pushd ${BUILD_DIR} > /dev/null 2>&1
122         git clone https://git.opnfv.org/samplevnf
123         pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
124 #       git checkout ffc6be26
125         git checkout ${PROX_COMMIT}
126         make -j`getconf _NPROCESSORS_ONLN`
127         sudo ln -s ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX /root/prox
128         popd > /dev/null 2>&1
129         popd > /dev/null 2>&1
130 }
131
132 [ ! -d ${BUILD_DIR} ] && sudo mkdir -p ${BUILD_DIR}
133 sudo chmod 0777 ${BUILD_DIR}
134
135 os_pkgs_install
136 os_cfg
137 mblib_install
138 dpdk_install
139 prox_install