@@ -638,6 +638,128 @@ def test_tmap_ipv6(self):
638638 for p in c4 .pg_read_packets ():
639639 p .show2 ()
640640
641+ def test_gtp4 (self ):
642+ # TESTS:
643+ # trace add af-packet-input 10
644+ # pg interface on c1 172.20.0.1
645+ # pg interface on c4 B::1/120
646+
647+ self .start_containers ()
648+
649+ c1 = self .containers .get (self .get_name (self .instance_names [0 ]))
650+ c2 = self .containers .get (self .get_name (self .instance_names [1 ]))
651+ c3 = self .containers .get (self .get_name (self .instance_names [2 ]))
652+ c4 = self .containers .get (self .get_name (self .instance_names [- 1 ]))
653+
654+ c1 .pg_create_interface4 (local_ip = "172.16.0.1/30" , remote_ip = "172.16.0.2/30" ,
655+ local_mac = "aa:bb:cc:dd:ee:01" , remote_mac = "aa:bb:cc:dd:ee:02" )
656+ c4 .pg_create_interface4 (local_ip = "1.0.0.2/30" , remote_ip = "1.0.0.1" ,
657+ local_mac = "aa:bb:cc:dd:ee:11" , remote_mac = "aa:bb:cc:dd:ee:22" )
658+
659+ c1 .vppctl_exec ("set sr encaps source addr A1::1" )
660+ c1 .vppctl_exec ("sr policy add bsid D4:: next D2:: next D3::" )
661+ c1 .vppctl_exec ("sr localsid prefix ::ffff:ac14:0001/128 behavior end.m.gtp4.d D4::/32 v6src_prefix C1::/64" )
662+
663+ c2 .vppctl_exec ("sr localsid address D2:: behavior end" )
664+
665+ c3 .vppctl_exec ("sr localsid address D3:: behavior end" )
666+
667+ c4 .vppctl_exec ("sr localsid prefix D4::/32 behavior end.m.gtp4.e v4src_position 64" )
668+
669+ #c1.set_ipv6_route("eth1", "A1::2", "D2::/128")
670+ c2 .set_ipv6_route ("eth2" , "A2::2" , "D3::/128" )
671+ c2 .set_ipv6_route ("eth1" , "A1::1" , "C::/120" )
672+ c3 .set_ipv6_route ("eth2" , "A3::2" , "D4::/32" )
673+ c3 .set_ipv6_route ("eth1" , "A2::1" , "C::/120" )
674+ c4 .set_ip_pgroute ("pg0" , "1.0.0.1" , "172.20.0.1/32" )
675+
676+ p = (Ether (src = "aa:bb:cc:dd:ee:02" , dst = "aa:bb:cc:dd:ee:01" )/
677+ IP (src = "172.20.0.2" , dst = "172.20.0.1" )/
678+ UDP (sport = 2152 , dport = 2152 )/
679+ GTP_U_Header (gtp_type = "g_pdu" , teid = 200 )/
680+ IP (src = "172.99.0.1" , dst = "172.99.0.2" )/
681+ ICMP ())
682+
683+ print ("Sending packet on {}:" .format (c1 .name ))
684+ p .show2 ()
685+
686+ c1 .enable_trace (10 )
687+ c4 .enable_trace (10 )
688+
689+ c4 .pg_start_capture ()
690+
691+ c1 .pg_create_stream (p )
692+ c1 .pg_enable ()
693+
694+ # timeout (sleep) if needed
695+ print ("Sleeping" )
696+ time .sleep (5 )
697+
698+ print ("Receiving packet on {}:" .format (c4 .name ))
699+ for p in c4 .pg_read_packets ():
700+ p .show2 ()
701+
702+ def test_gtp4_ipv6 (self ):
703+ # TESTS:
704+ # trace add af-packet-input 10
705+ # pg interface on c1 172.20.0.1
706+ # pg interface on c4 B::1/120
707+
708+ self .start_containers ()
709+
710+
711+ c1 = self .containers .get (self .get_name (self .instance_names [0 ]))
712+ c2 = self .containers .get (self .get_name (self .instance_names [1 ]))
713+ c3 = self .containers .get (self .get_name (self .instance_names [2 ]))
714+ c4 = self .containers .get (self .get_name (self .instance_names [- 1 ]))
715+
716+ c1 .pg_create_interface4 (local_ip = "172.16.0.1/30" , remote_ip = "172.16.0.2/30" ,
717+ local_mac = "aa:bb:cc:dd:ee:01" , remote_mac = "aa:bb:cc:dd:ee:02" )
718+ c4 .pg_create_interface4 (local_ip = "1.0.0.2/30" , remote_ip = "1.0.0.1" ,
719+ local_mac = "aa:bb:cc:dd:ee:11" , remote_mac = "aa:bb:cc:dd:ee:22" )
720+
721+ c1 .vppctl_exec ("set sr encaps source addr A1::1" )
722+ c1 .vppctl_exec ("sr policy add bsid D4:: next D2:: next D3::" )
723+ c1 .vppctl_exec ("sr localsid prefix ::ffff:ac14:0001/128 behavior end.m.gtp4.d D4::/32 v6src_prefix C1::/64" )
724+
725+ c2 .vppctl_exec ("sr localsid address D2:: behavior end" )
726+
727+ c3 .vppctl_exec ("sr localsid address D3:: behavior end" )
728+
729+ c4 .vppctl_exec ("sr localsid prefix D4::/32 behavior end.m.gtp4.e v4src_position 64" )
730+
731+ c2 .set_ipv6_route ("eth2" , "A2::2" , "D3::/128" )
732+ c2 .set_ipv6_route ("eth1" , "A1::1" , "C::/120" )
733+ c3 .set_ipv6_route ("eth2" , "A3::2" , "D4::/32" )
734+ c3 .set_ipv6_route ("eth1" , "A2::1" , "C::/120" )
735+ c4 .set_ip_pgroute ("pg0" , "1.0.0.1" , "172.20.0.1/32" )
736+
737+ p = (Ether (src = "aa:bb:cc:dd:ee:02" , dst = "aa:bb:cc:dd:ee:01" )/
738+ IP (src = "172.20.0.2" , dst = "172.20.0.1" )/
739+ UDP (sport = 2152 , dport = 2152 )/
740+ GTP_U_Header (gtp_type = "g_pdu" , teid = 200 )/
741+ IPv6 (src = "2001::1" , dst = "2002::1" )/
742+ ICMPv6EchoRequest ())
743+
744+ print ("Sending packet on {}:" .format (c1 .name ))
745+ p .show2 ()
746+
747+ c1 .enable_trace (10 )
748+ c4 .enable_trace (10 )
749+
750+ c4 .pg_start_capture ()
751+
752+ c1 .pg_create_stream (p )
753+ c1 .pg_enable ()
754+
755+ # timeout (sleep) if needed
756+ print ("Sleeping" )
757+ time .sleep (5 )
758+
759+ print ("Receiving packet on {}:" .format (c4 .name ))
760+ for p in c4 .pg_read_packets ():
761+ p .show2 ()
762+
641763 def test_gtp6_drop_in (self ):
642764 # TESTS:
643765 # trace add af-packet-input 10
@@ -995,7 +1117,7 @@ def get_args():
9951117 help = "Test related commands." )
9961118
9971119 p3 .add_argument ("op" , choices = [
998- "ping" , "srv6" , "tmap" , "tmap_ipv6" , "gtp6_drop_in" , "gtp6_drop_in_ipv6" , "gtp6" , "gtp6_ipv6" ])
1120+ "ping" , "srv6" , "tmap" , "tmap_ipv6" , "gtp4" , "gtp4_ipv6" , "gtp6_drop_in" , "gtp6_drop_in_ipv6" , "gtp6" , "gtp6_ipv6" ])
9991121
10001122 args = parser .parse_args ()
10011123 if not hasattr (args , "op" ) or not args .op :
@@ -1042,6 +1164,10 @@ def main(op=None, prefix=None, verbose=None, image=None, index=None, command=Non
10421164 program .test_tmap ()
10431165 elif op == 'tmap_ipv6' :
10441166 program .test_tmap_ipv6 ()
1167+ elif op == 'gtp4' :
1168+ program .test_gtp4 ()
1169+ elif op == 'gtp4_ipv6' :
1170+ program .test_gtp4_ipv6 ()
10451171 elif op == 'gtp6_drop_in' :
10461172 program .test_gtp6_drop_in ()
10471173 elif op == 'gtp6_drop_in_ipv6' :
0 commit comments