Skip to content

Commit a6ebb69

Browse files
EmanueleGallonepudelkoM
authored andcommitted
[SDFAB-582][SDFAB-584] Porting PTF run scripts from fabric-p4tests to 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
1 parent 9915737 commit a6ebb69

15 files changed

+365
-17
lines changed

.env

+2
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@ SDE_TM_DOCKER_IMG=${SDE_DOCKER_IMG:-registry.opennetworking.org/bf-sde/bf-sde:${
1717
SDE_P4C_DOCKER_IMG=${SDE_DOCKER_IMG:-registry.opennetworking.org/bf-sde/bf-sde:${SDE_VERSION}-p4c}
1818
# Used with tofino-model for PTF tests
1919
STRATUM_DOCKER_IMG=${STRATUM_DOCKER_IMG:-stratumproject/stratum-bfrt:${SDE_VERSION}}
20+
# Stratum bmv2. Use image sha to pin a specific stratum_bmv2 build and have reproducible runs.
21+
STRATUM_BMV2_IMG="opennetworking/mn-stratum@sha256:01ab29ccb9bc0635643ba9f130b26dee41abdd694f1f75245779cb69e61635b1"
2022
# Contains PTF and tvutils libraries, as well as P4RT, gNMI, and TV Python bindings
2123
TESTER_DOCKER_IMG=stratumproject/testvectors:ptf
2224
# Used to generate the P4Runtime p4_device_config blob from the bf-p4c compiler output

.gitignore

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright 2020-present Open Networking Foundation
1+
# Copyright 2021-present Open Networking Foundation
22
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
33
p4src/tna/build
44
target

.reuse/dep5

+8
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,11 @@ License: LicenseRef-ONF-Member-Only-1.0
2222
Files: ptf/run/hw/port_map.trex.json
2323
Copyright: 2020-present Open Networking Foundation
2424
License: LicenseRef-ONF-Member-Only-1.0
25+
26+
Files: ptf/run/bmv2/chassis_config.txt
27+
Copyright: 2021-present Open Networking Foundation
28+
License: LicenseRef-ONF-Member-Only-1.0
29+
30+
Files: ptf/run/bmv2/port_map.veth.json
31+
Copyright: 2021-present Open Networking Foundation
32+
License: LicenseRef-ONF-Member-Only-1.0

ptf/run/bmv2/.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Copyright 2021-present Open Networking Foundation
2+
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
3+
log/

ptf/run/bmv2/Makefile

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# Copyright 2021-present Open Networking Foundation
2+
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
3+
4+
define run_tests
5+
python3 -u ptf_runner.py \
6+
--platform bmv2 \
7+
--port-map /fabric-tna/ptf/run/bmv2/port_map.veth.json \
8+
--ptf-dir ../../tests/unary --cpu-port 255 --device-id 1 \
9+
--grpc-addr 127.0.0.1:28000 \
10+
--p4info /fabric-tna/"${P4C_OUT}"/p4info.txt \
11+
--pipeline-config /fabric-tna/"${P4C_OUT}"/bmv2.json \
12+
--profile $(1) \
13+
$(2)
14+
endef
15+
16+
.DEFAULT_GOAL := all
17+
18+
#Nothing to check
19+
_checkenv:
20+
21+
include ../../tests/common/Makefile.profiles
22+

ptf/run/bmv2/base.sh

+51
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
#!/bin/bash
2+
# Copyright 2021-present Open Networking Foundation
3+
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
4+
5+
set -eu -o pipefail
6+
7+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
8+
FABRIC_TNA_ROOT="${DIR}"/../../..
9+
10+
randomNum=${RANDOM}
11+
12+
# shellcheck source=.env
13+
source "${FABRIC_TNA_ROOT}"/.env
14+
15+
PTF_FILTER=${PTF_FILTER:-}
16+
STRATUM_DOCKER_FLAG=${STRATUM_DOCKER_FLAG:-}
17+
18+
fabricProfile=$1
19+
if [ -z "${fabricProfile}" ]; then
20+
echo "fabric profile is not set"
21+
exit 1
22+
fi
23+
24+
echo "*** Testing profile '${fabricProfile}'..."
25+
26+
echo "Running for BMV2"
27+
P4C_OUT=p4src/v1model/build/${fabricProfile}/bmv2
28+
echo "*** Using P4 compiler output in ${P4C_OUT}..."
29+
30+
# Clean up old logs (if any)
31+
rm -rf "${DIR}"/log
32+
mkdir "${DIR}"/log
33+
34+
# stratum_bmv2
35+
stratumBmv2ImageName=${STRATUM_BMV2_IMG}
36+
stratumBmv2RunName=stratum-bmv2-${randomNum}
37+
38+
function stop_stratum_bmv2() {
39+
set +e
40+
echo "*** Stopping ${stratumBmv2ImageName}..."
41+
docker stop -t0 "${stratumBmv2RunName}" > /dev/null
42+
}
43+
trap stop_stratum_bmv2 EXIT
44+
45+
46+
echo "*** Starting ${stratumBmv2RunName}..."
47+
docker run --name ${stratumBmv2RunName} -d -it --rm --privileged \
48+
-v "${FABRIC_TNA_ROOT}":/fabric-tna \
49+
--entrypoint "/fabric-tna/ptf/run/bmv2/stratum_entrypoint.sh" \
50+
"${stratumBmv2ImageName}"
51+
sleep 2

ptf/run/bmv2/chassis_config.txt

+107
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,107 @@
1+
description: "stratum_bmv2 dut"
2+
chassis {
3+
platform: PLT_P4_SOFT_SWITCH
4+
name: "bmv2_dut"
5+
}
6+
nodes {
7+
id: 1
8+
name: "bmv2_dut"
9+
slot: 1
10+
index: 1
11+
}
12+
singleton_ports {
13+
id: 0
14+
name: "veth1"
15+
slot: 1
16+
port: 0
17+
channel: 1
18+
speed_bps: 10000000000
19+
config_params {
20+
admin_state: ADMIN_STATE_ENABLED
21+
}
22+
node: 1
23+
}
24+
singleton_ports {
25+
id: 1
26+
name: "veth3"
27+
slot: 1
28+
port: 1
29+
channel: 1
30+
speed_bps: 10000000000
31+
config_params {
32+
admin_state: ADMIN_STATE_ENABLED
33+
}
34+
node: 1
35+
}
36+
singleton_ports {
37+
id: 2
38+
name: "veth5"
39+
slot: 1
40+
port: 2
41+
channel: 1
42+
speed_bps: 10000000000
43+
config_params {
44+
admin_state: ADMIN_STATE_ENABLED
45+
}
46+
node: 1
47+
}
48+
singleton_ports {
49+
id: 3
50+
name: "veth7"
51+
slot: 1
52+
port: 3
53+
channel: 1
54+
speed_bps: 10000000000
55+
config_params {
56+
admin_state: ADMIN_STATE_ENABLED
57+
}
58+
node: 1
59+
}
60+
singleton_ports {
61+
id: 4
62+
name: "veth9"
63+
slot: 1
64+
port: 4
65+
channel: 1
66+
speed_bps: 10000000000
67+
config_params {
68+
admin_state: ADMIN_STATE_ENABLED
69+
}
70+
node: 1
71+
}
72+
singleton_ports {
73+
id: 5
74+
name: "veth11"
75+
slot: 1
76+
port: 5
77+
channel: 1
78+
speed_bps: 10000000000
79+
config_params {
80+
admin_state: ADMIN_STATE_ENABLED
81+
}
82+
node: 1
83+
}
84+
singleton_ports {
85+
id: 6
86+
name: "veth13"
87+
slot: 1
88+
port: 6
89+
channel: 1
90+
speed_bps: 10000000000
91+
config_params {
92+
admin_state: ADMIN_STATE_ENABLED
93+
}
94+
node: 1
95+
}
96+
singleton_ports {
97+
id: 7
98+
name: "veth15"
99+
slot: 1
100+
port: 7
101+
channel: 1
102+
speed_bps: 10000000000
103+
config_params {
104+
admin_state: ADMIN_STATE_ENABLED
105+
}
106+
node: 1
107+
}

ptf/run/bmv2/port_map.veth.json

+42
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
[
2+
{
3+
"ptf_port": 0,
4+
"p4_port": 0,
5+
"iface_name": "veth1"
6+
},
7+
{
8+
"ptf_port": 1,
9+
"p4_port": 1,
10+
"iface_name": "veth3"
11+
},
12+
{
13+
"ptf_port": 2,
14+
"p4_port": 2,
15+
"iface_name": "veth5"
16+
},
17+
{
18+
"ptf_port": 3,
19+
"p4_port": 3,
20+
"iface_name": "veth7"
21+
},
22+
{
23+
"ptf_port": 4,
24+
"p4_port": 4,
25+
"iface_name": "veth9"
26+
},
27+
{
28+
"ptf_port": 5,
29+
"p4_port": 5,
30+
"iface_name": "veth11"
31+
},
32+
{
33+
"ptf_port": 6,
34+
"p4_port": 6,
35+
"iface_name": "veth13"
36+
},
37+
{
38+
"ptf_port": 7,
39+
"p4_port": 7,
40+
"iface_name": "veth15"
41+
}
42+
]

ptf/run/bmv2/run

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021-present Open Networking Foundation
3+
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
4+
5+
set -e
6+
7+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
8+
9+
# shellcheck source=ptf/run/bmv2/base.sh
10+
source "${DIR}/base.sh"
11+
testerRunName=tester-${randomNum}
12+
echo "*** Starting ${testerRunName}..."
13+
14+
# Do not attach stdin if running in an environment without it (e.g., Jenkins)
15+
it=$(test -t 0 && echo "-it" || echo "-t")
16+
# shellcheck disable=SC2068 disable=2086
17+
docker run --name "${testerRunName}" "${it}" --rm --privileged \
18+
--network "container:${stratumBmv2RunName}" \
19+
-e P4C_OUT="${P4C_OUT}" \
20+
-e PTF_FILTER="${PTF_FILTER}" \
21+
-v "${FABRIC_TNA_ROOT}":/fabric-tna \
22+
--entrypoint /fabric-tna/ptf/run/bmv2/start_test.sh \
23+
${TESTER_DOCKER_IMG} \
24+
${@}

ptf/run/bmv2/start_test.sh

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021-present Open Networking Foundation
3+
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
4+
5+
set -e
6+
7+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
8+
PTF_ROOT=${DIR}/../..
9+
TEST_DIR=${PTF_ROOT}/tests/common
10+
11+
err_report() {
12+
13+
echo "************************************************"
14+
echo "SOME PTF TESTS FAILED :("
15+
echo "************************************************"
16+
exit 1
17+
}
18+
19+
trap 'err_report' ERR
20+
cd "${TEST_DIR}"
21+
22+
echo "************************************************"
23+
echo "STARTING PTF TESTS..."
24+
echo "************************************************"
25+
26+
# shellcheck disable=SC2068
27+
make -f "${DIR}"/Makefile ${@}
28+
29+
echo "************************************************"
30+
echo "ALL PTF TESTS PASSED :)"
31+
echo "************************************************"

ptf/run/bmv2/stratum_entrypoint.sh

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
#!/usr/bin/env bash
2+
# Copyright 2021-present Open Networking Foundation
3+
# SPDX-License-Identifier: LicenseRef-ONF-Member-Only-1.0
4+
5+
set -ex
6+
7+
DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" > /dev/null 2>&1 && pwd)"
8+
9+
# From:
10+
# https://github.com/p4lang/behavioral-model/blob/master/tools/veth_setup.sh
11+
12+
for idx in 0 1 2 3 4 5 6 7 8; do
13+
intf0="veth$((idx * 2))"
14+
intf1="veth$((idx * 2 + 1))"
15+
if ! ip link show $intf0 &> /dev/null; then
16+
ip link add name $intf0 type veth peer name $intf1
17+
ip link set dev $intf0 up
18+
ip link set dev $intf1 up
19+
20+
# Set the MTU of these interfaces to be larger than default of
21+
# 1500 bytes, so that P4 behavioral-model testing can be done
22+
# on jumbo frames.
23+
# Note: ifconfig is deprecated, and no longer installed by
24+
# default in Ubuntu Linux minimal installs starting with
25+
# Ubuntu 18.04. The ip command is installed in Ubuntu
26+
# versions since at least 16.04, and probably older versions,
27+
# too.
28+
ip link set $intf0 mtu 9500
29+
ip link set $intf1 mtu 9500
30+
31+
# Disable IPv6 on the interfaces, so that the Linux kernel
32+
# will not automatically send IPv6 MDNS, Router Solicitation,
33+
# and Multicast Listener Report packets on the interface,
34+
# which can make P4 program debugging more confusing.
35+
#
36+
# Testing indicates that we can still send IPv6 packets across
37+
# such interfaces, both from scapy to simple_switch, and from
38+
# simple_switch out to scapy sniffing.
39+
#
40+
# https://superuser.com/questions/356286/how-can-i-switch-off-ipv6-nd-ra-transmissions-in-linux
41+
sysctl net.ipv6.conf.${intf0}.disable_ipv6=1
42+
sysctl net.ipv6.conf.${intf1}.disable_ipv6=1
43+
fi
44+
done
45+
46+
stratum_bmv2 \
47+
-bmv2_log_level=trace \
48+
-chassis_config_file="${DIR}"/chassis_config.txt \
49+
-cpu_port=255 \
50+
-device_id=1 \
51+
-external-stratum-urls=0.0.0.0:28000 \
52+
-forwarding_pipeline_configs_file=/dev/null \
53+
-initial_pipeline=/root/dummy.json \
54+
-local_stratum_url=localhost:28000 \
55+
-log_dir="${DIR}"/log/ \
56+
-logtostderr=true \
57+
-persistent_config_dir=/tmp/ \
58+
-write_req_log_file="${DIR}"/log/p4rt-write-reqs.log \
59+
&> "${DIR}"/log/stratum_bmv2.log

ptf/run/hw/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ define run_tests
99
--cpu-port 320 --device-id 1 \
1010
--grpc-addr $(SWITCH_ADDR) \
1111
--p4info /fabric-tna/${P4C_OUT}/p4info.txt \
12-
--tofino-pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
12+
--pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
1313
$(TREX_PARAMS) \
1414
--profile $(1) \
1515
--xunit \

ptf/run/tm/Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ define run_tests
88
--ptf-dir ../../tests/unary --cpu-port 320 --device-id 1 \
99
--grpc-addr "127.0.0.1:28000" \
1010
--p4info /fabric-tna/${P4C_OUT}/p4info.txt \
11-
--tofino-pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
11+
--pipeline-config /fabric-tna/${P4C_OUT}/pipeline_config.pb.bin \
1212
--profile $(1) \
1313
$(2)
1414
endef

0 commit comments

Comments
 (0)