3 ## Copyright (c) 2010-2020 Intel Corporation
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
9 ## http://www.apache.org/licenses/LICENSE-2.0
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.
18 # Directory for package build
19 BUILD_DIR="/opt/rapid"
21 PROX_COMMIT="b71a4cfd"
22 PROX_CHECKOUT="git checkout ${PROX_COMMIT}"
23 ## Next line is overruling the PROX_COMMIT and will replace the version with a very specific patch. Should be commented out
24 ## if you want to use a committed version of PROX with the COMMIT ID specified above
25 ##Following line has the commit for testing IMIX, IPV6, ... It is the merge of all PROX commits on May 27th 2020
26 PROX_CHECKOUT="git fetch \"https://gerrit.opnfv.org/gerrit/samplevnf\" refs/changes/23/70223/1 && git checkout FETCH_HEAD"
27 MULTI_BUFFER_LIB_VER="0.52"
28 export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}"
29 export RTE_TARGET="x86_64-native-linuxapp-gcc"
31 # By default, do not update OS
33 # By default, asumming that we are in the VM
36 # If already running from root, no need for sudo
38 [ $(id -u) -ne 0 ] && SUDO="sudo"
40 function os_pkgs_install()
42 ${SUDO} yum install -y deltarpm yum-utils
44 # NASM repository for AESNI MB library
45 ${SUDO} yum-config-manager --add-repo http://www.nasm.us/nasm.repo
47 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
48 ${SUDO} yum install -y git wget gcc unzip libpcap-devel ncurses-devel \
49 libedit-devel lua-devel kernel-devel iperf3 pciutils \
50 numactl-devel vim tuna openssl-devel nasm wireshark \
54 function k8s_os_pkgs_runtime_install()
56 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
58 # Install required dynamically linked libraries + required packages
59 ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \
65 # huge pages to be used by DPDK
66 ${SUDO} sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
68 # Enabling tuned with the realtime-virtual-guest profile
69 pushd ${BUILD_DIR} > /dev/null 2>&1
70 wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm
71 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
72 # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however
73 # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future
74 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps
75 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps
76 # 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
77 # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail.
78 # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM
79 # and update the realtime-virtual-guest-variables.conf accordingly.
80 echo "isolated_cores=1" | ${SUDO} tee -a /etc/tuned/realtime-virtual-guest-variables.conf
81 ${SUDO} tuned-adm profile realtime-virtual-guest
83 # 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
84 # assigned to this VM depends on the flavor used. We don't know at this time what that will be.
85 ${SUDO} chmod +x ${BUILD_DIR}/check_prox_system_setup.sh
86 ${SUDO} mv ${BUILD_DIR}/check_prox_system_setup.sh /usr/local/libexec/
87 ${SUDO} mv ${BUILD_DIR}/check-prox-system-setup.service /etc/systemd/system/
88 ${SUDO} systemctl daemon-reload
89 ${SUDO} systemctl enable check-prox-system-setup.service
90 # Following lines are added to fix the following issue: When the VM gets
91 # instantiated, the rapid scripts will try to ssh into the VM to start
92 # the testing. Once the script connects with ssh, it starts downloading
93 # config files and then start prox, etc... The problem is that when the VM
94 # boots, check_prox_system_setup.sh will check for some things and
95 # potentially reboot, resulting in losing the ssh connection again.
96 # To fix this issue, the following lines are disabling ssh access for the
97 # centos user. The script will not be able to connect to the VM till ssh
98 # access is restored after a reboot. Restoring ssh is now done by
99 # check-prox-system-setup.service
100 printf "\nMatch User centos\n" | ${SUDO} tee -a /etc/ssh/sshd_config
101 printf "%sPubkeyAuthentication no\n" " " | ${SUDO} tee -a /etc/ssh/sshd_config
102 printf "%sPasswordAuthentication no\n" " " | ${SUDO} tee -a /etc/ssh/sshd_config
103 popd > /dev/null 2>&1
106 function k8s_os_cfg()
108 [ ! -f /etc/ssh/ssh_host_rsa_key ] && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
109 [ ! -f /etc/ssh/ssh_host_ecdsa_key ] && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
110 [ ! -f /etc/ssh/ssh_host_ed25519_key ] && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
112 [ ! -d /var/run/sshd ] && mkdir -p /var/run/sshd
117 useradd -m -d /home/${USER_NAME} -s /bin/bash -U ${USER_NAME}
118 echo "${USER_NAME}:${USER_PWD}" | chpasswd
119 usermod -aG wheel ${USER_NAME}
121 echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheelnopass
124 function mblib_install()
126 export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-${MULTI_BUFFER_LIB_VER}"
128 # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
129 pushd ${BUILD_DIR} > /dev/null 2>&1
130 wget https://github.com/01org/intel-ipsec-mb/archive/v${MULTI_BUFFER_LIB_VER}.zip
131 unzip v${MULTI_BUFFER_LIB_VER}.zip
132 pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
133 make -j`getconf _NPROCESSORS_ONLN`
135 popd > /dev/null 2>&1
136 popd > /dev/null 2>&1
139 function dpdk_install()
141 # Build DPDK for the latest kernel installed
142 LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
143 export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
145 # Get and compile DPDK
146 pushd ${BUILD_DIR} > /dev/null 2>&1
147 wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
148 tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
149 popd > /dev/null 2>&1
151 ${SUDO} ln -s ${RTE_SDK} ${BUILD_DIR}/dpdk
153 pushd ${RTE_SDK} > /dev/null 2>&1
154 make config T=${RTE_TARGET}
155 # 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
156 #${SUDO} sed -i '/CONFIG_RTE_LIBRTE_KNI=y/c\CONFIG_RTE_LIBRTE_KNI=n' ${RTE_SDK}/build/.config
157 #${SUDO} sed -i '/CONFIG_RTE_LIBRTE_PMD_KNI=y/c\CONFIG_RTE_LIBRTE_PMD_KNI=n' ${RTE_SDK}/build/.config
158 #${SUDO} sed -i '/CONFIG_RTE_KNI_KMOD=y/c\CONFIG_RTE_KNI_KMOD=n' ${RTE_SDK}/build/.config
159 #${SUDO} sed -i '/CONFIG_RTE_KNI_PREEMPT_DEFAULT=y/c\CONFIG_RTE_KNI_PREEMPT_DEFAULT=n' ${RTE_SDK}/build/.config
161 # For Kubernetes environment we use host vfio module
162 if [ "${K8S_ENV}" == "y" ]; then
163 sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/g' ${RTE_SDK}/build/.config
164 sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/g' ${RTE_SDK}/build/.config
165 sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/g' ${RTE_SDK}/build/.config
168 # Compile with MB library
169 sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
170 make -j`getconf _NPROCESSORS_ONLN`
171 ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
172 popd > /dev/null 2>&1
175 function prox_compile()
178 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
179 make -j`getconf _NPROCESSORS_ONLN`
180 ${SUDO} cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/build/app/prox ${BUILD_DIR}/prox
181 popd > /dev/null 2>&1
184 function prox_install()
186 # Clone and compile PROX
187 pushd ${BUILD_DIR} > /dev/null 2>&1
188 git clone https://git.opnfv.org/samplevnf
189 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX > /dev/null 2>&1
190 bash -c "${PROX_CHECKOUT}"
191 popd > /dev/null 2>&1
193 popd > /dev/null 2>&1
196 function port_info_build()
198 [ ! -d ${BUILD_DIR}/port_info ] && echo "Skipping port_info compilation..." && return
200 pushd ${BUILD_DIR}/port_info > /dev/null 2>&1
202 ${SUDO} cp ${BUILD_DIR}/port_info/build/app/port_info ${HOME}/port_info
203 popd > /dev/null 2>&1
206 function create_minimal_install()
208 ldd ${HOME}/prox | awk '{ if ($(NF-1) != "=>") print $(NF-1) }' >> ${BUILD_DIR}/list_of_install_components
210 echo "${HOME}/prox" >> ${BUILD_DIR}/list_of_install_components
211 echo "${HOME}/port_info" >> ${BUILD_DIR}/list_of_install_components
213 tar -czvhf ${BUILD_DIR}/install_components.tgz -T ${BUILD_DIR}/list_of_install_components
218 ${SUDO} yum autoremove -y
219 ${SUDO} yum clean all
220 ${SUDO} rm -rf /var/cache/yum
223 function k8s_runtime_image()
225 k8s_os_pkgs_runtime_install
229 pushd / > /dev/null 2>&1
230 tar -xvf ${BUILD_DIR}/install_components.tgz --skip-old-files
231 popd > /dev/null 2>&1
235 #rm -rf ${BUILD_DIR}/install_components.tgz
238 function print_usage()
240 echo "Usage: ${0} [OPTIONS] [COMMAND]"
242 echo " -u, --update Full OS update"
243 echo " -k, --kubernetes Build for Kubernetes environment"
245 echo " deploy Run through all deployment steps"
246 echo " compile PROX compile only"
247 echo " runtime_image Apply runtime configuration only"
251 # Parse options and comman
255 echo 'Full OS update will be done!'
259 echo "Kubernetes environment is set!"
266 COMMAND="runtime_image"
272 echo "Unknown option/command ${opt}"
279 if [ "${COMMAND}" == "compile" ]; then
280 echo "PROX compile only..."
282 elif [ "${COMMAND}" == "runtime_image" ]; then
283 echo "Runtime image intallation and configuration..."
285 elif [ "${COMMAND}" == "deploy" ]; then
286 [ ! -d ${BUILD_DIR} ] && ${SUDO} mkdir -p ${BUILD_DIR}
287 ${SUDO} chmod 0777 ${BUILD_DIR}
291 if [ "${K8S_ENV}" == "y" ]; then
301 if [ "${K8S_ENV}" == "y" ]; then
303 create_minimal_install