selftests: forwarding: lib: Add tc_rule_handle_stats_get()
authorPetr Machata <petrm@mellanox.com>
Mon, 2 Mar 2020 17:56:02 +0000 (19:56 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 4 Mar 2020 01:03:52 +0000 (17:03 -0800)
The function tc_rule_stats_get() fetches a given statistic of a TC rule
given the rule preference. Another common way to reference a rule is using
its handle. Introduce a dual to the aforementioned function that gets a
statistic given rule handle.

Signed-off-by: Petr Machata <petrm@mellanox.com>
Reviewed-by: Amit Cohen <amitc@mellanox.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
tools/testing/selftests/net/forwarding/lib.sh

index 83fd15e3e5451856257cd550e755f07a32ee4212..de57e8887a7c20419ddf2e2f7c23e5fa37e29518 100644 (file)
@@ -626,6 +626,17 @@ tc_rule_stats_get()
            | jq ".[1].options.actions[].stats$selector"
 }
 
+tc_rule_handle_stats_get()
+{
+       local id=$1; shift
+       local handle=$1; shift
+       local selector=${1:-.packets}; shift
+
+       tc -j -s filter show $id \
+           | jq ".[] | select(.options.handle == $handle) | \
+                 .options.actions[0].stats$selector"
+}
+
 ethtool_stats_get()
 {
        local dev=$1; shift