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=getmacbyip(dst_ip), 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=getmacbyip6(dst_ip), 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 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")
200 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
201 self.pg0.add_stream(tx)
203 self.pg_enable_capture(self.pg_interfaces)
206 self.pg0.assert_nothing_captured(
207 remark="IP multicast packets forwarded on default route")
211 # one accepting interface, pg0, 7 forwarding interfaces
212 # many forwarding interfaces test the case where the replicate DPO
213 # needs to use extra cache lines for the buckets.
215 route_232_1_1_1 = VppIpMRoute(
219 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
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,
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,
235 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD)])
236 route_232_1_1_1.add_vpp_config()
240 # one accepting interface, pg0, 2 forwarding interfaces
242 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
245 "232.1.1.1", 27, # any grp-len is ok when src is set
246 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
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)])
253 route_1_1_1_1_232_1_1_1.add_vpp_config()
257 # one accepting interface, pg0, 2 forwarding interfaces
258 # that use unicast next-hops
260 route_1_1_1_1_232_1_1_2 = VppIpMRoute(
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()
277 # one accepting interface, pg0, 1 forwarding interfaces
279 route_232 = VppIpMRoute(
283 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
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)])
288 route_232.add_vpp_config()
291 # a stream that matches the route for (1.1.1.1,232.1.1.1)
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)
298 self.pg_enable_capture(self.pg_interfaces)
301 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
304 # We expect replications on Pg1->7
305 self.verify_capture_ip4(self.pg1, tx)
306 self.verify_capture_ip4(self.pg2, tx)
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")
315 # a stream that matches the route for (1.1.1.1,232.1.1.1)
318 self.vapi.cli("clear trace")
319 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1",
321 self.pg0.add_stream(tx)
323 self.pg_enable_capture(self.pg_interfaces)
326 # We expect replications on Pg1->7
327 self.verify_capture_ip4(self.pg1, tx)
328 self.verify_capture_ip4(self.pg2, tx)
330 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
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")
340 # a stream to the unicast next-hops
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)
346 self.pg_enable_capture(self.pg_interfaces)
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)
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")
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
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)
368 self.pg_enable_capture(self.pg_interfaces)
371 # We expect replications on Pg1 only
372 self.verify_capture_ip4(self.pg1, tx)
373 self.assertEqual(route_232.get_stats()['packets'], len(tx))
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")
384 # a stream that matches the route for (*,232.1.1.1)
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)
390 self.pg_enable_capture(self.pg_interfaces)
393 # We expect replications on Pg1->7
394 self.verify_capture_ip4(self.pg1, tx)
395 self.verify_capture_ip4(self.pg2, tx)
396 self.verify_capture_ip4(self.pg3, tx)
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)
402 # no replications on Pg0
403 self.pg0.assert_nothing_captured(
404 remark="IP multicast packets forwarded on PG0")
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")
414 def test_ip6_mcast(self):
415 """ IPv6 Multicast Replication """
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")
425 # a stream that matches the default route. gets dropped.
427 self.vapi.cli("clear trace")
428 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
429 self.pg0.add_stream(tx)
431 self.pg_enable_capture(self.pg_interfaces)
434 self.pg0.assert_nothing_captured(
435 remark="IPv6 multicast packets forwarded on default route")
439 # one accepting interface, pg0, 3 forwarding interfaces
441 route_ff01_1 = VppIpMRoute(
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 VppMRoutePath(self.pg3.sw_if_index,
456 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
457 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
458 route_ff01_1.add_vpp_config()
462 # one accepting interface, pg0, 2 forwarding interfaces
464 route_2001_ff01_1 = VppIpMRoute(
467 "ff01::1", 0, # any grp-len is ok when src is set
468 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
469 [VppMRoutePath(self.pg0.sw_if_index,
470 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
471 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
472 VppMRoutePath(self.pg1.sw_if_index,
473 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
474 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
475 VppMRoutePath(self.pg2.sw_if_index,
476 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
477 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
478 route_2001_ff01_1.add_vpp_config()
482 # one accepting interface, pg0, 1 forwarding interface
484 route_ff01 = VppIpMRoute(
488 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
489 [VppMRoutePath(self.pg0.sw_if_index,
490 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
491 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
492 VppMRoutePath(self.pg1.sw_if_index,
493 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
494 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
495 route_ff01.add_vpp_config()
498 # a stream that matches the route for (*, ff01::/16)
499 # sent on the non-accepting interface
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")
506 # a stream that matches the route for (*, ff01::/16)
507 # sent on the accepting interface
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)
513 self.pg_enable_capture(self.pg_interfaces)
516 # We expect replications on Pg1
517 self.verify_capture_ip6(self.pg1, tx)
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")
528 # Bounce the interface and it should still work
530 self.pg1.admin_down()
531 self.pg0.add_stream(tx)
532 self.pg_enable_capture(self.pg_interfaces)
534 self.pg1.assert_nothing_captured(
535 remark="IP multicast packets forwarded on down PG1")
538 self.pg0.add_stream(tx)
539 self.pg_enable_capture(self.pg_interfaces)
541 self.verify_capture_ip6(self.pg1, tx)
544 # a stream that matches the route for (*,ff01::1)
546 self.vapi.cli("clear trace")
547 tx = self.create_stream_ip6(self.pg0, "2002::2", "ff01::1")
548 self.pg0.add_stream(tx)
550 self.pg_enable_capture(self.pg_interfaces)
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)
558 # no replications on Pg0
559 self.pg0.assert_nothing_captured(
560 remark="IPv6 multicast packets forwarded on PG0")
563 # a stream that matches the route for (2001::1, ff00::1)
565 self.vapi.cli("clear trace")
566 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
567 self.pg0.add_stream(tx)
569 self.pg_enable_capture(self.pg_interfaces)
572 # We expect replications on Pg1, 2,
573 self.verify_capture_ip6(self.pg1, tx)
574 self.verify_capture_ip6(self.pg2, tx)
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")
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")
590 def _mcast_connected_send_stream(self, dst_ip):
591 self.vapi.cli("clear trace")
592 tx = self.create_stream_ip4(self.pg0,
595 self.pg0.add_stream(tx)
597 self.pg_enable_capture(self.pg_interfaces)
600 # We expect replications on Pg1.
601 self.verify_capture_ip4(self.pg1, tx)
605 def test_ip_mcast_connected(self):
606 """ IP Multicast Connected Source check """
610 # one accepting interface, pg0, 1 forwarding interfaces
612 route_232_1_1_1 = VppIpMRoute(
616 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
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)])
622 route_232_1_1_1.add_vpp_config()
623 route_232_1_1_1.update_entry_flags(
624 MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED)
627 # Now the (*,G) is present, send from connected source
629 tx = self._mcast_connected_send_stream("232.1.1.1")
632 # Constrct a representation of the signal we expect on pg0
634 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
636 self.pg0.sw_if_index,
640 # read the only expected signal
642 signals = self.vapi.mfib_signal_dump()
644 self.assertEqual(1, len(signals))
646 signal_232_1_1_1_itf_0.compare(signals[0])
649 # reading the signal allows for the generation of another
650 # so send more packets and expect the next signal
652 tx = self._mcast_connected_send_stream("232.1.1.1")
654 signals = self.vapi.mfib_signal_dump()
655 self.assertEqual(1, len(signals))
656 signal_232_1_1_1_itf_0.compare(signals[0])
659 # A Second entry with connected check
660 # one accepting interface, pg0, 1 forwarding interfaces
662 route_232_1_1_2 = VppIpMRoute(
666 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
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)])
672 route_232_1_1_2.add_vpp_config()
673 route_232_1_1_2.update_entry_flags(
674 MRouteEntryFlags.MFIB_ENTRY_FLAG_CONNECTED)
677 # Send traffic to both entries. One read should net us two signals
679 signal_232_1_1_2_itf_0 = VppMFibSignal(self,
681 self.pg0.sw_if_index,
683 tx = self._mcast_connected_send_stream("232.1.1.1")
684 tx2 = self._mcast_connected_send_stream("232.1.1.2")
687 # read the only expected signal
689 signals = self.vapi.mfib_signal_dump()
691 self.assertEqual(2, len(signals))
693 signal_232_1_1_1_itf_0.compare(signals[1])
694 signal_232_1_1_2_itf_0.compare(signals[0])
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)
701 def test_ip_mcast_signal(self):
702 """ IP Multicast Signal """
706 # one accepting interface, pg0, 1 forwarding interfaces
708 route_232_1_1_1 = VppIpMRoute(
712 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
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)])
718 route_232_1_1_1.add_vpp_config()
720 route_232_1_1_1.update_entry_flags(
721 MRouteEntryFlags.MFIB_ENTRY_FLAG_SIGNAL)
724 # Now the (*,G) is present, send from connected source
726 tx = self._mcast_connected_send_stream("232.1.1.1")
729 # Constrct a representation of the signal we expect on pg0
731 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
733 self.pg0.sw_if_index,
737 # read the only expected signal
739 signals = self.vapi.mfib_signal_dump()
741 self.assertEqual(1, len(signals))
743 signal_232_1_1_1_itf_0.compare(signals[0])
746 # reading the signal allows for the generation of another
747 # so send more packets and expect the next signal
749 tx = self._mcast_connected_send_stream("232.1.1.1")
751 signals = self.vapi.mfib_signal_dump()
752 self.assertEqual(1, len(signals))
753 signal_232_1_1_1_itf_0.compare(signals[0])
756 # Set the negate-signal on the accepting interval - the signals
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))
764 self.vapi.cli("clear trace")
765 tx = self._mcast_connected_send_stream("232.1.1.1")
767 signals = self.vapi.mfib_signal_dump()
768 self.assertEqual(0, len(signals))
771 # Clear the SIGNAL flag on the entry and the signals should
772 # come back since the interface is still NEGATE-SIGNAL
774 route_232_1_1_1.update_entry_flags(
775 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE)
777 tx = self._mcast_connected_send_stream("232.1.1.1")
779 signals = self.vapi.mfib_signal_dump()
780 self.assertEqual(1, len(signals))
781 signal_232_1_1_1_itf_0.compare(signals[0])
784 # Lastly remove the NEGATE-SIGNAL from the interface and the
785 # signals should stop
787 route_232_1_1_1.update_path_flags(self.pg0.sw_if_index,
788 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT)
790 tx = self._mcast_connected_send_stream("232.1.1.1")
791 signals = self.vapi.mfib_signal_dump()
792 self.assertEqual(0, len(signals))
794 def test_ip_mcast_vrf(self):
795 """ IP Multicast Replication in non-default table"""
799 # one accepting interface, pg0, 2 forwarding interfaces
801 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
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)],
813 route_1_1_1_1_232_1_1_1.add_vpp_config()
816 # a stream that matches the route for (1.1.1.1,232.1.1.1)
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)
823 self.pg_enable_capture(self.pg_interfaces)
826 # We expect replications on Pg1 & 2
827 self.verify_capture_ip4(self.pg1, tx)
828 self.verify_capture_ip4(self.pg2, tx)
830 def test_ip_mcast_gre(self):
831 """ IP Multicast Replication over GRE"""
833 gre_if_1 = VppGreInterface(
836 self.pg1.remote_ip4).add_vpp_config()
837 gre_if_2 = VppGreInterface(
840 self.pg2.remote_ip4).add_vpp_config()
841 gre_if_3 = VppGreInterface(
844 self.pg3.remote_ip4).add_vpp_config()
847 gre_if_1.config_ip4()
849 gre_if_2.config_ip4()
851 gre_if_3.config_ip4()
855 # one accepting interface, pg0, 2 forwarding interfaces
857 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
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()
871 # a stream that matches the route for (1.1.1.1,232.2.2.2)
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) /
879 IP(src="1.1.1.1", dst="232.2.2.2") /
880 UDP(sport=1234, dport=1234) /
881 Raw(b'\a5' * 64)) * 63
883 self.vapi.cli("clear trace")
884 self.pg1.add_stream(tx)
886 self.pg_enable_capture(self.pg_interfaces)
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))
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)
897 rxs = self.pg3.get_capture(len(tx))
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)
903 def test_ip6_mcast_vrf(self):
904 """ IPv6 Multicast Replication in non-default table"""
908 # one accepting interface, pg0, 2 forwarding interfaces
910 route_2001_ff01_1 = VppIpMRoute(
914 MRouteEntryFlags.MFIB_ENTRY_FLAG_NONE,
915 [VppMRoutePath(self.pg8.sw_if_index,
916 MRouteItfFlags.MFIB_ITF_FLAG_ACCEPT,
917 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
918 VppMRoutePath(self.pg1.sw_if_index,
919 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
920 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
921 VppMRoutePath(self.pg2.sw_if_index,
922 MRouteItfFlags.MFIB_ITF_FLAG_FORWARD,
923 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
925 route_2001_ff01_1.add_vpp_config()
928 # a stream that matches the route for (2001::1, ff00::1)
930 self.vapi.cli("clear trace")
931 tx = self.create_stream_ip6(self.pg8, "2001::1", "ff01::1")
932 self.pg8.add_stream(tx)
934 self.pg_enable_capture(self.pg_interfaces)
937 # We expect replications on Pg1, 2,
938 self.verify_capture_ip6(self.pg1, tx)
939 self.verify_capture_ip6(self.pg2, tx)
941 def test_bidir(self):
942 """ IP Multicast Bi-directional """
945 # A (*,G). The set of accepting interfaces matching the forwarding
947 route_232_1_1_1 = VppIpMRoute(
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()
966 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
967 self.pg0.add_stream(tx)
969 self.pg_enable_capture(self.pg_interfaces)
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")
980 if __name__ == '__main__':
981 unittest.main(testRunner=VppTestRunner)