diff options
Diffstat (limited to 'tools/k8s/test-containers/trafficgen-pods/trex')
7 files changed, 310 insertions, 0 deletions
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 +WgSqjy0NiLFoJEoNE5JYjz2XHTgBDKZ7Sr+oAto9/cOe3G5JsCyMFvCIIhrm/YIs8pwkqJ +sPMEPg6DbG6P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vWOJbvvQ1voTOiDF8LTOu60/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) |