From 68ac244283b60cbaf6356ab732f1d31583bb3e7a Mon Sep 17 00:00:00 2001 From: Takeru Hayasaka Date: Fri, 28 Oct 2022 04:26:05 +0900 Subject: srv6-mobile: Implement SRv6 mobile API funcs This merge request adds the feature to manipulate localsids and policies for SRv6 mobile via API. Type: feature Signed-off-by: Takeru Hayasaka Change-Id: Ibb46bf71ae1d9d4591ce2c8ccf66f520887dad70 --- test/test_srv6_mobile.py | 86 ++++++++++++++++++++++++------ test/vpp_srv6_mobile.py | 136 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 206 insertions(+), 16 deletions(-) create mode 100644 test/vpp_srv6_mobile.py (limited to 'test') diff --git a/test/test_srv6_mobile.py b/test/test_srv6_mobile.py index 89ab7a9c9fa..9d39f194015 100644 --- a/test/test_srv6_mobile.py +++ b/test/test_srv6_mobile.py @@ -3,6 +3,14 @@ from framework import VppTestCase from ipaddress import IPv4Address from ipaddress import IPv6Address +from vpp_ip_route import VppIpRoute, VppRoutePath, FibPathProto, VppIpTable + +from vpp_srv6_mobile import ( + SRv6MobileNhtype, + VppSRv6MobilePolicy, + VppSRv6MobileLocalSID, +) + from scapy.contrib.gtp import * from scapy.all import * @@ -67,10 +75,19 @@ class TestSRv6EndMGTP4E(VppTestCase): """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 ".format(pkts[0]["IPv6"].dst) - + "v4src_position 64 fib-table 0" + # "sr localsid address {} behavior end.m.gtp4.e v4src_position 64 fib-table 0" + # ".format(pkts[0]["IPv6"].dst) + localsid = VppSRv6MobileLocalSID( + self, + # address params case is length 0 + localsid_prefix="{}/{}".format(pkts[0]["IPv6"].dst, 0), + behavior="end.m.gtp4.e", + v4src_position=64, + fib_table=0, ) + localsid.add_vpp_config() + + # log the localsids self.logger.info(self.vapi.cli("show sr localsid")) self.vapi.cli("clear errors") @@ -150,13 +167,28 @@ class TestSRv6TMGTP4D(VppTestCase): 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 fib-table 0 drop-in" + + # sr policy add bsid D5:: behavior t.m.gtp4.d D4::/32 v6src_prefix C1::/64 nhtype ipv6 fib-table 0 drop-in + policy = VppSRv6MobilePolicy( + self, + bsid_addr="D5::", + behavior="t.m.gtp4.d", + sr_prefix="{}/{}".format("D4::", 32), + v6src_prefix="{}/{}".format("C1::", 64), + nhtype=SRv6MobileNhtype.SRV6_NHTYPE_API_IPV6, + fib_table=0, + drop_in=1, ) + policy.add_vpp_config() + 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)) + # "ip route add D2::/32 via {}".format(self.ip6_dst) + route = VppIpRoute( + self, "D2::", 32, [VppRoutePath(self.ip6_dst, self.pg1.sw_if_index)] + ) + route.add_vpp_config() + self.logger.info(self.vapi.cli("show ip6 fib")) self.logger.info(self.vapi.cli("show sr steer")) self.logger.info(self.vapi.cli("show sr policies")) @@ -239,12 +271,21 @@ class TestSRv6EndMGTP6E(VppTestCase): """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 fib-table 0".format( - pkts[0]["IPv6"].dst - ) + # "sr localsid prefix {}/64 behavior end.m.gtp6.e fib-table 0" + # .format(pkts[0]["IPv6"].dst) + localsid = VppSRv6MobileLocalSID( + self, + localsid_prefix="{}/{}".format(pkts[0]["IPv6"].dst, 64), + behavior="end.m.gtp6.e", + fib_table=0, + ) + localsid.add_vpp_config() + + # "ip route add a1::/64 via {}".format(self.ip6_nhop) + route = VppIpRoute( + self, "a1::", 64, [VppRoutePath(self.ip6_nhop, self.pg1.sw_if_index)] ) - self.vapi.cli("ip route add a1::/64 via {}".format(self.ip6_nhop)) + route.add_vpp_config() self.logger.info(self.vapi.cli("show sr localsid")) self.vapi.cli("clear errors") @@ -321,12 +362,25 @@ class TestSRv6EndMGTP6D(VppTestCase): 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 fib-table 0 drop-in" + + # "sr localsid prefix 2001::/64 behavior end.m.gtp6.d 4::/64 fib-table 0 drop-in" + # .format(self.ip6_nhop) + localsid = VppSRv6MobileLocalSID( + self, + localsid_prefix="{}/{}".format("2001::", 64), + behavior="end.m.gtp6.d", + fib_table=0, + drop_in=1, + sr_prefix="{}/{}".format("D4::", 64), ) - self.vapi.cli("ip route add D2::/64 via {}".format(self.ip6_nhop)) + localsid.add_vpp_config() + # "ip route add D2::/64 via {}" + # .format(self.ip6_nhop)) + route = VppIpRoute( + self, "D2::", 64, [VppRoutePath(self.ip6_nhop, self.pg1.sw_if_index)] + ) + route.add_vpp_config() self.logger.info(self.vapi.cli("show sr policies")) self.logger.info(self.vapi.cli("show sr localsid")) diff --git a/test/vpp_srv6_mobile.py b/test/vpp_srv6_mobile.py new file mode 100644 index 00000000000..33b6a6905ec --- /dev/null +++ b/test/vpp_srv6_mobile.py @@ -0,0 +1,136 @@ +from vpp_object import VppObject +from socket import inet_pton, inet_ntop, AF_INET, AF_INET6 + + +class SRv6MobileNhtype: + SRV6_NHTYPE_API_NONE = 0 + SRV6_NHTYPE_API_IPV4 = 1 + SRV6_NHTYPE_API_IPV6 = 2 + SRV6_NHTYPE_API_NON_IP = 3 + + +class VppSRv6MobileLocalSID(VppObject): + """ + SRv6 LocalSID + """ + + def __init__( + self, + test, + localsid_prefix, + behavior, + fib_table=0, + local_fib_table=0, + drop_in=0, + nhtype=SRv6MobileNhtype.SRV6_NHTYPE_API_NONE, + sr_prefix="", + v4src_addr="", + v4src_position=0, + ): + self._test = test + self.localsid_prefix = localsid_prefix + self.behavior = behavior + self.fib_table = fib_table + self.local_fib_table = local_fib_table + self.drop_in = drop_in + self.nhtype = nhtype + self.sr_prefix = sr_prefix + self.v4src_addr = v4src_addr + self.v4src_position = v4src_position + self._configured = False + + def add_vpp_config(self): + self._test.vapi.sr_mobile_localsid_add_del( + localsid_prefix=self.localsid_prefix, + behavior=self.behavior, + fib_table=self.fib_table, + local_fib_table=self.local_fib_table, + drop_in=self.drop_in, + sr_prefix=self.sr_prefix, + v4src_addr=self.v4src_addr, + v4src_position=self.v4src_position, + is_del=0, + ) + self._configured = True + + def remove_vpp_config(self): + self._test.vapi.sr_mobile_localsid_add_del( + localsid_prefix=self.localsid_prefix, + behavior=self.behavior, + fib_table=self.fib_table, + local_fib_table=self.local_fib_table, + drop_in=self.drop_in, + sr_prefix=self.sr_prefix, + v4src_addr=self.v4src_addr, + v4src_position=self.v4src_position, + is_del=1, + ) + self._configured = False + + def query_vpp_config(self): + return self._configured + + def object_id(self): + return "%d;%s,%s" % (self.fib_table, self.localsid_prefix, self.behavior) + + +class VppSRv6MobilePolicy(VppObject): + """ + SRv6 Policy + """ + + def __init__( + self, + test, + bsid_addr, + sr_prefix, + v6src_prefix, + behavior, + fib_table=0, + local_fib_table=0, + encap_src=None, + drop_in=0, + nhtype=SRv6MobileNhtype.SRV6_NHTYPE_API_NONE, + ): + self._test = test + self.bsid_addr = bsid_addr + self.sr_prefix = sr_prefix + self.v6src_prefix = v6src_prefix + self.behavior = behavior + self.fib_table = fib_table + self.local_fib_table = local_fib_table + self.drop_in = drop_in + self.nhtype = nhtype + self.encap_src = encap_src + self._configured = False + + def add_vpp_config(self): + self._test.vapi.sr_mobile_policy_add( + bsid_addr=self.bsid_addr, + sr_prefix=self.sr_prefix, + v6src_prefix=self.v6src_prefix, + behavior=self.behavior, + fib_table=self.fib_table, + local_fib_table=self.local_fib_table, + encap_src=self.encap_src, + drop_in=self.drop_in, + nhtype=self.nhtype, + ) + self._configured = True + + def remove_vpp_config(self): + self._test.vapi.sr_policy_del(self.bsid_addr) + self._configured = False + + def query_vpp_config(self): + # no API to query SR Policies + # use _configured flag for now + return self._configured + + def object_id(self): + return "%d;%s-><%s>;%d" % ( + self.sr_type, + self.bsid, + ",".join(self.segments), + self.is_encap, + ) -- cgit 1.2.3-korg