2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2017-05-27 20:23:09 +08:00
|
|
|
|
2020-05-02 22:34:40 -04:00
|
|
|
from util import ip4_range
|
2017-05-27 20:23:09 +08:00
|
|
|
import unittest
|
2021-05-31 16:08:53 +02:00
|
|
|
from config import config
|
2023-08-31 00:47:44 -04:00
|
|
|
from framework import VppTestCase
|
|
|
|
from asfframework import VppTestRunner
|
2017-05-27 20:23:09 +08:00
|
|
|
from template_bd import BridgeDomain
|
|
|
|
|
2019-12-13 23:39:35 +00:00
|
|
|
from scapy.layers.l2 import Ether
|
2023-08-31 00:47:44 -04:00
|
|
|
from scapy.packet import bind_layers
|
2017-05-27 20:23:09 +08:00
|
|
|
from scapy.layers.inet import IP, UDP
|
|
|
|
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
|
2021-05-28 19:09:14 +07:00
|
|
|
from vpp_vxlan_gpe_tunnel import VppVxlanGpeTunnel
|
2018-05-01 05:17:55 -07:00
|
|
|
from vpp_ip import INVALID_INDEX
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
|
2021-05-31 16:08:53 +02:00
|
|
|
@unittest.skipUnless(config.extended, "part of extended tests")
|
2017-05-27 20:23:09 +08:00
|
|
|
class TestVxlanGpe(BridgeDomain, VppTestCase):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""VXLAN-GPE Test Case"""
|
2017-05-27 20:23:09 +08: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-GPE 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)
|
|
|
|
/ IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4)
|
|
|
|
/ UDP(sport=self.dport, dport=self.dport, chksum=0)
|
|
|
|
/ VXLAN(vni=vni, flags=self.flags)
|
|
|
|
/ pkt
|
|
|
|
)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
2018-06-18 13:01:59 +03:00
|
|
|
def ip_range(self, start, end):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""range of remote ip's"""
|
2018-06-18 13:01:59 +03:00
|
|
|
return ip4_range(self.pg0.remote_ip4, start, end)
|
|
|
|
|
2017-05-27 20:23:09 +08:00
|
|
|
def encap_mcast(self, pkt, src_ip, src_mac, vni):
|
|
|
|
"""
|
|
|
|
Encapsulate the original payload frame by adding VXLAN-GPE 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)
|
|
|
|
/ IP(src=src_ip, dst=self.mcast_ip4)
|
|
|
|
/ UDP(sport=self.dport, dport=self.dport, chksum=0)
|
|
|
|
/ VXLAN(vni=vni, flags=self.flags)
|
|
|
|
/ pkt
|
|
|
|
)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
def decapsulate(self, pkt):
|
|
|
|
"""
|
|
|
|
Decapsulate the original payload frame by removing VXLAN-GPE header
|
|
|
|
"""
|
|
|
|
# check if is set I and P flag
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertEqual(pkt[VXLAN].flags, 0x0C)
|
2017-05-27 20:23:09 +08:00
|
|
|
return pkt[VXLAN].payload
|
|
|
|
|
|
|
|
# Method for checking VXLAN-GPE encapsulation.
|
|
|
|
#
|
|
|
|
def check_encapsulation(self, pkt, vni, local_only=False, mcast_pkt=False):
|
|
|
|
# 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-GPE tunnel src IP is VPP_IP and dst IP is MY_IP.
|
|
|
|
self.assertEqual(pkt[IP].src, self.pg0.local_ip4)
|
|
|
|
if not local_only:
|
|
|
|
if not mcast_pkt:
|
|
|
|
self.assertEqual(pkt[IP].dst, self.pg0.remote_ip4)
|
|
|
|
else:
|
|
|
|
self.assertEqual(pkt[IP].dst, type(self).mcast_ip4)
|
|
|
|
# Verify UDP destination port is VXLAN-GPE 4790, source UDP port
|
|
|
|
# could be arbitrary.
|
2021-05-28 19:09:14 +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)
|
2017-05-27 20:23:09 +08:00
|
|
|
# Verify VNI
|
2017-11-15 10:55:22 +01:00
|
|
|
self.assertEqual(pkt[VXLAN].vni, vni)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
@classmethod
|
2021-05-28 19:09:14 +07:00
|
|
|
def create_vxlan_gpe_flood_test_bd(cls, vni, n_ucast_tunnels, port):
|
2018-05-01 05:17:55 -07:00
|
|
|
# Create 10 ucast vxlan tunnels under bd
|
2017-05-27 20:23:09 +08:00
|
|
|
ip_range_start = 10
|
|
|
|
ip_range_end = ip_range_start + n_ucast_tunnels
|
2018-05-01 05:17:55 -07:00
|
|
|
next_hop_address = cls.pg0.remote_ip4
|
2022-04-26 19:02:15 +02:00
|
|
|
for dest_ip4 in ip4_range(next_hop_address, ip_range_start, ip_range_end):
|
2017-05-27 20:23:09 +08:00
|
|
|
# add host route so dest_ip4n will not be resolved
|
2022-04-26 19:02:15 +02:00
|
|
|
rip = VppIpRoute(
|
|
|
|
cls,
|
|
|
|
dest_ip4,
|
|
|
|
32,
|
|
|
|
[VppRoutePath(next_hop_address, 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 = VppVxlanGpeTunnel(
|
|
|
|
cls,
|
|
|
|
src_addr=cls.pg0.local_ip4,
|
|
|
|
dst_addr=dest_ip4,
|
|
|
|
src_port=port,
|
|
|
|
dst_port=port,
|
|
|
|
vni=vni,
|
|
|
|
)
|
2021-05-28 19:09:14 +07:00
|
|
|
r.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
cls.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=r.sw_if_index, bd_id=vni)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
@classmethod
|
2021-05-28 19:09:14 +07:00
|
|
|
def add_del_shared_mcast_dst_load(cls, port, is_add):
|
2017-05-27 20:23:09 +08:00
|
|
|
"""
|
|
|
|
add or del tunnels sharing the same mcast dst
|
|
|
|
to test vxlan_gpe ref_count mechanism
|
|
|
|
"""
|
|
|
|
n_shared_dst_tunnels = 20
|
|
|
|
vni_start = 1000
|
|
|
|
vni_end = vni_start + n_shared_dst_tunnels
|
|
|
|
for vni in range(vni_start, vni_end):
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppVxlanGpeTunnel(
|
|
|
|
cls,
|
|
|
|
src_addr=cls.pg0.local_ip4,
|
|
|
|
dst_addr=cls.mcast_ip4,
|
|
|
|
src_port=port,
|
|
|
|
dst_port=port,
|
|
|
|
mcast_sw_if_index=1,
|
|
|
|
vni=vni,
|
|
|
|
)
|
2021-05-28 19:09:14 +07:00
|
|
|
if is_add:
|
|
|
|
r.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
if r.sw_if_index == 0xFFFFFFFF:
|
2021-05-28 19:09:14 +07:00
|
|
|
raise ValueError("bad sw_if_index: ~0")
|
|
|
|
else:
|
|
|
|
r.remove_vpp_config()
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
@classmethod
|
2021-05-28 19:09:14 +07:00
|
|
|
def add_shared_mcast_dst_load(cls, port):
|
|
|
|
cls.add_del_shared_mcast_dst_load(port=port, is_add=1)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
@classmethod
|
2021-05-28 19:09:14 +07:00
|
|
|
def del_shared_mcast_dst_load(cls, port):
|
|
|
|
cls.add_del_shared_mcast_dst_load(port=port, is_add=0)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
@classmethod
|
2021-05-28 19:09:14 +07:00
|
|
|
def add_del_mcast_tunnels_load(cls, port, is_add):
|
2017-05-27 20:23:09 +08:00
|
|
|
"""
|
|
|
|
add or del tunnels to test vxlan_gpe stability
|
|
|
|
"""
|
|
|
|
n_distinct_dst_tunnels = 20
|
|
|
|
ip_range_start = 10
|
|
|
|
ip_range_end = ip_range_start + n_distinct_dst_tunnels
|
2022-04-26 19:02:15 +02:00
|
|
|
for dest_ip4 in ip4_range(cls.mcast_ip4, ip_range_start, ip_range_end):
|
2020-05-02 22:34:40 -04:00
|
|
|
vni = int(dest_ip4.split(".")[3])
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppVxlanGpeTunnel(
|
|
|
|
cls,
|
|
|
|
src_addr=cls.pg0.local_ip4,
|
|
|
|
dst_addr=dest_ip4,
|
|
|
|
src_port=port,
|
|
|
|
dst_port=port,
|
|
|
|
mcast_sw_if_index=1,
|
|
|
|
vni=vni,
|
|
|
|
)
|
2021-05-28 19:09:14 +07:00
|
|
|
if is_add:
|
|
|
|
r.add_vpp_config()
|
|
|
|
else:
|
|
|
|
r.remove_vpp_config()
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
@classmethod
|
2021-05-28 19:09:14 +07:00
|
|
|
def add_mcast_tunnels_load(cls, port):
|
|
|
|
cls.add_del_mcast_tunnels_load(port=port, is_add=1)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
@classmethod
|
2021-05-28 19:09:14 +07:00
|
|
|
def del_mcast_tunnels_load(cls, port):
|
|
|
|
cls.add_del_mcast_tunnels_load(port=port, is_add=0)
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
# Class method to start the VXLAN-GPE 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):
|
|
|
|
super(TestVxlanGpe, cls).setUpClass()
|
|
|
|
|
|
|
|
try:
|
2022-04-26 19:02:15 +02:00
|
|
|
cls.flags = 0x0C
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
# Create 2 pg interfaces.
|
|
|
|
cls.create_pg_interfaces(range(4))
|
|
|
|
for pg in cls.pg_interfaces:
|
|
|
|
pg.admin_up()
|
|
|
|
|
|
|
|
# Configure IPv4 addresses on VPP pg0.
|
|
|
|
cls.pg0.config_ip4()
|
|
|
|
|
|
|
|
# Resolve MAC address for VPP's IP address on pg0.
|
|
|
|
cls.pg0.resolve_arp()
|
|
|
|
|
|
|
|
# Our Multicast address
|
2022-04-26 19:02:15 +02:00
|
|
|
cls.mcast_ip4 = "239.1.1.1"
|
2020-05-02 22:34:40 -04:00
|
|
|
cls.mcast_mac = util.mcast_ip_to_mac(cls.mcast_ip4)
|
2017-05-27 20:23:09 +08:00
|
|
|
except Exception:
|
2021-05-28 19:09:14 +07:00
|
|
|
cls.tearDownClass()
|
2017-05-27 20:23:09 +08:00
|
|
|
raise
|
|
|
|
|
2019-01-25 14:05:48 -08:00
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestVxlanGpe, cls).tearDownClass()
|
|
|
|
|
2021-05-28 19:09:14 +07:00
|
|
|
def setUp(self):
|
|
|
|
super(TestVxlanGpe, self).setUp()
|
|
|
|
|
|
|
|
def createVxLANInterfaces(self, port=4790):
|
|
|
|
# Create VXLAN-GPE VTEP on VPP pg0, and put vxlan_gpe_tunnel0
|
|
|
|
# and pg1 into BD.
|
|
|
|
self.dport = port
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.single_tunnel_vni = 0xABCDE
|
2021-05-28 19:09:14 +07:00
|
|
|
self.single_tunnel_bd = 11
|
2022-04-26 19:02:15 +02:00
|
|
|
r = VppVxlanGpeTunnel(
|
|
|
|
self,
|
|
|
|
src_addr=self.pg0.local_ip4,
|
|
|
|
dst_addr=self.pg0.remote_ip4,
|
|
|
|
src_port=port,
|
|
|
|
dst_port=port,
|
|
|
|
vni=self.single_tunnel_vni,
|
|
|
|
)
|
2021-05-28 19:09:14 +07: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
|
|
|
|
)
|
2021-05-28 19:09:14 +07:00
|
|
|
|
|
|
|
# Setup vni 2 to test multicast flooding
|
|
|
|
self.n_ucast_tunnels = 10
|
|
|
|
self.mcast_flood_bd = 12
|
2022-04-26 19:02:15 +02:00
|
|
|
self.create_vxlan_gpe_flood_test_bd(
|
|
|
|
self.mcast_flood_bd, self.n_ucast_tunnels, self.dport
|
|
|
|
)
|
|
|
|
r = VppVxlanGpeTunnel(
|
|
|
|
self,
|
|
|
|
src_addr=self.pg0.local_ip4,
|
|
|
|
dst_addr=self.mcast_ip4,
|
|
|
|
src_port=port,
|
|
|
|
dst_port=port,
|
|
|
|
mcast_sw_if_index=1,
|
|
|
|
vni=self.mcast_flood_bd,
|
|
|
|
)
|
2021-05-28 19:09:14 +07: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
|
|
|
|
)
|
2021-05-28 19:09:14 +07:00
|
|
|
|
|
|
|
# Add and delete mcast tunnels to check stability
|
|
|
|
self.add_shared_mcast_dst_load(self.dport)
|
|
|
|
self.add_mcast_tunnels_load(self.dport)
|
|
|
|
self.del_shared_mcast_dst_load(self.dport)
|
|
|
|
self.del_mcast_tunnels_load(self.dport)
|
|
|
|
|
|
|
|
# Setup vni 3 to test unicast flooding
|
|
|
|
self.ucast_flood_bd = 13
|
2022-04-26 19:02:15 +02:00
|
|
|
self.create_vxlan_gpe_flood_test_bd(
|
|
|
|
self.ucast_flood_bd, self.n_ucast_tunnels, self.dport
|
|
|
|
)
|
2021-05-28 19:09:14 +07: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
|
|
|
|
)
|
2021-05-28 19:09:14 +07:00
|
|
|
|
|
|
|
# Set scapy listen custom port for VxLAN
|
|
|
|
bind_layers(UDP, VXLAN, dport=self.dport)
|
|
|
|
|
|
|
|
"""
|
|
|
|
Tests with default port (4790)
|
|
|
|
"""
|
2022-04-26 19:02:15 +02:00
|
|
|
|
2021-05-28 19:09:14 +07:00
|
|
|
def test_decap(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Decapsulation test
|
2021-05-28 19:09:14 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlanGpe, self).test_decap()
|
|
|
|
|
|
|
|
def test_encap(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Encapsulation test
|
2021-05-28 19:09:14 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlanGpe, self).test_encap()
|
|
|
|
|
|
|
|
def test_ucast_flood(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Unicast flood test
|
2021-05-28 19:09:14 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces()
|
|
|
|
super(TestVxlanGpe, self).test_ucast_flood()
|
|
|
|
|
|
|
|
"""
|
|
|
|
Tests with custom port (1112)
|
|
|
|
"""
|
2022-04-26 19:02:15 +02:00
|
|
|
|
2021-05-28 19:09:14 +07:00
|
|
|
def test_decap_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Decapsulation test custom port
|
2021-05-28 19:09:14 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1112)
|
|
|
|
super(TestVxlanGpe, self).test_decap()
|
|
|
|
|
|
|
|
def test_encap_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Encapsulation test custom port
|
2021-05-28 19:09:14 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1112)
|
|
|
|
super(TestVxlanGpe, self).test_encap()
|
|
|
|
|
|
|
|
def test_ucast_flood_custom_port(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""Unicast flood test custom port
|
2021-05-28 19:09:14 +07:00
|
|
|
from BridgeDoman
|
|
|
|
"""
|
|
|
|
self.createVxLANInterfaces(1112)
|
|
|
|
super(TestVxlanGpe, self).test_ucast_flood()
|
|
|
|
|
2017-11-17 09:18:53 +01:00
|
|
|
@unittest.skip("test disabled for vxlan-gpe")
|
|
|
|
def test_mcast_flood(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""inherited from BridgeDomain"""
|
2017-11-17 09:18:53 +01:00
|
|
|
pass
|
|
|
|
|
|
|
|
@unittest.skip("test disabled for vxlan-gpe")
|
|
|
|
def test_mcast_rcv(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""inherited from BridgeDomain"""
|
2017-11-17 09:18:53 +01:00
|
|
|
pass
|
|
|
|
|
2017-05-27 20:23:09 +08: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):
|
|
|
|
super(TestVxlanGpe, 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 11 detail"))
|
|
|
|
self.logger.info(self.vapi.cli("show bridge-domain 12 detail"))
|
|
|
|
self.logger.info(self.vapi.cli("show bridge-domain 13 detail"))
|
|
|
|
self.logger.info(self.vapi.cli("show int"))
|
|
|
|
self.logger.info(self.vapi.cli("show vxlan-gpe"))
|
|
|
|
self.logger.info(self.vapi.cli("show trace"))
|
2017-05-27 20:23:09 +08:00
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2017-05-27 20:23:09 +08:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|