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="7c3217fc16"
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 wireshark \
53 ${SUDO} wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm
54 ${SUDO} rpm -ivh nasm-2.14.02-0.fc27.x86_64.rpm
57 function k8s_os_pkgs_runtime_install()
59 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
61 # Install required dynamically linked libraries + required packages
62 ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \
68 # huge pages to be used by DPDK
69 ${SUDO} sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
71 ${SUDO} sh -c '(echo "options vfio enable_unsafe_noiommu_mode=1") > /etc/modprobe.d/vfio.conf'
72 ${SUDO} sh -c '(echo "vfio") > /etc/modules-load.d/vfio.conf'
73 ${SUDO} sh -c '(echo "vfio-pci") > /etc/modules-load.d/vfio.conf'
74 # Enabling tuned with the realtime-virtual-guest profile
75 pushd ${BUILD_DIR} > /dev/null 2>&1
76 wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm
77 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
78 # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however
79 # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future
80 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps
81 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps
82 # 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
83 # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail.
84 # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM
85 # and update the realtime-virtual-guest-variables.conf accordingly.
86 echo "isolated_cores=1-3" | ${SUDO} tee -a /etc/tuned/realtime-virtual-guest-variables.conf
87 ${SUDO} tuned-adm profile realtime-virtual-guest
89 # 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
90 # assigned to this VM depends on the flavor used. We don't know at this time what that will be.
91 ${SUDO} chmod +x ${BUILD_DIR}/check_prox_system_setup.sh
92 ${SUDO} mv ${BUILD_DIR}/check_prox_system_setup.sh /usr/local/libexec/
93 ${SUDO} mv ${BUILD_DIR}/check-prox-system-setup.service /etc/systemd/system/
94 ${SUDO} systemctl daemon-reload
95 ${SUDO} systemctl enable check-prox-system-setup.service
101 [ ! -f /etc/ssh/ssh_host_rsa_key ] && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
102 [ ! -f /etc/ssh/ssh_host_ecdsa_key ] && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
103 [ ! -f /etc/ssh/ssh_host_ed25519_key ] && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
105 [ ! -d /var/run/sshd ] && mkdir -p /var/run/sshd
110 useradd -m -d /home/${USER_NAME} -s /bin/bash -U ${USER_NAME}
111 echo "${USER_NAME}:${USER_PWD}" | chpasswd
112 usermod -aG wheel ${USER_NAME}
114 echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheelnopass
117 function mblib_install()
119 export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-${MULTI_BUFFER_LIB_VER}"
121 # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
122 pushd ${BUILD_DIR} > /dev/null 2>&1
123 wget https://github.com/01org/intel-ipsec-mb/archive/v${MULTI_BUFFER_LIB_VER}.zip
124 unzip v${MULTI_BUFFER_LIB_VER}.zip
125 pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
126 make -j`getconf _NPROCESSORS_ONLN`
128 popd > /dev/null 2>&1
129 popd > /dev/null 2>&1
132 function dpdk_install()
134 # Build DPDK for the latest kernel installed
135 LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
136 export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
138 # Get and compile DPDK
139 pushd ${BUILD_DIR} > /dev/null 2>&1
140 wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
141 tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
142 popd > /dev/null 2>&1
144 ${SUDO} ln -s ${RTE_SDK} ${BUILD_DIR}/dpdk
146 pushd ${RTE_SDK} > /dev/null 2>&1
147 make config T=${RTE_TARGET}
148 # Starting from DPDK 20.05, the IGB_UIO driver is not compiled by default.
149 # Uncomment the sed command to enable the driver compilation
150 #${SUDO} sed -i 's/CONFIG_RTE_EAL_IGB_UIO=n/c\/CONFIG_RTE_EAL_IGB_UIO=y' ${RTE_SDK}/build/.config
152 # For Kubernetes environment we use host vfio module
153 if [ "${K8S_ENV}" == "y" ]; then
154 sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/g' ${RTE_SDK}/build/.config
155 sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/g' ${RTE_SDK}/build/.config
156 sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/g' ${RTE_SDK}/build/.config
159 # Compile with MB library
160 sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
161 make -j`getconf _NPROCESSORS_ONLN`
162 ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
163 popd > /dev/null 2>&1
166 function prox_compile()
169 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
170 make -j`getconf _NPROCESSORS_ONLN`
171 ${SUDO} cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/build/app/prox ${BUILD_DIR}/prox
172 popd > /dev/null 2>&1
175 function prox_install()
177 # Clone and compile PROX
178 pushd ${BUILD_DIR} > /dev/null 2>&1
179 git clone https://git.opnfv.org/samplevnf
180 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX > /dev/null 2>&1
181 bash -c "${PROX_CHECKOUT}"
182 popd > /dev/null 2>&1
184 popd > /dev/null 2>&1
187 function port_info_build()
189 [ ! -d ${BUILD_DIR}/port_info ] && echo "Skipping port_info compilation..." && return
191 pushd ${BUILD_DIR}/port_info > /dev/null 2>&1
193 ${SUDO} cp ${BUILD_DIR}/port_info/build/app/port_info_app ${BUILD_DIR}/port_info_app
194 popd > /dev/null 2>&1
197 function create_minimal_install()
199 ldd ${BUILD_DIR}/prox | awk '{ if ($(NF-1) != "=>") print $(NF-1) }' >> ${BUILD_DIR}/list_of_install_components
201 echo "${BUILD_DIR}/prox" >> ${BUILD_DIR}/list_of_install_components
202 echo "${BUILD_DIR}/port_info_app" >> ${BUILD_DIR}/list_of_install_components
204 tar -czvhf ${BUILD_DIR}/install_components.tgz -T ${BUILD_DIR}/list_of_install_components
209 ${SUDO} yum autoremove -y
210 ${SUDO} yum clean all
211 ${SUDO} rm -rf /var/cache/yum
214 function k8s_runtime_image()
216 k8s_os_pkgs_runtime_install
220 pushd / > /dev/null 2>&1
221 tar -xvf ${BUILD_DIR}/install_components.tgz --skip-old-files
222 popd > /dev/null 2>&1
226 #rm -rf ${BUILD_DIR}/install_components.tgz
229 function print_usage()
231 echo "Usage: ${0} [OPTIONS] [COMMAND]"
233 echo " -u, --update Full OS update"
234 echo " -k, --kubernetes Build for Kubernetes environment"
236 echo " deploy Run through all deployment steps"
237 echo " compile PROX compile only"
238 echo " runtime_image Apply runtime configuration only"
242 # Parse options and comman
246 echo 'Full OS update will be done!'
250 echo "Kubernetes environment is set!"
257 COMMAND="runtime_image"
263 echo "Unknown option/command ${opt}"
270 if [ "${COMMAND}" == "compile" ]; then
271 echo "PROX compile only..."
273 elif [ "${COMMAND}" == "runtime_image" ]; then
274 echo "Runtime image intallation and configuration..."
276 elif [ "${COMMAND}" == "deploy" ]; then
277 [ ! -d ${BUILD_DIR} ] && ${SUDO} mkdir -p ${BUILD_DIR}
278 ${SUDO} chmod 0777 ${BUILD_DIR}
282 if [ "${K8S_ENV}" == "y" ]; then
292 if [ "${K8S_ENV}" == "y" ]; then
294 create_minimal_install