blob: a8b6b10f11abbee20210c04f3f7a9c08f9450eda [file] [log] [blame]
Neale Ranns055b2312018-07-20 01:16:04 -07001#!/usr/bin/env python
2
3import unittest
4import socket
5
6from framework import VppTestCase, VppTestRunner
7from vpp_ip_route import VppIpRoute, VppRoutePath
8
9from scapy.packet import Raw
10from scapy.layers.l2 import Ether
11from scapy.layers.inet import IP, UDP
12
13
14class TestL2Flood(VppTestCase):
15 """ L2-flood """
16
17 def setUp(self):
18 super(TestL2Flood, self).setUp()
19
20 # 12 l2 interface and one l3
21 self.create_pg_interfaces(range(13))
22 self.create_loopback_interfaces(1)
23
24 for i in self.pg_interfaces:
25 i.admin_up()
26 for i in self.lo_interfaces:
27 i.admin_up()
28
29 self.pg12.config_ip4()
30 self.pg12.resolve_arp()
31 self.loop0.config_ip4()
32
33 def tearDown(self):
34 self.pg12.unconfig_ip4()
35 self.loop0.unconfig_ip4()
36
37 for i in self.pg_interfaces:
38 i.admin_down()
39 for i in self.lo_interfaces:
40 i.admin_down()
41 super(TestL2Flood, self).tearDown()
42
43 def test_flood(self):
44 """ L2 Flood Tests """
45
46 #
47 # Create a single bridge Domain
48 #
49 self.vapi.bridge_domain_add_del(1)
50
51 #
52 # add each interface to the BD. 3 interfaces per split horizon group
53 #
54 for i in self.pg_interfaces[0:4]:
55 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 0)
56 for i in self.pg_interfaces[4:8]:
57 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 1)
58 for i in self.pg_interfaces[8:12]:
59 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 2)
60 for i in self.lo_interfaces:
61 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 2, bvi=1)
62
63 p = (Ether(dst="ff:ff:ff:ff:ff:ff",
64 src="00:00:de:ad:be:ef") /
65 IP(src="10.10.10.10", dst="1.1.1.1") /
66 UDP(sport=1234, dport=1234) /
67 Raw('\xa5' * 100))
68
69 #
70 # input on pg0 expect copies on pg1->11
71 # this is in SHG=0 so its flooded to all, expect the pg0 since that's
72 # the ingress link
73 #
74 self.pg0.add_stream(p*65)
75 self.pg_enable_capture(self.pg_interfaces)
76 self.pg_start()
77
78 for i in self.pg_interfaces[1:12]:
79 rx0 = i.get_capture(65, timeout=1)
80
Neale Ranns055b2312018-07-20 01:16:04 -070081 #
82 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
83 # and pg8->11 (SHG=2)
84 #
85 self.pg4.add_stream(p*65)
86 self.pg_enable_capture(self.pg_interfaces)
87 self.pg_start()
88
89 for i in self.pg_interfaces[:4]:
90 rx0 = i.get_capture(65, timeout=1)
91 for i in self.pg_interfaces[8:12]:
92 rx0 = i.get_capture(65, timeout=1)
93 for i in self.pg_interfaces[4:8]:
94 i.assert_nothing_captured(remark="Different SH group")
95
96 #
97 # An IP route so the packet that hits the BVI is sent out of pg12
98 #
99 ip_route = VppIpRoute(self, "1.1.1.1", 32,
100 [VppRoutePath(self.pg12.remote_ip4,
101 self.pg12.sw_if_index)])
102 ip_route.add_vpp_config()
103
104 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
105
106 #
107 # input on pg0 expect copies on pg1->12
108 # this is in SHG=0 so its flooded to all, expect the pg0 since that's
109 # the ingress link
110 #
111 self.pg0.add_stream(p*65)
112 self.pg_enable_capture(self.pg_interfaces)
113 self.pg_start()
114
115 for i in self.pg_interfaces[1:]:
116 rx0 = i.get_capture(65, timeout=1)
117
118 #
119 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
120 # and pg8->12 (SHG=2)
121 #
122 self.pg4.add_stream(p*65)
123 self.pg_enable_capture(self.pg_interfaces)
124 self.pg_start()
125
126 for i in self.pg_interfaces[:4]:
127 rx0 = i.get_capture(65, timeout=1)
128 for i in self.pg_interfaces[8:13]:
129 rx0 = i.get_capture(65, timeout=1)
130 for i in self.pg_interfaces[4:8]:
131 i.assert_nothing_captured(remark="Different SH group")
132
133 #
134 # cleanup
135 #
136 for i in self.pg_interfaces[:12]:
137 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, enable=0)
138 for i in self.lo_interfaces:
139 self.vapi.sw_interface_set_l2_bridge(i.sw_if_index, 1, 2,
140 bvi=1, enable=0)
141
142 self.vapi.bridge_domain_add_del(1, is_add=0)
143
144
145if __name__ == '__main__':
146 unittest.main(testRunner=VppTestRunner)