diff mbox series

[net-next,mlxsw,v3,08/10] selftests: forwarding: lib: Add DSCP capture

Message ID 7d9b5ce7ae80826de8c48441e5a0a22e8c449c88.1532716714.git.petrm@mellanox.com (mailing list archive)
State Not Applicable
Headers show
Series mlxsw: Support DSCP prioritization and rewrite | expand

Commit Message

Petr Machata July 27, 2018, 7:10 p.m. UTC
DSCP captures are TC rules intended to notice packets with a given DSCP
value. Add dscp_capture_install(), dscp_capture_uninstall() and their
helper along the lines of ICMP and VLAN captures already present in
lib.sh.

Complementary to the install and uninstall functions is a function to
collect the capture stats: dscp_fetch_stats().

Signed-off-by: Petr Machata <petrm@mellanox.com>
---
 tools/testing/selftests/net/forwarding/lib.sh | 42 +++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)
diff mbox series

Patch

diff --git a/tools/testing/selftests/net/forwarding/lib.sh b/tools/testing/selftests/net/forwarding/lib.sh
index 158d59ffee40..d396f89d864d 100644
--- a/tools/testing/selftests/net/forwarding/lib.sh
+++ b/tools/testing/selftests/net/forwarding/lib.sh
@@ -605,6 +605,48 @@  vlan_capture_uninstall()
 	__vlan_capture_add_del del 100 "$@"
 }
 
+__dscp_capture_add_del()
+{
+	local add_del=$1; shift
+	local dev=$1; shift
+	local base=$1; shift
+	local dscp;
+
+	for prio in {0..7}; do
+		dscp=$((base + prio))
+		__icmp_capture_add_del $add_del $((dscp + 100)) "" $dev \
+				       "skip_hw ip_tos $((dscp << 2))"
+	done
+}
+
+dscp_capture_install()
+{
+	local dev=$1; shift
+	local base=$1; shift
+
+	__dscp_capture_add_del add $dev $base
+}
+
+dscp_capture_uninstall()
+{
+	local dev=$1; shift
+	local base=$1; shift
+
+	__dscp_capture_add_del del $dev $base
+}
+
+dscp_fetch_stats()
+{
+	local dev=$1; shift
+	local base=$1; shift
+
+	for prio in {0..7}; do
+		local dscp=$((base + prio))
+		local t=$(tc_rule_stats_get $dev $((dscp + 100)))
+		echo "[$dscp]=$t "
+	done
+}
+
 matchall_sink_create()
 {
 	local dev=$1; shift