5 from framework import VppTestCase, VppTestRunner
6 from vpp_ip import DpoProto
7 from vpp_ip_route import VppIpMRoute, VppMRoutePath, VppMFibSignal, \
8 VppIpTable, FibPathProto
9 from vpp_gre_interface import VppGreInterface
10 from vpp_papi import VppEnum
12 from scapy.packet import Raw
13 from scapy.layers.l2 import Ether, GRE
14 from scapy.layers.inet import IP, UDP, getmacbyip
15 from scapy.layers.inet6 import IPv6, getmacbyip6
18 # The number of packets sent is set to 91 so that when we replicate more than 3
19 # times, which we do for some entries, we will generate more than 256 packets
20 # to the next node in the VLIB graph. Thus we are testing the code's
21 # correctness handling this over-flow.
22 # It's also an odd number so we hit any single loops.
27 class TestMFIB(VppTestCase):
28 """ MFIB Test Case """
32 super(TestMFIB, cls).setUpClass()
35 def tearDownClass(cls):
36 super(TestMFIB, cls).tearDownClass()
39 super(TestMFIB, self).setUp()
42 """ MFIB Unit Tests """
43 error = self.vapi.cli("test mfib")
46 self.logger.critical(error)
47 self.assertNotIn("Failed", error)
50 class TestIPMcast(VppTestCase):
51 """ IP Multicast Test Case """
55 super(TestIPMcast, cls).setUpClass()
58 def tearDownClass(cls):
59 super(TestIPMcast, cls).tearDownClass()
62 super(TestIPMcast, self).setUp()
64 # create 8 pg interfaces
65 self.create_pg_interfaces(range(9))
68 for i in self.pg_interfaces[:8]:
76 tbl4 = VppIpTable(self, 10)
78 self.pg8.set_table_ip4(10)
81 tbl6 = VppIpTable(self, 10, is_ip6=1)
83 self.pg8.set_table_ip6(10)
87 for i in self.pg_interfaces:
92 self.pg8.set_table_ip4(0)
93 self.pg8.set_table_ip6(0)
94 super(TestIPMcast, self).tearDown()
96 def create_stream_ip4(self, src_if, src_ip, dst_ip, payload_size=0):
98 # default to small packet sizes
99 p = (Ether(dst=getmacbyip(dst_ip), src=src_if.remote_mac) /
100 IP(src=src_ip, dst=dst_ip) /
101 UDP(sport=1234, dport=1234))
103 payload_size = 64 - len(p)
104 p = p / Raw(b'\xa5' * payload_size)
106 for i in range(0, N_PKTS_IN_STREAM):
110 def create_stream_ip6(self, src_if, src_ip, dst_ip):
112 for i in range(0, N_PKTS_IN_STREAM):
113 info = self.create_packet_info(src_if, src_if)
114 payload = self.info_to_payload(info)
115 p = (Ether(dst=getmacbyip6(dst_ip), src=src_if.remote_mac) /
116 IPv6(src=src_ip, dst=dst_ip) /
117 UDP(sport=1234, dport=1234) /
123 def verify_filter(self, capture, sent):
124 if not len(capture) == len(sent):
125 # filter out any IPv6 RAs from the capture
127 if (p.haslayer(IPv6)):
131 def verify_capture_ip4(self, rx_if, sent, dst_mac=None):
132 rxd = rx_if.get_capture(len(sent))
135 capture = self.verify_filter(rxd, sent)
137 self.assertEqual(len(capture), len(sent))
139 for i in range(len(capture)):
144 self.assertEqual(eth.type, 0x800)
150 dst_mac = getmacbyip(rx_ip.dst)
152 # check the MAC address on the RX'd packet is correctly formed
153 self.assertEqual(eth.dst, dst_mac)
155 self.assertEqual(rx_ip.src, tx_ip.src)
156 self.assertEqual(rx_ip.dst, tx_ip.dst)
157 # IP processing post pop has decremented the TTL
158 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
163 def verify_capture_ip6(self, rx_if, sent):
164 capture = rx_if.get_capture(len(sent))
166 self.assertEqual(len(capture), len(sent))
168 for i in range(len(capture)):
173 self.assertEqual(eth.type, 0x86DD)
178 # check the MAC address on the RX'd packet is correctly formed
179 self.assertEqual(eth.dst, getmacbyip6(rx_ip.dst))
181 self.assertEqual(rx_ip.src, tx_ip.src)
182 self.assertEqual(rx_ip.dst, tx_ip.dst)
183 # IP processing post pop has decremented the TTL
184 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
186 def test_ip_mcast(self):
187 """ IP Multicast Replication """
189 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
190 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
193 # a stream that matches the default route. gets dropped.
195 self.vapi.cli("clear trace")
196 self.vapi.cli("packet mac-filter pg0 on")
197 self.vapi.cli("packet mac-filter pg1 on")
198 self.vapi.cli("packet mac-filter pg2 on")
199 self.vapi.cli("packet mac-filter pg4 on")
200 self.vapi.cli("packet mac-filter pg5 on")
201 self.vapi.cli("packet mac-filter pg6 on")
202 self.vapi.cli("packet mac-filter pg7 on")
204 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
205 self.pg0.add_stream(tx)
207 self.pg_enable_capture(self.pg_interfaces)
210 self.pg0.assert_nothing_captured(
211 remark="IP multicast packets forwarded on default route")
215 # one accepting interface, pg0, 7 forwarding interfaces
216 # many forwarding interfaces test the case where the replicate DPO
217 # needs to use extra cache lines for the buckets.
219 route_232_1_1_1 = VppIpMRoute(
223 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
224 [VppMRoutePath(self.pg0.sw_if_index,
225 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
226 VppMRoutePath(self.pg1.sw_if_index,
227 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
228 VppMRoutePath(self.pg2.sw_if_index,
229 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
230 VppMRoutePath(self.pg3.sw_if_index,
231 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
232 VppMRoutePath(self.pg4.sw_if_index,
233 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
234 VppMRoutePath(self.pg5.sw_if_index,
235 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
236 VppMRoutePath(self.pg6.sw_if_index,
237 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
238 VppMRoutePath(self.pg7.sw_if_index,
239 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
240 route_232_1_1_1.add_vpp_config()
244 # one accepting interface, pg0, 2 forwarding interfaces
246 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
249 "232.1.1.1", 27, # any grp-len is ok when src is set
250 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
251 [VppMRoutePath(self.pg0.sw_if_index,
252 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
253 VppMRoutePath(self.pg1.sw_if_index,
254 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
255 VppMRoutePath(self.pg2.sw_if_index,
256 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
257 route_1_1_1_1_232_1_1_1.add_vpp_config()
261 # one accepting interface, pg0, 2 forwarding interfaces
262 # that use unicast next-hops
264 route_1_1_1_1_232_1_1_2 = VppIpMRoute(
268 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
269 [VppMRoutePath(self.pg0.sw_if_index,
270 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
271 VppMRoutePath(self.pg1.sw_if_index,
272 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
273 nh=self.pg1.remote_ip4),
274 VppMRoutePath(self.pg2.sw_if_index,
275 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
276 nh=self.pg2.remote_ip4)])
277 route_1_1_1_1_232_1_1_2.add_vpp_config()
281 # one accepting interface, pg0, 1 forwarding interfaces
283 route_232 = VppIpMRoute(
287 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
288 [VppMRoutePath(self.pg0.sw_if_index,
289 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
290 VppMRoutePath(self.pg1.sw_if_index,
291 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
292 route_232.add_vpp_config()
295 # a stream that matches the route for (1.1.1.1,232.1.1.1)
298 self.vapi.cli("clear trace")
299 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
300 self.pg0.add_stream(tx)
302 self.pg_enable_capture(self.pg_interfaces)
305 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
308 # We expect replications on Pg1->7
309 self.verify_capture_ip4(self.pg1, tx)
310 self.verify_capture_ip4(self.pg2, tx)
312 # no replications on Pg0
313 self.pg0.assert_nothing_captured(
314 remark="IP multicast packets forwarded on PG0")
315 self.pg3.assert_nothing_captured(
316 remark="IP multicast packets forwarded on PG3")
319 # a stream that matches the route for (1.1.1.1,232.1.1.1)
322 self.vapi.cli("clear trace")
323 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1",
325 self.pg0.add_stream(tx)
327 self.pg_enable_capture(self.pg_interfaces)
330 # We expect replications on Pg1->7
331 self.verify_capture_ip4(self.pg1, tx)
332 self.verify_capture_ip4(self.pg2, tx)
334 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
337 # no replications on Pg0
338 self.pg0.assert_nothing_captured(
339 remark="IP multicast packets forwarded on PG0")
340 self.pg3.assert_nothing_captured(
341 remark="IP multicast packets forwarded on PG3")
344 # a stream to the unicast next-hops
346 self.vapi.cli("clear trace")
347 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.2")
348 self.pg0.add_stream(tx)
350 self.pg_enable_capture(self.pg_interfaces)
353 # We expect replications on Pg1->7
354 self.verify_capture_ip4(self.pg1, tx, dst_mac=self.pg1.remote_mac)
355 self.verify_capture_ip4(self.pg2, tx, dst_mac=self.pg2.remote_mac)
357 # no replications on Pg0 nor pg3
358 self.pg0.assert_nothing_captured(
359 remark="IP multicast packets forwarded on PG0")
360 self.pg3.assert_nothing_captured(
361 remark="IP multicast packets forwarded on PG3")
364 # a stream that matches the route for (*,232.0.0.0/8)
365 # Send packets with the 9th bit set so we test the correct clearing
366 # of that bit in the mac rewrite
368 self.vapi.cli("clear trace")
369 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.255.255.255")
370 self.pg0.add_stream(tx)
372 self.pg_enable_capture(self.pg_interfaces)
375 # We expect replications on Pg1 only
376 self.verify_capture_ip4(self.pg1, tx)
377 self.assertEqual(route_232.get_stats()['packets'], len(tx))
379 # no replications on Pg0, Pg2 not Pg3
380 self.pg0.assert_nothing_captured(
381 remark="IP multicast packets forwarded on PG0")
382 self.pg2.assert_nothing_captured(
383 remark="IP multicast packets forwarded on PG2")
384 self.pg3.assert_nothing_captured(
385 remark="IP multicast packets forwarded on PG3")
388 # a stream that matches the route for (*,232.1.1.1)
390 self.vapi.cli("clear trace")
391 tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "232.1.1.1")
392 self.pg0.add_stream(tx)
394 self.pg_enable_capture(self.pg_interfaces)
397 # We expect replications on Pg1->7
398 self.verify_capture_ip4(self.pg1, tx)
399 self.verify_capture_ip4(self.pg2, tx)
400 self.verify_capture_ip4(self.pg3, tx)
401 self.verify_capture_ip4(self.pg4, tx)
402 self.verify_capture_ip4(self.pg5, tx)
403 self.verify_capture_ip4(self.pg6, tx)
404 self.verify_capture_ip4(self.pg7, tx)
406 # no replications on Pg0
407 self.pg0.assert_nothing_captured(
408 remark="IP multicast packets forwarded on PG0")
410 self.vapi.cli("packet mac-filter pg0 off")
411 self.vapi.cli("packet mac-filter pg1 off")
412 self.vapi.cli("packet mac-filter pg2 off")
413 self.vapi.cli("packet mac-filter pg4 off")
414 self.vapi.cli("packet mac-filter pg5 off")
415 self.vapi.cli("packet mac-filter pg6 off")
416 self.vapi.cli("packet mac-filter pg7 off")
418 def test_ip6_mcast(self):
419 """ IPv6 Multicast Replication """
421 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
422 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
424 self.vapi.cli("packet mac-filter pg0 on")
425 self.vapi.cli("packet mac-filter pg1 on")
426 self.vapi.cli("packet mac-filter pg2 on")
427 self.vapi.cli("packet mac-filter pg4 on")
428 self.vapi.cli("packet mac-filter pg5 on")
429 self.vapi.cli("packet mac-filter pg6 on")
430 self.vapi.cli("packet mac-filter pg7 on")
432 # a stream that matches the default route. gets dropped.
434 self.vapi.cli("clear trace")
435 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
436 self.pg0.add_stream(tx)
438 self.pg_enable_capture(self.pg_interfaces)
441 self.pg0.assert_nothing_captured(
442 remark="IPv6 multicast packets forwarded on default route")
446 # one accepting interface, pg0, 3 forwarding interfaces
448 route_ff01_1 = VppIpMRoute(
452 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
453 [VppMRoutePath(self.pg0.sw_if_index,
454 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
455 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
456 VppMRoutePath(self.pg1.sw_if_index,
457 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
458 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
459 VppMRoutePath(self.pg2.sw_if_index,
460 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
461 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
462 VppMRoutePath(self.pg3.sw_if_index,
463 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
464 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
465 route_ff01_1.add_vpp_config()
469 # one accepting interface, pg0, 2 forwarding interfaces
471 route_2001_ff01_1 = VppIpMRoute(
474 "ff01::1", 0, # any grp-len is ok when src is set
475 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
476 [VppMRoutePath(self.pg0.sw_if_index,
477 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
478 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
479 VppMRoutePath(self.pg1.sw_if_index,
480 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
481 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
482 VppMRoutePath(self.pg2.sw_if_index,
483 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
484 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
485 route_2001_ff01_1.add_vpp_config()
489 # one accepting interface, pg0, 1 forwarding interface
491 route_ff01 = VppIpMRoute(
495 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
496 [VppMRoutePath(self.pg0.sw_if_index,
497 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
498 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
499 VppMRoutePath(self.pg1.sw_if_index,
500 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
501 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
502 route_ff01.add_vpp_config()
505 # a stream that matches the route for (*, ff01::/16)
506 # sent on the non-accepting interface
508 self.vapi.cli("clear trace")
509 tx = self.create_stream_ip6(self.pg1, "2002::1", "ff01:2::255")
510 self.send_and_assert_no_replies(self.pg1, tx, "RPF miss")
513 # a stream that matches the route for (*, ff01::/16)
514 # sent on the accepting interface
516 self.vapi.cli("clear trace")
517 tx = self.create_stream_ip6(self.pg0, "2002::1", "ff01:2::255")
518 self.pg0.add_stream(tx)
520 self.pg_enable_capture(self.pg_interfaces)
523 # We expect replications on Pg1
524 self.verify_capture_ip6(self.pg1, tx)
526 # no replications on Pg0, Pg3
527 self.pg0.assert_nothing_captured(
528 remark="IP multicast packets forwarded on PG0")
529 self.pg2.assert_nothing_captured(
530 remark="IP multicast packets forwarded on PG2")
531 self.pg3.assert_nothing_captured(
532 remark="IP multicast packets forwarded on PG3")
535 # Bounce the interface and it should still work
537 self.pg1.admin_down()
538 self.pg0.add_stream(tx)
539 self.pg_enable_capture(self.pg_interfaces)
541 self.pg1.assert_nothing_captured(
542 remark="IP multicast packets forwarded on down PG1")
545 self.pg0.add_stream(tx)
546 self.pg_enable_capture(self.pg_interfaces)
548 self.verify_capture_ip6(self.pg1, tx)
551 # a stream that matches the route for (*,ff01::1)
553 self.vapi.cli("clear trace")
554 tx = self.create_stream_ip6(self.pg0, "2002::2", "ff01::1")
555 self.pg0.add_stream(tx)
557 self.pg_enable_capture(self.pg_interfaces)
560 # We expect replications on Pg1, 2, 3.
561 self.verify_capture_ip6(self.pg1, tx)
562 self.verify_capture_ip6(self.pg2, tx)
563 self.verify_capture_ip6(self.pg3, tx)
565 # no replications on Pg0
566 self.pg0.assert_nothing_captured(
567 remark="IPv6 multicast packets forwarded on PG0")
570 # a stream that matches the route for (2001::1, ff00::1)
572 self.vapi.cli("clear trace")
573 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
574 self.pg0.add_stream(tx)
576 self.pg_enable_capture(self.pg_interfaces)
579 # We expect replications on Pg1, 2,
580 self.verify_capture_ip6(self.pg1, tx)
581 self.verify_capture_ip6(self.pg2, tx)
583 # no replications on Pg0, Pg3
584 self.pg0.assert_nothing_captured(
585 remark="IP multicast packets forwarded on PG0")
586 self.pg3.assert_nothing_captured(
587 remark="IP multicast packets forwarded on PG3")
589 self.vapi.cli("packet mac-filter pg0 off")
590 self.vapi.cli("packet mac-filter pg1 off")
591 self.vapi.cli("packet mac-filter pg2 off")
592 self.vapi.cli("packet mac-filter pg4 off")
593 self.vapi.cli("packet mac-filter pg5 off")
594 self.vapi.cli("packet mac-filter pg6 off")
595 self.vapi.cli("packet mac-filter pg7 off")
597 def _mcast_connected_send_stream(self, dst_ip):
598 self.vapi.cli("clear trace")
599 tx = self.create_stream_ip4(self.pg0,
602 self.pg0.add_stream(tx)
604 self.pg_enable_capture(self.pg_interfaces)
607 # We expect replications on Pg1.
608 self.verify_capture_ip4(self.pg1, tx)
612 def test_ip_mcast_connected(self):
613 """ IP Multicast Connected Source check """
615 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
616 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
620 # one accepting interface, pg0, 1 forwarding interfaces
622 route_232_1_1_1 = VppIpMRoute(
626 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
627 [VppMRoutePath(self.pg0.sw_if_index,
628 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
629 VppMRoutePath(self.pg1.sw_if_index,
630 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
632 route_232_1_1_1.add_vpp_config()
633 route_232_1_1_1.update_entry_flags(
634 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_CONNECTED)
637 # Now the (*,G) is present, send from connected source
639 tx = self._mcast_connected_send_stream("232.1.1.1")
642 # Constrct a representation of the signal we expect on pg0
644 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
646 self.pg0.sw_if_index,
650 # read the only expected signal
652 signals = self.vapi.mfib_signal_dump()
654 self.assertEqual(1, len(signals))
656 signal_232_1_1_1_itf_0.compare(signals[0])
659 # reading the signal allows for the generation of another
660 # so send more packets and expect the next signal
662 tx = self._mcast_connected_send_stream("232.1.1.1")
664 signals = self.vapi.mfib_signal_dump()
665 self.assertEqual(1, len(signals))
666 signal_232_1_1_1_itf_0.compare(signals[0])
669 # A Second entry with connected check
670 # one accepting interface, pg0, 1 forwarding interfaces
672 route_232_1_1_2 = VppIpMRoute(
676 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
677 [VppMRoutePath(self.pg0.sw_if_index,
678 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
679 VppMRoutePath(self.pg1.sw_if_index,
680 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
682 route_232_1_1_2.add_vpp_config()
683 route_232_1_1_2.update_entry_flags(
684 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_CONNECTED)
687 # Send traffic to both entries. One read should net us two signals
689 signal_232_1_1_2_itf_0 = VppMFibSignal(self,
691 self.pg0.sw_if_index,
693 tx = self._mcast_connected_send_stream("232.1.1.1")
694 tx2 = self._mcast_connected_send_stream("232.1.1.2")
697 # read the only expected signal
699 signals = self.vapi.mfib_signal_dump()
701 self.assertEqual(2, len(signals))
703 signal_232_1_1_1_itf_0.compare(signals[1])
704 signal_232_1_1_2_itf_0.compare(signals[0])
706 route_232_1_1_1.update_entry_flags(
707 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE)
708 route_232_1_1_2.update_entry_flags(
709 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE)
711 def test_ip_mcast_signal(self):
712 """ IP Multicast Signal """
714 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
715 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
719 # one accepting interface, pg0, 1 forwarding interfaces
721 route_232_1_1_1 = VppIpMRoute(
725 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
726 [VppMRoutePath(self.pg0.sw_if_index,
727 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
728 VppMRoutePath(self.pg1.sw_if_index,
729 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
731 route_232_1_1_1.add_vpp_config()
733 route_232_1_1_1.update_entry_flags(
734 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_SIGNAL)
737 # Now the (*,G) is present, send from connected source
739 tx = self._mcast_connected_send_stream("232.1.1.1")
742 # Constrct a representation of the signal we expect on pg0
744 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
746 self.pg0.sw_if_index,
750 # read the only expected signal
752 signals = self.vapi.mfib_signal_dump()
754 self.assertEqual(1, len(signals))
756 signal_232_1_1_1_itf_0.compare(signals[0])
759 # reading the signal allows for the generation of another
760 # so send more packets and expect the next signal
762 tx = self._mcast_connected_send_stream("232.1.1.1")
764 signals = self.vapi.mfib_signal_dump()
765 self.assertEqual(1, len(signals))
766 signal_232_1_1_1_itf_0.compare(signals[0])
769 # Set the negate-signal on the accepting interval - the signals
772 route_232_1_1_1.update_path_flags(
773 self.pg0.sw_if_index,
774 (MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
775 MRouteItfFlags.MFIB_API_ITF_FLAG_NEGATE_SIGNAL))
777 self.vapi.cli("clear trace")
778 tx = self._mcast_connected_send_stream("232.1.1.1")
780 signals = self.vapi.mfib_signal_dump()
781 self.assertEqual(0, len(signals))
784 # Clear the SIGNAL flag on the entry and the signals should
785 # come back since the interface is still NEGATE-SIGNAL
787 route_232_1_1_1.update_entry_flags(
788 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE)
790 tx = self._mcast_connected_send_stream("232.1.1.1")
792 signals = self.vapi.mfib_signal_dump()
793 self.assertEqual(1, len(signals))
794 signal_232_1_1_1_itf_0.compare(signals[0])
797 # Lastly remove the NEGATE-SIGNAL from the interface and the
798 # signals should stop
800 route_232_1_1_1.update_path_flags(
801 self.pg0.sw_if_index,
802 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT)
804 tx = self._mcast_connected_send_stream("232.1.1.1")
805 signals = self.vapi.mfib_signal_dump()
806 self.assertEqual(0, len(signals))
808 def test_ip_mcast_vrf(self):
809 """ IP Multicast Replication in non-default table"""
811 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
812 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
816 # one accepting interface, pg0, 2 forwarding interfaces
818 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
822 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
823 [VppMRoutePath(self.pg8.sw_if_index,
824 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
825 VppMRoutePath(self.pg1.sw_if_index,
826 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
827 VppMRoutePath(self.pg2.sw_if_index,
828 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)],
830 route_1_1_1_1_232_1_1_1.add_vpp_config()
833 # a stream that matches the route for (1.1.1.1,232.1.1.1)
836 self.vapi.cli("clear trace")
837 tx = self.create_stream_ip4(self.pg8, "1.1.1.1", "232.1.1.1")
838 self.pg8.add_stream(tx)
840 self.pg_enable_capture(self.pg_interfaces)
843 # We expect replications on Pg1 & 2
844 self.verify_capture_ip4(self.pg1, tx)
845 self.verify_capture_ip4(self.pg2, tx)
847 def test_ip_mcast_gre(self):
848 """ IP Multicast Replication over GRE"""
850 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
851 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
853 gre_if_1 = VppGreInterface(
856 self.pg1.remote_ip4).add_vpp_config()
857 gre_if_2 = VppGreInterface(
860 self.pg2.remote_ip4).add_vpp_config()
861 gre_if_3 = VppGreInterface(
864 self.pg3.remote_ip4).add_vpp_config()
867 gre_if_1.config_ip4()
869 gre_if_2.config_ip4()
871 gre_if_3.config_ip4()
875 # one accepting interface, pg0, 2 forwarding interfaces
877 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
881 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
882 [VppMRoutePath(gre_if_1.sw_if_index,
883 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
884 VppMRoutePath(gre_if_2.sw_if_index,
885 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
886 VppMRoutePath(gre_if_3.sw_if_index,
887 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
888 route_1_1_1_1_232_1_1_1.add_vpp_config()
891 # a stream that matches the route for (1.1.1.1,232.2.2.2)
894 tx = (Ether(dst=self.pg1.local_mac,
895 src=self.pg1.remote_mac) /
896 IP(src=self.pg1.remote_ip4,
897 dst=self.pg1.local_ip4) /
899 IP(src="1.1.1.1", dst="232.2.2.2") /
900 UDP(sport=1234, dport=1234) /
901 Raw(b'\a5' * 64)) * 63
903 self.vapi.cli("clear trace")
904 self.pg1.add_stream(tx)
906 self.pg_enable_capture(self.pg_interfaces)
909 # We expect replications on Pg2 & 3
910 # check the encap headers are as expected based on the egress tunnel
911 rxs = self.pg2.get_capture(len(tx))
913 self.assertEqual(rx[IP].src, gre_if_2.t_src)
914 self.assertEqual(rx[IP].dst, gre_if_2.t_dst)
915 self.assert_packet_checksums_valid(rx)
917 rxs = self.pg3.get_capture(len(tx))
919 self.assertEqual(rx[IP].src, gre_if_3.t_src)
920 self.assertEqual(rx[IP].dst, gre_if_3.t_dst)
921 self.assert_packet_checksums_valid(rx)
923 def test_ip6_mcast_gre(self):
924 """ IP6 Multicast Replication over GRE"""
926 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
927 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
929 gre_if_1 = VppGreInterface(
932 self.pg1.remote_ip4).add_vpp_config()
933 gre_if_2 = VppGreInterface(
936 self.pg2.remote_ip4).add_vpp_config()
937 gre_if_3 = VppGreInterface(
940 self.pg3.remote_ip4).add_vpp_config()
943 gre_if_1.config_ip6()
945 gre_if_2.config_ip6()
947 gre_if_3.config_ip6()
951 # one accepting interface, pg0, 2 forwarding interfaces
953 route_1_1_FF_1 = VppIpMRoute(
957 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
958 [VppMRoutePath(gre_if_1.sw_if_index,
959 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
960 VppMRoutePath(gre_if_2.sw_if_index,
961 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
962 VppMRoutePath(gre_if_3.sw_if_index,
963 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
964 route_1_1_FF_1.add_vpp_config()
967 # a stream that matches the route for (1::1, FF::1)
970 tx = (Ether(dst=self.pg1.local_mac,
971 src=self.pg1.remote_mac) /
972 IP(src=self.pg1.remote_ip4,
973 dst=self.pg1.local_ip4) /
975 IPv6(src="1::1", dst="FF00::1") /
976 UDP(sport=1234, dport=1234) /
977 Raw(b'\a5' * 64)) * 63
979 self.vapi.cli("clear trace")
980 self.pg1.add_stream(tx)
982 self.pg_enable_capture(self.pg_interfaces)
985 # We expect replications on Pg2 & 3
986 # check the encap headers are as expected based on the egress tunnel
987 rxs = self.pg2.get_capture(len(tx))
989 self.assertEqual(rx[IP].src, gre_if_2.t_src)
990 self.assertEqual(rx[IP].dst, gre_if_2.t_dst)
991 self.assert_packet_checksums_valid(rx)
993 rxs = self.pg3.get_capture(len(tx))
995 self.assertEqual(rx[IP].src, gre_if_3.t_src)
996 self.assertEqual(rx[IP].dst, gre_if_3.t_dst)
997 self.assert_packet_checksums_valid(rx)
999 def test_ip6_mcast_vrf(self):
1000 """ IPv6 Multicast Replication in non-default table"""
1002 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
1003 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
1007 # one accepting interface, pg0, 2 forwarding interfaces
1009 route_2001_ff01_1 = VppIpMRoute(
1013 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
1014 [VppMRoutePath(self.pg8.sw_if_index,
1015 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
1016 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
1017 VppMRoutePath(self.pg1.sw_if_index,
1018 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
1019 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
1020 VppMRoutePath(self.pg2.sw_if_index,
1021 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
1022 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
1024 route_2001_ff01_1.add_vpp_config()
1027 # a stream that matches the route for (2001::1, ff00::1)
1029 self.vapi.cli("clear trace")
1030 tx = self.create_stream_ip6(self.pg8, "2001::1", "ff01::1")
1031 self.pg8.add_stream(tx)
1033 self.pg_enable_capture(self.pg_interfaces)
1036 # We expect replications on Pg1, 2,
1037 self.verify_capture_ip6(self.pg1, tx)
1038 self.verify_capture_ip6(self.pg2, tx)
1040 def test_bidir(self):
1041 """ IP Multicast Bi-directional """
1043 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
1044 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
1047 # A (*,G). The set of accepting interfaces matching the forwarding
1049 route_232_1_1_1 = VppIpMRoute(
1053 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
1054 [VppMRoutePath(self.pg0.sw_if_index,
1055 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1056 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
1057 VppMRoutePath(self.pg1.sw_if_index,
1058 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1059 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
1060 VppMRoutePath(self.pg2.sw_if_index,
1061 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1062 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
1063 VppMRoutePath(self.pg3.sw_if_index,
1064 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1065 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
1066 route_232_1_1_1.add_vpp_config()
1068 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
1069 self.pg0.add_stream(tx)
1071 self.pg_enable_capture(self.pg_interfaces)
1074 # We expect replications on Pg1, 2, 3, but not on pg0
1075 self.verify_capture_ip4(self.pg1, tx)
1076 self.verify_capture_ip4(self.pg2, tx)
1077 self.verify_capture_ip4(self.pg3, tx)
1078 self.pg0.assert_nothing_captured(
1079 remark="IP multicast packets forwarded on PG0")
1082 if __name__ == '__main__':
1083 unittest.main(testRunner=VppTestRunner)