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 https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm
48 ${SUDO} rpm -ivh nasm-2.14.02-0.fc27.x86_64.rpm
51 function k8s_os_pkgs_runtime_install()
53 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
55 # Install required dynamically linked libraries + required packages
56 ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \
62 # huge pages to be used by DPDK
63 ${SUDO} sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
65 ${SUDO} sh -c '(echo "options vfio enable_unsafe_noiommu_mode=1") > /etc/modprobe.d/vfio.conf'
66 ${SUDO} sh -c '(echo "vfio") > /etc/modules-load.d/vfio.conf'
67 ${SUDO} sh -c '(echo "vfio-pci") > /etc/modules-load.d/vfio.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-3" | ${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
95 [ ! -f /etc/ssh/ssh_host_rsa_key ] && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
96 [ ! -f /etc/ssh/ssh_host_ecdsa_key ] && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
97 [ ! -f /etc/ssh/ssh_host_ed25519_key ] && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
99 [ ! -d /var/run/sshd ] && mkdir -p /var/run/sshd
104 useradd -m -d /home/${USER_NAME} -s /bin/bash -U ${USER_NAME}
105 echo "${USER_NAME}:${USER_PWD}" | chpasswd
106 usermod -aG wheel ${USER_NAME}
108 echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheelnopass
111 function mblib_install()
113 export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-${MULTI_BUFFER_LIB_VER}"
115 # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
116 pushd ${BUILD_DIR} > /dev/null 2>&1
117 wget https://github.com/01org/intel-ipsec-mb/archive/v${MULTI_BUFFER_LIB_VER}.zip
118 unzip v${MULTI_BUFFER_LIB_VER}.zip
119 pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
120 make -j`getconf _NPROCESSORS_ONLN`
122 popd > /dev/null 2>&1
123 popd > /dev/null 2>&1
126 function dpdk_install()
128 # Build DPDK for the latest kernel installed
129 LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
130 export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
132 # Get and compile DPDK
133 pushd ${BUILD_DIR} > /dev/null 2>&1
134 wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
135 tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
136 popd > /dev/null 2>&1
138 ${SUDO} ln -s ${RTE_SDK} ${BUILD_DIR}/dpdk
140 pushd ${RTE_SDK} > /dev/null 2>&1
141 make config T=${RTE_TARGET}
142 # Starting from DPDK 20.05, the IGB_UIO driver is not compiled by default.
143 # Uncomment the sed command to enable the driver compilation
144 #${SUDO} sed -i 's/CONFIG_RTE_EAL_IGB_UIO=n/c\/CONFIG_RTE_EAL_IGB_UIO=y' ${RTE_SDK}/build/.config
146 # For Kubernetes environment we use host vfio module
147 if [ "${K8S_ENV}" == "y" ]; then
148 sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/g' ${RTE_SDK}/build/.config
149 sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/g' ${RTE_SDK}/build/.config
150 sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/g' ${RTE_SDK}/build/.config
153 # Compile with MB library
154 sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
155 make -j`getconf _NPROCESSORS_ONLN`
156 ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
157 popd > /dev/null 2>&1
160 function prox_compile()
163 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
164 COMMIT_ID=$(git rev-parse HEAD)
165 echo "${COMMIT_ID}" > ${BUILD_DIR}/commit_id
166 make -j`getconf _NPROCESSORS_ONLN`
167 ${SUDO} cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/build/app/prox ${BUILD_DIR}/prox
168 popd > /dev/null 2>&1
171 function prox_install()
174 pushd ${BUILD_DIR} > /dev/null 2>&1
175 git clone https://git.opnfv.org/samplevnf
176 cp -R ./samplevnf/VNFs/DPPD-PROX/helper-scripts/rapid ./src
177 popd > /dev/null 2>&1
181 rm -rf ${BUILD_DIR}/samplevnf
184 function port_info_build()
186 [ ! -d ${BUILD_DIR}/port_info ] && echo "Skipping port_info compilation..." && return
188 pushd ${BUILD_DIR}/port_info > /dev/null 2>&1
190 ${SUDO} cp ${BUILD_DIR}/port_info/build/app/port_info_app ${BUILD_DIR}/port_info_app
191 popd > /dev/null 2>&1
194 function create_minimal_install()
196 ldd ${BUILD_DIR}/prox | awk '{ if ($(NF-1) != "=>") print $(NF-1) }' >> ${BUILD_DIR}/list_of_install_components
198 echo "${BUILD_DIR}/prox" >> ${BUILD_DIR}/list_of_install_components
199 echo "${BUILD_DIR}/port_info_app" >> ${BUILD_DIR}/list_of_install_components
200 echo "${BUILD_DIR}/commit_id" >> ${BUILD_DIR}/list_of_install_components
202 tar -czvhf ${BUILD_DIR}/install_components.tgz -T ${BUILD_DIR}/list_of_install_components
207 ${SUDO} yum autoremove -y
208 ${SUDO} yum clean all
209 ${SUDO} rm -rf /var/cache/yum
212 function k8s_runtime_image()
214 k8s_os_pkgs_runtime_install
218 pushd / > /dev/null 2>&1
219 tar -xvf ${BUILD_DIR}/install_components.tgz --skip-old-files
220 popd > /dev/null 2>&1
224 rm -rf ${BUILD_DIR}/install_components.tgz
227 function print_usage()
229 echo "Usage: ${0} [OPTIONS] [COMMAND]"
231 echo " -u, --update Full OS update"
232 echo " -k, --kubernetes Build for Kubernetes environment"
234 echo " deploy Run through all deployment steps"
235 echo " compile PROX compile only"
236 echo " runtime_image Apply runtime configuration only"
240 # Parse options and comman
244 echo 'Full OS update will be done!'
248 echo "Kubernetes environment is set!"
255 COMMAND="runtime_image"
261 echo "Unknown option/command ${opt}"
268 if [ "${COMMAND}" == "compile" ]; then
269 echo "PROX compile only..."
271 elif [ "${COMMAND}" == "runtime_image" ]; then
272 echo "Runtime image intallation and configuration..."
274 elif [ "${COMMAND}" == "deploy" ]; then
275 [ ! -d ${BUILD_DIR} ] && ${SUDO} mkdir -p ${BUILD_DIR}
276 ${SUDO} chmod 0777 ${BUILD_DIR}
280 if [ "${K8S_ENV}" == "y" ]; then
290 if [ "${K8S_ENV}" == "y" ]; then
292 create_minimal_install