aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTetsuya Murakami <tetsuya.mrk@gmail.com>2020-03-04 16:27:14 -0800
committerDamjan Marion <dmarion@me.com>2020-03-21 12:49:12 +0000
commit9e722bd466383dd53b10d4c1de95ad18db939147 (patch)
treef870d7ad6b974798ac26a0b1580a67b2f61f12a7
parent7a6f5a4fee17bd34f70f9eb25a094764be39d81b (diff)
srv6-mobile: Support GTP4/6.DT and User Plane message mapping
Support the following new features in srv6-mobile. 1. GTP4.DT 2. GTP6.DT 3. User Plane Message encoding based on draft-murakami-dmm-user-plane-message-encoding-01 4. Add SRv6 mobile test cases Type: feature Signed-off-by: Tetsuya Murakami <tetsuya.mrk@gmail.com> Change-Id: I890e5171bf03513d54b4830f01b9dc7f47fe7c48 Signed-off-by: Tetsuya Murakami <tetsuya.mrk@gmail.com>
-rw-r--r--src/plugins/srv6-mobile/CMakeLists.txt2
-rw-r--r--src/plugins/srv6-mobile/extra/Dockerfile.j2.release1
-rwxr-xr-xsrc/plugins/srv6-mobile/extra/runner.py477
-rw-r--r--src/plugins/srv6-mobile/gtp4_dt.c205
-rw-r--r--src/plugins/srv6-mobile/gtp6_dt.c199
-rw-r--r--src/plugins/srv6-mobile/mobile.h71
-rw-r--r--src/plugins/srv6-mobile/node.c863
-rw-r--r--src/plugins/srv6-mobile/test/test_srv6_end.py160
-rw-r--r--src/plugins/srv6-mobile/test/test_srv6_mobile.py340
-rwxr-xr-xsrc/vnet/srv6/sr_packet.h7
10 files changed, 2119 insertions, 206 deletions
diff --git a/src/plugins/srv6-mobile/CMakeLists.txt b/src/plugins/srv6-mobile/CMakeLists.txt
index ebd03f7fbf4..5a9945c2e4f 100644
--- a/src/plugins/srv6-mobile/CMakeLists.txt
+++ b/src/plugins/srv6-mobile/CMakeLists.txt
@@ -15,9 +15,11 @@ add_vpp_plugin(srv6mobile
SOURCES
gtp4_e.c
gtp4_d.c
+ gtp4_dt.c
gtp6_e.c
gtp6_d.c
gtp6_d_di.c
+ gtp6_dt.c
node.c
INSTALL_HEADERS
diff --git a/src/plugins/srv6-mobile/extra/Dockerfile.j2.release b/src/plugins/srv6-mobile/extra/Dockerfile.j2.release
index 851aef66197..bdb57a61511 100644
--- a/src/plugins/srv6-mobile/extra/Dockerfile.j2.release
+++ b/src/plugins/srv6-mobile/extra/Dockerfile.j2.release
@@ -16,6 +16,7 @@ RUN set -eux; \
iproute2 \
tcpdump \
python3-cffi \
+ python2.7 \
netcat; \
rm -rf /var/lib/apt/lists/*; \
mv /usr/sbin/tcpdump /usr/bin/tcpdump
diff --git a/src/plugins/srv6-mobile/extra/runner.py b/src/plugins/srv6-mobile/extra/runner.py
index 79ec2d007c5..c438fb161b7 100755
--- a/src/plugins/srv6-mobile/extra/runner.py
+++ b/src/plugins/srv6-mobile/extra/runner.py
@@ -135,7 +135,7 @@ class Container(object):
self.vppctl_exec("set int mac address pg0 {}".format(local_mac))
self.vppctl_exec("set int ip addr pg0 {}".format(local_ip))
self.vppctl_exec(
- "set ip6 neighbor pg0 {} {}".format(remote_ip, remote_mac))
+ "set ip neighbor pg0 {} {}".format(remote_ip, remote_mac))
self.vppctl_exec("set int state pg0 up")
def pg_create_interface4(self, local_ip, remote_ip, local_mac, remote_mac):
@@ -145,7 +145,7 @@ class Container(object):
self.vppctl_exec("create packet-generator interface pg0")
self.vppctl_exec("set int mac address pg0 {}".format(local_mac))
self.vppctl_exec("set int ip addr pg0 {}".format(local_ip))
- self.vppctl_exec("set ip arp pg0 {} {}".format(remote_ip, remote_mac))
+ self.vppctl_exec("set ip neighbor pg0 {} {}".format(remote_ip, remote_mac))
self.vppctl_exec("set int state pg0 up")
def pg_create_interface6(self, local_ip, remote_ip, local_mac, remote_mac):
@@ -154,10 +154,30 @@ class Container(object):
time.sleep(2)
self.vppctl_exec("create packet-generator interface pg0")
self.vppctl_exec("set int mac address pg0 {}".format(local_mac))
- self.vppctl_exec("set int ip6 addr pg0 {}".format(local_ip))
- self.vppctl_exec("set ip6 arp pg0 {} {}".format(remote_ip, remote_mac))
+ self.vppctl_exec("set int ip addr pg0 {}".format(local_ip))
+ self.vppctl_exec("set ip neighbor pg0 {} {}".format(remote_ip, remote_mac))
self.vppctl_exec("set int state pg0 up")
+ def pg_create_interface4_name(self, ifname, local_ip, remote_ip, local_mac, remote_mac):
+ # remote_ip can't have subnet mask
+
+ time.sleep(2)
+ self.vppctl_exec("create packet-generator interface {}".format(ifname))
+ self.vppctl_exec("set int mac address {} {}".format(ifname, local_mac))
+ self.vppctl_exec("set int ip addr {} {}".format(ifname, local_ip))
+ self.vppctl_exec("set ip neighbor {} {} {}".format(ifname, remote_ip, remote_mac))
+ self.vppctl_exec("set int state {} up".format(ifname))
+
+ def pg_create_interface6_name(self, ifname, local_ip, remote_ip, local_mac, remote_mac):
+ # remote_ip can't have subnet mask
+
+ time.sleep(2)
+ self.vppctl_exec("create packet-generator interface {}".format(ifname))
+ self.vppctl_exec("set int mac address {} {}".format(ifname, local_mac))
+ self.vppctl_exec("set int ip addr {} {}".format(ifname, local_ip))
+ self.vppctl_exec("set ip neighbor {} {} {}".format(ifname, remote_ip, remote_mac))
+ self.vppctl_exec("set int state {} up".format(ifname))
+
def pg_enable(self):
# start packet generator
self.vppctl_exec("packet-generator enable")
@@ -176,6 +196,13 @@ class Container(object):
"packet-generator capture pg0 pcap {}".format(
self.pg_output_file_in))
+ def pg_start_capture_name(self, ifname):
+ if exists(self.pg_output_file):
+ remove(self.pg_output_file)
+ self.vppctl_exec(
+ "packet-generator capture {} pcap {}".format(
+ ifname, self.pg_output_file_in))
+
def pg_read_packets(self):
return rdpcap(self.pg_output_file)
@@ -184,6 +211,11 @@ class Container(object):
"ip route add {} via host-{} {}".format(
subnet, out_if_name, next_hop_ip))
+ def set_ipv6_route2(self, out_if_name, next_hop_ip, subnet):
+ self.vppctl_exec(
+ "ip route add {} via {} {}".format(
+ subnet, out_if_name, next_hop_ip))
+
def set_ip_pgroute(self, out_if_name, next_hop_ip, subnet):
self.vppctl_exec("ip route add {} via {} {}".format(
subnet, out_if_name, next_hop_ip))
@@ -1089,6 +1121,142 @@ class Program(object):
for p in c4.pg_read_packets():
p.show2()
+ def test_gtp4_reply(self):
+ # TESTS:
+ # trace add af-packet-input 10
+ # pg interface on c1 172.20.0.1
+ # pg interface on c4 B::1/120
+
+ self.start_containers()
+
+ c1 = self.containers.get(self.get_name(self.instance_names[0]))
+ c2 = self.containers.get(self.get_name(self.instance_names[1]))
+ c3 = self.containers.get(self.get_name(self.instance_names[2]))
+ c4 = self.containers.get(self.get_name(self.instance_names[-1]))
+
+ c1.pg_create_interface4(
+ local_ip="172.16.0.1/30",
+ remote_ip="172.16.0.2/30",
+ local_mac="aa:bb:cc:dd:ee:01",
+ remote_mac="aa:bb:cc:dd:ee:02")
+ c4.pg_create_interface4(
+ local_ip="1.0.0.2/30",
+ remote_ip="1.0.0.1",
+ local_mac="aa:bb:cc:dd:ee:11",
+ remote_mac="aa:bb:cc:dd:ee:22")
+
+ c1.vppctl_exec("set sr encaps source addr A1::1")
+ c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64 nhtype ipv4")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
+
+ c2.vppctl_exec("sr localsid address D2:: behavior end")
+
+ c3.vppctl_exec("sr localsid address D3:: behavior end")
+
+ c4.vppctl_exec(
+ "sr localsid prefix D4::/32 "
+ "behavior end.m.gtp4.e v4src_position 64")
+
+ c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
+ c2.set_ipv6_route("eth1", "A1::1", "C::/120")
+ c3.set_ipv6_route("eth2", "A3::2", "D4::/32")
+ c3.set_ipv6_route("eth1", "A2::1", "C::/120")
+ c4.set_ip_pgroute("pg0", "1.0.0.1", "172.20.0.1/32")
+
+ p = (Ether(src="aa:bb:cc:dd:ee:02", dst="aa:bb:cc:dd:ee:01") /
+ IP(src="172.20.0.2", dst="172.20.0.1") /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="echo_response", S=1, teid=200, seq=200))
+
+ print("Sending packet on {}:".format(c1.name))
+ p.show2()
+
+ c1.enable_trace(10)
+ c4.enable_trace(10)
+
+ c4.pg_start_capture()
+
+ c1.pg_create_stream(p)
+ c1.pg_enable()
+
+ # timeout (sleep) if needed
+ print("Sleeping")
+ time.sleep(5)
+
+ print("Receiving packet on {}:".format(c4.name))
+ for p in c4.pg_read_packets():
+ p.show2()
+
+ def test_gtp4_error(self):
+ # TESTS:
+ # trace add af-packet-input 10
+ # pg interface on c1 172.20.0.1
+ # pg interface on c4 B::1/120
+
+ self.start_containers()
+
+ c1 = self.containers.get(self.get_name(self.instance_names[0]))
+ c2 = self.containers.get(self.get_name(self.instance_names[1]))
+ c3 = self.containers.get(self.get_name(self.instance_names[2]))
+ c4 = self.containers.get(self.get_name(self.instance_names[-1]))
+
+ c1.pg_create_interface4(
+ local_ip="172.16.0.1/30",
+ remote_ip="172.16.0.2/30",
+ local_mac="aa:bb:cc:dd:ee:01",
+ remote_mac="aa:bb:cc:dd:ee:02")
+ c4.pg_create_interface4(
+ local_ip="1.0.0.2/30",
+ remote_ip="1.0.0.1",
+ local_mac="aa:bb:cc:dd:ee:11",
+ remote_mac="aa:bb:cc:dd:ee:22")
+
+ c1.vppctl_exec("set sr encaps source addr A1::1")
+ c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64 nhtype ipv4")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
+
+ c2.vppctl_exec("sr localsid address D2:: behavior end")
+
+ c3.vppctl_exec("sr localsid address D3:: behavior end")
+
+ c4.vppctl_exec(
+ "sr localsid prefix D4::/32 "
+ "behavior end.m.gtp4.e v4src_position 64")
+
+ c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
+ c2.set_ipv6_route("eth1", "A1::1", "C::/120")
+ c3.set_ipv6_route("eth2", "A3::2", "D4::/32")
+ c3.set_ipv6_route("eth1", "A2::1", "C::/120")
+ c4.set_ip_pgroute("pg0", "1.0.0.1", "172.20.0.1/32")
+
+ p = (Ether(src="aa:bb:cc:dd:ee:02", dst="aa:bb:cc:dd:ee:01") /
+ IP(src="172.20.0.2", dst="172.20.0.1") /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="error_indication", S=1, teid=200, seq=200)/
+ IE_TEIDI(TEIDI=65535)/IE_GSNAddress(address="1.1.1.1")/
+ IE_PrivateExtension(extention_value="z"))
+
+ print("Sending packet on {}:".format(c1.name))
+ p.show2()
+
+ c1.enable_trace(10)
+ c4.enable_trace(10)
+
+ c4.pg_start_capture()
+
+ c1.pg_create_stream(p)
+ c1.pg_enable()
+
+ # timeout (sleep) if needed
+ print("Sleeping")
+ time.sleep(5)
+
+ print("Receiving packet on {}:".format(c4.name))
+ for p in c4.pg_read_packets():
+ p.show2()
+
def test_gtp4_ipv6(self):
# TESTS:
# trace add af-packet-input 10
@@ -1452,6 +1620,154 @@ class Program(object):
for p in c4.pg_read_packets():
p.show2()
+ def test_gtp6_drop_in_reply(self):
+ # TESTS:
+ # trace add af-packet-input 10
+ # pg interface on c1 172.20.0.1
+ # pg interface on c4 B::1/120
+
+ self.start_containers()
+
+ print("Deleting the old containers...")
+ time.sleep(30)
+ print("Starting the new containers...")
+
+ c1 = self.containers.get(self.get_name(self.instance_names[0]))
+ c2 = self.containers.get(self.get_name(self.instance_names[1]))
+ c3 = self.containers.get(self.get_name(self.instance_names[2]))
+ c4 = self.containers.get(self.get_name(self.instance_names[-1]))
+
+ c1.pg_create_interface(
+ local_ip="C::1/120",
+ remote_ip="C::2",
+ local_mac="aa:bb:cc:dd:ee:01",
+ remote_mac="aa:bb:cc:dd:ee:02")
+ c4.pg_create_interface(
+ local_ip="B::1/120",
+ remote_ip="B::2",
+ local_mac="aa:bb:cc:dd:ee:11",
+ remote_mac="aa:bb:cc:dd:ee:22")
+
+ c1.vppctl_exec("set sr encaps source addr A1::1")
+ c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
+
+ c1.vppctl_exec(
+ "sr localsid prefix D::/64 behavior end.m.gtp6.d.di D4::/64")
+
+ c2.vppctl_exec("sr localsid address D2:: behavior end")
+
+ c3.vppctl_exec("sr localsid address D3:: behavior end")
+
+ c4.vppctl_exec("sr localsid prefix D4::/64 behavior end.m.gtp6.e")
+
+ c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
+ c2.set_ipv6_route("eth1", "A1::1", "C::/120")
+ c3.set_ipv6_route("eth2", "A3::2", "D4::/32")
+ c3.set_ipv6_route("eth1", "A2::1", "C::/120")
+ c4.set_ip_pgroute("pg0", "B::2", "D::2/128")
+
+ print("Waiting...")
+ time.sleep(30)
+
+ p = (Ether(src="aa:bb:cc:dd:ee:02", dst="aa:bb:cc:dd:ee:01") /
+ IPv6(src="C::2", dst="D::2") /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="echo_response", S=1, teid=200, seq=300))
+
+ print("Sending packet on {}:".format(c1.name))
+ p.show2()
+
+ c1.enable_trace(10)
+ c4.enable_trace(10)
+
+ c4.pg_start_capture()
+
+ c1.pg_create_stream(p)
+ c1.pg_enable()
+
+ # timeout (sleep) if needed
+ print("Sleeping")
+ time.sleep(5)
+
+ print("Receiving packet on {}:".format(c4.name))
+ for p in c4.pg_read_packets():
+ p.show2()
+
+ def test_gtp6_drop_in_error(self):
+ # TESTS:
+ # trace add af-packet-input 10
+ # pg interface on c1 172.20.0.1
+ # pg interface on c4 B::1/120
+
+ self.start_containers()
+
+ print("Deleting the old containers...")
+ time.sleep(30)
+ print("Starting the new containers...")
+
+ c1 = self.containers.get(self.get_name(self.instance_names[0]))
+ c2 = self.containers.get(self.get_name(self.instance_names[1]))
+ c3 = self.containers.get(self.get_name(self.instance_names[2]))
+ c4 = self.containers.get(self.get_name(self.instance_names[-1]))
+
+ c1.pg_create_interface(
+ local_ip="C::1/120",
+ remote_ip="C::2",
+ local_mac="aa:bb:cc:dd:ee:01",
+ remote_mac="aa:bb:cc:dd:ee:02")
+ c4.pg_create_interface(
+ local_ip="B::1/120",
+ remote_ip="B::2",
+ local_mac="aa:bb:cc:dd:ee:11",
+ remote_mac="aa:bb:cc:dd:ee:22")
+
+ c1.vppctl_exec("set sr encaps source addr A1::1")
+ c1.vppctl_exec("sr policy add bsid D4:: next D2:: next D3::")
+
+ c1.vppctl_exec(
+ "sr localsid prefix D::/64 behavior end.m.gtp6.d.di D4::/64")
+
+ c2.vppctl_exec("sr localsid address D2:: behavior end")
+
+ c3.vppctl_exec("sr localsid address D3:: behavior end")
+
+ c4.vppctl_exec("sr localsid prefix D4::/64 behavior end.m.gtp6.e")
+
+ c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
+ c2.set_ipv6_route("eth1", "A1::1", "C::/120")
+ c3.set_ipv6_route("eth2", "A3::2", "D4::/32")
+ c3.set_ipv6_route("eth1", "A2::1", "C::/120")
+ c4.set_ip_pgroute("pg0", "B::2", "D::2/128")
+
+ print("Waiting...")
+ time.sleep(30)
+
+ p = (Ether(src="aa:bb:cc:dd:ee:02", dst="aa:bb:cc:dd:ee:01") /
+ IPv6(src="C::2", dst="D::2") /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="error_indication", S=1, teid=200, seq=300)/
+ IE_TEIDI(TEIDI=65535)/IE_GSNAddress(address="1.1.1.1")/
+ IE_PrivateExtension(extention_value="z"))
+
+ print("Sending packet on {}:".format(c1.name))
+ p.show2()
+
+ c1.enable_trace(10)
+ c4.enable_trace(10)
+
+ c4.pg_start_capture()
+
+ c1.pg_create_stream(p)
+ c1.pg_enable()
+
+ # timeout (sleep) if needed
+ print("Sleeping")
+ time.sleep(5)
+
+ print("Receiving packet on {}:".format(c4.name))
+ for p in c4.pg_read_packets():
+ p.show2()
+
def test_gtp6_drop_in_ipv6(self):
# TESTS:
# trace add af-packet-input 10
@@ -1641,6 +1957,7 @@ class Program(object):
c3.vppctl_exec("sr localsid address D3:: behavior end")
+ c4.vppctl_exec("set ip neighbor pg0 1.0.0.1 aa:bb:cc:dd:ee:22")
c4.vppctl_exec("sr localsid prefix D4::/64 behavior end.dt4 2")
c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
@@ -1716,6 +2033,7 @@ class Program(object):
c3.vppctl_exec("sr localsid address D3:: behavior end")
+ c4.vppctl_exec("set ip neighbor pg0 1.0.0.1 aa:bb:cc:dd:ee:22")
c4.vppctl_exec("sr localsid prefix D4::/64 behavior end.dt4 2")
c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
@@ -1792,6 +2110,7 @@ class Program(object):
c3.vppctl_exec("sr localsid address D3:: behavior end")
+ c4.vppctl_exec("set ip neighbor pg0 B::2 aa:bb:cc:dd:ee:22")
c4.vppctl_exec("sr localsid prefix D4::/64 behavior end.dt6 2")
c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
@@ -1867,6 +2186,7 @@ class Program(object):
c3.vppctl_exec("sr localsid address D3:: behavior end")
+ c4.vppctl_exec("set ip neighbor pg0 B::2 aa:bb:cc:dd:ee:22")
c4.vppctl_exec("sr localsid prefix D4::/64 behavior end.dt6 2")
c2.set_ipv6_route("eth2", "A2::2", "D3::/128")
@@ -1905,6 +2225,133 @@ class Program(object):
for p in c4.pg_read_packets():
p.show2()
+ def test_gtp6_dt(self):
+ # TESTS:
+ # trace add af-packet-input 10
+ # pg interface on c1 172.20.0.1
+ # pg interface on c4 B::1/120
+
+ self.start_containers()
+
+ print("Deleting the old containers...")
+ time.sleep(30)
+ print("Starting the new containers...")
+
+ c1 = self.containers.get(self.get_name(self.instance_names[0]))
+
+ c1.pg_create_interface6_name(
+ ifname="pg0",
+ local_ip="C::1/120",
+ remote_ip="C::2",
+ local_mac="aa:bb:cc:dd:ee:01",
+ remote_mac="aa:bb:cc:dd:ee:02")
+
+ c1.pg_create_interface4_name(
+ ifname="pg1",
+ local_ip="1.0.0.2/30",
+ remote_ip="1.0.0.1",
+ local_mac="aa:bb:cc:dd:ee:11",
+ remote_mac="aa:bb:cc:dd:ee:22")
+
+ c1.vppctl_exec("set sr encaps source addr A1::1")
+
+ c1.vppctl_exec(
+ "sr localsid prefix D::/64 behavior end.m.gtp6.dt46 fib-table 0 local-fib-table 0")
+
+ c1.vppctl_exec("set ip neighbor pg1 1.0.0.1 aa:bb:cc:dd:ee:22")
+ c1.set_ip_pgroute("pg1", "1.0.0.1", "172.200.0.1/32")
+
+ print("Waiting...")
+ time.sleep(30)
+
+ p = (Ether(src="aa:bb:cc:dd:ee:02", dst="aa:bb:cc:dd:ee:01") /
+ IPv6(src="C::2", dst="D::2") /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="g_pdu", teid=200) /
+ IP(src="172.100.0.1", dst="172.200.0.1") /
+ ICMP())
+
+ print("Sending packet on {}:".format(c1.name))
+ p.show2()
+
+ c1.enable_trace(10)
+
+ c1.pg_start_capture_name(ifname="pg1")
+
+ c1.pg_create_stream(p)
+ c1.pg_enable()
+
+ # timeout (sleep) if needed
+ print("Sleeping")
+ time.sleep(5)
+
+ print("Receiving packet on {}:".format(c1.name))
+ for p in c1.pg_read_packets():
+ p.show2()
+
+ def test_gtp4_dt(self):
+ # TESTS:
+ # trace add af-packet-input 10
+ # pg interface on c1 172.20.0.1
+ # pg interface on c4 B::1/120
+
+ self.start_containers()
+
+ print("Deleting the old containers...")
+ time.sleep(30)
+ print("Starting the new containers...")
+
+ c1 = self.containers.get(self.get_name(self.instance_names[0]))
+
+ c1.pg_create_interface4_name(
+ ifname="pg0",
+ local_ip="172.16.0.1/30",
+ remote_ip="172.16.0.2",
+ local_mac="aa:bb:cc:dd:ee:01",
+ remote_mac="aa:bb:cc:dd:ee:02")
+
+ c1.pg_create_interface4_name(
+ ifname="pg1",
+ local_ip="1.0.0.2/30",
+ remote_ip="1.0.0.1",
+ local_mac="aa:bb:cc:dd:ee:11",
+ remote_mac="aa:bb:cc:dd:ee:22")
+
+ c1.vppctl_exec("set sr encaps source addr A1::1")
+ c1.vppctl_exec("sr policy add bsid D5:: behavior t.m.gtp4.dt4 fib-table 0")
+ c1.vppctl_exec("sr steer l3 172.20.0.1/32 via bsid D5::")
+
+ c1.vppctl_exec("set ip neighbor pg1 1.0.0.1 aa:bb:cc:dd:ee:22")
+ c1.set_ip_pgroute("pg1", "1.0.0.1", "172.200.0.1/32")
+
+ print("Waiting...")
+ time.sleep(30)
+
+ p = (Ether(src="aa:bb:cc:dd:ee:02", dst="aa:bb:cc:dd:ee:01") /
+ IP(src="172.20.0.2", dst="172.20.0.1") /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="g_pdu", teid=200) /
+ IP(src="172.100.0.1", dst="172.200.0.1") /
+ ICMP())
+
+ print("Sending packet on {}:".format(c1.name))
+ p.show2()
+
+ c1.enable_trace(10)
+
+ c1.pg_start_capture_name(ifname="pg1")
+
+ c1.pg_create_stream(p)
+ c1.pg_enable()
+
+ # timeout (sleep) if needed
+ print("Sleeping")
+ time.sleep(5)
+
+ print("Receiving packet on {}:".format(c1.name))
+ for p in c1.pg_read_packets():
+ p.show2()
+
def status_containers(self):
print("Instances:")
@@ -2008,17 +2455,23 @@ def get_args():
"gtp4_usid",
"gtp4_5g",
"gtp4_echo",
+ "gtp4_reply",
+ "gtp4_error",
"gtp4_ipv6",
"gtp4_ipv6_5g",
"gtp6_drop_in",
"gtp6_drop_in_5g",
"gtp6_drop_in_echo",
+ "gtp6_drop_in_reply",
+ "gtp6_drop_in_error",
"gtp6_drop_in_ipv6",
"gtp6_drop_in_ipv6_5g",
"gtp6",
"gtp6_5g",
"gtp6_ipv6",
- "gtp6_ipv6_5g"])
+ "gtp6_ipv6_5g",
+ "gtp6_dt",
+ "gtp4_dt"])
args = parser.parse_args()
if not hasattr(args, "op") or not args.op:
@@ -2038,7 +2491,7 @@ def main(op=None, prefix=None, verbose=None,
image = "srv6m-release-image"
elif image == 'debug':
image = "srv6m-image"
- else
+ else:
image = "srv6m-image"
print("Target image: {}".format(image))
@@ -2080,6 +2533,10 @@ def main(op=None, prefix=None, verbose=None,
program.test_gtp4_5g()
elif op == 'gtp4_echo':
program.test_gtp4_echo()
+ elif op == 'gtp4_reply':
+ program.test_gtp4_reply()
+ elif op == 'gtp4_error':
+ program.test_gtp4_error()
elif op == 'gtp4_ipv6':
program.test_gtp4_ipv6()
elif op == 'gtp4_ipv6_5g':
@@ -2090,6 +2547,10 @@ def main(op=None, prefix=None, verbose=None,
program.test_gtp6_drop_in_5g()
elif op == 'gtp6_drop_in_echo':
program.test_gtp6_drop_in_echo()
+ elif op == 'gtp6_drop_in_reply':
+ program.test_gtp6_drop_in_reply()
+ elif op == 'gtp6_drop_in_error':
+ program.test_gtp6_drop_in_error()
elif op == 'gtp6_drop_in_ipv6':
program.test_gtp6_drop_in_ipv6()
elif op == 'gtp6_drop_in_ipv6_5g':
@@ -2102,6 +2563,10 @@ def main(op=None, prefix=None, verbose=None,
program.test_gtp6_ipv6()
elif op == 'gtp6_ipv6_5g':
program.test_gtp6_ipv6_5g()
+ elif op == 'gtp6_dt':
+ program.test_gtp6_dt()
+ elif op == 'gtp4_dt':
+ program.test_gtp4_dt()
except Exception:
program.logger.exception("")
diff --git a/src/plugins/srv6-mobile/gtp4_dt.c b/src/plugins/srv6-mobile/gtp4_dt.c
new file mode 100644
index 00000000000..44a4af34c2f
--- /dev/null
+++ b/src/plugins/srv6-mobile/gtp4_dt.c
@@ -0,0 +1,205 @@
+/*
+ * srv6_t_m_gtp4_dt.c
+ *
+ * Copyright (c) 2019 Arrcus Inc and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vnet/vnet.h>
+#include <vnet/adj/adj.h>
+#include <vnet/fib/fib_table.h>
+#include <vnet/plugin/plugin.h>
+#include <vpp/app/version.h>
+#include <srv6-mobile/mobile.h>
+
+srv6_t_main_v4_dt_t srv6_t_main_v4_dt;
+
+static void
+clb_dpo_lock_srv6_t_m_gtp4_dt (dpo_id_t * dpo)
+{
+}
+
+static void
+clb_dpo_unlock_srv6_t_m_gtp4_dt (dpo_id_t * dpo)
+{
+}
+
+static u8 *
+clb_dpo_format_srv6_t_m_gtp4_dt (u8 * s, va_list * args)
+{
+ index_t index = va_arg (*args, index_t);
+ CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
+
+ return (format (s, "SR: dynamic_proxy_index:[%u]", index));
+}
+
+const static dpo_vft_t dpo_vft = {
+ .dv_lock = clb_dpo_lock_srv6_t_m_gtp4_dt,
+ .dv_unlock = clb_dpo_unlock_srv6_t_m_gtp4_dt,
+ .dv_format = clb_dpo_format_srv6_t_m_gtp4_dt,
+};
+
+const static char *const srv6_t_m_gtp4_dt_nodes[] = {
+ "srv6-t-m-gtp4-dt",
+ NULL,
+};
+
+const static char *const srv6_t_m_gtp4_dt_v6_nodes[] = {
+ "error-drop",
+ NULL,
+};
+
+const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
+ [DPO_PROTO_IP6] = srv6_t_m_gtp4_dt_v6_nodes,
+ [DPO_PROTO_IP4] = srv6_t_m_gtp4_dt_nodes,
+};
+
+static u8 fn_name[] = "SRv6-T.M.GTP4.DT-plugin";
+static u8 keyword_str[] = "t.m.gtp4.dt";
+static u8 def_str[] = "Transit function with DT for IPv4/GTP tunnel";
+static u8 param_str[] = "fib-index <index> [local-fib-table <index>]";
+
+static u8 *
+clb_format_srv6_t_m_gtp4_dt (u8 * s, va_list * args)
+{
+ srv6_t_gtp4_dt_param_t *ls_mem = va_arg (*args, void *);
+
+ s = format (s, "SRv6 Transit gtp4.dt\n\t");
+
+ if (ls_mem->type == SRV6_GTP4_DT4)
+ s = format (s, " Type GTP4.DT4 fib-table %u\n", ls_mem->fib4_index);
+ else if (ls_mem->type == SRV6_GTP4_DT6)
+ s = format (s, " Type GTP4.DT6, fib-table %u, local-fib-table %u\n",
+ ls_mem->fib6_index, ls_mem->local_fib_index);
+ else if (ls_mem->type == SRV6_GTP4_DT46)
+ s = format (s, " Type GTP4.DT46, fib-table %u, local-fib-table %u\n",
+ ls_mem->fib6_index, ls_mem->local_fib_index);
+ else
+ s = format (s, "\n");
+
+ return s;
+}
+
+static uword
+clb_unformat_srv6_t_m_gtp4_dt (unformat_input_t * input, va_list * args)
+{
+ void **plugin_mem_p = va_arg (*args, void **);
+ srv6_t_gtp4_dt_param_t *ls_mem;
+ u32 fib_index = 0;
+ u32 local_fib_index = 0;
+ u32 type;
+
+ if (unformat (input, "t.m.gtp4.dt4 fib-table %u", &fib_index))
+ {
+ type = SRV6_GTP4_DT4;
+ }
+ else if (unformat (input, "t.m.gtp4.dt6 fib-table %u local-fib-table %u",
+ &fib_index, &local_fib_index))
+ {
+ type = SRV6_GTP4_DT6;
+ }
+ else if (unformat (input, "t.m.gtp4.dt46 fib-table %u local-fib-table %u",
+ &fib_index, &local_fib_index))
+ {
+ type = SRV6_GTP4_DT46;
+ }
+ else
+ {
+ return 0;
+ }
+
+ ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
+ clib_memset (ls_mem, 0, sizeof *ls_mem);
+ *plugin_mem_p = ls_mem;
+
+ ls_mem->fib4_index = fib_table_find (FIB_PROTOCOL_IP4, fib_index);
+ ls_mem->fib6_index = fib_table_find (FIB_PROTOCOL_IP6, fib_index);
+
+ if (type == SRV6_GTP4_DT6 || type == SRV6_GTP4_DT46)
+ {
+ ls_mem->local_fib_index =
+ fib_table_find (FIB_PROTOCOL_IP6, local_fib_index);
+ }
+
+ ls_mem->type = type;
+
+ return 1;
+}
+
+static int
+clb_creation_srv6_t_m_gtp4_dt (ip6_sr_policy_t * sr_policy)
+{
+ return 0;
+}
+
+static int
+clb_removal_srv6_t_m_gtp4_dt (ip6_sr_policy_t * sr_policy)
+{
+ srv6_t_gtp4_dt_param_t *ls_mem;
+
+ ls_mem = (srv6_t_gtp4_dt_param_t *) sr_policy->plugin_mem;
+
+ clib_mem_free (ls_mem);
+
+ return 0;
+}
+
+static clib_error_t *
+srv6_t_m_gtp4_dt_init (vlib_main_t * vm)
+{
+ srv6_t_main_v4_dt_t *sm = &srv6_t_main_v4_dt;
+ dpo_type_t dpo_type;
+ vlib_node_t *node;
+ int rc;
+
+ sm->vlib_main = vm;
+ sm->vnet_main = vnet_get_main ();
+
+ node = vlib_get_node_by_name (vm, (u8 *) "srv6-t-m-gtp4-dt");
+ sm->t_m_gtp4_dt_node_index = node->index;
+
+ node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
+ sm->error_node_index = node->index;
+
+ dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
+
+ rc = sr_policy_register_function (vm, fn_name, keyword_str, def_str, param_str, 128, //prefix len
+ &dpo_type,
+ clb_format_srv6_t_m_gtp4_dt,
+ clb_unformat_srv6_t_m_gtp4_dt,
+ clb_creation_srv6_t_m_gtp4_dt,
+ clb_removal_srv6_t_m_gtp4_dt);
+ if (rc < 0)
+ clib_error_return (0, "SRv6 Transit GTP4.DT Policy function"
+ "couldn't be registered");
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VNET_FEATURE_INIT (srv6_t_m_gtp4_dt, static) =
+{
+ .arc_name = "ip4-unicast",
+ .node_name = "srv6-t-m-gtp4-dt",
+ .runs_before = 0,
+};
+
+VLIB_INIT_FUNCTION (srv6_t_m_gtp4_dt_init);
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/srv6-mobile/gtp6_dt.c b/src/plugins/srv6-mobile/gtp6_dt.c
new file mode 100644
index 00000000000..cbd2327cc47
--- /dev/null
+++ b/src/plugins/srv6-mobile/gtp6_dt.c
@@ -0,0 +1,199 @@
+/*
+ * srv6_end_m_gtp6_dt.c
+ *
+ * Copyright (c) 2019 Arrcus Inc and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <vnet/vnet.h>
+#include <vnet/adj/adj.h>
+#include <vnet/fib/fib_table.h>
+#include <vnet/plugin/plugin.h>
+#include <vpp/app/version.h>
+#include <srv6-mobile/mobile.h>
+
+srv6_end_main_v6_dt_t srv6_end_main_v6_dt;
+
+static void
+clb_dpo_lock_srv6_end_m_gtp6_dt (dpo_id_t * dpo)
+{
+}
+
+static void
+clb_dpo_unlock_srv6_end_m_gtp6_dt (dpo_id_t * dpo)
+{
+}
+
+static u8 *
+clb_dpo_format_srv6_end_m_gtp6_dt (u8 * s, va_list * args)
+{
+ index_t index = va_arg (*args, index_t);
+ CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
+
+ return (format (s, "SR: dynamic_proxy_index:[%u]", index));
+}
+
+const static dpo_vft_t dpo_vft = {
+ .dv_lock = clb_dpo_lock_srv6_end_m_gtp6_dt,
+ .dv_unlock = clb_dpo_unlock_srv6_end_m_gtp6_dt,
+ .dv_format = clb_dpo_format_srv6_end_m_gtp6_dt,
+};
+
+const static char *const srv6_end_m_gtp6_dt_nodes[] = {
+ "srv6-end-m-gtp6-dt",
+ NULL,
+};
+
+const static char *const *const dpo_nodes[DPO_PROTO_NUM] = {
+ [DPO_PROTO_IP6] = srv6_end_m_gtp6_dt_nodes,
+};
+
+static u8 fn_name[] = "SRv6-End.M.GTP6.DT-plugin";
+static u8 keyword_str[] = "end.m.gtp6.dt";
+static u8 def_str[] = "Endpoint function with DT for IPv6/GTP tunnel";
+static u8 param_str[] = "fib-index <index> [local-fib-table <index>]";
+
+static u8 *
+clb_format_srv6_end_m_gtp6_dt (u8 * s, va_list * args)
+{
+ srv6_end_gtp6_dt_param_t *ls_mem = va_arg (*args, void *);
+
+ s = format (s, "SRv6 End gtp6.dt\n\t");
+
+ if (ls_mem->type == SRV6_GTP6_DT4)
+ s = format (s, " Type GTP6.DT4 fib-table %u\n", ls_mem->fib4_index);
+ else if (ls_mem->type == SRV6_GTP6_DT6)
+ s = format (s, " Type GTP6.DT6, fib-table %u, local-fib-table %u\n",
+ ls_mem->fib6_index, ls_mem->local_fib_index);
+ else if (ls_mem->type == SRV6_GTP6_DT46)
+ s = format (s, " Type GTP6.DT46, fib-table %u, local-fib-table %u\n",
+ ls_mem->fib6_index, ls_mem->local_fib_index);
+ else
+ s = format (s, "\n");
+
+ return s;
+}
+
+static uword
+clb_unformat_srv6_end_m_gtp6_dt (unformat_input_t * input, va_list * args)
+{
+ void **plugin_mem_p = va_arg (*args, void **);
+ srv6_end_gtp6_dt_param_t *ls_mem;
+ u32 fib_index = 0;
+ u32 local_fib_index = 0;
+ u32 type;
+
+ if (unformat (input, "end.m.gtp6.dt4 fib-table %u", &fib_index))
+ {
+ type = SRV6_GTP6_DT4;
+ }
+ else if (unformat (input, "end.m.gtp6.dt6 fib-table %u local-fib-table %u",
+ &fib_index, &local_fib_index))
+ {
+ type = SRV6_GTP6_DT6;
+ }
+ else if (unformat (input, "end.m.gtp6.dt46 fib-table %u local-fib-table %u",
+ &fib_index, &local_fib_index))
+ {
+ type = SRV6_GTP6_DT46;
+ }
+ else
+ {
+ return 0;
+ }
+
+ ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
+ clib_memset (ls_mem, 0, sizeof *ls_mem);
+ *plugin_mem_p = ls_mem;
+
+ ls_mem->fib4_index = fib_table_find (FIB_PROTOCOL_IP4, fib_index);
+ ls_mem->fib6_index = fib_table_find (FIB_PROTOCOL_IP6, fib_index);
+
+ if (type == SRV6_GTP6_DT6 || type == SRV6_GTP6_DT46)
+ {
+ ls_mem->local_fib_index =
+ fib_table_find (FIB_PROTOCOL_IP6, local_fib_index);
+ }
+
+ ls_mem->type = type;
+
+ return 1;
+}
+
+static int
+clb_creation_srv6_end_m_gtp6_dt (ip6_sr_localsid_t * localsid)
+{
+ return 0;
+}
+
+static int
+clb_removal_srv6_end_m_gtp6_dt (ip6_sr_localsid_t * localsid)
+{
+ srv6_end_gtp6_dt_param_t *ls_mem;
+
+ ls_mem = localsid->plugin_mem;
+
+ clib_mem_free (ls_mem);
+
+ return 0;
+}
+
+static clib_error_t *
+srv6_end_m_gtp6_dt_init (vlib_main_t * vm)
+{
+ srv6_end_main_v6_dt_t *sm = &srv6_end_main_v6_dt;
+ dpo_type_t dpo_type;
+ vlib_node_t *node;
+ int rc;
+
+ sm->vlib_main = vm;
+ sm->vnet_main = vnet_get_main ();
+
+ node = vlib_get_node_by_name (vm, (u8 *) "srv6-end-m-gtp6-dt");
+ sm->end_m_gtp6_dt_node_index = node->index;
+
+ node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
+ sm->error_node_index = node->index;
+
+ dpo_type = dpo_register_new_type (&dpo_vft, dpo_nodes);
+
+ rc = sr_localsid_register_function (vm, fn_name, keyword_str, def_str, param_str, 128, //prefix len
+ &dpo_type,
+ clb_format_srv6_end_m_gtp6_dt,
+ clb_unformat_srv6_end_m_gtp6_dt,
+ clb_creation_srv6_end_m_gtp6_dt,
+ clb_removal_srv6_end_m_gtp6_dt);
+ if (rc < 0)
+ clib_error_return (0, "SRv6 Endpoint GTP6.DT LocalSID function"
+ "couldn't be registered");
+ return 0;
+}
+
+/* *INDENT-OFF* */
+VNET_FEATURE_INIT (srv6_end_m_gtp6_dt, static) =
+{
+ .arc_name = "ip6-unicast",
+ .node_name = "srv6-end-m-gtp6-dt",
+ .runs_before = 0,
+};
+
+VLIB_INIT_FUNCTION (srv6_end_m_gtp6_dt_init);
+/* *INDENT-ON* */
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/plugins/srv6-mobile/mobile.h b/src/plugins/srv6-mobile/mobile.h
index 460cbe17ef1..517e7c8f84c 100644
--- a/src/plugins/srv6-mobile/mobile.h
+++ b/src/plugins/srv6-mobile/mobile.h
@@ -42,6 +42,11 @@
#define SRV6_GTP6_DT6 2
#define SRV6_GTP6_DT46 3
+#define SRV6_GTP4_UNKNOW 0
+#define SRV6_GTP4_DT4 1
+#define SRV6_GTP4_DT6 2
+#define SRV6_GTP4_DT46 3
+
#if __BYTE_ORDER__ == __ORDER_BIG_ENDIAN__
#define BITALIGN2(A,B) A; B
#define BITALIGN3(A,B,C) A; B; C
@@ -59,6 +64,19 @@
#define SRH_TAG_ERROR_INDICATION 0x0002
#define SRH_TAG_END_MARKER 0x0001
+#define GTPU_RECOVERY_IE_TYPE 0x0e
+
+#define GTPU_IE_MAX_SIZ 256
+#define SRH_TLV_USER_PLANE_CONTAINER 0x0a /* tentative */
+
+/* *INDENT-OFF* */
+typedef struct
+{
+ u8 type;
+ u8 restart_counter;
+} __attribute__ ((packed)) gtpu_recovery_ie;
+/* *INDENT-ON* */
+
/* *INDENT-OFF* */
typedef struct
{
@@ -145,6 +163,17 @@ typedef struct
#define GTPU_PT_GTP (1<<4)
+/* *INDENT-OFF* */
+typedef struct
+{
+ u8 type;
+ u8 length;
+ u8 value[0];
+} __attribute__ ((packed)) user_plane_sub_tlv_t;
+/* *INDENT-ON* */
+
+#define USER_PLANE_SUB_TLV_IE 0x01
+
typedef struct srv6_end_gtp6_param_s
{
u8 nhtype;
@@ -153,6 +182,24 @@ typedef struct srv6_end_gtp6_param_s
u32 sr_prefixlen;
} srv6_end_gtp6_param_t;
+typedef struct srv6_end_gtp6_dt_param_s
+{
+ u8 type;
+
+ u32 fib4_index;
+ u32 fib6_index;
+ u32 local_fib_index;
+} srv6_end_gtp6_dt_param_t;
+
+typedef struct srv6_t_gtp4_dt_param_s
+{
+ u8 type;
+
+ u32 fib4_index;
+ u32 fib6_index;
+ u32 local_fib_index;
+} srv6_t_gtp4_dt_param_t;
+
typedef struct srv6_end_gtp4_param_s
{
u8 nhtype;
@@ -238,6 +285,30 @@ typedef struct srv6_end_main_v6_decap_di_s
extern srv6_end_main_v6_decap_di_t srv6_end_main_v6_decap_di;
extern vlib_node_registration_t srv6_end_m_gtp6_d_di;
+typedef struct srv6_end_main_v6_dt_s
+{
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
+
+ u32 end_m_gtp6_dt_node_index;
+ u32 error_node_index;
+} srv6_end_main_v6_dt_t;
+
+extern srv6_end_main_v6_dt_t srv6_end_main_v6_dt;
+extern vlib_node_registration_t srv6_end_m_gtp6_dt;
+
+typedef struct srv6_t_main_v4_dt_s
+{
+ vlib_main_t *vlib_main;
+ vnet_main_t *vnet_main;
+
+ u32 t_m_gtp4_dt_node_index;
+ u32 error_node_index;
+} srv6_t_main_v4_dt_t;
+
+extern srv6_t_main_v4_dt_t srv6_t_main_v4_dt;
+extern vlib_node_registration_t srv6_t_m_gtp4_dt;
+
#endif /* __included_srv6_end_h__ */
/*
diff --git a/src/plugins/srv6-mobile/node.c b/src/plugins/srv6-mobile/node.c
index 6eafefd3f5b..6d3240e77c4 100644
--- a/src/plugins/srv6-mobile/node.c
+++ b/src/plugins/srv6-mobile/node.c
@@ -129,6 +129,14 @@ format_srv6_end_rewrite_trace6 (u8 * s, va_list * args)
_(M_GTP6_D_DI_PACKETS, "srv6 End.M.GTP6.D.DI packets") \
_(M_GTP6_D_DI_BAD_PACKETS, "srv6 End.M.GTP6.D.DI bad packets")
+#define foreach_srv6_end_v6_dt_error \
+ _(M_GTP6_DT_PACKETS, "srv6 End.M.GTP6.DT packets") \
+ _(M_GTP6_DT_BAD_PACKETS, "srv6 End.M.GTP6.DT bad packets")
+
+#define foreach_srv6_t_v4_dt_error \
+ _(M_GTP4_DT_PACKETS, "srv6 T.M.GTP4.DT packets") \
+ _(M_GTP4_DT_BAD_PACKETS, "srv6 T.M.GTP4.DT bad packets")
+
typedef enum
{
#define _(sym,str) SRV6_END_ERROR_##sym,
@@ -169,6 +177,22 @@ typedef enum
SRV6_END_N_V6_D_DI_ERROR,
} srv6_end_error_v6_d_di_t;
+typedef enum
+{
+#define _(sym,str) SRV6_END_ERROR_##sym,
+ foreach_srv6_end_v6_dt_error
+#undef _
+ SRV6_END_N_V6_DT_ERROR,
+} srv6_end_error_v6_dt_t;
+
+typedef enum
+{
+#define _(sym,str) SRV6_T_ERROR_##sym,
+ foreach_srv6_t_v4_dt_error
+#undef _
+ SRV6_T_N_V4_DT_ERROR,
+} srv6_t_error_v4_dt_t;
+
static char *srv6_end_error_v4_strings[] = {
#define _(sym,string) string,
foreach_srv6_end_v4_error
@@ -199,6 +223,18 @@ static char *srv6_end_error_v6_d_di_strings[] = {
#undef _
};
+static char *srv6_end_error_v6_dt_strings[] = {
+#define _(sym,string) string,
+ foreach_srv6_end_v6_dt_error
+#undef _
+};
+
+static char *srv6_t_error_v4_dt_strings[] = {
+#define _(sym,string) string,
+ foreach_srv6_t_v4_dt_error
+#undef _
+};
+
typedef enum
{
SRV6_END_M_GTP4_E_NEXT_DROP,
@@ -234,6 +270,22 @@ typedef enum
SRV6_END_M_GTP6_D_DI_N_NEXT,
} srv6_end_m_gtp6_d_di_next_t;
+typedef enum
+{
+ SRV6_END_M_GTP6_DT_NEXT_DROP,
+ SRV6_END_M_GTP6_DT_NEXT_LOOKUP4,
+ SRV6_END_M_GTP6_DT_NEXT_LOOKUP6,
+ SRV6_END_M_GTP6_DT_N_NEXT,
+} srv6_end_m_gtp6_dt_next_t;
+
+typedef enum
+{
+ SRV6_T_M_GTP4_DT_NEXT_DROP,
+ SRV6_T_M_GTP4_DT_NEXT_LOOKUP4,
+ SRV6_T_M_GTP4_DT_NEXT_LOOKUP6,
+ SRV6_T_M_GTP4_DT_N_NEXT,
+} srv6_t_m_gtp4_dt_next_t;
+
static inline u16
hash_uword_to_u16 (uword * key)
{
@@ -345,33 +397,16 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
uword key;
u16 port;
ip4_address_t dst4;
+ u16 ie_size = 0;
+ u8 ie_buf[GTPU_IE_MAX_SIZ];
void *p;
+ uword plen;
- // we need to be sure there is enough space before
- // ip6srv0 header, there is some extra space
- // in the pre_data area for this kind of
- // logic
-
- // jump over variable length data
- // not sure about the length
if (ip6srv0->ip.protocol == IPPROTO_IPV6_ROUTE)
{
tag = ip6srv0->sr.tag;
-
- vlib_buffer_advance (b0,
- (word) sizeof (ip6srv_combo_header_t) +
- ip6srv0->sr.length * 8);
- }
- else
- {
- vlib_buffer_advance (b0, (word) sizeof (ip6_header_t));
}
- // get length of encapsulated IPv6 packet (the remaining part)
- p = vlib_buffer_get_current (b0);
-
- len0 = vlib_buffer_length_in_chain (vm, b0);
-
offset = ls0->localsid_prefix_len / 8;
shift = ls0->localsid_prefix_len % 8;
@@ -443,6 +478,58 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
{
hdrlen = sizeof (gtpu_exthdr_t);
}
+
+ if (PREDICT_FALSE (gtpu_type == GTPU_TYPE_ECHO_REPLY))
+ {
+ hdrlen += sizeof (gtpu_recovery_ie);
+ }
+
+ if (PREDICT_FALSE (gtpu_type == GTPU_TYPE_ERROR_INDICATION))
+ {
+ ip6_sr_tlv_t *tlv;
+ u16 ext_len;
+
+ ext_len = ip6srv0->sr.length * 8;
+
+ if (ext_len >
+ sizeof (ip6_address_t) * (ip6srv0->sr.last_entry + 1))
+ {
+ tlv =
+ (ip6_sr_tlv_t *) ((u8 *) & ip6srv0->sr +
+ sizeof (ip6_sr_header_t) +
+ sizeof (ip6_address_t) *
+ (ip6srv0->sr.last_entry + 1));
+
+ if (tlv->type == SRH_TLV_USER_PLANE_CONTAINER)
+ {
+ user_plane_sub_tlv_t *sub_tlv;
+
+ sub_tlv = (user_plane_sub_tlv_t *) tlv->value;
+
+ ie_size = sub_tlv->length;
+ clib_memcpy_fast (ie_buf, sub_tlv->value, ie_size);
+
+ hdrlen += ie_size;
+ }
+ }
+ }
+
+ if (ip6srv0->ip.protocol == IPPROTO_IPV6_ROUTE)
+ {
+ vlib_buffer_advance (b0,
+ (word) sizeof (ip6srv_combo_header_t) +
+ ip6srv0->sr.length * 8);
+ }
+ else
+ {
+ vlib_buffer_advance (b0, (word) sizeof (ip6_header_t));
+ }
+
+ // get length of encapsulated IPv6 packet (the remaining part)
+ p = vlib_buffer_get_current (b0);
+
+ plen = len0 = vlib_buffer_length_in_chain (vm, b0);
+
len0 += hdrlen;
hdrlen += sizeof (ip4_gtpu_header_t);
@@ -499,6 +586,28 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
hdr0->gtpu.ext->seq = seq;
hdr0->gtpu.ext->npdu_num = 0;
hdr0->gtpu.ext->nextexthdr = 0;
+
+ if (gtpu_type == GTPU_TYPE_ECHO_REPLY)
+ {
+ gtpu_recovery_ie *recovery;
+
+ recovery =
+ (gtpu_recovery_ie *) ((u8 *) hdr0 +
+ (hdrlen -
+ sizeof (gtpu_recovery_ie)));
+ recovery->type = GTPU_RECOVERY_IE_TYPE;
+ recovery->restart_counter = 0;
+ }
+ else if (gtpu_type == GTPU_TYPE_ERROR_INDICATION)
+ {
+ if (ie_size)
+ {
+ u8 *ie_ptr;
+
+ ie_ptr = (u8 *) ((u8 *) hdr0 + (hdrlen - ie_size));
+ clib_memcpy_fast (ie_ptr, ie_buf, ie_size);
+ }
+ }
}
offset = ls_param->v4src_position / 8;
@@ -523,7 +632,7 @@ VLIB_NODE_FN (srv6_end_m_gtp4_e) (vlib_main_t * vm,
}
}
- key = hash_memory (p, len0, 0);
+ key = hash_memory (p, plen < 40 ? plen : 40, 0);
port = hash_uword_to_u16 (&key);
hdr0->udp.src_port = port;
@@ -659,6 +768,9 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm,
u32 offset, shift, index;
ip6srv_combo_header_t *ip6srv;
gtpu_pdu_session_t *sess = NULL;
+ u16 ie_size = 0;
+ u16 tlv_siz = 0;
+ u8 ie_buf[GTPU_IE_MAX_SIZ];
// Decap from GTP-U.
hdr = (ip4_gtpu_header_t *) ip4;
@@ -784,6 +896,24 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm,
}
}
+ if (PREDICT_FALSE (gtpu_type == GTPU_TYPE_ERROR_INDICATION))
+ {
+ u16 payload_len;
+
+ payload_len = clib_net_to_host_u16 (hdr->gtpu.length);
+ if (payload_len != 0
+ && payload_len > hdr_len - sizeof (ip4_gtpu_header_t))
+ {
+ u8 *ies;
+
+ ies = (u8 *) ((u8 *) hdr + hdr_len);
+ ie_size =
+ payload_len - (hdr_len - sizeof (ip4_gtpu_header_t));
+ clib_memcpy_fast (ie_buf, ies, ie_size);
+ hdr_len += ie_size;
+ }
+ }
+
src6 = ls_param->v6src_prefix;
offset = ls_param->v6src_prefixlen / 8;
@@ -848,6 +978,16 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm,
}
}
+ if (ie_size)
+ {
+ tlv_siz =
+ sizeof (ip6_sr_tlv_t) + sizeof (user_plane_sub_tlv_t) +
+ ie_size;
+
+ tlv_siz = (tlv_siz & ~0x07) + (tlv_siz & 0x07 ? 0x08 : 0x0);
+ hdr_len += tlv_siz;
+ }
+
vlib_buffer_advance (b0, -(word) hdr_len);
ip6srv = vlib_buffer_get_current (b0);
@@ -1015,6 +1155,25 @@ VLIB_NODE_FN (srv6_t_m_gtp4_d) (vlib_main_t * vm,
ip6srv->ip.src_address = src6;
+ if (PREDICT_FALSE (ie_size))
+ {
+ ip6_sr_tlv_t *tlv;
+ user_plane_sub_tlv_t *sub_tlv;
+
+ tlv =
+ (ip6_sr_tlv_t *) ((u8 *) ip6srv + (hdr_len - tlv_siz));
+ tlv->type = SRH_TLV_USER_PLANE_CONTAINER;
+ tlv->length = tlv_siz - sizeof (ip6_sr_tlv_t);
+ clib_memset (tlv->value, 0, tlv->length);
+
+ sub_tlv = (user_plane_sub_tlv_t *) tlv->value;
+ sub_tlv->type = USER_PLANE_SUB_TLV_IE;
+ sub_tlv->length = ie_size;
+ clib_memcpy_fast (sub_tlv->value, ie_buf, ie_size);
+
+ ip6srv->sr.length += tlv_siz / 8;
+ }
+
ip6srv->ip.payload_length =
clib_host_to_net_u16 (len0 + hdr_len - sizeof (ip6_header_t));
@@ -1057,8 +1216,8 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp4_e) =
srv6_end_error_v4_strings,.n_next_nodes =
SRV6_END_M_GTP4_E_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP4_E_NEXT_DROP] = "error-drop",
- [SRV6_END_M_GTP4_E_NEXT_LOOKUP] = "ip4-lookup",}
+ [SRV6_END_M_GTP4_E_NEXT_DROP] =
+ "error-drop",[SRV6_END_M_GTP4_E_NEXT_LOOKUP] = "ip4-lookup",}
,};
VLIB_REGISTER_NODE (srv6_t_m_gtp4_d) =
@@ -1069,8 +1228,8 @@ VLIB_REGISTER_NODE (srv6_t_m_gtp4_d) =
srv6_t_error_v4_d_strings,.n_next_nodes =
SRV6_T_M_GTP4_D_N_NEXT,.next_nodes =
{
- [SRV6_T_M_GTP4_D_NEXT_DROP] = "error-drop",
- [SRV6_T_M_GTP4_D_NEXT_LOOKUP] = "ip6-lookup",}
+ [SRV6_T_M_GTP4_D_NEXT_DROP] =
+ "error-drop",[SRV6_T_M_GTP4_D_NEXT_LOOKUP] = "ip6-lookup",}
,};
// Function for SRv6 GTP6.E function
@@ -1110,6 +1269,7 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm,
u16 port;
u16 tag;
void *p;
+ uword plen;
u32 next0 = SRV6_END_M_GTP6_E_NEXT_LOOKUP;
@@ -1150,16 +1310,6 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm,
// in the pre_data area for this kind of
// logic
- // jump over variable length data
- // not sure about the length
- vlib_buffer_advance (b0, (word) sizeof (ip6srv_combo_header_t) +
- ip6srv0->sr.length * 8);
-
- // get length of encapsulated IPv6 packet (the remaining part)
- p = vlib_buffer_get_current (b0);
-
- len0 = vlib_buffer_length_in_chain (vm, b0);
-
u32 teid = 0;
u8 *teid8p = (u8 *) & teid;
u8 qfi = 0;
@@ -1168,6 +1318,8 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm,
u16 index;
u16 offset, shift;
u32 hdrlen = 0;
+ u16 ie_size = 0;
+ u8 ie_buf[GTPU_IE_MAX_SIZ];
index = ls0->localsid_prefix_len;
index += 8;
@@ -1234,7 +1386,52 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm,
hdrlen = sizeof (gtpu_exthdr_t);
}
+ if (gtpu_type == GTPU_TYPE_ECHO_REPLY)
+ {
+ hdrlen += sizeof (gtpu_recovery_ie);
+ }
+
+ if (PREDICT_FALSE (gtpu_type == GTPU_TYPE_ERROR_INDICATION))
+ {
+ ip6_sr_tlv_t *tlv;
+ u16 ext_len;
+
+ ext_len = ip6srv0->sr.length * 8;
+
+ if (ext_len >
+ sizeof (ip6_address_t) * (ip6srv0->sr.last_entry + 1))
+ {
+ tlv =
+ (ip6_sr_tlv_t *) ((u8 *) & ip6srv0->sr +
+ sizeof (ip6_sr_header_t) +
+ sizeof (ip6_address_t) *
+ (ip6srv0->sr.last_entry + 1));
+
+ if (tlv->type == SRH_TLV_USER_PLANE_CONTAINER)
+ {
+ user_plane_sub_tlv_t *sub_tlv;
+
+ sub_tlv = (user_plane_sub_tlv_t *) tlv->value;
+
+ ie_size = sub_tlv->length;
+ clib_memcpy_fast (ie_buf, sub_tlv->value, ie_size);
+
+ hdrlen += ie_size;
+ }
+ }
+ }
+
+ vlib_buffer_advance (b0,
+ (word) sizeof (ip6srv_combo_header_t) +
+ ip6srv0->sr.length * 8);
+
+ // get length of encapsulated IPv6 packet (the remaining part)
+ p = vlib_buffer_get_current (b0);
+
+ plen = len0 = vlib_buffer_length_in_chain (vm, b0);
+
len0 += hdrlen;
+
hdrlen += sizeof (ip6_gtpu_header_t);
vlib_buffer_advance (b0, -(word) hdrlen);
@@ -1285,6 +1482,28 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm,
hdr0->gtpu.ext->seq = seq;
hdr0->gtpu.ext->npdu_num = 0;
hdr0->gtpu.ext->nextexthdr = 0;
+
+ if (gtpu_type == GTPU_TYPE_ECHO_REPLY)
+ {
+ gtpu_recovery_ie *recovery;
+
+ recovery =
+ (gtpu_recovery_ie *) ((u8 *) hdr0 +
+ (hdrlen -
+ sizeof (gtpu_recovery_ie)));
+ recovery->type = GTPU_RECOVERY_IE_TYPE;
+ recovery->restart_counter = 0;
+ }
+ else if (gtpu_type == GTPU_TYPE_ERROR_INDICATION)
+ {
+ if (ie_size)
+ {
+ u8 *ie_ptr;
+
+ ie_ptr = (u8 *) ((u8 *) hdr0 + (hdrlen - ie_size));
+ clib_memcpy_fast (ie_ptr, ie_buf, ie_size);
+ }
+ }
}
hdr0->udp.length = clib_host_to_net_u16 (len0 +
@@ -1305,7 +1524,7 @@ VLIB_NODE_FN (srv6_end_m_gtp6_e) (vlib_main_t * vm,
(gtpu_header_t));
// UDP source port.
- key = hash_memory (p, len0, 0);
+ key = hash_memory (p, plen < 40 ? plen : 40, 0);
port = hash_uword_to_u16 (&key);
hdr0->udp.src_port = port;
@@ -1390,6 +1609,9 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm,
u32 hdrlen;
ip6_header_t *encap = NULL;
gtpu_pdu_session_t *sess = NULL;
+ u16 ie_size = 0;
+ u16 tlv_siz = 0;
+ u8 ie_buf[GTPU_IE_MAX_SIZ];
u32 next0 = SRV6_END_M_GTP6_D_NEXT_LOOKUP;
@@ -1533,6 +1755,24 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm,
}
}
+ if (PREDICT_FALSE (gtpu_type == GTPU_TYPE_ERROR_INDICATION))
+ {
+ u16 payload_len;
+
+ payload_len = clib_net_to_host_u16 (hdr0->gtpu.length);
+ if (payload_len != 0
+ && payload_len > hdrlen - sizeof (ip6_gtpu_header_t))
+ {
+ u8 *ies;
+
+ ies = (u8 *) ((u8 *) hdr0 + hdrlen);
+ ie_size =
+ payload_len - (hdrlen - sizeof (ip6_gtpu_header_t));
+ clib_memcpy_fast (ie_buf, ies, ie_size);
+ hdrlen += ie_size;
+ }
+ }
+
// jump over variable length data
vlib_buffer_advance (b0, (word) hdrlen);
@@ -1585,6 +1825,16 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm,
}
}
+ if (ie_size)
+ {
+ tlv_siz =
+ sizeof (ip6_sr_tlv_t) + sizeof (user_plane_sub_tlv_t) +
+ ie_size;
+
+ tlv_siz = (tlv_siz & ~0x07) + (tlv_siz & 0x07 ? 0x08 : 0x0);
+ hdr_len += tlv_siz;
+ }
+
// jump back to data[0] or pre_data if required
vlib_buffer_advance (b0, -(word) hdr_len);
@@ -1753,6 +2003,25 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d) (vlib_main_t * vm,
}
}
+ if (PREDICT_FALSE (ie_size))
+ {
+ ip6_sr_tlv_t *tlv;
+ user_plane_sub_tlv_t *sub_tlv;
+
+ tlv =
+ (ip6_sr_tlv_t *) ((u8 *) ip6srv + (hdr_len - tlv_siz));
+ tlv->type = SRH_TLV_USER_PLANE_CONTAINER;
+ tlv->length = tlv_siz - sizeof (ip6_sr_tlv_t);
+ clib_memset (tlv->value, 0, tlv->length);
+
+ sub_tlv = (user_plane_sub_tlv_t *) tlv->value;
+ sub_tlv->type = USER_PLANE_SUB_TLV_IE;
+ sub_tlv->length = ie_size;
+ clib_memcpy_fast (sub_tlv->value, ie_buf, ie_size);
+
+ ip6srv->sr.length += tlv_siz / 8;
+ }
+
ip6srv->ip.payload_length =
clib_host_to_net_u16 (len0 + hdr_len - sizeof (ip6_header_t));
@@ -1843,6 +2112,9 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm,
u32 hdrlen;
ip6_header_t *encap = NULL;
gtpu_pdu_session_t *sess;
+ u16 ie_size = 0;
+ u16 tlv_siz = 0;
+ u8 ie_buf[GTPU_IE_MAX_SIZ];
u32 next0 = SRV6_END_M_GTP6_D_DI_NEXT_LOOKUP;
@@ -1985,6 +2257,24 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm,
}
}
+ if (PREDICT_FALSE (gtpu_type == GTPU_TYPE_ERROR_INDICATION))
+ {
+ u16 payload_len;
+
+ payload_len = clib_net_to_host_u16 (hdr0->gtpu.length);
+ if (payload_len != 0
+ && payload_len > hdrlen - sizeof (ip6_gtpu_header_t))
+ {
+ u8 *ies;
+
+ ies = (u8 *) ((u8 *) hdr0 + hdrlen);
+ ie_size =
+ payload_len - (hdrlen - sizeof (ip6_gtpu_header_t));
+ clib_memcpy_fast (ie_buf, ies, ie_size);
+ hdrlen += ie_size;
+ }
+ }
+
// jump over variable length data
vlib_buffer_advance (b0, (word) hdrlen);
@@ -2028,6 +2318,16 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm,
hdr_len += sizeof (ip6_address_t) * 2;
+ if (ie_size)
+ {
+ tlv_siz =
+ sizeof (ip6_sr_tlv_t) + sizeof (user_plane_sub_tlv_t) +
+ ie_size;
+
+ tlv_siz = (tlv_siz & ~0x07) + (tlv_siz & 0x07 ? 0x08 : 0x0);
+ hdr_len += tlv_siz;
+ }
+
// jump back to data[0] or pre_data if required
vlib_buffer_advance (b0, -(word) hdr_len);
@@ -2109,6 +2409,24 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm,
ip6srv->sr.segments[0] = dst0;
}
+ if (PREDICT_FALSE (ie_size))
+ {
+ ip6_sr_tlv_t *tlv;
+ user_plane_sub_tlv_t *sub_tlv;
+
+ tlv =
+ (ip6_sr_tlv_t *) ((u8 *) ip6srv + (hdr_len - tlv_siz));
+ tlv->type = SRH_TLV_USER_PLANE_CONTAINER;
+ tlv->length = tlv_siz - sizeof (ip6_sr_tlv_t);
+ clib_memset (tlv->value, 0, tlv->length);
+
+ sub_tlv = (user_plane_sub_tlv_t *) tlv->value;
+ sub_tlv->length = ie_size;
+ clib_memcpy_fast (sub_tlv->value, ie_buf, ie_size);
+
+ ip6srv->sr.length += tlv_siz / 8;
+ }
+
ip6srv->ip.payload_length =
clib_host_to_net_u16 (len0 + hdr_len - sizeof (ip6_header_t));
ip6srv->ip.protocol = IP_PROTOCOL_IPV6_ROUTE;
@@ -2202,6 +2520,443 @@ VLIB_NODE_FN (srv6_end_m_gtp6_d_di) (vlib_main_t * vm,
return frame->n_vectors;
}
+// Function for SRv6 GTP6.DT function
+VLIB_NODE_FN (srv6_end_m_gtp6_dt) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ srv6_end_main_v6_dt_t *sm = &srv6_end_main_v6_dt;
+ ip6_sr_main_t *sm2 = &sr_main;
+ u32 n_left_from, next_index, *from, *to_next;
+ u32 thread_index = vm->thread_index;
+
+ u32 good_n = 0, bad_n = 0;
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ srv6_end_gtp6_dt_param_t *ls_param;
+ ip6_sr_localsid_t *ls0;
+
+ ip6_gtpu_header_t *hdr0 = NULL;
+ ip4_header_t *ip4 = NULL;
+ ip6_header_t *ip6 = NULL;
+ ip6_address_t src, dst;
+ u32 teid;
+ u32 hdrlen;
+ u32 len0;
+
+ u32 next0 = SRV6_END_M_GTP6_DT_NEXT_DROP;
+
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ ls0 =
+ pool_elt_at_index (sm2->localsids,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+
+ ls_param = (srv6_end_gtp6_dt_param_t *) ls0->plugin_mem;
+
+ hdr0 = vlib_buffer_get_current (b0);
+
+ hdrlen = sizeof (ip6_gtpu_header_t);
+
+ len0 = vlib_buffer_length_in_chain (vm, b0);
+
+ if ((hdr0->ip6.protocol != IP_PROTOCOL_UDP)
+ || (hdr0->udp.dst_port !=
+ clib_host_to_net_u16 (SRV6_GTP_UDP_DST_PORT))
+ || (len0 < sizeof (ip6_gtpu_header_t)))
+ {
+ next0 = SRV6_END_M_GTP6_DT_NEXT_DROP;
+
+ bad_n++;
+ }
+ else
+ {
+ clib_memcpy_fast (src.as_u8, hdr0->ip6.src_address.as_u8,
+ sizeof (ip6_address_t));
+ clib_memcpy_fast (dst.as_u8, hdr0->ip6.dst_address.as_u8,
+ sizeof (ip6_address_t));
+
+ teid = hdr0->gtpu.teid;
+
+ if (hdr0->gtpu.ver_flags & GTPU_EXTHDR_FLAG)
+ {
+ hdrlen += sizeof (gtpu_exthdr_t);
+ if (hdr0->gtpu.ext->nextexthdr == GTPU_EXTHDR_PDU_SESSION)
+ {
+ gtpu_pdu_session_t *sess;
+
+ sess =
+ (gtpu_pdu_session_t *) (((char *) hdr0) +
+ sizeof (ip6_gtpu_header_t) +
+ sizeof (gtpu_exthdr_t));
+
+ hdrlen += sizeof (gtpu_pdu_session_t);
+ if (sess->u.val & GTPU_PDU_SESSION_P_BIT_MASK)
+ {
+ hdrlen += sizeof (gtpu_paging_policy_t);
+ }
+ }
+ }
+
+ if (ls_param->type == SRV6_GTP6_DT4)
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ ip4 = vlib_buffer_get_current (b0);
+ if ((ip4->ip_version_and_header_length & 0xf0) != 0x40)
+ {
+ next0 = SRV6_END_M_GTP6_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+
+ next0 = SRV6_END_M_GTP6_DT_NEXT_LOOKUP4;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib4_index;
+ }
+ else if (ls_param->type == SRV6_GTP6_DT6)
+ {
+ ip6 = (ip6_header_t *) ((u8 *) hdr0 + hdrlen);
+ if ((clib_net_to_host_u32
+ (ip6->ip_version_traffic_class_and_flow_label) >> 28)
+ != 6)
+ {
+ next0 = SRV6_END_M_GTP6_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+
+ next0 = SRV6_END_M_GTP6_DT_NEXT_LOOKUP6;
+ if ((ip6->dst_address.as_u8[0] == 0xff)
+ && ((ip6->dst_address.as_u8[1] & 0xc0) == 0x80))
+ {
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->local_fib_index;
+ }
+ else
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib6_index;
+ }
+ }
+ else if (ls_param->type == SRV6_GTP6_DT46)
+ {
+ ip6 = (ip6_header_t *) ((u8 *) hdr0 + hdrlen);
+ if ((clib_net_to_host_u32
+ (ip6->ip_version_traffic_class_and_flow_label) >> 28)
+ == 6)
+ {
+ next0 = SRV6_END_M_GTP6_DT_NEXT_LOOKUP6;
+ if ((ip6->dst_address.as_u8[0] == 0xff)
+ && ((ip6->dst_address.as_u8[1] & 0xc0) == 0x80))
+ {
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->local_fib_index;
+ }
+ else
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib6_index;
+ }
+ }
+ else
+ if ((clib_net_to_host_u32
+ (ip6->ip_version_traffic_class_and_flow_label) >> 28)
+ == 4)
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ next0 = SRV6_END_M_GTP6_DT_NEXT_LOOKUP4;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib4_index;
+ }
+ else
+ {
+ next0 = SRV6_END_M_GTP6_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else
+ {
+ next0 = SRV6_END_M_GTP6_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+
+ good_n++;
+
+ if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) &&
+ PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ srv6_end_rewrite_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ clib_memcpy (tr->src.as_u8, src.as_u8,
+ sizeof (ip6_address_t));
+ clib_memcpy (tr->dst.as_u8, dst.as_u8,
+ sizeof (ip6_address_t));
+ tr->teid = teid;
+ }
+ }
+
+ DONE:
+ vlib_increment_combined_counter
+ (((next0 ==
+ SRV6_END_M_GTP6_DT_NEXT_DROP) ? &(sm2->sr_ls_invalid_counters)
+ : &(sm2->sr_ls_valid_counters)), thread_index,
+ ls0 - sm2->localsids, 1, vlib_buffer_length_in_chain (vm, b0));
+
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ vlib_node_increment_counter (vm, sm->end_m_gtp6_dt_node_index,
+ SRV6_END_ERROR_M_GTP6_DT_BAD_PACKETS, bad_n);
+
+ vlib_node_increment_counter (vm, sm->end_m_gtp6_dt_node_index,
+ SRV6_END_ERROR_M_GTP6_DT_PACKETS, good_n);
+
+ return frame->n_vectors;
+}
+
+// Function for SRv6 GTP4.DT function
+VLIB_NODE_FN (srv6_t_m_gtp4_dt) (vlib_main_t * vm,
+ vlib_node_runtime_t * node,
+ vlib_frame_t * frame)
+{
+ srv6_t_main_v4_dt_t *sm = &srv6_t_main_v4_dt;
+ ip6_sr_main_t *sm2 = &sr_main;
+ u32 n_left_from, next_index, *from, *to_next;
+
+ u32 good_n = 0, bad_n = 0;
+
+ from = vlib_frame_vector_args (frame);
+ n_left_from = frame->n_vectors;
+ next_index = node->cached_next_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ srv6_t_gtp4_dt_param_t *ls_param;
+ ip6_sr_sl_t *ls0;
+
+ ip4_gtpu_header_t *hdr0 = NULL;
+ ip4_header_t *ip4 = NULL;
+ ip6_header_t *ip6 = NULL;
+ ip6_address_t src, dst;
+ u32 teid;
+ u32 hdrlen;
+ u32 len0;
+
+ u32 next0 = SRV6_T_M_GTP4_DT_NEXT_DROP;
+
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ ls0 =
+ pool_elt_at_index (sm2->sid_lists,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+
+ ls_param = (srv6_t_gtp4_dt_param_t *) ls0->plugin_mem;
+
+ hdr0 = vlib_buffer_get_current (b0);
+
+ hdrlen = sizeof (ip4_gtpu_header_t);
+
+ len0 = vlib_buffer_length_in_chain (vm, b0);
+
+ if ((hdr0->ip4.protocol != IP_PROTOCOL_UDP)
+ || (hdr0->udp.dst_port !=
+ clib_host_to_net_u16 (SRV6_GTP_UDP_DST_PORT))
+ || (len0 < sizeof (ip4_gtpu_header_t)))
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_DROP;
+
+ bad_n++;
+ }
+ else
+ {
+ clib_memcpy_fast (src.as_u8, hdr0->ip4.src_address.as_u8,
+ sizeof (ip4_address_t));
+ clib_memcpy_fast (dst.as_u8, hdr0->ip4.dst_address.as_u8,
+ sizeof (ip4_address_t));
+
+ teid = hdr0->gtpu.teid;
+
+ if (hdr0->gtpu.ver_flags & GTPU_EXTHDR_FLAG)
+ {
+ hdrlen += sizeof (gtpu_exthdr_t);
+ if (hdr0->gtpu.ext->nextexthdr == GTPU_EXTHDR_PDU_SESSION)
+ {
+ gtpu_pdu_session_t *sess;
+
+ sess =
+ (gtpu_pdu_session_t *) (((char *) hdr0) +
+ sizeof (ip6_gtpu_header_t) +
+ sizeof (gtpu_exthdr_t));
+
+ hdrlen += sizeof (gtpu_pdu_session_t);
+ if (sess->u.val & GTPU_PDU_SESSION_P_BIT_MASK)
+ {
+ hdrlen += sizeof (gtpu_paging_policy_t);
+ }
+ }
+ }
+
+ if (ls_param->type == SRV6_GTP4_DT4)
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ ip4 = vlib_buffer_get_current (b0);
+ if ((ip4->ip_version_and_header_length & 0xf0) != 0x40)
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+
+ next0 = SRV6_T_M_GTP4_DT_NEXT_LOOKUP4;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib4_index;
+ }
+ else if (ls_param->type == SRV6_GTP4_DT6)
+ {
+ ip6 = (ip6_header_t *) ((u8 *) hdr0 + hdrlen);
+ if ((clib_net_to_host_u32
+ (ip6->ip_version_traffic_class_and_flow_label) >> 28)
+ != 6)
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+
+ next0 = SRV6_T_M_GTP4_DT_NEXT_LOOKUP6;
+ if ((ip6->dst_address.as_u8[0] == 0xff)
+ && ((ip6->dst_address.as_u8[1] & 0xc0) == 0x80))
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_LOOKUP4;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->local_fib_index;
+ }
+ else
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib6_index;
+ }
+ }
+ else if (ls_param->type == SRV6_GTP4_DT46)
+ {
+ ip6 = (ip6_header_t *) ((u8 *) hdr0 + hdrlen);
+ if ((clib_net_to_host_u32
+ (ip6->ip_version_traffic_class_and_flow_label) >> 28)
+ == 6)
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_LOOKUP6;
+ if ((ip6->dst_address.as_u8[0] == 0xff)
+ && ((ip6->dst_address.as_u8[1] & 0xc0) == 0x80))
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_LOOKUP4;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->local_fib_index;
+ }
+ else
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib6_index;
+ }
+ }
+ else
+ if ((clib_net_to_host_u32
+ (ip6->ip_version_traffic_class_and_flow_label) >> 28)
+ == 4)
+ {
+ vlib_buffer_advance (b0, (word) hdrlen);
+ next0 = SRV6_T_M_GTP4_DT_NEXT_LOOKUP4;
+ vnet_buffer (b0)->sw_if_index[VLIB_TX] =
+ ls_param->fib4_index;
+ }
+ else
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+ }
+ else
+ {
+ next0 = SRV6_T_M_GTP4_DT_NEXT_DROP;
+ bad_n++;
+ goto DONE;
+ }
+
+ good_n++;
+
+ if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE) &&
+ PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ srv6_end_rewrite_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ clib_memcpy (tr->src.as_u8, src.as_u8,
+ sizeof (ip6_address_t));
+ clib_memcpy (tr->dst.as_u8, dst.as_u8,
+ sizeof (ip6_address_t));
+ tr->teid = teid;
+ }
+ }
+
+ DONE:
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+
+ vlib_node_increment_counter (vm, sm->t_m_gtp4_dt_node_index,
+ SRV6_T_ERROR_M_GTP4_DT_BAD_PACKETS, bad_n);
+
+ vlib_node_increment_counter (vm, sm->t_m_gtp4_dt_node_index,
+ SRV6_T_ERROR_M_GTP4_DT_PACKETS, good_n);
+
+ return frame->n_vectors;
+}
+
VLIB_REGISTER_NODE (srv6_end_m_gtp6_e) =
{
.name = "srv6-end-m-gtp6-e",.vector_size = sizeof (u32),.format_trace =
@@ -2210,8 +2965,8 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp6_e) =
srv6_end_error_v6_e_strings,.n_next_nodes =
SRV6_END_M_GTP6_E_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP6_E_NEXT_DROP] = "error-drop",
- [SRV6_END_M_GTP6_E_NEXT_LOOKUP] = "ip6-lookup",}
+ [SRV6_END_M_GTP6_E_NEXT_DROP] =
+ "error-drop",[SRV6_END_M_GTP6_E_NEXT_LOOKUP] = "ip6-lookup",}
,};
VLIB_REGISTER_NODE (srv6_end_m_gtp6_d) =
@@ -2222,8 +2977,8 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp6_d) =
srv6_end_error_v6_d_strings,.n_next_nodes =
SRV6_END_M_GTP6_D_N_NEXT,.next_nodes =
{
- [SRV6_END_M_GTP6_D_NEXT_DROP] = "error-drop",
- [SRV6_END_M_GTP6_D_NEXT_LOOKUP] = "ip6-lookup",}
+ [SRV6_END_M_GTP6_D_NEXT_DROP] =
+ "error-drop",[SRV6_END_M_GTP6_D_NEXT_LOOKUP] = "ip6-lookup",}
,};
VLIB_REGISTER_NODE (srv6_end_m_gtp6_d_di) =
@@ -2238,6 +2993,34 @@ VLIB_REGISTER_NODE (srv6_end_m_gtp6_d_di) =
[SRV6_END_M_GTP6_D_DI_NEXT_LOOKUP] = "ip6-lookup",}
,};
+VLIB_REGISTER_NODE (srv6_end_m_gtp6_dt) =
+{
+ .name = "srv6-end-m-gtp6-dt",.vector_size = sizeof (u32),.format_trace =
+ format_srv6_end_rewrite_trace6,.type = VLIB_NODE_TYPE_INTERNAL,.n_errors =
+ ARRAY_LEN (srv6_end_error_v6_dt_strings),.error_strings =
+ srv6_end_error_v6_dt_strings,.n_next_nodes =
+ SRV6_END_M_GTP6_DT_N_NEXT,.next_nodes =
+ {
+ [SRV6_END_M_GTP6_DT_NEXT_DROP] =
+ "error-drop",
+ [SRV6_END_M_GTP6_DT_NEXT_LOOKUP4]
+ = "ip4-lookup",[SRV6_END_M_GTP6_DT_NEXT_LOOKUP6] = "ip6-lookup",}
+,};
+
+VLIB_REGISTER_NODE (srv6_t_m_gtp4_dt) =
+{
+ .name = "srv6-t-m-gtp4-dt",.vector_size = sizeof (u32),.format_trace =
+ format_srv6_end_rewrite_trace6,.type = VLIB_NODE_TYPE_INTERNAL,.n_errors =
+ ARRAY_LEN (srv6_t_error_v4_dt_strings),.error_strings =
+ srv6_t_error_v4_dt_strings,.n_next_nodes =
+ SRV6_T_M_GTP4_DT_N_NEXT,.next_nodes =
+ {
+ [SRV6_T_M_GTP4_DT_NEXT_DROP] =
+ "error-drop",
+ [SRV6_T_M_GTP4_DT_NEXT_LOOKUP4] =
+ "ip4-lookup",[SRV6_T_M_GTP4_DT_NEXT_LOOKUP6] = "ip6-lookup",}
+,};
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/plugins/srv6-mobile/test/test_srv6_end.py b/src/plugins/srv6-mobile/test/test_srv6_end.py
deleted file mode 100644
index 9eb62c9ce33..00000000000
--- a/src/plugins/srv6-mobile/test/test_srv6_end.py
+++ /dev/null
@@ -1,160 +0,0 @@
-#!/usr/bin/env python
-
-from framework import VppTestCase
-from ipaddress import IPv4Address
-from ipaddress import IPv6Address
-from scapy.contrib.gtp import *
-from scapy.all import *
-
-
-class TestSRv6EndMGTP4E(VppTestCase):
- """ SRv6 End.M.GTP4.E (SRv6 -> GTP-U) """
-
- @classmethod
- def setUpClass(cls):
- super(TestSRv6EndMGTP4E, cls).setUpClass()
- try:
- cls.create_pg_interfaces(range(2))
- cls.pg_if_i = cls.pg_interfaces[0]
- cls.pg_if_o = cls.pg_interfaces[1]
-
- cls.pg_if_i.config_ip6()
- cls.pg_if_o.config_ip4()
-
- cls.ip4_dst = cls.pg_if_o.remote_ip4
- # cls.ip4_src = cls.pg_if_o.local_ip4
- cls.ip4_src = "192.168.192.10"
-
- for pg_if in cls.pg_interfaces:
- pg_if.admin_up()
- pg_if.resolve_arp()
-
- except Exception:
- super(TestSRv6EndMGTP4E, cls).tearDownClass()
- raise
-
- def create_packets(self, inner):
-
- ip4_dst = IPv4Address(str(self.ip4_dst))
- # 32bit prefix + 32bit IPv4 DA + 8bit + 32bit TEID + 24bit
- dst = b'\xaa' * 4 + ip4_dst.packed + \
- b'\x11' + b'\xbb' * 4 + b'\x11' * 3
- ip6_dst = IPv6Address(dst)
-
- ip4_src = IPv4Address(str(self.ip4_src))
- # 64bit prefix + 32bit IPv4 SA + 16 bit port + 16bit
- src = b'\xcc' * 8 + ip4_src.packed + \
- b'\xdd' * 2 + b'\x11' * 2
- ip6_src = IPv6Address(src)
-
- self.logger.info("ip4 dst: {}".format(ip4_dst))
- self.logger.info("ip4 src: {}".format(ip4_src))
- self.logger.info("ip6 dst (remote srgw): {}".format(ip6_dst))
- self.logger.info("ip6 src (local srgw): {}".format(ip6_src))
-
- pkts = list()
- for d, s in inner:
- pkt = (Ether() /
- IPv6(dst=str(ip6_dst), src=str(ip6_src)) /
- IPv6ExtHdrSegmentRouting() /
- IPv6(dst=d, src=s) /
- UDP(sport=1000, dport=23))
- self.logger.info(pkt.show2(dump=True))
- pkts.append(pkt)
-
- return pkts
-
- def test_srv6_end(self):
- """ test_srv6_end """
- pkts = self.create_packets([("A::1", "B::1"), ("C::1", "D::1")])
-
- self.vapi.cli(
- "sr localsid address {} behavior end.m.gtp4.e v4src_position 64"
- .format(pkts[0]['IPv6'].dst))
- self.logger.info(self.vapi.cli("show sr localsids"))
-
- self.vapi.cli("clear errors")
-
- self.pg0.add_stream(pkts)
- self.pg_enable_capture(self.pg_interfaces)
- self.pg_start()
-
- self.logger.info(self.vapi.cli("show errors"))
- self.logger.info(self.vapi.cli("show int address"))
-
- capture = self.pg1.get_capture(len(pkts))
-
- for pkt in capture:
- self.logger.info(pkt.show2(dump=True))
- self.assertEqual(pkt[IP].dst, self.ip4_dst)
- self.assertEqual(pkt[IP].src, self.ip4_src)
- self.assertEqual(pkt[GTP_U_Header].teid, 0xbbbbbbbb)
-
-
-class TestSRv6TMTmap(VppTestCase):
- """ SRv6 T.M.Tmap (GTP-U -> SRv6) """
-
- @classmethod
- def setUpClass(cls):
- super(TestSRv6TMTmap, cls).setUpClass()
- try:
- cls.create_pg_interfaces(range(2))
- cls.pg_if_i = cls.pg_interfaces[0]
- cls.pg_if_o = cls.pg_interfaces[1]
-
- cls.pg_if_i.config_ip4()
- cls.pg_if_o.config_ip6()
-
- for pg_if in cls.pg_interfaces:
- pg_if.admin_up()
- pg_if.resolve_arp()
-
- except Exception:
- super(TestSRv6TMTmap, cls).tearDownClass()
- raise
-
-
-class TestSRv6EndMGTP6E(VppTestCase):
- """ SRv6 End.M.GTP6.E """
-
- @classmethod
- def setUpClass(cls):
- super(TestSRv6EndMGTP6E, cls).setUpClass()
- try:
- cls.create_pg_interfaces(range(2))
- cls.pg_if_i = cls.pg_interfaces[0]
- cls.pg_if_o = cls.pg_interfaces[1]
-
- cls.pg_if_i.config_ip4()
- cls.pg_if_o.config_ip6()
-
- for pg_if in cls.pg_interfaces:
- pg_if.admin_up()
- pg_if.resolve_arp()
-
- except Exception:
- super(TestSRv6EndMGTP6E, cls).tearDownClass()
- raise
-
-
-class TestSRv6EndMGTP6D(VppTestCase):
- """ SRv6 End.M.GTP6.D """
-
- @classmethod
- def setUpClass(cls):
- super(TestSRv6EndMGTP6D, cls).setUpClass()
- try:
- cls.create_pg_interfaces(range(2))
- cls.pg_if_i = cls.pg_interfaces[0]
- cls.pg_if_o = cls.pg_interfaces[1]
-
- cls.pg_if_i.config_ip4()
- cls.pg_if_o.config_ip6()
-
- for pg_if in cls.pg_interfaces:
- pg_if.admin_up()
- pg_if.resolve_arp()
-
- except Exception:
- super(TestSRv6EndMGTP6D, cls).tearDownClass()
- raise
diff --git a/src/plugins/srv6-mobile/test/test_srv6_mobile.py b/src/plugins/srv6-mobile/test/test_srv6_mobile.py
new file mode 100644
index 00000000000..ec94b8b9c03
--- /dev/null
+++ b/src/plugins/srv6-mobile/test/test_srv6_mobile.py
@@ -0,0 +1,340 @@
+#!/usr/bin/env python
+
+from framework import VppTestCase
+from ipaddress import IPv4Address
+from ipaddress import IPv6Address
+from scapy.contrib.gtp import *
+from scapy.all import *
+
+
+class TestSRv6EndMGTP4E(VppTestCase):
+ """ SRv6 End.M.GTP4.E (SRv6 -> GTP-U) """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestSRv6EndMGTP4E, cls).setUpClass()
+ try:
+ cls.create_pg_interfaces(range(2))
+ cls.pg_if_i = cls.pg_interfaces[0]
+ cls.pg_if_o = cls.pg_interfaces[1]
+
+ cls.pg_if_i.config_ip6()
+ cls.pg_if_o.config_ip4()
+
+ cls.ip4_dst = cls.pg_if_o.remote_ip4
+ # cls.ip4_src = cls.pg_if_o.local_ip4
+ cls.ip4_src = "192.168.192.10"
+
+ for pg_if in cls.pg_interfaces:
+ pg_if.admin_up()
+ pg_if.resolve_arp()
+
+ except Exception:
+ super(TestSRv6EndMGTP4E, cls).tearDownClass()
+ raise
+
+ def create_packets(self, inner):
+
+ ip4_dst = IPv4Address(str(self.ip4_dst))
+ # 32bit prefix + 32bit IPv4 DA + 8bit + 32bit TEID + 24bit
+ dst = b'\xaa' * 4 + ip4_dst.packed + \
+ b'\x11' + b'\xbb' * 4 + b'\x11' * 3
+ ip6_dst = IPv6Address(dst)
+
+ ip4_src = IPv4Address(str(self.ip4_src))
+ # 64bit prefix + 32bit IPv4 SA + 16 bit port + 16bit
+ src = b'\xcc' * 8 + ip4_src.packed + \
+ b'\xdd' * 2 + b'\x11' * 2
+ ip6_src = IPv6Address(src)
+
+ self.logger.info("ip4 dst: {}".format(ip4_dst))
+ self.logger.info("ip4 src: {}".format(ip4_src))
+ self.logger.info("ip6 dst (remote srgw): {}".format(ip6_dst))
+ self.logger.info("ip6 src (local srgw): {}".format(ip6_src))
+
+ pkts = list()
+ for d, s in inner:
+ pkt = (Ether() /
+ IPv6(dst=str(ip6_dst), src=str(ip6_src)) /
+ IPv6ExtHdrSegmentRouting() /
+ IPv6(dst=d, src=s) /
+ UDP(sport=1000, dport=23))
+ self.logger.info(pkt.show2(dump=True))
+ pkts.append(pkt)
+
+ return pkts
+
+ def test_srv6_mobile(self):
+ """ test_srv6_mobile """
+ pkts = self.create_packets([("A::1", "B::1"), ("C::1", "D::1")])
+
+ self.vapi.cli(
+ "sr localsid address {} behavior end.m.gtp4.e v4src_position 64"
+ .format(pkts[0]['IPv6'].dst))
+ self.logger.info(self.vapi.cli("show sr localsids"))
+
+ self.vapi.cli("clear errors")
+
+ self.pg0.add_stream(pkts)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ self.logger.info(self.vapi.cli("show errors"))
+ self.logger.info(self.vapi.cli("show int address"))
+
+ capture = self.pg1.get_capture(len(pkts))
+
+ for pkt in capture:
+ self.logger.info(pkt.show2(dump=True))
+ self.assertEqual(pkt[IP].dst, self.ip4_dst)
+ self.assertEqual(pkt[IP].src, self.ip4_src)
+ self.assertEqual(pkt[GTP_U_Header].teid, 0xbbbbbbbb)
+
+
+class TestSRv6TMGTP4D(VppTestCase):
+ """ SRv6 T.M.GTP4.D (GTP-U -> SRv6) """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestSRv6TMGTP4D, cls).setUpClass()
+ try:
+ cls.create_pg_interfaces(range(2))
+ cls.pg_if_i = cls.pg_interfaces[0]
+ cls.pg_if_o = cls.pg_interfaces[1]
+
+ cls.pg_if_i.config_ip4()
+ cls.pg_if_i.config_ip6()
+ cls.pg_if_o.config_ip4()
+ cls.pg_if_o.config_ip6()
+
+ cls.ip4_dst = "1.1.1.1"
+ cls.ip4_src = "2.2.2.2"
+
+ cls.ip6_dst = cls.pg_if_o.remote_ip6
+
+ for pg_if in cls.pg_interfaces:
+ pg_if.admin_up()
+ pg_if.resolve_arp()
+ pg_if.resolve_ndp(timeout=5)
+
+ except Exception:
+ super(TestSRv6TMGTP4D, cls).tearDownClass()
+ raise
+
+ def create_packets(self, inner):
+
+ ip4_dst = IPv4Address(str(self.ip4_dst))
+
+ ip4_src = IPv4Address(str(self.ip4_src))
+
+ self.logger.info("ip4 dst: {}".format(ip4_dst))
+ self.logger.info("ip4 src: {}".format(ip4_src))
+
+ pkts = list()
+ for d, s in inner:
+ pkt = (Ether() /
+ IP(dst=str(ip4_dst), src=str(ip4_src)) /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="g_pdu", teid=200) /
+ IPv6(dst=d, src=s) /
+ UDP(sport=1000, dport=23))
+ self.logger.info(pkt.show2(dump=True))
+ pkts.append(pkt)
+
+ return pkts
+
+ def test_srv6_mobile(self):
+ """ test_srv6_mobile """
+ pkts = self.create_packets([("A::1", "B::1"), ("C::1", "D::1")])
+
+ self.vapi.cli("set sr encaps source addr A1::1")
+ self.vapi.cli("sr policy add bsid D4:: next D2:: next D3::")
+ self.vapi.cli(
+ "sr policy add bsid D5:: behavior t.m.gtp4.d"
+ "D4::/32 v6src_prefix C1::/64 nhtype ipv6")
+ self.vapi.cli("sr steer l3 {}/32 via bsid D5::".format(self.ip4_dst))
+ self.vapi.cli("ip route add D2::/32 via {}".format(self.ip6_dst))
+
+ self.logger.info(self.vapi.cli("show sr steer"))
+ self.logger.info(self.vapi.cli("show sr policies"))
+
+ self.vapi.cli("clear errors")
+
+ self.pg0.add_stream(pkts)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ self.logger.info(self.vapi.cli("show errors"))
+ self.logger.info(self.vapi.cli("show int address"))
+
+ capture = self.pg1.get_capture(len(pkts))
+
+ for pkt in capture:
+ self.logger.info(pkt.show2(dump=True))
+ self.logger.info("GTP4.D Address={}".format(
+ str(pkt[IPv6ExtHdrSegmentRouting].addresses[0])))
+ self.assertEqual(
+ str(pkt[IPv6ExtHdrSegmentRouting].addresses[0]),
+ "d4:0:101:101::c800:0")
+
+
+class TestSRv6EndMGTP6E(VppTestCase):
+ """ SRv6 End.M.GTP6.E """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestSRv6EndMGTP6E, cls).setUpClass()
+ try:
+ cls.create_pg_interfaces(range(2))
+ cls.pg_if_i = cls.pg_interfaces[0]
+ cls.pg_if_o = cls.pg_interfaces[1]
+
+ cls.pg_if_i.config_ip6()
+ cls.pg_if_o.config_ip6()
+
+ cls.ip6_nhop = cls.pg_if_o.remote_ip6
+
+ for pg_if in cls.pg_interfaces:
+ pg_if.admin_up()
+ pg_if.resolve_ndp(timeout=5)
+
+ except Exception:
+ super(TestSRv6EndMGTP6E, cls).tearDownClass()
+ raise
+
+ def create_packets(self, inner):
+ # 64bit prefix + 32bit TEID + 8bit QFI + 24bit
+ dst = b'\xaa' * 8 + b'\x00' + \
+ b'\xbb' * 4 + b'\x00' * 3
+ ip6_dst = IPv6Address(dst)
+
+ self.ip6_dst = ip6_dst
+
+ src = b'\xcc' * 8 + \
+ b'\xdd' * 4 + b'\x11' * 4
+ ip6_src = IPv6Address(src)
+
+ self.ip6_src = ip6_src
+
+ pkts = list()
+ for d, s in inner:
+ pkt = (Ether() /
+ IPv6(dst=str(ip6_dst),
+ src=str(ip6_src)) /
+ IPv6ExtHdrSegmentRouting(segleft=1,
+ lastentry=0,
+ tag=0,
+ addresses=["a1::1"]) /
+ IPv6(dst=d, src=s) / UDP(sport=1000, dport=23))
+ self.logger.info(pkt.show2(dump=True))
+ pkts.append(pkt)
+
+ return pkts
+
+ def test_srv6_mobile(self):
+ """ test_srv6_mobile """
+ pkts = self.create_packets([("A::1", "B::1"), ("C::1", "D::1")])
+
+ self.vapi.cli(
+ "sr localsid prefix {}/64 behavior end.m.gtp6.e"
+ .format(pkts[0]['IPv6'].dst))
+ self.vapi.cli(
+ "ip route add a1::/64 via {}".format(self.ip6_nhop))
+ self.logger.info(self.vapi.cli("show sr localsids"))
+
+ self.vapi.cli("clear errors")
+
+ self.pg0.add_stream(pkts)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ self.logger.info(self.vapi.cli("show errors"))
+ self.logger.info(self.vapi.cli("show int address"))
+
+ capture = self.pg1.get_capture(len(pkts))
+
+ for pkt in capture:
+ self.logger.info(pkt.show2(dump=True))
+ self.assertEqual(pkt[IPv6].dst, "a1::1")
+ self.assertEqual(pkt[IPv6].src, str(self.ip6_src))
+ self.assertEqual(pkt[GTP_U_Header].teid, 0xbbbbbbbb)
+
+
+class TestSRv6EndMGTP6D(VppTestCase):
+ """ SRv6 End.M.GTP6.D """
+
+ @classmethod
+ def setUpClass(cls):
+ super(TestSRv6EndMGTP6D, cls).setUpClass()
+ try:
+ cls.create_pg_interfaces(range(2))
+ cls.pg_if_i = cls.pg_interfaces[0]
+ cls.pg_if_o = cls.pg_interfaces[1]
+
+ cls.pg_if_i.config_ip6()
+ cls.pg_if_o.config_ip6()
+
+ cls.ip6_nhop = cls.pg_if_o.remote_ip6
+
+ cls.ip6_dst = "2001::1"
+ cls.ip6_src = "2002::1"
+
+ for pg_if in cls.pg_interfaces:
+ pg_if.admin_up()
+ pg_if.resolve_ndp(timeout=5)
+
+ except Exception:
+ super(TestSRv6EndMGTP6D, cls).tearDownClass()
+ raise
+
+ def create_packets(self, inner):
+
+ ip6_dst = IPv6Address(str(self.ip6_dst))
+
+ ip6_src = IPv6Address(str(self.ip6_src))
+
+ self.logger.info("ip6 dst: {}".format(ip6_dst))
+ self.logger.info("ip6 src: {}".format(ip6_src))
+
+ pkts = list()
+ for d, s in inner:
+ pkt = (Ether() /
+ IPv6(dst=str(ip6_dst), src=str(ip6_src)) /
+ UDP(sport=2152, dport=2152) /
+ GTP_U_Header(gtp_type="g_pdu", teid=200) /
+ IPv6(dst=d, src=s) /
+ UDP(sport=1000, dport=23))
+ self.logger.info(pkt.show2(dump=True))
+ pkts.append(pkt)
+
+ return pkts
+
+ def test_srv6_mobile(self):
+ """ test_srv6_mobile """
+ pkts = self.create_packets([("A::1", "B::1"), ("C::1", "D::1")])
+
+ self.vapi.cli("set sr encaps source addr A1::1")
+ self.vapi.cli("sr policy add bsid D4:: next D2:: next D3::")
+ self.vapi.cli(
+ "sr localsid prefix 2001::/64 behavior end.m.gtp6.d D4::/64")
+ self.vapi.cli("ip route add D2::/64 via {}".format(self.ip6_nhop))
+
+ self.logger.info(self.vapi.cli("show sr policies"))
+
+ self.vapi.cli("clear errors")
+
+ self.pg0.add_stream(pkts)
+ self.pg_enable_capture(self.pg_interfaces)
+ self.pg_start()
+
+ self.logger.info(self.vapi.cli("show errors"))
+ self.logger.info(self.vapi.cli("show int address"))
+
+ capture = self.pg1.get_capture(len(pkts))
+
+ for pkt in capture:
+ self.logger.info(pkt.show2(dump=True))
+ self.logger.info("GTP6.D Address={}".format(
+ str(pkt[IPv6ExtHdrSegmentRouting].addresses[0])))
+ self.assertEqual(
+ str(pkt[IPv6ExtHdrSegmentRouting].addresses[0]), "d4::c800:0")
diff --git a/src/vnet/srv6/sr_packet.h b/src/vnet/srv6/sr_packet.h
index d2fb0898530..dda776b4037 100755
--- a/src/vnet/srv6/sr_packet.h
+++ b/src/vnet/srv6/sr_packet.h
@@ -149,6 +149,13 @@ typedef struct
ip6_address_t segments[0];
} __attribute__ ((packed)) ip6_sr_header_t;
+typedef struct
+{
+ u8 type;
+ u8 length;
+ u8 value[0];
+} __attribute__ ((packed)) ip6_sr_tlv_t;
+
/*
* fd.io coding-style-patch-verification: ON
*