diff --git a/Dockerfile.saivs b/Dockerfile similarity index 78% rename from Dockerfile.saivs rename to Dockerfile index 45c10af9..21be1aae 100644 --- a/Dockerfile.saivs +++ b/Dockerfile @@ -58,37 +58,10 @@ RUN git clone --recursive https://github.com/Azure/sonic-swss-common \ WORKDIR /sai -RUN git clone https://github.com/Azure/sonic-sairedis.git \ - && cd sonic-sairedis \ - && . /sai.env \ - && git checkout ${SAIREDIS_ID} \ - && git submodule update --init --recursive \ - && cd SAI && git fetch origin \ - && git checkout ${SAI_ID} \ - && git submodule update --init --recursive \ - && cd .. \ - && ./autogen.sh && ./configure --with-sai=vs && make -j4 \ - && make install && ldconfig \ - && mkdir -p /usr/include/sai \ - && mv SAI/experimental /usr/include/sai/experimental \ - && mv SAI/inc /usr/include/sai/inc \ - && mkdir -p /usr/include/sai/meta \ - && cp SAI/meta/*.h /usr/include/sai/meta/ \ - && mv tests .. && rm -rf * && mv ../tests . - - -# Build attr_list_generator and generate /etc/sai/sai.json +# Install SAI attributes metadata JSON generator COPY scripts/gen_attr_list /sai/gen_attr_list - RUN apt-get install -y nlohmann-json-dev -RUN cd /sai/gen_attr_list \ - && mkdir build && cd build \ - && cmake .. \ - && make -j$(nproc) \ - && mkdir -p /etc/sai \ - && ./attr_list_generator > /etc/sai/sai.json \ - && rm -rf /sai/gen_attr_list - + # Install ptf_nn_agent dependencies RUN apt-get install -y libffi-dev \ && wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz \ @@ -118,11 +91,9 @@ RUN sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf \ RUN sed -ri '/imklog/s/^/#/' /etc/rsyslog.conf # Setup supervisord -COPY scripts/sai.profile /etc/sai.d/sai.profile -COPY scripts/lanemap.ini /usr/share/sonic/hwsku/lanemap.ini -COPY scripts/redis_start.sh /usr/bin/redis_start.sh COPY scripts/veth-create.sh /usr/bin/veth-create.sh -COPY scripts/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY scripts/redis_start.sh /usr/bin/redis_start.sh +COPY configs/supervisord.conf /etc/supervisor/conf.d/supervisord.conf # Install PTF dependencies RUN pip3 install scapy diff --git a/Dockerfile.client b/Dockerfile.client index 96fa55d9..07617bc3 100644 --- a/Dockerfile.client +++ b/Dockerfile.client @@ -45,7 +45,7 @@ RUN apt-get install -y libffi-dev cmake wget \ # Disable kernel logging support RUN sed -ri '/imklog/s/^/#/' /etc/rsyslog.conf -COPY scripts/client/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY configs/client/supervisord.conf /etc/supervisor/conf.d/supervisord.conf COPY scripts/veth-create.sh /usr/bin/veth-create.sh WORKDIR /sai-challenger/tests diff --git a/Dockerfile.sai.server b/Dockerfile.sai.server deleted file mode 100644 index 4ea17bfc..00000000 --- a/Dockerfile.sai.server +++ /dev/null @@ -1,167 +0,0 @@ -FROM debian:buster-slim - -MAINTAINER andriy.kokhan@gmail.com - -RUN echo "deb [arch=amd64] http://debian-archive.trafficmanager.net/debian/ buster main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb-src [arch=amd64] http://debian-archive.trafficmanager.net/debian/ buster main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb [arch=amd64] http://debian-archive.trafficmanager.net/debian-security/ buster/updates main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb-src [arch=amd64] http://debian-archive.trafficmanager.net/debian-security/ buster/updates main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb [arch=amd64] http://debian-archive.trafficmanager.net/debian buster-backports main" >> /etc/apt/sources.list - -## Make apt-get non-interactive -ENV DEBIAN_FRONTEND=noninteractive - -# Install generic packages -RUN apt-get -o Acquire::Check-Valid-Until=false update && apt-get install -y \ - apt-utils \ - vim \ - curl \ - wget \ - iproute2 \ - unzip \ - git \ - procps \ - build-essential \ - graphviz \ - doxygen \ - aspell \ - python3-pip \ - rsyslog \ - supervisor - -# Add support for supervisord to handle startup dependencies -RUN pip3 install supervisord-dependent-startup==1.4.0 - -# Install dependencies -RUN apt-get install -y redis-server libhiredis0.14 python3-redis - -# Install sonic-swss-common & sonic-sairedis building dependencies -RUN apt-get install -y \ - make libtool m4 autoconf dh-exec debhelper automake cmake pkg-config \ - libhiredis-dev libnl-3-dev libnl-genl-3-dev libnl-route-3-dev swig3.0 \ - libpython2.7-dev libgtest-dev libgmock-dev libboost-dev autoconf-archive - -RUN apt-get install -y \ - libnl-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-nf-3-dev libzmq3-dev - -COPY sai.env / -RUN git clone --recursive https://github.com/Azure/sonic-swss-common \ - && cd sonic-swss-common \ - && . /sai.env \ - && git checkout ${SWSS_COMMON_ID} \ - && ./autogen.sh && ./configure && dpkg-buildpackage -us -uc -b \ - && cd .. \ - && dpkg -i libswsscommon_1.0.0_amd64.deb \ - && dpkg -i libswsscommon-dev_1.0.0_amd64.deb \ - && rm -rf sonic-swss-common \ - && rm -f *swsscommon* - -WORKDIR /sai - -COPY *.deb . -RUN dpkg -i *.deb - -RUN git clone https://github.com/Azure/sonic-sairedis.git \ - && cd sonic-sairedis \ - && . /sai.env \ - && git checkout ${SAIREDIS_ID} \ - && git submodule update --init --recursive \ - && cd SAI && git fetch origin \ - && git checkout ${SAI_ID} \ - && git submodule update --init --recursive \ - && cd .. \ - && ./autogen.sh && ./configure --with-sai=vs && make -j4 \ - && make install && ldconfig \ - && mkdir -p /usr/include/sai \ - && mv SAI/experimental /usr/include/sai/experimental \ - && mv SAI/inc /usr/include/sai/inc \ - && mkdir -p /usr/include/sai/meta \ - && cp SAI/meta/*.h /usr/include/sai/meta/ \ - && mv tests .. && rm -rf * && mv ../tests . - - -# Build attr_list_generator and generate /etc/sai/sai.json -COPY scripts/gen_attr_list /sai/gen_attr_list - -RUN apt-get install -y nlohmann-json-dev -RUN cd /sai/gen_attr_list \ - && mkdir build && cd build \ - && cmake .. \ - && make -j$(nproc) \ - && mkdir -p /etc/sai \ - && ./attr_list_generator > /etc/sai/sai.json \ - && rm -rf /sai/gen_attr_list - -# Install ptf_nn_agent dependencies -RUN apt-get install -y libffi-dev \ - && wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz \ - && tar xvfz 1.0.0.tar.gz \ - && cd nanomsg-1.0.0 \ - && mkdir -p build \ - && cd build \ - && cmake .. \ - && make install \ - && ldconfig \ - && cd ../.. \ - && rm -rf 1.0.0.tar.gz nanomsg-1.0.0 \ - && pip3 install nnpy - -# Update Redis configuration: -# - Enable keyspace notifications as per sonic-swss-common/README.md -# - Do not daemonize redis-server since supervisord will manage it -# - Do not save Redis DB on disk -RUN sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf \ - && sed -ri 's/^unixsocketperm .../unixsocketperm 777/' /etc/redis/redis.conf \ - && sed -ri 's/redis-server.sock/redis.sock/' /etc/redis/redis.conf \ - && sed -ri 's/notify-keyspace-events ""/notify-keyspace-events AKE/' /etc/redis/redis.conf \ - && sed -ri 's/^daemonize yes/daemonize no/' /etc/redis/redis.conf \ - && sed -ri 's/^save/# save/' /etc/redis/redis.conf - -# Disable kernel logging support -RUN sed -ri '/imklog/s/^/#/' /etc/rsyslog.conf - -# Setup supervisord -COPY scripts/sai.profile /etc/sai.d/sai.profile -COPY scripts/lanemap.ini /usr/share/sonic/hwsku/lanemap.ini -COPY scripts/redis_start.sh /usr/bin/redis_start.sh -COPY scripts/veth-create.sh /usr/bin/veth-create.sh -COPY scripts/server/supervisord.conf /etc/supervisor/conf.d/supervisord.conf - -# Install SAI Challenger CLI dependencies -RUN pip3 install click==8.0 pytest - -# Deploy SAI Challenger CLI -COPY setup.py /sai-challenger/setup.py -COPY cli/__init__.py /sai-challenger/cli/__init__.py -COPY cli/main.py /sai-challenger/cli/main.py -COPY common/setup.py /sai-challenger/common/setup.py -COPY common/__init__.py /sai-challenger/common/__init__.py -COPY common/sai.py /sai-challenger/common/sai.py -COPY common/sai_npu.py /sai-challenger/common/sai_npu.py -COPY common/sai_dataplane.py /sai-challenger/common/sai_dataplane.py -COPY topologies /sai-challenger/topologies -COPY scripts/sai-cli-completion.sh /sai-challenger/scripts/sai-cli-completion.sh -RUN echo ". /sai-challenger/scripts/sai-cli-completion.sh" >> /root/.bashrc - -# Deploy a remote commands listener -COPY scripts/redis-cmd-listener.py /sai-challenger/scripts/redis-cmd-listener.py - -# Install ptf_nn_agent and PTF helpers (required by sai_dataplane.py) -COPY ptf/ptf_nn/ptf_nn_agent.py /ptf/ptf_nn/ptf_nn_agent.py -COPY ptf/setup.py /ptf/setup.py -COPY ptf/README.md /ptf/README.md -COPY ptf/src/ptf/*.py /ptf/src/ptf/ -COPY ptf/src/ptf/platforms/*.py /ptf/src/ptf/platforms/ -COPY ptf/requirements.txt /ptf/requirements.txt - -RUN echo "#mock" > /ptf/ptf \ - && pip3 install /ptf - -# Install SAI Challenger CLI and the remote commands listener -RUN pip3 install --editable /sai-challenger/common \ - && pip3 install --editable /sai-challenger - -WORKDIR /sai-challenger - -CMD ["/usr/bin/supervisord"] - diff --git a/Dockerfile.saivs.intel b/Dockerfile.saivs.intel deleted file mode 100644 index 393ba1a0..00000000 --- a/Dockerfile.saivs.intel +++ /dev/null @@ -1,159 +0,0 @@ -FROM debian:buster-slim - -MAINTAINER andriy.kokhan@gmail.com - -RUN echo "deb [arch=amd64] http://debian-archive.trafficmanager.net/debian/ buster main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb-src [arch=amd64] http://debian-archive.trafficmanager.net/debian/ buster main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb [arch=amd64] http://debian-archive.trafficmanager.net/debian-security/ buster/updates main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb-src [arch=amd64] http://debian-archive.trafficmanager.net/debian-security/ buster/updates main contrib non-free" >> /etc/apt/sources.list && \ - echo "deb [arch=amd64] http://debian-archive.trafficmanager.net/debian buster-backports main" >> /etc/apt/sources.list - -## Make apt-get non-interactive -ENV DEBIAN_FRONTEND=noninteractive - -# Install generic packages -RUN apt-get -o Acquire::Check-Valid-Until=false update && apt-get install -y \ - apt-utils \ - vim \ - curl \ - wget \ - iproute2 \ - unzip \ - git \ - procps \ - build-essential \ - graphviz \ - doxygen \ - aspell \ - python3-pip \ - rsyslog \ - supervisor - -# Add support for supervisord to handle startup dependencies -RUN pip3 install supervisord-dependent-startup==1.4.0 - -# Install dependencies -RUN apt-get install -y redis-server libhiredis0.14 python3-redis - -# Install sonic-swss-common & sonic-sairedis building dependencies -RUN apt-get install -y \ - make libtool m4 autoconf dh-exec debhelper automake cmake pkg-config \ - libhiredis-dev libnl-3-dev libnl-genl-3-dev libnl-route-3-dev swig3.0 \ - libpython2.7-dev libgtest-dev libgmock-dev libboost-dev autoconf-archive - -RUN apt-get install -y \ - libnl-3-dev libnl-genl-3-dev libnl-route-3-dev libnl-nf-3-dev libzmq3-dev - -COPY sai.env / -RUN git clone --recursive https://github.com/Azure/sonic-swss-common \ - && cd sonic-swss-common \ - && . /sai.env \ - && git checkout ${SWSS_COMMON_ID} \ - && ./autogen.sh && ./configure && dpkg-buildpackage -us -uc -b \ - && cd .. \ - && dpkg -i libswsscommon_1.0.0_amd64.deb \ - && dpkg -i libswsscommon-dev_1.0.0_amd64.deb \ - && rm -rf sonic-swss-common \ - && rm -f *swsscommon* - -WORKDIR /sai - -# Intel specific dependencies -RUN apt-get install -y \ - libgoogle-perftools4 - -COPY *.deb /sai/ -RUN dpkg -i *.deb - -RUN git clone https://github.com/Azure/sonic-sairedis.git \ - && cd sonic-sairedis \ - && . /sai.env \ - && git checkout ${SAIREDIS_ID} \ - && git submodule update --init --recursive \ - && cd SAI && git fetch origin \ - && git checkout ${SAI_ID} \ - && git submodule update --init --recursive \ - && cd .. \ - && ./autogen.sh && ./configure && make -j4 \ - && make install && ldconfig \ - && mkdir -p /usr/include/sai \ - && mv SAI/experimental /usr/include/sai/experimental \ - && mv SAI/inc /usr/include/sai/inc \ - && mkdir -p /usr/include/sai/meta \ - && cp SAI/meta/*.h /usr/include/sai/meta/ \ - && mv tests .. && rm -rf * && mv ../tests . - - -# Build attr_list_generator and generate /etc/sai/sai.json -COPY scripts/gen_attr_list /sai/gen_attr_list - -RUN apt-get install -y nlohmann-json-dev -RUN cd /sai/gen_attr_list \ - && mkdir build && cd build \ - && cmake .. \ - && make -j$(nproc) \ - && mkdir -p /etc/sai \ - && ./attr_list_generator > /etc/sai/sai.json \ - && rm -rf /sai/gen_attr_list - -# Install ptf_nn_agent dependencies -RUN apt-get install -y libffi-dev \ - && wget https://github.com/nanomsg/nanomsg/archive/1.0.0.tar.gz \ - && tar xvfz 1.0.0.tar.gz \ - && cd nanomsg-1.0.0 \ - && mkdir -p build \ - && cd build \ - && cmake .. \ - && make install \ - && ldconfig \ - && cd ../.. \ - && rm -rf 1.0.0.tar.gz nanomsg-1.0.0 \ - && pip3 install nnpy - -# Update Redis configuration: -# - Enable keyspace notifications as per sonic-swss-common/README.md -# - Do not daemonize redis-server since supervisord will manage it -# - Do not save Redis DB on disk -RUN sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf \ - && sed -ri 's/^unixsocketperm .../unixsocketperm 777/' /etc/redis/redis.conf \ - && sed -ri 's/redis-server.sock/redis.sock/' /etc/redis/redis.conf \ - && sed -ri 's/notify-keyspace-events ""/notify-keyspace-events AKE/' /etc/redis/redis.conf \ - && sed -ri 's/^daemonize yes/daemonize no/' /etc/redis/redis.conf \ - && sed -ri 's/^save/# save/' /etc/redis/redis.conf - -# Disable kernel logging support -RUN sed -ri '/imklog/s/^/#/' /etc/rsyslog.conf - -# Setup supervisord -COPY platform/intel/veth-create.sh /usr/bin/veth-create.sh -COPY platform/intel/ports.json /usr/share/sonic/hwsku/ports.json -COPY platform/intel/switch-sai-cpu-veth.conf /usr/share/sonic/hwsku/switch-tna-sai.conf -COPY platform/intel/redis_start.sh /usr/bin/redis_start.sh -COPY platform/intel/model_start.sh /usr/bin/model_start.sh -COPY platform/intel/syncd_start.sh /usr/bin/syncd_start.sh -COPY platform/intel/supervisord.conf /etc/supervisor/conf.d/supervisord.conf - -# Install PTF dependencies -RUN pip3 install scapy - -# Install ptf_nn_agent and PTF helpers (required by sai_dataplane.py) -COPY ptf/ptf_nn/ptf_nn_agent.py /ptf/ptf_nn/ptf_nn_agent.py -COPY ptf/setup.py /ptf/setup.py -COPY ptf/README.md /ptf/README.md -COPY ptf/src/ptf/*.py /ptf/src/ptf/ -COPY ptf/src/ptf/platforms/*.py /ptf/src/ptf/platforms/ -COPY ptf/requirements.txt /ptf/requirements.txt - -RUN echo "#mock" > /ptf/ptf \ - && pip3 install /ptf - -# Install SAI Challenger CLI dependencies -RUN pip3 install click==8.0 -RUN echo ". /sai-challenger/scripts/sai-cli-completion.sh" >> /root/.bashrc - -RUN pip3 install pytest pytest_dependency pytest-html - -WORKDIR /sai-challenger/tests - -CMD ["/usr/bin/supervisord"] - diff --git a/Dockerfile.saivs.server b/Dockerfile.server similarity index 80% rename from Dockerfile.saivs.server rename to Dockerfile.server index 6abb7023..deb100af 100644 --- a/Dockerfile.saivs.server +++ b/Dockerfile.server @@ -58,36 +58,9 @@ RUN git clone --recursive https://github.com/Azure/sonic-swss-common \ WORKDIR /sai -RUN git clone https://github.com/Azure/sonic-sairedis.git \ - && cd sonic-sairedis \ - && . /sai.env \ - && git checkout ${SAIREDIS_ID} \ - && git submodule update --init --recursive \ - && cd SAI && git fetch origin \ - && git checkout ${SAI_ID} \ - && git submodule update --init --recursive \ - && cd .. \ - && ./autogen.sh && ./configure --with-sai=vs && make -j4 \ - && make install && ldconfig \ - && mkdir -p /usr/include/sai \ - && mv SAI/experimental /usr/include/sai/experimental \ - && mv SAI/inc /usr/include/sai/inc \ - && mkdir -p /usr/include/sai/meta \ - && cp SAI/meta/*.h /usr/include/sai/meta/ \ - && mv tests .. && rm -rf * && mv ../tests . - - -# Build attr_list_generator and generate /etc/sai/sai.json +# Install SAI attributes metadata JSON generator COPY scripts/gen_attr_list /sai/gen_attr_list - RUN apt-get install -y nlohmann-json-dev -RUN cd /sai/gen_attr_list \ - && mkdir build && cd build \ - && cmake .. \ - && make -j$(nproc) \ - && mkdir -p /etc/sai \ - && ./attr_list_generator > /etc/sai/sai.json \ - && rm -rf /sai/gen_attr_list # Install ptf_nn_agent dependencies RUN apt-get install -y libffi-dev \ @@ -118,11 +91,23 @@ RUN sed -ri 's/^# unixsocket/unixsocket/' /etc/redis/redis.conf \ RUN sed -ri '/imklog/s/^/#/' /etc/rsyslog.conf # Setup supervisord -COPY scripts/sai.profile /etc/sai.d/sai.profile -COPY scripts/lanemap.ini /usr/share/sonic/hwsku/lanemap.ini -COPY scripts/redis_start.sh /usr/bin/redis_start.sh COPY scripts/veth-create.sh /usr/bin/veth-create.sh -COPY scripts/server/supervisord.conf /etc/supervisor/conf.d/supervisord.conf +COPY scripts/redis_start.sh /usr/bin/redis_start.sh +COPY configs/server/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +# Install ptf_nn_agent and PTF helpers (required by sai_dataplane.py) +COPY ptf/ptf_nn/ptf_nn_agent.py /ptf/ptf_nn/ptf_nn_agent.py +COPY ptf/setup.py /ptf/setup.py +COPY ptf/README.md /ptf/README.md +COPY ptf/src/ptf/*.py /ptf/src/ptf/ +COPY ptf/src/ptf/platforms/*.py /ptf/src/ptf/platforms/ +COPY ptf/requirements.txt /ptf/requirements.txt + +RUN echo "#mock" > /ptf/ptf \ + && pip3 install /ptf + +# Deploy a remote commands listener +COPY scripts/redis-cmd-listener.py /sai-challenger/scripts/redis-cmd-listener.py # Install SAI Challenger CLI dependencies RUN pip3 install click==8.0 pytest @@ -140,20 +125,6 @@ COPY topologies /sai-challenger/topologies COPY scripts/sai-cli-completion.sh /sai-challenger/scripts/sai-cli-completion.sh RUN echo ". /sai-challenger/scripts/sai-cli-completion.sh" >> /root/.bashrc -# Deploy a remote commands listener -COPY scripts/redis-cmd-listener.py /sai-challenger/scripts/redis-cmd-listener.py - -# Install ptf_nn_agent and PTF helpers (required by sai_dataplane.py) -COPY ptf/ptf_nn/ptf_nn_agent.py /ptf/ptf_nn/ptf_nn_agent.py -COPY ptf/setup.py /ptf/setup.py -COPY ptf/README.md /ptf/README.md -COPY ptf/src/ptf/*.py /ptf/src/ptf/ -COPY ptf/src/ptf/platforms/*.py /ptf/src/ptf/platforms/ -COPY ptf/requirements.txt /ptf/requirements.txt - -RUN echo "#mock" > /ptf/ptf \ - && pip3 install /ptf - # Install SAI Challenger CLI and the remote commands listener RUN pip3 install --editable /sai-challenger/common /sai-challenger diff --git a/README.md b/README.md index 85011c46..6fa08b7d 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,10 @@ cd sai-challenger/ git submodule update --init --recursive ``` +## Porting SAI Challenger to new platform + +For more information on how port SAI Challenger to new platform, please refer to [Porting Guide](docs/porting_guide.md) document. + ## SAI Challenger internals For more information on how SAI Challenger operates on SAI, please refer to [SAI operation](docs/sai_operation.md) document. diff --git a/build.sh b/build.sh new file mode 100755 index 00000000..a23103da --- /dev/null +++ b/build.sh @@ -0,0 +1,125 @@ +#!/bin/bash + +# exit when any command fails +set -e + +# keep track of the last executed command +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG +# echo an error message before exiting +trap 'echo ERROR: "\"${last_command}\" command filed with exit code $?."' ERR + +IMAGE_TYPE="standalone" +ASIC_TYPE="" +ASIC_PATH="" +TARGET="" + +print-help() { + echo + echo "$(basename ""$0"") [OPTIONS]" + echo "Options:" + echo " -h Print script usage" + echo " -i [standalone|client|server]" + echo " Image type to be created" + echo " -a ASIC" + echo " ASIC to be tested" + echo " -t TARGET" + echo " Target device with this NPU" + echo + exit 0 +} + +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + "-h"|"--help") + print-help + exit 0 + ;; + "-i"|"--image") + IMAGE_TYPE="$2" + shift + ;; + "-a"|"--asic") + ASIC_TYPE="$2" + shift + ;; + "-t"|"--target") + TARGET="$2" + shift + ;; + esac + shift +done + +if [[ "${IMAGE_TYPE}" != "standalone" && \ + "${IMAGE_TYPE}" != "client" && \ + "${IMAGE_TYPE}" != "server" ]]; then + echo "Unknown image type \"${IMAGE_TYPE}\"" + exit 1 +fi + +if [[ "${IMAGE_TYPE}" != "client" ]]; then + + if [ -z "${ASIC_TYPE}" ]; then + ASIC_TYPE="trident2" + fi + + ASIC_PATH=$(find -L -type d -name "${ASIC_TYPE}") + if [ -z "${ASIC_PATH}" ]; then + echo "Unknown ASIC type \"${ASIC_TYPE}\"" + exit 1 + fi + + if [ ! -z "${TARGET}" ]; then + if [ ! -d "${ASIC_PATH}/${TARGET}" ]; then + echo "Unknown target \"${TARGET}\"" + exit 1 + fi + else + # Get first folder as a default target + TARGETS=( $(find -L "${ASIC_PATH}" -mindepth 1 -maxdepth 1 -type d) ) + TARGET="${TARGETS[0]}" + if [ -z "${TARGET}" ]; then + echo "Not able to find a default target..." + exit 1 + fi + TARGET=$(basename $TARGET) + fi +fi + +print-build-options() { + echo + echo "===========================================" + echo " SAI Challenger build options" + echo "===========================================" + echo + echo " Docker image type : ${IMAGE_TYPE}" + echo " ASIC name : ${ASIC_TYPE}" + echo " ASIC target : ${TARGET}" + echo " Platform path : ${ASIC_PATH}" + echo + echo "===========================================" + echo +} + +trap print-build-options EXIT + +# Build base Docker image +if [ "${IMAGE_TYPE}" = "standalone" ]; then + docker build -f Dockerfile -t sc-base . +elif [ "${IMAGE_TYPE}" = "server" ]; then + docker build -f Dockerfile.server -t sc-server-base . +else + docker build -f Dockerfile.client -t sc-client . +fi + +# Build target Docker image +pushd "${ASIC_PATH}/${TARGET}" +if [ "${IMAGE_TYPE}" = "standalone" ]; then + docker build -f Dockerfile -t sc-${ASIC_TYPE}-${TARGET} . +elif [ "${IMAGE_TYPE}" = "server" ]; then + docker build -f Dockerfile.server -t sc-server-${ASIC_TYPE}-${TARGET} . +fi +popd + + diff --git a/common/sai.py b/common/sai.py index 3ff026a6..f14217b7 100644 --- a/common/sai.py +++ b/common/sai.py @@ -170,7 +170,10 @@ def __init__(self, exec_params): libsai = os.path.isfile("/usr/lib/libsai.so") or os.path.isfile("/usr/local/lib/libsai.so") self.libsaivs = exec_params["saivs"] or (not self.client_mode and not libsai) self.run_traffic = exec_params["traffic"] and not self.libsaivs + self.name = exec_params["asic"] + self.target = exec_params["target"] self.sku = exec_params["sku"] + self.asic_dir = exec_params["asic_dir"] @staticmethod def get_meta(obj_type=None): diff --git a/common/sai_npu.py b/common/sai_npu.py index db3048e0..ea705b13 100644 --- a/common/sai_npu.py +++ b/common/sai_npu.py @@ -28,7 +28,7 @@ def init(self, attr): # Load SKU configuration if any if self.sku is not None: try: - f = open(f"../sku/{self.sku}.json") + f = open(f"{self.asic_dir}{self.target}/sku/{self.sku}.json") self.sku_config = json.load(f) f.close() except Exception as e: diff --git a/scripts/client/supervisord.conf b/configs/client/supervisord.conf similarity index 100% rename from scripts/client/supervisord.conf rename to configs/client/supervisord.conf diff --git a/scripts/server/supervisord.conf b/configs/server/supervisord.conf similarity index 100% rename from scripts/server/supervisord.conf rename to configs/server/supervisord.conf diff --git a/configs/supervisord.conf b/configs/supervisord.conf new file mode 100644 index 00000000..96da5b33 --- /dev/null +++ b/configs/supervisord.conf @@ -0,0 +1,53 @@ +[supervisord] +logfile_maxbytes=1MB +logfile_backups=2 +nodaemon=true + +[eventlistener:dependent-startup] +command=python3 -m supervisord_dependent_startup +autostart=true +autorestart=unexpected +startretries=0 +exitcodes=0,3 +events=PROCESS_STATE +buffer_size=1024 + +[program:rsyslogd] +command=/usr/sbin/rsyslogd -n -iNONE +priority=1 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true + +[program:sai-challenger-installer] +command=/usr/bin/pip3 install --editable /sai-challenger/common /sai-challenger +priority=2 +autostart=false +autorestart=false +startsecs=0 +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true + +[program:redis] +command=/usr/bin/redis_start.sh --bind 127.0.0.1 --port 6379 +priority=3 +autostart=false +autorestart=true +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running sai-challenger-installer:exited + +[program:redis-cmd-listener] +command=/bin/bash -c "python3 /sai-challenger/scripts/redis-cmd-listener.py" +priority=4 +autostart=false +autorestart=true +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running redis:running sai-challenger-installer:exited + diff --git a/docs/client_server_mode.md b/docs/client_server_mode.md index 459ec4c4..78412bc6 100644 --- a/docs/client_server_mode.md +++ b/docs/client_server_mode.md @@ -1,51 +1,34 @@ -## To start SAI Challenger on top of vslib in client-server mode +## Running SAI Challenger in client-server mode -In client-server mode, SAI server - syncd linked with vslib - runs in one Docker container. -Whereas the client - SAI Challenger - runs in the separate Docker container. These two Docker containers can also be running on the separate physical hosts. - -Build Docker image with vslib SAI implementation: +Build client Docker image ```sh -docker build -f Dockerfile.saivs.server -t saivs-server . +./build.sh -i client ``` -Build SAI Challenger Docker image with SAI tests: +Build server Docker image for ASIC `trident2` target `saivs`: ```sh -docker build -f Dockerfile.client -t sai-challenger-client . +./build.sh -i server -a trident2 -t saivs ``` -Start SAI Challenger server: +Start SAI Challenger client: ```sh -docker run --name saivs \ - --cap-add=NET_ADMIN \ - --device /dev/net/tun:/dev/net/tun \ - -d saivs-server +./run.sh -i client ``` -Start SAI Challenger client: +Start SAI Challenger server: ```sh -docker run --name sai-challenger \ - -v $(pwd):/sai-challenger \ - --cap-add=NET_ADMIN \ - --device /dev/net/tun:/dev/net/tun \ - -d sai-challenger-client +./run.sh -i server -a trident2 -t saivs ``` -## To run SAI Challenger testcases in client-server mode - Run SAI Challenger testcases: ```sh -docker exec -ti sai-challenger pytest \ - --sai-server= --traffic \ - -v test_l2_basic.py +./exec.sh -i client pytest --asic trident2 --target saivs --sai-server=172.17.0.4 -v -k "test_l2_basic" ``` Run SAI Challenger testcases and generate HTML report: ```sh -docker exec -ti sai-challenger pytest -v \ - --sai-server= --traffic \ - --html=report.html --self-contained-html \ - test_l2_basic.py +./exec.sh -i client pytest --asic trident2 --target saivs --sai-server=172.17.0.4 -v -k "test_l2_basic" --html=report.html --self-contained-html ``` -**NOTE:** The option `--traffic` will be ignored when running on vslib SAI implementation. +**NOTE:** The option `--traffic` will be ignored when running on `saivs` target. diff --git a/docs/porting_guide.md b/docs/porting_guide.md new file mode 100644 index 00000000..b1276d3b --- /dev/null +++ b/docs/porting_guide.md @@ -0,0 +1,77 @@ +# Porting Guide + +SAI Challenger (SC) uses plugin-based approach to build and start a platform specific instance. So, it is expected that a new platform porting process will be as simple as adding a new entry in the `platform/` folder with very limited number of platform specific scripts and configuration files. + +## Platform folder + +Typical platform folder structure: +```sh +platform/ +├── +│   ├── +│   │   ├── +│   │   │ ├── configs/ (optional) +│   │   │ ├── Dockerfile +│   │   │ ├── Dockerfile.server +│   │   │ └── sku/ (optional) +│   │   ├── +│   │   │ ├── configs/ +│   │   │ ├── Dockerfile +│   │   │ └── sku/ +│   │ └── sai_npu.py (optional) +│   ├── +│   │   └── +│   │   ├── configs/ +│   │   ├── Dockerfile +│   │   ├── scripts/ (optional) +│   │   └── sku/ +│   └── sai_npu.py (optional) +``` + +The platform folder MAY contain multiple vendors. Each vendor folder MAY contain 1..n ASICs and optional vendor-specific `sai_npu` module. Each ASIC folder MAY contain 1..n targets (either HW device or simulator or emulator) and optional ASIC-specific `sai_npu` module. Each target's folder MUST contain either `Dockerfile` for standalone mode or `Dockerfile.server` for client-server mode or both. Also, the target's folder MAY contain optional `sku/` folder with JSON files that define front panel ports configuration as well as others target-specific files and folders. + +E.g., +```sh +platform/ +├── broadcom +│   ├── BCM56850 +│   │   └── saivs +│   │   ├── configs/ +│   │   ├── Dockerfile +│   │   ├── Dockerfile.server +│   │   └── sku/ +│   ├── sai_npu.py +│   └── trident2 -> BCM56850/ +└── intel + ├── README.md + ├── sai_npu.py + └── tofino + ├── model + │   ├── configs/ + │   ├── Dockerfile + │   ├── scenarios -> ../montara/scenarios/ + │   ├── scripts/ + │   └── sku/ + └── montara + ├── scenarios/ + └── sku/ +``` + +The target specific `Dockerfile` should be based on SC base Docker image created of `Dockerfile` located in SC root folder. Also, it should define `SC_PLATFORM`, `SC_ASIC` and `SC_TARGET` environment variables. These environment variables are used by SC `conftest.py` to properly initialize the test environment. +```sh +FROM sc-base + +MAINTAINER your@email.com + +ENV SC_PLATFORM=intel +ENV SC_ASIC=tofino +ENV SC_TARGET=model +``` + +The target specific `Dockerfile.server` should be based on SC base Docker image created of `Dockerfile.server` located in SC root folder. +```sh +FROM sc-server-base + +MAINTAINER your@email.com +``` + diff --git a/docs/standalone_mode.md b/docs/standalone_mode.md index 4e962497..390bdb20 100644 --- a/docs/standalone_mode.md +++ b/docs/standalone_mode.md @@ -1,49 +1,24 @@ -## To start SAI Challenger on top of vslib SAI implementation +## Running SAI Challenger in standalone mode -The vslib SAI implementation is used as a virtual data-plane interface in SONiC Virtual Switch (SONiC VS). Though it does not configure the forwarding path but still process SAI CRUD calls in proper manner. This allows to use vslib for SAI testcases development without running traffic. - -Build SAI Challenger Docker image with vslib SAI implementation: +Build Docker image for ASIC `trident2` target `saivs`: ```sh -docker build -f Dockerfile.saivs -t saivs-challenger . +./build.sh -a trident2 -t saivs ``` -Start SAI Challenger: -```sh -docker run --name sai-challenger-run \ - -v $(pwd):/sai-challenger \ - --cap-add=NET_ADMIN \ - --device /dev/net/tun:/dev/net/tun \ - -d saivs-challenger -``` - -## To start SAI Challenger on top of vendor-specific SAI implementation - -Copy Debian package with SAI library into sai-challenger/ folder. +**NOTE:** The `saivs` target - defined in sonic-sairedis - is used as a virtual data-plane interface in SONiC Virtual Switch (SONiC VS). Though it does not configure the forwarding path but still process SAI CRUD calls in proper manner. This allows to use `saivs` for SAI testcases development without running traffic. -Build SAI Challenger Docker image with vendor-specific SAI implementation: +Start Docker container: ```sh -docker build -f Dockerfile.sai -t sai-challenger . +./run.sh -a trident2 -t saivs ``` -Start SAI Challenger -```sh -docker run --name sai-challenger-run \ - -v $(pwd):/sai-challenger \ - --cap-add=NET_ADMIN \ - --device /dev/net/tun:/dev/net/tun \ - -d sai-challenger -``` - -## To run SAI Challenger testcases in standalone mode - Run SAI Challenger testcases: ```sh -docker exec -ti sai-challenger-run pytest -v +./exec.sh -a trident2 -t saivs pytest -v -k "test_l2_basic" ``` Run SAI Challenger testcases and generate HTML report: ```sh -docker exec -ti sai-challenger-run pytest -v \ - --html=report.html --self-contained-html +./exec.sh -a trident2 -t saivs pytest -v -k "test_l2_basic" --html=report.html --self-contained-html ``` diff --git a/exec.sh b/exec.sh new file mode 100755 index 00000000..074f3f83 --- /dev/null +++ b/exec.sh @@ -0,0 +1,142 @@ +#!/bin/bash + +# exit when any command fails +set -e + +# keep track of the last executed command +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG +# echo an error message before exiting +trap 'echo ERROR: "\"${last_command}\" command filed with exit code $?."' ERR + +IMAGE_TYPE="standalone" +ASIC_TYPE="" +ASIC_PATH="" +TARGET="" +EXEC_CMD="" + +print-help() { + echo + echo "$(basename ""$0"") [OPTIONS] [command]" + echo "Options:" + echo " -h Print script usage" + echo " -i [standalone|client|server]" + echo " Image type to be started" + echo " -a ASIC" + echo " ASIC to be tested" + echo " -t TARGET" + echo " Target device with this NPU" + echo + exit 0 +} + +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + "-h"|"--help") + print-help + exit 0 + ;; + "-i"|"--image") + IMAGE_TYPE="$2" + shift + ;; + "-a"|"--asic") + if [ -z "${EXEC_CMD}" ]; then + ASIC_TYPE="$2" + else + EXEC_CMD="${EXEC_CMD} ${1} ${2}" + fi + shift + ;; + "-t"|"--target") + if [ -z "${EXEC_CMD}" ]; then + TARGET="$2" + else + EXEC_CMD="${EXEC_CMD} ${1} ${2}" + fi + shift + ;; + *) + if [ -z "${EXEC_CMD}" ]; then + EXEC_CMD=${1} + else + EXEC_CMD="${EXEC_CMD} ${1}" + fi + ;; + esac + shift +done + +if [[ "${IMAGE_TYPE}" != "standalone" && \ + "${IMAGE_TYPE}" != "client" && \ + "${IMAGE_TYPE}" != "server" ]]; then + echo "Unknown image type \"${IMAGE_TYPE}\"" + exit 1 +fi + +if [[ "${IMAGE_TYPE}" != "client" ]]; then + + if [ -z "${ASIC_TYPE}" ]; then + ASIC_TYPE="trident2" + fi + + ASIC_PATH=$(find -L -type d -name "${ASIC_TYPE}") + if [ -z "${ASIC_PATH}" ]; then + echo "Unknown ASIC type \"${ASIC_TYPE}\"" + exit 1 + fi + + if [ ! -z "${TARGET}" ]; then + if [ ! -d "${ASIC_PATH}/${TARGET}" ]; then + echo "Unknown target \"${TARGET}\"" + exit 1 + fi + else + # Get first folder as a default target + TARGETS=( $(find -L "${ASIC_PATH}" -mindepth 1 -maxdepth 1 -type d) ) + TARGET="${TARGETS[0]}" + if [ -z "${TARGET}" ]; then + echo "Not able to find a default target..." + exit 1 + fi + TARGET=$(basename $TARGET) + fi +fi + +if [ -z "${EXEC_CMD}" ]; then + EXEC_CMD="bash" +fi + +print-start-options() { + echo + echo "===========================================" + echo " SAI Challenger run options" + echo "===========================================" + echo + echo " Docker image type : ${IMAGE_TYPE}" + + if [ "${IMAGE_TYPE}" != "client" ]; then + echo " ASIC name : ${ASIC_TYPE}" + echo " ASIC target : ${TARGET}" + echo " Platform path : ${ASIC_PATH}" + fi + + echo " Container name : ${CONTAINER}" + echo " Command : ${EXEC_CMD}" + echo + echo "===========================================" + echo +} + +trap print-start-options EXIT + +# Start Docker container +if [ "${IMAGE_TYPE}" = "standalone" ]; then + CONTAINER="sc-${ASIC_TYPE}-${TARGET}-run" +elif [ "${IMAGE_TYPE}" = "server" ]; then + CONTAINER="sc-server-${ASIC_TYPE}-${TARGET}-run" +else + CONTAINER="sc-client-run" +fi +docker exec -ti ${CONTAINER} ${EXEC_CMD} + diff --git a/platform/broadcom/BCM56850/saivs/Dockerfile b/platform/broadcom/BCM56850/saivs/Dockerfile new file mode 100644 index 00000000..7804036a --- /dev/null +++ b/platform/broadcom/BCM56850/saivs/Dockerfile @@ -0,0 +1,46 @@ +FROM sc-base + +MAINTAINER andriy.kokhan@gmail.com + +ENV SC_PLATFORM=broadcom +ENV SC_ASIC=BCM56850 +ENV SC_TARGET=saivs + +WORKDIR /sai + +RUN git clone https://github.com/Azure/sonic-sairedis.git \ + && cd sonic-sairedis \ + && . /sai.env \ + && git checkout ${SAIREDIS_ID} \ + && git submodule update --init --recursive \ + && cd SAI && git fetch origin \ + && git checkout ${SAI_ID} \ + && git submodule update --init --recursive \ + && cd .. \ + && ./autogen.sh && ./configure --with-sai=vs && make -j4 \ + && make install && ldconfig \ + && mkdir -p /usr/include/sai \ + && mv SAI/experimental /usr/include/sai/experimental \ + && mv SAI/inc /usr/include/sai/inc \ + && mkdir -p /usr/include/sai/meta \ + && cp SAI/meta/*.h /usr/include/sai/meta/ \ + && mv tests .. && rm -rf * && mv ../tests . + + +# Build attr_list_generator and generate /etc/sai/sai.json +RUN cd /sai/gen_attr_list \ + && mkdir build && cd build \ + && cmake .. \ + && make -j$(nproc) \ + && mkdir -p /etc/sai \ + && ./attr_list_generator > /etc/sai/sai.json + +# Setup supervisord +COPY configs/sai.profile /etc/sai.d/sai.profile +COPY configs/lanemap.ini /usr/share/sonic/hwsku/lanemap.ini +COPY configs/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +WORKDIR /sai-challenger/tests + +CMD ["/usr/bin/supervisord"] + diff --git a/platform/broadcom/BCM56850/saivs/Dockerfile.server b/platform/broadcom/BCM56850/saivs/Dockerfile.server new file mode 100644 index 00000000..bc5f42db --- /dev/null +++ b/platform/broadcom/BCM56850/saivs/Dockerfile.server @@ -0,0 +1,42 @@ +FROM sc-server-base + +MAINTAINER andriy.kokhan@gmail.com + +WORKDIR /sai + +RUN git clone https://github.com/Azure/sonic-sairedis.git \ + && cd sonic-sairedis \ + && . /sai.env \ + && git checkout ${SAIREDIS_ID} \ + && git submodule update --init --recursive \ + && cd SAI && git fetch origin \ + && git checkout ${SAI_ID} \ + && git submodule update --init --recursive \ + && cd .. \ + && ./autogen.sh && ./configure --with-sai=vs && make -j4 \ + && make install && ldconfig \ + && mkdir -p /usr/include/sai \ + && mv SAI/experimental /usr/include/sai/experimental \ + && mv SAI/inc /usr/include/sai/inc \ + && mkdir -p /usr/include/sai/meta \ + && cp SAI/meta/*.h /usr/include/sai/meta/ \ + && mv tests .. && rm -rf * && mv ../tests . + + +# Build SAI attributes metadata JSON generator and generate /etc/sai/sai.json +RUN cd /sai/gen_attr_list \ + && mkdir build && cd build \ + && cmake .. \ + && make -j$(nproc) \ + && mkdir -p /etc/sai \ + && ./attr_list_generator > /etc/sai/sai.json + +# Setup supervisord +COPY configs/sai.profile /etc/sai.d/sai.profile +COPY configs/lanemap.ini /usr/share/sonic/hwsku/lanemap.ini +COPY configs/server/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +WORKDIR /sai-challenger + +CMD ["/usr/bin/supervisord"] + diff --git a/scripts/lanemap.ini b/platform/broadcom/BCM56850/saivs/configs/lanemap.ini similarity index 100% rename from scripts/lanemap.ini rename to platform/broadcom/BCM56850/saivs/configs/lanemap.ini diff --git a/scripts/sai.profile b/platform/broadcom/BCM56850/saivs/configs/sai.profile similarity index 100% rename from scripts/sai.profile rename to platform/broadcom/BCM56850/saivs/configs/sai.profile diff --git a/platform/broadcom/BCM56850/saivs/configs/server/supervisord.conf b/platform/broadcom/BCM56850/saivs/configs/server/supervisord.conf new file mode 100644 index 00000000..aba59bf9 --- /dev/null +++ b/platform/broadcom/BCM56850/saivs/configs/server/supervisord.conf @@ -0,0 +1,61 @@ +[supervisord] +logfile_maxbytes=1MB +logfile_backups=2 +nodaemon=true + +[eventlistener:dependent-startup] +command=python3 -m supervisord_dependent_startup +autostart=true +autorestart=unexpected +startretries=0 +exitcodes=0,3 +events=PROCESS_STATE +buffer_size=1024 + +[program:rsyslogd] +command=/usr/sbin/rsyslogd -n -iNONE +priority=1 +autostart=false +autorestart=false +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true + +[program:veth-creator] +command=/usr/bin/veth-create.sh +priority=2 +startsecs=0 +autostart=false +autorestart=false +dependent_startup=true + +[program:redis] +command=/usr/bin/redis_start.sh --bind 0.0.0.0 --port 6379 +priority=3 +autostart=false +autorestart=true +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running + +[program:redis-cmd-listener] +command=/bin/bash -c "python3 /sai-challenger/scripts/redis-cmd-listener.py" +priority=4 +autostart=false +autorestart=true +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running redis:running + +[program:syncd] +command=/usr/local/bin/syncd -s -p /etc/sai.d/sai.profile +priority=5 +autostart=false +autorestart=true +stdout_logfile=syslog +stderr_logfile=syslog +dependent_startup=true +dependent_startup_wait_for=rsyslogd:running redis:running veth-creator:exited + diff --git a/scripts/supervisord.conf b/platform/broadcom/BCM56850/saivs/configs/supervisord.conf similarity index 100% rename from scripts/supervisord.conf rename to platform/broadcom/BCM56850/saivs/configs/supervisord.conf diff --git a/sku/32x100g.json b/platform/broadcom/BCM56850/saivs/sku/32x100g.json similarity index 100% rename from sku/32x100g.json rename to platform/broadcom/BCM56850/saivs/sku/32x100g.json diff --git a/npu/sai_npu_vs.py b/platform/broadcom/sai_npu.py similarity index 100% rename from npu/sai_npu_vs.py rename to platform/broadcom/sai_npu.py diff --git a/platform/broadcom/trident2 b/platform/broadcom/trident2 new file mode 120000 index 00000000..5423cb38 --- /dev/null +++ b/platform/broadcom/trident2 @@ -0,0 +1 @@ +BCM56850/ \ No newline at end of file diff --git a/platform/intel/README.md b/platform/intel/README.md index b131ed4c..2e2d40e9 100644 --- a/platform/intel/README.md +++ b/platform/intel/README.md @@ -1,32 +1,19 @@ -## To start SAI Challenger on top of SAI implementation for Tofino Model -Update submodules -```sh -git submodule update --init --recursive -``` -Copy Debian packages with Intel SDK and Tofino Model into the root folder -of SAI Challenger sources: -```sh -bfnsdk_1.0.0_amd64.deb -bfnplatform_1.0.0_amd64.deb -``` +## Running SAI Challenger in standalone mode -Build SAI Challenger Docker image with SAI implementation for Tofino Model: +Copy Debian packages `bfnsdk_1.0.0_amd64.deb` and `bfnplatform_1.0.0_amd64.deb` with Intel SDK and Tofino Model into `platform/intel/tofino/model/` folder. + +Build Docker image for ASIC `tofino` target `model`: ```sh -docker build -f Dockerfile.saivs.intel -t saivs-challenger-intel . +./build.sh -a tofino -t model ``` -Start SAI Challenger: +Start Docker container: ```sh -docker run --name sai-challenger-run \ - -v $(pwd):/sai-challenger \ - --device /dev/net/tun:/dev/net/tun \ - --privileged \ - -d saivs-challenger-intel +./run.sh -a tofino -t model ``` -## To run SAI Challenger testcases on top of Tofino Model - Run SAI Challenger testcases: ```sh -docker exec -ti sai-challenger-run pytest --npu=tofino --sku=tofino_32x25g --traffic -v +./exec.sh -a tofino -t model pytest --sku=tofino_32x25g --traffic -v -k "test_l2_basic" ``` + diff --git a/npu/sai_npu_tofino.py b/platform/intel/sai_npu.py similarity index 100% rename from npu/sai_npu_tofino.py rename to platform/intel/sai_npu.py diff --git a/platform/intel/tofino/model/Dockerfile b/platform/intel/tofino/model/Dockerfile new file mode 100644 index 00000000..dd0f0476 --- /dev/null +++ b/platform/intel/tofino/model/Dockerfile @@ -0,0 +1,55 @@ +FROM sc-base + +MAINTAINER andriy.kokhan@gmail.com + +ENV SC_PLATFORM=intel +ENV SC_ASIC=tofino +ENV SC_TARGET=model + +WORKDIR /sai + +RUN apt-get install -y libgoogle-perftools4 + +COPY *.deb /sai/ +RUN dpkg -i *.deb + +RUN git clone https://github.com/Azure/sonic-sairedis.git \ + && cd sonic-sairedis \ + && . /sai.env \ + && git checkout ${SAIREDIS_ID} \ + && git submodule update --init --recursive \ + && cd SAI && git fetch origin \ + && git checkout ${SAI_ID} \ + && git submodule update --init --recursive \ + && cd .. \ + && ./autogen.sh && ./configure && make -j4 \ + && make install && ldconfig \ + && mkdir -p /usr/include/sai \ + && mv SAI/experimental /usr/include/sai/experimental \ + && mv SAI/inc /usr/include/sai/inc \ + && mkdir -p /usr/include/sai/meta \ + && cp SAI/meta/*.h /usr/include/sai/meta/ \ + && mv tests .. && rm -rf * && mv ../tests . + + +# Build attr_list_generator and generate /etc/sai/sai.json +RUN cd /sai/gen_attr_list \ + && mkdir build && cd build \ + && cmake .. \ + && make -j$(nproc) \ + && mkdir -p /etc/sai \ + && ./attr_list_generator > /etc/sai/sai.json + +# Setup supervisord +COPY scripts/redis_start.sh /usr/bin/redis_start.sh +COPY scripts/model_start.sh /usr/bin/model_start.sh +COPY scripts/syncd_start.sh /usr/bin/syncd_start.sh +COPY scripts/veth-create.sh /usr/bin/veth-create.sh +COPY configs/ports.json /usr/share/sonic/hwsku/ports.json +COPY configs/switch-sai-cpu-veth.conf /usr/share/sonic/hwsku/switch-tna-sai.conf +COPY configs/supervisord.conf /etc/supervisor/conf.d/supervisord.conf + +WORKDIR /sai-challenger/tests + +CMD ["/usr/bin/supervisord"] + diff --git a/platform/intel/ports.json b/platform/intel/tofino/model/configs/ports.json similarity index 100% rename from platform/intel/ports.json rename to platform/intel/tofino/model/configs/ports.json diff --git a/platform/intel/supervisord.conf b/platform/intel/tofino/model/configs/supervisord.conf similarity index 100% rename from platform/intel/supervisord.conf rename to platform/intel/tofino/model/configs/supervisord.conf diff --git a/platform/intel/switch-sai-cpu-veth.conf b/platform/intel/tofino/model/configs/switch-sai-cpu-veth.conf similarity index 100% rename from platform/intel/switch-sai-cpu-veth.conf rename to platform/intel/tofino/model/configs/switch-sai-cpu-veth.conf diff --git a/platform/intel/tofino/model/scenarios b/platform/intel/tofino/model/scenarios new file mode 120000 index 00000000..8c6fea1a --- /dev/null +++ b/platform/intel/tofino/model/scenarios @@ -0,0 +1 @@ +../montara/scenarios/ \ No newline at end of file diff --git a/platform/intel/model_start.sh b/platform/intel/tofino/model/scripts/model_start.sh similarity index 100% rename from platform/intel/model_start.sh rename to platform/intel/tofino/model/scripts/model_start.sh diff --git a/platform/intel/redis_start.sh b/platform/intel/tofino/model/scripts/redis_start.sh similarity index 100% rename from platform/intel/redis_start.sh rename to platform/intel/tofino/model/scripts/redis_start.sh diff --git a/platform/intel/syncd_start.sh b/platform/intel/tofino/model/scripts/syncd_start.sh similarity index 100% rename from platform/intel/syncd_start.sh rename to platform/intel/tofino/model/scripts/syncd_start.sh diff --git a/platform/intel/veth-create.sh b/platform/intel/tofino/model/scripts/veth-create.sh similarity index 100% rename from platform/intel/veth-create.sh rename to platform/intel/tofino/model/scripts/veth-create.sh diff --git a/sku/tofino_32x25g.json b/platform/intel/tofino/model/sku/32x25g.json similarity index 100% rename from sku/tofino_32x25g.json rename to platform/intel/tofino/model/sku/32x25g.json diff --git a/platform/intel/scenarios/t0_full.rec b/platform/intel/tofino/montara/scenarios/t0_full.rec similarity index 100% rename from platform/intel/scenarios/t0_full.rec rename to platform/intel/tofino/montara/scenarios/t0_full.rec diff --git a/platform/intel/scenarios/t1_full.rec b/platform/intel/tofino/montara/scenarios/t1_full.rec similarity index 100% rename from platform/intel/scenarios/t1_full.rec rename to platform/intel/tofino/montara/scenarios/t1_full.rec diff --git a/platform/intel/scenarios/t1_lag_full.rec b/platform/intel/tofino/montara/scenarios/t1_lag_full.rec similarity index 100% rename from platform/intel/scenarios/t1_lag_full.rec rename to platform/intel/tofino/montara/scenarios/t1_lag_full.rec diff --git a/sku/tofino_32x100g.json b/platform/intel/tofino/montara/sku/32x100g.json similarity index 100% rename from sku/tofino_32x100g.json rename to platform/intel/tofino/montara/sku/32x100g.json diff --git a/run.sh b/run.sh new file mode 100755 index 00000000..cd13a283 --- /dev/null +++ b/run.sh @@ -0,0 +1,133 @@ +#!/bin/bash + +# exit when any command fails +set -e + +# keep track of the last executed command +trap 'last_command=$current_command; current_command=$BASH_COMMAND' DEBUG +# echo an error message before exiting +trap 'echo ERROR: "\"${last_command}\" command filed with exit code $?."' ERR + +IMAGE_TYPE="standalone" +ASIC_TYPE="" +ASIC_PATH="" +TARGET="" +PRIVILEGED="" + +print-help() { + echo + echo "$(basename ""$0"") [OPTIONS]" + echo "Options:" + echo " -h Print script usage" + echo " -i [standalone|client|server]" + echo " Image type to be started" + echo " -a ASIC" + echo " ASIC to be tested" + echo " -t TARGET" + echo " Target device with this NPU" + echo " -p Run Docker in --privileged mode" + echo + exit 0 +} + +while [[ $# -gt 0 ]]; do + key="$1" + case $key in + "-h"|"--help") + print-help + exit 0 + ;; + "-i"|"--image") + IMAGE_TYPE="$2" + shift + ;; + "-a"|"--asic") + ASIC_TYPE="$2" + shift + ;; + "-t"|"--target") + TARGET="$2" + shift + ;; + "-p") + PRIVILEGED="--privileged" + ;; + esac + shift +done + +if [[ "${IMAGE_TYPE}" != "standalone" && \ + "${IMAGE_TYPE}" != "client" && \ + "${IMAGE_TYPE}" != "server" ]]; then + echo "Unknown image type \"${IMAGE_TYPE}\"" + exit 1 +fi + +if [[ "${IMAGE_TYPE}" != "client" ]]; then + + if [ -z "${ASIC_TYPE}" ]; then + ASIC_TYPE="trident2" + fi + + ASIC_PATH=$(find -L -type d -name "${ASIC_TYPE}") + if [ -z "${ASIC_PATH}" ]; then + echo "Unknown ASIC type \"${ASIC_TYPE}\"" + exit 1 + fi + + if [ ! -z "${TARGET}" ]; then + if [ ! -d "${ASIC_PATH}/${TARGET}" ]; then + echo "Unknown target \"${TARGET}\"" + exit 1 + fi + else + # Get first folder as a default target + TARGETS=( $(find -L "${ASIC_PATH}" -mindepth 1 -maxdepth 1 -type d) ) + TARGET="${TARGETS[0]}" + if [ -z "${TARGET}" ]; then + echo "Not able to find a default target..." + exit 1 + fi + TARGET=$(basename $TARGET) + fi +fi + +print-start-options() { + echo + echo "===========================================" + echo " SAI Challenger start options" + echo "===========================================" + echo + echo " Docker image type : ${IMAGE_TYPE}" + echo " ASIC name : ${ASIC_TYPE}" + echo " ASIC target : ${TARGET}" + echo " Platform path : ${ASIC_PATH}" + echo + echo "===========================================" + echo +} + +trap print-start-options EXIT + +# Start Docker container +if [ "${IMAGE_TYPE}" = "standalone" ]; then + docker run --name sc-${ASIC_TYPE}-${TARGET}-run \ + -v $(pwd):/sai-challenger \ + --cap-add=NET_ADMIN \ + ${PRIVILEGED} \ + --device /dev/net/tun:/dev/net/tun \ + -d sc-${ASIC_TYPE}-${TARGET} +elif [ "${IMAGE_TYPE}" = "server" ]; then + docker run --name sc-server-${ASIC_TYPE}-${TARGET}-run \ + --cap-add=NET_ADMIN \ + ${PRIVILEGED} \ + --device /dev/net/tun:/dev/net/tun \ + -d sc-server-${ASIC_TYPE}-${TARGET} +else + docker run --name sc-client-run \ + -v $(pwd):/sai-challenger \ + --cap-add=NET_ADMIN \ + --device /dev/net/tun:/dev/net/tun \ + -d sc-client +fi + diff --git a/scripts/veth-create.sh b/scripts/veth-create.sh index f3ae8038..ca42467b 100755 --- a/scripts/veth-create.sh +++ b/scripts/veth-create.sh @@ -5,4 +5,3 @@ for num in {1..32}; do ip link set eth"$num" up ip link set veth"$num" up done - diff --git a/tests/conftest.py b/tests/conftest.py index e2b4e1fe..cf7679b2 100644 --- a/tests/conftest.py +++ b/tests/conftest.py @@ -7,6 +7,7 @@ import signal import random import unittest +import glob curdir = os.path.dirname(os.path.realpath(__file__)) ptfdir = os.path.join(curdir, '../ptf/src') @@ -19,9 +20,6 @@ commondir = os.path.join(curdir, '../common') sys.path.append(commondir) -npudir = os.path.join(curdir, '../npu') -sys.path.append(npudir) - from sai_npu import SaiNpu from sai_dataplane import SaiDataPlane @@ -117,7 +115,8 @@ def pytest_addoption(parser): parser.addoption("--traffic", action="store_true", default=False, help="run tests with traffic") parser.addoption("--saivs", action="store_true", default=False, help="running tests on top of libsaivs") parser.addoption("--loglevel", action="store", default='NOTICE', help="syncd logging level") - parser.addoption("--npu", action="store", default='vs', help="NPU type") + parser.addoption("--asic", action="store", default=os.getenv('SC_ASIC'), help="ASIC type") + parser.addoption("--target", action="store", default=os.getenv('SC_TARGET'), help="The target device with this NPU") parser.addoption("--sku", action="store", default=None, help="SKU mode") @@ -128,7 +127,8 @@ def exec_params(request): config_param["traffic"] = request.config.getoption("--traffic") config_param["saivs"] = request.config.getoption("--saivs") config_param["loglevel"] = request.config.getoption("--loglevel") - config_param["npu"] = request.config.getoption("--npu") + config_param["asic"] = request.config.getoption("--asic") + config_param["target"] = request.config.getoption("--target") config_param["sku"] = request.config.getoption("--sku") return config_param @@ -155,23 +155,41 @@ def logging_setup(config): @pytest.fixture(scope="session") def npu(exec_params): npu = None + exec_params["asic_dir"] = None - if exec_params["npu"] == "generic": + if exec_params["asic"] == "generic": npu = SaiNpu(exec_params) else: + asic_dir = None npu_mod = None - npu_name = "sai_npu_" + exec_params["npu"] + module_name = "sai_npu" + try: - npu_mod = imp.load_module(npu_name, *imp.find_module(npu_name)) + asic_dir = glob.glob("../platform/**/" + exec_params["asic"] + "/", recursive=True) + asic_dir = asic_dir[0] + exec_params["asic_dir"] = asic_dir except: - logging.critical("Failed to import " + npu_name + " NPU module") + logging.critical("Failed to find " + exec_params["asic"] + " NPU folder") sys.exit(1) try: - npu = npu_mod.SaiNpuImpl(exec_params) + npu_mod = imp.load_module(module_name, *imp.find_module(module_name, [asic_dir])) except: - logging.critical("Failed to instantiate " + npu_name + " NPU") - sys.exit(1) + logging.info("No {} specific 'sai_npu' module defined..".format(exec_params["asic"])) + try: + npu_mod = imp.load_module(module_name, *imp.find_module(module_name, [asic_dir + "../"])) + except: + logging.warn("No platform specific 'sai_npu' module defined..") + + if npu_mod is not None: + try: + npu = npu_mod.SaiNpuImpl(exec_params) + except: + logging.critical("Failed to instantiate 'sai_npu' module for {}".format(exec_params["asic"])) + sys.exit(1) + else: + logging.info("Falling back to the default 'sai_npu' module..") + npu = SaiNpu(exec_params) if npu is not None: npu.reset() diff --git a/tests/test_l2_basic.py b/tests/test_l2_basic.py index 43567242..3abf9527 100644 --- a/tests/test_l2_basic.py +++ b/tests/test_l2_basic.py @@ -237,7 +237,7 @@ def test_l2_flood(npu, dataplane): npu.remove(vlan_oid) -def test_l2_lag(npu, dataplane, exec_params): +def test_l2_lag(npu, dataplane): """ Description: Check that the packets are equally divided among LAG members. @@ -254,7 +254,7 @@ def test_l2_lag(npu, dataplane, exec_params): 9. Send packets from each of the members and check they are received on port 4 (with port 4's destination MAC) 10. Clean up configuration """ - if 'tofino' in exec_params["npu"]: + if npu.name == 'tofino': pytest.skip("Temporarily disabled for Tofino NPU") vlan_id = "10" diff --git a/tests/test_sairec.py b/tests/test_sairec.py index f48425aa..6fccdc33 100644 --- a/tests/test_sairec.py +++ b/tests/test_sairec.py @@ -2,16 +2,16 @@ import time @pytest.fixture(scope="module") -def vs_teardown(npu, exec_params): +def bcm56850_teardown(npu): yield - if exec_params["npu"] == "vs": + if npu.name == "BCM56850": npu.reset() @pytest.fixture(scope="module") -def tofino_teardown(npu, exec_params): +def tofino_teardown(npu): yield - if "tofino" in exec_params["npu"]: + if npu.name == "tofino": npu.reset() @@ -29,8 +29,8 @@ def tofino_teardown(npu, exec_params): "BCM56850/remove_create_port.rec" ], ) -def test_apply_sairec(npu, exec_params, dataplane, fname, vs_teardown): - if exec_params["npu"] != "vs": +def test_apply_sairec(npu, exec_params, dataplane, fname, bcm56850_teardown): + if npu.name != "BCM56850": pytest.skip("VS specific scenario") if exec_params["server"] != 'localhost': @@ -47,8 +47,8 @@ def test_apply_sairec(npu, exec_params, dataplane, fname, vs_teardown): "t1_lag_full.rec", ], ) -def test_tofino_scenario(npu, exec_params, dataplane, fname, tofino_teardown): - if 'tofino' not in exec_params["npu"]: +def test_tofino_scenario(npu, dataplane, fname, tofino_teardown): + if npu.name != 'tofino': pytest.skip("Tofino specific scenario") - npu.apply_rec("/sai-challenger/platform/intel/scenarios/" + fname) + npu.apply_rec(f"/sai-challenger/platform/intel/{npu.name}/{npu.target}/scenarios/{fname}")