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:
Ivan Ivanets
committed by
Dave Wallace
parent
38e94c3461
commit
b2b87e4819
@ -26,7 +26,7 @@ from struct import pack, unpack
|
|||||||
|
|
||||||
import scapy.compat
|
import scapy.compat
|
||||||
from scapy.packet import Raw, Packet
|
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_sub_interface import VppSubInterface
|
||||||
from vpp_lo_interface import VppLoInterface
|
from vpp_lo_interface import VppLoInterface
|
||||||
from vpp_bvi_interface import VppBviInterface
|
from vpp_bvi_interface import VppBviInterface
|
||||||
@ -547,6 +547,7 @@ class VppTestCase(VppAsfTestCase):
|
|||||||
trace=True,
|
trace=True,
|
||||||
msg=None,
|
msg=None,
|
||||||
stats_diff=None,
|
stats_diff=None,
|
||||||
|
filter_out_fn=is_ipv6_misc,
|
||||||
):
|
):
|
||||||
if stats_diff:
|
if stats_diff:
|
||||||
stats_snapshot = self.snapshot_stats(stats_diff)
|
stats_snapshot = self.snapshot_stats(stats_diff)
|
||||||
@ -554,7 +555,7 @@ class VppTestCase(VppAsfTestCase):
|
|||||||
if not n_rx:
|
if not n_rx:
|
||||||
n_rx = 1 if isinstance(pkts, Packet) else len(pkts)
|
n_rx = 1 if isinstance(pkts, Packet) else len(pkts)
|
||||||
self.pg_send(intf, pkts, worker=worker, trace=trace)
|
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 trace:
|
||||||
if msg:
|
if msg:
|
||||||
self.logger.debug(f"send_and_expect: {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
|
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(
|
@unittest.skipIf(
|
||||||
"wireguard" in config.excluded_plugins, "Exclude Wireguard plugin tests"
|
"wireguard" in config.excluded_plugins, "Exclude Wireguard plugin tests"
|
||||||
)
|
)
|
||||||
@ -578,15 +582,14 @@ class TestWg(VppTestCase):
|
|||||||
):
|
):
|
||||||
self.pg_send(intf, pkts)
|
self.pg_send(intf, pkts)
|
||||||
|
|
||||||
def _filter_out_fn(p):
|
|
||||||
return is_ipv6_misc(p) or is_handshake_init(p)
|
|
||||||
|
|
||||||
try:
|
try:
|
||||||
if not timeout:
|
if not timeout:
|
||||||
timeout = 1
|
timeout = 1
|
||||||
for i in self.pg_interfaces:
|
for i in self.pg_interfaces:
|
||||||
i.assert_nothing_captured(
|
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
|
timeout = 0.1
|
||||||
finally:
|
finally:
|
||||||
@ -681,7 +684,12 @@ class TestWg(VppTestCase):
|
|||||||
# prepare and send a handshake initiation
|
# prepare and send a handshake initiation
|
||||||
# expect the peer to send a handshake response
|
# expect the peer to send a handshake response
|
||||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
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:
|
else:
|
||||||
# wait for the peer to send a handshake initiation
|
# wait for the peer to send a handshake initiation
|
||||||
rxs = self.pg1.get_capture(1, timeout=2)
|
rxs = self.pg1.get_capture(1, timeout=2)
|
||||||
@ -707,7 +715,7 @@ class TestWg(VppTestCase):
|
|||||||
self.pg_send(self.pg1, [cookie])
|
self.pg_send(self.pg1, [cookie])
|
||||||
|
|
||||||
# wait for the peer to send a handshake initiation with mac2 set
|
# 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
|
# verify the initiation and its mac2
|
||||||
peer_1.consume_init(rxs[0], self.pg1, is_ip6=is_ip6, is_mac2=True)
|
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
|
# expect a cookie reply
|
||||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
||||||
init.mac2 = b"1234567890"
|
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)
|
peer_1.consume_cookie(rxs[0], is_ip6=is_ip6)
|
||||||
|
|
||||||
# prepare and send a handshake initiation with correct mac2
|
# prepare and send a handshake initiation with correct mac2
|
||||||
# expect a handshake response
|
# expect a handshake response
|
||||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
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
|
# verify the response
|
||||||
peer_1.consume_response(rxs[0], is_ip6=is_ip6)
|
peer_1.consume_response(rxs[0], is_ip6=is_ip6)
|
||||||
@ -858,7 +870,9 @@ class TestWg(VppTestCase):
|
|||||||
# expect a cookie reply
|
# expect a cookie reply
|
||||||
init = peer_1.mk_handshake(self.pg1)
|
init = peer_1.mk_handshake(self.pg1)
|
||||||
init.mac2 = b"1234567890"
|
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])
|
peer_1.consume_cookie(rxs[0])
|
||||||
|
|
||||||
# sleep till the end of being under load
|
# sleep till the end of being under load
|
||||||
@ -869,7 +883,9 @@ class TestWg(VppTestCase):
|
|||||||
# expect a handshake response
|
# expect a handshake response
|
||||||
init = peer_1.mk_handshake(self.pg1)
|
init = peer_1.mk_handshake(self.pg1)
|
||||||
init.mac2 = b"1234567890"
|
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
|
# verify the response
|
||||||
peer_1.consume_response(rxs[0])
|
peer_1.consume_response(rxs[0])
|
||||||
@ -1017,7 +1033,12 @@ class TestWg(VppTestCase):
|
|||||||
# (peer_2) prepare and send a handshake initiation
|
# (peer_2) prepare and send a handshake initiation
|
||||||
# expect a cookie reply
|
# expect a cookie reply
|
||||||
init_2 = peer_2.mk_handshake(self.pg1)
|
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_2.consume_cookie(rxs[0])
|
||||||
|
|
||||||
# (peer_1) (peer_2) prepare and send a bunch of handshake initiations with correct mac2
|
# (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
|
# prepare and send a handshake initiation
|
||||||
# expect a handshake response sent to the new endpoint
|
# expect a handshake response sent to the new endpoint
|
||||||
init = peer_1.mk_handshake(self.pg1, is_ip6=is_ip6)
|
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
|
# verify the response
|
||||||
peer_1.consume_response(rxs[0], is_ip6=is_ip6)
|
peer_1.consume_response(rxs[0], is_ip6=is_ip6)
|
||||||
self.assertTrue(peer_1.query_vpp_config())
|
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
|
# send a valid handsake init for which we expect a response
|
||||||
p = peer_1.mk_handshake(self.pg1)
|
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])
|
peer_1.consume_response(rx[0])
|
||||||
|
|
||||||
@ -1667,7 +1695,9 @@ class TestWg(VppTestCase):
|
|||||||
# send a valid handsake init for which we expect a response
|
# send a valid handsake init for which we expect a response
|
||||||
p = peer_1.mk_handshake(self.pg1, True)
|
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)
|
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
|
# send a valid handsake init for which we expect a response
|
||||||
p = peer_1.mk_handshake(self.pg1)
|
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])
|
peer_1.consume_response(rx[0])
|
||||||
|
|
||||||
@ -1947,7 +1979,9 @@ class TestWg(VppTestCase):
|
|||||||
# send a valid handsake init for which we expect a response
|
# send a valid handsake init for which we expect a response
|
||||||
p = peer_1.mk_handshake(self.pg1, True)
|
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)
|
peer_1.consume_response(rx[0], True)
|
||||||
|
|
||||||
@ -2172,7 +2206,12 @@ class TestWg(VppTestCase):
|
|||||||
for i in range(NUM_IFS):
|
for i in range(NUM_IFS):
|
||||||
# send a valid handsake init for which we expect a response
|
# send a valid handsake init for which we expect a response
|
||||||
p = peers[i].mk_handshake(self.pg1)
|
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])
|
peers[i].consume_response(rx[0])
|
||||||
|
|
||||||
# send a data packet from the peer through the tunnel
|
# send a data packet from the peer through the tunnel
|
||||||
@ -2334,7 +2373,12 @@ class TestWg(VppTestCase):
|
|||||||
for i in range(NUM_PEERS):
|
for i in range(NUM_PEERS):
|
||||||
# wg0 peers: send a valid handsake init for which we expect a response
|
# wg0 peers: send a valid handsake init for which we expect a response
|
||||||
p = peers_0[i].mk_handshake(self.pg1)
|
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])
|
peers_0[i].consume_response(rx[0])
|
||||||
|
|
||||||
# wg0 peers: send empty packet, it means successful connection (WIREGUARD_PEER_ESTABLISHED)
|
# 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
|
# wg1 peers: send a valid handsake init for which we expect a response
|
||||||
p = peers_1[i].mk_handshake(self.pg2)
|
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])
|
peers_1[i].consume_response(rx[0])
|
||||||
|
|
||||||
# wg1 peers: send empty packet, it means successful connection (WIREGUARD_PEER_ESTABLISHED)
|
# wg1 peers: send empty packet, it means successful connection (WIREGUARD_PEER_ESTABLISHED)
|
||||||
|
Reference in New Issue
Block a user