8d85e345ee4e8f1a5976693864572ece1a13e32a
[samplevnf.git] / VNFs / DPPD-PROX / helper-scripts / rapid / deploycentostools.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/rapid"
19 WORK_DIR="/home/centos" # Directory where the packer tool has copied some files (e.g. check_prox_system_setup.sh)
20                         # Runtime scripts are assuming ${WORK_DIR} as the directory for PROX. Check the rundir variable in runrapid.py. Should be the same!
21                         # This variable is defined in 4 different places and should have the same value: centos.json, deploycentos.sh, check_prox_system_setup.sh and runrapid.py
22 DPDK_VERSION="19.05"
23 PROX_COMMIT="f456ab65"
24 ##PROX_CHECKOUT="git checkout ${PROX_COMMIT}"
25 ## Next line is overruling the PROX_COMMIT and will replace the version with a very specific patch. Should be commented out
26 ##      if you want to use a committed version of PROX
27 PROX_CHECKOUT="git fetch \"https://gerrit.opnfv.org/gerrit/samplevnf\" refs/changes/75/69475/2 && git checkout FETCH_HEAD"
28 MULTI_BUFFER_LIB_VER="0.52"
29 export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}"
30 export RTE_TARGET="x86_64-native-linuxapp-gcc"
31
32 function os_pkgs_install()
33 {
34         sudo yum install -y deltarpm yum-utils
35         # NASM repository for AESNI MB library
36         sudo yum-config-manager --add-repo http://www.nasm.us/nasm.repo
37
38         sudo yum update -y
39         sudo yum install -y git wget gcc unzip libpcap-devel ncurses-devel \
40                          libedit-devel lua-devel kernel-devel iperf3 pciutils \
41                          numactl-devel vim tuna openssl-devel nasm wireshark
42 }
43
44 function os_cfg()
45 {
46         # huge pages to be used by DPDK
47         sudo sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
48
49         # Enabling tuned with the realtime-virtual-guest profile
50         pushd ${BUILD_DIR} > /dev/null 2>&1
51         wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm
52         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
53         # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however
54         # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future
55         sudo rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps
56         sudo rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps
57         # 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
58         # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail.
59         # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM 
60         # and update the realtime-virtual-guest-variables.conf accordingly.
61         echo "isolated_cores=1" | sudo tee -a /etc/tuned/realtime-virtual-guest-variables.conf
62         sudo tuned-adm profile realtime-virtual-guest
63
64         # 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
65         # assigned to this VM depends on the flavor used. We don't know at this time what that will be.
66         sudo chmod +x ${WORK_DIR}/check_prox_system_setup.sh
67         sudo cp -r ${WORK_DIR}/check_prox_system_setup.sh /usr/local/libexec/
68         sudo cp -r ${WORK_DIR}/check-prox-system-setup.service /etc/systemd/system/
69         sudo systemctl daemon-reload
70         sudo systemctl enable check-prox-system-setup.service
71
72         popd > /dev/null 2>&1
73 }
74
75 function mblib_install()
76 {
77         export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-${MULTI_BUFFER_LIB_VER}"
78
79         # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
80         pushd ${BUILD_DIR} > /dev/null 2>&1
81         wget https://github.com/01org/intel-ipsec-mb/archive/v${MULTI_BUFFER_LIB_VER}.zip
82         unzip v${MULTI_BUFFER_LIB_VER}.zip
83         pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
84         make -j`getconf _NPROCESSORS_ONLN`
85         sudo make install
86         popd > /dev/null 2>&1
87         popd > /dev/null 2>&1
88 }
89
90 function dpdk_install()
91 {
92         # Build DPDK for the latest kernel installed
93         LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
94         export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
95
96         # Get and compile DPDK
97         pushd ${BUILD_DIR} > /dev/null 2>&1
98         wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
99         tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
100         popd > /dev/null 2>&1
101
102         sudo ln -s ${RTE_SDK} ${WORK_DIR}/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_compile()
119 {
120         # Compile PROX
121         pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
122         make -j`getconf _NPROCESSORS_ONLN`
123         popd > /dev/null 2>&1
124 }
125
126 function prox_install()
127 {
128         # Clone and compile PROX
129         pushd ${BUILD_DIR} > /dev/null 2>&1
130         git clone https://git.opnfv.org/samplevnf
131         pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
132         #git checkout ${PROX_COMMIT}
133         ${PROX_CHECKOUT}
134         popd > /dev/null 2>&1
135         prox_compile
136         sudo ln -s ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX ${WORK_DIR}/prox
137         popd > /dev/null 2>&1
138 }
139
140 if [ "$1" == "compile" ]; then
141         prox_compile
142 else
143         [ ! -d ${BUILD_DIR} ] && sudo mkdir -p ${BUILD_DIR}
144         sudo chmod 0777 ${BUILD_DIR}
145
146         os_pkgs_install
147         os_cfg
148         mblib_install
149         dpdk_install
150         prox_install
151 fi