Commit 6b45fe95 authored by Amit Cohen's avatar Amit Cohen Committed by David S. Miller

selftests: devlink: Export functions to devlink library

l2_drops_test() is used to check that drop traps are functioning as
intended. Currently it is only used in the layer 2 test, but it is also
useful for the layer 3 test introduced in the subsequent patch.

l2_drops_cleanup() is used to clean configurations and kill mausezahn
proccess.

Export the functions to the common devlink library to allow it to be
re-used by future tests.
Signed-off-by: default avatarAmit Cohen <amitc@mellanox.com>
Acked-by: default avatarJiri Pirko <jiri@mellanox.com>
Signed-off-by: default avatarIdo Schimmel <idosch@mellanox.com>
Signed-off-by: default avatarDavid S. Miller <davem@davemloft.net>
parent dbc684f1
......@@ -92,46 +92,6 @@ cleanup()
vrf_cleanup
}
l2_drops_test()
{
local trap_name=$1; shift
local group_name=$1; shift
# This is the common part of all the tests. It checks that stats are
# initially idle, then non-idle after changing the trap action and
# finally idle again. It also makes sure the packets are dropped and
# never forwarded.
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle with initial drop action"
devlink_trap_group_stats_idle_test $group_name
check_err $? "Trap group stats not idle with initial drop action"
devlink_trap_action_set $trap_name "trap"
devlink_trap_stats_idle_test $trap_name
check_fail $? "Trap stats idle after setting action to trap"
devlink_trap_group_stats_idle_test $group_name
check_fail $? "Trap group stats idle after setting action to trap"
devlink_trap_action_set $trap_name "drop"
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle after setting action to drop"
devlink_trap_group_stats_idle_test $group_name
check_err $? "Trap group stats not idle after setting action to drop"
tc_check_packets "dev $swp2 egress" 101 0
check_err $? "Packets were not dropped"
}
l2_drops_cleanup()
{
local mz_pid=$1; shift
kill $mz_pid && wait $mz_pid &> /dev/null
tc filter del dev $swp2 egress protocol ip pref 1 handle 101 flower
}
source_mac_is_multicast_test()
{
local trap_name="source_mac_is_multicast"
......@@ -147,11 +107,11 @@ source_mac_is_multicast_test()
RET=0
l2_drops_test $trap_name $group_name
devlink_trap_drop_test $trap_name $group_name $swp2
log_test "Source MAC is multicast"
l2_drops_cleanup $mz_pid
devlink_trap_drop_cleanup $mz_pid $swp2
}
__vlan_tag_mismatch_test()
......@@ -172,7 +132,7 @@ __vlan_tag_mismatch_test()
$MZ $h1 "$opt" -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
l2_drops_test $trap_name $group_name
devlink_trap_drop_test $trap_name $group_name $swp2
# Add PVID and make sure packets are no longer dropped.
bridge vlan add vid 1 dev $swp1 pvid untagged master
......@@ -188,7 +148,7 @@ __vlan_tag_mismatch_test()
devlink_trap_action_set $trap_name "drop"
l2_drops_cleanup $mz_pid
devlink_trap_drop_cleanup $mz_pid $swp2
}
vlan_tag_mismatch_untagged_test()
......@@ -233,7 +193,7 @@ ingress_vlan_filter_test()
$MZ $h1 -Q $vid -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
l2_drops_test $trap_name $group_name
devlink_trap_drop_test $trap_name $group_name $swp2
# Add the VLAN on the bridge port and make sure packets are no longer
# dropped.
......@@ -252,7 +212,7 @@ ingress_vlan_filter_test()
log_test "Ingress VLAN filter"
l2_drops_cleanup $mz_pid
devlink_trap_drop_cleanup $mz_pid $swp2
bridge vlan del vid $vid dev $swp1 master
bridge vlan del vid $vid dev $swp2 master
......@@ -277,7 +237,7 @@ __ingress_stp_filter_test()
$MZ $h1 -Q $vid -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
l2_drops_test $trap_name $group_name
devlink_trap_drop_test $trap_name $group_name $swp2
# Change STP state to forwarding and make sure packets are no longer
# dropped.
......@@ -294,7 +254,7 @@ __ingress_stp_filter_test()
devlink_trap_action_set $trap_name "drop"
l2_drops_cleanup $mz_pid
devlink_trap_drop_cleanup $mz_pid $swp2
bridge vlan del vid $vid dev $swp1 master
bridge vlan del vid $vid dev $swp2 master
......@@ -348,7 +308,7 @@ port_list_is_empty_uc_test()
$MZ $h1 -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
l2_drops_test $trap_name $group_name
devlink_trap_drop_test $trap_name $group_name $swp2
# Allow packets to be flooded to one port.
ip link set dev $swp2 type bridge_slave flood on
......@@ -366,7 +326,7 @@ port_list_is_empty_uc_test()
log_test "Port list is empty - unicast"
l2_drops_cleanup $mz_pid
devlink_trap_drop_cleanup $mz_pid $swp2
ip link set dev $swp1 type bridge_slave flood on
}
......@@ -394,7 +354,7 @@ port_list_is_empty_mc_test()
$MZ $h1 -c 0 -p 100 -a own -b $dmac -t ip -B $dip -d 1msec -q &
mz_pid=$!
l2_drops_test $trap_name $group_name
devlink_trap_drop_test $trap_name $group_name $swp2
# Allow packets to be flooded to one port.
ip link set dev $swp2 type bridge_slave mcast_flood on
......@@ -412,7 +372,7 @@ port_list_is_empty_mc_test()
log_test "Port list is empty - multicast"
l2_drops_cleanup $mz_pid
devlink_trap_drop_cleanup $mz_pid $swp2
ip link set dev $swp1 type bridge_slave mcast_flood on
}
......@@ -441,7 +401,7 @@ port_loopback_filter_uc_test()
$MZ $h1 -c 0 -p 100 -a own -b $dmac -t ip -d 1msec -q &
mz_pid=$!
l2_drops_test $trap_name $group_name
devlink_trap_drop_test $trap_name $group_name $swp2
# Allow packets to be flooded.
ip link set dev $swp2 type bridge_slave flood on
......@@ -459,7 +419,7 @@ port_loopback_filter_uc_test()
log_test "Port loopback filter - unicast"
l2_drops_cleanup $mz_pid
devlink_trap_drop_cleanup $mz_pid $swp2
}
port_loopback_filter_test()
......
......@@ -355,3 +355,45 @@ devlink_trap_group_stats_idle_test()
return 1
fi
}
devlink_trap_drop_test()
{
local trap_name=$1; shift
local group_name=$1; shift
local dev=$1; shift
# This is the common part of all the tests. It checks that stats are
# initially idle, then non-idle after changing the trap action and
# finally idle again. It also makes sure the packets are dropped and
# never forwarded.
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle with initial drop action"
devlink_trap_group_stats_idle_test $group_name
check_err $? "Trap group stats not idle with initial drop action"
devlink_trap_action_set $trap_name "trap"
devlink_trap_stats_idle_test $trap_name
check_fail $? "Trap stats idle after setting action to trap"
devlink_trap_group_stats_idle_test $group_name
check_fail $? "Trap group stats idle after setting action to trap"
devlink_trap_action_set $trap_name "drop"
devlink_trap_stats_idle_test $trap_name
check_err $? "Trap stats not idle after setting action to drop"
devlink_trap_group_stats_idle_test $group_name
check_err $? "Trap group stats not idle after setting action to drop"
tc_check_packets "dev $dev egress" 101 0
check_err $? "Packets were not dropped"
}
devlink_trap_drop_cleanup()
{
local mz_pid=$1; shift
local dev=$1; shift
kill $mz_pid && wait $mz_pid &> /dev/null
tc filter del dev $dev egress protocol ip pref 1 handle 101 flower
}
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment