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