2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2018-06-18 13:01:59 +03:00
|
|
|
|
|
|
|
import unittest
|
2023-08-31 00:47:44 -04:00
|
|
|
from framework import VppTestCase
|
|
|
|
from asfframework import VppTestRunner
|
2018-06-18 13:01:59 +03:00
|
|
|
from template_bd import BridgeDomain
|
|
|
|
|
|
|
|
from scapy.layers.l2 import Ether
|
2020-12-01 02:39:21 +07:00
|
|
|
from scapy.packet import Raw, bind_layers
|
2020-05-21 16:34:17 +03:00
|
|
|
from scapy.layers.inet6 import IP, IPv6, UDP
|
2018-06-18 13:01:59 +03:00
|
|
|
from scapy.layers.vxlan import VXLAN
|
2020-05-02 22:34:40 -04:00
|
|
|
|
|
|
|
import util
|
2018-05-01 05:17:55 -07:00
|
|
|
from vpp_ip_route import VppIpRoute, VppRoutePath
|
2020-03-02 13:55:31 +01:00
|
|
|
from vpp_vxlan_tunnel import VppVxlanTunnel
|
2018-05-01 05:17:55 -07:00
|
|
|
from vpp_ip import INVALID_INDEX
|
2024-03-11 10:38:46 +00:00
|
|
|
from config import config
|
2018-06-18 13:01:59 +03:00
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf("vxlan" in config.excluded_plugins, "Exclude VXLAN plugin tests")
|
2018-07-08 08:15:56 +03:00
|
|
|
class TestVxlan6(BridgeDomain, VppTestCase):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""VXLAN over IPv6 Test Case"""
|
2018-06-18 13:01:59 +03:00
|
|
|
|
|
|
|
def __init__(self, *args):
|
|
|
|
BridgeDomain.__init__(self)
|
|
|
|
VppTestCase.__init__(self, *args)
|
|
|
|
|
|
|
|
def encapsulate(self, pkt, vni):
|
|
|
|
"""
|
|
|
|
Encapsulate the original payload frame by adding VXLAN header with its
|
|
|
|
UDP, IP and Ethernet fields
|
|
|
|
"""
|
2022-04-26 19:02:15 +02:00
|
|
|
return (
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IPv6(src=self.pg0.remote_ip6, dst=self.pg0.local_ip6)
|
|
|
|
/ UDP(sport=self.dport, dport=self.dport, chksum=0)
|
|
|
|
/ VXLAN(vni=vni, flags=self.flags)
|
|
|
|
/ pkt
|
|
|
|
)
|
2018-06-18 13:01:59 +03:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def ip_range(cls, s, e):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""range of remote ip's"""
|
|
|
|
tmp = cls.pg0.remote_ip6.rsplit(":", 1)[0]
|
2018-06-18 13:01:59 +03:00
|
|
|
return ("%s:%x" % (tmp, i) for i in range(s, e))
|
|
|
|
|
|
|
|
def encap_mcast(self, pkt, src_ip, src_mac, vni):
|
|
|
|
"""
|
|
|
|
Encapsulate the original payload frame by adding VXLAN header with its
|
|
|
|
UDP, IP and Ethernet fields
|
|
|
|
"""
|
2022-04-26 19:02:15 +02:00
|
|
|
return (
|
|
|
|
Ether(src=src_mac, dst=self.mcast_mac)
|
|
|
|
/ IPv6(src=src_ip, dst=self.mcast_ip6)
|
|
|
|
/ UDP(sport=self.dport, dport=self.dport, chksum=0)
|
|
|
|
/ VXLAN(vni=vni, flags=self.flags)
|
|
|
|
/ pkt
|
|
|
|
)
|
2018-06-18 13:01:59 +03:00
|
|
|
|
|
|
|
def decapsulate(self, pkt):
|
|
|
|
"""
|
|
|
|
Decapsulate the original payload frame by removing VXLAN header
|
|
|
|
"""
|
|
|
|
# check if is set I flag
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(pkt[VXLAN].flags, int("0x8", 16))
|
2018-06-18 13:01:59 +03:00
|
|
|
return pkt[VXLAN].payload
|
|
|
|
|
|
|
|
# Method for checking VXLAN encapsulation.
|
|
|
|
#
|
|
|
|
def check_encapsulation(self, pkt, vni, local_only=False, mcast_pkt=False):
|
|
|
|
# TODO: add error messages
|
|
|
|
# Verify source MAC is VPP_MAC and destination MAC is MY_MAC resolved
|
|
|
|
# by VPP using ARP.
|
|
|
|
self.assertEqual(pkt[Ether].src, self.pg0.local_mac)
|
|
|
|
if not local_only:
|
|
|
|
if not mcast_pkt:
|
|
|
|
self.assertEqual(pkt[Ether].dst, self.pg0.remote_mac)
|
|
|
|
else:
|
|
|
|
self.assertEqual(pkt[Ether].dst, type(self).mcast_mac)
|
|
|
|
# Verify VXLAN tunnel source IP is VPP_IP and destination IP is MY_IP.
|
|
|
|
self.assertEqual(pkt[IPv6].src, self.pg0.local_ip6)
|
|
|
|
if not local_only:
|
|
|
|
if not mcast_pkt:
|
|
|
|
self.assertEqual(pkt[IPv6].dst, self.pg0.remote_ip6)
|
|
|
|
else:
|
|
|
|
self.assertEqual(pkt[IPv6].dst, type(self).mcast_ip6)
|
|
|
|
# Verify UDP destination port is VXLAN 4789, source UDP port could be
|
|
|
|
# arbitrary.
|
2020-12-01 02:39:21 +07:00
|
|
|
self.assertEqual(pkt[UDP].dport, self.dport)
|
2020-05-21 16:34:17 +03:00
|
|
|
# Verify UDP checksum
|
|
|
|
self.assert_udp_checksum_valid(pkt, ignore_zero_checksum=False)
|
2018-06-18 13:01:59 +03:00
|
|
|
# Verify VNI
|
|
|
|
self.assertEqual(pkt[VXLAN].vni, vni)
|
|
|
|
|
|
|
|
@classmethod
|
2020-12-01 02:39:21 +07:00
|
|
|
def create_vxlan_flood_test_bd(cls, vni, n_ucast_tunnels, port):
|
2018-06-18 13:01:59 +03:00
|
|
|
# Create 10 ucast vxlan tunnels under bd
|
|
|
|
start = 10
|
|
|
|
end = start + n_ucast_tunnels
|
|
|
|
for dest_ip6 in cls.ip_range(start, end):
|
|
|
|
# add host route so dest ip will not be resolved
|
2022-04-26 19:02:15 +02:00
|
|
|
rip = VppIpRoute(
|
|
|
|
cls,
|
|
|
|
dest_ip6,
|
|
|
|
128,
|
|
|
|
[VppRoutePath(cls.pg0.remote_ip6, INVALID_INDEX)],
|
|
|
|
register=False,
|
|
|
|
)
|
2018-05-01 05:17:55 -07:00
|
|
|
rip.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppVxlanTunnel(
|
|
|
|
cls,
|
|
|
|
src=cls.pg0.local_ip6,
|
|
|
|
src_port=port,
|
|
|
|
dst_port=port,
|
|
|
|
dst=dest_ip6,
|
|
|
|
vni=vni,
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
r.add_vpp_config()
|
2018-05-01 05:17:55 -07:00
|
|
|
cls.vapi.sw_interface_set_l2_bridge(r.sw_if_index, bd_id=vni)
|
2018-06-18 13:01:59 +03:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def add_mcast_tunnels_load(cls):
|
|
|
|
cls.add_del_mcast_tunnels_load(is_add=1)
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def del_mcast_tunnels_load(cls):
|
|
|
|
cls.add_del_mcast_tunnels_load(is_add=0)
|
|
|
|
|
|
|
|
# Class method to start the VXLAN test case.
|
|
|
|
# Overrides setUpClass method in VppTestCase class.
|
|
|
|
# Python try..except statement is used to ensure that the tear down of
|
|
|
|
# the class will be executed even if exception is raised.
|
|
|
|
# @param cls The class pointer.
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
2018-07-08 08:15:56 +03:00
|
|
|
super(TestVxlan6, cls).setUpClass()
|
2018-06-18 13:01:59 +03:00
|
|
|
|
|
|
|
try:
|
|
|
|
cls.flags = 0x8
|
|
|
|
|
|
|
|
# Create 2 pg interfaces.
|
|
|
|
cls.create_pg_interfaces(range(4))
|
|
|
|
for pg in cls.pg_interfaces:
|
|
|
|
pg.admin_up()
|
|
|
|
|
2020-05-02 22:34:40 -04:00
|
|
|
# Configure IPv6 addresses on VPP pg0.
|
2018-06-18 13:01:59 +03:00
|
|
|
cls.pg0.config_ip6()
|
|
|
|
|
|
|
|
# Resolve MAC address for VPP's IP address on pg0.
|
|
|
|
cls.pg0.resolve_ndp()
|
|
|
|
|
2020-05-02 22:34:40 -04:00
|
|
|
# Our Multicast address
|
2022-04-26 19:02:15 +02:00
|
|
|
cls.mcast_ip6 = "ff0e::1"
|
2020-05-02 22:34:40 -04:00
|
|
|
cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip6)
|
2018-06-18 13:01:59 +03:00
|
|
|
except Exception:
|
2018-07-08 08:15:56 +03:00
|
|
|
super(TestVxlan6, cls).tearDownClass()
|
2018-06-18 13:01:59 +03:00
|
|
|
raise
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestVxlan6, cls).tearDownClass()
|
|
|
|
|
2020-03-02 13:55:31 +01:00
|
|
|
def setUp(self):
|
|
|
|
super(TestVxlan6, self).setUp()
|
2020-12-01 02:39:21 +07:00
|
|
|
|
|
|
|
def createVxLANInterfaces(self, port=4789):
|
2020-03-02 13:55:31 +01:00
|
|
|
# Create VXLAN VTEP on VPP pg0, and put vxlan_tunnel0 and pg1
|
|
|
|
# into BD.
|
2020-12-01 02:39:21 +07:00
|
|
|
self.dport = port
|
|
|
|
|
2020-04-03 07:46:28 +00:00
|
|
|
self.single_tunnel_vni = 0x12345
|
2020-03-02 13:55:31 +01:00
|
|
|
self.single_tunnel_bd = 1
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppVxlanTunnel(
|
|
|
|
self,
|
|
|
|
src=self.pg0.local_ip6,
|
|
|
|
dst=self.pg0.remote_ip6,
|
|
|
|
src_port=self.dport,
|
|
|
|
dst_port=self.dport,
|
|
|
|
vni=self.single_tunnel_vni,
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
r.add_vpp_config()
|
|
|
|
self.vapi.sw_interface_set_l2_bridge(
|
2022-04-26 19:02:15 +02:00
|
|
|
rx_sw_if_index=r.sw_if_index, bd_id=self.single_tunnel_bd
|
|
|
|
)
|
|
|
|
self.vapi.sw_interface_set_l2_bridge(
|
|
|
|
rx_sw_if_index=self.pg1.sw_if_index, bd_id=self.single_tunnel_bd
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
|
|
|
|
# Setup vni 2 to test multicast flooding
|
|
|
|
self.n_ucast_tunnels = 10
|
|
|
|
self.mcast_flood_bd = 2
|
2022-04-26 19:02:15 +02:00
|
|
|
self.create_vxlan_flood_test_bd(
|
|
|
|
self.mcast_flood_bd, self.n_ucast_tunnels, self.dport
|
|
|
|
)
|
|
|
|
r = VppVxlanTunnel(
|
|
|
|
self,
|
|
|
|
src=self.pg0.local_ip6,
|
|
|
|
dst=self.mcast_ip6,
|
|
|
|
src_port=self.dport,
|
|
|
|
dst_port=self.dport,
|
|
|
|
mcast_sw_if_index=1,
|
|
|
|
vni=self.mcast_flood_bd,
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
r.add_vpp_config()
|
|
|
|
self.vapi.sw_interface_set_l2_bridge(
|
2022-04-26 19:02:15 +02:00
|
|
|
rx_sw_if_index=r.sw_if_index, bd_id=self.mcast_flood_bd
|
|
|
|
)
|
|
|
|
self.vapi.sw_interface_set_l2_bridge(
|
|
|
|
rx_sw_if_index=self.pg2.sw_if_index, bd_id=self.mcast_flood_bd
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
|
|
|
|
# Setup vni 3 to test unicast flooding
|
|
|
|
self.ucast_flood_bd = 3
|
2022-04-26 19:02:15 +02:00
|
|
|
self.create_vxlan_flood_test_bd(
|
|
|
|
self.ucast_flood_bd, self.n_ucast_tunnels, self.dport
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
self.vapi.sw_interface_set_l2_bridge(
|
2022-04-26 19:02:15 +02:00
|
|
|
rx_sw_if_index=self.pg3.sw_if_index, bd_id=self.ucast_flood_bd
|
|
|
|
)
|
2020-03-02 13:55:31 +01:00
|
|
|
|
2020-12-01 02:39:21 +07:00
|
|
|
# Set scapy listen custom port for VxLAN
|
|
|
|
bind_layers(UDP, VXLAN, dport=self.dport)
|
|
|
|
|
2018-06-18 13:01:59 +03:00
|
|
|
# Method to define VPP actions before tear down of the test case.
|
|
|
|
# Overrides tearDown method in VppTestCase class.
|
|
|
|
# @param self The object pointer.
|
|
|
|
def tearDown(self):
|
2018-07-08 08:15:56 +03:00
|
|
|
super(TestVxlan6, self).tearDown()
|
2019-03-13 09:23:05 -07:00
|
|
|
|
|
|
|
def show_commands_at_teardown(self):
|
|
|
|
self.logger.info(self.vapi.cli("show bridge-domain 1 detail"))
|
|
|
|
self.logger.info(self.vapi.cli("show bridge-domain 2 detail"))
|
|
|
|
self.logger.info(self.vapi.cli("show bridge-domain 3 detail"))
|
|
|
|
self.logger.info(self.vapi.cli("show vxlan tunnel"))
|
2018-06-18 13:01:59 +03:00
|
|
|
|
2020-12-01 02:39:21 +07:00
|
|
|
def encap_fragmented_packet(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
frame = (
|
|
|
|
Ether(src="00:00:00:00:00:02", dst="00:00:00:00:00:01")
|
|
|
|
/ IP(src="4.3.2.1", dst="1.2.3.4")
|
|
|
|
/ UDP(sport=20000, dport=10000)
|
|
|
|
/ Raw(b"\xa5" * 1000)
|
|
|
|
)
|
2020-05-21 16:34:17 +03:00
|
|
|
|
|
|
|
frags = util.fragment_rfc791(frame, 400)
|
|
|
|
|
|
|
|
self.pg1.add_stream(frags)
|
|
|
|
|
|
|
|
self.pg0.enable_capture()
|
|
|
|
|
|
|
|
self.pg_start()
|
|
|
|
|
|
|
|
out = self.pg0.get_capture(3)
|
|
|
|
|
|
|
|
payload = []
|
|
|
|
for pkt in out:
|
|
|
|
payload.append(self.decapsulate(pkt))
|
|
|
|
self.check_encapsulation(pkt, self.single_tunnel_vni)
|
|
|
|
|
|
|
|
reassembled = util.reassemble4(payload)
|
|
|
|
|
2024-07-23 01:28:19 -04:00
|
|
|
self.assertEqual(Ether(bytes(frame))[IP], reassembled[IP])
|
2020-05-21 16:34:17 +03:00
|
|
|
|
2020-12-01 02:39:21 +07:00
|
|
|
"""
|
|
|
|
Tests with default port (4789)
|
|
|
|
"""
|
2022-04-26 19:02:15 +02:00
|
|
|
|
2020-12-01 02:39:21 +07:00
|
|
|
def test_decap(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Decapsulation test
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlan6, self).test_decap()
|
|
|
|
|
|
|
|
def test_encap(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Encapsulation test
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlan6, self).test_encap()
|
|
|
|
|
|
|
|
def test_encap_fragmented_packet(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Encapsulation test send fragments from pg1
|
2020-12-01 02:39:21 +07:00
|
|
|
Verify receipt of encapsulated frames on pg0
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
self.encap_fragmented_packet()
|
|
|
|
|
|
|
|
def test_ucast_flood(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Unicast flood test
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlan6, self).test_ucast_flood()
|
|
|
|
|
|
|
|
def test_mcast_flood(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Multicast flood test
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlan6, self).test_mcast_flood()
|
|
|
|
|
|
|
|
def test_mcast_rcv(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Multicast receive test
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlan6, self).test_mcast_rcv()
|
|
|
|
|
|
|
|
"""
|
|
|
|
Tests with custom port
|
|
|
|
"""
|
2022-04-26 19:02:15 +02:00
|
|
|
|
2020-12-01 02:39:21 +07:00
|
|
|
def test_decap_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Decapsulation test custom port
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1111)
|
|
|
|
super(TestVxlan6, self).test_decap()
|
|
|
|
|
|
|
|
def test_encap_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Encapsulation test custom port
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1111)
|
|
|
|
super(TestVxlan6, self).test_encap()
|
|
|
|
|
|
|
|
def test_ucast_flood_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Unicast flood test custom port
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1111)
|
|
|
|
super(TestVxlan6, self).test_ucast_flood()
|
|
|
|
|
|
|
|
def test_mcast_flood_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Multicast flood test custom port
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1111)
|
|
|
|
super(TestVxlan6, self).test_mcast_flood()
|
|
|
|
|
|
|
|
def test_mcast_rcv_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Multicast receive test custom port
|
2020-12-01 02:39:21 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1111)
|
|
|
|
super(TestVxlan6, self).test_mcast_rcv()
|
|
|
|
|
2018-06-18 13:01:59 +03:00
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2018-06-18 13:01:59 +03:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|