Merge changes from topic 'june_release'
[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/openstackrapid"
19 COPY_DIR="/home/centos" # Directory where the packer tool has copied some files (e.g. check_prox_system_setup.sh)
20 DPDK_VERSION="18.08"
21 PROX_COMMIT="c8e9e6bb696363a397b2e718eb4d3e5f38a8ef22"
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 wireshark
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         # huge pages to be used by DPDK
43         sudo sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
44
45         # Enabling tuned with the realtime-virtual-guest profile
46         pushd ${BUILD_DIR} > /dev/null 2>&1
47         wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm
48         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
49         # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however
50         # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future
51         sudo rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps
52         sudo rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps
53         # 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
54         # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail.
55         # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM 
56         # and update the realtime-virtual-guest-variables.conf accordingly.
57         echo "isolated_cores=1" | sudo tee -a /etc/tuned/realtime-virtual-guest-variables.conf
58         sudo tuned-adm profile realtime-virtual-guest
59
60         # 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
61         # assigned to this VM depends on the flavor used. We don't know at this time what that will be.
62         sudo chmod +x ${COPY_DIR}/check_prox_system_setup.sh
63         sudo cp -r ${COPY_DIR}/check_prox_system_setup.sh /usr/local/libexec/
64         sudo cp -r ${COPY_DIR}/check-prox-system-setup.service /etc/systemd/system/
65         sudo systemctl daemon-reload
66         sudo systemctl enable check-prox-system-setup.service
67
68         popd > /dev/null 2>&1
69 }
70
71 function mblib_install()
72 {
73         export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-0.50"
74
75         # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
76         pushd ${BUILD_DIR} > /dev/null 2>&1
77         wget https://github.com/01org/intel-ipsec-mb/archive/v0.50.zip
78         unzip v0.50.zip
79         pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
80         make -j`getconf _NPROCESSORS_ONLN`
81         sudo make install
82         popd > /dev/null 2>&1
83         popd > /dev/null 2>&1
84 }
85
86 function dpdk_install()
87 {
88         # Build DPDK for the latest kernel installed
89         LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
90         export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
91
92         # Get and compile DPDK
93         pushd ${BUILD_DIR} > /dev/null 2>&1
94         wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
95         tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
96         popd > /dev/null 2>&1
97
98         # Runtime scripts are assuming /root as the directory for PROX
99         sudo ln -s ${RTE_SDK} /root/dpdk
100
101         pushd ${RTE_SDK} > /dev/null 2>&1
102         make config T=${RTE_TARGET}
103         # 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
104         #sudo sed -i '/CONFIG_RTE_LIBRTE_KNI=y/c\CONFIG_RTE_LIBRTE_KNI=n' ${RTE_SDK}/build/.config
105         #sudo sed -i '/CONFIG_RTE_LIBRTE_PMD_KNI=y/c\CONFIG_RTE_LIBRTE_PMD_KNI=n' ${RTE_SDK}/build/.config
106         #sudo sed -i '/CONFIG_RTE_KNI_KMOD=y/c\CONFIG_RTE_KNI_KMOD=n' ${RTE_SDK}/build/.config
107         #sudo sed -i '/CONFIG_RTE_KNI_PREEMPT_DEFAULT=y/c\CONFIG_RTE_KNI_PREEMPT_DEFAULT=n' ${RTE_SDK}/build/.config
108         # Compile with MB library
109         sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
110         make -j`getconf _NPROCESSORS_ONLN`
111         ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
112         popd > /dev/null 2>&1
113 }
114
115 function prox_compile()
116 {
117         # Compile PROX
118         pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
119         make -j`getconf _NPROCESSORS_ONLN`
120         popd > /dev/null 2>&1
121 }
122
123 function prox_install()
124 {
125         # Clone and compile PROX
126         pushd ${BUILD_DIR} > /dev/null 2>&1
127         git clone https://git.opnfv.org/samplevnf
128         pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
129         git checkout ${PROX_COMMIT}
130         popd > /dev/null 2>&1
131         prox_compile
132         sudo ln -s ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX /root/prox
133         popd > /dev/null 2>&1
134 }
135
136 if [ "$1" == "compile" ]; then
137         prox_compile
138 else
139         [ ! -d ${BUILD_DIR} ] && sudo mkdir -p ${BUILD_DIR}
140         sudo chmod 0777 ${BUILD_DIR}
141
142         os_pkgs_install
143         os_cfg
144         mblib_install
145         dpdk_install
146         prox_install
147 fi