Skip to content

Commit

Permalink
[SDFAB-582][SDFAB-584] Porting PTF run scripts from fabric-p4tests to…
Browse files Browse the repository at this point in the history
… fabric-tna (#384)

* Make ptf/run/bmv2/ scripts consistent with ptf/run/tna/

* Add port map for BmV2

* Remove Tofino-model scripts

* Rename --tofino-pipeline-config parameter in --pipeline-config

* Fix license header for ptf/run/bmv2/port_map.veth.json

* Fix tofino-pipeline-config parameter to pipeline-config

* Fix Linter

* Add mn-stratum container's digest

* Remove comments on old docker tester image

* Remove Todo

* Edit help message in --pipeline-config parser argument

* Refactor update_config() making it more generic.

* Refactor build pipeline method

* Refactor and address changes

* Fix license header

* Refactor container name

* Rename Bmv2 docker image

* Address review changes

* Fix license header

* Fix license header
  • Loading branch information
EmanueleGallone authored and pudelkoM committed Feb 2, 2022
1 parent 9915737 commit a6ebb69
Show file tree
Hide file tree
Showing 15 changed files with 365 additions and 17 deletions.
2 changes: 2 additions & 0 deletions .env
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@ SDE_TM_DOCKER_IMG=${SDE_DOCKER_IMG:-registry.opennetworking.org/bf-sde/bf-sde:${
SDE_P4C_DOCKER_IMG=${SDE_DOCKER_IMG:-registry.opennetworking.org/bf-sde/bf-sde:${SDE_VERSION}-p4c}
# Used with tofino-model for PTF tests
STRATUM_DOCKER_IMG=${STRATUM_DOCKER_IMG:-stratumproject/stratum-bfrt:${SDE_VERSION}}
# Stratum bmv2. Use image sha to pin a specific stratum_bmv2 build and have reproducible runs.
STRATUM_BMV2_IMG="opennetworking/mn-stratum@sha256:01ab29ccb9bc0635643ba9f130b26dee41abdd694f1f75245779cb69e61635b1"
# Contains PTF and tvutils libraries, as well as P4RT, gNMI, and TV Python bindings
TESTER_DOCKER_IMG=stratumproject/testvectors:ptf
# Used to generate the P4Runtime p4_device_config blob from the bf-p4c compiler output
Expand Down
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Copyright 2020-present Open Networking Foundation
# Copyright 2021-present Open Networking Foundation
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
p4src/tna/build
target
Expand Down
8 changes: 8 additions & 0 deletions .reuse/dep5
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,11 @@ License: LicenseRef-ONF-Member-Only-1.0
Files: ptf/run/hw/port_map.trex.json
Copyright: 2020-present Open Networking Foundation
License: LicenseRef-ONF-Member-Only-1.0

Files: ptf/run/bmv2/chassis_config.txt
Copyright: 2021-present Open Networking Foundation
License: LicenseRef-ONF-Member-Only-1.0

Files: ptf/run/bmv2/port_map.veth.json
Copyright: 2021-present Open Networking Foundation
License: LicenseRef-ONF-Member-Only-1.0
3 changes: 3 additions & 0 deletions ptf/run/bmv2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# Copyright 2021-present Open Networking Foundation
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
log/
22 changes: 22 additions & 0 deletions ptf/run/bmv2/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Copyright 2021-present Open Networking Foundation
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0

define run_tests
python3 -u ptf_runner.py \
--platform bmv2 \
--port-map /fabric-tna/ptf/run/bmv2/port_map.veth.json \
--ptf-dir ../../tests/unary --cpu-port 255 --device-id 1 \
--grpc-addr 127.0.0.1:28000 \
--p4info /fabric-tna/"${P4C_OUT}"/p4info.txt \
--pipeline-config /fabric-tna/"${P4C_OUT}"/bmv2.json \
--profile $(1) \
$(2)
endef

.DEFAULT_GOAL := all

#Nothing to check
_checkenv:

include ../../tests/common/Makefile.profiles

51 changes: 51 additions & 0 deletions ptf/run/bmv2/base.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#!/bin/bash
# Copyright 2021-present Open Networking Foundation
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0

set -eu -o pipefail

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
FABRIC_TNA_ROOT="${DIR}"/../../..

randomNum=${RANDOM}

# shellcheck source=.env
source "${FABRIC_TNA_ROOT}"/.env

PTF_FILTER=${PTF_FILTER:-}
STRATUM_DOCKER_FLAG=${STRATUM_DOCKER_FLAG:-}

fabricProfile=$1
if [ -z "${fabricProfile}" ]; then
echo "fabric profile is not set"
exit 1
fi

echo "*** Testing profile '${fabricProfile}'..."

echo "Running for BMV2"
P4C_OUT=p4src/v1model/build/${fabricProfile}/bmv2
echo "*** Using P4 compiler output in ${P4C_OUT}..."

# Clean up old logs (if any)
rm -rf "${DIR}"/log
mkdir "${DIR}"/log

# stratum_bmv2
stratumBmv2ImageName=${STRATUM_BMV2_IMG}
stratumBmv2RunName=stratum-bmv2-${randomNum}

function stop_stratum_bmv2() {
set +e
echo "*** Stopping ${stratumBmv2ImageName}..."
docker stop -t0 "${stratumBmv2RunName}" > /dev/null
}
trap stop_stratum_bmv2 EXIT


echo "*** Starting ${stratumBmv2RunName}..."
docker run --name ${stratumBmv2RunName} -d -it --rm --privileged \
-v "${FABRIC_TNA_ROOT}":/fabric-tna \
--entrypoint "/fabric-tna/ptf/run/bmv2/stratum_entrypoint.sh" \
"${stratumBmv2ImageName}"
sleep 2
107 changes: 107 additions & 0 deletions ptf/run/bmv2/chassis_config.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,107 @@
description: "stratum_bmv2 dut"
chassis {
platform: PLT_P4_SOFT_SWITCH
name: "bmv2_dut"
}
nodes {
id: 1
name: "bmv2_dut"
slot: 1
index: 1
}
singleton_ports {
id: 0
name: "veth1"
slot: 1
port: 0
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
singleton_ports {
id: 1
name: "veth3"
slot: 1
port: 1
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
singleton_ports {
id: 2
name: "veth5"
slot: 1
port: 2
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
singleton_ports {
id: 3
name: "veth7"
slot: 1
port: 3
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
singleton_ports {
id: 4
name: "veth9"
slot: 1
port: 4
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
singleton_ports {
id: 5
name: "veth11"
slot: 1
port: 5
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
singleton_ports {
id: 6
name: "veth13"
slot: 1
port: 6
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
singleton_ports {
id: 7
name: "veth15"
slot: 1
port: 7
channel: 1
speed_bps: 10000000000
config_params {
admin_state: ADMIN_STATE_ENABLED
}
node: 1
}
42 changes: 42 additions & 0 deletions ptf/run/bmv2/port_map.veth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
[
{
"ptf_port": 0,
"p4_port": 0,
"iface_name": "veth1"
},
{
"ptf_port": 1,
"p4_port": 1,
"iface_name": "veth3"
},
{
"ptf_port": 2,
"p4_port": 2,
"iface_name": "veth5"
},
{
"ptf_port": 3,
"p4_port": 3,
"iface_name": "veth7"
},
{
"ptf_port": 4,
"p4_port": 4,
"iface_name": "veth9"
},
{
"ptf_port": 5,
"p4_port": 5,
"iface_name": "veth11"
},
{
"ptf_port": 6,
"p4_port": 6,
"iface_name": "veth13"
},
{
"ptf_port": 7,
"p4_port": 7,
"iface_name": "veth15"
}
]
24 changes: 24 additions & 0 deletions ptf/run/bmv2/run
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#!/usr/bin/env bash
# Copyright 2021-present Open Networking Foundation
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0

set -e

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"

# shellcheck source=ptf/run/bmv2/base.sh
source "${DIR}/base.sh"
testerRunName=tester-${randomNum}
echo "*** Starting ${testerRunName}..."

# Do not attach stdin if running in an environment without it (e.g., Jenkins)
it=$(test -t 0 && echo "-it" || echo "-t")
# shellcheck disable=SC2068 disable=2086
docker run --name "${testerRunName}" "${it}" --rm --privileged \
--network "container:${stratumBmv2RunName}" \
-e P4C_OUT="${P4C_OUT}" \
-e PTF_FILTER="${PTF_FILTER}" \
-v "${FABRIC_TNA_ROOT}":/fabric-tna \
--entrypoint /fabric-tna/ptf/run/bmv2/start_test.sh \
${TESTER_DOCKER_IMG} \
${@}
31 changes: 31 additions & 0 deletions ptf/run/bmv2/start_test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
#!/usr/bin/env bash
# Copyright 2021-present Open Networking Foundation
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0

set -e

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
PTF_ROOT=${DIR}/../..
TEST_DIR=${PTF_ROOT}/tests/common

err_report() {

echo "************************************************"
echo "SOME PTF TESTS FAILED :("
echo "************************************************"
exit 1
}

trap 'err_report' ERR
cd "${TEST_DIR}"

echo "************************************************"
echo "STARTING PTF TESTS..."
echo "************************************************"

# shellcheck disable=SC2068
make -f "${DIR}"/Makefile ${@}

echo "************************************************"
echo "ALL PTF TESTS PASSED :)"
echo "************************************************"
59 changes: 59 additions & 0 deletions ptf/run/bmv2/stratum_entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
#!/usr/bin/env bash
# Copyright 2021-present Open Networking Foundation
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0

set -ex

DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"

# From:
# https://github.com/p4lang/behavioral-model/blob/master/tools/veth_setup.sh

for idx in 0 1 2 3 4 5 6 7 8; do
intf0="veth$((idx * 2))"
intf1="veth$((idx * 2 + 1))"
if ! ip link show $intf0 &> /dev/null; then
ip link add name $intf0 type veth peer name $intf1
ip link set dev $intf0 up
ip link set dev $intf1 up

# Set the MTU of these interfaces to be larger than default of
# 1500 bytes, so that P4 behavioral-model testing can be done
# on jumbo frames.
# Note: ifconfig is deprecated, and no longer installed by
# default in Ubuntu Linux minimal installs starting with
# Ubuntu 18.04. The ip command is installed in Ubuntu
# versions since at least 16.04, and probably older versions,
# too.
ip link set $intf0 mtu 9500
ip link set $intf1 mtu 9500

# Disable IPv6 on the interfaces, so that the Linux kernel
# will not automatically send IPv6 MDNS, Router Solicitation,
# and Multicast Listener Report packets on the interface,
# which can make P4 program debugging more confusing.
#
# Testing indicates that we can still send IPv6 packets across
# such interfaces, both from scapy to simple_switch, and from
# simple_switch out to scapy sniffing.
#
# https://superuser.com/questions/356286/how-can-i-switch-off-ipv6-nd-ra-transmissions-in-linux
sysctl net.ipv6.conf.${intf0}.disable_ipv6=1
sysctl net.ipv6.conf.${intf1}.disable_ipv6=1
fi
done

stratum_bmv2 \
-bmv2_log_level=trace \
-chassis_config_file="${DIR}"/chassis_config.txt \
-cpu_port=255 \
-device_id=1 \
-external-stratum-urls=0.0.0.0:28000 \
-forwarding_pipeline_configs_file=/dev/null \
-initial_pipeline=/root/dummy.json \
-local_stratum_url=localhost:28000 \
-log_dir="${DIR}"/log/ \
-logtostderr=true \
-persistent_config_dir=/tmp/ \
-write_req_log_file="${DIR}"/log/p4rt-write-reqs.log \
&> "${DIR}"/log/stratum_bmv2.log
2 changes: 1 addition & 1 deletion ptf/run/hw/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ define run_tests
--cpu-port 320 --device-id 1 \
--grpc-addr $(SWITCH_ADDR) \
--p4info /fabric-tna/${P4C_OUT}/p4info.txt \
--tofino-pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
--pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
$(TREX_PARAMS) \
--profile $(1) \
--xunit \
Expand Down
2 changes: 1 addition & 1 deletion ptf/run/tm/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ define run_tests
--ptf-dir ../../tests/unary --cpu-port 320 --device-id 1 \
--grpc-addr "127.0.0.1:28000" \
--p4info /fabric-tna/${P4C_OUT}/p4info.txt \
--tofino-pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
--pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
--profile $(1) \
$(2)
endef
Expand Down
Loading

0 comments on commit a6ebb69

Please sign in to comment.