diff options
author | Klement Sekera <klement@graphiant.com> | 2022-02-18 10:34:35 +0000 |
---|---|---|
committer | Neale Ranns <neale@graphiant.com> | 2022-02-21 08:29:00 +0000 |
commit | ad3187fe23bb139b44c1bac7cd13dd86523fb90a (patch) | |
tree | 6d3a9ecd50ec7b4ed1c9074c9f20f97fcdb318e3 /test/test_nat44_ed.py | |
parent | 107ad73e1be0b95f72b68c06f22d4e94ea841181 (diff) |
tests: add enhanced packet counter verification
Add support for inline packet counter verification to send_and_* functions.
Diff dictionary is a dictionary of dictionaries of interesting stats:
diff_dictionary =
{
"err" : { '/error/counter1' : 4, },
sw_if_index1 : { '/stat/segment/counter1' : 5,
'/stat/segment/counter2' : 6,
},
sw_if_index2 : { '/stat/segment/counter1' : 7,
},
}
It describes a per sw-if-index diffset, where each key is stat segment
path and value is the expected change for that counter for sw-if-index.
Special case string "err" is used for error counters.
This then allows more precise packet counter verification by first
defining a "zero" dictionary, e.g. for ED NAT:
cls.no_diff = StatsDiff({
pg.sw_if_index: {
'/nat44-ed/in2out/fastpath/tcp': 0,
'/nat44-ed/in2out/fastpath/udp': 0,
'/nat44-ed/in2out/fastpath/icmp': 0,
'/nat44-ed/in2out/fastpath/drops': 0,
'/nat44-ed/in2out/slowpath/tcp': 0,
'/nat44-ed/in2out/slowpath/udp': 0,
'/nat44-ed/in2out/slowpath/icmp': 0,
'/nat44-ed/in2out/slowpath/drops': 0,
'/nat44-ed/in2out/fastpath/tcp': 0,
'/nat44-ed/in2out/fastpath/udp': 0,
'/nat44-ed/in2out/fastpath/icmp': 0,
'/nat44-ed/in2out/fastpath/drops': 0,
'/nat44-ed/in2out/slowpath/tcp': 0,
'/nat44-ed/in2out/slowpath/udp': 0,
'/nat44-ed/in2out/slowpath/icmp': 0,
'/nat44-ed/in2out/slowpath/drops': 0,
}
for pg in cls.pg_interfaces
})
and then to specify only changed counters directly when calling
one of send_and_* functions:
self.send_and_assert_no_replies(
self.pg0, pkts, msg="i2o pkts",
stats_diff=self.no_diff | {
"err": {
'/err/nat44-ed-in2out-slowpath/out of ports': len(pkts),
},
self.pg0.sw_if_index: {
'/nat44-ed/in2out/slowpath/drops': len(pkts),
},
}
)
operator | is overloaded by StatsDiff class to perform a deep merge operation,
so in above case, dictionaries for "err" and self.pg0.sw_if_index do not
overwrite whole sub-dictionaries, rather the contents are merged,
assuring that all the remaining counters are verified to be zero.
Type: improvement
Signed-off-by: Klement Sekera <klement.sekera@gmail.com>
Change-Id: I2b87f7bd58a7d4b34ee72344e2f871b2f372e2d9
Diffstat (limited to 'test/test_nat44_ed.py')
-rw-r--r-- | test/test_nat44_ed.py | 79 |
1 files changed, 53 insertions, 26 deletions
diff --git a/test/test_nat44_ed.py b/test/test_nat44_ed.py index 9bb803e4435..764693d636a 100644 --- a/test/test_nat44_ed.py +++ b/test/test_nat44_ed.py @@ -2,7 +2,7 @@ import unittest from io import BytesIO -from random import randint, shuffle, choice +from random import randint, choice import scapy.compat from framework import VppTestCase, VppTestRunner @@ -17,6 +17,7 @@ from util import ppp, ip4_range from vpp_acl import AclRule, VppAcl, VppAclInterface from vpp_ip_route import VppIpRoute, VppRoutePath from vpp_papi import VppEnum +from util import StatsDiff class TestNAT44ED(VppTestCase): @@ -213,6 +214,28 @@ class TestNAT44ED(VppTestCase): for r in rl: r.add_vpp_config() + cls.no_diff = StatsDiff({ + pg.sw_if_index: { + '/nat44-ed/in2out/fastpath/tcp': 0, + '/nat44-ed/in2out/fastpath/udp': 0, + '/nat44-ed/in2out/fastpath/icmp': 0, + '/nat44-ed/in2out/fastpath/drops': 0, + '/nat44-ed/in2out/slowpath/tcp': 0, + '/nat44-ed/in2out/slowpath/udp': 0, + '/nat44-ed/in2out/slowpath/icmp': 0, + '/nat44-ed/in2out/slowpath/drops': 0, + '/nat44-ed/in2out/fastpath/tcp': 0, + '/nat44-ed/in2out/fastpath/udp': 0, + '/nat44-ed/in2out/fastpath/icmp': 0, + '/nat44-ed/in2out/fastpath/drops': 0, + '/nat44-ed/in2out/slowpath/tcp': 0, + '/nat44-ed/in2out/slowpath/udp': 0, + '/nat44-ed/in2out/slowpath/icmp': 0, + '/nat44-ed/in2out/slowpath/drops': 0, + } + for pg in cls.pg_interfaces + }) + def get_err_counter(self, path): return self.statistics.get_err_counter(path) @@ -2622,37 +2645,41 @@ class TestNAT44EDMW(TestNAT44ED): self.nat_add_outside_interface(self.pg1) # in2out and no NAT addresses added - err_old = self.statistics.get_err_counter( - '/err/nat44-ed-in2out-slowpath/out of ports') - pkts = self.create_stream_in(self.pg0, self.pg1) - self.pg0.add_stream(pkts) - self.pg_enable_capture(self.pg_interfaces) - self.pg_start() - self.pg1.get_capture(0, timeout=1) - err_new = self.statistics.get_err_counter( - '/err/nat44-ed-in2out-slowpath/out of ports') - - self.assertEqual(err_new - err_old, len(pkts)) + self.send_and_assert_no_replies( + self.pg0, pkts, msg="i2o pkts", + stats_diff=self.no_diff | { + "err": { + '/err/nat44-ed-in2out-slowpath/out of ports': len(pkts), + }, + self.pg0.sw_if_index: { + '/nat44-ed/in2out/slowpath/drops': len(pkts), + }, + } + ) # in2out after NAT addresses added self.nat_add_address(self.nat_addr) - err_old = self.statistics.get_err_counter( - '/err/nat44-ed-in2out-slowpath/out of ports') - - pkts = self.create_stream_in(self.pg0, self.pg1) - self.pg0.add_stream(pkts) - self.pg_enable_capture(self.pg_interfaces) - self.pg_start() - capture = self.pg1.get_capture(len(pkts)) - self.verify_capture_out(capture, ignore_port=True) - - err_new = self.statistics.get_err_counter( - '/err/nat44-ed-in2out-slowpath/out of ports') - - self.assertEqual(err_new, err_old) + tcpn, udpn, icmpn = (sum(x) for x in + zip(*((TCP in p, UDP in p, ICMP in p) + for p in pkts))) + + self.send_and_expect( + self.pg0, pkts, self.pg1, msg="i2o pkts", + stats_diff=self.no_diff | { + "err": { + '/err/nat44-ed-in2out-slowpath/out of ports': 0, + }, + self.pg0.sw_if_index: { + '/nat44-ed/in2out/slowpath/drops': 0, + '/nat44-ed/in2out/slowpath/tcp': tcpn, + '/nat44-ed/in2out/slowpath/udp': udpn, + '/nat44-ed/in2out/slowpath/icmp': icmpn, + }, + } + ) def test_unknown_proto(self): """ NAT44ED translate packet with unknown protocol """ |