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 MULTI_BUFFER_LIB_VER="0.52"
22 export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}"
23 export RTE_TARGET="x86_64-native-linuxapp-gcc"
25 # By default, do not update OS
27 # By default, asumming that we are in the VM
30 # If already running from root, no need for sudo
32 [ $(id -u) -ne 0 ] && SUDO="sudo"
34 function os_pkgs_install()
36 ${SUDO} yum install -y deltarpm yum-utils
38 # NASM repository for AESNI MB library
39 #${SUDO} yum-config-manager --add-repo http://www.nasm.us/nasm.repo
41 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
42 ${SUDO} yum install -y git wget gcc unzip libpcap-devel ncurses-devel \
43 libedit-devel lua-devel kernel-devel iperf3 pciutils \
44 numactl-devel vim tuna openssl-devel wireshark \
47 ${SUDO} wget --no-check-certificate \
48 https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm
49 ${SUDO} rpm -ivh nasm-2.14.02-0.fc27.x86_64.rpm
52 function k8s_os_pkgs_runtime_install()
54 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
56 # Install required dynamically linked libraries + required packages
57 ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \
60 # Install additional packets for universal image
61 ${SUDO} yum install -y epel-release python3 kubernetes-client
62 ${SUDO} yum install -y python3-paramiko python3-future
63 ${SUDO} python3 -m pip install --upgrade pip
64 ${SUDO} pip3 install scp kubernetes
69 # huge pages to be used by DPDK
70 ${SUDO} sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
72 ${SUDO} sh -c '(echo "options vfio enable_unsafe_noiommu_mode=1") > /etc/modprobe.d/vfio.conf'
73 ${SUDO} sh -c '(echo "vfio") > /etc/modules-load.d/vfio.conf'
74 ${SUDO} sh -c '(echo "vfio-pci") > /etc/modules-load.d/vfio.conf'
75 # Enabling tuned with the realtime-virtual-guest profile
76 pushd ${BUILD_DIR} > /dev/null 2>&1
77 wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm
78 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
79 # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however
80 # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future
81 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps
82 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps
83 # 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
84 # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail.
85 # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM
86 # and update the realtime-virtual-guest-variables.conf accordingly.
87 echo "isolated_cores=1-3" | ${SUDO} tee -a /etc/tuned/realtime-virtual-guest-variables.conf
88 ${SUDO} tuned-adm profile realtime-virtual-guest
90 # 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
91 # assigned to this VM depends on the flavor used. We don't know at this time what that will be.
92 ${SUDO} chmod +x ${BUILD_DIR}/check_prox_system_setup.sh
93 ${SUDO} mv ${BUILD_DIR}/check_prox_system_setup.sh /usr/local/libexec/
94 ${SUDO} mv ${BUILD_DIR}/check-prox-system-setup.service /etc/systemd/system/
95 ${SUDO} systemctl daemon-reload
96 ${SUDO} systemctl enable check-prox-system-setup.service
100 function k8s_os_cfg()
102 [ ! -f /etc/ssh/ssh_host_rsa_key ] && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
103 [ ! -f /etc/ssh/ssh_host_ecdsa_key ] && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
104 [ ! -f /etc/ssh/ssh_host_ed25519_key ] && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
106 [ ! -d /var/run/sshd ] && mkdir -p /var/run/sshd
111 useradd -m -d /home/${USER_NAME} -s /bin/bash -U ${USER_NAME}
112 echo "${USER_NAME}:${USER_PWD}" | chpasswd
113 usermod -aG wheel ${USER_NAME}
115 echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheelnopass
118 function mblib_install()
120 export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-${MULTI_BUFFER_LIB_VER}"
122 # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
123 pushd ${BUILD_DIR} > /dev/null 2>&1
124 wget https://github.com/01org/intel-ipsec-mb/archive/v${MULTI_BUFFER_LIB_VER}.zip
125 unzip v${MULTI_BUFFER_LIB_VER}.zip
126 pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
127 make -j`getconf _NPROCESSORS_ONLN`
129 popd > /dev/null 2>&1
130 popd > /dev/null 2>&1
133 function dpdk_install()
135 # Build DPDK for the latest kernel installed
136 LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
137 export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
139 # Get and compile DPDK
140 pushd ${BUILD_DIR} > /dev/null 2>&1
141 wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
142 tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
143 popd > /dev/null 2>&1
145 ${SUDO} ln -s ${RTE_SDK} ${BUILD_DIR}/dpdk
147 pushd ${RTE_SDK} > /dev/null 2>&1
148 make config T=${RTE_TARGET}
149 # Starting from DPDK 20.05, the IGB_UIO driver is not compiled by default.
150 # Uncomment the sed command to enable the driver compilation
151 #${SUDO} sed -i 's/CONFIG_RTE_EAL_IGB_UIO=n/c\/CONFIG_RTE_EAL_IGB_UIO=y' ${RTE_SDK}/build/.config
153 # For Kubernetes environment we use host vfio module
154 if [ "${K8S_ENV}" == "y" ]; then
155 sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/g' ${RTE_SDK}/build/.config
156 sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/g' ${RTE_SDK}/build/.config
157 sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/g' ${RTE_SDK}/build/.config
160 # Compile with MB library
161 sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
162 make -j`getconf _NPROCESSORS_ONLN`
163 ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
164 popd > /dev/null 2>&1
167 function prox_compile()
170 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
171 COMMIT_ID=$(git rev-parse HEAD)
172 echo "${COMMIT_ID}" > ${BUILD_DIR}/commit_id
173 make -j`getconf _NPROCESSORS_ONLN`
174 ${SUDO} cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/build/app/prox ${BUILD_DIR}/prox
175 popd > /dev/null 2>&1
178 function prox_install()
181 pushd ${BUILD_DIR} > /dev/null 2>&1
182 git clone https://git.opnfv.org/samplevnf
183 cp -R ./samplevnf/VNFs/DPPD-PROX/helper-scripts/rapid ./src
184 popd > /dev/null 2>&1
188 rm -rf ${BUILD_DIR}/samplevnf
191 function port_info_build()
193 [ ! -d ${BUILD_DIR}/port_info ] && echo "Skipping port_info compilation..." && return
195 pushd ${BUILD_DIR}/port_info > /dev/null 2>&1
197 ${SUDO} cp ${BUILD_DIR}/port_info/build/app/port_info_app ${BUILD_DIR}/port_info_app
198 popd > /dev/null 2>&1
201 function create_minimal_install()
203 ldd ${BUILD_DIR}/prox | awk '{ if ($(NF-1) != "=>") print $(NF-1) }' >> ${BUILD_DIR}/list_of_install_components
205 echo "${BUILD_DIR}/prox" >> ${BUILD_DIR}/list_of_install_components
206 echo "${BUILD_DIR}/port_info_app" >> ${BUILD_DIR}/list_of_install_components
207 echo "${BUILD_DIR}/commit_id" >> ${BUILD_DIR}/list_of_install_components
209 tar -czvhf ${BUILD_DIR}/install_components.tgz -T ${BUILD_DIR}/list_of_install_components
214 ${SUDO} yum autoremove -y
215 ${SUDO} yum clean all
216 ${SUDO} rm -rf /var/cache/yum
219 function k8s_runtime_image()
221 k8s_os_pkgs_runtime_install
225 pushd / > /dev/null 2>&1
226 tar -xvf ${BUILD_DIR}/install_components.tgz --skip-old-files
227 popd > /dev/null 2>&1
231 rm -rf ${BUILD_DIR}/install_components.tgz
234 function print_usage()
236 echo "Usage: ${0} [OPTIONS] [COMMAND]"
238 echo " -u, --update Full OS update"
239 echo " -k, --kubernetes Build for Kubernetes environment"
241 echo " deploy Run through all deployment steps"
242 echo " compile PROX compile only"
243 echo " runtime_image Apply runtime configuration only"
247 # Parse options and comman
251 echo 'Full OS update will be done!'
255 echo "Kubernetes environment is set!"
262 COMMAND="runtime_image"
268 echo "Unknown option/command ${opt}"
275 if [ "${COMMAND}" == "compile" ]; then
276 echo "PROX compile only..."
278 elif [ "${COMMAND}" == "runtime_image" ]; then
279 echo "Runtime image intallation and configuration..."
281 elif [ "${COMMAND}" == "deploy" ]; then
282 [ ! -d ${BUILD_DIR} ] && ${SUDO} mkdir -p ${BUILD_DIR}
283 ${SUDO} chmod 0777 ${BUILD_DIR}
287 if [ "${K8S_ENV}" == "y" ]; then
297 if [ "${K8S_ENV}" == "y" ]; then
299 create_minimal_install