From e66443c9b411368bf856b74580d19144bb28d236 Mon Sep 17 00:00:00 2001 From: Ole Troan Date: Thu, 18 Mar 2021 11:12:01 +0100 Subject: stats: python vpp_stats rewrite to access stat segment directly This module implement Python access to the VPP statistics segment. It accesses the data structures directly in shared memory. VPP uses optimistic locking, so data structures may change underneath us while we are reading. Data is copied out and it's important to spend as little time as possible "holding the lock". Counters are stored in VPP as a two dimensional array. Index by thread and index (typically sw_if_index). Simple counters count only packets, Combined counters count packets and octets. Counters can be accessed in either dimension. stat['/if/rx'] - returns 2D lists stat['/if/rx'][0] - returns counters for all interfaces for thread 0 stat['/if/rx'][0][1] - returns counter for interface 1 on thread 0 stat['/if/rx'][0][1]['packets'] - returns the packet counter for interface 1 on thread 0 stat['/if/rx'][:, 1] - returns the counters for interface 1 on all threads stat['/if/rx'][:, 1].packets() - returns the packet counters for interface 1 on all threads stat['/if/rx'][:, 1].sum_packets() - returns the sum of packet counters for interface 1 on all threads stat['/if/rx-miss'][:, 1].sum() - returns the sum of packet counters for interface 1 on all threads for simple counters Type: refactor Signed-off-by: Ole Troan Change-Id: I1fe7f7c7d11378d06be8276db5e1900ecdb8f515 Signed-off-by: Ole Troan --- src/plugins/urpf/ip4_urpf.c | 2 +- src/plugins/urpf/ip6_urpf.c | 2 +- src/plugins/urpf/test/test_urpf.py | 30 ++++++++++++++++++++---------- 3 files changed, 22 insertions(+), 12 deletions(-) (limited to 'src/plugins/urpf') diff --git a/src/plugins/urpf/ip4_urpf.c b/src/plugins/urpf/ip4_urpf.c index 25b6c94bde3..1d329029478 100644 --- a/src/plugins/urpf/ip4_urpf.c +++ b/src/plugins/urpf/ip4_urpf.c @@ -41,7 +41,7 @@ #include static char *ip4_urpf_error_strings[] = { -#define _(a,b) "ip4-" # b, +#define _(a, b) b, foreach_urpf_error #undef _ }; diff --git a/src/plugins/urpf/ip6_urpf.c b/src/plugins/urpf/ip6_urpf.c index 3a94a456cb7..48d991573b5 100644 --- a/src/plugins/urpf/ip6_urpf.c +++ b/src/plugins/urpf/ip6_urpf.c @@ -41,7 +41,7 @@ #include static char *ip6_urpf_error_strings[] = { -#define _(a,b) "ip6-" # b, +#define _(a, b) b, foreach_urpf_error #undef _ }; diff --git a/src/plugins/urpf/test/test_urpf.py b/src/plugins/urpf/test/test_urpf.py index 64b246cd663..8f4e563f8bc 100644 --- a/src/plugins/urpf/test/test_urpf.py +++ b/src/plugins/urpf/test/test_urpf.py @@ -90,7 +90,8 @@ class TestURPF(VppTestCase): # packets from address to which there is no route are dropped self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip4-rx-urpf-loose", N_PKTS) + self.assert_error_counter_equal("/err/ip4-rx-urpf-loose/uRPF Drop", + N_PKTS) # # crank it up to strict mode @@ -106,7 +107,8 @@ class TestURPF(VppTestCase): self.send_and_assert_no_replies(self.pg0, p_spoof_strict) self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip4-rx-urpf-strict", 2 * N_PKTS) + self.assert_error_counter_equal("/err/ip4-rx-urpf-strict/uRPF Drop", + 2 * N_PKTS) # # disable uRPF, all traffic should pass @@ -136,7 +138,8 @@ class TestURPF(VppTestCase): self.send_and_expect(self.pg0, p_spoof_strict, self.pg1) self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip4-tx-urpf-loose", N_PKTS) + self.assert_error_counter_equal("/err/ip4-tx-urpf-loose/uRPF Drop", + N_PKTS) self.vapi.urpf_update(is_input=False, mode=e.vl_api_urpf_mode_t.URPF_API_MODE_STRICT, @@ -149,7 +152,8 @@ class TestURPF(VppTestCase): self.send_and_expect(self.pg0, p_spoof_strict, self.pg1) self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip4-tx-urpf-strict", N_PKTS) + self.assert_error_counter_equal("/err/ip4-tx-urpf-strict/uRPF Drop", + N_PKTS) # change the strict packet so that it would forward through pg1 p_spoof_strict = (Ether(dst=self.pg0.local_mac, @@ -160,7 +164,8 @@ class TestURPF(VppTestCase): Raw(b'\xa5' * 100)) * N_PKTS self.send_and_assert_no_replies(self.pg0, p_spoof_strict) - self.assert_error_counter_equal("ip4-tx-urpf-strict", 2 * N_PKTS) + self.assert_error_counter_equal("/err/ip4-tx-urpf-strict/uRPF Drop", + 2 * N_PKTS) # cleanup self.vapi.urpf_update(is_input=False, @@ -212,7 +217,8 @@ class TestURPF(VppTestCase): # packets from address to which there is no route are dropped self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip6-rx-urpf-loose", N_PKTS) + self.assert_error_counter_equal("/err/ip6-rx-urpf-loose/uRPF Drop", + N_PKTS) # # crank it up to strict mode @@ -228,7 +234,8 @@ class TestURPF(VppTestCase): self.send_and_assert_no_replies(self.pg0, p_spoof_strict) self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip6-rx-urpf-strict", 2 * N_PKTS) + self.assert_error_counter_equal("/err/ip6-rx-urpf-strict/uRPF Drop", + 2 * N_PKTS) # # disable uRPF, all traffic should pass @@ -258,7 +265,8 @@ class TestURPF(VppTestCase): self.send_and_expect(self.pg0, p_spoof_strict, self.pg1) self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip6-tx-urpf-loose", N_PKTS) + self.assert_error_counter_equal("/err/ip6-tx-urpf-loose/uRPF Drop", + N_PKTS) self.vapi.urpf_update(is_input=False, mode=e.vl_api_urpf_mode_t.URPF_API_MODE_STRICT, @@ -271,7 +279,8 @@ class TestURPF(VppTestCase): self.send_and_expect(self.pg0, p_spoof_strict, self.pg1) self.send_and_assert_no_replies(self.pg0, p_spoof_loose) - self.assert_error_counter_equal("ip6-tx-urpf-strict", N_PKTS) + self.assert_error_counter_equal("/err/ip6-tx-urpf-strict/uRPF Drop", + N_PKTS) # change the strict packet so that it would forward through pg1 p_spoof_strict = (Ether(dst=self.pg0.local_mac, @@ -282,7 +291,8 @@ class TestURPF(VppTestCase): Raw(b'\xa5' * 100)) * N_PKTS self.send_and_assert_no_replies(self.pg0, p_spoof_strict) - self.assert_error_counter_equal("ip6-tx-urpf-strict", 2 * N_PKTS) + self.assert_error_counter_equal("/err/ip6-tx-urpf-strict/uRPF Drop", + 2 * N_PKTS) # cleanup self.vapi.urpf_update(is_input=False, -- cgit 1.2.3-korg