5 from framework import VppTestCase, VppTestRunner
6 from vpp_ip import DpoProto
7 from vpp_ip_route import VppIpMRoute, VppMRoutePath, VppMFibSignal, \
8 MRouteItfFlags, MRouteEntryFlags, VppIpTable, FibPathProto
9 from vpp_gre_interface import VppGreInterface
11 from scapy.packet import Raw
12 from scapy.layers.l2 import Ether, GRE
13 from scapy.layers.inet import IP, UDP, getmacbyip
14 from scapy.layers.inet6 import IPv6, getmacbyip6
17 # The number of packets sent is set to 91 so that when we replicate more than 3
18 # times, which we do for some entries, we will generate more than 256 packets
19 # to the next node in the VLIB graph. Thus we are testing the code's
20 # correctness handling this over-flow.
21 # It's also an odd number so we hit any single loops.
26 class TestMFIB(VppTestCase):
27 """ MFIB Test Case """
31 super(TestMFIB, cls).setUpClass()
34 def tearDownClass(cls):
35 super(TestMFIB, cls).tearDownClass()
38 super(TestMFIB, self).setUp()
41 """ MFIB Unit Tests """
42 error = self.vapi.cli("test mfib")
45 self.logger.critical(error)
46 self.assertNotIn("Failed", error)
49 class TestIPMcast(VppTestCase):
50 """ IP Multicast Test Case """
54 super(TestIPMcast, cls).setUpClass()
57 def tearDownClass(cls):
58 super(TestIPMcast, cls).tearDownClass()
61 super(TestIPMcast, self).setUp()
63 # create 8 pg interfaces
64 self.create_pg_interfaces(range(9))
67 for i in self.pg_interfaces[:8]:
75 tbl4 = VppIpTable(self, 10)
77 self.pg8.set_table_ip4(10)
80 tbl6 = VppIpTable(self, 10, is_ip6=1)
82 self.pg8.set_table_ip6(10)
86 for i in self.pg_interfaces:
91 self.pg8.set_table_ip4(0)
92 self.pg8.set_table_ip6(0)
93 super(TestIPMcast, self).tearDown()
95 def create_stream_ip4(self, src_if, src_ip, dst_ip, payload_size=0):
97 # default to small packet sizes
98 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
99 IP(src=src_ip, dst=dst_ip) /
100 UDP(sport=1234, dport=1234))
102 payload_size = 64 - len(p)
103 p = p / Raw(b'\xa5' * payload_size)
105 for i in range(0, N_PKTS_IN_STREAM):
109 def create_stream_ip6(self, src_if, src_ip, dst_ip):
111 for i in range(0, N_PKTS_IN_STREAM):
112 info = self.create_packet_info(src_if, src_if)
113 payload = self.info_to_payload(info)
114 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
115 IPv6(src=src_ip, dst=dst_ip) /
116 UDP(sport=1234, dport=1234) /
122 def verify_filter(self, capture, sent):
123 if not len(capture) == len(sent):
124 # filter out any IPv6 RAs from the capture
126 if (p.haslayer(IPv6)):
130 def verify_capture_ip4(self, rx_if, sent, dst_mac=None):
131 rxd = rx_if.get_capture(len(sent))
134 capture = self.verify_filter(rxd, sent)
136 self.assertEqual(len(capture), len(sent))
138 for i in range(len(capture)):
143 self.assertEqual(eth.type, 0x800)
149 dst_mac = getmacbyip(rx_ip.dst)
151 # check the MAC address on the RX'd packet is correctly formed
152 self.assertEqual(eth.dst, dst_mac)
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)
162 def verify_capture_ip6(self, rx_if, sent):
163 capture = rx_if.get_capture(len(sent))
165 self.assertEqual(len(capture), len(sent))
167 for i in range(len(capture)):
172 self.assertEqual(eth.type, 0x86DD)
177 # check the MAC address on the RX'd packet is correctly formed
178 self.assertEqual(eth.dst, getmacbyip6(rx_ip.dst))
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)
185 def test_ip_mcast(self):
186 """ IP Multicast Replication """
189 # a stream that matches the default route. gets dropped.
191 self.vapi.cli("clear trace")
192 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
193 self.pg0.add_stream(tx)
195 self.pg_enable_capture(self.pg_interfaces)
198 self.pg0.assert_nothing_captured(
199 remark="IP multicast packets forwarded on default route")
203 # one accepting interface, pg0, 7 forwarding interfaces
204 # many forwarding interfaces test the case where the replicate DPO
205 # needs to use extra cache lines for the buckets.
207 route_232_1_1_1 = VppIpMRoute(
211 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
212 [VppMRoutePath(self.pg0.sw_if_index,
213 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
214 VppMRoutePath(self.pg1.sw_if_index,
215 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
216 VppMRoutePath(self.pg2.sw_if_index,
217 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
218 VppMRoutePath(self.pg3.sw_if_index,
219 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
220 VppMRoutePath(self.pg4.sw_if_index,
221 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
222 VppMRoutePath(self.pg5.sw_if_index,
223 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
224 VppMRoutePath(self.pg6.sw_if_index,
225 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
226 VppMRoutePath(self.pg7.sw_if_index,
227 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
228 route_232_1_1_1.add_vpp_config()
232 # one accepting interface, pg0, 2 forwarding interfaces
234 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
237 "232.1.1.1", 27, # any grp-len is ok when src is set
238 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
239 [VppMRoutePath(self.pg0.sw_if_index,
240 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
241 VppMRoutePath(self.pg1.sw_if_index,
242 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
243 VppMRoutePath(self.pg2.sw_if_index,
244 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
245 route_1_1_1_1_232_1_1_1.add_vpp_config()
249 # one accepting interface, pg0, 2 forwarding interfaces
250 # that use unicast next-hops
252 route_1_1_1_1_232_1_1_2 = VppIpMRoute(
256 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
257 [VppMRoutePath(self.pg0.sw_if_index,
258 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
259 VppMRoutePath(self.pg1.sw_if_index,
260 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
261 nh=self.pg1.remote_ip4),
262 VppMRoutePath(self.pg2.sw_if_index,
263 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
264 nh=self.pg2.remote_ip4)])
265 route_1_1_1_1_232_1_1_2.add_vpp_config()
269 # one accepting interface, pg0, 1 forwarding interfaces
271 route_232 = VppIpMRoute(
275 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
276 [VppMRoutePath(self.pg0.sw_if_index,
277 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
278 VppMRoutePath(self.pg1.sw_if_index,
279 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
280 route_232.add_vpp_config()
283 # a stream that matches the route for (1.1.1.1,232.1.1.1)
286 self.vapi.cli("clear trace")
287 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
288 self.pg0.add_stream(tx)
290 self.pg_enable_capture(self.pg_interfaces)
293 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
296 # We expect replications on Pg1->7
297 self.verify_capture_ip4(self.pg1, tx)
298 self.verify_capture_ip4(self.pg2, tx)
300 # no replications on Pg0
301 self.pg0.assert_nothing_captured(
302 remark="IP multicast packets forwarded on PG0")
303 self.pg3.assert_nothing_captured(
304 remark="IP multicast packets forwarded on PG3")
307 # a stream that matches the route for (1.1.1.1,232.1.1.1)
310 self.vapi.cli("clear trace")
311 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1",
313 self.pg0.add_stream(tx)
315 self.pg_enable_capture(self.pg_interfaces)
318 # We expect replications on Pg1->7
319 self.verify_capture_ip4(self.pg1, tx)
320 self.verify_capture_ip4(self.pg2, tx)
322 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
325 # no replications on Pg0
326 self.pg0.assert_nothing_captured(
327 remark="IP multicast packets forwarded on PG0")
328 self.pg3.assert_nothing_captured(
329 remark="IP multicast packets forwarded on PG3")
332 # a stream to the unicast next-hops
334 self.vapi.cli("clear trace")
335 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.2")
336 self.pg0.add_stream(tx)
338 self.pg_enable_capture(self.pg_interfaces)
341 # We expect replications on Pg1->7
342 self.verify_capture_ip4(self.pg1, tx, dst_mac=self.pg1.remote_mac)
343 self.verify_capture_ip4(self.pg2, tx, dst_mac=self.pg2.remote_mac)
345 # no replications on Pg0 nor pg3
346 self.pg0.assert_nothing_captured(
347 remark="IP multicast packets forwarded on PG0")
348 self.pg3.assert_nothing_captured(
349 remark="IP multicast packets forwarded on PG3")
352 # a stream that matches the route for (*,232.0.0.0/8)
353 # Send packets with the 9th bit set so we test the correct clearing
354 # of that bit in the mac rewrite
356 self.vapi.cli("clear trace")
357 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.255.255.255")
358 self.pg0.add_stream(tx)
360 self.pg_enable_capture(self.pg_interfaces)
363 # We expect replications on Pg1 only
364 self.verify_capture_ip4(self.pg1, tx)
365 self.assertEqual(route_232.get_stats()['packets'], len(tx))
367 # no replications on Pg0, Pg2 not Pg3
368 self.pg0.assert_nothing_captured(
369 remark="IP multicast packets forwarded on PG0")
370 self.pg2.assert_nothing_captured(
371 remark="IP multicast packets forwarded on PG2")
372 self.pg3.assert_nothing_captured(
373 remark="IP multicast packets forwarded on PG3")
376 # a stream that matches the route for (*,232.1.1.1)
378 self.vapi.cli("clear trace")
379 tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "232.1.1.1")
380 self.pg0.add_stream(tx)
382 self.pg_enable_capture(self.pg_interfaces)
385 # We expect replications on Pg1->7
386 self.verify_capture_ip4(self.pg1, tx)
387 self.verify_capture_ip4(self.pg2, tx)
388 self.verify_capture_ip4(self.pg3, tx)
389 self.verify_capture_ip4(self.pg4, tx)
390 self.verify_capture_ip4(self.pg5, tx)
391 self.verify_capture_ip4(self.pg6, tx)
392 self.verify_capture_ip4(self.pg7, tx)
394 # no replications on Pg0
395 self.pg0.assert_nothing_captured(
396 remark="IP multicast packets forwarded on PG0")
398 def test_ip6_mcast(self):
399 """ IPv6 Multicast Replication """
402 # a stream that matches the default route. gets dropped.
404 self.vapi.cli("clear trace")
405 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
406 self.pg0.add_stream(tx)
408 self.pg_enable_capture(self.pg_interfaces)
411 self.pg0.assert_nothing_captured(
412 remark="IPv6 multicast packets forwarded on default route")
416 # one accepting interface, pg0, 3 forwarding interfaces
418 route_ff01_1 = VppIpMRoute(
422 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
423 [VppMRoutePath(self.pg0.sw_if_index,
424 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
425 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
426 VppMRoutePath(self.pg1.sw_if_index,
427 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
428 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
429 VppMRoutePath(self.pg2.sw_if_index,
430 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
431 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
432 VppMRoutePath(self.pg3.sw_if_index,
433 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
434 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
435 route_ff01_1.add_vpp_config()
439 # one accepting interface, pg0, 2 forwarding interfaces
441 route_2001_ff01_1 = VppIpMRoute(
444 "ff01::1", 0, # any grp-len is ok when src is set
445 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
446 [VppMRoutePath(self.pg0.sw_if_index,
447 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
448 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
449 VppMRoutePath(self.pg1.sw_if_index,
450 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
451 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
452 VppMRoutePath(self.pg2.sw_if_index,
453 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
454 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
455 route_2001_ff01_1.add_vpp_config()
459 # one accepting interface, pg0, 1 forwarding interface
461 route_ff01 = VppIpMRoute(
465 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
466 [VppMRoutePath(self.pg0.sw_if_index,
467 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
468 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
469 VppMRoutePath(self.pg1.sw_if_index,
470 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
471 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
472 route_ff01.add_vpp_config()
475 # a stream that matches the route for (*, ff01::/16)
476 # sent on the non-accepting interface
478 self.vapi.cli("clear trace")
479 tx = self.create_stream_ip6(self.pg1, "2002::1", "ff01:2::255")
480 self.send_and_assert_no_replies(self.pg1, tx, "RPF miss")
483 # a stream that matches the route for (*, ff01::/16)
484 # sent on the accepting interface
486 self.vapi.cli("clear trace")
487 tx = self.create_stream_ip6(self.pg0, "2002::1", "ff01:2::255")
488 self.pg0.add_stream(tx)
490 self.pg_enable_capture(self.pg_interfaces)
493 # We expect replications on Pg1
494 self.verify_capture_ip6(self.pg1, tx)
496 # no replications on Pg0, Pg3
497 self.pg0.assert_nothing_captured(
498 remark="IP multicast packets forwarded on PG0")
499 self.pg2.assert_nothing_captured(
500 remark="IP multicast packets forwarded on PG2")
501 self.pg3.assert_nothing_captured(
502 remark="IP multicast packets forwarded on PG3")
505 # Bounce the interface and it should still work
507 self.pg1.admin_down()
508 self.pg0.add_stream(tx)
509 self.pg_enable_capture(self.pg_interfaces)
511 self.pg1.assert_nothing_captured(
512 remark="IP multicast packets forwarded on down PG1")
515 self.pg0.add_stream(tx)
516 self.pg_enable_capture(self.pg_interfaces)
518 self.verify_capture_ip6(self.pg1, tx)
521 # a stream that matches the route for (*,ff01::1)
523 self.vapi.cli("clear trace")
524 tx = self.create_stream_ip6(self.pg0, "2002::2", "ff01::1")
525 self.pg0.add_stream(tx)
527 self.pg_enable_capture(self.pg_interfaces)
530 # We expect replications on Pg1, 2, 3.
531 self.verify_capture_ip6(self.pg1, tx)
532 self.verify_capture_ip6(self.pg2, tx)
533 self.verify_capture_ip6(self.pg3, tx)
535 # no replications on Pg0
536 self.pg0.assert_nothing_captured(
537 remark="IPv6 multicast packets forwarded on PG0")
540 # a stream that matches the route for (2001::1, ff00::1)
542 self.vapi.cli("clear trace")
543 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
544 self.pg0.add_stream(tx)
546 self.pg_enable_capture(self.pg_interfaces)
549 # We expect replications on Pg1, 2,
550 self.verify_capture_ip6(self.pg1, tx)
551 self.verify_capture_ip6(self.pg2, tx)
553 # no replications on Pg0, Pg3
554 self.pg0.assert_nothing_captured(
555 remark="IP multicast packets forwarded on PG0")
556 self.pg3.assert_nothing_captured(
557 remark="IP multicast packets forwarded on PG3")
559 def _mcast_connected_send_stream(self, dst_ip):
560 self.vapi.cli("clear trace")
561 tx = self.create_stream_ip4(self.pg0,
564 self.pg0.add_stream(tx)
566 self.pg_enable_capture(self.pg_interfaces)
569 # We expect replications on Pg1.
570 self.verify_capture_ip4(self.pg1, tx)
574 def test_ip_mcast_connected(self):
575 """ IP Multicast Connected Source check """
579 # one accepting interface, pg0, 1 forwarding interfaces
581 route_232_1_1_1 = VppIpMRoute(
585 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
586 [VppMRoutePath(self.pg0.sw_if_index,
587 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
588 VppMRoutePath(self.pg1.sw_if_index,
589 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
591 route_232_1_1_1.add_vpp_config()
592 route_232_1_1_1.update_entry_flags(
593 MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED)
596 # Now the (*,G) is present, send from connected source
598 tx = self._mcast_connected_send_stream("232.1.1.1")
601 # Constrct a representation of the signal we expect on pg0
603 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
605 self.pg0.sw_if_index,
609 # read the only expected signal
611 signals = self.vapi.mfib_signal_dump()
613 self.assertEqual(1, len(signals))
615 signal_232_1_1_1_itf_0.compare(signals[0])
618 # reading the signal allows for the generation of another
619 # so send more packets and expect the next signal
621 tx = self._mcast_connected_send_stream("232.1.1.1")
623 signals = self.vapi.mfib_signal_dump()
624 self.assertEqual(1, len(signals))
625 signal_232_1_1_1_itf_0.compare(signals[0])
628 # A Second entry with connected check
629 # one accepting interface, pg0, 1 forwarding interfaces
631 route_232_1_1_2 = VppIpMRoute(
635 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
636 [VppMRoutePath(self.pg0.sw_if_index,
637 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
638 VppMRoutePath(self.pg1.sw_if_index,
639 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
641 route_232_1_1_2.add_vpp_config()
642 route_232_1_1_2.update_entry_flags(
643 MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED)
646 # Send traffic to both entries. One read should net us two signals
648 signal_232_1_1_2_itf_0 = VppMFibSignal(self,
650 self.pg0.sw_if_index,
652 tx = self._mcast_connected_send_stream("232.1.1.1")
653 tx2 = self._mcast_connected_send_stream("232.1.1.2")
656 # read the only expected signal
658 signals = self.vapi.mfib_signal_dump()
660 self.assertEqual(2, len(signals))
662 signal_232_1_1_1_itf_0.compare(signals[1])
663 signal_232_1_1_2_itf_0.compare(signals[0])
665 route_232_1_1_1.update_entry_flags(
666 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE)
667 route_232_1_1_2.update_entry_flags(
668 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE)
670 def test_ip_mcast_signal(self):
671 """ IP Multicast Signal """
675 # one accepting interface, pg0, 1 forwarding interfaces
677 route_232_1_1_1 = VppIpMRoute(
681 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
682 [VppMRoutePath(self.pg0.sw_if_index,
683 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
684 VppMRoutePath(self.pg1.sw_if_index,
685 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
687 route_232_1_1_1.add_vpp_config()
689 route_232_1_1_1.update_entry_flags(
690 MRouteEntryFlags.MFIB_ENTRY_FLAG_SIGNAL)
693 # Now the (*,G) is present, send from connected source
695 tx = self._mcast_connected_send_stream("232.1.1.1")
698 # Constrct a representation of the signal we expect on pg0
700 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
702 self.pg0.sw_if_index,
706 # read the only expected signal
708 signals = self.vapi.mfib_signal_dump()
710 self.assertEqual(1, len(signals))
712 signal_232_1_1_1_itf_0.compare(signals[0])
715 # reading the signal allows for the generation of another
716 # so send more packets and expect the next signal
718 tx = self._mcast_connected_send_stream("232.1.1.1")
720 signals = self.vapi.mfib_signal_dump()
721 self.assertEqual(1, len(signals))
722 signal_232_1_1_1_itf_0.compare(signals[0])
725 # Set the negate-signal on the accepting interval - the signals
728 route_232_1_1_1.update_path_flags(
729 self.pg0.sw_if_index,
730 (MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT |
731 MRouteItfFlags.MFIB_ITF_FLAG_NEGATE_SIGNAL))
733 self.vapi.cli("clear trace")
734 tx = self._mcast_connected_send_stream("232.1.1.1")
736 signals = self.vapi.mfib_signal_dump()
737 self.assertEqual(0, len(signals))
740 # Clear the SIGNAL flag on the entry and the signals should
741 # come back since the interface is still NEGATE-SIGNAL
743 route_232_1_1_1.update_entry_flags(
744 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE)
746 tx = self._mcast_connected_send_stream("232.1.1.1")
748 signals = self.vapi.mfib_signal_dump()
749 self.assertEqual(1, len(signals))
750 signal_232_1_1_1_itf_0.compare(signals[0])
753 # Lastly remove the NEGATE-SIGNAL from the interface and the
754 # signals should stop
756 route_232_1_1_1.update_path_flags(self.pg0.sw_if_index,
757 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT)
759 tx = self._mcast_connected_send_stream("232.1.1.1")
760 signals = self.vapi.mfib_signal_dump()
761 self.assertEqual(0, len(signals))
763 def test_ip_mcast_vrf(self):
764 """ IP Multicast Replication in non-default table"""
768 # one accepting interface, pg0, 2 forwarding interfaces
770 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
774 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
775 [VppMRoutePath(self.pg8.sw_if_index,
776 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
777 VppMRoutePath(self.pg1.sw_if_index,
778 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
779 VppMRoutePath(self.pg2.sw_if_index,
780 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)],
782 route_1_1_1_1_232_1_1_1.add_vpp_config()
785 # a stream that matches the route for (1.1.1.1,232.1.1.1)
788 self.vapi.cli("clear trace")
789 tx = self.create_stream_ip4(self.pg8, "1.1.1.1", "232.1.1.1")
790 self.pg8.add_stream(tx)
792 self.pg_enable_capture(self.pg_interfaces)
795 # We expect replications on Pg1 & 2
796 self.verify_capture_ip4(self.pg1, tx)
797 self.verify_capture_ip4(self.pg2, tx)
799 def test_ip_mcast_gre(self):
800 """ IP Multicast Replication over GRE"""
802 gre_if_1 = VppGreInterface(
805 self.pg1.remote_ip4).add_vpp_config()
806 gre_if_2 = VppGreInterface(
809 self.pg2.remote_ip4).add_vpp_config()
810 gre_if_3 = VppGreInterface(
813 self.pg3.remote_ip4).add_vpp_config()
816 gre_if_1.config_ip4()
818 gre_if_2.config_ip4()
820 gre_if_3.config_ip4()
824 # one accepting interface, pg0, 2 forwarding interfaces
826 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
830 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
831 [VppMRoutePath(gre_if_1.sw_if_index,
832 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT),
833 VppMRoutePath(gre_if_2.sw_if_index,
834 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
835 VppMRoutePath(gre_if_3.sw_if_index,
836 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
837 route_1_1_1_1_232_1_1_1.add_vpp_config()
840 # a stream that matches the route for (1.1.1.1,232.2.2.2)
843 tx = (Ether(dst=self.pg1.local_mac,
844 src=self.pg1.remote_mac) /
845 IP(src=self.pg1.remote_ip4,
846 dst=self.pg1.local_ip4) /
848 IP(src="1.1.1.1", dst="232.2.2.2") /
849 UDP(sport=1234, dport=1234) /
850 Raw(b'\a5' * 64)) * 63
852 self.vapi.cli("clear trace")
853 self.pg1.add_stream(tx)
855 self.pg_enable_capture(self.pg_interfaces)
858 # We expect replications on Pg2 & 3
859 # check the encap headers are as expected based on the egress tunnel
860 rxs = self.pg2.get_capture(len(tx))
862 self.assertEqual(rx[IP].src, gre_if_2.t_src)
863 self.assertEqual(rx[IP].dst, gre_if_2.t_dst)
864 self.assert_packet_checksums_valid(rx)
866 rxs = self.pg3.get_capture(len(tx))
868 self.assertEqual(rx[IP].src, gre_if_3.t_src)
869 self.assertEqual(rx[IP].dst, gre_if_3.t_dst)
870 self.assert_packet_checksums_valid(rx)
872 def test_ip6_mcast_vrf(self):
873 """ IPv6 Multicast Replication in non-default table"""
877 # one accepting interface, pg0, 2 forwarding interfaces
879 route_2001_ff01_1 = VppIpMRoute(
883 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
884 [VppMRoutePath(self.pg8.sw_if_index,
885 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
886 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
887 VppMRoutePath(self.pg1.sw_if_index,
888 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
889 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
890 VppMRoutePath(self.pg2.sw_if_index,
891 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
892 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
894 route_2001_ff01_1.add_vpp_config()
897 # a stream that matches the route for (2001::1, ff00::1)
899 self.vapi.cli("clear trace")
900 tx = self.create_stream_ip6(self.pg8, "2001::1", "ff01::1")
901 self.pg8.add_stream(tx)
903 self.pg_enable_capture(self.pg_interfaces)
906 # We expect replications on Pg1, 2,
907 self.verify_capture_ip6(self.pg1, tx)
908 self.verify_capture_ip6(self.pg2, tx)
910 def test_bidir(self):
911 """ IP Multicast Bi-directional """
914 # A (*,G). The set of accepting interfaces matching the forwarding
916 route_232_1_1_1 = VppIpMRoute(
920 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
921 [VppMRoutePath(self.pg0.sw_if_index,
922 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT |
923 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
924 VppMRoutePath(self.pg1.sw_if_index,
925 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT |
926 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
927 VppMRoutePath(self.pg2.sw_if_index,
928 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT |
929 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD),
930 VppMRoutePath(self.pg3.sw_if_index,
931 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT |
932 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
933 route_232_1_1_1.add_vpp_config()
935 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
936 self.pg0.add_stream(tx)
938 self.pg_enable_capture(self.pg_interfaces)
941 # We expect replications on Pg1, 2, 3, but not on pg0
942 self.verify_capture_ip4(self.pg1, tx)
943 self.verify_capture_ip4(self.pg2, tx)
944 self.verify_capture_ip4(self.pg3, tx)
945 self.pg0.assert_nothing_captured(
946 remark="IP multicast packets forwarded on PG0")
949 if __name__ == '__main__':
950 unittest.main(testRunner=VppTestRunner)