diff options
author | Sridhar K. N. Rao <sridhar.rao@spirent.com> | 2021-11-02 14:18:18 +0530 |
---|---|---|
committer | Al Morton <acm@research.att.com> | 2021-11-03 18:10:42 +0000 |
commit | 773934de71fafcd332879838bf519ef3d90271e1 (patch) | |
tree | f9d442007c643f1c9e4efb6a0c34815c932f9359 /tools/k8s | |
parent | 0ab7ff90c3fec546275fd35ffc13cb787c03721e (diff) |
K8S: PROX and TREX containers.
This patch adds source files to build prox and trex containers.
Signed-off-by: Sridhar K. N. Rao <sridhar.rao@spirent.com>
Change-Id: I9a26672bc4869e663e6afc64741dbb9ededbb832
Diffstat (limited to 'tools/k8s')
15 files changed, 899 insertions, 0 deletions
diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/Dockerfile b/tools/k8s/test-containers/trafficgen-pods/prox/Dockerfile new file mode 100644 index 00000000..3235e725 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/Dockerfile @@ -0,0 +1,75 @@ +## +## Copyright (c) 2019 Intel Corporation +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +################################################## +# Build all components in separate builder image # +################################################## +FROM centos:7 as builder + +ARG BUILD_DIR=/opt/rapid + +COPY ./port_info ${BUILD_DIR}/port_info + +COPY ./deploycentostools.sh ${BUILD_DIR}/ +RUN chmod +x ${BUILD_DIR}/deploycentostools.sh \ + && ${BUILD_DIR}/deploycentostools.sh -k deploy + + +RUN rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO && curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo +RUN yum groupinstall -y "Development Tools" +RUN yum install -y golang; yum clean all + +## +## Download and Build APP-NetUtil +## +WORKDIR /root/go/src/ +RUN mkdir github.com && cd github.com && mkdir openshift && cd openshift && git clone https://github.com/openshift/app-netutil +WORKDIR /root/go/src/github.com/openshift/app-netutil +RUN make c_sample +#RUN cp bin/libnetutil_api.so /lib64/libnetutil_api.so; cp bin/libnetutil_api.h /usr/include/libnetutil_api.h + + +############################# +# Create slim runtime image # +############################# +FROM centos:7 + +ARG BUILD_DIR=/opt/rapid + +COPY ./deploycentostools.sh ${BUILD_DIR}/ +COPY --from=builder ${BUILD_DIR}/install_components.tgz ${BUILD_DIR}/install_components.tgz +COPY --from=builder ${BUILD_DIR}/src ${BUILD_DIR}/src +COPY --from=builder /root/go/src/github.com/openshift/app-netutil/bin/c_sample /usr/bin/c_sample +COPY --from=builder /root/go/src/github.com/openshift/app-netutil/bin/libnetutil_api.so /lib64/libnetutil_api.so +COPY --from=builder /root/go/src/github.com/openshift/app-netutil/bin/libnetutil_api.h /usr/include/libnetutil_api.h + +RUN chmod a+rwx ${BUILD_DIR} && chmod +x ${BUILD_DIR}/deploycentostools.sh \ + && ${BUILD_DIR}/deploycentostools.sh -k runtime_image + +RUN yum install -y pciutils iproute; yum clean all + +# Expose SSH and PROX ports +EXPOSE 22 8474 + +# Copy SSH keys +COPY ./rapid_rsa_key.pub /home/centos/.ssh/authorized_keys +COPY ./rapid_rsa_key.pub /root/.ssh/authorized_keys + +# Copy startup script +COPY ./start.sh /start.sh +RUN chmod +x /start.sh + +#ENTRYPOINT ["/start.sh"] diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/deploycentostools.sh b/tools/k8s/test-containers/trafficgen-pods/prox/deploycentostools.sh new file mode 100644 index 00000000..80af81fd --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/deploycentostools.sh @@ -0,0 +1,298 @@ +#!/usr/bin/env bash +## +## Copyright (c) 2010-2020 Intel Corporation +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +# Directory for package build +BUILD_DIR="/opt/rapid" +DPDK_VERSION="20.05" +MULTI_BUFFER_LIB_VER="0.52" +export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}" +export RTE_TARGET="x86_64-native-linuxapp-gcc" + +# By default, do not update OS +OS_UPDATE="n" +# By default, asumming that we are in the VM +K8S_ENV="n" + +# If already running from root, no need for sudo +SUDO="" +[ $(id -u) -ne 0 ] && SUDO="sudo" + +function os_pkgs_install() +{ + ${SUDO} yum install -y deltarpm yum-utils + + # NASM repository for AESNI MB library + #${SUDO} yum-config-manager --add-repo http://www.nasm.us/nasm.repo + + [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y + ${SUDO} yum install -y git wget gcc unzip libpcap-devel ncurses-devel \ + libedit-devel lua-devel kernel-devel iperf3 pciutils \ + numactl-devel vim tuna openssl-devel wireshark \ + make driverctl + + ${SUDO} wget --no-check-certificate https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm + ${SUDO} rpm -ivh nasm-2.14.02-0.fc27.x86_64.rpm +} + +function k8s_os_pkgs_runtime_install() +{ + [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y + + # Install required dynamically linked libraries + required packages + ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \ + openssh-clients sudo +} + +function os_cfg() +{ + # huge pages to be used by DPDK + ${SUDO} sh -c '(echo "vm.nr_hugepages = 1024") > /etc/sysctl.conf' + + ${SUDO} sh -c '(echo "options vfio enable_unsafe_noiommu_mode=1") > /etc/modprobe.d/vfio.conf' + ${SUDO} sh -c '(echo "vfio") > /etc/modules-load.d/vfio.conf' + ${SUDO} sh -c '(echo "vfio-pci") > /etc/modules-load.d/vfio.conf' + # Enabling tuned with the realtime-virtual-guest profile + pushd ${BUILD_DIR} > /dev/null 2>&1 + wget http://linuxsoft.cern.ch/cern/centos/7/rt/x86_64/Packages/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm + 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 + # Install with --nodeps. The latest CentOS cloud images come with a tuned version higher than 2.8. These 2 packages however + # do not depend on v2.8 and also work with tuned 2.9. Need to be careful in the future + ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-realtime-2.8.0-5.el7_4.2.noarch.rpm --nodeps + ${SUDO} rpm -ivh ${BUILD_DIR}/tuned-profiles-nfv-guest-2.8.0-5.el7_4.2.noarch.rpm --nodeps + # 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 + # isolated CPUs so we can start the realtime-virtual-guest profile. If we don't, that command will fail. + # When the VM will be instantiated, the check_kernel_params service will check for the real number of cores available to this VM + # and update the realtime-virtual-guest-variables.conf accordingly. + echo "isolated_cores=1-3" | ${SUDO} tee -a /etc/tuned/realtime-virtual-guest-variables.conf + ${SUDO} tuned-adm profile realtime-virtual-guest + + # 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 + # assigned to this VM depends on the flavor used. We don't know at this time what that will be. + ${SUDO} chmod +x ${BUILD_DIR}/check_prox_system_setup.sh + ${SUDO} mv ${BUILD_DIR}/check_prox_system_setup.sh /usr/local/libexec/ + ${SUDO} mv ${BUILD_DIR}/check-prox-system-setup.service /etc/systemd/system/ + ${SUDO} systemctl daemon-reload + ${SUDO} systemctl enable check-prox-system-setup.service + popd > /dev/null 2>&1 +} + +function k8s_os_cfg() +{ + [ ! -f /etc/ssh/ssh_host_rsa_key ] && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' + [ ! -f /etc/ssh/ssh_host_ecdsa_key ] && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' + [ ! -f /etc/ssh/ssh_host_ed25519_key ] && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N '' + + [ ! -d /var/run/sshd ] && mkdir -p /var/run/sshd + + USER_NAME="centos" + USER_PWD="centos" + + useradd -m -d /home/${USER_NAME} -s /bin/bash -U ${USER_NAME} + echo "${USER_NAME}:${USER_PWD}" | chpasswd + usermod -aG wheel ${USER_NAME} + + echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheelnopass +} + +function mblib_install() +{ + export AESNI_MULTI_BUFFER_LIB_PATH="${BUILD_DIR}/intel-ipsec-mb-${MULTI_BUFFER_LIB_VER}" + + # Downloading the Multi-buffer library. Note that the version to download is linked to the DPDK version being used + pushd ${BUILD_DIR} > /dev/null 2>&1 + wget https://github.com/01org/intel-ipsec-mb/archive/v${MULTI_BUFFER_LIB_VER}.zip + unzip v${MULTI_BUFFER_LIB_VER}.zip + pushd ${AESNI_MULTI_BUFFER_LIB_PATH} + make -j`getconf _NPROCESSORS_ONLN` + ${SUDO} make install + popd > /dev/null 2>&1 + popd > /dev/null 2>&1 +} + +function dpdk_install() +{ + # Build DPDK for the latest kernel installed + LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1` + export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build" + + # Get and compile DPDK + pushd ${BUILD_DIR} > /dev/null 2>&1 + wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz + tar -xf ./dpdk-${DPDK_VERSION}.tar.xz + popd > /dev/null 2>&1 + + ${SUDO} ln -s ${RTE_SDK} ${BUILD_DIR}/dpdk + + pushd ${RTE_SDK} > /dev/null 2>&1 + make config T=${RTE_TARGET} + # Starting from DPDK 20.05, the IGB_UIO driver is not compiled by default. + # Uncomment the sed command to enable the driver compilation + #${SUDO} sed -i 's/CONFIG_RTE_EAL_IGB_UIO=n/c\/CONFIG_RTE_EAL_IGB_UIO=y' ${RTE_SDK}/build/.config + + # For Kubernetes environment we use host vfio module + if [ "${K8S_ENV}" == "y" ]; then + sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/g' ${RTE_SDK}/build/.config + sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/g' ${RTE_SDK}/build/.config + sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/g' ${RTE_SDK}/build/.config + fi + + # Compile with MB library + sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config + make -j`getconf _NPROCESSORS_ONLN` + ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET} + popd > /dev/null 2>&1 +} + +function prox_compile() +{ + # Compile PROX + pushd ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX + COMMIT_ID=$(git rev-parse HEAD) + echo "${COMMIT_ID}" > ${BUILD_DIR}/commit_id + make -j`getconf _NPROCESSORS_ONLN` + ${SUDO} cp ${BUILD_DIR}/samplevnf/VNFs/DPPD-PROX/build/app/prox ${BUILD_DIR}/prox + popd > /dev/null 2>&1 +} + +function prox_install() +{ + # Clone PROX + pushd ${BUILD_DIR} > /dev/null 2>&1 + git clone https://git.opnfv.org/samplevnf + cp -R ./samplevnf/VNFs/DPPD-PROX/helper-scripts/rapid ./src + popd > /dev/null 2>&1 + prox_compile + + # Clean build folder + rm -rf ${BUILD_DIR}/samplevnf +} + +function port_info_build() +{ + [ ! -d ${BUILD_DIR}/port_info ] && echo "Skipping port_info compilation..." && return + + pushd ${BUILD_DIR}/port_info > /dev/null 2>&1 + make + ${SUDO} cp ${BUILD_DIR}/port_info/build/app/port_info_app ${BUILD_DIR}/port_info_app + popd > /dev/null 2>&1 +} + +function create_minimal_install() +{ + ldd ${BUILD_DIR}/prox | awk '{ if ($(NF-1) != "=>") print $(NF-1) }' >> ${BUILD_DIR}/list_of_install_components + + echo "${BUILD_DIR}/prox" >> ${BUILD_DIR}/list_of_install_components + echo "${BUILD_DIR}/port_info_app" >> ${BUILD_DIR}/list_of_install_components + echo "${BUILD_DIR}/commit_id" >> ${BUILD_DIR}/list_of_install_components + + tar -czvhf ${BUILD_DIR}/install_components.tgz -T ${BUILD_DIR}/list_of_install_components +} + +function cleanup() +{ + ${SUDO} yum autoremove -y + ${SUDO} yum clean all + ${SUDO} rm -rf /var/cache/yum +} + +function k8s_runtime_image() +{ + k8s_os_pkgs_runtime_install + k8s_os_cfg + cleanup + + pushd / > /dev/null 2>&1 + tar -xvf ${BUILD_DIR}/install_components.tgz --skip-old-files + popd > /dev/null 2>&1 + + ldconfig + + rm -rf ${BUILD_DIR}/install_components.tgz +} + +function print_usage() +{ + echo "Usage: ${0} [OPTIONS] [COMMAND]" + echo "Options:" + echo " -u, --update Full OS update" + echo " -k, --kubernetes Build for Kubernetes environment" + echo "Commands:" + echo " deploy Run through all deployment steps" + echo " compile PROX compile only" + echo " runtime_image Apply runtime configuration only" +} + +COMMAND="" +# Parse options and comman +for opt in "$@"; do + case ${opt} in + -u|--update) + echo 'Full OS update will be done!' + OS_UPDATE="y" + ;; + -k|--kubernetes) + echo "Kubernetes environment is set!" + K8S_ENV="y" + ;; + compile) + COMMAND="compile" + ;; + runtime_image) + COMMAND="runtime_image" + ;; + deploy) + COMMAND="deploy" + ;; + *) + echo "Unknown option/command ${opt}" + print_usage + exit 1 + ;; + esac +done + +if [ "${COMMAND}" == "compile" ]; then + echo "PROX compile only..." + prox_compile +elif [ "${COMMAND}" == "runtime_image" ]; then + echo "Runtime image intallation and configuration..." + k8s_runtime_image +elif [ "${COMMAND}" == "deploy" ]; then + [ ! -d ${BUILD_DIR} ] && ${SUDO} mkdir -p ${BUILD_DIR} + ${SUDO} chmod 0777 ${BUILD_DIR} + + os_pkgs_install + + if [ "${K8S_ENV}" == "y" ]; then + k8s_os_cfg + else + os_cfg + fi + + mblib_install + dpdk_install + prox_install + + if [ "${K8S_ENV}" == "y" ]; then + port_info_build + create_minimal_install + fi + + cleanup +else + print_usage +fi diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/port_info/Makefile b/tools/k8s/test-containers/trafficgen-pods/prox/port_info/Makefile new file mode 100644 index 00000000..f91cf156 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/port_info/Makefile @@ -0,0 +1,42 @@ +## +## Copyright (c) 2019 Intel Corporation +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +ifeq ($(RTE_SDK),) +$(error "Please define RTE_SDK environment variable") +endif + +# Default target, can be overridden by command line or environment +RTE_TARGET ?= x86_64-native-linuxapp-gcc + +include $(RTE_SDK)/mk/rte.vars.mk + +# binary name +APP = port_info_app + +# all source are stored in SRCS-y +SRCS-y := port_info.c + +CFLAGS += $(WERROR_FLAGS) + +# workaround for a gcc bug with noreturn attribute +# http://gcc.gnu.org/bugzilla/show_bug.cgi?id=12603 +ifeq ($(CONFIG_RTE_TOOLCHAIN_GCC),y) +CFLAGS_main.o += -Wno-return-type +endif + +EXTRA_CFLAGS += -O3 -g -Wfatal-errors + +include $(RTE_SDK)/mk/rte.extapp.mk diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/port_info/port_info.c b/tools/k8s/test-containers/trafficgen-pods/prox/port_info/port_info.c new file mode 100644 index 00000000..79bd0c0b --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/port_info/port_info.c @@ -0,0 +1,66 @@ +/* +// Copyright (c) 2019 Intel Corporation +// +// Licensed under the Apache License, Version 2.0 (the "License"); +// you may not use this file except in compliance with the License. +// You may obtain a copy of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +// See the License for the specific language governing permissions and +// limitations under the License. +*/ + +#include <stdint.h> +#include <inttypes.h> +#include <rte_eal.h> +#include <rte_ethdev.h> +#include <rte_version.h> + +static const uint16_t rx_rings = 1, tx_rings = 1; +static const struct rte_eth_conf port_conf = { .link_speeds = ETH_LINK_SPEED_AUTONEG }; + +static inline int +port_info(void) +{ + uint8_t port_id; + int ret_val; + + RTE_ETH_FOREACH_DEV(port_id) { + ret_val = rte_eth_dev_configure(port_id, rx_rings, tx_rings, &port_conf); + if (ret_val != 0) + return ret_val; + +#if RTE_VERSION < RTE_VERSION_NUM(19,8,0,0) + struct ether_addr addr; +#else + struct rte_ether_addr addr; +#endif + rte_eth_macaddr_get(port_id, &addr); + printf("Port %u MAC: %02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 + ":%02" PRIx8 ":%02" PRIx8 ":%02" PRIx8 "\n", + (unsigned) port_id, + addr.addr_bytes[0], addr.addr_bytes[1], + addr.addr_bytes[2], addr.addr_bytes[3], + addr.addr_bytes[4], addr.addr_bytes[5]); + } + + return 0; +} + +int +main(int argc, char *argv[]) +{ + /* Initialize the Environment Abstraction Layer (EAL). */ + int ret = rte_eal_init(argc, argv); + if (ret < 0) + rte_exit(EXIT_FAILURE, "Error with EAL initialization\n"); + + argc -= ret; + argv += ret; + + return port_info(); +} diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/rapid_rsa_key b/tools/k8s/test-containers/trafficgen-pods/prox/rapid_rsa_key new file mode 100644 index 00000000..6ecdb277 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/rapid_rsa_key @@ -0,0 +1,49 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNza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hQ/oE8ZXqtBqJ3CbINPEyuLK9PYj9e2zABoEOcXTaJcvmVve97xhhw6om +zVgd4qw70oUAAAAVeWt5bHVsaW5AMGJkODI0NDk5MTYwAQIDBAUG +-----END OPENSSH PRIVATE KEY----- diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/rapid_rsa_key.pub b/tools/k8s/test-containers/trafficgen-pods/prox/rapid_rsa_key.pub new file mode 100644 index 00000000..c735d178 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/rapid_rsa_key.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCs2xZMUPvSWOMv5addzQZuU3sqWJyKK4ZLYKD+1w/zNke/OTz+WRHzkRxcam9iseRMXV1pkJtBTLeKzQq8/bs6GiWvFW/0cCfgGQDa6BbGnYVp48cqnQUGQyC6kYcVWHN6DiEDigW2Oloz3kBMxxZMH77ue6Xp1b5/n++HHPJrnKkSDX3LC1mYOiiJfPp9ahpaBKqPLQ2IsWgkSg0TkliPPZcdOAEMpntKv6gC2j39w57cbkmwLIwW8IgiGub9gizynCSomw8wQ+DoNsbo/pLVhucvqsz8GzBWOnUihak9VuZmENuGU1KT/hkMisy1soFA8c/3Qq74LmKNjpk0niAPsLCb5kunip0iomg2h7OYbwLRi87xa98wtGjJQKHBIvc+ZQaXTYl1YmBgb8Hft8lBubzR3oc68ATmu87ln11vAG/NkLRinl1fXfQ601qOk6F8FE3WpshhgaCki4sSBBQoLf3+LWEYw1M5UOMngY1uJJSFSRtzriPSTYH65iz3ju1+7Cui026Yki4ObC2rFQfAK4o1OFRWEDdTW1uUJYxLoTFVjjNrASVcFP+mt6IBhoWXMW5igePO5Zc3RY6/Ty2JEkvWWt8yKzxn2yh9hzeoFKqUuACxbl20Hk8wjLcnFdaqMVAh2COXFZnngG723l+o9KCBL502MNpyXS/V7oHIGQ== default@default diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/start.sh b/tools/k8s/test-containers/trafficgen-pods/prox/start.sh new file mode 100755 index 00000000..7fbeedf8 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/start.sh @@ -0,0 +1,39 @@ +#!/usr/bin/env bash +## +## Copyright (c) 2010-2019 Intel Corporation +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +function save_k8s_envs() +{ + printenv | grep "PCIDEVICE_INTEL_COM" > /opt/rapid/k8s_sriov_device_plugin_envs +} + +function create_tun() +{ + mkdir -p /dev/net + mknod /dev/net/tun c 10 200 + chmod 600 /dev/net/tun +} + +save_k8s_envs +create_tun + +# Ready for testing +touch /opt/rapid/system_ready_for_rapid + +# Start SSH server in background +/usr/sbin/sshd + +exec sleep infinity diff --git a/tools/k8s/test-containers/trafficgen-pods/prox/vhost_substitute.sh b/tools/k8s/test-containers/trafficgen-pods/prox/vhost_substitute.sh new file mode 100755 index 00000000..b33f3521 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/prox/vhost_substitute.sh @@ -0,0 +1,19 @@ +!/bin/bash + +# The first two commands update one of the 'if' checks to remove +# the check for 'master == VHOST_USER_SET_VRING_CALL'. +# +# Search for: " !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) &&". +# Replace with: " !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED)) {". +sed -i -e 's/ !(dev->flags & VIRTIO_DEV_VDPA_CONFIGURED) &&/ !(dev->flags \& VIRTIO_DEV_VDPA_CONFIGURED)) {/g' lib/librte_vhost/vhost_user.c +# +# Search for line with: " msg.request.master == VHOST_USER_SET_VRING_CALL) {". +# Delete the line. +sed -i -e '/ msg\.request\.master == VHOST_USER_SET_VRING_CALL) {/d' lib/librte_vhost/vhost_user.c + + +# Force an RARP message to be sent out. +# +# Search for line with: " hw->started = true;". +# Append line: " virtio_notify_peers(dev);". +sed -i -e '/ hw->started = true;/a virtio_notify_peers(dev);' drivers/net/virtio/virtio_ethdev.c diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/Dockerfile b/tools/k8s/test-containers/trafficgen-pods/trex/Dockerfile new file mode 100644 index 00000000..7258533a --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/trex/Dockerfile @@ -0,0 +1,46 @@ +########################################################## +# Build app-netutil components in separate builder image # +########################################################## +FROM centos:7 as builder + +RUN rpm --import https://mirror.go-repo.io/centos/RPM-GPG-KEY-GO-REPO && curl -s https://mirror.go-repo.io/centos/go-repo.repo | tee /etc/yum.repos.d/go-repo.repo +RUN yum groupinstall -y "Development Tools" +RUN yum install -y wget numactl-devel git golang make; yum clean all + +## +## Download and Build APP-NetUtil +## +WORKDIR /root/go/src/ +RUN mkdir github.com && cd github.com && mkdir openshift && cd openshift && git clone https://github.com/openshift/app-netutil +WORKDIR /root/go/src/github.com/openshift/app-netutil +RUN make c_sample + +############################# +# Create slim runtime image # +############################# +FROM centos:7 + +ARG BUILD_DIR=/root + +COPY ./deploycentostools.sh ${BUILD_DIR}/ +COPY --from=builder /root/go/src/github.com/openshift/app-netutil/bin/c_sample /usr/bin/c_sample +COPY --from=builder /root/go/src/github.com/openshift/app-netutil/bin/libnetutil_api.so /lib64/libnetutil_api.so +COPY --from=builder /root/go/src/github.com/openshift/app-netutil/bin/libnetutil_api.h /usr/include/libnetutil_api.h + +RUN chmod a+rwx ${BUILD_DIR} && chmod +x ${BUILD_DIR}/deploycentostools.sh \ + && ${BUILD_DIR}/deploycentostools.sh + +WORKDIR /root +COPY trex_cfg.yaml.j2 /root/trex_cfg.yaml.j2 +COPY vppconf.py /root/vppconf.py +RUN wget --no-check-certificate https://trex-tgn.cisco.com/trex/release/latest; tar -xzvf latest; rm latest + +# Expose SSH +EXPOSE 22 + +# Copy SSH keys +COPY ./rapid_rsa_key.pub /home/centos/.ssh/authorized_keys +COPY ./rapid_rsa_key.pub /root/.ssh/authorized_keys + +RUN yum -y install python3 python3-pip; yum clean all +RUN pip3 install jinja2 diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/deploycentostools.sh b/tools/k8s/test-containers/trafficgen-pods/trex/deploycentostools.sh new file mode 100644 index 00000000..69889b9d --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/trex/deploycentostools.sh @@ -0,0 +1,126 @@ +#!/usr/bin/env bash +## +## Copyright (c) 2010-2020 Intel Corporation +## +## Licensed under the Apache License, Version 2.0 (the "License"); +## you may not use this file except in compliance with the License. +## You may obtain a copy of the License at +## +## http://www.apache.org/licenses/LICENSE-2.0 +## +## Unless required by applicable law or agreed to in writing, software +## distributed under the License is distributed on an "AS IS" BASIS, +## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +## See the License for the specific language governing permissions and +## limitations under the License. +## + +# Directory for package build +BUILD_DIR="/root" +DPDK_VERSION="20.05" +MULTI_BUFFER_LIB_VER="0.52" +export RTE_SDK="${BUILD_DIR}/dpdk-${DPDK_VERSION}" +export RTE_TARGET="x86_64-native-linuxapp-gcc" + +# By default, do not update OS +OS_UPDATE="n" +# By default, asumming that we are in the VM +K8S_ENV="y" + +# If already running from root, no need for sudo +SUDO="" +[ $(id -u) -ne 0 ] && SUDO="sudo" + +function os_pkgs_install() +{ + ${SUDO} yum install -y deltarpm yum-utils + + # NASM repository for AESNI MB library + #${SUDO} yum-config-manager --add-repo http://www.nasm.us/nasm.repo + + [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y + ${SUDO} yum install -y git wget gcc unzip libpcap-devel ncurses-devel \ + libedit-devel lua-devel kernel-devel iperf3 pciutils \ + numactl-devel vim tuna openssl-devel wireshark \ + make driverctl + + ${SUDO} wget https://www.nasm.us/pub/nasm/releasebuilds/2.14.02/linux/nasm-2.14.02-0.fc27.x86_64.rpm + ${SUDO} rpm -ivh nasm-2.14.02-0.fc27.x86_64.rpm +} + + +function os_pkgs_runtime_install() +{ + [ "${OS_UPDATE}" == "y" ] && ${SUDO} yum update -y + + # Install required dynamically linked libraries + required packages + ${SUDO} yum install -y numactl-libs libpcap openssh openssh-server \ + openssh-clients sudo iproute +} + + +function os_cfg() +{ + [ ! -f /etc/ssh/ssh_host_rsa_key ] && ssh-keygen -t rsa -f /etc/ssh/ssh_host_rsa_key -N '' + [ ! -f /etc/ssh/ssh_host_ecdsa_key ] && ssh-keygen -t ecdsa -f /etc/ssh/ssh_host_ecdsa_key -N '' + [ ! -f /etc/ssh/ssh_host_ed25519_key ] && ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N '' + + [ ! -d /var/run/sshd ] && mkdir -p /var/run/sshd + + USER_NAME="centos" + USER_PWD="centos" + + useradd -m -d /home/${USER_NAME} -s /bin/bash -U ${USER_NAME} + echo "${USER_NAME}:${USER_PWD}" | chpasswd + usermod -aG wheel ${USER_NAME} + + echo "%wheel ALL=(ALL) NOPASSWD: ALL" > /etc/sudoers.d/wheelnopass +} + +function dpdk_install() +{ + # Build DPDK for the latest kernel installed + LATEST_KERNEL_INSTALLED=`ls -v1 /lib/modules/ | tail -1` + export RTE_KERNELDIR="/lib/modules/${LATEST_KERNEL_INSTALLED}/build" + + # Get and compile DPDK + pushd ${BUILD_DIR} > /dev/null 2>&1 + wget http://fast.dpdk.org/rel/dpdk-${DPDK_VERSION}.tar.xz + tar -xf ./dpdk-${DPDK_VERSION}.tar.xz + popd > /dev/null 2>&1 + + ${SUDO} ln -s ${RTE_SDK} ${BUILD_DIR}/dpdk + + pushd ${RTE_SDK} > /dev/null 2>&1 + make config T=${RTE_TARGET} + # Starting from DPDK 20.05, the IGB_UIO driver is not compiled by default. + # Uncomment the sed command to enable the driver compilation + #${SUDO} sed -i 's/CONFIG_RTE_EAL_IGB_UIO=n/c\/CONFIG_RTE_EAL_IGB_UIO=y' ${RTE_SDK}/build/.config + + # For Kubernetes environment we use host vfio module + if [ "${K8S_ENV}" == "y" ]; then + sed -i 's/CONFIG_RTE_EAL_IGB_UIO=y/CONFIG_RTE_EAL_IGB_UIO=n/g' ${RTE_SDK}/build/.config + sed -i 's/CONFIG_RTE_LIBRTE_KNI=y/CONFIG_RTE_LIBRTE_KNI=n/g' ${RTE_SDK}/build/.config + sed -i 's/CONFIG_RTE_KNI_KMOD=y/CONFIG_RTE_KNI_KMOD=n/g' ${RTE_SDK}/build/.config + fi + + # Compile with MB library if reqd. + # sed -i '/CONFIG_RTE_LIBRTE_PMD_AESNI_MB=n/c\CONFIG_RTE_LIBRTE_PMD_AESNI_MB=y' ${RTE_SDK}/build/.config + make -j`getconf _NPROCESSORS_ONLN` + ln -s ${RTE_SDK}/build ${RTE_SDK}/${RTE_TARGET} + popd > /dev/null 2>&1 +} + +function cleanup() +{ + ${SUDO} yum autoremove -y + ${SUDO} yum clean all + ${SUDO} rm -rf /var/cache/yum + ${SUDO} rm ${BUILD_DIR}/*.xz +} + +os_pkgs_install +os_cfg +dpdk_install +os_pkgs_runtime_install +cleanup diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/rapid_rsa_key b/tools/k8s/test-containers/trafficgen-pods/trex/rapid_rsa_key new file mode 100644 index 00000000..6ecdb277 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/trex/rapid_rsa_key @@ -0,0 +1,49 @@ +-----BEGIN OPENSSH PRIVATE KEY----- +b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAACFwAAAAdzc2gtcn +NhAAAAAwEAAQAAAgEArNsWTFD70ljjL+WnXc0GblN7KliciiuGS2Cg/tcP8zZHvzk8/lkR +85EcXGpvYrHkTF1daZCbQUy3is0KvP27OholrxVv9HAn4BkA2ugWxp2FaePHKp0FBkMgup +GHFVhzeg4hA4oFtjpaM95ATMcWTB++7nul6dW+f5/vhxzya5ypEg19ywtZmDooiXz6fWoa +WgSqjy0NiLFoJEoNE5JYjz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zUObcKrm5mWAYddINbflAYVswpT/LxNl7jduUsQd3Ul6fOBX4sBK +rWYMv3Qo4z25oShqvWOJbvvQ1voTOiDF8LTOu60/YbbOfF116J6BcWTHbwe8z+Du8SxdVi +1N4tFcadL7HqsZEAAAEBAN4ma7nbSI0fA3QM1IK9h5cN/h0qMk91Syh7+vFyNfe/DILFnJ +0TGNaYhAow1jNMOQKeyEJOfuZkeMdR9/ohtfwSvzSJml/k0JV9aIZHehncZOMt93Gi6WtC ++Os2owyhcXMJN7MbKo1e3Ln21OyaAJi6TAdwSDivFSytvNCKoX8NncQu/UIPzNQVJcrvJn +SZ+0AHFeuZVl9HgxZY1fUvIs24m9QnYH3HpMiYc2p8UT1hEOqq1bJpgKx9WHhj0fNCBsZ1 +6zTnCDa/HiDADHmlif6pyEu7nD+3MHAeGxS7LJjmMSvtbH/ltrYaz6wFSowlr/RiX7Z8pT +Ib1lf7KPYulYUAAAEBAMcxzoKSEZt/eYz5w4h9Bs6tdBEBnmSzwni8P0DTv1q0sDan1g4Q ++Mcuo42lSXS9aTmfI+hJDRSuRraLE9xzmxUJ+R2bQkpOLgG6QOF1uU36ZtMoxtptII8pXT +yQtIW2sHSz9Kgv16PFp98EaEfwzmdk/C8A6NxoGW7EpzAXzXZYLRSwgAr6wVE83jUsbIu5 +lAN6DG6vIm62PLsxmpDZuS5idQwxP8DP4itHMMRh2jE0+msQAWHRQ514nCTqeuy/ORbNSO +4A1yMy1KxXBH6hQ/oE8ZXqtBqJ3CbINPEyuLK9PYj9e2zABoEOcXTaJcvmVve97xhhw6om +zVgd4qw70oUAAAAVeWt5bHVsaW5AMGJkODI0NDk5MTYwAQIDBAUG +-----END OPENSSH PRIVATE KEY----- diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/rapid_rsa_key.pub b/tools/k8s/test-containers/trafficgen-pods/trex/rapid_rsa_key.pub new file mode 100644 index 00000000..c735d178 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/trex/rapid_rsa_key.pub @@ -0,0 +1 @@ +ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAACAQCs2xZMUPvSWOMv5addzQZuU3sqWJyKK4ZLYKD+1w/zNke/OTz+WRHzkRxcam9iseRMXV1pkJtBTLeKzQq8/bs6GiWvFW/0cCfgGQDa6BbGnYVp48cqnQUGQyC6kYcVWHN6DiEDigW2Oloz3kBMxxZMH77ue6Xp1b5/n++HHPJrnKkSDX3LC1mYOiiJfPp9ahpaBKqPLQ2IsWgkSg0TkliPPZcdOAEMpntKv6gC2j39w57cbkmwLIwW8IgiGub9gizynCSomw8wQ+DoNsbo/pLVhucvqsz8GzBWOnUihak9VuZmENuGU1KT/hkMisy1soFA8c/3Qq74LmKNjpk0niAPsLCb5kunip0iomg2h7OYbwLRi87xa98wtGjJQKHBIvc+ZQaXTYl1YmBgb8Hft8lBubzR3oc68ATmu87ln11vAG/NkLRinl1fXfQ601qOk6F8FE3WpshhgaCki4sSBBQoLf3+LWEYw1M5UOMngY1uJJSFSRtzriPSTYH65iz3ju1+7Cui026Yki4ObC2rFQfAK4o1OFRWEDdTW1uUJYxLoTFVjjNrASVcFP+mt6IBhoWXMW5igePO5Zc3RY6/Ty2JEkvWWt8yKzxn2yh9hzeoFKqUuACxbl20Hk8wjLcnFdaqMVAh2COXFZnngG723l+o9KCBL502MNpyXS/V7oHIGQ== default@default diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/trex_cfg.yaml b/tools/k8s/test-containers/trafficgen-pods/trex/trex_cfg.yaml new file mode 100644 index 00000000..384817a4 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/trex/trex_cfg.yaml @@ -0,0 +1,10 @@ +- port_limit : 2 + version : 2 + c : 8 + interfaces : ["--vdev=net_memif0,socket=/var/lib/cni/usrspcni/memif--net1.sock,role=slave,id=0", "--vdev=net_memif1,socket=/var/lib/cni/usrspcni/memif--net2.sock,role=slave,id=1"] # list of the interfaces + port_info : # set eh mac addr + + - ip : 1.1.1.1 + default_gw : 2.2.2.2 + - ip : 2.2.2.2 + default_gw : 1.1.1.1 diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/trex_cfg.yaml.j2 b/tools/k8s/test-containers/trafficgen-pods/trex/trex_cfg.yaml.j2 new file mode 100644 index 00000000..9a42bd97 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/trex/trex_cfg.yaml.j2 @@ -0,0 +1,8 @@ +- port_limit : 2 + version : 2 + interfaces : ["--vdev=net_memif0,socket={{data.if1}},role=master", "--vdev=net_memif1,socket={{data.if2}},role=master"] # list of the interfaces + port_info : # set eth mac addr + - dest_mac : "3c:fd:fe:b4:41:09" # port 0 + src_mac : "3c:fd:fe:b4:41:08" + - dest_mac : "3c:fd:fe:b4:41:08" # port 1 + src_mac : "3c:fd:fe:b4:41:09" diff --git a/tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py b/tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py new file mode 100644 index 00000000..ad7d63d8 --- /dev/null +++ b/tools/k8s/test-containers/trafficgen-pods/trex/vppconf.py @@ -0,0 +1,70 @@ +import select +import subprocess +import logging +import threading +import sys +import os +import locale +import time +from jinja2 import Environment, FileSystemLoader + +CMD_PREFIX = 'cmd : ' +VERBOSITY = 'info' +_logger = logging.getLogger(__name__) + +def run_task(cmd, logger=_logger, msg=None, check_error=False): + """Run task, report errors and log overall status. + + Run given task using ``subprocess.Popen``. Log the commands + used and any errors generated. Prints stdout to screen if + in verbose mode and returns it regardless. Prints stderr to + screen always. + + :param cmd: Exact command to be executed + :param logger: Logger to write details to + :param msg: Message to be shown to user + :param check_error: Throw exception on error + + :returns: (stdout, stderr) + """ + def handle_error(exception): + """Handle errors by logging and optionally raising an exception. + """ + logger.error( + 'Unable to execute %(cmd)s. Exception: %(exception)s', + {'cmd': ' '.join(cmd), 'exception': exception}) + if check_error: + raise exception + + try: + proc = subprocess.Popen(map(os.path.expanduser, cmd), + stdout=subprocess.PIPE, + stderr=subprocess.PIPE) + output = proc.communicate()[0].decode("utf-8") + except OSError as ex: + handle_error(ex) + else: + if proc.returncode: + ex = subprocess.CalledProcessError(proc.returncode, cmd, stderr) + handle_error(ex) + return output + +ifaces = [] +sout = run_task(['/usr/bin/c_sample']) +if sout: + for line in sout.split('\n'): + if 'Path=' in line: + print(line) + field = line.split(' ')[-1].split('=')[-1] + ifaces.append(field) +ifacesdir = { + 'if1' : ifaces[0], + 'if2' : ifaces[1]} + +if len(ifaces) == 2: + file_loader = FileSystemLoader('./') + env = Environment(loader = file_loader) + fileref = env.get_template('./trex_cfg.yaml.j2') + renderedcon = fileref.render(data=ifacesdir) + with open('/etc/trex_cfg.yaml', "w+") as fh: + fh.write(renderedcon) |