5 from framework import tag_fixme_vpp_workers
6 from framework import VppTestCase, VppTestRunner
7 from vpp_ip import DpoProto
8 from vpp_ip_route import VppIpMRoute, VppMRoutePath, VppMFibSignal, \
9 VppIpTable, FibPathProto, FibPathType
10 from vpp_gre_interface import VppGreInterface
11 from vpp_papi import VppEnum
13 from scapy.packet import Raw
14 from scapy.layers.l2 import Ether, GRE
15 from scapy.layers.inet import IP, UDP, getmacbyip, ICMP
16 from scapy.layers.inet6 import IPv6, getmacbyip6
19 # The number of packets sent is set to 91 so that when we replicate more than 3
20 # times, which we do for some entries, we will generate more than 256 packets
21 # to the next node in the VLIB graph. Thus we are testing the code's
22 # correctness handling this over-flow.
23 # It's also an odd number so we hit any single loops.
28 class TestMFIB(VppTestCase):
29 """ MFIB Test Case """
33 super(TestMFIB, cls).setUpClass()
36 def tearDownClass(cls):
37 super(TestMFIB, cls).tearDownClass()
40 super(TestMFIB, self).setUp()
43 """ MFIB Unit Tests """
44 error = self.vapi.cli("test mfib")
47 self.logger.critical(error)
48 self.assertNotIn("Failed", error)
51 @tag_fixme_vpp_workers
52 class TestIPMcast(VppTestCase):
53 """ IP Multicast Test Case """
57 super(TestIPMcast, cls).setUpClass()
60 def tearDownClass(cls):
61 super(TestIPMcast, cls).tearDownClass()
64 super(TestIPMcast, self).setUp()
66 # create 8 pg interfaces
67 self.create_pg_interfaces(range(9))
70 for i in self.pg_interfaces[:8]:
78 tbl4 = VppIpTable(self, 10)
80 self.pg8.set_table_ip4(10)
83 tbl6 = VppIpTable(self, 10, is_ip6=1)
85 self.pg8.set_table_ip6(10)
89 for i in self.pg_interfaces:
94 self.pg8.set_table_ip4(0)
95 self.pg8.set_table_ip6(0)
96 super(TestIPMcast, self).tearDown()
98 def create_stream_ip4(self, src_if, src_ip, dst_ip, payload_size=0):
100 # default to small packet sizes
101 p = (Ether(dst=getmacbyip(dst_ip), src=src_if.remote_mac) /
102 IP(src=src_ip, dst=dst_ip) /
103 UDP(sport=1234, dport=1234))
105 payload_size = 64 - len(p)
106 p = p / Raw(b'\xa5' * payload_size)
108 for i in range(0, N_PKTS_IN_STREAM):
112 def create_stream_ip6(self, src_if, src_ip, dst_ip):
114 for i in range(0, N_PKTS_IN_STREAM):
115 info = self.create_packet_info(src_if, src_if)
116 payload = self.info_to_payload(info)
117 p = (Ether(dst=getmacbyip6(dst_ip), src=src_if.remote_mac) /
118 IPv6(src=src_ip, dst=dst_ip) /
119 UDP(sport=1234, dport=1234) /
125 def verify_filter(self, capture, sent):
126 if not len(capture) == len(sent):
127 # filter out any IPv6 RAs from the capture
129 if (p.haslayer(IPv6)):
133 def verify_capture_ip4(self, rx_if, sent, dst_mac=None):
134 rxd = rx_if.get_capture(len(sent))
137 capture = self.verify_filter(rxd, sent)
139 self.assertEqual(len(capture), len(sent))
141 for i in range(len(capture)):
146 self.assertEqual(eth.type, 0x800)
152 dst_mac = getmacbyip(rx_ip.dst)
154 # check the MAC address on the RX'd packet is correctly formed
155 self.assertEqual(eth.dst, dst_mac)
157 self.assertEqual(rx_ip.src, tx_ip.src)
158 self.assertEqual(rx_ip.dst, tx_ip.dst)
159 # IP processing post pop has decremented the TTL
160 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
165 def verify_capture_ip6(self, rx_if, sent):
166 capture = rx_if.get_capture(len(sent))
168 self.assertEqual(len(capture), len(sent))
170 for i in range(len(capture)):
175 self.assertEqual(eth.type, 0x86DD)
180 # check the MAC address on the RX'd packet is correctly formed
181 self.assertEqual(eth.dst, getmacbyip6(rx_ip.dst))
183 self.assertEqual(rx_ip.src, tx_ip.src)
184 self.assertEqual(rx_ip.dst, tx_ip.dst)
185 # IP processing post pop has decremented the TTL
186 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
188 def test_ip_mcast(self):
189 """ IP Multicast Replication """
191 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
192 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
195 # a stream that matches the default route. gets dropped.
197 self.vapi.cli("clear trace")
198 self.vapi.cli("packet mac-filter pg0 on")
199 self.vapi.cli("packet mac-filter pg1 on")
200 self.vapi.cli("packet mac-filter pg2 on")
201 self.vapi.cli("packet mac-filter pg4 on")
202 self.vapi.cli("packet mac-filter pg5 on")
203 self.vapi.cli("packet mac-filter pg6 on")
204 self.vapi.cli("packet mac-filter pg7 on")
206 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
207 self.pg0.add_stream(tx)
209 self.pg_enable_capture(self.pg_interfaces)
212 self.pg0.assert_nothing_captured(
213 remark="IP multicast packets forwarded on default route")
217 # one accepting interface, pg0, 7 forwarding interfaces
218 # many forwarding interfaces test the case where the replicate DPO
219 # needs to use extra cache lines for the buckets.
221 route_232_1_1_1 = VppIpMRoute(
225 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
226 [VppMRoutePath(self.pg0.sw_if_index,
227 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
228 VppMRoutePath(self.pg1.sw_if_index,
229 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
230 VppMRoutePath(self.pg2.sw_if_index,
231 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
232 VppMRoutePath(self.pg3.sw_if_index,
233 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
234 VppMRoutePath(self.pg4.sw_if_index,
235 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
236 VppMRoutePath(self.pg5.sw_if_index,
237 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
238 VppMRoutePath(self.pg6.sw_if_index,
239 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
240 VppMRoutePath(self.pg7.sw_if_index,
241 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
242 route_232_1_1_1.add_vpp_config()
246 # one accepting interface, pg0, 2 forwarding interfaces
248 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
251 "232.1.1.1", 27, # any grp-len is ok when src is set
252 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
253 [VppMRoutePath(self.pg0.sw_if_index,
254 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
255 VppMRoutePath(self.pg1.sw_if_index,
256 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
257 VppMRoutePath(self.pg2.sw_if_index,
258 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
259 route_1_1_1_1_232_1_1_1.add_vpp_config()
263 # one accepting interface, pg0, 2 forwarding interfaces
264 # that use unicast next-hops
266 route_1_1_1_1_232_1_1_2 = VppIpMRoute(
270 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
271 [VppMRoutePath(self.pg0.sw_if_index,
272 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
273 VppMRoutePath(self.pg1.sw_if_index,
274 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
275 nh=self.pg1.remote_ip4),
276 VppMRoutePath(self.pg2.sw_if_index,
277 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
278 nh=self.pg2.remote_ip4)])
279 route_1_1_1_1_232_1_1_2.add_vpp_config()
283 # one accepting interface, pg0, 1 forwarding interfaces
285 route_232 = VppIpMRoute(
289 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
290 [VppMRoutePath(self.pg0.sw_if_index,
291 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
292 VppMRoutePath(self.pg1.sw_if_index,
293 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
294 route_232.add_vpp_config()
297 # a stream that matches the route for (1.1.1.1,232.1.1.1)
300 self.vapi.cli("clear trace")
301 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
302 self.pg0.add_stream(tx)
304 self.pg_enable_capture(self.pg_interfaces)
307 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
310 # We expect replications on Pg1->7
311 self.verify_capture_ip4(self.pg1, tx)
312 self.verify_capture_ip4(self.pg2, tx)
314 # no replications on Pg0
315 self.pg0.assert_nothing_captured(
316 remark="IP multicast packets forwarded on PG0")
317 self.pg3.assert_nothing_captured(
318 remark="IP multicast packets forwarded on PG3")
321 # a stream that matches the route for (1.1.1.1,232.1.1.1)
324 self.vapi.cli("clear trace")
325 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1",
327 self.pg0.add_stream(tx)
329 self.pg_enable_capture(self.pg_interfaces)
332 # We expect replications on Pg1->7
333 self.verify_capture_ip4(self.pg1, tx)
334 self.verify_capture_ip4(self.pg2, tx)
336 self.assertEqual(route_1_1_1_1_232_1_1_1.get_stats()['packets'],
339 # no replications on Pg0
340 self.pg0.assert_nothing_captured(
341 remark="IP multicast packets forwarded on PG0")
342 self.pg3.assert_nothing_captured(
343 remark="IP multicast packets forwarded on PG3")
346 # a stream to the unicast next-hops
348 self.vapi.cli("clear trace")
349 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.2")
350 self.pg0.add_stream(tx)
352 self.pg_enable_capture(self.pg_interfaces)
355 # We expect replications on Pg1->7
356 self.verify_capture_ip4(self.pg1, tx, dst_mac=self.pg1.remote_mac)
357 self.verify_capture_ip4(self.pg2, tx, dst_mac=self.pg2.remote_mac)
359 # no replications on Pg0 nor pg3
360 self.pg0.assert_nothing_captured(
361 remark="IP multicast packets forwarded on PG0")
362 self.pg3.assert_nothing_captured(
363 remark="IP multicast packets forwarded on PG3")
366 # a stream that matches the route for (*,232.0.0.0/8)
367 # Send packets with the 9th bit set so we test the correct clearing
368 # of that bit in the mac rewrite
370 self.vapi.cli("clear trace")
371 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.255.255.255")
372 self.pg0.add_stream(tx)
374 self.pg_enable_capture(self.pg_interfaces)
377 # We expect replications on Pg1 only
378 self.verify_capture_ip4(self.pg1, tx)
379 self.assertEqual(route_232.get_stats()['packets'], len(tx))
381 # no replications on Pg0, Pg2 not Pg3
382 self.pg0.assert_nothing_captured(
383 remark="IP multicast packets forwarded on PG0")
384 self.pg2.assert_nothing_captured(
385 remark="IP multicast packets forwarded on PG2")
386 self.pg3.assert_nothing_captured(
387 remark="IP multicast packets forwarded on PG3")
390 # a stream that matches the route for (*,232.1.1.1)
392 self.vapi.cli("clear trace")
393 tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "232.1.1.1")
394 self.pg0.add_stream(tx)
396 self.pg_enable_capture(self.pg_interfaces)
399 # We expect replications on Pg1->7
400 self.verify_capture_ip4(self.pg1, tx)
401 self.verify_capture_ip4(self.pg2, tx)
402 self.verify_capture_ip4(self.pg3, tx)
403 self.verify_capture_ip4(self.pg4, tx)
404 self.verify_capture_ip4(self.pg5, tx)
405 self.verify_capture_ip4(self.pg6, tx)
406 self.verify_capture_ip4(self.pg7, tx)
408 # no replications on Pg0
409 self.pg0.assert_nothing_captured(
410 remark="IP multicast packets forwarded on PG0")
412 self.vapi.cli("packet mac-filter pg0 off")
413 self.vapi.cli("packet mac-filter pg1 off")
414 self.vapi.cli("packet mac-filter pg2 off")
415 self.vapi.cli("packet mac-filter pg4 off")
416 self.vapi.cli("packet mac-filter pg5 off")
417 self.vapi.cli("packet mac-filter pg6 off")
418 self.vapi.cli("packet mac-filter pg7 off")
420 def test_ip6_mcast(self):
421 """ IPv6 Multicast Replication """
423 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
424 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
426 self.vapi.cli("packet mac-filter pg0 on")
427 self.vapi.cli("packet mac-filter pg1 on")
428 self.vapi.cli("packet mac-filter pg2 on")
429 self.vapi.cli("packet mac-filter pg4 on")
430 self.vapi.cli("packet mac-filter pg5 on")
431 self.vapi.cli("packet mac-filter pg6 on")
432 self.vapi.cli("packet mac-filter pg7 on")
434 # a stream that matches the default route. gets dropped.
436 self.vapi.cli("clear trace")
437 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
438 self.pg0.add_stream(tx)
440 self.pg_enable_capture(self.pg_interfaces)
443 self.pg0.assert_nothing_captured(
444 remark="IPv6 multicast packets forwarded on default route")
448 # one accepting interface, pg0, 3 forwarding interfaces
450 route_ff01_1 = VppIpMRoute(
454 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
455 [VppMRoutePath(self.pg0.sw_if_index,
456 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
457 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
458 VppMRoutePath(self.pg1.sw_if_index,
459 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
460 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
461 VppMRoutePath(self.pg2.sw_if_index,
462 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
463 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
464 VppMRoutePath(self.pg3.sw_if_index,
465 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
466 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
467 route_ff01_1.add_vpp_config()
471 # one accepting interface, pg0, 2 forwarding interfaces
473 route_2001_ff01_1 = VppIpMRoute(
476 "ff01::1", 0, # any grp-len is ok when src is set
477 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
478 [VppMRoutePath(self.pg0.sw_if_index,
479 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
480 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
481 VppMRoutePath(self.pg1.sw_if_index,
482 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
483 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
484 VppMRoutePath(self.pg2.sw_if_index,
485 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
486 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
487 route_2001_ff01_1.add_vpp_config()
491 # one accepting interface, pg0, 1 forwarding interface
493 route_ff01 = VppIpMRoute(
497 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
498 [VppMRoutePath(self.pg0.sw_if_index,
499 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
500 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
501 VppMRoutePath(self.pg1.sw_if_index,
502 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
503 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)])
504 route_ff01.add_vpp_config()
507 # a stream that matches the route for (*, ff01::/16)
508 # sent on the non-accepting interface
510 self.vapi.cli("clear trace")
511 tx = self.create_stream_ip6(self.pg1, "2002::1", "ff01:2::255")
512 self.send_and_assert_no_replies(self.pg1, tx, "RPF miss")
515 # a stream that matches the route for (*, ff01::/16)
516 # sent on the accepting interface
518 self.vapi.cli("clear trace")
519 tx = self.create_stream_ip6(self.pg0, "2002::1", "ff01:2::255")
520 self.pg0.add_stream(tx)
522 self.pg_enable_capture(self.pg_interfaces)
525 # We expect replications on Pg1
526 self.verify_capture_ip6(self.pg1, tx)
528 # no replications on Pg0, Pg3
529 self.pg0.assert_nothing_captured(
530 remark="IP multicast packets forwarded on PG0")
531 self.pg2.assert_nothing_captured(
532 remark="IP multicast packets forwarded on PG2")
533 self.pg3.assert_nothing_captured(
534 remark="IP multicast packets forwarded on PG3")
537 # Bounce the interface and it should still work
539 self.pg1.admin_down()
540 self.pg0.add_stream(tx)
541 self.pg_enable_capture(self.pg_interfaces)
543 self.pg1.assert_nothing_captured(
544 remark="IP multicast packets forwarded on down PG1")
547 self.pg0.add_stream(tx)
548 self.pg_enable_capture(self.pg_interfaces)
550 self.verify_capture_ip6(self.pg1, tx)
553 # a stream that matches the route for (*,ff01::1)
555 self.vapi.cli("clear trace")
556 tx = self.create_stream_ip6(self.pg0, "2002::2", "ff01::1")
557 self.pg0.add_stream(tx)
559 self.pg_enable_capture(self.pg_interfaces)
562 # We expect replications on Pg1, 2, 3.
563 self.verify_capture_ip6(self.pg1, tx)
564 self.verify_capture_ip6(self.pg2, tx)
565 self.verify_capture_ip6(self.pg3, tx)
567 # no replications on Pg0
568 self.pg0.assert_nothing_captured(
569 remark="IPv6 multicast packets forwarded on PG0")
572 # a stream that matches the route for (2001::1, ff00::1)
574 self.vapi.cli("clear trace")
575 tx = self.create_stream_ip6(self.pg0, "2001::1", "ff01::1")
576 self.pg0.add_stream(tx)
578 self.pg_enable_capture(self.pg_interfaces)
581 # We expect replications on Pg1, 2,
582 self.verify_capture_ip6(self.pg1, tx)
583 self.verify_capture_ip6(self.pg2, tx)
585 # no replications on Pg0, Pg3
586 self.pg0.assert_nothing_captured(
587 remark="IP multicast packets forwarded on PG0")
588 self.pg3.assert_nothing_captured(
589 remark="IP multicast packets forwarded on PG3")
591 self.vapi.cli("packet mac-filter pg0 off")
592 self.vapi.cli("packet mac-filter pg1 off")
593 self.vapi.cli("packet mac-filter pg2 off")
594 self.vapi.cli("packet mac-filter pg4 off")
595 self.vapi.cli("packet mac-filter pg5 off")
596 self.vapi.cli("packet mac-filter pg6 off")
597 self.vapi.cli("packet mac-filter pg7 off")
599 def _mcast_connected_send_stream(self, dst_ip):
600 self.vapi.cli("clear trace")
601 tx = self.create_stream_ip4(self.pg0,
604 self.pg0.add_stream(tx)
606 self.pg_enable_capture(self.pg_interfaces)
609 # We expect replications on Pg1.
610 self.verify_capture_ip4(self.pg1, tx)
614 def test_ip_mcast_connected(self):
615 """ IP Multicast Connected Source check """
617 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
618 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
622 # one accepting interface, pg0, 1 forwarding interfaces
624 route_232_1_1_1 = VppIpMRoute(
628 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
629 [VppMRoutePath(self.pg0.sw_if_index,
630 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
631 VppMRoutePath(self.pg1.sw_if_index,
632 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
634 route_232_1_1_1.add_vpp_config()
635 route_232_1_1_1.update_entry_flags(
636 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_CONNECTED)
639 # Now the (*,G) is present, send from connected source
641 tx = self._mcast_connected_send_stream("232.1.1.1")
644 # Constrct a representation of the signal we expect on pg0
646 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
648 self.pg0.sw_if_index,
652 # read the only expected signal
654 signals = self.vapi.mfib_signal_dump()
656 self.assertEqual(1, len(signals))
658 signal_232_1_1_1_itf_0.compare(signals[0])
661 # reading the signal allows for the generation of another
662 # so send more packets and expect the next signal
664 tx = self._mcast_connected_send_stream("232.1.1.1")
666 signals = self.vapi.mfib_signal_dump()
667 self.assertEqual(1, len(signals))
668 signal_232_1_1_1_itf_0.compare(signals[0])
671 # A Second entry with connected check
672 # one accepting interface, pg0, 1 forwarding interfaces
674 route_232_1_1_2 = VppIpMRoute(
678 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
679 [VppMRoutePath(self.pg0.sw_if_index,
680 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
681 VppMRoutePath(self.pg1.sw_if_index,
682 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
684 route_232_1_1_2.add_vpp_config()
685 route_232_1_1_2.update_entry_flags(
686 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_CONNECTED)
689 # Send traffic to both entries. One read should net us two signals
691 signal_232_1_1_2_itf_0 = VppMFibSignal(self,
693 self.pg0.sw_if_index,
695 tx = self._mcast_connected_send_stream("232.1.1.1")
696 tx2 = self._mcast_connected_send_stream("232.1.1.2")
699 # read the only expected signal
701 signals = self.vapi.mfib_signal_dump()
703 self.assertEqual(2, len(signals))
705 signal_232_1_1_1_itf_0.compare(signals[1])
706 signal_232_1_1_2_itf_0.compare(signals[0])
708 route_232_1_1_1.update_entry_flags(
709 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE)
710 route_232_1_1_2.update_entry_flags(
711 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE)
713 def test_ip_mcast_signal(self):
714 """ IP Multicast Signal """
716 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
717 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
721 # one accepting interface, pg0, 1 forwarding interfaces
723 route_232_1_1_1 = VppIpMRoute(
727 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
728 [VppMRoutePath(self.pg0.sw_if_index,
729 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
730 VppMRoutePath(self.pg1.sw_if_index,
731 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
733 route_232_1_1_1.add_vpp_config()
735 route_232_1_1_1.update_entry_flags(
736 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_SIGNAL)
739 # Now the (*,G) is present, send from connected source
741 tx = self._mcast_connected_send_stream("232.1.1.1")
744 # Constrct a representation of the signal we expect on pg0
746 signal_232_1_1_1_itf_0 = VppMFibSignal(self,
748 self.pg0.sw_if_index,
752 # read the only expected signal
754 signals = self.vapi.mfib_signal_dump()
756 self.assertEqual(1, len(signals))
758 signal_232_1_1_1_itf_0.compare(signals[0])
761 # reading the signal allows for the generation of another
762 # so send more packets and expect the next signal
764 tx = self._mcast_connected_send_stream("232.1.1.1")
766 signals = self.vapi.mfib_signal_dump()
767 self.assertEqual(1, len(signals))
768 signal_232_1_1_1_itf_0.compare(signals[0])
771 # Set the negate-signal on the accepting interval - the signals
774 route_232_1_1_1.update_path_flags(
775 self.pg0.sw_if_index,
776 (MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
777 MRouteItfFlags.MFIB_API_ITF_FLAG_NEGATE_SIGNAL))
779 self.vapi.cli("clear trace")
780 tx = self._mcast_connected_send_stream("232.1.1.1")
782 signals = self.vapi.mfib_signal_dump()
783 self.assertEqual(0, len(signals))
786 # Clear the SIGNAL flag on the entry and the signals should
787 # come back since the interface is still NEGATE-SIGNAL
789 route_232_1_1_1.update_entry_flags(
790 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE)
792 tx = self._mcast_connected_send_stream("232.1.1.1")
794 signals = self.vapi.mfib_signal_dump()
795 self.assertEqual(1, len(signals))
796 signal_232_1_1_1_itf_0.compare(signals[0])
799 # Lastly remove the NEGATE-SIGNAL from the interface and the
800 # signals should stop
802 route_232_1_1_1.update_path_flags(
803 self.pg0.sw_if_index,
804 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT)
806 tx = self._mcast_connected_send_stream("232.1.1.1")
807 signals = self.vapi.mfib_signal_dump()
808 self.assertEqual(0, len(signals))
810 def test_ip_mcast_vrf(self):
811 """ IP Multicast Replication in non-default table"""
813 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
814 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
818 # one accepting interface, pg0, 2 forwarding interfaces
820 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
824 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
825 [VppMRoutePath(self.pg8.sw_if_index,
826 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
827 VppMRoutePath(self.pg1.sw_if_index,
828 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
829 VppMRoutePath(self.pg2.sw_if_index,
830 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)],
832 route_1_1_1_1_232_1_1_1.add_vpp_config()
835 # a stream that matches the route for (1.1.1.1,232.1.1.1)
838 self.vapi.cli("clear trace")
839 tx = self.create_stream_ip4(self.pg8, "1.1.1.1", "232.1.1.1")
840 self.pg8.add_stream(tx)
842 self.pg_enable_capture(self.pg_interfaces)
845 # We expect replications on Pg1 & 2
846 self.verify_capture_ip4(self.pg1, tx)
847 self.verify_capture_ip4(self.pg2, tx)
850 # An (S,G). for for-us
852 route_0_0_0_0_224_0_0_5 = VppIpMRoute(
856 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
857 [VppMRoutePath(self.pg8.sw_if_index,
858 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
859 VppMRoutePath(0xffffffff,
860 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
861 type=FibPathType.FIB_PATH_TYPE_LOCAL)],
863 route_0_0_0_0_224_0_0_5.add_vpp_config()
866 # a stream that matches the route for (0.0.0.0, 224.0.0.5)
869 self.vapi.cli("clear trace")
870 self.pg8.resolve_arp()
873 # send a ping to mcast address from peer on pg8
878 icmp_load = b'\x0a' * 18
879 tx = (Ether(dst=getmacbyip("224.0.0.5"), src=self.pg8.remote_mac) /
880 IP(src=self.pg8.remote_ip4, dst="224.0.0.5") /
881 ICMP(id=icmp_id, seq=icmp_seq) /
882 Raw(load=icmp_load)) * 2
884 self.send_and_expect(self.pg8, tx, self.pg8)
886 def test_ip_mcast_gre(self):
887 """ IP Multicast Replication over GRE"""
889 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
890 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
892 gre_if_1 = VppGreInterface(
895 self.pg1.remote_ip4).add_vpp_config()
896 gre_if_2 = VppGreInterface(
899 self.pg2.remote_ip4).add_vpp_config()
900 gre_if_3 = VppGreInterface(
903 self.pg3.remote_ip4).add_vpp_config()
906 gre_if_1.config_ip4()
908 gre_if_2.config_ip4()
910 gre_if_3.config_ip4()
914 # one accepting interface, pg0, 2 forwarding interfaces
916 route_1_1_1_1_232_1_1_1 = VppIpMRoute(
920 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
921 [VppMRoutePath(gre_if_1.sw_if_index,
922 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
923 VppMRoutePath(gre_if_2.sw_if_index,
924 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
925 VppMRoutePath(gre_if_3.sw_if_index,
926 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
927 route_1_1_1_1_232_1_1_1.add_vpp_config()
930 # a stream that matches the route for (1.1.1.1,232.2.2.2)
933 tx = (Ether(dst=self.pg1.local_mac,
934 src=self.pg1.remote_mac) /
935 IP(src=self.pg1.remote_ip4,
936 dst=self.pg1.local_ip4) /
938 IP(src="1.1.1.1", dst="232.2.2.2") /
939 UDP(sport=1234, dport=1234) /
940 Raw(b'\a5' * 64)) * 63
942 self.vapi.cli("clear trace")
943 self.pg1.add_stream(tx)
945 self.pg_enable_capture(self.pg_interfaces)
948 # We expect replications on Pg2 & 3
949 # check the encap headers are as expected based on the egress tunnel
950 rxs = self.pg2.get_capture(len(tx))
952 self.assertEqual(rx[IP].src, gre_if_2.t_src)
953 self.assertEqual(rx[IP].dst, gre_if_2.t_dst)
954 self.assert_packet_checksums_valid(rx)
956 rxs = self.pg3.get_capture(len(tx))
958 self.assertEqual(rx[IP].src, gre_if_3.t_src)
959 self.assertEqual(rx[IP].dst, gre_if_3.t_dst)
960 self.assert_packet_checksums_valid(rx)
962 def test_ip6_mcast_gre(self):
963 """ IP6 Multicast Replication over GRE"""
965 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
966 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
968 gre_if_1 = VppGreInterface(
971 self.pg1.remote_ip4).add_vpp_config()
972 gre_if_2 = VppGreInterface(
975 self.pg2.remote_ip4).add_vpp_config()
976 gre_if_3 = VppGreInterface(
979 self.pg3.remote_ip4).add_vpp_config()
982 gre_if_1.config_ip6()
984 gre_if_2.config_ip6()
986 gre_if_3.config_ip6()
990 # one accepting interface, pg0, 2 forwarding interfaces
992 route_1_1_FF_1 = VppIpMRoute(
996 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
997 [VppMRoutePath(gre_if_1.sw_if_index,
998 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT),
999 VppMRoutePath(gre_if_2.sw_if_index,
1000 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
1001 VppMRoutePath(gre_if_3.sw_if_index,
1002 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
1003 route_1_1_FF_1.add_vpp_config()
1006 # a stream that matches the route for (1::1, FF::1)
1009 tx = (Ether(dst=self.pg1.local_mac,
1010 src=self.pg1.remote_mac) /
1011 IP(src=self.pg1.remote_ip4,
1012 dst=self.pg1.local_ip4) /
1014 IPv6(src="1::1", dst="FF00::1") /
1015 UDP(sport=1234, dport=1234) /
1016 Raw(b'\a5' * 64)) * 63
1018 self.vapi.cli("clear trace")
1019 self.pg1.add_stream(tx)
1021 self.pg_enable_capture(self.pg_interfaces)
1024 # We expect replications on Pg2 & 3
1025 # check the encap headers are as expected based on the egress tunnel
1026 rxs = self.pg2.get_capture(len(tx))
1028 self.assertEqual(rx[IP].src, gre_if_2.t_src)
1029 self.assertEqual(rx[IP].dst, gre_if_2.t_dst)
1030 self.assert_packet_checksums_valid(rx)
1032 rxs = self.pg3.get_capture(len(tx))
1034 self.assertEqual(rx[IP].src, gre_if_3.t_src)
1035 self.assertEqual(rx[IP].dst, gre_if_3.t_dst)
1036 self.assert_packet_checksums_valid(rx)
1038 def test_ip6_mcast_vrf(self):
1039 """ IPv6 Multicast Replication in non-default table"""
1041 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
1042 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
1046 # one accepting interface, pg0, 2 forwarding interfaces
1048 route_2001_ff01_1 = VppIpMRoute(
1052 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
1053 [VppMRoutePath(self.pg8.sw_if_index,
1054 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT,
1055 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
1056 VppMRoutePath(self.pg1.sw_if_index,
1057 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
1058 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6),
1059 VppMRoutePath(self.pg2.sw_if_index,
1060 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD,
1061 proto=FibPathProto.FIB_PATH_NH_PROTO_IP6)],
1063 route_2001_ff01_1.add_vpp_config()
1066 # a stream that matches the route for (2001::1, ff00::1)
1068 self.vapi.cli("clear trace")
1069 tx = self.create_stream_ip6(self.pg8, "2001::1", "ff01::1")
1070 self.pg8.add_stream(tx)
1072 self.pg_enable_capture(self.pg_interfaces)
1075 # We expect replications on Pg1, 2,
1076 self.verify_capture_ip6(self.pg1, tx)
1077 self.verify_capture_ip6(self.pg2, tx)
1079 def test_bidir(self):
1080 """ IP Multicast Bi-directional """
1082 MRouteItfFlags = VppEnum.vl_api_mfib_itf_flags_t
1083 MRouteEntryFlags = VppEnum.vl_api_mfib_entry_flags_t
1086 # A (*,G). The set of accepting interfaces matching the forwarding
1088 route_232_1_1_1 = VppIpMRoute(
1092 MRouteEntryFlags.MFIB_API_ENTRY_FLAG_NONE,
1093 [VppMRoutePath(self.pg0.sw_if_index,
1094 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1095 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
1096 VppMRoutePath(self.pg1.sw_if_index,
1097 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1098 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
1099 VppMRoutePath(self.pg2.sw_if_index,
1100 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1101 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD),
1102 VppMRoutePath(self.pg3.sw_if_index,
1103 MRouteItfFlags.MFIB_API_ITF_FLAG_ACCEPT |
1104 MRouteItfFlags.MFIB_API_ITF_FLAG_FORWARD)])
1105 route_232_1_1_1.add_vpp_config()
1107 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "232.1.1.1")
1108 self.pg0.add_stream(tx)
1110 self.pg_enable_capture(self.pg_interfaces)
1113 # We expect replications on Pg1, 2, 3, but not on pg0
1114 self.verify_capture_ip4(self.pg1, tx)
1115 self.verify_capture_ip4(self.pg2, tx)
1116 self.verify_capture_ip4(self.pg3, tx)
1117 self.pg0.assert_nothing_captured(
1118 remark="IP multicast packets forwarded on PG0")
1121 if __name__ == '__main__':
1122 unittest.main(testRunner=VppTestRunner)