blob: 36ec309ad97f0ff6f16cb3360b4274865a7267d4 [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
81 self.logger.error(self.vapi.cli("sh trace"))
82
83 #
84 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
85 # and pg8->11 (SHG=2)
86 #
87 self.pg4.add_stream(p*65)
88 self.pg_enable_capture(self.pg_interfaces)
89 self.pg_start()
90
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")
97
98 #
99 # An IP route so the packet that hits the BVI is sent out of pg12
100 #
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()
105
106 self.logger.info(self.vapi.cli("sh bridge 1 detail"))
107
108 #
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
111 # the ingress link
112 #
113 self.pg0.add_stream(p*65)
114 self.pg_enable_capture(self.pg_interfaces)
115 self.pg_start()
116
117 for i in self.pg_interfaces[1:]:
118 rx0 = i.get_capture(65, timeout=1)
119
120 #
121 # input on pg4 (SHG=1) expect copies on pg0->3 (SHG=0)
122 # and pg8->12 (SHG=2)
123 #
124 self.pg4.add_stream(p*65)
125 self.pg_enable_capture(self.pg_interfaces)
126 self.pg_start()
127
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")
134
135 #
136 # cleanup
137 #
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 bvi=1, enable=0)
143
144 self.vapi.bridge_domain_add_del(1, is_add=0)
145
146
147if __name__ == '__main__':
148 unittest.main(testRunner=VppTestRunner)