blob: 021eed831775483e73155b0905b92e7dd16cafec [file] [log] [blame]
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01001#!/usr/bin/env python
2
3import unittest
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01004
5from scapy.packet import Raw
John Lo2bf8b812018-02-27 16:35:03 -05006from scapy.layers.l2 import Ether, Dot1Q, GRE, ERSPAN
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01007from scapy.layers.inet import IP, UDP
Eyal Bari001fd402017-07-16 09:34:53 +03008from scapy.layers.vxlan import VXLAN
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +01009
10from framework import VppTestCase, VppTestRunner
Klement Sekera7bb873a2016-11-18 07:38:42 +010011from util import Host, ppp
Eyal Bari001fd402017-07-16 09:34:53 +030012from vpp_sub_interface import VppDot1QSubint, VppDot1ADSubint
13from vpp_gre_interface import VppGreInterface, VppGre6Interface
14from vpp_papi_provider import L2_VTR_OP
15from collections import namedtuple
16
17Tag = namedtuple('Tag', ['dot1', 'vlan'])
18DOT1AD = 0x88A8
19DOT1Q = 0x8100
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010020
21
22class TestSpan(VppTestCase):
23 """ SPAN Test Case """
24
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010025 @classmethod
26 def setUpClass(cls):
27 super(TestSpan, cls).setUpClass()
Eyal Bari001fd402017-07-16 09:34:53 +030028 # Test variables
Eyal Bari001fd402017-07-16 09:34:53 +030029 cls.pkts_per_burst = 257 # Number of packets per burst
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010030 # create 3 pg interfaces
Eyal Bari001fd402017-07-16 09:34:53 +030031 cls.create_pg_interfaces(range(3))
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010032
Eyal Bari001fd402017-07-16 09:34:53 +030033 cls.bd_id = 55
34 cls.sub_if = VppDot1QSubint(cls, cls.pg0, 100)
Eyal Bari17142b22017-10-16 13:38:21 +030035 cls.vlan_sub_if = VppDot1QSubint(cls, cls.pg2, 300)
36 cls.vlan_sub_if.set_vtr(L2_VTR_OP.L2_POP_1, tag=300)
37
38 cls.qinq_sub_if = VppDot1ADSubint(cls, cls.pg2, 33, 400, 500)
39 cls.qinq_sub_if.set_vtr(L2_VTR_OP.L2_POP_2, outer=500, inner=400)
40
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010041 # packet flows mapping pg0 -> pg1, pg2 -> pg3, etc.
Eyal Bari001fd402017-07-16 09:34:53 +030042 cls.flows = dict()
43 cls.flows[cls.pg0] = [cls.pg1]
Eyal Baricdeb7f22017-10-15 16:55:11 +030044 cls.flows[cls.pg1] = [cls.pg0]
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010045
46 # packet sizes
Eyal Bari17142b22017-10-16 13:38:21 +030047 cls.pg_if_packet_sizes = [64, 512, 1518] # , 9018]
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010048
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010049 # setup all interfaces
Eyal Bari17142b22017-10-16 13:38:21 +030050 for i in cls.pg_interfaces:
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010051 i.admin_up()
52 i.config_ip4()
53 i.resolve_arp()
54
Eyal Bari001fd402017-07-16 09:34:53 +030055 cls.vxlan = cls.vapi.vxlan_add_del_tunnel(
56 src_addr=cls.pg2.local_ip4n,
57 dst_addr=cls.pg2.remote_ip4n,
58 vni=1111,
59 is_add=1)
60
61 def setUp(self):
62 super(TestSpan, self).setUp()
63 self.reset_packet_infos()
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010064
65 def tearDown(self):
66 super(TestSpan, self).tearDown()
Eyal Bari001fd402017-07-16 09:34:53 +030067 if not self.vpp_dead:
68 self.logger.info(self.vapi.ppcli("show interface span"))
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +010069
Eyal Bari001fd402017-07-16 09:34:53 +030070 def xconnect(self, a, b, is_add=1):
71 self.vapi.sw_interface_set_l2_xconnect(a, b, enable=is_add)
72 self.vapi.sw_interface_set_l2_xconnect(b, a, enable=is_add)
73
74 def bridge(self, sw_if_index, is_add=1):
75 self.vapi.sw_interface_set_l2_bridge(
76 sw_if_index, bd_id=self.bd_id, enable=is_add)
77
78 def _remove_tag(self, packet, vlan, tag_type):
79 self.assertEqual(packet.type, tag_type)
80 payload = packet.payload
81 self.assertEqual(payload.vlan, vlan)
82 inner_type = payload.type
83 payload = payload.payload
84 packet.remove_payload()
85 packet.add_payload(payload)
86 packet.type = inner_type
87
88 def remove_tags(self, packet, tags):
89 for t in tags:
90 self._remove_tag(packet, t.vlan, t.dot1)
91 return packet
92
93 def decap_gre(self, pkt):
94 """
95 Decapsulate the original payload frame by removing GRE header
96 """
97 self.assertEqual(pkt[Ether].src, self.pg2.local_mac)
98 self.assertEqual(pkt[Ether].dst, self.pg2.remote_mac)
99
100 self.assertEqual(pkt[IP].src, self.pg2.local_ip4)
101 self.assertEqual(pkt[IP].dst, self.pg2.remote_ip4)
102
103 return pkt[GRE].payload
104
John Lo2bf8b812018-02-27 16:35:03 -0500105 def decap_erspan(self, pkt, session):
106 """
107 Decapsulate the original payload frame by removing ERSPAN header
108 """
109 self.assertEqual(pkt[Ether].src, self.pg2.local_mac)
110 self.assertEqual(pkt[Ether].dst, self.pg2.remote_mac)
111
112 self.assertEqual(pkt[IP].src, self.pg2.local_ip4)
113 self.assertEqual(pkt[IP].dst, self.pg2.remote_ip4)
114
115 self.assertEqual(pkt[ERSPAN].ver, 1)
116 self.assertEqual(pkt[ERSPAN].vlan, 0)
117 self.assertEqual(pkt[ERSPAN].cos, 0)
118 self.assertEqual(pkt[ERSPAN].en, 3)
119 self.assertEqual(pkt[ERSPAN].t, 0)
120 self.assertEqual(pkt[ERSPAN].session_id, session)
121 self.assertEqual(pkt[ERSPAN].reserved, 0)
122 self.assertEqual(pkt[ERSPAN].index, 0)
123
124 return pkt[ERSPAN].payload
125
Eyal Bari001fd402017-07-16 09:34:53 +0300126 def decap_vxlan(self, pkt):
127 """
128 Decapsulate the original payload frame by removing VXLAN header
129 """
130 self.assertEqual(pkt[Ether].src, self.pg2.local_mac)
131 self.assertEqual(pkt[Ether].dst, self.pg2.remote_mac)
132
133 self.assertEqual(pkt[IP].src, self.pg2.local_ip4)
134 self.assertEqual(pkt[IP].dst, self.pg2.remote_ip4)
135
136 return pkt[VXLAN].payload
137
Eyal Bari17142b22017-10-16 13:38:21 +0300138 def create_stream(self, src_if, packet_sizes, do_dot1=False, bcast=False):
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100139 pkts = []
Eyal Baricdeb7f22017-10-15 16:55:11 +0300140 dst_if = self.flows[src_if][0]
Eyal Bari17142b22017-10-16 13:38:21 +0300141 dst_mac = src_if.remote_mac
142 if bcast:
143 dst_mac = "ff:ff:ff:ff:ff:ff"
144
Eyal Bari001fd402017-07-16 09:34:53 +0300145 for i in range(0, self.pkts_per_burst):
Eyal Bari17142b22017-10-16 13:38:21 +0300146 payload = "span test"
Eyal Baricdeb7f22017-10-15 16:55:11 +0300147 size = packet_sizes[(i / 2) % len(packet_sizes)]
Eyal Bari17142b22017-10-16 13:38:21 +0300148 p = (Ether(src=src_if.local_mac, dst=dst_mac) /
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100149 IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4) /
Eyal Baricdeb7f22017-10-15 16:55:11 +0300150 UDP(sport=10000 + src_if.sw_if_index * 1000 + i, dport=1234) /
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100151 Raw(payload))
Eyal Bari001fd402017-07-16 09:34:53 +0300152 if do_dot1:
153 p = self.sub_if.add_dot1_layer(p)
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100154 self.extend_packet(p, size)
155 pkts.append(p)
156 return pkts
157
Eyal Baricdeb7f22017-10-15 16:55:11 +0300158 def verify_capture(self, cap1, cap2):
159 self.assertEqual(len(cap1), len(cap2),
160 "Different number of sent and mirrored packets :"
161 "%u != %u" % (len(cap1), len(cap2)))
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100162
Eyal Baricdeb7f22017-10-15 16:55:11 +0300163 pkts1 = [(pkt[Ether] / pkt[IP] / pkt[UDP]) for pkt in cap1]
164 pkts2 = [(pkt[Ether] / pkt[IP] / pkt[UDP]) for pkt in cap2]
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100165
Eyal Baricdeb7f22017-10-15 16:55:11 +0300166 self.assertEqual(pkts1.sort(), pkts2.sort())
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100167
Eyal Bari001fd402017-07-16 09:34:53 +0300168 def test_device_span(self):
Eyal Bari17142b22017-10-16 13:38:21 +0300169 """ SPAN device rx mirror """
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100170
Eyal Bari001fd402017-07-16 09:34:53 +0300171 # Create bi-directional cross-connects between pg0 and pg1
172 self.xconnect(self.pg0.sw_if_index, self.pg1.sw_if_index)
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100173 # Create incoming packet streams for packet-generator interfaces
174 pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes)
175 self.pg0.add_stream(pkts)
176
Eyal Bari001fd402017-07-16 09:34:53 +0300177 # Enable SPAN on pg0 (mirrored to pg2)
178 self.vapi.sw_interface_span_enable_disable(
179 self.pg0.sw_if_index, self.pg2.sw_if_index)
180
181 self.logger.info(self.vapi.ppcli("show interface span"))
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100182 # Enable packet capturing and start packet sending
183 self.pg_enable_capture(self.pg_interfaces)
184 self.pg_start()
185
186 # Verify packets outgoing packet streams on mirrored interface (pg2)
Eyal Bari17142b22017-10-16 13:38:21 +0300187 n_pkts = len(pkts)
Eyal Baricdeb7f22017-10-15 16:55:11 +0300188 pg1_pkts = self.pg1.get_capture(n_pkts)
189 pg2_pkts = self.pg2.get_capture(n_pkts)
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100190
Eyal Bari001fd402017-07-16 09:34:53 +0300191 # Disable SPAN on pg0 (mirrored to pg2)
192 self.vapi.sw_interface_span_enable_disable(
193 self.pg0.sw_if_index, self.pg2.sw_if_index, state=0)
194 self.xconnect(self.pg0.sw_if_index, self.pg1.sw_if_index, is_add=0)
195
Eyal Baricdeb7f22017-10-15 16:55:11 +0300196 self.verify_capture(pg1_pkts, pg2_pkts)
197
Eyal Bari001fd402017-07-16 09:34:53 +0300198 def test_span_l2_rx(self):
Eyal Bari17142b22017-10-16 13:38:21 +0300199 """ SPAN l2 rx mirror """
Eyal Bari001fd402017-07-16 09:34:53 +0300200
201 self.sub_if.admin_up()
202
203 self.bridge(self.pg2.sw_if_index)
Eyal Bari17142b22017-10-16 13:38:21 +0300204 # Create bi-directional cross-connects between pg0 subif and pg1
Eyal Bari001fd402017-07-16 09:34:53 +0300205 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index)
206 # Create incoming packet streams for packet-generator interfaces
207 pkts = self.create_stream(
208 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
209 self.pg0.add_stream(pkts)
210
211 # Enable SPAN on pg0 (mirrored to pg2)
212 self.vapi.sw_interface_span_enable_disable(
213 self.sub_if.sw_if_index, self.pg2.sw_if_index, is_l2=1)
214
215 self.logger.info(self.vapi.ppcli("show interface span"))
216 # Enable packet capturing and start packet sending
217 self.pg_enable_capture(self.pg_interfaces)
218 self.pg_start()
219
220 # Verify packets outgoing packet streams on mirrored interface (pg2)
Eyal Baricdeb7f22017-10-15 16:55:11 +0300221 pg2_expected = len(pkts)
222 pg1_pkts = self.pg1.get_capture(pg2_expected)
Eyal Bari001fd402017-07-16 09:34:53 +0300223 pg2_pkts = self.pg2.get_capture(pg2_expected)
Eyal Bari001fd402017-07-16 09:34:53 +0300224 self.bridge(self.pg2.sw_if_index, is_add=0)
Eyal Baricdeb7f22017-10-15 16:55:11 +0300225
Eyal Bari001fd402017-07-16 09:34:53 +0300226 # Disable SPAN on pg0 (mirrored to pg2)
227 self.vapi.sw_interface_span_enable_disable(
228 self.sub_if.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1)
229 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
230
Eyal Baricdeb7f22017-10-15 16:55:11 +0300231 self.verify_capture(pg1_pkts, pg2_pkts)
232
Eyal Bari001fd402017-07-16 09:34:53 +0300233 def test_span_l2_rx_dst_vxlan(self):
Eyal Bari17142b22017-10-16 13:38:21 +0300234 """ SPAN l2 rx mirror into vxlan """
Eyal Bari001fd402017-07-16 09:34:53 +0300235
236 self.sub_if.admin_up()
237 self.vapi.sw_interface_set_flags(self.vxlan.sw_if_index,
238 admin_up_down=1)
239
240 self.bridge(self.vxlan.sw_if_index, is_add=1)
Eyal Bari17142b22017-10-16 13:38:21 +0300241 # Create bi-directional cross-connects between pg0 subif and pg1
Eyal Bari001fd402017-07-16 09:34:53 +0300242 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index)
243 # Create incoming packet streams for packet-generator interfaces
244 pkts = self.create_stream(
245 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
246 self.pg0.add_stream(pkts)
247
248 # Enable SPAN on pg0 sub if (mirrored to vxlan)
249 self.vapi.sw_interface_span_enable_disable(
250 self.sub_if.sw_if_index, self.vxlan.sw_if_index, is_l2=1)
251
252 self.logger.info(self.vapi.ppcli("show interface span"))
253 # Enable packet capturing and start packet sending
254 self.pg_enable_capture(self.pg_interfaces)
255 self.pg_start()
256
257 # Verify packets outgoing packet streams on mirrored interface (pg2)
Eyal Bari17142b22017-10-16 13:38:21 +0300258 n_pkts = len(pkts)
259 pg1_pkts = self.pg1.get_capture(n_pkts)
260 pg2_pkts = [self.decap_vxlan(p) for p in self.pg2.get_capture(n_pkts)]
Eyal Bari001fd402017-07-16 09:34:53 +0300261
262 self.bridge(self.vxlan.sw_if_index, is_add=0)
263 # Disable SPAN on pg0 sub if (mirrored to vxlan)
264 self.vapi.sw_interface_span_enable_disable(
265 self.sub_if.sw_if_index, self.vxlan.sw_if_index, state=0, is_l2=1)
266 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
Eyal Baricdeb7f22017-10-15 16:55:11 +0300267 self.verify_capture(pg1_pkts, pg2_pkts)
Eyal Bari001fd402017-07-16 09:34:53 +0300268
John Lo2bf8b812018-02-27 16:35:03 -0500269 def test_span_l2_rx_dst_gre_erspan(self):
270 """ SPAN l2 rx mirror into gre-erspan """
271
272 self.sub_if.admin_up()
273
274 gre_if = VppGreInterface(self, self.pg2.local_ip4,
275 self.pg2.remote_ip4,
276 type=2,
277 session=543)
278
279 gre_if.add_vpp_config()
280 gre_if.admin_up()
281
282 self.bridge(gre_if.sw_if_index)
283 # Create bi-directional cross-connects between pg0 and pg1
284 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1)
285
286 # Create incoming packet streams for packet-generator interfaces
287 pkts = self.create_stream(
288 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
289 self.pg0.add_stream(pkts)
290
291 # Enable SPAN on pg0 sub if (mirrored to gre-erspan)
292 self.vapi.sw_interface_span_enable_disable(
293 self.sub_if.sw_if_index, gre_if.sw_if_index, is_l2=1)
294
295 # Enable packet capturing and start packet sending
296 self.pg_enable_capture(self.pg_interfaces)
297 self.pg_start()
298
299 # Verify packets outgoing packet streams on mirrored interface (pg2)
300 n_pkts = len(pkts)
301 pg1_pkts = self.pg1.get_capture(n_pkts)
302 pg2_pkts = self.pg2.get_capture(n_pkts)
303
304 def decap(p): return self.decap_erspan(p, session=543)
305 pg2_decaped = [decap(p) for p in pg2_pkts]
306
307 self.bridge(gre_if.sw_if_index, is_add=0)
308
309 # Disable SPAN on pg0 sub if
310 self.vapi.sw_interface_span_enable_disable(
311 self.sub_if.sw_if_index, gre_if.sw_if_index, state=0, is_l2=1)
312 gre_if.remove_vpp_config()
313 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
314
315 self.verify_capture(pg1_pkts, pg2_decaped)
316
Eyal Bari001fd402017-07-16 09:34:53 +0300317 def test_span_l2_rx_dst_gre_subif_vtr(self):
318 """ SPAN l2 rx mirror into gre-subif+vtr """
319
320 self.sub_if.admin_up()
321
322 gre_if = VppGreInterface(self, self.pg2.local_ip4,
323 self.pg2.remote_ip4,
John Loa43ccae2018-02-13 17:15:23 -0500324 type=1)
Eyal Bari001fd402017-07-16 09:34:53 +0300325
326 gre_if.add_vpp_config()
327 gre_if.admin_up()
328
329 gre_sub_if = VppDot1QSubint(self, gre_if, 500)
330 gre_sub_if.set_vtr(L2_VTR_OP.L2_POP_1, tag=500)
331 gre_sub_if.admin_up()
332
333 self.bridge(gre_sub_if.sw_if_index)
334 # Create bi-directional cross-connects between pg0 and pg1
335 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1)
336
337 # Create incoming packet streams for packet-generator interfaces
338 pkts = self.create_stream(
339 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
340 self.pg0.add_stream(pkts)
341
John Lo2bf8b812018-02-27 16:35:03 -0500342 # Enable SPAN on pg0 sub if (mirrored to gre sub if)
Eyal Bari001fd402017-07-16 09:34:53 +0300343 self.vapi.sw_interface_span_enable_disable(
344 self.sub_if.sw_if_index, gre_sub_if.sw_if_index, is_l2=1)
345
346 # Enable packet capturing and start packet sending
347 self.pg_enable_capture(self.pg_interfaces)
348 self.pg_start()
349
350 # Verify packets outgoing packet streams on mirrored interface (pg2)
Eyal Bari17142b22017-10-16 13:38:21 +0300351 n_pkts = len(pkts)
352 pg1_pkts = self.pg1.get_capture(n_pkts)
353 pg2_pkts = self.pg2.get_capture(n_pkts)
354
355 def decap(p): return self.remove_tags(
356 self.decap_gre(p), [Tag(dot1=DOT1Q, vlan=500)])
357 pg2_decaped = [decap(p) for p in pg2_pkts]
358
Eyal Bari001fd402017-07-16 09:34:53 +0300359 self.bridge(gre_sub_if.sw_if_index, is_add=0)
Eyal Baricdeb7f22017-10-15 16:55:11 +0300360
Eyal Bari001fd402017-07-16 09:34:53 +0300361 # Disable SPAN on pg0 sub if
362 self.vapi.sw_interface_span_enable_disable(
Eyal Baricdeb7f22017-10-15 16:55:11 +0300363 self.sub_if.sw_if_index, gre_sub_if.sw_if_index, state=0, is_l2=1)
Eyal Bari001fd402017-07-16 09:34:53 +0300364 gre_if.remove_vpp_config()
365 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
366
Eyal Baricdeb7f22017-10-15 16:55:11 +0300367 self.verify_capture(pg1_pkts, pg2_decaped)
368
Eyal Bari17142b22017-10-16 13:38:21 +0300369 def test_span_l2_rx_dst_1q_vtr(self):
370 """ SPAN l2 rx mirror into 1q subif+vtr """
Eyal Bari001fd402017-07-16 09:34:53 +0300371
372 self.sub_if.admin_up()
Eyal Bari17142b22017-10-16 13:38:21 +0300373 self.vlan_sub_if.admin_up()
Eyal Bari001fd402017-07-16 09:34:53 +0300374
Eyal Bari17142b22017-10-16 13:38:21 +0300375 self.bridge(self.vlan_sub_if.sw_if_index)
Eyal Bari001fd402017-07-16 09:34:53 +0300376 # Create bi-directional cross-connects between pg0 and pg1
377 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1)
378
379 # Create incoming packet streams for packet-generator interfaces
380 pkts = self.create_stream(
381 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
382 self.pg0.add_stream(pkts)
383
384 self.vapi.sw_interface_span_enable_disable(
Eyal Bari17142b22017-10-16 13:38:21 +0300385 self.sub_if.sw_if_index, self.vlan_sub_if.sw_if_index, is_l2=1)
Eyal Bari001fd402017-07-16 09:34:53 +0300386
387 # Enable packet capturing and start packet sending
388 self.pg_enable_capture(self.pg_interfaces)
389 self.pg_start()
390
391 # Verify packets outgoing packet streams on mirrored interface (pg2)
Eyal Bari17142b22017-10-16 13:38:21 +0300392 n_pkts = len(pkts)
393 pg1_pkts = self.pg1.get_capture(n_pkts)
394 pg2_pkts = self.pg2.get_capture(n_pkts)
Eyal Bari001fd402017-07-16 09:34:53 +0300395 pg2_untagged = [self.remove_tags(p, [Tag(dot1=DOT1Q, vlan=300)])
396 for p in pg2_pkts]
Eyal Bari001fd402017-07-16 09:34:53 +0300397
Eyal Bari17142b22017-10-16 13:38:21 +0300398 self.bridge(self.vlan_sub_if.sw_if_index, is_add=0)
Eyal Bari001fd402017-07-16 09:34:53 +0300399 # Disable SPAN on pg0 sub if (mirrored to vxlan)
400 self.vapi.sw_interface_span_enable_disable(
Eyal Bari17142b22017-10-16 13:38:21 +0300401 self.sub_if.sw_if_index, self.vlan_sub_if.sw_if_index, state=0,
402 is_l2=1)
403 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
404
405 self.verify_capture(pg1_pkts, pg2_untagged)
406
407 def test_span_l2_rx_dst_1ad_vtr(self):
408 """ SPAN l2 rx mirror into 1ad subif+vtr """
409
410 self.sub_if.admin_up()
411 self.qinq_sub_if.admin_up()
412
413 self.bridge(self.qinq_sub_if.sw_if_index)
414 # Create bi-directional cross-connects between pg0 and pg1
415 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1)
416
417 # Create incoming packet streams for packet-generator interfaces
418 pkts = self.create_stream(
419 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
420 self.pg0.add_stream(pkts)
421
422 self.vapi.sw_interface_span_enable_disable(
423 self.sub_if.sw_if_index, self.qinq_sub_if.sw_if_index, is_l2=1)
424
425 # Enable packet capturing and start packet sending
426 self.pg_enable_capture(self.pg_interfaces)
427 self.pg_start()
428
429 # Verify packets outgoing packet streams on mirrored interface (pg2)
430 n_pkts = len(pkts)
431 pg1_pkts = self.pg1.get_capture(n_pkts)
432 pg2_pkts = self.pg2.get_capture(n_pkts)
433 pg2_untagged = [self.remove_tags(p, [Tag(dot1=DOT1AD, vlan=400),
434 Tag(dot1=DOT1Q, vlan=500)])
435 for p in pg2_pkts]
436
437 self.bridge(self.qinq_sub_if.sw_if_index, is_add=0)
438 # Disable SPAN on pg0 sub if (mirrored to vxlan)
439 self.vapi.sw_interface_span_enable_disable(
440 self.sub_if.sw_if_index, self.qinq_sub_if.sw_if_index, state=0,
Eyal Bari001fd402017-07-16 09:34:53 +0300441 is_l2=1)
442 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
443
Eyal Baricdeb7f22017-10-15 16:55:11 +0300444 self.verify_capture(pg1_pkts, pg2_untagged)
445
Eyal Bari001fd402017-07-16 09:34:53 +0300446 def test_l2_tx_span(self):
Eyal Bari17142b22017-10-16 13:38:21 +0300447 """ SPAN l2 tx mirror """
Eyal Bari001fd402017-07-16 09:34:53 +0300448
449 self.sub_if.admin_up()
450 self.bridge(self.pg2.sw_if_index)
451 # Create bi-directional cross-connects between pg0 and pg1
452 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index)
453 # Create incoming packet streams for packet-generator interfaces
454 pkts = self.create_stream(
455 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
456 self.pg0.add_stream(pkts)
457
Eyal Baricdeb7f22017-10-15 16:55:11 +0300458 # Enable SPAN on pg1 (mirrored to pg2)
Eyal Bari001fd402017-07-16 09:34:53 +0300459 self.vapi.sw_interface_span_enable_disable(
460 self.pg1.sw_if_index, self.pg2.sw_if_index, is_l2=1, state=2)
461
462 self.logger.info(self.vapi.ppcli("show interface span"))
463 # Enable packet capturing and start packet sending
464 self.pg_enable_capture(self.pg_interfaces)
465 self.pg_start()
466
467 # Verify packets outgoing packet streams on mirrored interface (pg2)
Eyal Bari17142b22017-10-16 13:38:21 +0300468 n_pkts = len(pkts)
469 pg1_pkts = self.pg1.get_capture(n_pkts)
470 pg2_pkts = self.pg2.get_capture(n_pkts)
Eyal Bari001fd402017-07-16 09:34:53 +0300471 self.bridge(self.pg2.sw_if_index, is_add=0)
472 # Disable SPAN on pg0 (mirrored to pg2)
473 self.vapi.sw_interface_span_enable_disable(
474 self.pg1.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1)
475 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
476
Eyal Baricdeb7f22017-10-15 16:55:11 +0300477 self.verify_capture(pg1_pkts, pg2_pkts)
478
479 def test_l2_rx_tx_span(self):
Eyal Bari17142b22017-10-16 13:38:21 +0300480 """ SPAN l2 rx tx mirror """
Eyal Baricdeb7f22017-10-15 16:55:11 +0300481
482 self.sub_if.admin_up()
483 self.bridge(self.pg2.sw_if_index)
484 # Create bi-directional cross-connects between pg0 and pg1
485 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index)
486
487 # Create incoming packet streams for packet-generator interfaces
488 pg0_pkts = self.create_stream(
489 self.pg0, self.pg_if_packet_sizes, do_dot1=True)
490 self.pg0.add_stream(pg0_pkts)
491 pg1_pkts = self.create_stream(
492 self.pg1, self.pg_if_packet_sizes, do_dot1=False)
493 self.pg1.add_stream(pg1_pkts)
494
495 # Enable SPAN on pg0 (mirrored to pg2)
496 self.vapi.sw_interface_span_enable_disable(
497 self.sub_if.sw_if_index, self.pg2.sw_if_index, is_l2=1, state=3)
498 self.logger.info(self.vapi.ppcli("show interface span"))
499
500 # Enable packet capturing and start packet sending
501 self.pg_enable_capture(self.pg_interfaces)
502 self.pg_start()
503
504 # Verify packets outgoing packet streams on mirrored interface (pg2)
Eyal Bari17142b22017-10-16 13:38:21 +0300505 pg0_expected = len(pg1_pkts)
506 pg1_expected = len(pg0_pkts)
Eyal Baricdeb7f22017-10-15 16:55:11 +0300507 pg2_expected = pg0_expected + pg1_expected
508
509 pg0_pkts = self.pg0.get_capture(pg0_expected)
510 pg1_pkts = self.pg1.get_capture(pg1_expected)
511 pg2_pkts = self.pg2.get_capture(pg2_expected)
512
513 self.bridge(self.pg2.sw_if_index, is_add=0)
514 # Disable SPAN on pg0 (mirrored to pg2)
515 self.vapi.sw_interface_span_enable_disable(
516 self.sub_if.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1)
517 self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0)
518
519 self.verify_capture(pg0_pkts + pg1_pkts, pg2_pkts)
520
Eyal Bari17142b22017-10-16 13:38:21 +0300521 def test_l2_bcast_mirror(self):
522 """ SPAN l2 broadcast mirror """
523
524 self.sub_if.admin_up()
525 self.bridge(self.pg2.sw_if_index)
526
527 # Create bi-directional cross-connects between pg0 and pg1
528 self.vapi.sw_interface_set_l2_bridge(
529 self.sub_if.sw_if_index, bd_id=99, enable=1)
530 self.vapi.sw_interface_set_l2_bridge(
531 self.pg1.sw_if_index, bd_id=99, enable=1)
532
533 # Create incoming packet streams for packet-generator interfaces
534 pg0_pkts = self.create_stream(
535 self.pg0, self.pg_if_packet_sizes, do_dot1=True, bcast=True)
536 self.pg0.add_stream(pg0_pkts)
537 pg1_pkts = self.create_stream(
538 self.pg1, self.pg_if_packet_sizes, do_dot1=False, bcast=True)
539 self.pg1.add_stream(pg1_pkts)
540
541 # Enable SPAN on pg0 (mirrored to pg2)
542 self.vapi.sw_interface_span_enable_disable(
543 self.sub_if.sw_if_index, self.pg2.sw_if_index, is_l2=1, state=3)
544 self.logger.info(self.vapi.ppcli("show interface span"))
545
546 # Enable packet capturing and start packet sending
547 self.pg_enable_capture(self.pg_interfaces)
548 self.pg_start()
549
550 # Verify packets outgoing packet streams on mirrored interface (pg2)
551 pg0_expected = len(pg1_pkts)
552 pg1_expected = len(pg0_pkts)
553 pg2_expected = pg0_expected + pg1_expected
554
555 pg0_pkts = self.pg0.get_capture(pg0_expected)
556 pg1_pkts = self.pg1.get_capture(pg1_expected)
557 pg2_pkts = self.pg2.get_capture(pg2_expected)
558
559 self.bridge(self.pg2.sw_if_index, is_add=0)
560 self.vapi.sw_interface_set_l2_bridge(
561 self.sub_if.sw_if_index, bd_id=99, enable=0)
562 self.vapi.sw_interface_set_l2_bridge(
563 self.pg1.sw_if_index, bd_id=99, enable=0)
564 # Disable SPAN on pg0 (mirrored to pg2)
565 self.vapi.sw_interface_span_enable_disable(
566 self.sub_if.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1)
567
568 self.verify_capture(pg0_pkts + pg1_pkts, pg2_pkts)
569
Pavel Kotucekf6e3dc42016-11-04 09:58:01 +0100570
571if __name__ == '__main__':
572 unittest.main(testRunner=VppTestRunner)