Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 2 | |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 3 | import unittest |
| 4 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 5 | from framework import VppTestCase |
| 6 | from asfframework import VppTestRunner |
| 7 | from vpp_ip_route import VppRoutePath |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 8 | |
| 9 | from scapy.packet import Raw |
| 10 | from scapy.layers.l2 import Ether |
| 11 | from scapy.layers.inet import IP, UDP |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 12 | |
| 13 | from vpp_object import VppObject |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame^] | 14 | from config import config |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 15 | |
| 16 | NUM_PKTS = 67 |
| 17 | |
| 18 | |
| 19 | def find_l3xc(test, sw_if_index, dump_sw_if_index=None): |
| 20 | if not dump_sw_if_index: |
| 21 | dump_sw_if_index = sw_if_index |
| 22 | xcs = test.vapi.l3xc_dump(dump_sw_if_index) |
| 23 | for xc in xcs: |
| 24 | if sw_if_index == xc.l3xc.sw_if_index: |
| 25 | return True |
| 26 | return False |
| 27 | |
| 28 | |
| 29 | class VppL3xc(VppObject): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 30 | def __init__(self, test, intf, paths, is_ip6=False): |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 31 | self._test = test |
| 32 | self.intf = intf |
| 33 | self.is_ip6 = is_ip6 |
| 34 | self.paths = paths |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 35 | self.encoded_paths = [] |
| 36 | for path in self.paths: |
| 37 | self.encoded_paths.append(path.encode()) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 38 | |
| 39 | def add_vpp_config(self): |
| 40 | self._test.vapi.l3xc_update( |
| 41 | l3xc={ |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 42 | "is_ip6": self.is_ip6, |
| 43 | "sw_if_index": self.intf.sw_if_index, |
| 44 | "n_paths": len(self.paths), |
| 45 | "paths": self.encoded_paths, |
| 46 | } |
| 47 | ) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 48 | self._test.registry.register(self, self._test.logger) |
| 49 | |
| 50 | def remove_vpp_config(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 51 | self._test.vapi.l3xc_del(is_ip6=self.is_ip6, sw_if_index=self.intf.sw_if_index) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 52 | |
| 53 | def query_vpp_config(self): |
| 54 | return find_l3xc(self._test, self.intf.sw_if_index) |
| 55 | |
| 56 | def object_id(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 57 | return "l3xc-%d" % self.intf.sw_if_index |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 58 | |
| 59 | |
Dmitry Valter | 34fa0ce | 2024-03-11 10:38:46 +0000 | [diff] [blame^] | 60 | @unittest.skipIf("l3xc" in config.excluded_plugins, "Exclude L3XC plugin tests") |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 61 | class TestL3xc(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 62 | """L3XC Test Case""" |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 63 | |
| 64 | @classmethod |
| 65 | def setUpClass(cls): |
| 66 | super(TestL3xc, cls).setUpClass() |
| 67 | |
| 68 | @classmethod |
| 69 | def tearDownClass(cls): |
| 70 | super(TestL3xc, cls).tearDownClass() |
| 71 | |
| 72 | def setUp(self): |
| 73 | super(TestL3xc, self).setUp() |
| 74 | |
| 75 | self.create_pg_interfaces(range(6)) |
| 76 | |
| 77 | for i in self.pg_interfaces: |
| 78 | i.admin_up() |
| 79 | i.config_ip4() |
| 80 | i.resolve_arp() |
| 81 | i.config_ip6() |
| 82 | i.resolve_ndp() |
| 83 | |
| 84 | def tearDown(self): |
| 85 | for i in self.pg_interfaces: |
| 86 | i.unconfig_ip4() |
| 87 | i.unconfig_ip6() |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 88 | i.admin_down() |
| 89 | super(TestL3xc, self).tearDown() |
| 90 | |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 91 | def test_l3xc4(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 92 | """IPv4 X-Connect""" |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 93 | |
| 94 | # |
| 95 | # x-connect pg0 to pg1 and pg2 to pg3->5 |
| 96 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 97 | l3xc_1 = VppL3xc( |
| 98 | self, self.pg0, [VppRoutePath(self.pg1.remote_ip4, self.pg1.sw_if_index)] |
| 99 | ) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 100 | l3xc_1.add_vpp_config() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 101 | l3xc_2 = VppL3xc( |
| 102 | self, |
| 103 | self.pg2, |
| 104 | [ |
| 105 | VppRoutePath(self.pg3.remote_ip4, self.pg3.sw_if_index), |
| 106 | VppRoutePath(self.pg4.remote_ip4, self.pg4.sw_if_index), |
| 107 | VppRoutePath(self.pg5.remote_ip4, self.pg5.sw_if_index), |
| 108 | ], |
| 109 | ) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 110 | l3xc_2.add_vpp_config() |
| 111 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 112 | self.assertTrue(find_l3xc(self, self.pg2.sw_if_index, 0xFFFFFFFF)) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 113 | |
| 114 | self.logger.info(self.vapi.cli("sh l3xc")) |
| 115 | |
| 116 | # |
| 117 | # fire in packets. If it's forwarded then the L3XC was successful, |
| 118 | # since default routing will drop it |
| 119 | # |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 120 | p_1 = ( |
| 121 | Ether(src=self.pg0.remote_mac, dst=self.pg0.local_mac) |
| 122 | / IP(src="1.1.1.1", dst="1.1.1.2") |
| 123 | / UDP(sport=1234, dport=1234) |
| 124 | / Raw(b"\xa5" * 100) |
| 125 | ) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 126 | # self.send_and_expect(self.pg0, p_1*NUM_PKTS, self.pg1) |
| 127 | |
| 128 | p_2 = [] |
| 129 | for ii in range(NUM_PKTS): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 130 | p_2.append( |
Steven Luong | e4238aa | 2024-04-19 09:49:20 -0700 | [diff] [blame] | 131 | Ether(src=self.pg2.remote_mac, dst=self.pg2.local_mac) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 132 | / IP(src="1.1.1.1", dst="1.1.1.2") |
| 133 | / UDP(sport=1000 + ii, dport=1234) |
| 134 | / Raw(b"\xa5" * 100) |
| 135 | ) |
| 136 | self.send_and_expect_load_balancing( |
| 137 | self.pg2, p_2, [self.pg3, self.pg4, self.pg5] |
| 138 | ) |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 139 | |
| 140 | l3xc_2.remove_vpp_config() |
| 141 | self.send_and_assert_no_replies(self.pg2, p_2) |
| 142 | |
| 143 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 144 | if __name__ == "__main__": |
Neale Ranns | 59fa121 | 2019-05-22 13:26:39 +0000 | [diff] [blame] | 145 | unittest.main(testRunner=VppTestRunner) |