2019-10-31 13:31:07 -05:00
|
|
|
#!/usr/bin/env python3
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
import unittest
|
|
|
|
|
2023-08-31 00:47:44 -04:00
|
|
|
from framework import VppTestCase
|
|
|
|
from asfframework import VppTestRunner
|
|
|
|
from vpp_ip_route import VppRoutePath
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
from scapy.packet import Raw
|
|
|
|
from scapy.layers.l2 import Ether
|
|
|
|
from scapy.layers.inet import IP, UDP
|
|
|
|
|
|
|
|
from vpp_object import VppObject
|
2024-03-11 10:38:46 +00:00
|
|
|
from config import config
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
NUM_PKTS = 67
|
|
|
|
|
|
|
|
|
|
|
|
def find_l3xc(test, sw_if_index, dump_sw_if_index=None):
|
|
|
|
if not dump_sw_if_index:
|
|
|
|
dump_sw_if_index = sw_if_index
|
|
|
|
xcs = test.vapi.l3xc_dump(dump_sw_if_index)
|
|
|
|
for xc in xcs:
|
|
|
|
if sw_if_index == xc.l3xc.sw_if_index:
|
|
|
|
return True
|
|
|
|
return False
|
|
|
|
|
|
|
|
|
|
|
|
class VppL3xc(VppObject):
|
2022-04-26 19:02:15 +02:00
|
|
|
def __init__(self, test, intf, paths, is_ip6=False):
|
2019-05-22 13:26:39 +00:00
|
|
|
self._test = test
|
|
|
|
self.intf = intf
|
|
|
|
self.is_ip6 = is_ip6
|
|
|
|
self.paths = paths
|
2018-05-01 05:17:55 -07:00
|
|
|
self.encoded_paths = []
|
|
|
|
for path in self.paths:
|
|
|
|
self.encoded_paths.append(path.encode())
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
def add_vpp_config(self):
|
|
|
|
self._test.vapi.l3xc_update(
|
|
|
|
l3xc={
|
2022-04-26 19:02:15 +02:00
|
|
|
"is_ip6": self.is_ip6,
|
|
|
|
"sw_if_index": self.intf.sw_if_index,
|
|
|
|
"n_paths": len(self.paths),
|
|
|
|
"paths": self.encoded_paths,
|
|
|
|
}
|
|
|
|
)
|
2019-05-22 13:26:39 +00:00
|
|
|
self._test.registry.register(self, self._test.logger)
|
|
|
|
|
|
|
|
def remove_vpp_config(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
self._test.vapi.l3xc_del(is_ip6=self.is_ip6, sw_if_index=self.intf.sw_if_index)
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
def query_vpp_config(self):
|
|
|
|
return find_l3xc(self._test, self.intf.sw_if_index)
|
|
|
|
|
|
|
|
def object_id(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
return "l3xc-%d" % self.intf.sw_if_index
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
|
2024-03-11 10:38:46 +00:00
|
|
|
@unittest.skipIf("l3xc" in config.excluded_plugins, "Exclude L3XC plugin tests")
|
2019-05-22 13:26:39 +00:00
|
|
|
class TestL3xc(VppTestCase):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""L3XC Test Case"""
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def setUpClass(cls):
|
|
|
|
super(TestL3xc, cls).setUpClass()
|
|
|
|
|
|
|
|
@classmethod
|
|
|
|
def tearDownClass(cls):
|
|
|
|
super(TestL3xc, cls).tearDownClass()
|
|
|
|
|
|
|
|
def setUp(self):
|
|
|
|
super(TestL3xc, self).setUp()
|
|
|
|
|
|
|
|
self.create_pg_interfaces(range(6))
|
|
|
|
|
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.admin_up()
|
|
|
|
i.config_ip4()
|
|
|
|
i.resolve_arp()
|
|
|
|
i.config_ip6()
|
|
|
|
i.resolve_ndp()
|
|
|
|
|
|
|
|
def tearDown(self):
|
|
|
|
for i in self.pg_interfaces:
|
|
|
|
i.unconfig_ip4()
|
|
|
|
i.unconfig_ip6()
|
|
|
|
i.admin_down()
|
|
|
|
super(TestL3xc, self).tearDown()
|
|
|
|
|
|
|
|
def test_l3xc4(self):
|
2022-04-26 19:02:15 +02:00
|
|
|
"""IPv4 X-Connect"""
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
#
|
|
|
|
# x-connect pg0 to pg1 and pg2 to pg3->5
|
|
|
|
#
|
2022-04-26 19:02:15 +02:00
|
|
|
l3xc_1 = VppL3xc(
|
|
|
|
self, self.pg0, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)]
|
|
|
|
)
|
2019-05-22 13:26:39 +00:00
|
|
|
l3xc_1.add_vpp_config()
|
2022-04-26 19:02:15 +02:00
|
|
|
l3xc_2 = VppL3xc(
|
|
|
|
self,
|
|
|
|
self.pg2,
|
|
|
|
[
|
|
|
|
VppRoutePath(self.pg3.remote_ip4, self.pg3.sw_if_index),
|
|
|
|
VppRoutePath(self.pg4.remote_ip4, self.pg4.sw_if_index),
|
|
|
|
VppRoutePath(self.pg5.remote_ip4, self.pg5.sw_if_index),
|
|
|
|
],
|
|
|
|
)
|
2019-05-22 13:26:39 +00:00
|
|
|
l3xc_2.add_vpp_config()
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
self.assertTrue(find_l3xc(self, self.pg2.sw_if_index, 0xFFFFFFFF))
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
self.logger.info(self.vapi.cli("sh l3xc"))
|
|
|
|
|
|
|
|
#
|
|
|
|
# fire in packets. If it's forwarded then the L3XC was successful,
|
|
|
|
# since default routing will drop it
|
|
|
|
#
|
2022-04-26 19:02:15 +02:00
|
|
|
p_1 = (
|
|
|
|
Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac)
|
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1234, dport=1234)
|
|
|
|
/ Raw(b"\xa5" * 100)
|
|
|
|
)
|
2019-05-22 13:26:39 +00:00
|
|
|
# self.send_and_expect(self.pg0, p_1*NUM_PKTS, self.pg1)
|
|
|
|
|
|
|
|
p_2 = []
|
|
|
|
for ii in range(NUM_PKTS):
|
2022-04-26 19:02:15 +02:00
|
|
|
p_2.append(
|
ethernet: check destination mac for L3 in ethernet-input node
When the NIC does not support mac filter, we rely on ethernet-input
node to do the destination mac check, ie, when the interface is in L3,
the mac address for the packet must be the mac address of the
interface where the packet arrives. This works fine in ethernet-input
node when all packets in the frame might have different interfaces, ie,
ETH_INPUT_FRAME_F_SINGLE_SW_IF_ID is not set in the frame. However,
when all packets are having the same interface,
ETH_INPUT_FRAME_F_SINGLE_SW_IF_ID is set, ethernet-input node goes
through the optimized routine eth_input_single_int -> eth_input_process_frame.
That is where dmac check has a bug when all packets in the frame are
either, ip4, ip6, or mpls without vlan tags. Because without vlan tags,
the code handles all packets in fast path and ignores dmac check.
With vlan tags, the code goes to slow path where dmac check is handled
properly.
The fix is to check if we have a bad dmac in the fast path and force the
code to go to slow path which will handle dmac check properly.
Also do a wholesale correction on all the testcases which do not use
the proper dmac when sending L3 packets.
Type: fix
Change-Id: I73153a805cecdc24c4eefcc781676de04737ae2c
Signed-off-by: Steven Luong <sluong@cisco.com>
2024-04-19 09:49:20 -07:00
|
|
|
Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac)
|
2022-04-26 19:02:15 +02:00
|
|
|
/ IP(src="1.1.1.1", dst="1.1.1.2")
|
|
|
|
/ UDP(sport=1000 + ii, dport=1234)
|
|
|
|
/ Raw(b"\xa5" * 100)
|
|
|
|
)
|
|
|
|
self.send_and_expect_load_balancing(
|
|
|
|
self.pg2, p_2, [self.pg3, self.pg4, self.pg5]
|
|
|
|
)
|
2019-05-22 13:26:39 +00:00
|
|
|
|
|
|
|
l3xc_2.remove_vpp_config()
|
|
|
|
self.send_and_assert_no_replies(self.pg2, p_2)
|
|
|
|
|
|
|
|
|
2022-04-26 19:02:15 +02:00
|
|
|
if __name__ == "__main__":
|
2019-05-22 13:26:39 +00:00
|
|
|
unittest.main(testRunner=VppTestRunner)
|