from vpp_ip_route import VppIpRoute, VppRoutePath
from vpp_object import VppObject
from vpp_papi import VppEnum
-from framework import tag_fixme_ubuntu2204, tag_fixme_debian11
-from framework import is_distro_ubuntu2204, is_distro_debian11
+from framework import is_distro_ubuntu2204, is_distro_debian11, tag_fixme_vpp_debug
from framework import VppTestCase
from re import compile
import unittest
if is_ip6 is False:
self._test.assertEqual(p[IP].src, self.itf.src)
self._test.assertEqual(p[IP].dst, self.endpoint)
+ self._test.assert_packet_checksums_valid(p)
else:
self._test.assertEqual(p[IPv6].src, self.itf.src)
self._test.assertEqual(p[IPv6].dst, self.endpoint)
+ self._test.assert_packet_checksums_valid(p, False)
self._test.assertEqual(p[UDP].sport, self.itf.port)
self._test.assertEqual(p[UDP].dport, self.port)
- self._test.assert_packet_checksums_valid(p)
def consume_init(self, p, tx_itf, is_ip6=False, is_mac2=False):
self.noise.set_as_responder()
def encrypt_transport(self, p):
return self.noise.encrypt(bytes(p))
- def validate_encapped(self, rxs, tx, is_ip6=False):
+ def validate_encapped(self, rxs, tx, is_tunnel_ip6=False, is_transport_ip6=False):
for rx in rxs:
- if is_ip6 is False:
- rx = IP(self.decrypt_transport(rx, is_ip6=is_ip6))
-
+ rx = self.decrypt_transport(rx, is_tunnel_ip6)
+ if is_transport_ip6 is False:
+ rx = IP(rx)
# check the original packet is present
self._test.assertEqual(rx[IP].dst, tx[IP].dst)
self._test.assertEqual(rx[IP].ttl, tx[IP].ttl - 1)
else:
- rx = IPv6(self.decrypt_transport(rx, is_ip6=is_ip6))
-
+ rx = IPv6(rx)
# check the original packet is present
self._test.assertEqual(rx[IPv6].dst, tx[IPv6].dst)
self._test.assertEqual(rx[IPv6].hlim, tx[IPv6].hlim - 1)
return wg_p[Wireguard].message_type == 1
-@tag_fixme_ubuntu2204
-@tag_fixme_debian11
class TestWg(VppTestCase):
"""Wireguard Test Case"""
rxs = self.send_and_expect(self.pg1, [init_2], self.pg1)
peer_2.consume_cookie(rxs[0])
- # (peer_1) prepare and send a bunch of handshake initiations with correct mac2
- # expect no ratelimiting and a handshake response
+ # (peer_1) (peer_2) prepare and send a bunch of handshake initiations with correct mac2
+ # expect a handshake response and then ratelimiting
+ PEER_1_NUM_TO_REJECT = 2
+ PEER_2_NUM_TO_REJECT = 5
init_1 = peer_1.mk_handshake(self.pg1)
- txs = [init_1] * HANDSHAKE_NUM_BEFORE_RATELIMITING
- rxs = self.send_and_expect_some(self.pg1, txs, self.pg1)
- self.assertEqual(
- self.base_ratelimited4_err,
- self.statistics.get_err_counter(self.ratelimited4_err),
- )
-
- # (peer_1) verify the response
- peer_1.consume_response(rxs[0])
- peer_1.noise_reset()
-
- # (peer_1) send another two handshake initiations with correct mac2
- # expect ratelimiting
- # (peer_2) prepare and send a handshake initiation with correct mac2
- # expect no ratelimiting and a handshake response
+ txs = [init_1] * (HANDSHAKE_NUM_BEFORE_RATELIMITING + PEER_1_NUM_TO_REJECT)
init_2 = peer_2.mk_handshake(self.pg1)
- txs = [init_1, init_2, init_1]
+ txs += [init_2] * (HANDSHAKE_NUM_BEFORE_RATELIMITING + PEER_2_NUM_TO_REJECT)
rxs = self.send_and_expect_some(self.pg1, txs, self.pg1)
- # (peer_1) verify ratelimiting
- self.assertEqual(
- self.base_ratelimited4_err + 2,
- self.statistics.get_err_counter(self.ratelimited4_err),
+ self.assertTrue(
+ self.base_ratelimited4_err + PEER_1_NUM_TO_REJECT
+ < self.statistics.get_err_counter(self.ratelimited4_err)
+ <= self.base_ratelimited4_err + PEER_1_NUM_TO_REJECT + PEER_2_NUM_TO_REJECT
)
- # (peer_2) verify the response
- peer_2.consume_response(rxs[0])
+ # (peer_1) (peer_2) verify the response
+ peer_1.consume_response(rxs[0])
+ peer_2.consume_response(rxs[1])
# clear up under load state
self.sleep(UNDER_LOAD_INTERVAL)
rxs = self.send_and_expect(self.pg0, [p], self.pg1)
# verify the data packet
- peer_1.validate_encapped(rxs, p, is_ip6=is_ip6)
+ peer_1.validate_encapped(rxs, p, is_tunnel_ip6=is_ip6, is_transport_ip6=is_ip6)
# remove configs
r1.remove_vpp_config()
self._test_wg_peer_roaming_on_data_tmpl(is_async=True, is_ip6=True)
def test_wg_peer_resp(self):
- """Send handshake response"""
+ """Send handshake response IPv4 tunnel"""
port = 12323
# Create interfaces
peer_1.remove_vpp_config()
wg0.remove_vpp_config()
+ def test_wg_peer_resp_ipv6(self):
+ """Send handshake response IPv6 tunnel"""
+ port = 12323
+
+ # Create interfaces
+ wg0 = VppWgInterface(self, self.pg1.local_ip6, port).add_vpp_config()
+ wg0.admin_up()
+ wg0.config_ip4()
+
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ peer_1 = VppWgPeer(
+ self, wg0, self.pg1.remote_ip6, port + 1, ["10.11.3.0/24"]
+ ).add_vpp_config()
+ self.assertEqual(len(self.vapi.wireguard_peers_dump()), 1)
+
+ r1 = VppIpRoute(
+ self, "10.11.3.0", 24, [VppRoutePath("10.11.3.1", wg0.sw_if_index)]
+ ).add_vpp_config()
+
+ # wait for the peer to send a handshake
+ rx = self.pg1.get_capture(1, timeout=2)
+
+ # consume the handshake in the noise protocol and
+ # generate the response
+ resp = peer_1.consume_init(rx[0], self.pg1, is_ip6=True)
+
+ # send the response, get keepalive
+ rxs = self.send_and_expect(self.pg1, [resp], self.pg1)
+
+ for rx in rxs:
+ b = peer_1.decrypt_transport(rx, True)
+ self.assertEqual(0, len(b))
+
+ # send a packets that are routed into the tunnel
+ p = (
+ Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac)
+ / IP(src=self.pg0.remote_ip4, dst="10.11.3.2")
+ / UDP(sport=555, dport=556)
+ / Raw(b"\x00" * 80)
+ )
+
+ rxs = self.send_and_expect(self.pg0, p * 2, self.pg1)
+ peer_1.validate_encapped(rxs, p, True)
+
+ # send packets into the tunnel, expect to receive them on
+ # the other side
+ p = [
+ (
+ peer_1.mk_tunnel_header(self.pg1, True)
+ / Wireguard(message_type=4, reserved_zero=0)
+ / WireguardTransport(
+ receiver_index=peer_1.sender,
+ counter=ii,
+ encrypted_encapsulated_packet=peer_1.encrypt_transport(
+ (
+ IP(src="10.11.3.1", dst=self.pg0.remote_ip4, ttl=20)
+ / UDP(sport=222, dport=223)
+ / Raw()
+ )
+ ),
+ )
+ )
+ for ii in range(255)
+ ]
+
+ rxs = self.send_and_expect(self.pg1, p, self.pg0)
+
+ for rx in rxs:
+ self.assertEqual(rx[IP].dst, self.pg0.remote_ip4)
+ self.assertEqual(rx[IP].ttl, 19)
+
+ r1.remove_vpp_config()
+ peer_1.remove_vpp_config()
+ wg0.remove_vpp_config()
+
def test_wg_peer_v4o4(self):
"""Test v4o4"""
wg0.remove_vpp_config()
wg1.remove_vpp_config()
+ def test_wg_sending_handshake_when_admin_down(self):
+ """Sending handshake when admin down"""
+ port = 12323
+
+ # create wg interface
+ wg0 = VppWgInterface(self, self.pg1.local_ip4, port).add_vpp_config()
+ wg0.config_ip4()
-@tag_fixme_ubuntu2204
-@tag_fixme_debian11
+ # create a peer
+ peer_1 = VppWgPeer(
+ self, wg0, self.pg1.remote_ip4, port + 1, ["10.11.3.0/24"]
+ ).add_vpp_config()
+ self.assertEqual(len(self.vapi.wireguard_peers_dump()), 1)
+
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ # wait for the peer to send a handshake initiation
+ # expect no handshakes
+ for i in range(2):
+ self.pg1.assert_nothing_captured(remark="handshake packet(s) sent")
+
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ # administratively enable the wg interface
+ # expect the peer to send a handshake initiation
+ wg0.admin_up()
+ rxs = self.pg1.get_capture(1, timeout=2)
+ peer_1.consume_init(rxs[0], self.pg1)
+
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ # administratively disable the wg interface
+ # expect no handshakes
+ wg0.admin_down()
+ for i in range(6):
+ self.pg1.assert_nothing_captured(remark="handshake packet(s) sent")
+
+ # remove configs
+ peer_1.remove_vpp_config()
+ wg0.remove_vpp_config()
+
+ def test_wg_sending_data_when_admin_down(self):
+ """Sending data when admin down"""
+ port = 12323
+
+ # create wg interface
+ wg0 = VppWgInterface(self, self.pg1.local_ip4, port).add_vpp_config()
+ wg0.admin_up()
+ wg0.config_ip4()
+
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ # create a peer
+ peer_1 = VppWgPeer(
+ self, wg0, self.pg1.remote_ip4, port + 1, ["10.11.3.0/24"]
+ ).add_vpp_config()
+ self.assertEqual(len(self.vapi.wireguard_peers_dump()), 1)
+
+ # create a route to rewrite traffic into the wg interface
+ r1 = VppIpRoute(
+ self, "10.11.3.0", 24, [VppRoutePath("10.11.3.1", wg0.sw_if_index)]
+ ).add_vpp_config()
+
+ # wait for the peer to send a handshake initiation
+ rxs = self.pg1.get_capture(1, timeout=2)
+
+ # prepare and send a handshake response
+ # expect a keepalive message
+ resp = peer_1.consume_init(rxs[0], self.pg1)
+ rxs = self.send_and_expect(self.pg1, [resp], self.pg1)
+
+ # verify the keepalive message
+ b = peer_1.decrypt_transport(rxs[0])
+ self.assertEqual(0, len(b))
+
+ # prepare and send a packet that will be rewritten into the wg interface
+ # expect a data packet sent
+ p = (
+ Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac)
+ / IP(src=self.pg0.remote_ip4, dst="10.11.3.2")
+ / UDP(sport=555, dport=556)
+ / Raw()
+ )
+ rxs = self.send_and_expect(self.pg0, [p], self.pg1)
+
+ # verify the data packet
+ peer_1.validate_encapped(rxs, p)
+
+ # administratively disable the wg interface
+ wg0.admin_down()
+
+ # send a packet that will be rewritten into the wg interface
+ # expect no data packets sent
+ self.send_and_assert_no_replies(self.pg0, [p])
+
+ # administratively enable the wg interface
+ # expect the peer to send a handshake initiation
+ wg0.admin_up()
+ peer_1.noise_reset()
+ rxs = self.pg1.get_capture(1, timeout=2)
+ resp = peer_1.consume_init(rxs[0], self.pg1)
+
+ # send a packet that will be rewritten into the wg interface
+ # expect no data packets sent because the peer is not initiated
+ self.send_and_assert_no_replies(self.pg0, [p])
+ self.assertEqual(
+ self.base_kp4_err + 1, self.statistics.get_err_counter(self.kp4_error)
+ )
+
+ # send a handshake response and expect a keepalive message
+ rxs = self.send_and_expect(self.pg1, [resp], self.pg1)
+
+ # verify the keepalive message
+ b = peer_1.decrypt_transport(rxs[0])
+ self.assertEqual(0, len(b))
+
+ # send a packet that will be rewritten into the wg interface
+ # expect a data packet sent
+ rxs = self.send_and_expect(self.pg0, [p], self.pg1)
+
+ # verify the data packet
+ peer_1.validate_encapped(rxs, p)
+
+ # remove configs
+ r1.remove_vpp_config()
+ peer_1.remove_vpp_config()
+ wg0.remove_vpp_config()
+
+
+@tag_fixme_vpp_debug
class WireguardHandoffTests(TestWg):
"""Wireguard Tests in multi worker setup"""
self.assertEqual(0, len(b))
# prepare and send a packet that will be rewritten into the wg interface
- # expect a data packet sent to the new endpoint
+ # expect a data packet sent
p = (
Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac)
/ IP(src=self.pg0.remote_ip4, dst="10.11.3.2")