6 from framework import VppTestCase, VppTestRunner
7 from vpp_ip_route import VppIpRoute, VppRoutePath
8 from vpp_papi_provider import L2_PORT_TYPE, BRIDGE_FLAGS
10 from scapy.packet import Raw
11 from scapy.layers.l2 import Ether
12 from scapy.layers.inet import IP, UDP
15 class TestL2Flood(VppTestCase):
19 super(TestL2Flood, self).setUp()
21 # 12 l2 interface and one l3
22 self.create_pg_interfaces(range(13))
23 self.create_loopback_interfaces(1)
25 for i in self.pg_interfaces:
27 for i in self.lo_interfaces:
30 self.pg12.config_ip4()
31 self.pg12.resolve_arp()
32 self.loop0.config_ip4()
35 self.pg12.unconfig_ip4()
36 self.loop0.unconfig_ip4()
38 for i in self.pg_interfaces:
40 for i in self.lo_interfaces:
42 super(TestL2Flood, self).tearDown()
45 """ L2 Flood Tests """
48 # Create a single bridge Domain
50 self.vapi.bridge_domain_add_del(1)
53 # add each interface to the BD. 3 interfaces per split horizon group
55 for i in self.pg_interfaces[0:4]:
56 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 0)
57 for i in self.pg_interfaces[4:8]:
58 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 1)
59 for i in self.pg_interfaces[8:12]:
60 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 2)
61 for i in self.lo_interfaces:
62 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 2,
63 port_type=L2_PORT_TYPE.BVI)
65 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
66 src="00:00:de:ad:be:ef") /
67 IP(src="10.10.10.10", dst="1.1.1.1") /
68 UDP(sport=1234, dport=1234) /
72 # input on pg0 expect copies on pg1->11
73 # this is in SHG=0 so its flooded to all, expect the pg0 since that's
76 self.pg0.add_stream(p*65)
77 self.pg_enable_capture(self.pg_interfaces)
80 for i in self.pg_interfaces[1:12]:
81 rx0 = i.get_capture(65, timeout=1)
84 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
87 self.pg4.add_stream(p*65)
88 self.pg_enable_capture(self.pg_interfaces)
91 for i in self.pg_interfaces[:4]:
92 rx0 = i.get_capture(65, timeout=1)
93 for i in self.pg_interfaces[8:12]:
94 rx0 = i.get_capture(65, timeout=1)
95 for i in self.pg_interfaces[4:8]:
96 i.assert_nothing_captured(remark="Different SH group")
99 # An IP route so the packet that hits the BVI is sent out of pg12
101 ip_route = VppIpRoute(self, "1.1.1.1", 32,
102 [VppRoutePath(self.pg12.remote_ip4,
103 self.pg12.sw_if_index)])
104 ip_route.add_vpp_config()
106 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
109 # input on pg0 expect copies on pg1->12
110 # this is in SHG=0 so its flooded to all, expect the pg0 since that's
113 self.pg0.add_stream(p*65)
114 self.pg_enable_capture(self.pg_interfaces)
117 for i in self.pg_interfaces[1:]:
118 rx0 = i.get_capture(65, timeout=1)
121 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
122 # and pg8->12 (SHG=2)
124 self.pg4.add_stream(p*65)
125 self.pg_enable_capture(self.pg_interfaces)
128 for i in self.pg_interfaces[:4]:
129 rx0 = i.get_capture(65, timeout=1)
130 for i in self.pg_interfaces[8:13]:
131 rx0 = i.get_capture(65, timeout=1)
132 for i in self.pg_interfaces[4:8]:
133 i.assert_nothing_captured(remark="Different SH group")
138 for i in self.pg_interfaces[:12]:
139 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, enable=0)
140 for i in self.lo_interfaces:
141 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 2,
142 port_type=L2_PORT_TYPE.BVI,
145 self.vapi.bridge_domain_add_del(1, is_add=0)
147 def test_flood_one(self):
148 """ L2 no-Flood Test """
151 # Create a single bridge Domain
153 self.vapi.bridge_domain_add_del(1)
156 # add 2 interfaces to the BD. this means a flood goes to only
159 for i in self.pg_interfaces[:2]:
160 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 0)
162 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
163 src="00:00:de:ad:be:ef") /
164 IP(src="10.10.10.10", dst="1.1.1.1") /
165 UDP(sport=1234, dport=1234) /
169 # input on pg0 expect copies on pg1
171 self.send_and_expect(self.pg0, p*65, self.pg1)
176 for i in self.pg_interfaces[:2]:
177 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, enable=0)
178 self.vapi.bridge_domain_add_del(1, is_add=0)
180 def test_uu_fwd(self):
184 # Create a single bridge Domain
186 self.vapi.bridge_domain_add_del(1, uu_flood=1)
189 # add each interface to the BD. 3 interfaces per split horizon group
191 for i in self.pg_interfaces[0:4]:
192 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 0)
195 # an unknown unicast and braodcast packets
197 p_uu = (Ether(dst="00:00:00:c1:5c:00",
198 src="00:00:de:ad:be:ef") /
199 IP(src="10.10.10.10", dst="1.1.1.1") /
200 UDP(sport=1234, dport=1234) /
202 p_bm = (Ether(dst="ff:ff:ff:ff:ff:ff",
203 src="00:00:de:ad:be:ef") /
204 IP(src="10.10.10.10", dst="1.1.1.1") /
205 UDP(sport=1234, dport=1234) /
209 # input on pg0, expected copies on pg1->4
211 self.pg0.add_stream(p_uu*65)
212 self.pg_enable_capture(self.pg_interfaces)
215 for i in self.pg_interfaces[1:4]:
216 rx0 = i.get_capture(65, timeout=1)
218 self.pg0.add_stream(p_bm*65)
219 self.pg_enable_capture(self.pg_interfaces)
222 for i in self.pg_interfaces[1:4]:
223 rx0 = i.get_capture(65, timeout=1)
226 # use pg8 as the uu-fwd interface
228 self.vapi.sw_interface_set_l2_bridge(self.pg8.sw_if_index, 1, 0,
229 port_type=L2_PORT_TYPE.UU_FWD)
232 # expect the UU packet on the uu-fwd interface and not be flooded
234 self.pg0.add_stream(p_uu*65)
235 self.pg_enable_capture(self.pg_interfaces)
238 rx0 = self.pg8.get_capture(65, timeout=1)
240 for i in self.pg_interfaces[0:4]:
241 i.assert_nothing_captured(remark="UU not flooded")
243 self.pg0.add_stream(p_bm*65)
244 self.pg_enable_capture(self.pg_interfaces)
247 for i in self.pg_interfaces[1:4]:
248 rx0 = i.get_capture(65, timeout=1)
251 # remove the uu-fwd interface and expect UU to be flooded again
253 self.vapi.sw_interface_set_l2_bridge(self.pg8.sw_if_index, 1, 0,
254 port_type=L2_PORT_TYPE.UU_FWD,
257 self.pg0.add_stream(p_uu*65)
258 self.pg_enable_capture(self.pg_interfaces)
261 for i in self.pg_interfaces[1:4]:
262 rx0 = i.get_capture(65, timeout=1)
265 # change the BD config to not support UU-flood
267 self.vapi.bridge_flags(1, 0, BRIDGE_FLAGS.UU_FLOOD)
269 self.send_and_assert_no_replies(self.pg0, p_uu)
272 # re-add the uu-fwd interface
274 self.vapi.sw_interface_set_l2_bridge(self.pg8.sw_if_index, 1, 0,
275 port_type=L2_PORT_TYPE.UU_FWD)
276 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
278 self.pg0.add_stream(p_uu*65)
279 self.pg_enable_capture(self.pg_interfaces)
282 rx0 = self.pg8.get_capture(65, timeout=1)
284 for i in self.pg_interfaces[0:4]:
285 i.assert_nothing_captured(remark="UU not flooded")
288 # remove the uu-fwd interface
290 self.vapi.sw_interface_set_l2_bridge(self.pg8.sw_if_index, 1, 0,
291 port_type=L2_PORT_TYPE.UU_FWD,
293 self.send_and_assert_no_replies(self.pg0, p_uu)
298 for i in self.pg_interfaces[:4]:
299 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, enable=0)
301 self.vapi.bridge_domain_add_del(1, is_add=0)
304 if __name__ == '__main__':
305 unittest.main(testRunner=VppTestRunner)