6 from scapy.packet import Raw
7 from scapy.layers.l2 import Ether, Dot1Q, GRE
8 from scapy.layers.inet import IP, UDP
9 from scapy.layers.inet6 import IPv6
10 from scapy.volatile import RandMAC, RandIP
12 from framework import tag_fixme_vpp_workers
13 from framework import VppTestCase, VppTestRunner
14 from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint
15 from vpp_gre_interface import VppGreInterface
16 from vpp_teib import VppTeib
17 from vpp_ip import DpoProto
18 from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, FibPathProto, \
20 from vpp_mpls_tunnel_interface import VppMPLSTunnelInterface
21 from util import ppp, ppc
22 from vpp_papi import VppEnum
25 @tag_fixme_vpp_workers
26 class TestGREInputNodes(VppTestCase):
27 """ GRE Input Nodes Test Case """
30 super(TestGREInputNodes, self).setUp()
32 # create 3 pg interfaces - set one in a non-default table.
33 self.create_pg_interfaces(range(1))
35 for i in self.pg_interfaces:
40 for i in self.pg_interfaces:
43 super(TestGREInputNodes, self).tearDown()
45 def test_gre_input_node(self):
46 """ GRE gre input nodes not registerd unless configured """
47 pkt = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
48 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
51 self.pg0.add_stream(pkt)
53 # no tunnel created, gre-input not registered
54 err = self.statistics.get_counter(
55 '/err/ip4-local/unknown ip protocol')[0]
56 self.assertEqual(err, 1)
60 gre_if = VppGreInterface(self, self.pg0.local_ip4, "1.1.1.2")
61 gre_if.add_vpp_config()
63 self.pg0.add_stream(pkt)
65 # tunnel created, gre-input registered
66 err = self.statistics.get_counter(
67 '/err/ip4-local/unknown ip protocol')[0]
68 # expect no new errors
69 self.assertEqual(err, err_count)
72 class TestGRE(VppTestCase):
77 super(TestGRE, cls).setUpClass()
80 def tearDownClass(cls):
81 super(TestGRE, cls).tearDownClass()
84 super(TestGRE, self).setUp()
86 # create 3 pg interfaces - set one in a non-default table.
87 self.create_pg_interfaces(range(5))
89 self.tbl = VppIpTable(self, 1)
90 self.tbl.add_vpp_config()
91 self.pg1.set_table_ip4(1)
93 for i in self.pg_interfaces:
97 self.pg0.resolve_arp()
99 self.pg1.resolve_arp()
100 self.pg2.config_ip6()
101 self.pg2.resolve_ndp()
102 self.pg3.config_ip4()
103 self.pg3.resolve_arp()
104 self.pg4.config_ip4()
105 self.pg4.resolve_arp()
108 for i in self.pg_interfaces:
112 self.pg1.set_table_ip4(0)
113 super(TestGRE, self).tearDown()
115 def create_stream_ip4(self, src_if, src_ip, dst_ip, dscp=0, ecn=0):
117 tos = (dscp << 2) | ecn
118 for i in range(0, 257):
119 info = self.create_packet_info(src_if, src_if)
120 payload = self.info_to_payload(info)
121 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
122 IP(src=src_ip, dst=dst_ip, tos=tos) /
123 UDP(sport=1234, dport=1234) /
129 def create_stream_ip6(self, src_if, src_ip, dst_ip, dscp=0, ecn=0):
131 tc = (dscp << 2) | ecn
132 for i in range(0, 257):
133 info = self.create_packet_info(src_if, src_if)
134 payload = self.info_to_payload(info)
135 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
136 IPv6(src=src_ip, dst=dst_ip, tc=tc) /
137 UDP(sport=1234, dport=1234) /
143 def create_tunnel_stream_4o4(self, src_if,
144 tunnel_src, tunnel_dst,
147 for i in range(0, 257):
148 info = self.create_packet_info(src_if, src_if)
149 payload = self.info_to_payload(info)
150 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
151 IP(src=tunnel_src, dst=tunnel_dst) /
153 IP(src=src_ip, dst=dst_ip) /
154 UDP(sport=1234, dport=1234) /
160 def create_tunnel_stream_6o4(self, src_if,
161 tunnel_src, tunnel_dst,
164 for i in range(0, 257):
165 info = self.create_packet_info(src_if, src_if)
166 payload = self.info_to_payload(info)
167 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
168 IP(src=tunnel_src, dst=tunnel_dst) /
170 IPv6(src=src_ip, dst=dst_ip) /
171 UDP(sport=1234, dport=1234) /
177 def create_tunnel_stream_6o6(self, src_if,
178 tunnel_src, tunnel_dst,
181 for i in range(0, 257):
182 info = self.create_packet_info(src_if, src_if)
183 payload = self.info_to_payload(info)
184 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
185 IPv6(src=tunnel_src, dst=tunnel_dst) /
187 IPv6(src=src_ip, dst=dst_ip) /
188 UDP(sport=1234, dport=1234) /
194 def create_tunnel_stream_l2o4(self, src_if,
195 tunnel_src, tunnel_dst):
197 for i in range(0, 257):
198 info = self.create_packet_info(src_if, src_if)
199 payload = self.info_to_payload(info)
200 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
201 IP(src=tunnel_src, dst=tunnel_dst) /
203 Ether(dst=RandMAC('*:*:*:*:*:*'),
204 src=RandMAC('*:*:*:*:*:*')) /
205 IP(src=scapy.compat.raw(RandIP()),
206 dst=scapy.compat.raw(RandIP())) /
207 UDP(sport=1234, dport=1234) /
213 def create_tunnel_stream_vlano4(self, src_if,
214 tunnel_src, tunnel_dst, vlan):
216 for i in range(0, 257):
217 info = self.create_packet_info(src_if, src_if)
218 payload = self.info_to_payload(info)
219 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
220 IP(src=tunnel_src, dst=tunnel_dst) /
222 Ether(dst=RandMAC('*:*:*:*:*:*'),
223 src=RandMAC('*:*:*:*:*:*')) /
225 IP(src=scapy.compat.raw(RandIP()),
226 dst=scapy.compat.raw(RandIP())) /
227 UDP(sport=1234, dport=1234) /
233 def verify_tunneled_4o4(self, src_if, capture, sent,
234 tunnel_src, tunnel_dst,
237 self.assertEqual(len(capture), len(sent))
238 tos = (dscp << 2) | ecn
240 for i in range(len(capture)):
248 self.assertEqual(rx_ip.src, tunnel_src)
249 self.assertEqual(rx_ip.dst, tunnel_dst)
250 self.assertEqual(rx_ip.tos, tos)
251 self.assertEqual(rx_ip.len, len(rx_ip))
256 self.assertEqual(rx_ip.src, tx_ip.src)
257 self.assertEqual(rx_ip.dst, tx_ip.dst)
258 # IP processing post pop has decremented the TTL
259 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
262 self.logger.error(ppp("Rx:", rx))
263 self.logger.error(ppp("Tx:", tx))
266 def verify_tunneled_6o6(self, src_if, capture, sent,
267 tunnel_src, tunnel_dst,
270 self.assertEqual(len(capture), len(sent))
271 tc = (dscp << 2) | ecn
273 for i in range(len(capture)):
281 self.assertEqual(rx_ip.src, tunnel_src)
282 self.assertEqual(rx_ip.dst, tunnel_dst)
283 self.assertEqual(rx_ip.tc, tc)
285 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
287 self.assertEqual(rx_ip.plen, len(rx_gre))
291 self.assertEqual(rx_ip.src, tx_ip.src)
292 self.assertEqual(rx_ip.dst, tx_ip.dst)
295 self.logger.error(ppp("Rx:", rx))
296 self.logger.error(ppp("Tx:", tx))
299 def verify_tunneled_4o6(self, src_if, capture, sent,
300 tunnel_src, tunnel_dst):
302 self.assertEqual(len(capture), len(sent))
304 for i in range(len(capture)):
311 self.assertEqual(rx_ip.src, tunnel_src)
312 self.assertEqual(rx_ip.dst, tunnel_dst)
314 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
316 self.assertEqual(rx_ip.plen, len(rx_gre))
321 self.assertEqual(rx_ip.src, tx_ip.src)
322 self.assertEqual(rx_ip.dst, tx_ip.dst)
325 self.logger.error(ppp("Rx:", rx))
326 self.logger.error(ppp("Tx:", tx))
329 def verify_tunneled_6o4(self, src_if, capture, sent,
330 tunnel_src, tunnel_dst):
332 self.assertEqual(len(capture), len(sent))
334 for i in range(len(capture)):
341 self.assertEqual(rx_ip.src, tunnel_src)
342 self.assertEqual(rx_ip.dst, tunnel_dst)
343 self.assertEqual(rx_ip.len, len(rx_ip))
345 rx_gre = GRE(scapy.compat.raw(rx_ip[IP].payload))
349 self.assertEqual(rx_ip.src, tx_ip.src)
350 self.assertEqual(rx_ip.dst, tx_ip.dst)
353 self.logger.error(ppp("Rx:", rx))
354 self.logger.error(ppp("Tx:", tx))
357 def verify_tunneled_l2o4(self, src_if, capture, sent,
358 tunnel_src, tunnel_dst):
359 self.assertEqual(len(capture), len(sent))
361 for i in range(len(capture)):
369 self.assertEqual(rx_ip.src, tunnel_src)
370 self.assertEqual(rx_ip.dst, tunnel_dst)
371 self.assertEqual(rx_ip.len, len(rx_ip))
374 rx_l2 = rx_gre[Ether]
377 tx_l2 = tx_gre[Ether]
380 self.assertEqual(rx_ip.src, tx_ip.src)
381 self.assertEqual(rx_ip.dst, tx_ip.dst)
382 # bridged, not L3 forwarded, so no TTL decrement
383 self.assertEqual(rx_ip.ttl, tx_ip.ttl)
386 self.logger.error(ppp("Rx:", rx))
387 self.logger.error(ppp("Tx:", tx))
390 def verify_tunneled_vlano4(self, src_if, capture, sent,
391 tunnel_src, tunnel_dst, vlan):
393 self.assertEqual(len(capture), len(sent))
395 ppc("Unexpected packets captured:", capture)
398 for i in range(len(capture)):
406 self.assertEqual(rx_ip.src, tunnel_src)
407 self.assertEqual(rx_ip.dst, tunnel_dst)
410 rx_l2 = rx_gre[Ether]
411 rx_vlan = rx_l2[Dot1Q]
414 self.assertEqual(rx_vlan.vlan, vlan)
417 tx_l2 = tx_gre[Ether]
420 self.assertEqual(rx_ip.src, tx_ip.src)
421 self.assertEqual(rx_ip.dst, tx_ip.dst)
422 # bridged, not L3 forwarded, so no TTL decrement
423 self.assertEqual(rx_ip.ttl, tx_ip.ttl)
426 self.logger.error(ppp("Rx:", rx))
427 self.logger.error(ppp("Tx:", tx))
430 def verify_decapped_4o4(self, src_if, capture, sent):
431 self.assertEqual(len(capture), len(sent))
433 for i in range(len(capture)):
443 self.assertEqual(rx_ip.src, tx_ip.src)
444 self.assertEqual(rx_ip.dst, tx_ip.dst)
445 # IP processing post pop has decremented the TTL
446 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
449 self.logger.error(ppp("Rx:", rx))
450 self.logger.error(ppp("Tx:", tx))
453 def verify_decapped_6o4(self, src_if, capture, sent):
454 self.assertEqual(len(capture), len(sent))
456 for i in range(len(capture)):
466 self.assertEqual(rx_ip.src, tx_ip.src)
467 self.assertEqual(rx_ip.dst, tx_ip.dst)
468 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
471 self.logger.error(ppp("Rx:", rx))
472 self.logger.error(ppp("Tx:", tx))
475 def verify_decapped_6o6(self, src_if, capture, sent):
476 self.assertEqual(len(capture), len(sent))
478 for i in range(len(capture)):
488 self.assertEqual(rx_ip.src, tx_ip.src)
489 self.assertEqual(rx_ip.dst, tx_ip.dst)
490 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
493 self.logger.error(ppp("Rx:", rx))
494 self.logger.error(ppp("Tx:", tx))
498 """ GRE IPv4 tunnel Tests """
501 # Create an L3 GRE tunnel.
503 # - assign an IP Addres
504 # - Add a route via the tunnel
506 gre_if = VppGreInterface(self,
509 gre_if.add_vpp_config()
512 # The double create (create the same tunnel twice) should fail,
513 # and we should still be able to use the original
516 gre_if.add_vpp_config()
520 self.fail("Double GRE tunnel add does not fail")
525 route_via_tun = VppIpRoute(self, "4.4.4.4", 32,
526 [VppRoutePath("0.0.0.0",
527 gre_if.sw_if_index)])
529 route_via_tun.add_vpp_config()
532 # Send a packet stream that is routed into the tunnel
533 # - they are all dropped since the tunnel's destintation IP
534 # is unresolved - or resolves via the default route - which
537 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "4.4.4.4")
539 self.send_and_assert_no_replies(self.pg0, tx)
542 # Add a route that resolves the tunnel's destination
544 route_tun_dst = VppIpRoute(self, "1.1.1.2", 32,
545 [VppRoutePath(self.pg0.remote_ip4,
546 self.pg0.sw_if_index)])
547 route_tun_dst.add_vpp_config()
550 # Send a packet stream that is routed into the tunnel
551 # - packets are GRE encapped
553 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "4.4.4.4")
554 rx = self.send_and_expect(self.pg0, tx, self.pg0)
555 self.verify_tunneled_4o4(self.pg0, rx, tx,
556 self.pg0.local_ip4, "1.1.1.2")
559 # Send tunneled packets that match the created tunnel and
560 # are decapped and forwarded
562 tx = self.create_tunnel_stream_4o4(self.pg0,
567 rx = self.send_and_expect(self.pg0, tx, self.pg0)
568 self.verify_decapped_4o4(self.pg0, rx, tx)
571 # Send tunneled packets that do not match the tunnel's src
573 self.vapi.cli("clear trace")
574 tx = self.create_tunnel_stream_4o4(self.pg0,
579 self.send_and_assert_no_replies(
581 remark="GRE packets forwarded despite no SRC address match")
584 # Configure IPv6 on the PG interface so we can route IPv6
587 self.pg0.config_ip6()
588 self.pg0.resolve_ndp()
591 # Send IPv6 tunnel encapslated packets
592 # - dropped since IPv6 is not enabled on the tunnel
594 tx = self.create_tunnel_stream_6o4(self.pg0,
599 self.send_and_assert_no_replies(self.pg0, tx,
600 "IPv6 GRE packets forwarded "
601 "despite IPv6 not enabled on tunnel")
604 # Enable IPv6 on the tunnel
609 # Send IPv6 tunnel encapslated packets
610 # - forwarded since IPv6 is enabled on the tunnel
612 tx = self.create_tunnel_stream_6o4(self.pg0,
617 rx = self.send_and_expect(self.pg0, tx, self.pg0)
618 self.verify_decapped_6o4(self.pg0, rx, tx)
621 # Send v6 packets for v4 encap
623 route6_via_tun = VppIpRoute(
624 self, "2001::1", 128,
627 proto=DpoProto.DPO_PROTO_IP6)])
628 route6_via_tun.add_vpp_config()
630 tx = self.create_stream_ip6(self.pg0, "2001::2", "2001::1")
631 rx = self.send_and_expect(self.pg0, tx, self.pg0)
633 self.verify_tunneled_6o4(self.pg0, rx, tx,
634 self.pg0.local_ip4, "1.1.1.2")
637 # add a labelled route through the tunnel
639 label_via_tun = VppIpRoute(self, "5.4.3.2", 32,
640 [VppRoutePath("0.0.0.0",
642 labels=[VppMplsLabel(33)])])
643 label_via_tun.add_vpp_config()
645 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "5.4.3.2")
646 rx = self.send_and_expect(self.pg0, tx, self.pg0)
647 self.verify_tunneled_4o4(self.pg0, rx, tx,
648 self.pg0.local_ip4, "1.1.1.2")
651 # an MPLS tunnel over the GRE tunnel add a route through
654 mpls_tun = VppMPLSTunnelInterface(
656 [VppRoutePath("0.0.0.0",
658 labels=[VppMplsLabel(44),
660 mpls_tun.add_vpp_config()
663 label_via_mpls = VppIpRoute(self, "5.4.3.1", 32,
664 [VppRoutePath("0.0.0.0",
665 mpls_tun.sw_if_index,
666 labels=[VppMplsLabel(33)])])
667 label_via_mpls.add_vpp_config()
669 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "5.4.3.1")
670 rx = self.send_and_expect(self.pg0, tx, self.pg0)
671 self.verify_tunneled_4o4(self.pg0, rx, tx,
672 self.pg0.local_ip4, "1.1.1.2")
674 mpls_tun_l2 = VppMPLSTunnelInterface(
676 [VppRoutePath("0.0.0.0",
678 labels=[VppMplsLabel(44),
681 mpls_tun_l2.add_vpp_config()
682 mpls_tun_l2.admin_up()
687 route_tun_dst.remove_vpp_config()
688 route_via_tun.remove_vpp_config()
689 route6_via_tun.remove_vpp_config()
690 label_via_mpls.remove_vpp_config()
691 label_via_tun.remove_vpp_config()
692 mpls_tun.remove_vpp_config()
693 mpls_tun_l2.remove_vpp_config()
694 gre_if.remove_vpp_config()
696 self.pg0.unconfig_ip6()
699 """ GRE IPv6 tunnel Tests """
701 self.pg1.config_ip6()
702 self.pg1.resolve_ndp()
705 # Create an L3 GRE tunnel.
707 # - assign an IP Address
708 # - Add a route via the tunnel
710 gre_if = VppGreInterface(self,
713 gre_if.add_vpp_config()
717 route_via_tun = VppIpRoute(self, "4004::1", 128,
718 [VppRoutePath("0::0",
719 gre_if.sw_if_index)])
721 route_via_tun.add_vpp_config()
724 # Send a packet stream that is routed into the tunnel
725 # - they are all dropped since the tunnel's destintation IP
726 # is unresolved - or resolves via the default route - which
729 tx = self.create_stream_ip6(self.pg2, "5005::1", "4004::1")
730 self.send_and_assert_no_replies(
732 "GRE packets forwarded without DIP resolved")
735 # Add a route that resolves the tunnel's destination
737 route_tun_dst = VppIpRoute(self, "1002::1", 128,
738 [VppRoutePath(self.pg2.remote_ip6,
739 self.pg2.sw_if_index)])
740 route_tun_dst.add_vpp_config()
743 # Send a packet stream that is routed into the tunnel
744 # - packets are GRE encapped
746 tx = self.create_stream_ip6(self.pg2, "5005::1", "4004::1")
747 rx = self.send_and_expect(self.pg2, tx, self.pg2)
748 self.verify_tunneled_6o6(self.pg2, rx, tx,
749 self.pg2.local_ip6, "1002::1")
752 # Test decap. decapped packets go out pg1
754 tx = self.create_tunnel_stream_6o6(self.pg2,
759 rx = self.send_and_expect(self.pg2, tx, self.pg1)
762 # RX'd packet is UDP over IPv6, test the GRE header is gone.
764 self.assertFalse(rx[0].haslayer(GRE))
765 self.assertEqual(rx[0][IPv6].dst, self.pg1.remote_ip6)
770 route4_via_tun = VppIpRoute(self, "1.1.1.1", 32,
771 [VppRoutePath("0.0.0.0",
772 gre_if.sw_if_index)])
773 route4_via_tun.add_vpp_config()
775 tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "1.1.1.1")
776 rx = self.send_and_expect(self.pg0, tx, self.pg2)
778 self.verify_tunneled_4o6(self.pg0, rx, tx,
779 self.pg2.local_ip6, "1002::1")
784 route_tun_dst.remove_vpp_config()
785 route_via_tun.remove_vpp_config()
786 route4_via_tun.remove_vpp_config()
787 gre_if.remove_vpp_config()
789 self.pg2.unconfig_ip6()
790 self.pg1.unconfig_ip6()
792 def test_gre_vrf(self):
793 """ GRE tunnel VRF Tests """
795 e = VppEnum.vl_api_tunnel_encap_decap_flags_t
798 # Create an L3 GRE tunnel whose destination is in the non-default
799 # table. The underlay is thus non-default - the overlay is still
802 # - assign an IP Addres
804 gre_if = VppGreInterface(
805 self, self.pg1.local_ip4,
808 flags=(e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP |
809 e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
811 gre_if.add_vpp_config()
816 # Add a route via the tunnel - in the overlay
818 route_via_tun = VppIpRoute(self, "9.9.9.9", 32,
819 [VppRoutePath("0.0.0.0",
820 gre_if.sw_if_index)])
821 route_via_tun.add_vpp_config()
824 # Add a route that resolves the tunnel's destination - in the
827 route_tun_dst = VppIpRoute(self, "2.2.2.2", 32, table_id=1,
828 paths=[VppRoutePath(self.pg1.remote_ip4,
829 self.pg1.sw_if_index)])
830 route_tun_dst.add_vpp_config()
833 # Send a packet stream that is routed into the tunnel
834 # packets are sent in on pg0 which is in the default table
835 # - packets are GRE encapped
837 self.vapi.cli("clear trace")
838 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "9.9.9.9",
840 rx = self.send_and_expect(self.pg0, tx, self.pg1)
841 self.verify_tunneled_4o4(self.pg1, rx, tx,
842 self.pg1.local_ip4, "2.2.2.2",
846 # Send tunneled packets that match the created tunnel and
847 # are decapped and forwarded. This tests the decap lookup
848 # does not happen in the encap table
850 self.vapi.cli("clear trace")
851 tx = self.create_tunnel_stream_4o4(self.pg1,
856 rx = self.send_and_expect(self.pg1, tx, self.pg0)
857 self.verify_decapped_4o4(self.pg0, rx, tx)
860 # Send tunneled packets that match the created tunnel
861 # but arrive on an interface that is not in the tunnel's
862 # encap VRF, these are dropped.
863 # IP enable the interface so they aren't dropped due to
864 # IP not being enabled.
866 self.pg2.config_ip4()
867 self.vapi.cli("clear trace")
868 tx = self.create_tunnel_stream_4o4(self.pg2,
873 rx = self.send_and_assert_no_replies(
875 "GRE decap packets in wrong VRF")
877 self.pg2.unconfig_ip4()
882 route_tun_dst.remove_vpp_config()
883 route_via_tun.remove_vpp_config()
884 gre_if.remove_vpp_config()
886 def test_gre_l2(self):
887 """ GRE tunnel L2 Tests """
890 # Add routes to resolve the tunnel destinations
892 route_tun1_dst = VppIpRoute(self, "2.2.2.2", 32,
893 [VppRoutePath(self.pg0.remote_ip4,
894 self.pg0.sw_if_index)])
895 route_tun2_dst = VppIpRoute(self, "2.2.2.3", 32,
896 [VppRoutePath(self.pg0.remote_ip4,
897 self.pg0.sw_if_index)])
899 route_tun1_dst.add_vpp_config()
900 route_tun2_dst.add_vpp_config()
903 # Create 2 L2 GRE tunnels and x-connect them
905 gre_if1 = VppGreInterface(self, self.pg0.local_ip4,
907 type=(VppEnum.vl_api_gre_tunnel_type_t.
908 GRE_API_TUNNEL_TYPE_TEB))
909 gre_if2 = VppGreInterface(self, self.pg0.local_ip4,
911 type=(VppEnum.vl_api_gre_tunnel_type_t.
912 GRE_API_TUNNEL_TYPE_TEB))
913 gre_if1.add_vpp_config()
914 gre_if2.add_vpp_config()
919 self.vapi.sw_interface_set_l2_xconnect(gre_if1.sw_if_index,
922 self.vapi.sw_interface_set_l2_xconnect(gre_if2.sw_if_index,
927 # Send in tunnel encapped L2. expect out tunnel encapped L2
930 tx = self.create_tunnel_stream_l2o4(self.pg0,
933 rx = self.send_and_expect(self.pg0, tx, self.pg0)
934 self.verify_tunneled_l2o4(self.pg0, rx, tx,
938 tx = self.create_tunnel_stream_l2o4(self.pg0,
941 rx = self.send_and_expect(self.pg0, tx, self.pg0)
942 self.verify_tunneled_l2o4(self.pg0, rx, tx,
946 self.vapi.sw_interface_set_l2_xconnect(gre_if1.sw_if_index,
949 self.vapi.sw_interface_set_l2_xconnect(gre_if2.sw_if_index,
954 # Create a VLAN sub-interfaces on the GRE TEB interfaces
955 # then x-connect them
957 gre_if_11 = VppDot1QSubint(self, gre_if1, 11)
958 gre_if_12 = VppDot1QSubint(self, gre_if2, 12)
960 # gre_if_11.add_vpp_config()
961 # gre_if_12.add_vpp_config()
966 self.vapi.sw_interface_set_l2_xconnect(gre_if_11.sw_if_index,
967 gre_if_12.sw_if_index,
969 self.vapi.sw_interface_set_l2_xconnect(gre_if_12.sw_if_index,
970 gre_if_11.sw_if_index,
974 # Configure both to pop thier respective VLAN tags,
975 # so that during the x-coonect they will subsequently push
977 self.vapi.l2_interface_vlan_tag_rewrite(
978 sw_if_index=gre_if_12.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
980 self.vapi.l2_interface_vlan_tag_rewrite(
981 sw_if_index=gre_if_11.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
985 # Send traffic in both directiond - expect the VLAN tags to
988 tx = self.create_tunnel_stream_vlano4(self.pg0,
992 rx = self.send_and_expect(self.pg0, tx, self.pg0)
993 self.verify_tunneled_vlano4(self.pg0, rx, tx,
998 tx = self.create_tunnel_stream_vlano4(self.pg0,
1002 rx = self.send_and_expect(self.pg0, tx, self.pg0)
1003 self.verify_tunneled_vlano4(self.pg0, rx, tx,
1009 # Cleanup Test resources
1011 gre_if_11.remove_vpp_config()
1012 gre_if_12.remove_vpp_config()
1013 gre_if1.remove_vpp_config()
1014 gre_if2.remove_vpp_config()
1015 route_tun1_dst.add_vpp_config()
1016 route_tun2_dst.add_vpp_config()
1018 def test_gre_loop(self):
1019 """ GRE tunnel loop Tests """
1022 # Create an L3 GRE tunnel.
1024 # - assign an IP Addres
1026 gre_if = VppGreInterface(self,
1029 gre_if.add_vpp_config()
1034 # add a route to the tunnel's destination that points
1035 # through the tunnel, hence forming a loop in the forwarding
1038 route_dst = VppIpRoute(self, "1.1.1.2", 32,
1039 [VppRoutePath("0.0.0.0",
1040 gre_if.sw_if_index)])
1041 route_dst.add_vpp_config()
1044 # packets to the tunnels destination should be dropped
1046 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "1.1.1.2")
1047 self.send_and_assert_no_replies(self.pg2, tx)
1049 self.logger.info(self.vapi.ppcli("sh adj 7"))
1054 route_dst.modify([VppRoutePath(self.pg1.remote_ip4,
1055 self.pg1.sw_if_index)])
1056 route_dst.add_vpp_config()
1058 rx = self.send_and_expect(self.pg0, tx, self.pg1)
1061 # a good route throught the tunnel to check it restacked
1063 route_via_tun_2 = VppIpRoute(self, "2.2.2.2", 32,
1064 [VppRoutePath("0.0.0.0",
1065 gre_if.sw_if_index)])
1066 route_via_tun_2.add_vpp_config()
1068 tx = self.create_stream_ip4(self.pg0, "2.2.2.3", "2.2.2.2")
1069 rx = self.send_and_expect(self.pg0, tx, self.pg1)
1070 self.verify_tunneled_4o4(self.pg1, rx, tx,
1071 self.pg0.local_ip4, "1.1.1.2")
1076 route_via_tun_2.remove_vpp_config()
1077 gre_if.remove_vpp_config()
1079 def test_mgre(self):
1080 """ mGRE IPv4 tunnel Tests """
1082 for itf in self.pg_interfaces[3:]:
1084 # one underlay nh for each overlay/tunnel peer
1086 itf.generate_remote_hosts(4)
1087 itf.configure_ipv4_neighbors()
1090 # Create an L3 GRE tunnel.
1092 # - assign an IP Addres
1093 # - Add a route via the tunnel
1095 gre_if = VppGreInterface(self,
1098 mode=(VppEnum.vl_api_tunnel_mode_t.
1099 TUNNEL_API_MODE_MP))
1100 gre_if.add_vpp_config()
1103 gre_if.generate_remote_hosts(4)
1105 self.logger.info(self.vapi.cli("sh adj"))
1106 self.logger.info(self.vapi.cli("sh ip fib"))
1109 # ensure we don't match to the tunnel if the source address
1112 tx = self.create_tunnel_stream_4o4(self.pg0,
1116 self.pg0.remote_ip4)
1117 self.send_and_assert_no_replies(self.pg0, tx)
1122 for ii in range(1, 4):
1123 route_addr = "4.4.4.%d" % ii
1124 tx_e = self.create_stream_ip4(self.pg0, "5.5.5.5", route_addr)
1127 # route traffic via the peer
1129 route_via_tun = VppIpRoute(
1130 self, route_addr, 32,
1131 [VppRoutePath(gre_if._remote_hosts[ii].ip4,
1132 gre_if.sw_if_index)])
1133 route_via_tun.add_vpp_config()
1135 # all packets dropped at this point
1136 rx = self.send_and_assert_no_replies(self.pg0, tx_e)
1140 rx = self.send_and_assert_no_replies(self.pg0, tx_e)
1143 # Add a TEIB entry resolves the peer
1145 teib = VppTeib(self, gre_if,
1146 gre_if._remote_hosts[ii].ip4,
1147 itf._remote_hosts[ii].ip4)
1148 teib.add_vpp_config()
1151 # Send a packet stream that is routed into the tunnel
1152 # - packets are GRE encapped
1154 rx = self.send_and_expect(self.pg0, tx_e, itf)
1155 self.verify_tunneled_4o4(self.pg0, rx, tx_e,
1157 itf._remote_hosts[ii].ip4)
1159 tx_i = self.create_tunnel_stream_4o4(self.pg0,
1160 itf._remote_hosts[ii].ip4,
1163 self.pg0.remote_ip4)
1164 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1165 self.verify_decapped_4o4(self.pg0, rx, tx_i)
1168 # delete and re-add the TEIB
1170 teib.remove_vpp_config()
1171 self.send_and_assert_no_replies(self.pg0, tx_e)
1172 self.send_and_assert_no_replies(self.pg0, tx_i)
1174 teib.add_vpp_config()
1175 rx = self.send_and_expect(self.pg0, tx_e, itf)
1176 self.verify_tunneled_4o4(self.pg0, rx, tx_e,
1178 itf._remote_hosts[ii].ip4)
1179 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1180 self.verify_decapped_4o4(self.pg0, rx, tx_i)
1183 # bounce the interface state and try packets again
1187 rx = self.send_and_expect(self.pg0, tx_e, itf)
1188 self.verify_tunneled_4o4(self.pg0, rx, tx_e,
1190 itf._remote_hosts[ii].ip4)
1191 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1192 self.verify_decapped_4o4(self.pg0, rx, tx_i)
1195 gre_if.unconfig_ip4()
1197 def test_mgre6(self):
1198 """ mGRE IPv6 tunnel Tests """
1200 self.pg0.config_ip6()
1201 self.pg0.resolve_ndp()
1203 e = VppEnum.vl_api_tunnel_encap_decap_flags_t
1205 for itf in self.pg_interfaces[3:]:
1207 # one underlay nh for each overlay/tunnel peer
1210 itf.generate_remote_hosts(4)
1211 itf.configure_ipv6_neighbors()
1214 # Create an L3 GRE tunnel.
1216 # - assign an IP Addres
1217 # - Add a route via the tunnel
1219 gre_if = VppGreInterface(
1223 mode=(VppEnum.vl_api_tunnel_mode_t.
1224 TUNNEL_API_MODE_MP),
1225 flags=e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
1227 gre_if.add_vpp_config()
1230 gre_if.generate_remote_hosts(4)
1235 for ii in range(1, 4):
1236 route_addr = "4::%d" % ii
1239 # Add a TEIB entry resolves the peer
1241 teib = VppTeib(self, gre_if,
1242 gre_if._remote_hosts[ii].ip6,
1243 itf._remote_hosts[ii].ip6)
1244 teib.add_vpp_config()
1247 # route traffic via the peer
1249 route_via_tun = VppIpRoute(
1250 self, route_addr, 128,
1251 [VppRoutePath(gre_if._remote_hosts[ii].ip6,
1252 gre_if.sw_if_index)])
1253 route_via_tun.add_vpp_config()
1256 # Send a packet stream that is routed into the tunnel
1257 # - packets are GRE encapped
1259 tx_e = self.create_stream_ip6(self.pg0, "5::5", route_addr,
1261 rx = self.send_and_expect(self.pg0, tx_e, itf)
1262 self.verify_tunneled_6o6(self.pg0, rx, tx_e,
1264 itf._remote_hosts[ii].ip6,
1266 tx_i = self.create_tunnel_stream_6o6(self.pg0,
1267 itf._remote_hosts[ii].ip6,
1270 self.pg0.remote_ip6)
1271 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1272 self.verify_decapped_6o6(self.pg0, rx, tx_i)
1275 # delete and re-add the TEIB
1277 teib.remove_vpp_config()
1278 self.send_and_assert_no_replies(self.pg0, tx_e)
1280 teib.add_vpp_config()
1281 rx = self.send_and_expect(self.pg0, tx_e, itf)
1282 self.verify_tunneled_6o6(self.pg0, rx, tx_e,
1284 itf._remote_hosts[ii].ip6,
1286 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1287 self.verify_decapped_6o6(self.pg0, rx, tx_i)
1290 gre_if.unconfig_ip4()
1292 self.pg0.unconfig_ip6()
1295 if __name__ == '__main__':
1296 unittest.main(testRunner=VppTestRunner)