Renato Botelho do Couto | ead1e53 | 2019-10-31 13:31:07 -0500 | [diff] [blame] | 1 | #!/usr/bin/env python3 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 2 | |
| 3 | import unittest |
| 4 | |
| 5 | from framework import VppTestCase, VppTestRunner |
Neale Ranns | c0a9314 | 2018-09-05 15:42:26 -0700 | [diff] [blame] | 6 | from vpp_ip import DpoProto |
Neale Ranns | 180279b | 2017-03-16 15:49:09 -0400 | [diff] [blame] | 7 | from vpp_ip_route import VppIpMRoute, VppMRoutePath, VppMFibSignal, \ |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 8 | MRouteItfFlags, MRouteEntryFlags, VppIpTable, FibPathProto |
Neale Ranns | adb17a8 | 2019-08-04 02:41:57 -0700 | [diff] [blame] | 9 | from vpp_gre_interface import VppGreInterface |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 10 | |
| 11 | from scapy.packet import Raw |
Neale Ranns | adb17a8 | 2019-08-04 02:41:57 -0700 | [diff] [blame] | 12 | from scapy.layers.l2 import Ether, GRE |
Klement Sekera | b9ef273 | 2018-06-24 22:49:33 +0200 | [diff] [blame] | 13 | from scapy.layers.inet import IP, UDP, getmacbyip |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 14 | from scapy.layers.inet6 import IPv6, getmacbyip6 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 15 | |
Neale Ranns | 9bea8fb | 2017-02-03 04:34:01 -0800 | [diff] [blame] | 16 | # |
Neale Ranns | cf3561b | 2017-12-13 01:44:25 -0800 | [diff] [blame] | 17 | # The number of packets sent is set to 91 so that when we replicate more than 3 |
Neale Ranns | 9bea8fb | 2017-02-03 04:34:01 -0800 | [diff] [blame] | 18 | # times, which we do for some entries, we will generate more than 256 packets |
Neale Ranns | aaa396a | 2017-02-05 09:12:02 -0800 | [diff] [blame] | 19 | # to the next node in the VLIB graph. Thus we are testing the code's |
Neale Ranns | cf3561b | 2017-12-13 01:44:25 -0800 | [diff] [blame] | 20 | # correctness handling this over-flow. |
| 21 | # It's also an odd number so we hit any single loops. |
Neale Ranns | 9bea8fb | 2017-02-03 04:34:01 -0800 | [diff] [blame] | 22 | # |
Neale Ranns | cf3561b | 2017-12-13 01:44:25 -0800 | [diff] [blame] | 23 | N_PKTS_IN_STREAM = 91 |
Neale Ranns | 9bea8fb | 2017-02-03 04:34:01 -0800 | [diff] [blame] | 24 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 25 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 26 | class TestMFIB(VppTestCase): |
| 27 | """ MFIB Test Case """ |
| 28 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 29 | @classmethod |
| 30 | def setUpClass(cls): |
| 31 | super(TestMFIB, cls).setUpClass() |
| 32 | |
| 33 | @classmethod |
| 34 | def tearDownClass(cls): |
| 35 | super(TestMFIB, cls).tearDownClass() |
| 36 | |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 37 | def setUp(self): |
| 38 | super(TestMFIB, self).setUp() |
| 39 | |
| 40 | def test_mfib(self): |
| 41 | """ MFIB Unit Tests """ |
| 42 | error = self.vapi.cli("test mfib") |
| 43 | |
| 44 | if error: |
| 45 | self.logger.critical(error) |
Paul Vinciguerra | 9a6dafd | 2019-03-06 15:11:28 -0800 | [diff] [blame] | 46 | self.assertNotIn("Failed", error) |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 47 | |
| 48 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 49 | class TestIPMcast(VppTestCase): |
| 50 | """ IP Multicast Test Case """ |
| 51 | |
Paul Vinciguerra | 7f9b7f9 | 2019-03-12 19:23:27 -0700 | [diff] [blame] | 52 | @classmethod |
| 53 | def setUpClass(cls): |
| 54 | super(TestIPMcast, cls).setUpClass() |
| 55 | |
| 56 | @classmethod |
| 57 | def tearDownClass(cls): |
| 58 | super(TestIPMcast, cls).tearDownClass() |
| 59 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 60 | def setUp(self): |
| 61 | super(TestIPMcast, self).setUp() |
| 62 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 63 | # create 8 pg interfaces |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 64 | self.create_pg_interfaces(range(9)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 65 | |
| 66 | # setup interfaces |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 67 | for i in self.pg_interfaces[:8]: |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 68 | i.admin_up() |
| 69 | i.config_ip4() |
| 70 | i.config_ip6() |
| 71 | i.resolve_arp() |
| 72 | i.resolve_ndp() |
| 73 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 74 | # one more in a vrf |
| 75 | tbl4 = VppIpTable(self, 10) |
| 76 | tbl4.add_vpp_config() |
| 77 | self.pg8.set_table_ip4(10) |
| 78 | self.pg8.config_ip4() |
| 79 | |
| 80 | tbl6 = VppIpTable(self, 10, is_ip6=1) |
| 81 | tbl6.add_vpp_config() |
| 82 | self.pg8.set_table_ip6(10) |
| 83 | self.pg8.config_ip6() |
| 84 | |
| 85 | def tearDown(self): |
| 86 | for i in self.pg_interfaces: |
| 87 | i.unconfig_ip4() |
| 88 | i.unconfig_ip6() |
| 89 | i.admin_down() |
| 90 | |
| 91 | self.pg8.set_table_ip4(0) |
| 92 | self.pg8.set_table_ip6(0) |
| 93 | super(TestIPMcast, self).tearDown() |
| 94 | |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 95 | def create_stream_ip4(self, src_if, src_ip, dst_ip, payload_size=0): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 96 | pkts = [] |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 97 | # default to small packet sizes |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 98 | p = (Ether(dst=getmacbyip(dst_ip), src=src_if.remote_mac) / |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 99 | IP(src=src_ip, dst=dst_ip) / |
| 100 | UDP(sport=1234, dport=1234)) |
| 101 | if not payload_size: |
| 102 | payload_size = 64 - len(p) |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 103 | p = p / Raw(b'\xa5' * payload_size) |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 104 | |
Neale Ranns | 9bea8fb | 2017-02-03 04:34:01 -0800 | [diff] [blame] | 105 | for i in range(0, N_PKTS_IN_STREAM): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 106 | pkts.append(p) |
| 107 | return pkts |
| 108 | |
| 109 | def create_stream_ip6(self, src_if, src_ip, dst_ip): |
| 110 | pkts = [] |
Neale Ranns | 9bea8fb | 2017-02-03 04:34:01 -0800 | [diff] [blame] | 111 | for i in range(0, N_PKTS_IN_STREAM): |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 112 | info = self.create_packet_info(src_if, src_if) |
| 113 | payload = self.info_to_payload(info) |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 114 | p = (Ether(dst=getmacbyip6(dst_ip), src=src_if.remote_mac) / |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 115 | IPv6(src=src_ip, dst=dst_ip) / |
| 116 | UDP(sport=1234, dport=1234) / |
| 117 | Raw(payload)) |
| 118 | info.data = p.copy() |
| 119 | pkts.append(p) |
| 120 | return pkts |
| 121 | |
| 122 | def verify_filter(self, capture, sent): |
| 123 | if not len(capture) == len(sent): |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 124 | # filter out any IPv6 RAs from the capture |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 125 | for p in capture: |
| 126 | if (p.haslayer(IPv6)): |
| 127 | capture.remove(p) |
| 128 | return capture |
| 129 | |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 130 | def verify_capture_ip4(self, rx_if, sent, dst_mac=None): |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 131 | rxd = rx_if.get_capture(len(sent)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 132 | |
| 133 | try: |
| 134 | capture = self.verify_filter(rxd, sent) |
| 135 | |
| 136 | self.assertEqual(len(capture), len(sent)) |
| 137 | |
| 138 | for i in range(len(capture)): |
| 139 | tx = sent[i] |
| 140 | rx = capture[i] |
| 141 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 142 | eth = rx[Ether] |
| 143 | self.assertEqual(eth.type, 0x800) |
| 144 | |
| 145 | tx_ip = tx[IP] |
| 146 | rx_ip = rx[IP] |
| 147 | |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 148 | if dst_mac is None: |
| 149 | dst_mac = getmacbyip(rx_ip.dst) |
| 150 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 151 | # check the MAC address on the RX'd packet is correctly formed |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 152 | self.assertEqual(eth.dst, dst_mac) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 153 | |
| 154 | self.assertEqual(rx_ip.src, tx_ip.src) |
| 155 | self.assertEqual(rx_ip.dst, tx_ip.dst) |
| 156 | # IP processing post pop has decremented the TTL |
| 157 | self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl) |
| 158 | |
| 159 | except: |
| 160 | raise |
| 161 | |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 162 | def verify_capture_ip6(self, rx_if, sent): |
| 163 | capture = rx_if.get_capture(len(sent)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 164 | |
| 165 | self.assertEqual(len(capture), len(sent)) |
| 166 | |
| 167 | for i in range(len(capture)): |
| 168 | tx = sent[i] |
| 169 | rx = capture[i] |
| 170 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 171 | eth = rx[Ether] |
| 172 | self.assertEqual(eth.type, 0x86DD) |
| 173 | |
| 174 | tx_ip = tx[IPv6] |
| 175 | rx_ip = rx[IPv6] |
| 176 | |
| 177 | # check the MAC address on the RX'd packet is correctly formed |
| 178 | self.assertEqual(eth.dst, getmacbyip6(rx_ip.dst)) |
| 179 | |
| 180 | self.assertEqual(rx_ip.src, tx_ip.src) |
| 181 | self.assertEqual(rx_ip.dst, tx_ip.dst) |
| 182 | # IP processing post pop has decremented the TTL |
| 183 | self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim) |
| 184 | |
| 185 | def test_ip_mcast(self): |
| 186 | """ IP Multicast Replication """ |
| 187 | |
| 188 | # |
| 189 | # a stream that matches the default route. gets dropped. |
| 190 | # |
| 191 | self.vapi.cli("clear trace") |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 192 | self.vapi.cli("packet mac-filter pg0 on") |
| 193 | self.vapi.cli("packet mac-filter pg1 on") |
| 194 | self.vapi.cli("packet mac-filter pg2 on") |
| 195 | self.vapi.cli("packet mac-filter pg4 on") |
| 196 | self.vapi.cli("packet mac-filter pg5 on") |
| 197 | self.vapi.cli("packet mac-filter pg6 on") |
| 198 | self.vapi.cli("packet mac-filter pg7 on") |
| 199 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 200 | tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1") |
| 201 | self.pg0.add_stream(tx) |
| 202 | |
| 203 | self.pg_enable_capture(self.pg_interfaces) |
| 204 | self.pg_start() |
| 205 | |
| 206 | self.pg0.assert_nothing_captured( |
| 207 | remark="IP multicast packets forwarded on default route") |
| 208 | |
| 209 | # |
| 210 | # A (*,G). |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 211 | # one accepting interface, pg0, 7 forwarding interfaces |
Paul Vinciguerra | 8feeaff | 2019-03-27 11:25:48 -0700 | [diff] [blame] | 212 | # many forwarding interfaces test the case where the replicate DPO |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 213 | # needs to use extra cache lines for the buckets. |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 214 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 215 | route_232_1_1_1 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 216 | self, |
| 217 | "0.0.0.0", |
| 218 | "232.1.1.1", 32, |
| 219 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 220 | [VppMRoutePath(self.pg0.sw_if_index, |
| 221 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 222 | VppMRoutePath(self.pg1.sw_if_index, |
| 223 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 224 | VppMRoutePath(self.pg2.sw_if_index, |
| 225 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 226 | VppMRoutePath(self.pg3.sw_if_index, |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 227 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 228 | VppMRoutePath(self.pg4.sw_if_index, |
| 229 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 230 | VppMRoutePath(self.pg5.sw_if_index, |
| 231 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 232 | VppMRoutePath(self.pg6.sw_if_index, |
| 233 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 234 | VppMRoutePath(self.pg7.sw_if_index, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 235 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 236 | route_232_1_1_1.add_vpp_config() |
| 237 | |
| 238 | # |
| 239 | # An (S,G). |
| 240 | # one accepting interface, pg0, 2 forwarding interfaces |
| 241 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 242 | route_1_1_1_1_232_1_1_1 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 243 | self, |
| 244 | "1.1.1.1", |
Neale Ranns | 3e42ebe | 2018-10-04 08:36:56 -0700 | [diff] [blame] | 245 | "232.1.1.1", 27, # any grp-len is ok when src is set |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 246 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 247 | [VppMRoutePath(self.pg0.sw_if_index, |
| 248 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 249 | VppMRoutePath(self.pg1.sw_if_index, |
| 250 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 251 | VppMRoutePath(self.pg2.sw_if_index, |
| 252 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 253 | route_1_1_1_1_232_1_1_1.add_vpp_config() |
| 254 | |
| 255 | # |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 256 | # An (S,G). |
| 257 | # one accepting interface, pg0, 2 forwarding interfaces |
| 258 | # that use unicast next-hops |
| 259 | # |
| 260 | route_1_1_1_1_232_1_1_2 = VppIpMRoute( |
| 261 | self, |
| 262 | "1.1.1.1", |
| 263 | "232.1.1.2", 64, |
| 264 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
| 265 | [VppMRoutePath(self.pg0.sw_if_index, |
| 266 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 267 | VppMRoutePath(self.pg1.sw_if_index, |
| 268 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
| 269 | nh=self.pg1.remote_ip4), |
| 270 | VppMRoutePath(self.pg2.sw_if_index, |
| 271 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
| 272 | nh=self.pg2.remote_ip4)]) |
| 273 | route_1_1_1_1_232_1_1_2.add_vpp_config() |
| 274 | |
| 275 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 276 | # An (*,G/m). |
| 277 | # one accepting interface, pg0, 1 forwarding interfaces |
| 278 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 279 | route_232 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 280 | self, |
| 281 | "0.0.0.0", |
| 282 | "232.0.0.0", 8, |
| 283 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 284 | [VppMRoutePath(self.pg0.sw_if_index, |
| 285 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 286 | VppMRoutePath(self.pg1.sw_if_index, |
| 287 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 288 | route_232.add_vpp_config() |
| 289 | |
| 290 | # |
| 291 | # a stream that matches the route for (1.1.1.1,232.1.1.1) |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 292 | # small packets |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 293 | # |
| 294 | self.vapi.cli("clear trace") |
| 295 | tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1") |
| 296 | self.pg0.add_stream(tx) |
| 297 | |
| 298 | self.pg_enable_capture(self.pg_interfaces) |
| 299 | self.pg_start() |
| 300 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 301 | self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'], |
| 302 | len(tx)) |
| 303 | |
Neale Ranns | 37be736 | 2017-02-21 17:30:26 -0800 | [diff] [blame] | 304 | # We expect replications on Pg1->7 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 305 | self.verify_capture_ip4(self.pg1, tx) |
| 306 | self.verify_capture_ip4(self.pg2, tx) |
| 307 | |
| 308 | # no replications on Pg0 |
| 309 | self.pg0.assert_nothing_captured( |
| 310 | remark="IP multicast packets forwarded on PG0") |
| 311 | self.pg3.assert_nothing_captured( |
| 312 | remark="IP multicast packets forwarded on PG3") |
| 313 | |
| 314 | # |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 315 | # a stream that matches the route for (1.1.1.1,232.1.1.1) |
| 316 | # large packets |
| 317 | # |
| 318 | self.vapi.cli("clear trace") |
| 319 | tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1", |
| 320 | payload_size=1024) |
| 321 | self.pg0.add_stream(tx) |
| 322 | |
| 323 | self.pg_enable_capture(self.pg_interfaces) |
| 324 | self.pg_start() |
| 325 | |
| 326 | # We expect replications on Pg1->7 |
| 327 | self.verify_capture_ip4(self.pg1, tx) |
| 328 | self.verify_capture_ip4(self.pg2, tx) |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 329 | |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 330 | self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'], |
| 331 | 2*len(tx)) |
| 332 | |
Neale Ranns | 9d676af | 2017-03-15 01:28:31 -0700 | [diff] [blame] | 333 | # no replications on Pg0 |
| 334 | self.pg0.assert_nothing_captured( |
| 335 | remark="IP multicast packets forwarded on PG0") |
| 336 | self.pg3.assert_nothing_captured( |
| 337 | remark="IP multicast packets forwarded on PG3") |
| 338 | |
| 339 | # |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 340 | # a stream to the unicast next-hops |
| 341 | # |
| 342 | self.vapi.cli("clear trace") |
| 343 | tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.2") |
| 344 | self.pg0.add_stream(tx) |
| 345 | |
| 346 | self.pg_enable_capture(self.pg_interfaces) |
| 347 | self.pg_start() |
| 348 | |
| 349 | # We expect replications on Pg1->7 |
| 350 | self.verify_capture_ip4(self.pg1, tx, dst_mac=self.pg1.remote_mac) |
| 351 | self.verify_capture_ip4(self.pg2, tx, dst_mac=self.pg2.remote_mac) |
| 352 | |
| 353 | # no replications on Pg0 nor pg3 |
| 354 | self.pg0.assert_nothing_captured( |
| 355 | remark="IP multicast packets forwarded on PG0") |
| 356 | self.pg3.assert_nothing_captured( |
| 357 | remark="IP multicast packets forwarded on PG3") |
| 358 | |
| 359 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 360 | # a stream that matches the route for (*,232.0.0.0/8) |
| 361 | # Send packets with the 9th bit set so we test the correct clearing |
| 362 | # of that bit in the mac rewrite |
| 363 | # |
| 364 | self.vapi.cli("clear trace") |
| 365 | tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.255.255.255") |
| 366 | self.pg0.add_stream(tx) |
| 367 | |
| 368 | self.pg_enable_capture(self.pg_interfaces) |
| 369 | self.pg_start() |
| 370 | |
| 371 | # We expect replications on Pg1 only |
| 372 | self.verify_capture_ip4(self.pg1, tx) |
Neale Ranns | 28c142e | 2018-09-07 09:37:07 -0700 | [diff] [blame] | 373 | self.assertEqual(route_232.get_stats()['packets'], len(tx)) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 374 | |
| 375 | # no replications on Pg0, Pg2 not Pg3 |
| 376 | self.pg0.assert_nothing_captured( |
| 377 | remark="IP multicast packets forwarded on PG0") |
| 378 | self.pg2.assert_nothing_captured( |
| 379 | remark="IP multicast packets forwarded on PG2") |
| 380 | self.pg3.assert_nothing_captured( |
| 381 | remark="IP multicast packets forwarded on PG3") |
| 382 | |
| 383 | # |
| 384 | # a stream that matches the route for (*,232.1.1.1) |
| 385 | # |
| 386 | self.vapi.cli("clear trace") |
| 387 | tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "232.1.1.1") |
| 388 | self.pg0.add_stream(tx) |
| 389 | |
| 390 | self.pg_enable_capture(self.pg_interfaces) |
| 391 | self.pg_start() |
| 392 | |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 393 | # We expect replications on Pg1->7 |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 394 | self.verify_capture_ip4(self.pg1, tx) |
| 395 | self.verify_capture_ip4(self.pg2, tx) |
| 396 | self.verify_capture_ip4(self.pg3, tx) |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 397 | self.verify_capture_ip4(self.pg4, tx) |
| 398 | self.verify_capture_ip4(self.pg5, tx) |
| 399 | self.verify_capture_ip4(self.pg6, tx) |
| 400 | self.verify_capture_ip4(self.pg7, tx) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 401 | |
Neale Ranns | e821ab1 | 2017-06-01 07:45:05 -0700 | [diff] [blame] | 402 | # no replications on Pg0 |
| 403 | self.pg0.assert_nothing_captured( |
| 404 | remark="IP multicast packets forwarded on PG0") |
| 405 | |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 406 | self.vapi.cli("packet mac-filter pg0 off") |
| 407 | self.vapi.cli("packet mac-filter pg1 off") |
| 408 | self.vapi.cli("packet mac-filter pg2 off") |
| 409 | self.vapi.cli("packet mac-filter pg4 off") |
| 410 | self.vapi.cli("packet mac-filter pg5 off") |
| 411 | self.vapi.cli("packet mac-filter pg6 off") |
| 412 | self.vapi.cli("packet mac-filter pg7 off") |
| 413 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 414 | def test_ip6_mcast(self): |
| 415 | """ IPv6 Multicast Replication """ |
| 416 | |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 417 | self.vapi.cli("packet mac-filter pg0 on") |
| 418 | self.vapi.cli("packet mac-filter pg1 on") |
| 419 | self.vapi.cli("packet mac-filter pg2 on") |
| 420 | self.vapi.cli("packet mac-filter pg4 on") |
| 421 | self.vapi.cli("packet mac-filter pg5 on") |
| 422 | self.vapi.cli("packet mac-filter pg6 on") |
| 423 | self.vapi.cli("packet mac-filter pg7 on") |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 424 | # |
| 425 | # a stream that matches the default route. gets dropped. |
| 426 | # |
| 427 | self.vapi.cli("clear trace") |
| 428 | tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1") |
| 429 | self.pg0.add_stream(tx) |
| 430 | |
| 431 | self.pg_enable_capture(self.pg_interfaces) |
| 432 | self.pg_start() |
| 433 | |
| 434 | self.pg0.assert_nothing_captured( |
| 435 | remark="IPv6 multicast packets forwarded on default route") |
| 436 | |
| 437 | # |
| 438 | # A (*,G). |
| 439 | # one accepting interface, pg0, 3 forwarding interfaces |
| 440 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 441 | route_ff01_1 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 442 | self, |
| 443 | "::", |
| 444 | "ff01::1", 128, |
| 445 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 446 | [VppMRoutePath(self.pg0.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 447 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 448 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 449 | VppMRoutePath(self.pg1.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 450 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 451 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 452 | VppMRoutePath(self.pg2.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 453 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 454 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 455 | VppMRoutePath(self.pg3.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 456 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 457 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 458 | route_ff01_1.add_vpp_config() |
| 459 | |
| 460 | # |
| 461 | # An (S,G). |
| 462 | # one accepting interface, pg0, 2 forwarding interfaces |
| 463 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 464 | route_2001_ff01_1 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 465 | self, |
| 466 | "2001::1", |
Neale Ranns | 3e42ebe | 2018-10-04 08:36:56 -0700 | [diff] [blame] | 467 | "ff01::1", 0, # any grp-len is ok when src is set |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 468 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 469 | [VppMRoutePath(self.pg0.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 470 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 471 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 472 | VppMRoutePath(self.pg1.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 473 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 474 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 475 | VppMRoutePath(self.pg2.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 476 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 477 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 478 | route_2001_ff01_1.add_vpp_config() |
| 479 | |
| 480 | # |
| 481 | # An (*,G/m). |
| 482 | # one accepting interface, pg0, 1 forwarding interface |
| 483 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 484 | route_ff01 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 485 | self, |
| 486 | "::", |
| 487 | "ff01::", 16, |
| 488 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 489 | [VppMRoutePath(self.pg0.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 490 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 491 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 492 | VppMRoutePath(self.pg1.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 493 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 494 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 495 | route_ff01.add_vpp_config() |
| 496 | |
| 497 | # |
| 498 | # a stream that matches the route for (*, ff01::/16) |
Neale Ranns | ce111d2 | 2018-01-23 08:38:50 -0800 | [diff] [blame] | 499 | # sent on the non-accepting interface |
| 500 | # |
| 501 | self.vapi.cli("clear trace") |
| 502 | tx = self.create_stream_ip6(self.pg1, "2002::1", "ff01:2::255") |
| 503 | self.send_and_assert_no_replies(self.pg1, tx, "RPF miss") |
| 504 | |
| 505 | # |
| 506 | # a stream that matches the route for (*, ff01::/16) |
| 507 | # sent on the accepting interface |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 508 | # |
| 509 | self.vapi.cli("clear trace") |
| 510 | tx = self.create_stream_ip6(self.pg0, "2002::1", "ff01:2::255") |
| 511 | self.pg0.add_stream(tx) |
| 512 | |
| 513 | self.pg_enable_capture(self.pg_interfaces) |
| 514 | self.pg_start() |
| 515 | |
| 516 | # We expect replications on Pg1 |
| 517 | self.verify_capture_ip6(self.pg1, tx) |
| 518 | |
| 519 | # no replications on Pg0, Pg3 |
| 520 | self.pg0.assert_nothing_captured( |
| 521 | remark="IP multicast packets forwarded on PG0") |
| 522 | self.pg2.assert_nothing_captured( |
| 523 | remark="IP multicast packets forwarded on PG2") |
| 524 | self.pg3.assert_nothing_captured( |
| 525 | remark="IP multicast packets forwarded on PG3") |
| 526 | |
| 527 | # |
Neale Ranns | c2aad53 | 2017-05-30 09:53:52 -0700 | [diff] [blame] | 528 | # Bounce the interface and it should still work |
| 529 | # |
| 530 | self.pg1.admin_down() |
| 531 | self.pg0.add_stream(tx) |
| 532 | self.pg_enable_capture(self.pg_interfaces) |
| 533 | self.pg_start() |
| 534 | self.pg1.assert_nothing_captured( |
| 535 | remark="IP multicast packets forwarded on down PG1") |
| 536 | |
| 537 | self.pg1.admin_up() |
| 538 | self.pg0.add_stream(tx) |
| 539 | self.pg_enable_capture(self.pg_interfaces) |
| 540 | self.pg_start() |
| 541 | self.verify_capture_ip6(self.pg1, tx) |
| 542 | |
| 543 | # |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 544 | # a stream that matches the route for (*,ff01::1) |
| 545 | # |
| 546 | self.vapi.cli("clear trace") |
| 547 | tx = self.create_stream_ip6(self.pg0, "2002::2", "ff01::1") |
| 548 | self.pg0.add_stream(tx) |
| 549 | |
| 550 | self.pg_enable_capture(self.pg_interfaces) |
| 551 | self.pg_start() |
| 552 | |
| 553 | # We expect replications on Pg1, 2, 3. |
| 554 | self.verify_capture_ip6(self.pg1, tx) |
| 555 | self.verify_capture_ip6(self.pg2, tx) |
| 556 | self.verify_capture_ip6(self.pg3, tx) |
| 557 | |
| 558 | # no replications on Pg0 |
| 559 | self.pg0.assert_nothing_captured( |
| 560 | remark="IPv6 multicast packets forwarded on PG0") |
| 561 | |
| 562 | # |
| 563 | # a stream that matches the route for (2001::1, ff00::1) |
| 564 | # |
| 565 | self.vapi.cli("clear trace") |
| 566 | tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1") |
| 567 | self.pg0.add_stream(tx) |
| 568 | |
| 569 | self.pg_enable_capture(self.pg_interfaces) |
| 570 | self.pg_start() |
| 571 | |
| 572 | # We expect replications on Pg1, 2, |
| 573 | self.verify_capture_ip6(self.pg1, tx) |
| 574 | self.verify_capture_ip6(self.pg2, tx) |
| 575 | |
| 576 | # no replications on Pg0, Pg3 |
| 577 | self.pg0.assert_nothing_captured( |
| 578 | remark="IP multicast packets forwarded on PG0") |
| 579 | self.pg3.assert_nothing_captured( |
| 580 | remark="IP multicast packets forwarded on PG3") |
| 581 | |
Neale Ranns | 21fb4f7 | 2020-10-05 12:26:47 +0000 | [diff] [blame] | 582 | self.vapi.cli("packet mac-filter pg0 off") |
| 583 | self.vapi.cli("packet mac-filter pg1 off") |
| 584 | self.vapi.cli("packet mac-filter pg2 off") |
| 585 | self.vapi.cli("packet mac-filter pg4 off") |
| 586 | self.vapi.cli("packet mac-filter pg5 off") |
| 587 | self.vapi.cli("packet mac-filter pg6 off") |
| 588 | self.vapi.cli("packet mac-filter pg7 off") |
| 589 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 590 | def _mcast_connected_send_stream(self, dst_ip): |
| 591 | self.vapi.cli("clear trace") |
| 592 | tx = self.create_stream_ip4(self.pg0, |
| 593 | self.pg0.remote_ip4, |
| 594 | dst_ip) |
| 595 | self.pg0.add_stream(tx) |
| 596 | |
| 597 | self.pg_enable_capture(self.pg_interfaces) |
| 598 | self.pg_start() |
| 599 | |
| 600 | # We expect replications on Pg1. |
| 601 | self.verify_capture_ip4(self.pg1, tx) |
| 602 | |
| 603 | return tx |
| 604 | |
| 605 | def test_ip_mcast_connected(self): |
| 606 | """ IP Multicast Connected Source check """ |
| 607 | |
| 608 | # |
| 609 | # A (*,G). |
| 610 | # one accepting interface, pg0, 1 forwarding interfaces |
| 611 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 612 | route_232_1_1_1 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 613 | self, |
| 614 | "0.0.0.0", |
| 615 | "232.1.1.1", 32, |
| 616 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 617 | [VppMRoutePath(self.pg0.sw_if_index, |
| 618 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 619 | VppMRoutePath(self.pg1.sw_if_index, |
| 620 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 621 | |
| 622 | route_232_1_1_1.add_vpp_config() |
| 623 | route_232_1_1_1.update_entry_flags( |
| 624 | MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED) |
| 625 | |
| 626 | # |
| 627 | # Now the (*,G) is present, send from connected source |
| 628 | # |
| 629 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 630 | |
| 631 | # |
| 632 | # Constrct a representation of the signal we expect on pg0 |
| 633 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 634 | signal_232_1_1_1_itf_0 = VppMFibSignal(self, |
| 635 | route_232_1_1_1, |
| 636 | self.pg0.sw_if_index, |
| 637 | tx[0]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 638 | |
| 639 | # |
| 640 | # read the only expected signal |
| 641 | # |
| 642 | signals = self.vapi.mfib_signal_dump() |
| 643 | |
| 644 | self.assertEqual(1, len(signals)) |
| 645 | |
| 646 | signal_232_1_1_1_itf_0.compare(signals[0]) |
| 647 | |
| 648 | # |
| 649 | # reading the signal allows for the generation of another |
| 650 | # so send more packets and expect the next signal |
| 651 | # |
| 652 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 653 | |
| 654 | signals = self.vapi.mfib_signal_dump() |
| 655 | self.assertEqual(1, len(signals)) |
| 656 | signal_232_1_1_1_itf_0.compare(signals[0]) |
| 657 | |
| 658 | # |
| 659 | # A Second entry with connected check |
| 660 | # one accepting interface, pg0, 1 forwarding interfaces |
| 661 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 662 | route_232_1_1_2 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 663 | self, |
| 664 | "0.0.0.0", |
| 665 | "232.1.1.2", 32, |
| 666 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 667 | [VppMRoutePath(self.pg0.sw_if_index, |
| 668 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 669 | VppMRoutePath(self.pg1.sw_if_index, |
| 670 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 671 | |
| 672 | route_232_1_1_2.add_vpp_config() |
| 673 | route_232_1_1_2.update_entry_flags( |
| 674 | MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED) |
| 675 | |
| 676 | # |
| 677 | # Send traffic to both entries. One read should net us two signals |
| 678 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 679 | signal_232_1_1_2_itf_0 = VppMFibSignal(self, |
| 680 | route_232_1_1_2, |
| 681 | self.pg0.sw_if_index, |
| 682 | tx[0]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 683 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 684 | tx2 = self._mcast_connected_send_stream("232.1.1.2") |
| 685 | |
| 686 | # |
| 687 | # read the only expected signal |
| 688 | # |
| 689 | signals = self.vapi.mfib_signal_dump() |
| 690 | |
| 691 | self.assertEqual(2, len(signals)) |
| 692 | |
| 693 | signal_232_1_1_1_itf_0.compare(signals[1]) |
| 694 | signal_232_1_1_2_itf_0.compare(signals[0]) |
| 695 | |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 696 | route_232_1_1_1.update_entry_flags( |
| 697 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE) |
| 698 | route_232_1_1_2.update_entry_flags( |
| 699 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 700 | |
| 701 | def test_ip_mcast_signal(self): |
| 702 | """ IP Multicast Signal """ |
| 703 | |
| 704 | # |
| 705 | # A (*,G). |
| 706 | # one accepting interface, pg0, 1 forwarding interfaces |
| 707 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 708 | route_232_1_1_1 = VppIpMRoute( |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 709 | self, |
| 710 | "0.0.0.0", |
| 711 | "232.1.1.1", 32, |
| 712 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 713 | [VppMRoutePath(self.pg0.sw_if_index, |
| 714 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 715 | VppMRoutePath(self.pg1.sw_if_index, |
| 716 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 717 | |
| 718 | route_232_1_1_1.add_vpp_config() |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 719 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 720 | route_232_1_1_1.update_entry_flags( |
| 721 | MRouteEntryFlags.MFIB_ENTRY_FLAG_SIGNAL) |
| 722 | |
| 723 | # |
| 724 | # Now the (*,G) is present, send from connected source |
| 725 | # |
| 726 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 727 | |
| 728 | # |
| 729 | # Constrct a representation of the signal we expect on pg0 |
| 730 | # |
Neale Ranns | 5a8123b | 2017-01-26 01:18:23 -0800 | [diff] [blame] | 731 | signal_232_1_1_1_itf_0 = VppMFibSignal(self, |
| 732 | route_232_1_1_1, |
| 733 | self.pg0.sw_if_index, |
| 734 | tx[0]) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 735 | |
| 736 | # |
| 737 | # read the only expected signal |
| 738 | # |
| 739 | signals = self.vapi.mfib_signal_dump() |
| 740 | |
| 741 | self.assertEqual(1, len(signals)) |
| 742 | |
| 743 | signal_232_1_1_1_itf_0.compare(signals[0]) |
| 744 | |
| 745 | # |
| 746 | # reading the signal allows for the generation of another |
| 747 | # so send more packets and expect the next signal |
| 748 | # |
| 749 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 750 | |
| 751 | signals = self.vapi.mfib_signal_dump() |
| 752 | self.assertEqual(1, len(signals)) |
| 753 | signal_232_1_1_1_itf_0.compare(signals[0]) |
| 754 | |
| 755 | # |
| 756 | # Set the negate-signal on the accepting interval - the signals |
| 757 | # should stop |
| 758 | # |
| 759 | route_232_1_1_1.update_path_flags( |
| 760 | self.pg0.sw_if_index, |
| 761 | (MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT | |
| 762 | MRouteItfFlags.MFIB_ITF_FLAG_NEGATE_SIGNAL)) |
| 763 | |
Neale Ranns | 0f26c5a | 2017-03-01 15:12:11 -0800 | [diff] [blame] | 764 | self.vapi.cli("clear trace") |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 765 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 766 | |
| 767 | signals = self.vapi.mfib_signal_dump() |
| 768 | self.assertEqual(0, len(signals)) |
| 769 | |
| 770 | # |
| 771 | # Clear the SIGNAL flag on the entry and the signals should |
| 772 | # come back since the interface is still NEGATE-SIGNAL |
| 773 | # |
| 774 | route_232_1_1_1.update_entry_flags( |
| 775 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE) |
| 776 | |
| 777 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 778 | |
| 779 | signals = self.vapi.mfib_signal_dump() |
| 780 | self.assertEqual(1, len(signals)) |
| 781 | signal_232_1_1_1_itf_0.compare(signals[0]) |
| 782 | |
| 783 | # |
| 784 | # Lastly remove the NEGATE-SIGNAL from the interface and the |
| 785 | # signals should stop |
| 786 | # |
| 787 | route_232_1_1_1.update_path_flags(self.pg0.sw_if_index, |
| 788 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT) |
| 789 | |
| 790 | tx = self._mcast_connected_send_stream("232.1.1.1") |
| 791 | signals = self.vapi.mfib_signal_dump() |
| 792 | self.assertEqual(0, len(signals)) |
| 793 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 794 | def test_ip_mcast_vrf(self): |
| 795 | """ IP Multicast Replication in non-default table""" |
| 796 | |
| 797 | # |
| 798 | # An (S,G). |
| 799 | # one accepting interface, pg0, 2 forwarding interfaces |
| 800 | # |
| 801 | route_1_1_1_1_232_1_1_1 = VppIpMRoute( |
| 802 | self, |
| 803 | "1.1.1.1", |
| 804 | "232.1.1.1", 64, |
| 805 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
| 806 | [VppMRoutePath(self.pg8.sw_if_index, |
| 807 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 808 | VppMRoutePath(self.pg1.sw_if_index, |
| 809 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 810 | VppMRoutePath(self.pg2.sw_if_index, |
| 811 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)], |
| 812 | table_id=10) |
| 813 | route_1_1_1_1_232_1_1_1.add_vpp_config() |
| 814 | |
| 815 | # |
| 816 | # a stream that matches the route for (1.1.1.1,232.1.1.1) |
| 817 | # small packets |
| 818 | # |
| 819 | self.vapi.cli("clear trace") |
| 820 | tx = self.create_stream_ip4(self.pg8, "1.1.1.1", "232.1.1.1") |
| 821 | self.pg8.add_stream(tx) |
| 822 | |
| 823 | self.pg_enable_capture(self.pg_interfaces) |
| 824 | self.pg_start() |
| 825 | |
| 826 | # We expect replications on Pg1 & 2 |
| 827 | self.verify_capture_ip4(self.pg1, tx) |
| 828 | self.verify_capture_ip4(self.pg2, tx) |
| 829 | |
Neale Ranns | adb17a8 | 2019-08-04 02:41:57 -0700 | [diff] [blame] | 830 | def test_ip_mcast_gre(self): |
| 831 | """ IP Multicast Replication over GRE""" |
| 832 | |
| 833 | gre_if_1 = VppGreInterface( |
| 834 | self, |
| 835 | self.pg1.local_ip4, |
| 836 | self.pg1.remote_ip4).add_vpp_config() |
| 837 | gre_if_2 = VppGreInterface( |
| 838 | self, |
| 839 | self.pg2.local_ip4, |
| 840 | self.pg2.remote_ip4).add_vpp_config() |
| 841 | gre_if_3 = VppGreInterface( |
| 842 | self, |
| 843 | self.pg3.local_ip4, |
| 844 | self.pg3.remote_ip4).add_vpp_config() |
| 845 | |
| 846 | gre_if_1.admin_up() |
| 847 | gre_if_1.config_ip4() |
| 848 | gre_if_2.admin_up() |
| 849 | gre_if_2.config_ip4() |
| 850 | gre_if_3.admin_up() |
| 851 | gre_if_3.config_ip4() |
| 852 | |
| 853 | # |
| 854 | # An (S,G). |
| 855 | # one accepting interface, pg0, 2 forwarding interfaces |
| 856 | # |
| 857 | route_1_1_1_1_232_1_1_1 = VppIpMRoute( |
| 858 | self, |
| 859 | "1.1.1.1", |
| 860 | "232.2.2.2", 64, |
| 861 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
| 862 | [VppMRoutePath(gre_if_1.sw_if_index, |
| 863 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT), |
| 864 | VppMRoutePath(gre_if_2.sw_if_index, |
| 865 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 866 | VppMRoutePath(gre_if_3.sw_if_index, |
| 867 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
| 868 | route_1_1_1_1_232_1_1_1.add_vpp_config() |
| 869 | |
| 870 | # |
| 871 | # a stream that matches the route for (1.1.1.1,232.2.2.2) |
| 872 | # small packets |
| 873 | # |
| 874 | tx = (Ether(dst=self.pg1.local_mac, |
| 875 | src=self.pg1.remote_mac) / |
| 876 | IP(src=self.pg1.remote_ip4, |
| 877 | dst=self.pg1.local_ip4) / |
| 878 | GRE() / |
| 879 | IP(src="1.1.1.1", dst="232.2.2.2") / |
| 880 | UDP(sport=1234, dport=1234) / |
Ole Troan | 770a0de | 2019-11-07 13:52:21 +0100 | [diff] [blame] | 881 | Raw(b'\a5' * 64)) * 63 |
Neale Ranns | adb17a8 | 2019-08-04 02:41:57 -0700 | [diff] [blame] | 882 | |
| 883 | self.vapi.cli("clear trace") |
| 884 | self.pg1.add_stream(tx) |
| 885 | |
| 886 | self.pg_enable_capture(self.pg_interfaces) |
| 887 | self.pg_start() |
| 888 | |
| 889 | # We expect replications on Pg2 & 3 |
| 890 | # check the encap headers are as expected based on the egress tunnel |
| 891 | rxs = self.pg2.get_capture(len(tx)) |
| 892 | for rx in rxs: |
| 893 | self.assertEqual(rx[IP].src, gre_if_2.t_src) |
| 894 | self.assertEqual(rx[IP].dst, gre_if_2.t_dst) |
| 895 | self.assert_packet_checksums_valid(rx) |
| 896 | |
| 897 | rxs = self.pg3.get_capture(len(tx)) |
| 898 | for rx in rxs: |
| 899 | self.assertEqual(rx[IP].src, gre_if_3.t_src) |
| 900 | self.assertEqual(rx[IP].dst, gre_if_3.t_dst) |
| 901 | self.assert_packet_checksums_valid(rx) |
| 902 | |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 903 | def test_ip6_mcast_vrf(self): |
| 904 | """ IPv6 Multicast Replication in non-default table""" |
| 905 | |
| 906 | # |
| 907 | # An (S,G). |
| 908 | # one accepting interface, pg0, 2 forwarding interfaces |
| 909 | # |
| 910 | route_2001_ff01_1 = VppIpMRoute( |
| 911 | self, |
| 912 | "2001::1", |
| 913 | "ff01::1", 256, |
| 914 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
| 915 | [VppMRoutePath(self.pg8.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 916 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 917 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 918 | VppMRoutePath(self.pg1.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 919 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 920 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6), |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 921 | VppMRoutePath(self.pg2.sw_if_index, |
Neale Ranns | d792d9c | 2017-10-21 10:53:20 -0700 | [diff] [blame] | 922 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD, |
Neale Ranns | 097fa66 | 2018-05-01 05:17:55 -0700 | [diff] [blame] | 923 | proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)], |
| 924 | table_id=10) |
Neale Ranns | 1500254 | 2017-09-10 04:39:11 -0700 | [diff] [blame] | 925 | route_2001_ff01_1.add_vpp_config() |
| 926 | |
| 927 | # |
| 928 | # a stream that matches the route for (2001::1, ff00::1) |
| 929 | # |
| 930 | self.vapi.cli("clear trace") |
| 931 | tx = self.create_stream_ip6(self.pg8, "2001::1", "ff01::1") |
| 932 | self.pg8.add_stream(tx) |
| 933 | |
| 934 | self.pg_enable_capture(self.pg_interfaces) |
| 935 | self.pg_start() |
| 936 | |
| 937 | # We expect replications on Pg1, 2, |
| 938 | self.verify_capture_ip6(self.pg1, tx) |
| 939 | self.verify_capture_ip6(self.pg2, tx) |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 940 | |
Neale Ranns | cf3561b | 2017-12-13 01:44:25 -0800 | [diff] [blame] | 941 | def test_bidir(self): |
| 942 | """ IP Multicast Bi-directional """ |
| 943 | |
| 944 | # |
| 945 | # A (*,G). The set of accepting interfaces matching the forwarding |
| 946 | # |
| 947 | route_232_1_1_1 = VppIpMRoute( |
| 948 | self, |
| 949 | "0.0.0.0", |
| 950 | "232.1.1.1", 32, |
| 951 | MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE, |
| 952 | [VppMRoutePath(self.pg0.sw_if_index, |
| 953 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT | |
| 954 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 955 | VppMRoutePath(self.pg1.sw_if_index, |
| 956 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT | |
| 957 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 958 | VppMRoutePath(self.pg2.sw_if_index, |
| 959 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT | |
| 960 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD), |
| 961 | VppMRoutePath(self.pg3.sw_if_index, |
| 962 | MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT | |
| 963 | MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)]) |
| 964 | route_232_1_1_1.add_vpp_config() |
| 965 | |
| 966 | tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1") |
| 967 | self.pg0.add_stream(tx) |
| 968 | |
| 969 | self.pg_enable_capture(self.pg_interfaces) |
| 970 | self.pg_start() |
| 971 | |
| 972 | # We expect replications on Pg1, 2, 3, but not on pg0 |
| 973 | self.verify_capture_ip4(self.pg1, tx) |
| 974 | self.verify_capture_ip4(self.pg2, tx) |
| 975 | self.verify_capture_ip4(self.pg3, tx) |
| 976 | self.pg0.assert_nothing_captured( |
| 977 | remark="IP multicast packets forwarded on PG0") |
| 978 | |
| 979 | |
Neale Ranns | 32e1c01 | 2016-11-22 17:07:28 +0000 | [diff] [blame] | 980 | if __name__ == '__main__': |
| 981 | unittest.main(testRunner=VppTestRunner) |