summaryrefslogtreecommitdiff
path: root/tools/testing/selftests/net/forwarding/mirror_lib.sh
diff options
context:
space:
mode:
authorPetr Machata <petrm@mellanox.com>2018-04-27 01:17:56 +0200
committerDavid S. Miller <davem@davemloft.net>2018-04-27 14:57:49 -0400
commit7d4cbae04f835525295c501770155c755228eb55 (patch)
treee06b1fc456e60f8ca3b1ef356a70801b1535bd19 /tools/testing/selftests/net/forwarding/mirror_lib.sh
parent6a26ef9bf4821633c02ee4cb8d1957072eb22c9b (diff)
selftests: forwarding: Add libs for gretap mirror testing
To simplify implementation of mirror-to-gretap tests, extend lib.sh with several new functions that might potentially be useful more broadly (although right now the mirroring tests will be the only client). Also add mirror_lib.sh with code useful for mirroring tests, mirror_gre_lib.sh with code specifically useful for mirror-to-gretap tests, and mirror_gre_topo.sh that primes a given test with a good baseline topology that the test can then tweak to its liking. Signed-off-by: Petr Machata <petrm@mellanox.com> Reviewed-by: Jiri Pirko <jiri@mellanox.com> Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'tools/testing/selftests/net/forwarding/mirror_lib.sh')
-rw-r--r--tools/testing/selftests/net/forwarding/mirror_lib.sh40
1 files changed, 40 insertions, 0 deletions
diff --git a/tools/testing/selftests/net/forwarding/mirror_lib.sh b/tools/testing/selftests/net/forwarding/mirror_lib.sh
new file mode 100644
index 000000000000..e5028a5725e3
--- /dev/null
+++ b/tools/testing/selftests/net/forwarding/mirror_lib.sh
@@ -0,0 +1,40 @@
+# SPDX-License-Identifier: GPL-2.0
+
+mirror_install()
+{
+ local from_dev=$1; shift
+ local direction=$1; shift
+ local to_dev=$1; shift
+ local filter=$1; shift
+
+ tc filter add dev $from_dev $direction \
+ pref 1000 $filter \
+ action mirred egress mirror dev $to_dev
+}
+
+mirror_uninstall()
+{
+ local from_dev=$1; shift
+ local direction=$1; shift
+
+ tc filter del dev $swp1 $direction pref 1000
+}
+
+mirror_test()
+{
+ local vrf_name=$1; shift
+ local sip=$1; shift
+ local dip=$1; shift
+ local dev=$1; shift
+ local pref=$1; shift
+ local expect=$1; shift
+
+ local t0=$(tc_rule_stats_get $dev $pref)
+ ip vrf exec $vrf_name \
+ ${PING} ${sip:+-I $sip} $dip -c 10 -i 0.1 -w 2 &> /dev/null
+ local t1=$(tc_rule_stats_get $dev $pref)
+ local delta=$((t1 - t0))
+ # Tolerate a couple stray extra packets.
+ ((expect <= delta && delta <= expect + 2))
+ check_err $? "Expected to capture $expect packets, got $delta."
+}