diff --git a/.github/workflows/test-exercises.yml b/.github/workflows/test-exercises.yml index 0a38a440..4a126ef0 100644 --- a/.github/workflows/test-exercises.yml +++ b/.github/workflows/test-exercises.yml @@ -31,7 +31,6 @@ jobs: - name: Run PTF Tests run: | cd exercises/basic - mkdir -p logs make test # Retain logs in case runs fail - name: Upload Logs diff --git a/bin/veth_setup.sh b/bin/veth_setup.sh new file mode 100755 index 00000000..3ee481a3 --- /dev/null +++ b/bin/veth_setup.sh @@ -0,0 +1,44 @@ +#!/bin/bash +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2017 Andy Fingerhut + +# This script was originally copied from the location below, then +# modified: +# +# 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. + ip link set $intf0 mtu 9500 + ip link set $intf1 mtu 9500 + ############################################################ + # ifconfig is deprecated, and no longer installed by default + # in Ubuntu Linux minimal installs starting with Ubuntu 18.04 + # LTS. + #ifconfig $intf0 mtu 9500 up + #ifconfig $intf1 mtu 9500 up + ############################################################ + + # 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 -q net.ipv6.conf.${intf0}.disable_ipv6=1 + sysctl -q net.ipv6.conf.${intf1}.disable_ipv6=1 + fi +done diff --git a/bin/veth_teardown.sh b/bin/veth_teardown.sh new file mode 100755 index 00000000..51986304 --- /dev/null +++ b/bin/veth_teardown.sh @@ -0,0 +1,16 @@ +#!/bin/bash +# SPDX-License-Identifier: Apache-2.0 +# Copyright 2019 Andy Fingerhut +# + +# This script was copied from the location below, for convenience of +# p4-guide users: +# +# https://github.com/p4lang/behavioral-model/blob/master/tools/veth_teardown.sh + +for idx in 0 1 2 3 4 5 6 7 8; do + intf="veth$(($idx*2))" + if ip link show $intf &> /dev/null; then + ip link delete $intf type veth + fi +done diff --git a/exercises/basic/Makefile b/exercises/basic/Makefile index b61b2468..fc5fb0ed 100644 --- a/exercises/basic/Makefile +++ b/exercises/basic/Makefile @@ -4,5 +4,5 @@ TOPO = pod-topo/topology.json include ../../utils/Makefile -test: +test: dirs ./runptf.sh diff --git a/exercises/basic/runptf.sh b/exercises/basic/runptf.sh index 8602db53..99d0b916 100755 --- a/exercises/basic/runptf.sh +++ b/exercises/basic/runptf.sh @@ -3,20 +3,9 @@ # Tests run against the solution P4 program. set -e +BINDIR=$(realpath ../../bin) -# ---- veth setup ---- -echo "Creating veth interfaces..." -for i in 0 1 2 3 4 5 6 7; do - intf0="veth$(( i * 2 ))" - intf1="veth$(( i * 2 + 1 ))" - if ! ip link show $intf0 &>/dev/null; then - sudo ip link add name $intf0 type veth peer name $intf1 - sudo ip link set dev $intf0 up - sudo ip link set dev $intf1 up - sudo sysctl -q net.ipv6.conf.$intf0.disable_ipv6=1 - sudo sysctl -q net.ipv6.conf.$intf1.disable_ipv6=1 - fi -done +sudo "${BINDIR}"/veth_setup.sh set -x @@ -71,12 +60,7 @@ sudo pkill --signal 9 --list-name simple_switch echo "" echo "Cleaning up veth interfaces..." -for i in 0 1 2 3 4 5 6 7; do - intf0="veth$(( i * 2 ))" - if ip link show $intf0 &>/dev/null; then - sudo ip link del $intf0 - fi -done +sudo "${BINDIR}"/veth_teardown.sh echo "" echo "Verifying no simple_switch_grpc processes remain..."