Commit cb7f2d05 authored by David S. Miller's avatar David S. Miller
Browse files

Merge branch 'ocelot-selftests'



Vladimir Oltean says:

====================
Streamline Ocelot tc-chains selftest

This series changes the output and the argument format of the Ocelot
switch selftest so that it is more similar to what can be found in
tools/testing/selftests/net/forwarding/.
====================

Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parents c304eddc 4ea1396a
Loading
Loading
Loading
Loading
+97 −105
Original line number Diff line number Diff line
@@ -4,35 +4,17 @@

WAIT_TIME=1
NUM_NETIFS=4
STABLE_MAC_ADDRS=yes
lib_dir=$(dirname $0)/../../../net/forwarding
source $lib_dir/tc_common.sh
source $lib_dir/lib.sh

require_command tcpdump

#
#   +---------------------------------------------+
#   |       DUT ports         Generator ports     |
#   | +--------+ +--------+ +--------+ +--------+ |
#   | |        | |        | |        | |        | |
#   | |  eth0  | |  eth1  | |  eth2  | |  eth3  | |
#   | |        | |        | |        | |        | |
#   +-+--------+-+--------+-+--------+-+--------+-+
#          |         |           |          |
#          |         |           |          |
#          |         +-----------+          |
#          |                                |
#          +--------------------------------+

eth0=${NETIFS[p1]}
eth1=${NETIFS[p2]}
eth2=${NETIFS[p3]}
eth3=${NETIFS[p4]}

eth0_mac="de:ad:be:ef:00:00"
eth1_mac="de:ad:be:ef:00:01"
eth2_mac="de:ad:be:ef:00:02"
eth3_mac="de:ad:be:ef:00:03"
h1=${NETIFS[p1]}
swp1=${NETIFS[p2]}
swp2=${NETIFS[p3]}
h2=${NETIFS[p4]}

# Helpers to map a VCAP IS1 and VCAP IS2 lookup and policy to a chain number
# used by the kernel driver. The numbers are:
@@ -156,39 +138,39 @@ create_tcam_skeleton()

setup_prepare()
{
	ip link set $eth0 up
	ip link set $eth1 up
	ip link set $eth2 up
	ip link set $eth3 up
	ip link set $swp1 up
	ip link set $swp2 up
	ip link set $h2 up
	ip link set $h1 up

	create_tcam_skeleton $eth0
	create_tcam_skeleton $swp1

	ip link add br0 type bridge
	ip link set $eth0 master br0
	ip link set $eth1 master br0
	ip link set $swp1 master br0
	ip link set $swp2 master br0
	ip link set br0 up

	ip link add link $eth3 name $eth3.100 type vlan id 100
	ip link set $eth3.100 up
	ip link add link $h1 name $h1.100 type vlan id 100
	ip link set $h1.100 up

	ip link add link $eth3 name $eth3.200 type vlan id 200
	ip link set $eth3.200 up
	ip link add link $h1 name $h1.200 type vlan id 200
	ip link set $h1.200 up

	tc filter add dev $eth0 ingress chain $(IS1 1) pref 1 \
	tc filter add dev $swp1 ingress chain $(IS1 1) pref 1 \
		protocol 802.1Q flower skip_sw vlan_id 100 \
		action vlan pop \
		action goto chain $(IS1 2)

	tc filter add dev $eth0 egress chain $(ES0) pref 1 \
		flower skip_sw indev $eth1 \
	tc filter add dev $swp1 egress chain $(ES0) pref 1 \
		flower skip_sw indev $swp2 \
		action vlan push protocol 802.1Q id 100

	tc filter add dev $eth0 ingress chain $(IS1 0) pref 2 \
	tc filter add dev $swp1 ingress chain $(IS1 0) pref 2 \
		protocol ipv4 flower skip_sw src_ip 10.1.1.2 \
		action skbedit priority 7 \
		action goto chain $(IS1 1)

	tc filter add dev $eth0 ingress chain $(IS2 0 0) pref 1 \
	tc filter add dev $swp1 ingress chain $(IS2 0 0) pref 1 \
		protocol ipv4 flower skip_sw ip_proto udp dst_port 5201 \
		action police rate 50mbit burst 64k conform-exceed drop/pipe \
		action goto chain $(IS2 1 0)
@@ -196,150 +178,160 @@ setup_prepare()

cleanup()
{
	ip link del $eth3.200
	ip link del $eth3.100
	tc qdisc del dev $eth0 clsact
	ip link del $h1.200
	ip link del $h1.100
	tc qdisc del dev $swp1 clsact
	ip link del br0
}

test_vlan_pop()
{
	printf "Testing VLAN pop..			"
	local h1_mac=$(mac_get $h1)
	local h2_mac=$(mac_get $h2)

	RET=0

	tcpdump_start $eth2
	tcpdump_start $h2

	# Work around Mausezahn VLAN builder bug
	# (https://github.com/netsniff-ng/netsniff-ng/issues/225) by using
	# an 8021q upper
	$MZ $eth3.100 -q -c 1 -p 64 -a $eth3_mac -b $eth2_mac -t ip
	$MZ $h1.100 -q -c 1 -p 64 -a $h1_mac -b $h2_mac -t ip

	sleep 1

	tcpdump_stop $eth2
	tcpdump_stop $h2

	if tcpdump_show $eth2 | grep -q "$eth3_mac > $eth2_mac, ethertype IPv4"; then
		echo "OK"
	else
		echo "FAIL"
	fi
	tcpdump_show $h2 | grep -q "$h1_mac > $h2_mac, ethertype IPv4"
	check_err "$?" "untagged reception"

	tcpdump_cleanup $h2

	tcpdump_cleanup $eth2
	log_test "VLAN pop"
}

test_vlan_push()
{
	printf "Testing VLAN push..			"
	local h1_mac=$(mac_get $h1)
	local h2_mac=$(mac_get $h2)

	tcpdump_start $eth3.100
	RET=0

	$MZ $eth2 -q -c 1 -p 64 -a $eth2_mac -b $eth3_mac -t ip
	tcpdump_start $h1.100

	$MZ $h2 -q -c 1 -p 64 -a $h2_mac -b $h1_mac -t ip

	sleep 1

	tcpdump_stop $eth3.100
	tcpdump_stop $h1.100

	if tcpdump_show $eth3.100 | grep -q "$eth2_mac > $eth3_mac"; then
		echo "OK"
	else
		echo "FAIL"
	fi
	tcpdump_show $h1.100 | grep -q "$h2_mac > $h1_mac"
	check_err "$?" "tagged reception"

	tcpdump_cleanup $eth3.100
	tcpdump_cleanup $h1.100

	log_test "VLAN push"
}

test_vlan_ingress_modify()
{
	printf "Testing ingress VLAN modification..		"
	local h1_mac=$(mac_get $h1)
	local h2_mac=$(mac_get $h2)

	RET=0

	ip link set br0 type bridge vlan_filtering 1
	bridge vlan add dev $eth0 vid 200
	bridge vlan add dev $eth0 vid 300
	bridge vlan add dev $eth1 vid 300
	bridge vlan add dev $swp1 vid 200
	bridge vlan add dev $swp1 vid 300
	bridge vlan add dev $swp2 vid 300

	tc filter add dev $eth0 ingress chain $(IS1 2) pref 3 \
	tc filter add dev $swp1 ingress chain $(IS1 2) pref 3 \
		protocol 802.1Q flower skip_sw vlan_id 200 \
		action vlan modify id 300 \
		action goto chain $(IS2 0 0)

	tcpdump_start $eth2
	tcpdump_start $h2

	$MZ $eth3.200 -q -c 1 -p 64 -a $eth3_mac -b $eth2_mac -t ip
	$MZ $h1.200 -q -c 1 -p 64 -a $h1_mac -b $h2_mac -t ip

	sleep 1

	tcpdump_stop $eth2
	tcpdump_stop $h2

	if tcpdump_show $eth2 | grep -q "$eth3_mac > $eth2_mac, .* vlan 300"; then
		echo "OK"
	else
		echo "FAIL"
	fi
	tcpdump_show $h2 | grep -q "$h1_mac > $h2_mac, .* vlan 300"
	check_err "$?" "tagged reception"

	tcpdump_cleanup $eth2
	tcpdump_cleanup $h2

	tc filter del dev $eth0 ingress chain $(IS1 2) pref 3
	tc filter del dev $swp1 ingress chain $(IS1 2) pref 3

	bridge vlan del dev $eth0 vid 200
	bridge vlan del dev $eth0 vid 300
	bridge vlan del dev $eth1 vid 300
	bridge vlan del dev $swp1 vid 200
	bridge vlan del dev $swp1 vid 300
	bridge vlan del dev $swp2 vid 300
	ip link set br0 type bridge vlan_filtering 0

	log_test "Ingress VLAN modification"
}

test_vlan_egress_modify()
{
	printf "Testing egress VLAN modification..		"
	local h1_mac=$(mac_get $h1)
	local h2_mac=$(mac_get $h2)

	RET=0

	tc qdisc add dev $eth1 clsact
	tc qdisc add dev $swp2 clsact

	ip link set br0 type bridge vlan_filtering 1
	bridge vlan add dev $eth0 vid 200
	bridge vlan add dev $eth1 vid 200
	bridge vlan add dev $swp1 vid 200
	bridge vlan add dev $swp2 vid 200

	tc filter add dev $eth1 egress chain $(ES0) pref 3 \
	tc filter add dev $swp2 egress chain $(ES0) pref 3 \
		protocol 802.1Q flower skip_sw vlan_id 200 vlan_prio 0 \
		action vlan modify id 300 priority 7

	tcpdump_start $eth2
	tcpdump_start $h2

	$MZ $eth3.200 -q -c 1 -p 64 -a $eth3_mac -b $eth2_mac -t ip
	$MZ $h1.200 -q -c 1 -p 64 -a $h1_mac -b $h2_mac -t ip

	sleep 1

	tcpdump_stop $eth2
	tcpdump_stop $h2

	if tcpdump_show $eth2 | grep -q "$eth3_mac > $eth2_mac, .* vlan 300"; then
		echo "OK"
	else
		echo "FAIL"
	fi
	tcpdump_show $h2 | grep -q "$h1_mac > $h2_mac, .* vlan 300"
	check_err "$?" "tagged reception"

	tcpdump_cleanup $eth2
	tcpdump_cleanup $h2

	tc filter del dev $eth1 egress chain $(ES0) pref 3
	tc qdisc del dev $eth1 clsact
	tc filter del dev $swp2 egress chain $(ES0) pref 3
	tc qdisc del dev $swp2 clsact

	bridge vlan del dev $eth0 vid 200
	bridge vlan del dev $eth1 vid 200
	bridge vlan del dev $swp1 vid 200
	bridge vlan del dev $swp2 vid 200
	ip link set br0 type bridge vlan_filtering 0

	log_test "Egress VLAN modification"
}

test_skbedit_priority()
{
	local h1_mac=$(mac_get $h1)
	local h2_mac=$(mac_get $h2)
	local num_pkts=100

	printf "Testing frame prioritization..		"
	before=$(ethtool_stats_get $swp1 'rx_green_prio_7')

	before=$(ethtool_stats_get $eth0 'rx_green_prio_7')
	$MZ $h1 -q -c $num_pkts -p 64 -a $h1_mac -b $h2_mac -t ip -A 10.1.1.2

	$MZ $eth3 -q -c $num_pkts -p 64 -a $eth3_mac -b $eth2_mac -t ip -A 10.1.1.2

	after=$(ethtool_stats_get $eth0 'rx_green_prio_7')
	after=$(ethtool_stats_get $swp1 'rx_green_prio_7')

	if [ $((after - before)) = $num_pkts ]; then
		echo "OK"
		RET=0
	else
		echo "FAIL"
		RET=1
	fi

	log_test "Frame prioritization"
}

trap cleanup EXIT