Specify latency bucket size & correct calculation
[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 MULTI_BUFFER_LIB_VER="0.52"
25 export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}"
26 export RTE_TARGET="x86_64-native-linuxapp-gcc"
27
28 function os_pkgs_install()
29 {
30         sudo yum install -y deltarpm yum-utils
31         # NASM repository for AESNI MB library
32         sudo yum-config-manager --add-repo http://www.nasm.us/nasm.repo
33
34         sudo yum update -y
35         sudo yum install -y git wget gcc unzip libpcap-devel ncurses-devel \
36                          libedit-devel lua-devel kernel-devel iperf3 pciutils \
37                          numactl-devel vim tuna openssl-devel nasm wireshark
38 }
39
40 function os_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 ${WORK_DIR}/check_prox_system_setup.sh
63         sudo cp -r ${WORK_DIR}/check_prox_system_setup.sh /usr/local/libexec/
64         sudo cp -r ${WORK_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-${MULTI_BUFFER_LIB_VER}"
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/v${MULTI_BUFFER_LIB_VER}.zip
78         unzip v${MULTI_BUFFER_LIB_VER}.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         sudo ln -s ${RTE_SDK} ${WORK_DIR}/dpdk
99
100         pushd ${RTE_SDK} > /dev/null 2>&1
101         make config T=${RTE_TARGET}
102         # 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
103         #sudo sed -i '/CONFIG_RTE_LIBRTE_KNI=y/c\CONFIG_RTE_LIBRTE_KNI=n' ${RTE_SDK}/build/.config
104         #sudo sed -i '/CONFIG_RTE_LIBRTE_PMD_KNI=y/c\CONFIG_RTE_LIBRTE_PMD_KNI=n' ${RTE_SDK}/build/.config
105         #sudo sed -i '/CONFIG_RTE_KNI_KMOD=y/c\CONFIG_RTE_KNI_KMOD=n' ${RTE_SDK}/build/.config
106         #sudo sed -i '/CONFIG_RTE_KNI_PREEMPT_DEFAULT=y/c\CONFIG_RTE_KNI_PREEMPT_DEFAULT=n' ${RTE_SDK}/build/.config
107         # Compile with MB library
108         sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
109         make -j`getconf _NPROCESSORS_ONLN`
110         ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
111         popd > /dev/null 2>&1
112 }
113
114 function prox_compile()
115 {
116         # Compile PROX
117         pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
118         make -j`getconf _NPROCESSORS_ONLN`
119         popd > /dev/null 2>&1
120 }
121
122 function prox_install()
123 {
124         # Clone and compile PROX
125         pushd ${BUILD_DIR} > /dev/null 2>&1
126         git clone https://git.opnfv.org/samplevnf
127         pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
128         git checkout ${PROX_COMMIT}
129         popd > /dev/null 2>&1
130         prox_compile
131         sudo ln -s ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX ${WORK_DIR}/prox
132         popd > /dev/null 2>&1
133 }
134
135 if [ "$1" == "compile" ]; then
136         prox_compile
137 else
138         [ ! -d ${BUILD_DIR} ] && sudo mkdir -p ${BUILD_DIR}
139         sudo chmod 0777 ${BUILD_DIR}
140
141         os_pkgs_install
142         os_cfg
143         mblib_install
144         dpdk_install
145         prox_install
146 fi