Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 1 | #!/usr/bin/env python |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 2 | import unittest |
| 3 | |
| 4 | from framework import VppTestCase, VppTestRunner |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 5 | from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathType |
Paul Vinciguerra | 95c0ca4 | 2019-03-28 13:07:00 -0700 | [diff] [blame] | 6 | from vpp_l2 import L2_PORT_TYPE |
| 7 | from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 8 | |
| 9 | from scapy.packet import Raw |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 10 | from scapy.layers.l2 import Ether, Dot1Q |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 11 | from scapy.layers.inet import IP, UDP |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 12 | from socket import AF_INET, inet_pton |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 13 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 14 | NUM_PKTS = 67 |
| 15 | |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 16 | |
| 17 | class TestDVR(VppTestCase): |
Neale Ranns | 62fe07c | 2017-10-31 12:28:22 -0700 | [diff] [blame] | 18 | """ Distributed Virtual Router """ |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 19 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 20 | @classmethod |
| 21 | def setUpClass(cls): |
| 22 | super(TestDVR, cls).setUpClass() |
| 23 | |
| 24 | @classmethod |
| 25 | def tearDownClass(cls): |
| 26 | super(TestDVR, cls).tearDownClass() |
| 27 | |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 28 | def setUp(self): |
| 29 | super(TestDVR, self).setUp() |
| 30 | |
| 31 | self.create_pg_interfaces(range(4)) |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 32 | self.create_loopback_interfaces(1) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 33 | |
| 34 | for i in self.pg_interfaces: |
| 35 | i.admin_up() |
| 36 | |
| 37 | self.loop0.config_ip4() |
| 38 | |
| 39 | def tearDown(self): |
| 40 | for i in self.pg_interfaces: |
| 41 | i.admin_down() |
| 42 | self.loop0.unconfig_ip4() |
| 43 | |
| 44 | super(TestDVR, self).tearDown() |
| 45 | |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 46 | def assert_same_mac_addr(self, tx, rx): |
| 47 | t_eth = tx[Ether] |
| 48 | for p in rx: |
| 49 | r_eth = p[Ether] |
| 50 | self.assertEqual(t_eth.src, r_eth.src) |
| 51 | self.assertEqual(t_eth.dst, r_eth.dst) |
| 52 | |
| 53 | def assert_has_vlan_tag(self, tag, rx): |
| 54 | for p in rx: |
| 55 | r_1q = p[Dot1Q] |
| 56 | self.assertEqual(tag, r_1q.vlan) |
| 57 | |
| 58 | def assert_has_no_tag(self, rx): |
| 59 | for p in rx: |
| 60 | self.assertFalse(p.haslayer(Dot1Q)) |
| 61 | |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 62 | def test_dvr(self): |
| 63 | """ Distributed Virtual Router """ |
| 64 | |
| 65 | # |
| 66 | # A packet destined to an IP address that is L2 bridged via |
| 67 | # a non-tag interface |
| 68 | # |
| 69 | ip_non_tag_bridged = "10.10.10.10" |
| 70 | ip_tag_bridged = "10.10.10.11" |
| 71 | any_src_addr = "1.1.1.1" |
| 72 | |
| 73 | pkt_no_tag = (Ether(src=self.pg0.remote_mac, |
| 74 | dst=self.loop0.local_mac) / |
| 75 | IP(src=any_src_addr, |
| 76 | dst=ip_non_tag_bridged) / |
| 77 | UDP(sport=1234, dport=1234) / |
| 78 | Raw('\xa5' * 100)) |
| 79 | pkt_tag = (Ether(src=self.pg0.remote_mac, |
| 80 | dst=self.loop0.local_mac) / |
| 81 | IP(src=any_src_addr, |
| 82 | dst=ip_tag_bridged) / |
| 83 | UDP(sport=1234, dport=1234) / |
| 84 | Raw('\xa5' * 100)) |
| 85 | |
| 86 | # |
| 87 | # Two sub-interfaces so we can test VLAN tag push/pop |
| 88 | # |
| 89 | sub_if_on_pg2 = VppDot1QSubint(self, self.pg2, 92) |
| 90 | sub_if_on_pg3 = VppDot1QSubint(self, self.pg3, 93) |
| 91 | sub_if_on_pg2.admin_up() |
| 92 | sub_if_on_pg3.admin_up() |
| 93 | |
| 94 | # |
| 95 | # Put all the interfaces into a new bridge domain |
| 96 | # |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 97 | self.vapi.sw_interface_set_l2_bridge( |
| 98 | rx_sw_if_index=self.pg0.sw_if_index, bd_id=1) |
| 99 | self.vapi.sw_interface_set_l2_bridge( |
| 100 | rx_sw_if_index=self.pg1.sw_if_index, bd_id=1) |
| 101 | self.vapi.sw_interface_set_l2_bridge( |
| 102 | rx_sw_if_index=sub_if_on_pg2.sw_if_index, bd_id=1) |
| 103 | self.vapi.sw_interface_set_l2_bridge( |
| 104 | rx_sw_if_index=sub_if_on_pg3.sw_if_index, bd_id=1) |
| 105 | self.vapi.sw_interface_set_l2_bridge( |
| 106 | rx_sw_if_index=self.loop0.sw_if_index, bd_id=1, |
| 107 | port_type=L2_PORT_TYPE.BVI) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 108 | |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 109 | self.vapi.l2_interface_vlan_tag_rewrite( |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 110 | sw_if_index=sub_if_on_pg2.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1, |
| 111 | push_dot1q=92) |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 112 | self.vapi.l2_interface_vlan_tag_rewrite( |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 113 | sw_if_index=sub_if_on_pg3.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1, |
| 114 | push_dot1q=93) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 115 | |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 116 | # |
| 117 | # Add routes to bridge the traffic via a tagged an nontagged interface |
| 118 | # |
| 119 | route_no_tag = VppIpRoute( |
| 120 | self, ip_non_tag_bridged, 32, |
| 121 | [VppRoutePath("0.0.0.0", |
| 122 | self.pg1.sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 123 | type=FibPathType.FIB_PATH_TYPE_DVR)]) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 124 | route_no_tag.add_vpp_config() |
| 125 | |
| 126 | # |
| 127 | # Inject the packet that arrives and leaves on a non-tagged interface |
| 128 | # Since it's 'bridged' expect that the MAC headed is unchanged. |
| 129 | # |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 130 | rx = self.send_and_expect(self.pg0, pkt_no_tag * NUM_PKTS, self.pg1) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 131 | self.assert_same_mac_addr(pkt_no_tag, rx) |
| 132 | self.assert_has_no_tag(rx) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 133 | |
| 134 | # |
| 135 | # Add routes to bridge the traffic via a tagged interface |
| 136 | # |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 137 | route_with_tag = VppIpRoute( |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 138 | self, ip_tag_bridged, 32, |
| 139 | [VppRoutePath("0.0.0.0", |
| 140 | sub_if_on_pg3.sw_if_index, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 141 | type=FibPathType.FIB_PATH_TYPE_DVR)]) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 142 | route_with_tag.add_vpp_config() |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 143 | |
| 144 | # |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 145 | # Inject the packet that arrives non-tag and leaves on a tagged |
| 146 | # interface |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 147 | # |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 148 | rx = self.send_and_expect(self.pg0, pkt_tag * NUM_PKTS, self.pg3) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 149 | self.assert_same_mac_addr(pkt_tag, rx) |
| 150 | self.assert_has_vlan_tag(93, rx) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 151 | |
| 152 | # |
| 153 | # Tag to tag |
| 154 | # |
| 155 | pkt_tag_to_tag = (Ether(src=self.pg2.remote_mac, |
| 156 | dst=self.loop0.local_mac) / |
| 157 | Dot1Q(vlan=92) / |
| 158 | IP(src=any_src_addr, |
| 159 | dst=ip_tag_bridged) / |
| 160 | UDP(sport=1234, dport=1234) / |
| 161 | Raw('\xa5' * 100)) |
| 162 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 163 | rx = self.send_and_expect(self.pg2, |
| 164 | pkt_tag_to_tag * NUM_PKTS, |
| 165 | self.pg3) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 166 | self.assert_same_mac_addr(pkt_tag_to_tag, rx) |
| 167 | self.assert_has_vlan_tag(93, rx) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 168 | |
| 169 | # |
| 170 | # Tag to non-Tag |
| 171 | # |
| 172 | pkt_tag_to_non_tag = (Ether(src=self.pg2.remote_mac, |
| 173 | dst=self.loop0.local_mac) / |
| 174 | Dot1Q(vlan=92) / |
| 175 | IP(src=any_src_addr, |
| 176 | dst=ip_non_tag_bridged) / |
| 177 | UDP(sport=1234, dport=1234) / |
| 178 | Raw('\xa5' * 100)) |
| 179 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 180 | rx = self.send_and_expect(self.pg2, |
| 181 | pkt_tag_to_non_tag * NUM_PKTS, |
| 182 | self.pg1) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 183 | self.assert_same_mac_addr(pkt_tag_to_tag, rx) |
| 184 | self.assert_has_no_tag(rx) |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 185 | |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 186 | # |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 187 | # Add an output L3 ACL that will block the traffic |
| 188 | # |
| 189 | rule_1 = ({'is_permit': 0, |
| 190 | 'is_ipv6': 0, |
| 191 | 'proto': 17, |
| 192 | 'srcport_or_icmptype_first': 1234, |
| 193 | 'srcport_or_icmptype_last': 1234, |
| 194 | 'src_ip_prefix_len': 32, |
| 195 | 'src_ip_addr': inet_pton(AF_INET, any_src_addr), |
| 196 | 'dstport_or_icmpcode_first': 1234, |
| 197 | 'dstport_or_icmpcode_last': 1234, |
| 198 | 'dst_ip_prefix_len': 32, |
| 199 | 'dst_ip_addr': inet_pton(AF_INET, ip_non_tag_bridged)}) |
| 200 | acl = self.vapi.acl_add_replace(acl_index=4294967295, |
| 201 | r=[rule_1]) |
| 202 | |
| 203 | # |
| 204 | # Apply the ACL on the output interface |
| 205 | # |
| 206 | self.vapi.acl_interface_set_acl_list(self.pg1.sw_if_index, |
| 207 | 0, |
| 208 | [acl.acl_index]) |
| 209 | |
| 210 | # |
| 211 | # Send packet's that should match the ACL and be dropped |
| 212 | # |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 213 | rx = self.send_and_assert_no_replies(self.pg2, |
| 214 | pkt_tag_to_non_tag * NUM_PKTS) |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 215 | |
| 216 | # |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 217 | # cleanup |
| 218 | # |
Neale Ranns | f068c3e | 2018-01-03 04:18:48 -0800 | [diff] [blame] | 219 | self.vapi.acl_interface_set_acl_list(self.pg1.sw_if_index, |
| 220 | 0, []) |
| 221 | self.vapi.acl_del(acl.acl_index) |
| 222 | |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 223 | self.vapi.sw_interface_set_l2_bridge( |
| 224 | rx_sw_if_index=self.pg0.sw_if_index, bd_id=1, enable=0) |
| 225 | self.vapi.sw_interface_set_l2_bridge( |
| 226 | rx_sw_if_index=self.pg1.sw_if_index, bd_id=1, enable=0) |
| 227 | self.vapi.sw_interface_set_l2_bridge( |
| 228 | rx_sw_if_index=sub_if_on_pg2.sw_if_index, bd_id=1, enable=0) |
| 229 | self.vapi.sw_interface_set_l2_bridge( |
| 230 | rx_sw_if_index=sub_if_on_pg3.sw_if_index, bd_id=1, enable=0) |
| 231 | self.vapi.sw_interface_set_l2_bridge( |
| 232 | rx_sw_if_index=self.loop0.sw_if_index, bd_id=1, |
| 233 | port_type=L2_PORT_TYPE.BVI, enable=0) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 234 | |
| 235 | # |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 236 | # Do a FIB dump to make sure the paths are correctly reported as DVR |
| 237 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 238 | routes = self.vapi.ip_route_dump(0) |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 239 | |
| 240 | for r in routes: |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 241 | if (ip_tag_bridged == str(r.route.prefix.network_address)): |
| 242 | self.assertEqual(r.route.paths[0].sw_if_index, |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 243 | sub_if_on_pg3.sw_if_index) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 244 | self.assertEqual(r.route.paths[0].type, |
| 245 | FibPathType.FIB_PATH_TYPE_DVR) |
| 246 | if (ip_non_tag_bridged == str(r.route.prefix.network_address)): |
| 247 | self.assertEqual(r.route.paths[0].sw_if_index, |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 248 | self.pg1.sw_if_index) |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 249 | self.assertEqual(r.route.paths[0].type, |
| 250 | FibPathType.FIB_PATH_TYPE_DVR) |
Neale Ranns | 8145842 | 2018-03-12 06:59:36 -0700 | [diff] [blame] | 251 | |
| 252 | # |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 253 | # the explicit route delete is require so it happens before |
| 254 | # the sbu-interface delete. subinterface delete is required |
| 255 | # because that object type does not use the object registry |
| 256 | # |
| 257 | route_no_tag.remove_vpp_config() |
| 258 | route_with_tag.remove_vpp_config() |
| 259 | sub_if_on_pg3.remove_vpp_config() |
| 260 | sub_if_on_pg2.remove_vpp_config() |
| 261 | |
| 262 | def test_l2_emulation(self): |
| 263 | """ L2 Emulation """ |
| 264 | |
| 265 | # |
| 266 | # non distinct L3 packets, in the tag/non-tag combos |
| 267 | # |
| 268 | pkt_no_tag = (Ether(src=self.pg0.remote_mac, |
| 269 | dst=self.pg1.remote_mac) / |
| 270 | IP(src="2.2.2.2", |
| 271 | dst="1.1.1.1") / |
| 272 | UDP(sport=1234, dport=1234) / |
| 273 | Raw('\xa5' * 100)) |
| 274 | pkt_to_tag = (Ether(src=self.pg0.remote_mac, |
| 275 | dst=self.pg2.remote_mac) / |
| 276 | IP(src="2.2.2.2", |
| 277 | dst="1.1.1.2") / |
| 278 | UDP(sport=1234, dport=1234) / |
| 279 | Raw('\xa5' * 100)) |
| 280 | pkt_from_tag = (Ether(src=self.pg3.remote_mac, |
| 281 | dst=self.pg2.remote_mac) / |
| 282 | Dot1Q(vlan=93) / |
| 283 | IP(src="2.2.2.2", |
| 284 | dst="1.1.1.1") / |
| 285 | UDP(sport=1234, dport=1234) / |
| 286 | Raw('\xa5' * 100)) |
| 287 | pkt_from_to_tag = (Ether(src=self.pg3.remote_mac, |
| 288 | dst=self.pg2.remote_mac) / |
| 289 | Dot1Q(vlan=93) / |
| 290 | IP(src="2.2.2.2", |
| 291 | dst="1.1.1.2") / |
| 292 | UDP(sport=1234, dport=1234) / |
| 293 | Raw('\xa5' * 100)) |
| 294 | pkt_bcast = (Ether(src=self.pg0.remote_mac, |
| 295 | dst="ff:ff:ff:ff:ff:ff") / |
| 296 | IP(src="2.2.2.2", |
| 297 | dst="255.255.255.255") / |
| 298 | UDP(sport=1234, dport=1234) / |
| 299 | Raw('\xa5' * 100)) |
| 300 | |
| 301 | # |
| 302 | # A couple of sub-interfaces for tags |
| 303 | # |
| 304 | sub_if_on_pg2 = VppDot1QSubint(self, self.pg2, 92) |
| 305 | sub_if_on_pg3 = VppDot1QSubint(self, self.pg3, 93) |
| 306 | sub_if_on_pg2.admin_up() |
| 307 | sub_if_on_pg3.admin_up() |
| 308 | |
| 309 | # |
| 310 | # Put all the interfaces into a new bridge domain |
| 311 | # |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 312 | self.vapi.sw_interface_set_l2_bridge( |
| 313 | rx_sw_if_index=self.pg0.sw_if_index, bd_id=1) |
| 314 | self.vapi.sw_interface_set_l2_bridge( |
| 315 | rx_sw_if_index=self.pg1.sw_if_index, bd_id=1) |
| 316 | self.vapi.sw_interface_set_l2_bridge( |
| 317 | rx_sw_if_index=sub_if_on_pg2.sw_if_index, bd_id=1) |
| 318 | self.vapi.sw_interface_set_l2_bridge( |
| 319 | rx_sw_if_index=sub_if_on_pg3.sw_if_index, bd_id=1) |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 320 | self.vapi.l2_interface_vlan_tag_rewrite( |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 321 | sw_if_index=sub_if_on_pg2.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1, |
| 322 | push_dot1q=92) |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 323 | self.vapi.l2_interface_vlan_tag_rewrite( |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 324 | sw_if_index=sub_if_on_pg3.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1, |
| 325 | push_dot1q=93) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 326 | |
| 327 | # |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 328 | # Disable UU flooding, learning and ARP termination. makes this test |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 329 | # easier as unicast packets are dropped if not extracted. |
| 330 | # |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 331 | self.vapi.bridge_flags(bd_id=1, is_set=0, |
| 332 | flags=(1 << 0) | (1 << 3) | (1 << 4)) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 333 | |
| 334 | # |
| 335 | # Add a DVR route to steer traffic at L3 |
| 336 | # |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 337 | route_1 = VppIpRoute( |
| 338 | self, "1.1.1.1", 32, |
| 339 | [VppRoutePath("0.0.0.0", |
| 340 | self.pg1.sw_if_index, |
| 341 | type=FibPathType.FIB_PATH_TYPE_DVR)]) |
| 342 | route_2 = VppIpRoute( |
| 343 | self, "1.1.1.2", 32, |
| 344 | [VppRoutePath("0.0.0.0", |
| 345 | sub_if_on_pg2.sw_if_index, |
| 346 | type=FibPathType.FIB_PATH_TYPE_DVR)]) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 347 | route_1.add_vpp_config() |
| 348 | route_2.add_vpp_config() |
| 349 | |
| 350 | # |
Andrey "Zed" Zaikin | 701625b | 2018-04-18 17:07:07 +0300 | [diff] [blame] | 351 | # packets are dropped because bridge does not flood unknown unicast |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 352 | # |
| 353 | self.send_and_assert_no_replies(self.pg0, pkt_no_tag) |
| 354 | |
| 355 | # |
| 356 | # Enable L3 extraction on pgs |
| 357 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 358 | self.vapi.l2_emulation(self.pg0.sw_if_index) |
| 359 | self.vapi.l2_emulation(self.pg1.sw_if_index) |
| 360 | self.vapi.l2_emulation(sub_if_on_pg2.sw_if_index) |
| 361 | self.vapi.l2_emulation(sub_if_on_pg3.sw_if_index) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 362 | |
| 363 | # |
| 364 | # now we expect the packet forward according to the DVR route |
| 365 | # |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 366 | rx = self.send_and_expect(self.pg0, pkt_no_tag * NUM_PKTS, self.pg1) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 367 | self.assert_same_mac_addr(pkt_no_tag, rx) |
| 368 | self.assert_has_no_tag(rx) |
| 369 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 370 | rx = self.send_and_expect(self.pg0, pkt_to_tag * NUM_PKTS, self.pg2) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 371 | self.assert_same_mac_addr(pkt_to_tag, rx) |
| 372 | self.assert_has_vlan_tag(92, rx) |
| 373 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 374 | rx = self.send_and_expect(self.pg3, pkt_from_tag * NUM_PKTS, self.pg1) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 375 | self.assert_same_mac_addr(pkt_from_tag, rx) |
| 376 | self.assert_has_no_tag(rx) |
| 377 | |
Paul Vinciguerra | 4271c97 | 2019-05-14 13:25:49 -0400 | [diff] [blame] | 378 | rx = self.send_and_expect(self.pg3, |
| 379 | pkt_from_to_tag * NUM_PKTS, |
| 380 | self.pg2) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 381 | self.assert_same_mac_addr(pkt_from_tag, rx) |
| 382 | self.assert_has_vlan_tag(92, rx) |
| 383 | |
| 384 | # |
| 385 | # but broadcast packets are still flooded |
| 386 | # |
| 387 | self.send_and_expect(self.pg0, pkt_bcast * 33, self.pg2) |
| 388 | |
| 389 | # |
| 390 | # cleanup |
| 391 | # |
Ole Troan | e1ade68 | 2019-03-04 23:55:43 +0100 | [diff] [blame] | 392 | self.vapi.l2_emulation(self.pg0.sw_if_index, |
| 393 | enable=0) |
| 394 | self.vapi.l2_emulation(self.pg1.sw_if_index, |
| 395 | enable=0) |
| 396 | self.vapi.l2_emulation(sub_if_on_pg2.sw_if_index, |
| 397 | enable=0) |
| 398 | self.vapi.l2_emulation(sub_if_on_pg3.sw_if_index, |
| 399 | enable=0) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 400 | |
Ole Troan | a5b2eec | 2019-03-11 19:23:25 +0100 | [diff] [blame] | 401 | self.vapi.sw_interface_set_l2_bridge( |
| 402 | rx_sw_if_index=self.pg0.sw_if_index, bd_id=1, enable=0) |
| 403 | self.vapi.sw_interface_set_l2_bridge( |
| 404 | rx_sw_if_index=self.pg1.sw_if_index, bd_id=1, enable=0) |
| 405 | self.vapi.sw_interface_set_l2_bridge( |
| 406 | rx_sw_if_index=sub_if_on_pg2.sw_if_index, bd_id=1, enable=0) |
| 407 | self.vapi.sw_interface_set_l2_bridge( |
| 408 | rx_sw_if_index=sub_if_on_pg3.sw_if_index, bd_id=1, enable=0) |
Neale Ranns | 55d0378 | 2017-10-21 06:34:22 -0700 | [diff] [blame] | 409 | |
| 410 | route_1.remove_vpp_config() |
| 411 | route_2.remove_vpp_config() |
| 412 | sub_if_on_pg3.remove_vpp_config() |
| 413 | sub_if_on_pg2.remove_vpp_config() |
| 414 | |
Neale Ranns | 6f63115 | 2017-10-03 08:20:21 -0700 | [diff] [blame] | 415 | |
| 416 | if __name__ == '__main__': |
| 417 | unittest.main(testRunner=VppTestRunner) |