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 RAMSPEED_DIR="/opt/ramspeed"
22 STRESSNG_DIR="/opt/stressng"
23 UNIXBENCH_DIR="/opt/unixbench"
25 PROX_COMMIT="80dfeb5c734cc4d681f467e853a541a8a91fe1cf"
26 PROX_CHECKOUT="git checkout ${PROX_COMMIT}"
27 ## Next line is overruling the PROX_COMMIT and will replace the version with a very specific patch. Should be commented out
28 ## if you want to use a committed version of PROX with the COMMIT ID specified above
29 ## As an example: Following line has the commit for testing IMIX, IPV6, ... It is the merge of all PROX commits on May 27th 2020
30 #PROX_CHECKOUT="git fetch \"https://gerrit.opnfv.org/gerrit/samplevnf\" refs/changes/23/70223/1 && git checkout FETCH_HEAD"
31 MULTI_BUFFER_LIB_VER="0.52"
32 export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}"
33 export RTE_TARGET="x86_64-native-linuxapp-gcc"
35 # By default, do not update OS
37 # By default, asumming that we are in the VM
40 # If already running from root, no need for sudo
42 [ $(id -u) -ne 0 ] && SUDO="sudo"
44 function os_pkgs_install()
46 ${SUDO} yum install -y deltarpm yum-utils
48 # NASM repository for AESNI MB library
49 #${SUDO} yum-config-manager --add-repo http://www.nasm.us/nasm.repo
51 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
52 ${SUDO} yum install -y git wget gcc unzip libpcap-devel ncurses-devel \
53 libedit-devel lua-devel kernel-devel iperf3 pciutils \
54 numactl-devel vim tuna openssl-devel wireshark \
57 ${SUDO} wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm
58 ${SUDO} rpm -ivh nasm-2.14.02-0.fc27.x86_64.rpm
61 function k8s_os_pkgs_runtime_install()
63 [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y
65 # Install required dynamically linked libraries + required packages
66 ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \
72 # huge pages to be used by DPDK
73 ${SUDO} sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf'
75 ${SUDO} sh -c '(echo "options vfio enable_unsafe_noiommu_mode=1") > /etc/modprobe.d/vfio.conf'
76 ${SUDO} sh -c '(echo "vfio") > /etc/modules-load.d/vfio.conf'
77 ${SUDO} sh -c '(echo "vfio-pci") > /etc/modules-load.d/vfio.conf'
78 # Enabling tuned with the realtime-virtual-guest profile
79 pushd ${BUILD_DIR} > /dev/null 2>&1
80 wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm
81 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
82 # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however
83 # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future
84 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps
85 ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps
86 # 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
87 # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail.
88 # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM
89 # and update the realtime-virtual-guest-variables.conf accordingly.
90 echo "isolated_cores=1-3" | ${SUDO} tee -a /etc/tuned/realtime-virtual-guest-variables.conf
91 ${SUDO} tuned-adm profile realtime-virtual-guest
93 # 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
94 # assigned to this VM depends on the flavor used. We don't know at this time what that will be.
95 ${SUDO} chmod +x ${BUILD_DIR}/check_prox_system_setup.sh
96 ${SUDO} mv ${BUILD_DIR}/check_prox_system_setup.sh /usr/local/libexec/
97 ${SUDO} mv ${BUILD_DIR}/check-prox-system-setup.service /etc/systemd/system/
98 ${SUDO} systemctl daemon-reload
99 ${SUDO} systemctl enable check-prox-system-setup.service
100 popd > /dev/null 2>&1
103 function k8s_os_cfg()
105 [ ! -f /etc/ssh/ssh_host_rsa_key ] && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N ''
106 [ ! -f /etc/ssh/ssh_host_ecdsa_key ] && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N ''
107 [ ! -f /etc/ssh/ssh_host_ed25519_key ] && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ''
109 [ ! -d /var/run/sshd ] && mkdir -p /var/run/sshd
114 useradd -m -d /home/${USER_NAME} -s /bin/bash -U ${USER_NAME}
115 echo "${USER_NAME}:${USER_PWD}" | chpasswd
116 usermod -aG wheel ${USER_NAME}
118 echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheelnopass
121 function mblib_install()
123 export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-${MULTI_BUFFER_LIB_VER}"
125 # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used
126 pushd ${BUILD_DIR} > /dev/null 2>&1
127 wget https://github.com/01org/intel-ipsec-mb/archive/v${MULTI_BUFFER_LIB_VER}.zip
128 unzip v${MULTI_BUFFER_LIB_VER}.zip
129 pushd ${AESNI_MULTI_BUFFER_LIB_PATH}
130 make -j`getconf _NPROCESSORS_ONLN`
132 popd > /dev/null 2>&1
133 popd > /dev/null 2>&1
136 function trex_install()
138 pushd ${TREX_DIR} > /dev/null 2>&1
139 wget --no-cache https://trex-tgen.cisco.com/trex/release/latest
141 popd > /dev/null 2>&1
144 function unixbench_install()
146 pushd ${UNIXBENCH_DIR} > /dev/null 2>&1
147 git clone https://github.com/kdlucas/byte-unixbench
148 popd > /dev/null 2>&1
151 function ramspeed_install()
153 RAMSPEED_BUILD_DIR = "${RAMSPEED_DIR}/ramspeed-smp"
154 pushd ${RAMSPEED_DIR} > /dev/null 2>&1
155 git clone https://github.com/cruvolo/ramspeed-smp
156 pushd ${RAMSPEED_BUILD_DIR} > /dev/null 2>&1
159 popd > /dev/null 2>&1
160 popd > /dev/null 2>&1
163 function collectd_install()
165 ${SUDO} yum -y install collectd
168 function fio_install()
170 ${SUDO} yum -y install fio
173 function stressng_install()
175 STRESSNG_BUILD_DIR = "${STRESSNG_DIR}/stress-ng"
176 pushd ${STRESSNG_DIR} > /dev/null 2>&1
177 git clone https://github.com/ColinIanKing/stress-ng
178 ${SUDO} yum -y install libaio-devel libbsd-devel libcap-devel libattr-devel libgcrypt-devel
179 ${SUDO} yum -y install Judy-devel keyutils-libs-devel lksctp-tools-devel libatomic zlib-devel
180 pushd ${STRESSNG_BUILD_DIR} > /dev/null 2>&1
184 popd > /dev/null 2>&1
185 popd > /dev/null 2>&1
188 function dpdk_install()
190 # Build DPDK for the latest kernel installed
191 LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1`
192 export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build"
194 # Get and compile DPDK
195 pushd ${BUILD_DIR} > /dev/null 2>&1
196 wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz
197 tar -xf ./dpdk-${DPDK_VERSION}.tar.xz
198 popd > /dev/null 2>&1
200 ${SUDO} ln -s ${RTE_SDK} ${BUILD_DIR}/dpdk
202 pushd ${RTE_SDK} > /dev/null 2>&1
203 make config T=${RTE_TARGET}
204 # Starting from DPDK 20.05, the IGB_UIO driver is not compiled by default.
205 # Uncomment the sed command to enable the driver compilation
206 #${SUDO} sed -i 's/CONFIG_RTE_EAL_IGB_UIO=n/c\/CONFIG_RTE_EAL_IGB_UIO=y' ${RTE_SDK}/build/.config
208 # For Kubernetes environment we use host vfio module
209 if [ "${K8S_ENV}" == "y" ]; then
210 sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/g' ${RTE_SDK}/build/.config
211 sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/g' ${RTE_SDK}/build/.config
212 sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/g' ${RTE_SDK}/build/.config
215 # Compile with MB library
216 sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config
217 make -j`getconf _NPROCESSORS_ONLN`
218 ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET}
219 popd > /dev/null 2>&1
222 function prox_compile()
225 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX
226 make -j`getconf _NPROCESSORS_ONLN`
227 ${SUDO} cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/build/app/prox ${BUILD_DIR}/prox
228 popd > /dev/null 2>&1
231 function prox_install()
233 # Clone and compile PROX
234 pushd ${BUILD_DIR} > /dev/null 2>&1
235 git clone https://git.opnfv.org/samplevnf
236 pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX > /dev/null 2>&1
237 bash -c "${PROX_CHECKOUT}"
238 popd > /dev/null 2>&1
240 popd > /dev/null 2>&1
243 function port_info_build()
245 [ ! -d ${BUILD_DIR}/port_info ] && echo "Skipping port_info compilation..." && return
247 pushd ${BUILD_DIR}/port_info > /dev/null 2>&1
249 ${SUDO} cp ${BUILD_DIR}/port_info/build/app/port_info_app ${BUILD_DIR}/port_info_app
250 popd > /dev/null 2>&1
253 function create_minimal_install()
255 ldd ${BUILD_DIR}/prox | awk '{ if ($(NF-1) != "=>") print $(NF-1) }' >> ${BUILD_DIR}/list_of_install_components
257 echo "${BUILD_DIR}/prox" >> ${BUILD_DIR}/list_of_install_components
258 echo "${BUILD_DIR}/port_info_app" >> ${BUILD_DIR}/list_of_install_components
260 tar -czvhf ${BUILD_DIR}/install_components.tgz -T ${BUILD_DIR}/list_of_install_components
265 ${SUDO} yum autoremove -y
266 ${SUDO} yum clean all
267 ${SUDO} rm -rf /var/cache/yum
270 function k8s_runtime_image()
272 k8s_os_pkgs_runtime_install
276 pushd / > /dev/null 2>&1
277 tar -xvf ${BUILD_DIR}/install_components.tgz --skip-old-files
278 popd > /dev/null 2>&1
282 #rm -rf ${BUILD_DIR}/install_components.tgz
285 function print_usage()
287 echo "Usage: ${0} [OPTIONS] [COMMAND]"
289 echo " -u, --update Full OS update"
290 echo " -k, --kubernetes Build for Kubernetes environment"
292 echo " deploy Run through all deployment steps"
293 echo " compile PROX compile only"
294 echo " runtime_image Apply runtime configuration only"
298 # Parse options and comman
302 echo 'Full OS update will be done!'
306 echo "Kubernetes environment is set!"
313 COMMAND="runtime_image"
319 echo "Unknown option/command ${opt}"
326 if [ "${COMMAND}" == "compile" ]; then
327 echo "PROX compile only..."
329 elif [ "${COMMAND}" == "runtime_image" ]; then
330 echo "Runtime image intallation and configuration..."
332 elif [ "${COMMAND}" == "deploy" ]; then
333 [ ! -d ${BUILD_DIR} ] && ${SUDO} mkdir -p ${BUILD_DIR}
334 ${SUDO} chmod 0777 ${BUILD_DIR}
338 if [ "${K8S_ENV}" == "y" ]; then
356 if [ "${K8S_ENV}" == "y" ]; then
358 create_minimal_install