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 VppTestCase, VppTestRunner
13 from vpp_sub_interface import L2_VTR_OP, VppDot1QSubint
14 from vpp_gre_interface import VppGreInterface
15 from vpp_teib import VppNhrp
16 from vpp_ip import DpoProto
17 from vpp_ip_route import VppIpRoute, VppRoutePath, VppIpTable, FibPathProto
18 from util import ppp, ppc
19 from vpp_papi import VppEnum
22 class TestGREInputNodes(VppTestCase):
23 """ GRE Input Nodes Test Case """
26 super(TestGREInputNodes, self).setUp()
28 # create 3 pg interfaces - set one in a non-default table.
29 self.create_pg_interfaces(range(1))
31 for i in self.pg_interfaces:
36 for i in self.pg_interfaces:
39 super(TestGREInputNodes, self).tearDown()
41 def test_gre_input_node(self):
42 """ GRE gre input nodes not registerd unless configured """
43 pkt = (Ether(dst=self.pg0.local_mac, src=self.pg0.remote_mac) /
44 IP(src=self.pg0.remote_ip4, dst=self.pg0.local_ip4) /
47 self.pg0.add_stream(pkt)
49 # no tunnel created, gre-input not registered
50 err = self.statistics.get_counter(
51 '/err/ip4-local/unknown ip protocol')[0]
52 self.assertEqual(err, 1)
56 gre_if = VppGreInterface(self, self.pg0.local_ip4, "1.1.1.2")
57 gre_if.add_vpp_config()
59 self.pg0.add_stream(pkt)
61 # tunnel created, gre-input registered
62 err = self.statistics.get_counter(
63 '/err/ip4-local/unknown ip protocol')[0]
64 # expect no new errors
65 self.assertEqual(err, err_count)
68 class TestGRE(VppTestCase):
73 super(TestGRE, cls).setUpClass()
76 def tearDownClass(cls):
77 super(TestGRE, cls).tearDownClass()
80 super(TestGRE, self).setUp()
82 # create 3 pg interfaces - set one in a non-default table.
83 self.create_pg_interfaces(range(5))
85 self.tbl = VppIpTable(self, 1)
86 self.tbl.add_vpp_config()
87 self.pg1.set_table_ip4(1)
89 for i in self.pg_interfaces:
93 self.pg0.resolve_arp()
95 self.pg1.resolve_arp()
97 self.pg2.resolve_ndp()
99 self.pg3.resolve_arp()
100 self.pg4.config_ip4()
101 self.pg4.resolve_arp()
104 for i in self.pg_interfaces:
108 self.pg1.set_table_ip4(0)
109 super(TestGRE, self).tearDown()
111 def create_stream_ip4(self, src_if, src_ip, dst_ip, dscp=0, ecn=0):
113 tos = (dscp << 2) | ecn
114 for i in range(0, 257):
115 info = self.create_packet_info(src_if, src_if)
116 payload = self.info_to_payload(info)
117 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
118 IP(src=src_ip, dst=dst_ip, tos=tos) /
119 UDP(sport=1234, dport=1234) /
125 def create_stream_ip6(self, src_if, src_ip, dst_ip, dscp=0, ecn=0):
127 tc = (dscp << 2) | ecn
128 for i in range(0, 257):
129 info = self.create_packet_info(src_if, src_if)
130 payload = self.info_to_payload(info)
131 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
132 IPv6(src=src_ip, dst=dst_ip, tc=tc) /
133 UDP(sport=1234, dport=1234) /
139 def create_tunnel_stream_4o4(self, src_if,
140 tunnel_src, tunnel_dst,
143 for i in range(0, 257):
144 info = self.create_packet_info(src_if, src_if)
145 payload = self.info_to_payload(info)
146 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
147 IP(src=tunnel_src, dst=tunnel_dst) /
149 IP(src=src_ip, dst=dst_ip) /
150 UDP(sport=1234, dport=1234) /
156 def create_tunnel_stream_6o4(self, src_if,
157 tunnel_src, tunnel_dst,
160 for i in range(0, 257):
161 info = self.create_packet_info(src_if, src_if)
162 payload = self.info_to_payload(info)
163 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
164 IP(src=tunnel_src, dst=tunnel_dst) /
166 IPv6(src=src_ip, dst=dst_ip) /
167 UDP(sport=1234, dport=1234) /
173 def create_tunnel_stream_6o6(self, src_if,
174 tunnel_src, tunnel_dst,
177 for i in range(0, 257):
178 info = self.create_packet_info(src_if, src_if)
179 payload = self.info_to_payload(info)
180 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
181 IPv6(src=tunnel_src, dst=tunnel_dst) /
183 IPv6(src=src_ip, dst=dst_ip) /
184 UDP(sport=1234, dport=1234) /
190 def create_tunnel_stream_l2o4(self, src_if,
191 tunnel_src, tunnel_dst):
193 for i in range(0, 257):
194 info = self.create_packet_info(src_if, src_if)
195 payload = self.info_to_payload(info)
196 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
197 IP(src=tunnel_src, dst=tunnel_dst) /
199 Ether(dst=RandMAC('*:*:*:*:*:*'),
200 src=RandMAC('*:*:*:*:*:*')) /
201 IP(src=scapy.compat.raw(RandIP()),
202 dst=scapy.compat.raw(RandIP())) /
203 UDP(sport=1234, dport=1234) /
209 def create_tunnel_stream_vlano4(self, src_if,
210 tunnel_src, tunnel_dst, vlan):
212 for i in range(0, 257):
213 info = self.create_packet_info(src_if, src_if)
214 payload = self.info_to_payload(info)
215 p = (Ether(dst=src_if.local_mac, src=src_if.remote_mac) /
216 IP(src=tunnel_src, dst=tunnel_dst) /
218 Ether(dst=RandMAC('*:*:*:*:*:*'),
219 src=RandMAC('*:*:*:*:*:*')) /
221 IP(src=scapy.compat.raw(RandIP()),
222 dst=scapy.compat.raw(RandIP())) /
223 UDP(sport=1234, dport=1234) /
229 def verify_tunneled_4o4(self, src_if, capture, sent,
230 tunnel_src, tunnel_dst,
233 self.assertEqual(len(capture), len(sent))
234 tos = (dscp << 2) | ecn
236 for i in range(len(capture)):
244 self.assertEqual(rx_ip.src, tunnel_src)
245 self.assertEqual(rx_ip.dst, tunnel_dst)
246 self.assertEqual(rx_ip.tos, tos)
251 self.assertEqual(rx_ip.src, tx_ip.src)
252 self.assertEqual(rx_ip.dst, tx_ip.dst)
253 # IP processing post pop has decremented the TTL
254 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
257 self.logger.error(ppp("Rx:", rx))
258 self.logger.error(ppp("Tx:", tx))
261 def verify_tunneled_6o6(self, src_if, capture, sent,
262 tunnel_src, tunnel_dst,
265 self.assertEqual(len(capture), len(sent))
266 tc = (dscp << 2) | ecn
268 for i in range(len(capture)):
276 self.assertEqual(rx_ip.src, tunnel_src)
277 self.assertEqual(rx_ip.dst, tunnel_dst)
278 self.assertEqual(rx_ip.tc, tc)
280 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
283 self.assertEqual(rx_ip.src, tx_ip.src)
284 self.assertEqual(rx_ip.dst, tx_ip.dst)
287 self.logger.error(ppp("Rx:", rx))
288 self.logger.error(ppp("Tx:", tx))
291 def verify_tunneled_4o6(self, src_if, capture, sent,
292 tunnel_src, tunnel_dst):
294 self.assertEqual(len(capture), len(sent))
296 for i in range(len(capture)):
303 self.assertEqual(rx_ip.src, tunnel_src)
304 self.assertEqual(rx_ip.dst, tunnel_dst)
306 rx_gre = GRE(scapy.compat.raw(rx_ip[IPv6].payload))
310 self.assertEqual(rx_ip.src, tx_ip.src)
311 self.assertEqual(rx_ip.dst, tx_ip.dst)
314 self.logger.error(ppp("Rx:", rx))
315 self.logger.error(ppp("Tx:", tx))
318 def verify_tunneled_6o4(self, src_if, capture, sent,
319 tunnel_src, tunnel_dst):
321 self.assertEqual(len(capture), len(sent))
323 for i in range(len(capture)):
330 self.assertEqual(rx_ip.src, tunnel_src)
331 self.assertEqual(rx_ip.dst, tunnel_dst)
333 rx_gre = GRE(scapy.compat.raw(rx_ip[IP].payload))
337 self.assertEqual(rx_ip.src, tx_ip.src)
338 self.assertEqual(rx_ip.dst, tx_ip.dst)
341 self.logger.error(ppp("Rx:", rx))
342 self.logger.error(ppp("Tx:", tx))
345 def verify_tunneled_l2o4(self, src_if, capture, sent,
346 tunnel_src, tunnel_dst):
347 self.assertEqual(len(capture), len(sent))
349 for i in range(len(capture)):
357 self.assertEqual(rx_ip.src, tunnel_src)
358 self.assertEqual(rx_ip.dst, tunnel_dst)
361 rx_l2 = rx_gre[Ether]
364 tx_l2 = tx_gre[Ether]
367 self.assertEqual(rx_ip.src, tx_ip.src)
368 self.assertEqual(rx_ip.dst, tx_ip.dst)
369 # bridged, not L3 forwarded, so no TTL decrement
370 self.assertEqual(rx_ip.ttl, tx_ip.ttl)
373 self.logger.error(ppp("Rx:", rx))
374 self.logger.error(ppp("Tx:", tx))
377 def verify_tunneled_vlano4(self, src_if, capture, sent,
378 tunnel_src, tunnel_dst, vlan):
380 self.assertEqual(len(capture), len(sent))
382 ppc("Unexpected packets captured:", capture)
385 for i in range(len(capture)):
393 self.assertEqual(rx_ip.src, tunnel_src)
394 self.assertEqual(rx_ip.dst, tunnel_dst)
397 rx_l2 = rx_gre[Ether]
398 rx_vlan = rx_l2[Dot1Q]
401 self.assertEqual(rx_vlan.vlan, vlan)
404 tx_l2 = tx_gre[Ether]
407 self.assertEqual(rx_ip.src, tx_ip.src)
408 self.assertEqual(rx_ip.dst, tx_ip.dst)
409 # bridged, not L3 forwarded, so no TTL decrement
410 self.assertEqual(rx_ip.ttl, tx_ip.ttl)
413 self.logger.error(ppp("Rx:", rx))
414 self.logger.error(ppp("Tx:", tx))
417 def verify_decapped_4o4(self, src_if, capture, sent):
418 self.assertEqual(len(capture), len(sent))
420 for i in range(len(capture)):
430 self.assertEqual(rx_ip.src, tx_ip.src)
431 self.assertEqual(rx_ip.dst, tx_ip.dst)
432 # IP processing post pop has decremented the TTL
433 self.assertEqual(rx_ip.ttl + 1, tx_ip.ttl)
436 self.logger.error(ppp("Rx:", rx))
437 self.logger.error(ppp("Tx:", tx))
440 def verify_decapped_6o4(self, src_if, capture, sent):
441 self.assertEqual(len(capture), len(sent))
443 for i in range(len(capture)):
453 self.assertEqual(rx_ip.src, tx_ip.src)
454 self.assertEqual(rx_ip.dst, tx_ip.dst)
455 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
458 self.logger.error(ppp("Rx:", rx))
459 self.logger.error(ppp("Tx:", tx))
462 def verify_decapped_6o6(self, src_if, capture, sent):
463 self.assertEqual(len(capture), len(sent))
465 for i in range(len(capture)):
475 self.assertEqual(rx_ip.src, tx_ip.src)
476 self.assertEqual(rx_ip.dst, tx_ip.dst)
477 self.assertEqual(rx_ip.hlim + 1, tx_ip.hlim)
480 self.logger.error(ppp("Rx:", rx))
481 self.logger.error(ppp("Tx:", tx))
485 """ GRE IPv4 tunnel Tests """
488 # Create an L3 GRE tunnel.
490 # - assign an IP Addres
491 # - Add a route via the tunnel
493 gre_if = VppGreInterface(self,
496 gre_if.add_vpp_config()
499 # The double create (create the same tunnel twice) should fail,
500 # and we should still be able to use the original
503 gre_if.add_vpp_config()
507 self.fail("Double GRE tunnel add does not fail")
512 route_via_tun = VppIpRoute(self, "4.4.4.4", 32,
513 [VppRoutePath("0.0.0.0",
514 gre_if.sw_if_index)])
516 route_via_tun.add_vpp_config()
519 # Send a packet stream that is routed into the tunnel
520 # - they are all dropped since the tunnel's destintation IP
521 # is unresolved - or resolves via the default route - which
524 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "4.4.4.4")
526 self.send_and_assert_no_replies(self.pg0, tx)
529 # Add a route that resolves the tunnel's destination
531 route_tun_dst = VppIpRoute(self, "1.1.1.2", 32,
532 [VppRoutePath(self.pg0.remote_ip4,
533 self.pg0.sw_if_index)])
534 route_tun_dst.add_vpp_config()
537 # Send a packet stream that is routed into the tunnel
538 # - packets are GRE encapped
540 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "4.4.4.4")
541 rx = self.send_and_expect(self.pg0, tx, self.pg0)
542 self.verify_tunneled_4o4(self.pg0, rx, tx,
543 self.pg0.local_ip4, "1.1.1.2")
546 # Send tunneled packets that match the created tunnel and
547 # are decapped and forwarded
549 tx = self.create_tunnel_stream_4o4(self.pg0,
554 rx = self.send_and_expect(self.pg0, tx, self.pg0)
555 self.verify_decapped_4o4(self.pg0, rx, tx)
558 # Send tunneled packets that do not match the tunnel's src
560 self.vapi.cli("clear trace")
561 tx = self.create_tunnel_stream_4o4(self.pg0,
566 self.send_and_assert_no_replies(
568 remark="GRE packets forwarded despite no SRC address match")
571 # Configure IPv6 on the PG interface so we can route IPv6
574 self.pg0.config_ip6()
575 self.pg0.resolve_ndp()
578 # Send IPv6 tunnel encapslated packets
579 # - dropped since IPv6 is not enabled on the tunnel
581 tx = self.create_tunnel_stream_6o4(self.pg0,
586 self.send_and_assert_no_replies(self.pg0, tx,
587 "IPv6 GRE packets forwarded "
588 "despite IPv6 not enabled on tunnel")
591 # Enable IPv6 on the tunnel
596 # Send IPv6 tunnel encapslated packets
597 # - forwarded since IPv6 is enabled on the tunnel
599 tx = self.create_tunnel_stream_6o4(self.pg0,
604 rx = self.send_and_expect(self.pg0, tx, self.pg0)
605 self.verify_decapped_6o4(self.pg0, rx, tx)
608 # Send v6 packets for v4 encap
610 route6_via_tun = VppIpRoute(
611 self, "2001::1", 128,
614 proto=DpoProto.DPO_PROTO_IP6)])
615 route6_via_tun.add_vpp_config()
617 tx = self.create_stream_ip6(self.pg0, "2001::2", "2001::1")
618 rx = self.send_and_expect(self.pg0, tx, self.pg0)
620 self.verify_tunneled_6o4(self.pg0, rx, tx,
621 self.pg0.local_ip4, "1.1.1.2")
626 route_tun_dst.remove_vpp_config()
627 route_via_tun.remove_vpp_config()
628 route6_via_tun.remove_vpp_config()
629 gre_if.remove_vpp_config()
631 self.pg0.unconfig_ip6()
634 """ GRE IPv6 tunnel Tests """
636 self.pg1.config_ip6()
637 self.pg1.resolve_ndp()
640 # Create an L3 GRE tunnel.
642 # - assign an IP Address
643 # - Add a route via the tunnel
645 gre_if = VppGreInterface(self,
648 gre_if.add_vpp_config()
652 route_via_tun = VppIpRoute(self, "4004::1", 128,
653 [VppRoutePath("0::0",
654 gre_if.sw_if_index)])
656 route_via_tun.add_vpp_config()
659 # Send a packet stream that is routed into the tunnel
660 # - they are all dropped since the tunnel's destintation IP
661 # is unresolved - or resolves via the default route - which
664 tx = self.create_stream_ip6(self.pg2, "5005::1", "4004::1")
665 self.send_and_assert_no_replies(
667 "GRE packets forwarded without DIP resolved")
670 # Add a route that resolves the tunnel's destination
672 route_tun_dst = VppIpRoute(self, "1002::1", 128,
673 [VppRoutePath(self.pg2.remote_ip6,
674 self.pg2.sw_if_index)])
675 route_tun_dst.add_vpp_config()
678 # Send a packet stream that is routed into the tunnel
679 # - packets are GRE encapped
681 tx = self.create_stream_ip6(self.pg2, "5005::1", "4004::1")
682 rx = self.send_and_expect(self.pg2, tx, self.pg2)
683 self.verify_tunneled_6o6(self.pg2, rx, tx,
684 self.pg2.local_ip6, "1002::1")
687 # Test decap. decapped packets go out pg1
689 tx = self.create_tunnel_stream_6o6(self.pg2,
694 rx = self.send_and_expect(self.pg2, tx, self.pg1)
697 # RX'd packet is UDP over IPv6, test the GRE header is gone.
699 self.assertFalse(rx[0].haslayer(GRE))
700 self.assertEqual(rx[0][IPv6].dst, self.pg1.remote_ip6)
705 route4_via_tun = VppIpRoute(self, "1.1.1.1", 32,
706 [VppRoutePath("0.0.0.0",
707 gre_if.sw_if_index)])
708 route4_via_tun.add_vpp_config()
710 tx = self.create_stream_ip4(self.pg0, "1.1.1.2", "1.1.1.1")
711 rx = self.send_and_expect(self.pg0, tx, self.pg2)
713 self.verify_tunneled_4o6(self.pg0, rx, tx,
714 self.pg2.local_ip6, "1002::1")
719 route_tun_dst.remove_vpp_config()
720 route_via_tun.remove_vpp_config()
721 route4_via_tun.remove_vpp_config()
722 gre_if.remove_vpp_config()
724 self.pg2.unconfig_ip6()
725 self.pg1.unconfig_ip6()
727 def test_gre_vrf(self):
728 """ GRE tunnel VRF Tests """
730 e = VppEnum.vl_api_tunnel_encap_decap_flags_t
733 # Create an L3 GRE tunnel whose destination is in the non-default
734 # table. The underlay is thus non-default - the overlay is still
737 # - assign an IP Addres
739 gre_if = VppGreInterface(
740 self, self.pg1.local_ip4,
743 flags=(e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP |
744 e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_ECN))
746 gre_if.add_vpp_config()
751 # Add a route via the tunnel - in the overlay
753 route_via_tun = VppIpRoute(self, "9.9.9.9", 32,
754 [VppRoutePath("0.0.0.0",
755 gre_if.sw_if_index)])
756 route_via_tun.add_vpp_config()
759 # Add a route that resolves the tunnel's destination - in the
762 route_tun_dst = VppIpRoute(self, "2.2.2.2", 32, table_id=1,
763 paths=[VppRoutePath(self.pg1.remote_ip4,
764 self.pg1.sw_if_index)])
765 route_tun_dst.add_vpp_config()
768 # Send a packet stream that is routed into the tunnel
769 # packets are sent in on pg0 which is in the default table
770 # - packets are GRE encapped
772 self.vapi.cli("clear trace")
773 tx = self.create_stream_ip4(self.pg0, "5.5.5.5", "9.9.9.9",
775 rx = self.send_and_expect(self.pg0, tx, self.pg1)
776 self.verify_tunneled_4o4(self.pg1, rx, tx,
777 self.pg1.local_ip4, "2.2.2.2",
781 # Send tunneled packets that match the created tunnel and
782 # are decapped and forwarded. This tests the decap lookup
783 # does not happen in the encap table
785 self.vapi.cli("clear trace")
786 tx = self.create_tunnel_stream_4o4(self.pg1,
791 rx = self.send_and_expect(self.pg1, tx, self.pg0)
792 self.verify_decapped_4o4(self.pg0, rx, tx)
795 # Send tunneled packets that match the created tunnel
796 # but arrive on an interface that is not in the tunnel's
797 # encap VRF, these are dropped.
798 # IP enable the interface so they aren't dropped due to
799 # IP not being enabled.
801 self.pg2.config_ip4()
802 self.vapi.cli("clear trace")
803 tx = self.create_tunnel_stream_4o4(self.pg2,
808 rx = self.send_and_assert_no_replies(
810 "GRE decap packets in wrong VRF")
812 self.pg2.unconfig_ip4()
817 route_tun_dst.remove_vpp_config()
818 route_via_tun.remove_vpp_config()
819 gre_if.remove_vpp_config()
821 def test_gre_l2(self):
822 """ GRE tunnel L2 Tests """
825 # Add routes to resolve the tunnel destinations
827 route_tun1_dst = VppIpRoute(self, "2.2.2.2", 32,
828 [VppRoutePath(self.pg0.remote_ip4,
829 self.pg0.sw_if_index)])
830 route_tun2_dst = VppIpRoute(self, "2.2.2.3", 32,
831 [VppRoutePath(self.pg0.remote_ip4,
832 self.pg0.sw_if_index)])
834 route_tun1_dst.add_vpp_config()
835 route_tun2_dst.add_vpp_config()
838 # Create 2 L2 GRE tunnels and x-connect them
840 gre_if1 = VppGreInterface(self, self.pg0.local_ip4,
842 type=(VppEnum.vl_api_gre_tunnel_type_t.
843 GRE_API_TUNNEL_TYPE_TEB))
844 gre_if2 = VppGreInterface(self, self.pg0.local_ip4,
846 type=(VppEnum.vl_api_gre_tunnel_type_t.
847 GRE_API_TUNNEL_TYPE_TEB))
848 gre_if1.add_vpp_config()
849 gre_if2.add_vpp_config()
854 self.vapi.sw_interface_set_l2_xconnect(gre_if1.sw_if_index,
857 self.vapi.sw_interface_set_l2_xconnect(gre_if2.sw_if_index,
862 # Send in tunnel encapped L2. expect out tunnel encapped L2
865 tx = self.create_tunnel_stream_l2o4(self.pg0,
868 rx = self.send_and_expect(self.pg0, tx, self.pg0)
869 self.verify_tunneled_l2o4(self.pg0, rx, tx,
873 tx = self.create_tunnel_stream_l2o4(self.pg0,
876 rx = self.send_and_expect(self.pg0, tx, self.pg0)
877 self.verify_tunneled_l2o4(self.pg0, rx, tx,
881 self.vapi.sw_interface_set_l2_xconnect(gre_if1.sw_if_index,
884 self.vapi.sw_interface_set_l2_xconnect(gre_if2.sw_if_index,
889 # Create a VLAN sub-interfaces on the GRE TEB interfaces
890 # then x-connect them
892 gre_if_11 = VppDot1QSubint(self, gre_if1, 11)
893 gre_if_12 = VppDot1QSubint(self, gre_if2, 12)
895 # gre_if_11.add_vpp_config()
896 # gre_if_12.add_vpp_config()
901 self.vapi.sw_interface_set_l2_xconnect(gre_if_11.sw_if_index,
902 gre_if_12.sw_if_index,
904 self.vapi.sw_interface_set_l2_xconnect(gre_if_12.sw_if_index,
905 gre_if_11.sw_if_index,
909 # Configure both to pop thier respective VLAN tags,
910 # so that during the x-coonect they will subsequently push
912 self.vapi.l2_interface_vlan_tag_rewrite(
913 sw_if_index=gre_if_12.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
915 self.vapi.l2_interface_vlan_tag_rewrite(
916 sw_if_index=gre_if_11.sw_if_index, vtr_op=L2_VTR_OP.L2_POP_1,
920 # Send traffic in both directiond - expect the VLAN tags to
923 tx = self.create_tunnel_stream_vlano4(self.pg0,
927 rx = self.send_and_expect(self.pg0, tx, self.pg0)
928 self.verify_tunneled_vlano4(self.pg0, rx, tx,
933 tx = self.create_tunnel_stream_vlano4(self.pg0,
937 rx = self.send_and_expect(self.pg0, tx, self.pg0)
938 self.verify_tunneled_vlano4(self.pg0, rx, tx,
944 # Cleanup Test resources
946 gre_if_11.remove_vpp_config()
947 gre_if_12.remove_vpp_config()
948 gre_if1.remove_vpp_config()
949 gre_if2.remove_vpp_config()
950 route_tun1_dst.add_vpp_config()
951 route_tun2_dst.add_vpp_config()
953 def test_gre_loop(self):
954 """ GRE tunnel loop Tests """
957 # Create an L3 GRE tunnel.
959 # - assign an IP Addres
961 gre_if = VppGreInterface(self,
964 gre_if.add_vpp_config()
969 # add a route to the tunnel's destination that points
970 # through the tunnel, hence forming a loop in the forwarding
973 route_dst = VppIpRoute(self, "1.1.1.2", 32,
974 [VppRoutePath("0.0.0.0",
975 gre_if.sw_if_index)])
976 route_dst.add_vpp_config()
979 # packets to the tunnels destination should be dropped
981 tx = self.create_stream_ip4(self.pg0, "1.1.1.1", "1.1.1.2")
982 self.send_and_assert_no_replies(self.pg2, tx)
984 self.logger.info(self.vapi.ppcli("sh adj 7"))
989 route_dst.modify([VppRoutePath(self.pg1.remote_ip4,
990 self.pg1.sw_if_index)])
991 route_dst.add_vpp_config()
993 rx = self.send_and_expect(self.pg0, tx, self.pg1)
996 # a good route throught the tunnel to check it restacked
998 route_via_tun_2 = VppIpRoute(self, "2.2.2.2", 32,
999 [VppRoutePath("0.0.0.0",
1000 gre_if.sw_if_index)])
1001 route_via_tun_2.add_vpp_config()
1003 tx = self.create_stream_ip4(self.pg0, "2.2.2.3", "2.2.2.2")
1004 rx = self.send_and_expect(self.pg0, tx, self.pg1)
1005 self.verify_tunneled_4o4(self.pg1, rx, tx,
1006 self.pg0.local_ip4, "1.1.1.2")
1011 route_via_tun_2.remove_vpp_config()
1012 gre_if.remove_vpp_config()
1014 def test_mgre(self):
1015 """ mGRE IPv4 tunnel Tests """
1017 for itf in self.pg_interfaces[3:]:
1019 # one underlay nh for each overlay/tunnel peer
1021 itf.generate_remote_hosts(4)
1022 itf.configure_ipv4_neighbors()
1025 # Create an L3 GRE tunnel.
1027 # - assign an IP Addres
1028 # - Add a route via the tunnel
1030 gre_if = VppGreInterface(self,
1033 mode=(VppEnum.vl_api_tunnel_mode_t.
1034 TUNNEL_API_MODE_MP))
1035 gre_if.add_vpp_config()
1038 gre_if.generate_remote_hosts(4)
1040 self.logger.info(self.vapi.cli("sh adj"))
1041 self.logger.info(self.vapi.cli("sh ip fib"))
1044 # ensure we don't match to the tunnel if the source address
1047 tx = self.create_tunnel_stream_4o4(self.pg0,
1051 self.pg0.remote_ip4)
1052 self.send_and_assert_no_replies(self.pg0, tx)
1057 for ii in range(1, 4):
1058 route_addr = "4.4.4.%d" % ii
1061 # route traffic via the peer
1063 route_via_tun = VppIpRoute(
1064 self, route_addr, 32,
1065 [VppRoutePath(gre_if._remote_hosts[ii].ip4,
1066 gre_if.sw_if_index)])
1067 route_via_tun.add_vpp_config()
1070 # Add a NHRP entry resolves the peer
1072 teib = VppNhrp(self, gre_if,
1073 gre_if._remote_hosts[ii].ip4,
1074 itf._remote_hosts[ii].ip4)
1075 teib.add_vpp_config()
1078 # Send a packet stream that is routed into the tunnel
1079 # - packets are GRE encapped
1081 tx_e = self.create_stream_ip4(self.pg0, "5.5.5.5", route_addr)
1082 rx = self.send_and_expect(self.pg0, tx_e, itf)
1083 self.verify_tunneled_4o4(self.pg0, rx, tx_e,
1085 itf._remote_hosts[ii].ip4)
1087 tx_i = self.create_tunnel_stream_4o4(self.pg0,
1088 itf._remote_hosts[ii].ip4,
1091 self.pg0.remote_ip4)
1092 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1093 self.verify_decapped_4o4(self.pg0, rx, tx_i)
1096 # delete and re-add the NHRP
1098 teib.remove_vpp_config()
1099 self.send_and_assert_no_replies(self.pg0, tx_e)
1100 self.send_and_assert_no_replies(self.pg0, tx_i)
1102 teib.add_vpp_config()
1103 rx = self.send_and_expect(self.pg0, tx_e, itf)
1104 self.verify_tunneled_4o4(self.pg0, rx, tx_e,
1106 itf._remote_hosts[ii].ip4)
1107 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1108 self.verify_decapped_4o4(self.pg0, rx, tx_i)
1111 gre_if.unconfig_ip4()
1113 def test_mgre6(self):
1114 """ mGRE IPv6 tunnel Tests """
1116 self.pg0.config_ip6()
1117 self.pg0.resolve_ndp()
1119 e = VppEnum.vl_api_tunnel_encap_decap_flags_t
1121 for itf in self.pg_interfaces[3:]:
1123 # one underlay nh for each overlay/tunnel peer
1126 itf.generate_remote_hosts(4)
1127 itf.configure_ipv6_neighbors()
1130 # Create an L3 GRE tunnel.
1132 # - assign an IP Addres
1133 # - Add a route via the tunnel
1135 gre_if = VppGreInterface(
1139 mode=(VppEnum.vl_api_tunnel_mode_t.
1140 TUNNEL_API_MODE_MP),
1141 flags=e.TUNNEL_API_ENCAP_DECAP_FLAG_ENCAP_COPY_DSCP)
1143 gre_if.add_vpp_config()
1146 gre_if.generate_remote_hosts(4)
1151 for ii in range(1, 4):
1152 route_addr = "4::%d" % ii
1155 # Add a NHRP entry resolves the peer
1157 teib = VppNhrp(self, gre_if,
1158 gre_if._remote_hosts[ii].ip6,
1159 itf._remote_hosts[ii].ip6)
1160 teib.add_vpp_config()
1163 # route traffic via the peer
1165 route_via_tun = VppIpRoute(
1166 self, route_addr, 128,
1167 [VppRoutePath(gre_if._remote_hosts[ii].ip6,
1168 gre_if.sw_if_index)])
1169 route_via_tun.add_vpp_config()
1172 # Send a packet stream that is routed into the tunnel
1173 # - packets are GRE encapped
1175 tx_e = self.create_stream_ip6(self.pg0, "5::5", route_addr,
1177 rx = self.send_and_expect(self.pg0, tx_e, itf)
1178 self.verify_tunneled_6o6(self.pg0, rx, tx_e,
1180 itf._remote_hosts[ii].ip6,
1182 tx_i = self.create_tunnel_stream_6o6(self.pg0,
1183 itf._remote_hosts[ii].ip6,
1186 self.pg0.remote_ip6)
1187 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1188 self.verify_decapped_6o6(self.pg0, rx, tx_i)
1191 # delete and re-add the NHRP
1193 teib.remove_vpp_config()
1194 self.send_and_assert_no_replies(self.pg0, tx_e)
1196 teib.add_vpp_config()
1197 rx = self.send_and_expect(self.pg0, tx_e, itf)
1198 self.verify_tunneled_6o6(self.pg0, rx, tx_e,
1200 itf._remote_hosts[ii].ip6,
1202 rx = self.send_and_expect(self.pg0, tx_i, self.pg0)
1203 self.verify_decapped_6o6(self.pg0, rx, tx_i)
1206 gre_if.unconfig_ip4()
1208 self.pg0.unconfig_ip6()
1211 if __name__ == '__main__':
1212 unittest.main(testRunner=VppTestRunner)