Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 2 | |
| 3 | import unittest |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 4 | |
| 5 | from scapy.packet import Raw |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 6 | from scapy.layers.l2 import Ether, GRE, ERSPAN |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 7 | from scapy.layers.inet import IP, UDP |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 8 | from scapy.layers.vxlan import VXLAN |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 9 | |
Dave Wallace | 8800f73 | 2023-08-31 00:47:44 -0400 | [diff] [blame] | 10 | from framework import VppTestCase |
| 11 | from asfframework import VppTestRunner |
Paul Vinciguerra | 95c0ca4 | 2019-03-28 13:07:00 -0700 | [diff] [blame] | 12 | from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint, VppDot1ADSubint |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 13 | from vpp_gre_interface import VppGreInterface |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 14 | from vpp_vxlan_tunnel import VppVxlanTunnel |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 15 | from collections import namedtuple |
Neale Ranns | 5a8844b | 2019-04-16 07:15:35 +0000 | [diff] [blame] | 16 | from vpp_papi import VppEnum |
| 17 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 18 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 19 | Tag = namedtuple("Tag", ["dot1", "vlan"]) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 20 | DOT1AD = 0x88A8 |
| 21 | DOT1Q = 0x8100 |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 22 | |
| 23 | |
| 24 | class TestSpan(VppTestCase): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 25 | """SPAN Test Case""" |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 26 | |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 27 | @classmethod |
| 28 | def setUpClass(cls): |
| 29 | super(TestSpan, cls).setUpClass() |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 30 | # Test variables |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 31 | cls.pkts_per_burst = 257 # Number of packets per burst |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 32 | # create 3 pg interfaces |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 33 | cls.create_pg_interfaces(range(3)) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 34 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 35 | cls.bd_id = 55 |
| 36 | cls.sub_if = VppDot1QSubint(cls, cls.pg0, 100) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 37 | cls.vlan_sub_if = VppDot1QSubint(cls, cls.pg2, 300) |
| 38 | cls.vlan_sub_if.set_vtr(L2_VTR_OP.L2_POP_1, tag=300) |
| 39 | |
| 40 | cls.qinq_sub_if = VppDot1ADSubint(cls, cls.pg2, 33, 400, 500) |
| 41 | cls.qinq_sub_if.set_vtr(L2_VTR_OP.L2_POP_2, outer=500, inner=400) |
| 42 | |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 43 | # packet flows mapping pg0 -> pg1, pg2 -> pg3, etc. |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 44 | cls.flows = dict() |
| 45 | cls.flows[cls.pg0] = [cls.pg1] |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 46 | cls.flows[cls.pg1] = [cls.pg0] |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 47 | |
| 48 | # packet sizes |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 49 | cls.pg_if_packet_sizes = [64, 512, 1518] # , 9018] |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 50 | |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 51 | # setup all interfaces |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 52 | for i in cls.pg_interfaces: |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 53 | i.admin_up() |
| 54 | i.config_ip4() |
| 55 | i.resolve_arp() |
| 56 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 57 | def setUp(self): |
| 58 | super(TestSpan, self).setUp() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 59 | self.vxlan = VppVxlanTunnel( |
| 60 | self, src=self.pg2.local_ip4, dst=self.pg2.remote_ip4, vni=1111 |
| 61 | ) |
Jakub Grajciar | 7c0eb56 | 2020-03-02 13:55:31 +0100 | [diff] [blame] | 62 | self.vxlan.add_vpp_config() |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 63 | self.reset_packet_infos() |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 64 | |
| 65 | def tearDown(self): |
| 66 | super(TestSpan, self).tearDown() |
Paul Vinciguerra | 90cf21b | 2019-03-13 09:23:05 -0700 | [diff] [blame] | 67 | |
| 68 | def show_commands_at_teardown(self): |
| 69 | self.logger.info(self.vapi.ppcli("show interface span")) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 70 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 71 | def xconnect(self, a, b, is_add=1): |
| 72 | self.vapi.sw_interface_set_l2_xconnect(a, b, enable=is_add) |
| 73 | self.vapi.sw_interface_set_l2_xconnect(b, a, enable=is_add) |
| 74 | |
| 75 | def bridge(self, sw_if_index, is_add=1): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 76 | self.vapi.sw_interface_set_l2_bridge( |
| 77 | rx_sw_if_index=sw_if_index, bd_id=self.bd_id, enable=is_add |
| 78 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 79 | |
| 80 | def _remove_tag(self, packet, vlan, tag_type): |
| 81 | self.assertEqual(packet.type, tag_type) |
| 82 | payload = packet.payload |
| 83 | self.assertEqual(payload.vlan, vlan) |
| 84 | inner_type = payload.type |
| 85 | payload = payload.payload |
| 86 | packet.remove_payload() |
| 87 | packet.add_payload(payload) |
| 88 | packet.type = inner_type |
| 89 | |
| 90 | def remove_tags(self, packet, tags): |
| 91 | for t in tags: |
| 92 | self._remove_tag(packet, t.vlan, t.dot1) |
| 93 | return packet |
| 94 | |
| 95 | def decap_gre(self, pkt): |
| 96 | """ |
| 97 | Decapsulate the original payload frame by removing GRE header |
| 98 | """ |
| 99 | self.assertEqual(pkt[Ether].src, self.pg2.local_mac) |
| 100 | self.assertEqual(pkt[Ether].dst, self.pg2.remote_mac) |
| 101 | |
| 102 | self.assertEqual(pkt[IP].src, self.pg2.local_ip4) |
| 103 | self.assertEqual(pkt[IP].dst, self.pg2.remote_ip4) |
| 104 | |
| 105 | return pkt[GRE].payload |
| 106 | |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 107 | def decap_erspan(self, pkt, session): |
| 108 | """ |
| 109 | Decapsulate the original payload frame by removing ERSPAN header |
| 110 | """ |
| 111 | self.assertEqual(pkt[Ether].src, self.pg2.local_mac) |
| 112 | self.assertEqual(pkt[Ether].dst, self.pg2.remote_mac) |
| 113 | |
| 114 | self.assertEqual(pkt[IP].src, self.pg2.local_ip4) |
| 115 | self.assertEqual(pkt[IP].dst, self.pg2.remote_ip4) |
| 116 | |
| 117 | self.assertEqual(pkt[ERSPAN].ver, 1) |
| 118 | self.assertEqual(pkt[ERSPAN].vlan, 0) |
| 119 | self.assertEqual(pkt[ERSPAN].cos, 0) |
| 120 | self.assertEqual(pkt[ERSPAN].en, 3) |
| 121 | self.assertEqual(pkt[ERSPAN].t, 0) |
| 122 | self.assertEqual(pkt[ERSPAN].session_id, session) |
| 123 | self.assertEqual(pkt[ERSPAN].reserved, 0) |
| 124 | self.assertEqual(pkt[ERSPAN].index, 0) |
| 125 | |
| 126 | return pkt[ERSPAN].payload |
| 127 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 128 | def decap_vxlan(self, pkt): |
| 129 | """ |
| 130 | Decapsulate the original payload frame by removing VXLAN header |
| 131 | """ |
| 132 | self.assertEqual(pkt[Ether].src, self.pg2.local_mac) |
| 133 | self.assertEqual(pkt[Ether].dst, self.pg2.remote_mac) |
| 134 | |
| 135 | self.assertEqual(pkt[IP].src, self.pg2.local_ip4) |
| 136 | self.assertEqual(pkt[IP].dst, self.pg2.remote_ip4) |
| 137 | |
| 138 | return pkt[VXLAN].payload |
| 139 | |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 140 | def create_stream(self, src_if, packet_sizes, do_dot1=False, bcast=False): |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 141 | pkts = [] |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 142 | dst_if = self.flows[src_if][0] |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 143 | dst_mac = src_if.remote_mac |
| 144 | if bcast: |
| 145 | dst_mac = "ff:ff:ff:ff:ff:ff" |
| 146 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 147 | for i in range(0, self.pkts_per_burst): |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 148 | payload = "span test" |
snaramre | 2bb7151 | 2019-10-16 22:15:43 +0000 | [diff] [blame] | 149 | size = packet_sizes[int((i / 2) % len(packet_sizes))] |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 150 | p = ( |
| 151 | Ether(src=src_if.local_mac, dst=dst_mac) |
| 152 | / IP(src=src_if.remote_ip4, dst=dst_if.remote_ip4) |
| 153 | / UDP(sport=10000 + src_if.sw_if_index * 1000 + i, dport=1234) |
| 154 | / Raw(payload) |
| 155 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 156 | if do_dot1: |
| 157 | p = self.sub_if.add_dot1_layer(p) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 158 | self.extend_packet(p, size) |
| 159 | pkts.append(p) |
| 160 | return pkts |
| 161 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 162 | def verify_capture(self, cap1, cap2): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 163 | self.assertEqual( |
| 164 | len(cap1), |
| 165 | len(cap2), |
| 166 | "Different number of sent and mirrored packets :" |
| 167 | "%u != %u" % (len(cap1), len(cap2)), |
| 168 | ) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 169 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 170 | pkts1 = [(pkt[Ether] / pkt[IP] / pkt[UDP]) for pkt in cap1] |
| 171 | pkts2 = [(pkt[Ether] / pkt[IP] / pkt[UDP]) for pkt in cap2] |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 172 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 173 | self.assertEqual(pkts1.sort(), pkts2.sort()) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 174 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 175 | def test_device_span(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 176 | """SPAN device rx mirror""" |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 177 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 178 | # Create bi-directional cross-connects between pg0 and pg1 |
| 179 | self.xconnect(self.pg0.sw_if_index, self.pg1.sw_if_index) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 180 | # Create incoming packet streams for packet-generator interfaces |
| 181 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes) |
| 182 | self.pg0.add_stream(pkts) |
| 183 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 184 | # Enable SPAN on pg0 (mirrored to pg2) |
| 185 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 186 | self.pg0.sw_if_index, self.pg2.sw_if_index |
| 187 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 188 | |
| 189 | self.logger.info(self.vapi.ppcli("show interface span")) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 190 | # Enable packet capturing and start packet sending |
| 191 | self.pg_enable_capture(self.pg_interfaces) |
| 192 | self.pg_start() |
| 193 | |
| 194 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 195 | n_pkts = len(pkts) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 196 | pg1_pkts = self.pg1.get_capture(n_pkts) |
| 197 | pg2_pkts = self.pg2.get_capture(n_pkts) |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 198 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 199 | # Disable SPAN on pg0 (mirrored to pg2) |
| 200 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 201 | self.pg0.sw_if_index, self.pg2.sw_if_index, state=0 |
| 202 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 203 | self.xconnect(self.pg0.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 204 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 205 | self.verify_capture(pg1_pkts, pg2_pkts) |
| 206 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 207 | def test_span_l2_rx(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 208 | """SPAN l2 rx mirror""" |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 209 | |
| 210 | self.sub_if.admin_up() |
| 211 | |
| 212 | self.bridge(self.pg2.sw_if_index) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 213 | # Create bi-directional cross-connects between pg0 subif and pg1 |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 214 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index) |
| 215 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 216 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 217 | self.pg0.add_stream(pkts) |
| 218 | |
| 219 | # Enable SPAN on pg0 (mirrored to pg2) |
| 220 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 221 | self.sub_if.sw_if_index, self.pg2.sw_if_index, is_l2=1 |
| 222 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 223 | |
| 224 | self.logger.info(self.vapi.ppcli("show interface span")) |
| 225 | # Enable packet capturing and start packet sending |
| 226 | self.pg_enable_capture(self.pg_interfaces) |
| 227 | self.pg_start() |
| 228 | |
| 229 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 230 | pg2_expected = len(pkts) |
| 231 | pg1_pkts = self.pg1.get_capture(pg2_expected) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 232 | pg2_pkts = self.pg2.get_capture(pg2_expected) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 233 | self.bridge(self.pg2.sw_if_index, is_add=0) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 234 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 235 | # Disable SPAN on pg0 (mirrored to pg2) |
| 236 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 237 | self.sub_if.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1 |
| 238 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 239 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 240 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 241 | self.verify_capture(pg1_pkts, pg2_pkts) |
| 242 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 243 | def test_span_l2_rx_dst_vxlan(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 244 | """SPAN l2 rx mirror into vxlan""" |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 245 | |
| 246 | self.sub_if.admin_up() |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 247 | self.vapi.sw_interface_set_flags(self.vxlan.sw_if_index, flags=1) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 248 | |
| 249 | self.bridge(self.vxlan.sw_if_index, is_add=1) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 250 | # Create bi-directional cross-connects between pg0 subif and pg1 |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 251 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index) |
| 252 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 253 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 254 | self.pg0.add_stream(pkts) |
| 255 | |
| 256 | # Enable SPAN on pg0 sub if (mirrored to vxlan) |
| 257 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 258 | self.sub_if.sw_if_index, self.vxlan.sw_if_index, is_l2=1 |
| 259 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 260 | |
| 261 | self.logger.info(self.vapi.ppcli("show interface span")) |
| 262 | # Enable packet capturing and start packet sending |
| 263 | self.pg_enable_capture(self.pg_interfaces) |
| 264 | self.pg_start() |
| 265 | |
| 266 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 267 | n_pkts = len(pkts) |
| 268 | pg1_pkts = self.pg1.get_capture(n_pkts) |
| 269 | pg2_pkts = [self.decap_vxlan(p) for p in self.pg2.get_capture(n_pkts)] |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 270 | |
| 271 | self.bridge(self.vxlan.sw_if_index, is_add=0) |
| 272 | # Disable SPAN on pg0 sub if (mirrored to vxlan) |
| 273 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 274 | self.sub_if.sw_if_index, self.vxlan.sw_if_index, state=0, is_l2=1 |
| 275 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 276 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 277 | self.verify_capture(pg1_pkts, pg2_pkts) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 278 | |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 279 | def test_span_l2_rx_dst_gre_erspan(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 280 | """SPAN l2 rx mirror into gre-erspan""" |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 281 | |
| 282 | self.sub_if.admin_up() |
| 283 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 284 | gre_if = VppGreInterface( |
| 285 | self, |
| 286 | self.pg2.local_ip4, |
| 287 | self.pg2.remote_ip4, |
| 288 | session=543, |
| 289 | type=(VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_ERSPAN), |
| 290 | ) |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 291 | |
| 292 | gre_if.add_vpp_config() |
| 293 | gre_if.admin_up() |
| 294 | |
| 295 | self.bridge(gre_if.sw_if_index) |
| 296 | # Create bi-directional cross-connects between pg0 and pg1 |
| 297 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1) |
| 298 | |
| 299 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 300 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 301 | self.pg0.add_stream(pkts) |
| 302 | |
| 303 | # Enable SPAN on pg0 sub if (mirrored to gre-erspan) |
| 304 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 305 | self.sub_if.sw_if_index, gre_if.sw_if_index, is_l2=1 |
| 306 | ) |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 307 | |
| 308 | # Enable packet capturing and start packet sending |
| 309 | self.pg_enable_capture(self.pg_interfaces) |
| 310 | self.pg_start() |
| 311 | |
| 312 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
| 313 | n_pkts = len(pkts) |
| 314 | pg1_pkts = self.pg1.get_capture(n_pkts) |
| 315 | pg2_pkts = self.pg2.get_capture(n_pkts) |
| 316 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 317 | def decap(p): |
| 318 | return self.decap_erspan(p, session=543) |
| 319 | |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 320 | pg2_decaped = [decap(p) for p in pg2_pkts] |
| 321 | |
| 322 | self.bridge(gre_if.sw_if_index, is_add=0) |
| 323 | |
| 324 | # Disable SPAN on pg0 sub if |
| 325 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 326 | self.sub_if.sw_if_index, gre_if.sw_if_index, state=0, is_l2=1 |
| 327 | ) |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 328 | gre_if.remove_vpp_config() |
| 329 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 330 | |
| 331 | self.verify_capture(pg1_pkts, pg2_decaped) |
| 332 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 333 | def test_span_l2_rx_dst_gre_subif_vtr(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 334 | """SPAN l2 rx mirror into gre-subif+vtr""" |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 335 | |
| 336 | self.sub_if.admin_up() |
| 337 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 338 | gre_if = VppGreInterface( |
| 339 | self, |
| 340 | self.pg2.local_ip4, |
| 341 | self.pg2.remote_ip4, |
| 342 | type=(VppEnum.vl_api_gre_tunnel_type_t.GRE_API_TUNNEL_TYPE_TEB), |
| 343 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 344 | |
| 345 | gre_if.add_vpp_config() |
| 346 | gre_if.admin_up() |
| 347 | |
| 348 | gre_sub_if = VppDot1QSubint(self, gre_if, 500) |
| 349 | gre_sub_if.set_vtr(L2_VTR_OP.L2_POP_1, tag=500) |
| 350 | gre_sub_if.admin_up() |
| 351 | |
| 352 | self.bridge(gre_sub_if.sw_if_index) |
| 353 | # Create bi-directional cross-connects between pg0 and pg1 |
| 354 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1) |
| 355 | |
| 356 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 357 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 358 | self.pg0.add_stream(pkts) |
| 359 | |
John Lo | 2bf8b81 | 2018-02-27 16:35:03 -0500 | [diff] [blame] | 360 | # Enable SPAN on pg0 sub if (mirrored to gre sub if) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 361 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 362 | self.sub_if.sw_if_index, gre_sub_if.sw_if_index, is_l2=1 |
| 363 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 364 | |
| 365 | # Enable packet capturing and start packet sending |
| 366 | self.pg_enable_capture(self.pg_interfaces) |
| 367 | self.pg_start() |
| 368 | |
| 369 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 370 | n_pkts = len(pkts) |
| 371 | pg1_pkts = self.pg1.get_capture(n_pkts) |
| 372 | pg2_pkts = self.pg2.get_capture(n_pkts) |
| 373 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 374 | def decap(p): |
| 375 | return self.remove_tags(self.decap_gre(p), [Tag(dot1=DOT1Q, vlan=500)]) |
| 376 | |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 377 | pg2_decaped = [decap(p) for p in pg2_pkts] |
| 378 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 379 | self.bridge(gre_sub_if.sw_if_index, is_add=0) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 380 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 381 | # Disable SPAN on pg0 sub if |
| 382 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 383 | self.sub_if.sw_if_index, gre_sub_if.sw_if_index, state=0, is_l2=1 |
| 384 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 385 | gre_if.remove_vpp_config() |
| 386 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 387 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 388 | self.verify_capture(pg1_pkts, pg2_decaped) |
| 389 | |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 390 | def test_span_l2_rx_dst_1q_vtr(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 391 | """SPAN l2 rx mirror into 1q subif+vtr""" |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 392 | |
| 393 | self.sub_if.admin_up() |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 394 | self.vlan_sub_if.admin_up() |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 395 | |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 396 | self.bridge(self.vlan_sub_if.sw_if_index) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 397 | # Create bi-directional cross-connects between pg0 and pg1 |
| 398 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1) |
| 399 | |
| 400 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 401 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 402 | self.pg0.add_stream(pkts) |
| 403 | |
| 404 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 405 | self.sub_if.sw_if_index, self.vlan_sub_if.sw_if_index, is_l2=1 |
| 406 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 407 | |
| 408 | # Enable packet capturing and start packet sending |
| 409 | self.pg_enable_capture(self.pg_interfaces) |
| 410 | self.pg_start() |
| 411 | |
| 412 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 413 | n_pkts = len(pkts) |
| 414 | pg1_pkts = self.pg1.get_capture(n_pkts) |
| 415 | pg2_pkts = self.pg2.get_capture(n_pkts) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 416 | pg2_untagged = [ |
| 417 | self.remove_tags(p, [Tag(dot1=DOT1Q, vlan=300)]) for p in pg2_pkts |
| 418 | ] |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 419 | |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 420 | self.bridge(self.vlan_sub_if.sw_if_index, is_add=0) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 421 | # Disable SPAN on pg0 sub if (mirrored to vxlan) |
| 422 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 423 | self.sub_if.sw_if_index, self.vlan_sub_if.sw_if_index, state=0, is_l2=1 |
| 424 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 425 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 426 | |
| 427 | self.verify_capture(pg1_pkts, pg2_untagged) |
| 428 | |
| 429 | def test_span_l2_rx_dst_1ad_vtr(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 430 | """SPAN l2 rx mirror into 1ad subif+vtr""" |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 431 | |
| 432 | self.sub_if.admin_up() |
| 433 | self.qinq_sub_if.admin_up() |
| 434 | |
| 435 | self.bridge(self.qinq_sub_if.sw_if_index) |
| 436 | # Create bi-directional cross-connects between pg0 and pg1 |
| 437 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=1) |
| 438 | |
| 439 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 440 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 441 | self.pg0.add_stream(pkts) |
| 442 | |
| 443 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 444 | self.sub_if.sw_if_index, self.qinq_sub_if.sw_if_index, is_l2=1 |
| 445 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 446 | |
| 447 | # Enable packet capturing and start packet sending |
| 448 | self.pg_enable_capture(self.pg_interfaces) |
| 449 | self.pg_start() |
| 450 | |
| 451 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
| 452 | n_pkts = len(pkts) |
| 453 | pg1_pkts = self.pg1.get_capture(n_pkts) |
| 454 | pg2_pkts = self.pg2.get_capture(n_pkts) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 455 | pg2_untagged = [ |
| 456 | self.remove_tags(p, [Tag(dot1=DOT1AD, vlan=400), Tag(dot1=DOT1Q, vlan=500)]) |
| 457 | for p in pg2_pkts |
| 458 | ] |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 459 | |
| 460 | self.bridge(self.qinq_sub_if.sw_if_index, is_add=0) |
| 461 | # Disable SPAN on pg0 sub if (mirrored to vxlan) |
| 462 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 463 | self.sub_if.sw_if_index, self.qinq_sub_if.sw_if_index, state=0, is_l2=1 |
| 464 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 465 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 466 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 467 | self.verify_capture(pg1_pkts, pg2_untagged) |
| 468 | |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 469 | def test_l2_tx_span(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 470 | """SPAN l2 tx mirror""" |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 471 | |
| 472 | self.sub_if.admin_up() |
| 473 | self.bridge(self.pg2.sw_if_index) |
| 474 | # Create bi-directional cross-connects between pg0 and pg1 |
| 475 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index) |
| 476 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 477 | pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 478 | self.pg0.add_stream(pkts) |
| 479 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 480 | # Enable SPAN on pg1 (mirrored to pg2) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 481 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 482 | self.pg1.sw_if_index, self.pg2.sw_if_index, is_l2=1, state=2 |
| 483 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 484 | |
| 485 | self.logger.info(self.vapi.ppcli("show interface span")) |
| 486 | # Enable packet capturing and start packet sending |
| 487 | self.pg_enable_capture(self.pg_interfaces) |
| 488 | self.pg_start() |
| 489 | |
| 490 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 491 | n_pkts = len(pkts) |
| 492 | pg1_pkts = self.pg1.get_capture(n_pkts) |
| 493 | pg2_pkts = self.pg2.get_capture(n_pkts) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 494 | self.bridge(self.pg2.sw_if_index, is_add=0) |
| 495 | # Disable SPAN on pg0 (mirrored to pg2) |
| 496 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 497 | self.pg1.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1 |
| 498 | ) |
Eyal Bari | 001fd40 | 2017-07-16 09:34:53 +0300 | [diff] [blame] | 499 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 500 | |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 501 | self.verify_capture(pg1_pkts, pg2_pkts) |
| 502 | |
| 503 | def test_l2_rx_tx_span(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 504 | """SPAN l2 rx tx mirror""" |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 505 | |
| 506 | self.sub_if.admin_up() |
| 507 | self.bridge(self.pg2.sw_if_index) |
| 508 | # Create bi-directional cross-connects between pg0 and pg1 |
| 509 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index) |
| 510 | |
| 511 | # Create incoming packet streams for packet-generator interfaces |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 512 | pg0_pkts = self.create_stream(self.pg0, self.pg_if_packet_sizes, do_dot1=True) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 513 | self.pg0.add_stream(pg0_pkts) |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 514 | pg1_pkts = self.create_stream(self.pg1, self.pg_if_packet_sizes, do_dot1=False) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 515 | self.pg1.add_stream(pg1_pkts) |
| 516 | |
| 517 | # Enable SPAN on pg0 (mirrored to pg2) |
| 518 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 519 | self.sub_if.sw_if_index, self.pg2.sw_if_index, is_l2=1, state=3 |
| 520 | ) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 521 | self.logger.info(self.vapi.ppcli("show interface span")) |
| 522 | |
| 523 | # Enable packet capturing and start packet sending |
| 524 | self.pg_enable_capture(self.pg_interfaces) |
| 525 | self.pg_start() |
| 526 | |
| 527 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 528 | pg0_expected = len(pg1_pkts) |
| 529 | pg1_expected = len(pg0_pkts) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 530 | pg2_expected = pg0_expected + pg1_expected |
| 531 | |
| 532 | pg0_pkts = self.pg0.get_capture(pg0_expected) |
| 533 | pg1_pkts = self.pg1.get_capture(pg1_expected) |
| 534 | pg2_pkts = self.pg2.get_capture(pg2_expected) |
| 535 | |
| 536 | self.bridge(self.pg2.sw_if_index, is_add=0) |
| 537 | # Disable SPAN on pg0 (mirrored to pg2) |
| 538 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 539 | self.sub_if.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1 |
| 540 | ) |
Eyal Bari | cdeb7f2 | 2017-10-15 16:55:11 +0300 | [diff] [blame] | 541 | self.xconnect(self.sub_if.sw_if_index, self.pg1.sw_if_index, is_add=0) |
| 542 | |
| 543 | self.verify_capture(pg0_pkts + pg1_pkts, pg2_pkts) |
| 544 | |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 545 | def test_l2_bcast_mirror(self): |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 546 | """SPAN l2 broadcast mirror""" |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 547 | |
| 548 | self.sub_if.admin_up() |
| 549 | self.bridge(self.pg2.sw_if_index) |
| 550 | |
| 551 | # Create bi-directional cross-connects between pg0 and pg1 |
| 552 | self.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 553 | rx_sw_if_index=self.sub_if.sw_if_index, bd_id=99, enable=1 |
| 554 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 555 | self.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 556 | rx_sw_if_index=self.pg1.sw_if_index, bd_id=99, enable=1 |
| 557 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 558 | |
| 559 | # Create incoming packet streams for packet-generator interfaces |
| 560 | pg0_pkts = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 561 | self.pg0, self.pg_if_packet_sizes, do_dot1=True, bcast=True |
| 562 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 563 | self.pg0.add_stream(pg0_pkts) |
| 564 | pg1_pkts = self.create_stream( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 565 | self.pg1, self.pg_if_packet_sizes, do_dot1=False, bcast=True |
| 566 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 567 | self.pg1.add_stream(pg1_pkts) |
| 568 | |
| 569 | # Enable SPAN on pg0 (mirrored to pg2) |
| 570 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 571 | self.sub_if.sw_if_index, self.pg2.sw_if_index, is_l2=1, state=3 |
| 572 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 573 | self.logger.info(self.vapi.ppcli("show interface span")) |
| 574 | |
| 575 | # Enable packet capturing and start packet sending |
| 576 | self.pg_enable_capture(self.pg_interfaces) |
| 577 | self.pg_start() |
| 578 | |
| 579 | # Verify packets outgoing packet streams on mirrored interface (pg2) |
| 580 | pg0_expected = len(pg1_pkts) |
| 581 | pg1_expected = len(pg0_pkts) |
| 582 | pg2_expected = pg0_expected + pg1_expected |
| 583 | |
| 584 | pg0_pkts = self.pg0.get_capture(pg0_expected) |
| 585 | pg1_pkts = self.pg1.get_capture(pg1_expected) |
| 586 | pg2_pkts = self.pg2.get_capture(pg2_expected) |
| 587 | |
| 588 | self.bridge(self.pg2.sw_if_index, is_add=0) |
| 589 | self.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 590 | rx_sw_if_index=self.sub_if.sw_if_index, bd_id=99, enable=0 |
| 591 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 592 | self.vapi.sw_interface_set_l2_bridge( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 593 | rx_sw_if_index=self.pg1.sw_if_index, bd_id=99, enable=0 |
| 594 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 595 | # Disable SPAN on pg0 (mirrored to pg2) |
| 596 | self.vapi.sw_interface_span_enable_disable( |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 597 | self.sub_if.sw_if_index, self.pg2.sw_if_index, state=0, is_l2=1 |
| 598 | ) |
Eyal Bari | 17142b2 | 2017-10-16 13:38:21 +0300 | [diff] [blame] | 599 | |
| 600 | self.verify_capture(pg0_pkts + pg1_pkts, pg2_pkts) |
| 601 | |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 602 | |
Klement Sekera | d9b0c6f | 2022-04-26 19:02:15 +0200 | [diff] [blame] | 603 | if __name__ == "__main__": |
Pavel Kotucek | f6e3dc4 | 2016-11-04 09:58:01 +0100 | [diff] [blame] | 604 | unittest.main(testRunner=VppTestRunner) |