tests: fix wireguard test case failures
Type: test There are random failures in the wireguard test cases that are not related to concurrency issues. The root cause is a retry of the handshake initiation after (REKEY_TIMEOUT + JITTER) ms, where JITTER is a random value between 0 and 333 ms. Solution: Add a filter parameter for the `send_and_expect` method of the vpptestcase. This filter allows for excluding unexpected handshake initiation packets when the responder sends two packets (with `message_type = 1` and `message_type = 2`),while only a single packet (with `message_type = 2`) is expected. Change-Id: I62816931fc1b85e2202f3d36eb6c2a23714644d5 Signed-off-by: Ivan Ivanets <iivanets@cisco.com>
This commit is contained in:
parent
38e94c3461
commit
b2b87e4819
@ -26,7 +26,7 @@ from struct import pack, unpack
|
||||
|
||||
import scapy.compat
|
||||
from scapy.packet import Raw, Packet
|
||||
from vpp_pg_interface import VppPGInterface
|
||||
from vpp_pg_interface import VppPGInterface, is_ipv6_misc
|
||||
from vpp_sub_interface import VppSubInterface
|
||||
from vpp_lo_interface import VppLoInterface
|
||||
from vpp_bvi_interface import VppBviInterface
|
||||
@ -547,6 +547,7 @@ class VppTestCase(VppAsfTestCase):
|
||||
trace=True,
|
||||
msg=None,
|
||||
stats_diff=None,
|
||||
filter_out_fn=is_ipv6_misc,
|
||||
):
|
||||
if stats_diff:
|
||||
stats_snapshot = self.snapshot_stats(stats_diff)
|
||||
@ -554,7 +555,7 @@ class VppTestCase(VppAsfTestCase):
|
||||
if not n_rx:
|
||||
n_rx = 1 if isinstance(pkts, Packet) else len(pkts)
|
||||
self.pg_send(intf, pkts, worker=worker, trace=trace)
|
||||
rx = output.get_capture(n_rx)
|
||||
rx = output.get_capture(n_rx, filter_out_fn=filter_out_fn)
|
||||
if trace:
|
||||
if msg:
|
||||
self.logger.debug(f"send_and_expect: {msg}")
|
||||
|
@ -504,6 +504,10 @@ def is_handshake_init(p):
|
||||
return wg_p[Wireguard].message_type == 1
|
||||
|
||||
|
||||
def filter_out_misc_and_handshake_init(p):
|
||||
return is_ipv6_misc(p) or is_handshake_init(p)
|
||||
|
||||
|
||||
@unittest.skipIf(
|
||||
"wireguard" in config.excluded_plugins, "Exclude Wireguard plugin tests"
|
||||
)
|
||||
@ -578,15 +582,14 @@ class TestWg(VppTestCase):
|
||||
):
|
||||
self.pg_send(intf, pkts)
|
||||
|
||||
def _filter_out_fn(p):
|
||||
return is_ipv6_misc(p) or is_handshake_init(p)
|
||||
|
||||
try:
|
||||
if not timeout:
|
||||
timeout = 1
|
||||
for i in self.pg_interfaces:
|
||||
i.assert_nothing_captured(
|
||||
timeout=timeout, remark=remark, filter_out_fn=_filter_out_fn
|
||||
timeout=timeout,
|
||||
remark=remark,
|
||||
filter_out_fn=filter_out_misc_and_handshake_init,
|
||||
)
|
||||
timeout = 0.1
|
||||
finally:
|
||||
@ -681,7 +684,12 @@ class TestWg(VppTestCase):
|
||||
# prepare and send a handshake initiation
|
||||
# expect the peer to send a handshake response
|
||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
||||
rxs = self.send_and_expect(self.pg1, [init], self.pg1)
|
||||
rxs = self.send_and_expect(
|
||||
self.pg1,
|
||||
[init],
|
||||
self.pg1,
|
||||
filter_out_fn=filter_out_misc_and_handshake_init,
|
||||
)
|
||||
else:
|
||||
# wait for the peer to send a handshake initiation
|
||||
rxs = self.pg1.get_capture(1, timeout=2)
|
||||
@ -707,7 +715,7 @@ class TestWg(VppTestCase):
|
||||
self.pg_send(self.pg1, [cookie])
|
||||
|
||||
# wait for the peer to send a handshake initiation with mac2 set
|
||||
rxs = self.pg1.get_capture(1, timeout=6)
|
||||
rxs = self.pg1.get_capture(1, timeout=30)
|
||||
|
||||
# verify the initiation and its mac2
|
||||
peer_1.consume_init(rxs[0], self.pg1, is_ip6=is_ip6, is_mac2=True)
|
||||
@ -786,13 +794,17 @@ class TestWg(VppTestCase):
|
||||
# expect a cookie reply
|
||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
||||
init.mac2 = b"1234567890"
|
||||
rxs = self.send_and_expect(self.pg1, [init], self.pg1)
|
||||
rxs = self.send_and_expect(
|
||||
self.pg1, [init], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
peer_1.consume_cookie(rxs[0], is_ip6=is_ip6)
|
||||
|
||||
# prepare and send a handshake initiation with correct mac2
|
||||
# expect a handshake response
|
||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
||||
rxs = self.send_and_expect(self.pg1, [init], self.pg1)
|
||||
rxs = self.send_and_expect(
|
||||
self.pg1, [init], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
|
||||
# verify the response
|
||||
peer_1.consume_response(rxs[0], is_ip6=is_ip6)
|
||||
@ -858,7 +870,9 @@ class TestWg(VppTestCase):
|
||||
# expect a cookie reply
|
||||
init = peer_1.mk_handshake(self.pg1)
|
||||
init.mac2 = b"1234567890"
|
||||
rxs = self.send_and_expect(self.pg1, [init], self.pg1)
|
||||
rxs = self.send_and_expect(
|
||||
self.pg1, [init], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
peer_1.consume_cookie(rxs[0])
|
||||
|
||||
# sleep till the end of being under load
|
||||
@ -869,7 +883,9 @@ class TestWg(VppTestCase):
|
||||
# expect a handshake response
|
||||
init = peer_1.mk_handshake(self.pg1)
|
||||
init.mac2 = b"1234567890"
|
||||
rxs = self.send_and_expect(self.pg1, [init], self.pg1)
|
||||
rxs = self.send_and_expect(
|
||||
self.pg1, [init], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
|
||||
# verify the response
|
||||
peer_1.consume_response(rxs[0])
|
||||
@ -1017,7 +1033,12 @@ class TestWg(VppTestCase):
|
||||
# (peer_2) prepare and send a handshake initiation
|
||||
# expect a cookie reply
|
||||
init_2 = peer_2.mk_handshake(self.pg1)
|
||||
rxs = self.send_and_expect(self.pg1, [init_2], self.pg1)
|
||||
rxs = self.send_and_expect(
|
||||
self.pg1,
|
||||
[init_2],
|
||||
self.pg1,
|
||||
filter_out_fn=filter_out_misc_and_handshake_init,
|
||||
)
|
||||
peer_2.consume_cookie(rxs[0])
|
||||
|
||||
# (peer_1) (peer_2) prepare and send a bunch of handshake initiations with correct mac2
|
||||
@ -1118,7 +1139,12 @@ class TestWg(VppTestCase):
|
||||
# prepare and send a handshake initiation
|
||||
# expect a handshake response sent to the new endpoint
|
||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
||||
rxs = self.send_and_expect(self.pg1, [init], self.pg1)
|
||||
rxs = self.send_and_expect(
|
||||
self.pg1,
|
||||
[init],
|
||||
self.pg1,
|
||||
filter_out_fn=filter_out_misc_and_handshake_init,
|
||||
)
|
||||
# verify the response
|
||||
peer_1.consume_response(rxs[0], is_ip6=is_ip6)
|
||||
self.assertTrue(peer_1.query_vpp_config())
|
||||
@ -1506,7 +1532,9 @@ class TestWg(VppTestCase):
|
||||
# send a valid handsake init for which we expect a response
|
||||
p = peer_1.mk_handshake(self.pg1)
|
||||
|
||||
rx = self.send_and_expect(self.pg1, [p], self.pg1)
|
||||
rx = self.send_and_expect(
|
||||
self.pg1, [p], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
|
||||
peer_1.consume_response(rx[0])
|
||||
|
||||
@ -1667,7 +1695,9 @@ class TestWg(VppTestCase):
|
||||
# send a valid handsake init for which we expect a response
|
||||
p = peer_1.mk_handshake(self.pg1, True)
|
||||
|
||||
rx = self.send_and_expect(self.pg1, [p], self.pg1)
|
||||
rx = self.send_and_expect(
|
||||
self.pg1, [p], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
|
||||
peer_1.consume_response(rx[0], True)
|
||||
|
||||
@ -1808,7 +1838,9 @@ class TestWg(VppTestCase):
|
||||
# send a valid handsake init for which we expect a response
|
||||
p = peer_1.mk_handshake(self.pg1)
|
||||
|
||||
rx = self.send_and_expect(self.pg1, [p], self.pg1)
|
||||
rx = self.send_and_expect(
|
||||
self.pg1, [p], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
|
||||
peer_1.consume_response(rx[0])
|
||||
|
||||
@ -1947,7 +1979,9 @@ class TestWg(VppTestCase):
|
||||
# send a valid handsake init for which we expect a response
|
||||
p = peer_1.mk_handshake(self.pg1, True)
|
||||
|
||||
rx = self.send_and_expect(self.pg1, [p], self.pg1)
|
||||
rx = self.send_and_expect(
|
||||
self.pg1, [p], self.pg1, filter_out_fn=filter_out_misc_and_handshake_init
|
||||
)
|
||||
|
||||
peer_1.consume_response(rx[0], True)
|
||||
|
||||
@ -2172,7 +2206,12 @@ class TestWg(VppTestCase):
|
||||
for i in range(NUM_IFS):
|
||||
# send a valid handsake init for which we expect a response
|
||||
p = peers[i].mk_handshake(self.pg1)
|
||||
rx = self.send_and_expect(self.pg1, [p], self.pg1)
|
||||
rx = self.send_and_expect(
|
||||
self.pg1,
|
||||
[p],
|
||||
self.pg1,
|
||||
filter_out_fn=filter_out_misc_and_handshake_init,
|
||||
)
|
||||
peers[i].consume_response(rx[0])
|
||||
|
||||
# send a data packet from the peer through the tunnel
|
||||
@ -2334,7 +2373,12 @@ class TestWg(VppTestCase):
|
||||
for i in range(NUM_PEERS):
|
||||
# wg0 peers: send a valid handsake init for which we expect a response
|
||||
p = peers_0[i].mk_handshake(self.pg1)
|
||||
rx = self.send_and_expect(self.pg1, [p], self.pg1)
|
||||
rx = self.send_and_expect(
|
||||
self.pg1,
|
||||
[p],
|
||||
self.pg1,
|
||||
filter_out_fn=filter_out_misc_and_handshake_init,
|
||||
)
|
||||
peers_0[i].consume_response(rx[0])
|
||||
|
||||
# wg0 peers: send empty packet, it means successful connection (WIREGUARD_PEER_ESTABLISHED)
|
||||
@ -2357,7 +2401,12 @@ class TestWg(VppTestCase):
|
||||
|
||||
# wg1 peers: send a valid handsake init for which we expect a response
|
||||
p = peers_1[i].mk_handshake(self.pg2)
|
||||
rx = self.send_and_expect(self.pg2, [p], self.pg2)
|
||||
rx = self.send_and_expect(
|
||||
self.pg2,
|
||||
[p],
|
||||
self.pg2,
|
||||
filter_out_fn=filter_out_misc_and_handshake_init,
|
||||
)
|
||||
peers_1[i].consume_response(rx[0])
|
||||
|
||||
# wg1 peers: send empty packet, it means successful connection (WIREGUARD_PEER_ESTABLISHED)
|
||||
|
Loading…
x
Reference in New Issue
Block a user