6 from framework import VppTestCase, VppTestRunner
7 from vpp_ip_route import VppIpRoute, VppRoutePath
8 from vpp_l2 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_bvi_interfaces(1)
25 for i in self.pg_interfaces:
27 for i in self.bvi_interfaces:
30 self.pg12.config_ip4()
31 self.pg12.resolve_arp()
32 self.bvi0.config_ip4()
35 self.pg12.unconfig_ip4()
36 self.bvi0.unconfig_ip4()
38 for i in self.pg_interfaces:
40 for i in self.bvi_interfaces:
42 super(TestL2Flood, self).tearDown()
45 """ L2 Flood Tests """
48 # Create a single bridge Domain
50 self.vapi.bridge_domain_add_del(bd_id=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(rx_sw_if_index=i.sw_if_index,
58 for i in self.pg_interfaces[4:8]:
59 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
61 for i in self.pg_interfaces[8:12]:
62 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
64 for i in self.bvi_interfaces:
65 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
67 port_type=L2_PORT_TYPE.BVI)
69 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
70 src="00:00:de:ad:be:ef") /
71 IP(src="10.10.10.10", dst="1.1.1.1") /
72 UDP(sport=1234, dport=1234) /
76 # input on pg0 expect copies on pg1->11
77 # this is in SHG=0 so its flooded to all, expect the pg0 since that's
80 self.pg0.add_stream(p*65)
81 self.pg_enable_capture(self.pg_interfaces)
84 for i in self.pg_interfaces[1:12]:
85 rx0 = i.get_capture(65, timeout=1)
88 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
91 self.pg4.add_stream(p*65)
92 self.pg_enable_capture(self.pg_interfaces)
95 for i in self.pg_interfaces[:4]:
96 rx0 = i.get_capture(65, timeout=1)
97 for i in self.pg_interfaces[8:12]:
98 rx0 = i.get_capture(65, timeout=1)
99 for i in self.pg_interfaces[4:8]:
100 i.assert_nothing_captured(remark="Different SH group")
103 # An IP route so the packet that hits the BVI is sent out of pg12
105 ip_route = VppIpRoute(self, "1.1.1.1", 32,
106 [VppRoutePath(self.pg12.remote_ip4,
107 self.pg12.sw_if_index)])
108 ip_route.add_vpp_config()
110 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
113 # input on pg0 expect copies on pg1->12
114 # this is in SHG=0 so its flooded to all, expect the pg0 since that's
117 self.pg0.add_stream(p*65)
118 self.pg_enable_capture(self.pg_interfaces)
121 for i in self.pg_interfaces[1:]:
122 rx0 = i.get_capture(65, timeout=1)
125 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
126 # and pg8->12 (SHG=2)
128 self.pg4.add_stream(p*65)
129 self.pg_enable_capture(self.pg_interfaces)
132 for i in self.pg_interfaces[:4]:
133 rx0 = i.get_capture(65, timeout=1)
134 for i in self.pg_interfaces[8:13]:
135 rx0 = i.get_capture(65, timeout=1)
136 for i in self.pg_interfaces[4:8]:
137 i.assert_nothing_captured(remark="Different SH group")
142 for i in self.pg_interfaces[:12]:
143 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
145 for i in self.bvi_interfaces:
146 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
148 port_type=L2_PORT_TYPE.BVI,
151 self.vapi.bridge_domain_add_del(bd_id=1, is_add=0)
153 def test_flood_one(self):
154 """ L2 no-Flood Test """
157 # Create a single bridge Domain
159 self.vapi.bridge_domain_add_del(bd_id=1)
162 # add 2 interfaces to the BD. this means a flood goes to only
165 for i in self.pg_interfaces[:2]:
166 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
169 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
170 src="00:00:de:ad:be:ef") /
171 IP(src="10.10.10.10", dst="1.1.1.1") /
172 UDP(sport=1234, dport=1234) /
176 # input on pg0 expect copies on pg1
178 self.send_and_expect(self.pg0, p*65, self.pg1)
183 for i in self.pg_interfaces[:2]:
184 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
186 self.vapi.bridge_domain_add_del(bd_id=1, is_add=0)
188 def test_uu_fwd(self):
192 # Create a single bridge Domain
194 self.vapi.bridge_domain_add_del(bd_id=1, uu_flood=1)
197 # add each interface to the BD. 3 interfaces per split horizon group
199 for i in self.pg_interfaces[0:4]:
200 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
204 # an unknown unicast and broadcast packets
206 p_uu = (Ether(dst="00:00:00:c1:5c:00",
207 src="00:00:de:ad:be:ef") /
208 IP(src="10.10.10.10", dst="1.1.1.1") /
209 UDP(sport=1234, dport=1234) /
211 p_bm = (Ether(dst="ff:ff:ff:ff:ff:ff",
212 src="00:00:de:ad:be:ef") /
213 IP(src="10.10.10.10", dst="1.1.1.1") /
214 UDP(sport=1234, dport=1234) /
218 # input on pg0, expected copies on pg1->4
220 self.pg0.add_stream(p_uu*65)
221 self.pg_enable_capture(self.pg_interfaces)
224 for i in self.pg_interfaces[1:4]:
225 rx0 = i.get_capture(65, timeout=1)
227 self.pg0.add_stream(p_bm*65)
228 self.pg_enable_capture(self.pg_interfaces)
231 for i in self.pg_interfaces[1:4]:
232 rx0 = i.get_capture(65, timeout=1)
235 # use pg8 as the uu-fwd interface
237 self.vapi.sw_interface_set_l2_bridge(
238 rx_sw_if_index=self.pg8.sw_if_index, bd_id=1, shg=0,
239 port_type=L2_PORT_TYPE.UU_FWD)
242 # expect the UU packet on the uu-fwd interface and not be flooded
244 self.pg0.add_stream(p_uu*65)
245 self.pg_enable_capture(self.pg_interfaces)
248 rx0 = self.pg8.get_capture(65, timeout=1)
250 for i in self.pg_interfaces[0:4]:
251 i.assert_nothing_captured(remark="UU not flooded")
253 self.pg0.add_stream(p_bm*65)
254 self.pg_enable_capture(self.pg_interfaces)
257 for i in self.pg_interfaces[1:4]:
258 rx0 = i.get_capture(65, timeout=1)
261 # remove the uu-fwd interface and expect UU to be flooded again
263 self.vapi.sw_interface_set_l2_bridge(
264 rx_sw_if_index=self.pg8.sw_if_index, bd_id=1, shg=0,
265 port_type=L2_PORT_TYPE.UU_FWD, enable=0)
267 self.pg0.add_stream(p_uu*65)
268 self.pg_enable_capture(self.pg_interfaces)
271 for i in self.pg_interfaces[1:4]:
272 rx0 = i.get_capture(65, timeout=1)
275 # change the BD config to not support UU-flood
277 self.vapi.bridge_flags(bd_id=1, is_set=0, flags=BRIDGE_FLAGS.UU_FLOOD)
279 self.send_and_assert_no_replies(self.pg0, p_uu)
282 # re-add the uu-fwd interface
284 self.vapi.sw_interface_set_l2_bridge(
285 rx_sw_if_index=self.pg8.sw_if_index, bd_id=1, shg=0,
286 port_type=L2_PORT_TYPE.UU_FWD)
287 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
289 self.pg0.add_stream(p_uu*65)
290 self.pg_enable_capture(self.pg_interfaces)
293 rx0 = self.pg8.get_capture(65, timeout=1)
295 for i in self.pg_interfaces[0:4]:
296 i.assert_nothing_captured(remark="UU not flooded")
299 # remove the uu-fwd interface
301 self.vapi.sw_interface_set_l2_bridge(
302 rx_sw_if_index=self.pg8.sw_if_index, bd_id=1, shg=0,
303 port_type=L2_PORT_TYPE.UU_FWD, enable=0)
304 self.send_and_assert_no_replies(self.pg0, p_uu)
309 for i in self.pg_interfaces[:4]:
310 self.vapi.sw_interface_set_l2_bridge(rx_sw_if_index=i.sw_if_index,
313 self.vapi.bridge_domain_add_del(bd_id=1, is_add=0)
316 if __name__ == '__main__':
317 unittest.main(testRunner=VppTestRunner)