From 0938eba153ed20b8a32b7278ed6301b45ce257cc Mon Sep 17 00:00:00 2001 From: Jakub Grajciar Date: Wed, 4 Mar 2020 13:08:27 +0100 Subject: [PATCH] sr: srv6 API cleanup Use consistent API types. Type: fix Signed-off-by: Jakub Grajciar Change-Id: I3c348ad2fca8bb3d9a246af7a2aa9dc9c33f57c3 Signed-off-by: Jakub Grajciar --- src/plugins/srv6-ad/test/vpp_srv6.py | 84 ++++++++--------------- src/plugins/srv6-am/test/test_srv6.py | 45 +++++-------- src/vat/api_format.c | 15 ++--- src/vnet/CMakeLists.txt | 10 ++- src/vnet/srmpls/sr_mpls.api | 14 +--- src/vnet/srv6/sr.api | 86 +++++++++++------------- src/vnet/srv6/sr_api.c | 105 +++++++++++++++-------------- src/vnet/srv6/sr_types.api | 45 +++++++++++++ src/vpp/api/custom_dump.c | 30 +++++---- test/vpp_papi_provider.py | 121 ---------------------------------- 10 files changed, 217 insertions(+), 338 deletions(-) create mode 100644 src/vnet/srv6/sr_types.api diff --git a/src/plugins/srv6-ad/test/vpp_srv6.py b/src/plugins/srv6-ad/test/vpp_srv6.py index b6dbc014207..80e771eea18 100644 --- a/src/plugins/srv6-ad/test/vpp_srv6.py +++ b/src/plugins/srv6-ad/test/vpp_srv6.py @@ -40,15 +40,12 @@ class VppSRv6LocalSID(VppObject): SRv6 LocalSID """ - def __init__(self, test, localsid, behavior, nh_addr4, nh_addr6, + def __init__(self, test, localsid, behavior, nh_addr, end_psp, sw_if_index, vlan_index, fib_table): self._test = test self.localsid = localsid - # keep binary format in _localsid - self.localsid["addr"] = inet_pton(AF_INET6, self.localsid["addr"]) self.behavior = behavior - self.nh_addr4 = inet_pton(AF_INET, nh_addr4) - self.nh_addr6 = inet_pton(AF_INET6, nh_addr6) + self.nh_addr = nh_addr self.end_psp = end_psp self.sw_if_index = sw_if_index self.vlan_index = vlan_index @@ -57,10 +54,9 @@ class VppSRv6LocalSID(VppObject): def add_vpp_config(self): self._test.vapi.sr_localsid_add_del( - self.localsid, - self.behavior, - self.nh_addr4, - self.nh_addr6, + localsid=self.localsid, + behavior=self.behavior, + nh_addr=self.nh_addr, is_del=0, end_psp=self.end_psp, sw_if_index=self.sw_if_index, @@ -70,10 +66,9 @@ class VppSRv6LocalSID(VppObject): def remove_vpp_config(self): self._test.vapi.sr_localsid_add_del( - self.localsid, - self.behavior, - self.nh_addr4, - self.nh_addr6, + localsid=self.localsid, + behavior=self.behavior, + nh_addr=self.nh_addr, is_del=1, end_psp=self.end_psp, sw_if_index=self.sw_if_index, @@ -103,17 +98,11 @@ class VppSRv6Policy(VppObject): segments, source): self._test = test self.bsid = bsid - # keep binary format in _bsid - self._bsid = inet_pton(AF_INET6, bsid) self.is_encap = is_encap self.sr_type = sr_type self.weight = weight self.fib_table = fib_table self.segments = segments - # keep binary format in _segments - self._segments = [] - for seg in segments: - self._segments.extend(inet_pton(AF_INET6, seg)) self.n_segments = len(segments) # source not passed to API # self.source = inet_pton(AF_INET6, source) @@ -122,18 +111,17 @@ class VppSRv6Policy(VppObject): def add_vpp_config(self): self._test.vapi.sr_policy_add( - self._bsid, - self.weight, - self.is_encap, - self.sr_type, - self.fib_table, - self.n_segments, - self._segments) + bsid=self.bsid, + weight=self.weight, + is_encap=self.is_encap, + is_spray=self.sr_type, + fib_table=self.fib_table, + sids={'num_sids': self.n_segments, 'sids': self.segments}) self._configured = True def remove_vpp_config(self): self._test.vapi.sr_policy_del( - self._bsid) + self.bsid) self._configured = False def query_vpp_config(self): @@ -164,19 +152,7 @@ class VppSRv6Steering(VppObject): sw_if_index): self._test = test self.bsid = bsid - # keep binary format in _bsid - self._bsid = inet_pton(AF_INET6, bsid) self.prefix = prefix - # keep binary format in _prefix - if ':' in prefix: - # IPv6 - self._prefix = inet_pton(AF_INET6, prefix) - else: - # IPv4 - # API expects 16 octets (128 bits) - # last 4 octets are used for IPv4 - # --> prepend 12 octets - self._prefix = ('\x00' * 12) + inet_pton(AF_INET, prefix) self.mask_width = mask_width self.traffic_type = traffic_type self.sr_policy_index = sr_policy_index @@ -186,26 +162,24 @@ class VppSRv6Steering(VppObject): def add_vpp_config(self): self._test.vapi.sr_steering_add_del( - 0, - self._bsid, - self.sr_policy_index, - self.table_id, - self._prefix, - self.mask_width, - self.sw_if_index, - self.traffic_type) + is_del=0, + bsid=self.bsid, + sr_policy_index=self.sr_policy_index, + table_id=self.table_id, + prefix={'address': self.prefix, 'len': self.mask_width}, + sw_if_index=self.sw_if_index, + traffic_type=self.traffic_type) self._configured = True def remove_vpp_config(self): self._test.vapi.sr_steering_add_del( - 1, - self._bsid, - self.sr_policy_index, - self.table_id, - self._prefix, - self.mask_width, - self.sw_if_index, - self.traffic_type) + is_del=1, + bsid=self.bsid, + sr_policy_index=self.sr_policy_index, + table_id=self.table_id, + prefix={'address': self.prefix, 'len': self.mask_width}, + sw_if_index=self.sw_if_index, + traffic_type=self.traffic_type) self._configured = False def query_vpp_config(self): diff --git a/src/plugins/srv6-am/test/test_srv6.py b/src/plugins/srv6-am/test/test_srv6.py index 5a4a936b0cb..449ad59ac60 100644 --- a/src/plugins/srv6-am/test/test_srv6.py +++ b/src/plugins/srv6-am/test/test_srv6.py @@ -507,10 +507,9 @@ class TestSRv6(VppTestCase): # configure SRv6 localSID End without PSP behavior localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::0'}, + self, localsid='A3::0', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_END, - nh_addr4='0.0.0.0', - nh_addr6='::', + nh_addr=0, end_psp=0, sw_if_index=0, vlan_index=0, @@ -586,10 +585,9 @@ class TestSRv6(VppTestCase): # configure SRv6 localSID End with PSP behavior localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::0'}, + self, localsid='A3::0', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_END, - nh_addr4='0.0.0.0', - nh_addr6='::', + nh_addr=0, end_psp=1, sw_if_index=0, vlan_index=0, @@ -659,10 +657,9 @@ class TestSRv6(VppTestCase): # configure SRv6 localSID End.X without PSP behavior # End.X points to interface pg1 localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::C4'}, + self, localsid='A3::C4', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_X, - nh_addr4='0.0.0.0', - nh_addr6=self.pg1.remote_ip6, + nh_addr=self.pg1.remote_ip6, end_psp=0, sw_if_index=self.pg1.sw_if_index, vlan_index=0, @@ -735,10 +732,9 @@ class TestSRv6(VppTestCase): # configure SRv6 localSID End with PSP behavior localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::C4'}, + self, localsid='A3::C4', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_X, - nh_addr4='0.0.0.0', - nh_addr6=self.pg1.remote_ip6, + nh_addr=self.pg1.remote_ip6, end_psp=1, sw_if_index=self.pg1.sw_if_index, vlan_index=0, @@ -801,10 +797,9 @@ class TestSRv6(VppTestCase): # configure SRv6 localSID End.DX6 behavior localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::C4'}, + self, localsid='A3::C4', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_DX6, - nh_addr4='0.0.0.0', - nh_addr6=self.pg1.remote_ip6, + nh_addr=self.pg1.remote_ip6, end_psp=0, sw_if_index=self.pg1.sw_if_index, vlan_index=0, @@ -886,10 +881,9 @@ class TestSRv6(VppTestCase): # fib_table: where the localsid is installed # sw_if_index: in T-variants of localsid this is the vrf table_id localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::C4'}, + self, localsid='A3::C4', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_DT6, - nh_addr4='0.0.0.0', - nh_addr6='::', + nh_addr=0, end_psp=0, sw_if_index=vrf_1, vlan_index=0, @@ -952,10 +946,9 @@ class TestSRv6(VppTestCase): # configure SRv6 localSID End.DX4 behavior localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::C4'}, + self, localsid='A3::C4', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_DX4, - nh_addr4=self.pg1.remote_ip4, - nh_addr6='::', + nh_addr=self.pg1.remote_ip4, end_psp=0, sw_if_index=self.pg1.sw_if_index, vlan_index=0, @@ -1039,10 +1032,9 @@ class TestSRv6(VppTestCase): # fib_table: where the localsid is installed # sw_if_index: in T-variants of localsid: vrf table_id localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::C4'}, + self, localsid='A3::C4', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_DT4, - nh_addr4='0.0.0.0', - nh_addr6='::', + nh_addr=0, end_psp=0, sw_if_index=vrf_1, vlan_index=0, @@ -1104,10 +1096,9 @@ class TestSRv6(VppTestCase): # configure SRv6 localSID End.DX2 behavior localsid = VppSRv6LocalSID( - self, localsid={'addr': 'A3::C4'}, + self, localsid='A3::C4', behavior=SRv6LocalSIDBehaviors.SR_BEHAVIOR_DX2, - nh_addr4='0.0.0.0', - nh_addr6='::', + nh_addr=0, end_psp=0, sw_if_index=self.pg1.sw_if_index, vlan_index=0, diff --git a/src/vat/api_format.c b/src/vat/api_format.c index cfd2028ce19..8ab47c9aa00 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -9325,10 +9325,8 @@ api_sr_localsid_add_del (vat_main_t * vam) u8 behavior = ~0; u32 sw_if_index; u32 fib_table = ~(u32) 0; - ip6_address_t nh_addr6; - ip4_address_t nh_addr4; - clib_memset (&nh_addr6, 0, sizeof (ip6_address_t)); - clib_memset (&nh_addr4, 0, sizeof (ip4_address_t)); + ip46_address_t nh_addr; + clib_memset (&nh_addr, 0, sizeof (ip46_address_t)); bool nexthop_set = 0; @@ -9339,9 +9337,7 @@ api_sr_localsid_add_del (vat_main_t * vam) if (unformat (i, "del")) is_del = 1; else if (unformat (i, "address %U", unformat_ip6_address, &localsid)); - else if (unformat (i, "next-hop %U", unformat_ip4_address, &nh_addr4)) - nexthop_set = 1; - else if (unformat (i, "next-hop %U", unformat_ip6_address, &nh_addr6)) + else if (unformat (i, "next-hop %U", unformat_ip46_address, &nh_addr)) nexthop_set = 1; else if (unformat (i, "behavior %u", &behavior)); else if (unformat (i, "sw_if_index %u", &sw_if_index)); @@ -9353,12 +9349,11 @@ api_sr_localsid_add_del (vat_main_t * vam) M (SR_LOCALSID_ADD_DEL, mp); - clib_memcpy (mp->localsid.addr, &localsid, sizeof (mp->localsid)); + clib_memcpy (mp->localsid, &localsid, sizeof (mp->localsid)); if (nexthop_set) { - clib_memcpy (mp->nh_addr6, &nh_addr6, sizeof (mp->nh_addr6)); - clib_memcpy (mp->nh_addr4, &nh_addr4, sizeof (mp->nh_addr4)); + clib_memcpy (&mp->nh_addr.un, &nh_addr, sizeof (mp->nh_addr.un)); } mp->behavior = behavior; mp->sw_if_index = ntohl (sw_if_index); diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt index 0ae1b0a8328..95068f96e9a 100644 --- a/src/vnet/CMakeLists.txt +++ b/src/vnet/CMakeLists.txt @@ -946,7 +946,10 @@ list(APPEND VNET_HEADERS srv6/sr.h ) -list(APPEND VNET_API_FILES srv6/sr.api) +list(APPEND VNET_API_FILES + srv6/sr.api + srv6/sr_types.api +) ############################################################################## # mpls segment routing @@ -962,7 +965,10 @@ list(APPEND VNET_HEADERS srmpls/sr_mpls.h ) -list(APPEND VNET_API_FILES srmpls/sr_mpls.api) +list(APPEND VNET_API_FILES + srmpls/sr_mpls.api + srv6/sr_types.api +) ############################################################################## # IPFIX / netflow v10 diff --git a/src/vnet/srmpls/sr_mpls.api b/src/vnet/srmpls/sr_mpls.api index 4c9181839ce..742f135d493 100644 --- a/src/vnet/srmpls/sr_mpls.api +++ b/src/vnet/srmpls/sr_mpls.api @@ -13,10 +13,11 @@ * under the License. */ -option version = "2.0.0"; +option version = "3.0.0"; import "vnet/interface_types.api"; import "vnet/ip/ip_types.api"; +import "vnet/srv6/sr_types.api"; /** \brief MPLS SR policy add @param client_index - opaque cookie to identify the sender @@ -37,15 +38,6 @@ autoreply define sr_mpls_policy_add u32 segments[n_segments]; }; -enum sr_mpls_policy_op -{ - SR_MPLS_POLICY_OP_API_NONE = 0, - SR_MPLS_POLICY_OP_API_ADD = 1, - SR_MPLS_POLICY_OP_API_DEL = 2, - SR_MPLS_POLICY_OP_API_MOD = 3, - -}; - /** \brief MPLS SR policy modification @param client_index - opaque cookie to identify the sender @param context - sender context, to match reply w/ request @@ -63,7 +55,7 @@ autoreply define sr_mpls_policy_mod u32 client_index; u32 context; u32 bsid; - vl_api_sr_mpls_policy_op_t operation; + vl_api_sr_policy_op_t operation; u32 sl_index; u32 weight; u8 n_segments; diff --git a/src/vnet/srv6/sr.api b/src/vnet/srv6/sr.api index 543f3fd7d00..75a23b06e04 100644 --- a/src/vnet/srv6/sr.api +++ b/src/vnet/srv6/sr.api @@ -14,20 +14,18 @@ * limitations under the License. */ -option version = "1.2.1"; +option version = "2.0.0"; + +import "vnet/interface_types.api"; +import "vnet/ip/ip_types.api"; +import "vnet/srv6/sr_types.api"; -/** \brief SRv6 SID -*/ -typedef srv6_sid -{ - u8 addr[16]; -}; typedef srv6_sid_list { u8 num_sids; u32 weight; - vl_api_srv6_sid_t sids[16]; + vl_api_ip6_address_t sids[16]; }; /** \brief IPv6 SR LocalSID add/del request @@ -41,27 +39,20 @@ typedef srv6_sid_list fib_table. @param vlan_index Only for L2 xconnect. Outgoing VLAN tag. @param fib_table FIB table in which we should install the localsid entry - @param nh_addr6 Next Hop IPv6 address. Only for L2/L3 xconnect. - @param nh_addr4 Next Hop IPv4 address. Only for L2/L3 xconnect. + @param nh_addr Next Hop IPv46 address. Only for L2/L3 xconnect. */ autoreply define sr_localsid_add_del { u32 client_index; u32 context; - u8 is_del; - vl_api_srv6_sid_t localsid; - u8 end_psp; - u8 behavior; - u32 sw_if_index; + bool is_del [default=false]; + vl_api_ip6_address_t localsid; + bool end_psp; + vl_api_sr_behavior_t behavior; + vl_api_interface_index_t sw_if_index; u32 vlan_index; u32 fib_table; - u8 nh_addr6[16]; - u8 nh_addr4[4]; -}; - -typedef sr_ip6_address -{ - u8 data[16]; + vl_api_address_t nh_addr; }; /** \brief IPv6 SR policy add @@ -70,7 +61,7 @@ typedef sr_ip6_address @param bsid is the bindingSID of the SR Policy @param weight is the weight of the sid list. optional. @param is_encap is the behavior of the SR policy. (0.SRH insert // 1.Encapsulation) - @param type is the type of the SR policy. (0.Default // 1.Spray) + @param is_spray is the type of the SR policy. (0.Default // 1.Spray) @param fib_table is the VRF where to install the FIB entry for the BSID @param sids is a srv6_sid_list object */ @@ -78,10 +69,10 @@ autoreply define sr_policy_add { u32 client_index; u32 context; - u8 bsid_addr[16]; + vl_api_ip6_address_t bsid_addr; u32 weight; - u8 is_encap; - u8 type; + bool is_encap; + bool is_spray; u32 fib_table; vl_api_srv6_sid_list_t sids; }; @@ -101,10 +92,10 @@ autoreply define sr_policy_mod { u32 client_index; u32 context; - u8 bsid_addr[16]; + vl_api_ip6_address_t bsid_addr; u32 sr_policy_index; u32 fib_table; - u8 operation; + vl_api_sr_policy_op_t operation; u32 sl_index; u32 weight; vl_api_srv6_sid_list_t sids; @@ -120,7 +111,7 @@ autoreply define sr_policy_del { u32 client_index; u32 context; - vl_api_srv6_sid_t bsid_addr; + vl_api_ip6_address_t bsid_addr; u32 sr_policy_index; }; @@ -134,7 +125,7 @@ autoreply define sr_set_encap_source { u32 client_index; u32 context; - u8 encaps_source[16]; + vl_api_ip6_address_t encaps_source; }; /** \brief IPv6 SR Set SRv6 encapsulation hop-limit @@ -165,14 +156,13 @@ autoreply define sr_steering_add_del { u32 client_index; u32 context; - u8 is_del; - u8 bsid_addr[16]; + bool is_del [default=false]; + vl_api_ip6_address_t bsid_addr; u32 sr_policy_index; u32 table_id; - u8 prefix_addr[16]; - u32 mask_width; - u32 sw_if_index; - u8 traffic_type; + vl_api_prefix_t prefix; + vl_api_interface_index_t sw_if_index; + vl_api_sr_steer_t traffic_type; }; /** \brief Dump the list of SR LocalSIDs @@ -188,13 +178,12 @@ define sr_localsids_dump define sr_localsids_details { u32 context; - vl_api_srv6_sid_t addr; - u8 end_psp; - u16 behavior; + vl_api_ip6_address_t addr; + bool end_psp; + vl_api_sr_behavior_t behavior; u32 fib_table; u32 vlan_index; - u8 xconnect_nh_addr6[16]; - u8 xconnect_nh_addr4[4]; + vl_api_address_t xconnect_nh_addr; u32 xconnect_iface_or_vrf_table; }; @@ -211,9 +200,9 @@ define sr_policies_dump define sr_policies_details { u32 context; - vl_api_srv6_sid_t bsid; - u8 type; - u8 is_encap; + vl_api_ip6_address_t bsid; + bool is_spray; + bool is_encap; u32 fib_table; u8 num_sid_lists; vl_api_srv6_sid_list_t sid_lists[num_sid_lists]; @@ -232,12 +221,11 @@ define sr_steering_pol_dump define sr_steering_pol_details { u32 context; - u8 traffic_type; + vl_api_sr_steer_t traffic_type; u32 fib_table; - u8 prefix_addr[16]; - u32 mask_width; - u32 sw_if_index; - vl_api_srv6_sid_t bsid; + vl_api_prefix_t prefix; + vl_api_interface_index_t sw_if_index; + vl_api_ip6_address_t bsid; }; /* diff --git a/src/vnet/srv6/sr_api.c b/src/vnet/srv6/sr_api.c index cd8182480a4..142b5c2a4b6 100644 --- a/src/vnet/srv6/sr_api.c +++ b/src/vnet/srv6/sr_api.c @@ -26,6 +26,8 @@ #include #include +#include + #include #define vl_typedefs /* define message structures */ @@ -61,6 +63,8 @@ static void vl_api_sr_localsid_add_del_t_handler { vl_api_sr_localsid_add_del_reply_t *rmp; int rv = 0; + ip46_address_t prefix; + ip6_address_t localsid; /* * int sr_cli_localsid (char is_del, ip6_address_t *localsid_addr, * char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table, @@ -71,17 +75,11 @@ static void vl_api_sr_localsid_add_del_t_handler mp->behavior == SR_BEHAVIOR_DX4 || mp->behavior == SR_BEHAVIOR_DX2) VALIDATE_SW_IF_INDEX (mp); - ip46_address_t prefix; - - clib_memset (&prefix, 0, sizeof (ip46_address_t)); - if ((mp->nh_addr4[0] | mp->nh_addr4[1] | mp-> - nh_addr4[2] | mp->nh_addr4[3]) != 0) - memcpy (&prefix.ip4, mp->nh_addr4, sizeof (prefix.ip4)); - else - memcpy (&prefix.ip6, mp->nh_addr6, sizeof (prefix.ip6)); + ip6_address_decode (mp->localsid, &localsid); + ip_address_decode (&mp->nh_addr, &prefix); rv = sr_cli_localsid (mp->is_del, - (ip6_address_t *) & mp->localsid, 128, + &localsid, 128, mp->end_psp, mp->behavior, ntohl (mp->sw_if_index), @@ -97,26 +95,28 @@ vl_api_sr_policy_add_t_handler (vl_api_sr_policy_add_t * mp) { vl_api_sr_policy_add_reply_t *rmp; ip6_address_t *segments = 0, *seg; - ip6_address_t *this_address = (ip6_address_t *) mp->sids.sids; + ip6_address_t bsid_addr; int i; for (i = 0; i < mp->sids.num_sids; i++) { vec_add2 (segments, seg, 1); - clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address)); - this_address++; + ip6_address_decode (mp->sids.sids[i], seg); } + ip6_address_decode (mp->bsid_addr, &bsid_addr); + /* * sr_policy_add (ip6_address_t *bsid, ip6_address_t *segments, * u32 weight, u8 behavior, u32 fib_table, u8 is_encap, * u16 behavior, void *plugin_mem) */ int rv = 0; - rv = sr_policy_add ((ip6_address_t *) & mp->bsid_addr, + rv = sr_policy_add (&bsid_addr, segments, ntohl (mp->sids.weight), - mp->type, ntohl (mp->fib_table), mp->is_encap, 0, NULL); + mp->is_spray, ntohl (mp->fib_table), mp->is_encap, 0, + NULL); vec_free (segments); REPLY_MACRO (VL_API_SR_POLICY_ADD_REPLY); @@ -126,18 +126,18 @@ static void vl_api_sr_policy_mod_t_handler (vl_api_sr_policy_mod_t * mp) { vl_api_sr_policy_mod_reply_t *rmp; - ip6_address_t *segments = 0, *seg; - ip6_address_t *this_address = (ip6_address_t *) mp->sids.sids; + ip6_address_t bsid_addr; int i; for (i = 0; i < mp->sids.num_sids; i++) { vec_add2 (segments, seg, 1); - clib_memcpy (seg->as_u8, this_address->as_u8, sizeof (*this_address)); - this_address++; + ip6_address_decode (mp->sids.sids[i], seg); } + ip6_address_decode (mp->bsid_addr, &bsid_addr); + int rv = 0; /* * int @@ -145,7 +145,7 @@ vl_api_sr_policy_mod_t_handler (vl_api_sr_policy_mod_t * mp) * u8 operation, ip6_address_t *segments, u32 sl_index, * u32 weight, u8 is_encap) */ - rv = sr_policy_mod ((ip6_address_t *) & mp->bsid_addr, + rv = sr_policy_mod (&bsid_addr, ntohl (mp->sr_policy_index), ntohl (mp->fib_table), mp->operation, @@ -161,12 +161,13 @@ vl_api_sr_policy_del_t_handler (vl_api_sr_policy_del_t * mp) { vl_api_sr_policy_del_reply_t *rmp; int rv = 0; + ip6_address_t bsid_addr; /* * int * sr_policy_del (ip6_address_t *bsid, u32 index) */ - rv = sr_policy_del ((ip6_address_t *) & mp->bsid_addr, - ntohl (mp->sr_policy_index)); + ip6_address_decode (mp->bsid_addr, &bsid_addr); + rv = sr_policy_del (&bsid_addr, ntohl (mp->sr_policy_index)); REPLY_MACRO (VL_API_SR_POLICY_DEL_REPLY); } @@ -176,7 +177,10 @@ vl_api_sr_set_encap_source_t_handler (vl_api_sr_set_encap_source_t * mp) { vl_api_sr_set_encap_source_reply_t *rmp; int rv = 0; - sr_set_source ((ip6_address_t *) & mp->encaps_source); + ip6_address_t encaps_source; + + ip6_address_decode (mp->encaps_source, &encaps_source); + sr_set_source (&encaps_source); REPLY_MACRO (VL_API_SR_SET_ENCAP_SOURCE_REPLY); } @@ -200,21 +204,27 @@ static void vl_api_sr_steering_add_del_t_handler { vl_api_sr_steering_add_del_reply_t *rmp; int rv = 0; + ip6_address_t bsid_addr; + ip46_address_t prefix_addr; /* * int * sr_steering_policy(int is_del, ip6_address_t *bsid, u32 sr_policy_index, * u32 table_id, ip46_address_t *prefix, u32 mask_width, u32 sw_if_index, * u8 traffic_type) */ + + ip6_address_decode (mp->bsid_addr, &bsid_addr); + ip_address_decode (&mp->prefix.address, &prefix_addr); + if (mp->traffic_type == SR_STEER_L2) VALIDATE_SW_IF_INDEX (mp); rv = sr_steering_policy (mp->is_del, - (ip6_address_t *) & mp->bsid_addr, + &bsid_addr, ntohl (mp->sr_policy_index), ntohl (mp->table_id), - (ip46_address_t *) & mp->prefix_addr, - ntohl (mp->mask_width), + &prefix_addr, + ntohl (mp->prefix.len), ntohl (mp->sw_if_index), mp->traffic_type); BAD_SW_IF_INDEX_LABEL; @@ -229,17 +239,12 @@ static void send_sr_localsid_details rmp = vl_msg_api_alloc (sizeof (*rmp)); clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_SR_LOCALSIDS_DETAILS); - clib_memcpy (rmp->addr.addr, &t->localsid, sizeof (ip6_address_t)); + ip6_address_encode (&t->localsid, rmp->addr); rmp->end_psp = t->end_psp; rmp->behavior = htons (t->behavior); rmp->fib_table = htonl (t->fib_table); rmp->vlan_index = htonl (t->vlan_index); - if (ip46_address_is_ip4 (&t->next_hop)) - clib_memcpy (rmp->xconnect_nh_addr4, &t->next_hop.ip4, - sizeof (ip4_address_t)); - else - clib_memcpy (rmp->xconnect_nh_addr6, &t->next_hop.ip6, - sizeof (ip6_address_t)); + ip_address_encode (&t->next_hop, IP46_TYPE_ANY, &rmp->xconnect_nh_addr); if (t->behavior == SR_BEHAVIOR_T || t->behavior == SR_BEHAVIOR_DT6) rmp->xconnect_iface_or_vrf_table = @@ -280,9 +285,10 @@ static void send_sr_policies_details vl_api_sr_policies_details_t *rmp; ip6_sr_main_t *sm = &sr_main; - u32 *sl_index; + u32 *sl_index, slidx = 0; ip6_sr_sl_t *segment_list = 0; - vl_api_srv6_sid_list_t *write_sid_list; + ip6_address_t *segment; + vl_api_srv6_sid_list_t *api_sid_list; rmp = vl_msg_api_alloc (sizeof (*rmp) + vec_len (t->segments_lists) * @@ -293,9 +299,9 @@ static void send_sr_policies_details sizeof (vl_api_srv6_sid_list_t))); rmp->_vl_msg_id = ntohs (VL_API_SR_POLICIES_DETAILS); - clib_memcpy (rmp->bsid.addr, &t->bsid, sizeof (ip6_address_t)); + ip6_address_encode (&t->bsid, rmp->bsid); rmp->is_encap = t->is_encap; - rmp->type = t->type; + rmp->is_spray = t->type; rmp->fib_table = htonl (t->fib_table); rmp->num_sid_lists = vec_len (t->segments_lists); @@ -303,11 +309,16 @@ static void send_sr_policies_details vec_foreach (sl_index, t->segments_lists) { segment_list = pool_elt_at_index (sm->sid_lists, *sl_index); - write_sid_list = &rmp->sid_lists[sl_index - t->segments_lists]; - write_sid_list->num_sids = vec_len (segment_list->segments); - write_sid_list->weight = htonl (segment_list->weight); - clib_memcpy (write_sid_list->sids, segment_list->segments, - vec_len (segment_list->segments) * sizeof (ip6_address_t)); + + api_sid_list = &rmp->sid_lists[sl_index - t->segments_lists]; + + api_sid_list->num_sids = vec_len (segment_list->segments); + api_sid_list->weight = htonl (segment_list->weight); + + vec_foreach (segment, segment_list->segments) + { + ip6_address_encode (segment, api_sid_list->sids[slidx++]); + } } rmp->context = context; @@ -346,18 +357,14 @@ static void send_sr_steering_pol_details //Get the SR policy BSID ip6_sr_policy_t *p; p = pool_elt_at_index (sm->sr_policies, t->sr_policy); - clib_memcpy (rmp->bsid.addr, &p->bsid, sizeof (ip6_address_t)); + ip6_address_encode (&p->bsid, rmp->bsid); //Get the steering rmp->traffic_type = t->classify.traffic_type; rmp->fib_table = htonl (t->classify.l3.fib_table); - rmp->mask_width = htonl (t->classify.l3.mask_width); - if (ip46_address_is_ip4 (&t->classify.l3.prefix)) - clib_memcpy (rmp->prefix_addr, &t->classify.l3.prefix.ip4, - sizeof (ip4_address_t)); - else - clib_memcpy (rmp->prefix_addr, &t->classify.l3.prefix.ip6, - sizeof (ip6_address_t)); + ip_address_encode (&t->classify.l3.prefix, IP46_TYPE_ANY, + &rmp->prefix.address); + rmp->prefix.len = htonl (t->classify.l3.mask_width); rmp->sw_if_index = htonl (t->classify.l2.sw_if_index); diff --git a/src/vnet/srv6/sr_types.api b/src/vnet/srv6/sr_types.api new file mode 100644 index 00000000000..ba99a325544 --- /dev/null +++ b/src/vnet/srv6/sr_types.api @@ -0,0 +1,45 @@ +/* Hey Emacs use -*- mode: C -*- */ +/* + * Copyright (c) 2015-2016 Cisco 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. + */ + +enum sr_policy_op : u8 +{ + SR_POLICY_OP_API_NONE = 0, + SR_POLICY_OP_API_ADD = 1, + SR_POLICY_OP_API_DEL = 2, + SR_POLICY_OP_API_MOD = 3, + +}; + +enum sr_behavior : u8 +{ + SR_BEHAVIOR_API_END = 1, + SR_BEHAVIOR_API_X = 2, + SR_BEHAVIOR_API_T = 3, + SR_BEHAVIOR_API_D_FIRST = 4, /* Unused. Separator in between regular and D */ + SR_BEHAVIOR_API_DX2 = 5, + SR_BEHAVIOR_API_DX6 = 6, + SR_BEHAVIOR_API_DX4 = 7, + SR_BEHAVIOR_API_DT6 = 8, + SR_BEHAVIOR_API_DT4 = 9, + SR_BEHAVIOR_API_LAST = 10, /* Must always be the last one */ +}; + +enum sr_steer : u8 +{ + SR_STEER_API_L2 = 2, + SR_STEER_API_IPV4 = 4, + SR_STEER_API_IPV6 = 6, +}; diff --git a/src/vpp/api/custom_dump.c b/src/vpp/api/custom_dump.c index f9524a9de58..657a5802f47 100644 --- a/src/vpp/api/custom_dump.c +++ b/src/vpp/api/custom_dump.c @@ -1078,7 +1078,7 @@ static void *vl_api_sr_localsid_add_del_t_print { case SR_BEHAVIOR_END: s = format (s, "Address: %U\nBehavior: End", - format_ip6_address, (ip6_address_t *) mp->localsid.addr); + format_ip6_address, (ip6_address_t *) mp->localsid); s = format (s, (mp->end_psp ? "End.PSP: True" : "End.PSP: False")); break; case SR_BEHAVIOR_X: @@ -1086,9 +1086,9 @@ static void *vl_api_sr_localsid_add_del_t_print format (s, "Address: %U\nBehavior: X (Endpoint with Layer-3 cross-connect)" "\nIface: %U\nNext hop: %U", format_ip6_address, - (ip6_address_t *) mp->localsid.addr, + (ip6_address_t *) mp->localsid, format_vnet_sw_if_index_name, vnm, (mp->sw_if_index), - format_ip6_address, (ip6_address_t *) mp->nh_addr6); + format_ip6_address, (ip6_address_t *) mp->nh_addr.un.ip6); s = format (s, (mp->end_psp ? "End.PSP: True" : "End.PSP: False")); break; case SR_BEHAVIOR_DX4: @@ -1096,25 +1096,25 @@ static void *vl_api_sr_localsid_add_del_t_print format (s, "Address: %U\nBehavior: DX4 (Endpoint with decapsulation with IPv4 cross-connect)" "\nIface: %U\nNext hop: %U", format_ip6_address, - (ip6_address_t *) mp->localsid.addr, + (ip6_address_t *) mp->localsid, format_vnet_sw_if_index_name, vnm, (mp->sw_if_index), - format_ip4_address, (ip4_address_t *) mp->nh_addr4); + format_ip4_address, (ip4_address_t *) mp->nh_addr.un.ip4); break; case SR_BEHAVIOR_DX6: s = format (s, "Address: %U\nBehavior: DX6 (Endpoint with decapsulation with IPv6 cross-connect)" "\nIface: %UNext hop: %U", format_ip6_address, - (ip6_address_t *) mp->localsid.addr, + (ip6_address_t *) mp->localsid, format_vnet_sw_if_index_name, vnm, (mp->sw_if_index), - format_ip6_address, (ip6_address_t *) mp->nh_addr6); + format_ip6_address, (ip6_address_t *) mp->nh_addr.un.ip6); break; case SR_BEHAVIOR_DX2: s = format (s, "Address: %U\nBehavior: DX2 (Endpoint with decapulation and Layer-2 cross-connect)" "\nIface: %U", format_ip6_address, - (ip6_address_t *) mp->localsid.addr, + (ip6_address_t *) mp->localsid, format_vnet_sw_if_index_name, vnm, (mp->sw_if_index)); break; case SR_BEHAVIOR_DT6: @@ -1122,20 +1122,20 @@ static void *vl_api_sr_localsid_add_del_t_print format (s, "Address: %U\nBehavior: DT6 (Endpoint with decapsulation and specific IPv6 table lookup)" "\nTable: %u", format_ip6_address, - (ip6_address_t *) mp->localsid.addr, (mp->fib_table)); + (ip6_address_t *) mp->localsid, (mp->fib_table)); break; case SR_BEHAVIOR_DT4: s = format (s, "Address: %U\nBehavior: DT4 (Endpoint with decapsulation and specific IPv4 table lookup)" "\nTable: %u", format_ip6_address, - (ip6_address_t *) mp->localsid.addr, (mp->fib_table)); + (ip6_address_t *) mp->localsid, (mp->fib_table)); break; default: if (mp->behavior >= SR_BEHAVIOR_LAST) { s = format (s, "Address: %U\n Behavior: %u", - format_ip6_address, (ip6_address_t *) mp->localsid.addr, + format_ip6_address, (ip6_address_t *) mp->localsid, mp->behavior); } else @@ -1162,11 +1162,13 @@ static void *vl_api_sr_steering_add_del_t_print break; case SR_STEER_IPV4: s = format (s, "Traffic type: IPv4 %U/%u", format_ip4_address, - (ip4_address_t *) mp->prefix_addr, (mp->mask_width)); + (ip4_address_t *) mp->prefix.address.un.ip4, + (mp->prefix.len)); break; case SR_STEER_IPV6: s = format (s, "Traffic type: IPv6 %U/%u", format_ip6_address, - (ip6_address_t *) mp->prefix_addr, (mp->mask_width)); + (ip6_address_t *) mp->prefix.address.un.ip6, + (mp->prefix.len)); break; default: s = format (s, "Traffic type: Unknown(%u)", mp->traffic_type); @@ -1210,7 +1212,7 @@ static void *vl_api_sr_policy_add_t_print s = format (s, "FIB_table: %u", (mp->fib_table)); - s = format (s, (mp->type ? "Type: Default" : "Type: Spray")); + s = format (s, (mp->is_spray ? "Type: Default" : "Type: Spray")); s = format (s, "SID list weight: %u", (mp->weight)); diff --git a/test/vpp_papi_provider.py b/test/vpp_papi_provider.py index 52ce492adbd..651e07a98b1 100644 --- a/test/vpp_papi_provider.py +++ b/test/vpp_papi_provider.py @@ -925,127 +925,6 @@ class VppPapiProvider(object): return self.api(self.papi.sr_mpls_policy_del, {'bsid': bsid}) - def sr_localsid_add_del(self, - localsid, - behavior, - nh_addr4, - nh_addr6, - is_del=0, - end_psp=0, - sw_if_index=0xFFFFFFFF, - vlan_index=0, - fib_table=0, - ): - """ Add/del IPv6 SR local-SID. - - :param localsid: - :param behavior: END=1; END.X=2; END.DX2=4; END.DX6=5; - :param behavior: END.DX4=6; END.DT6=7; END.DT4=8 - :param nh_addr4: - :param nh_addr6: - :param is_del: (Default value = 0) - :param end_psp: (Default value = 0) - :param sw_if_index: (Default value = 0xFFFFFFFF) - :param vlan_index: (Default value = 0) - :param fib_table: (Default value = 0) - """ - return self.api( - self.papi.sr_localsid_add_del, - {'is_del': is_del, - 'localsid': localsid, - 'end_psp': end_psp, - 'behavior': behavior, - 'sw_if_index': sw_if_index, - 'vlan_index': vlan_index, - 'fib_table': fib_table, - 'nh_addr4': nh_addr4, - 'nh_addr6': nh_addr6 - } - ) - - def sr_policy_add( - self, - bsid_addr, - weight=1, - is_encap=1, - type=0, - fib_table=0, - n_segments=0, - segments=[]): - """ - :param bsid_addr: bindingSID of the SR Policy - :param weight: weight of the sid list. optional. (default: 1) - :param is_encap: (bool) whether SR policy should Encap or SRH insert \ - (default: Encap) - :param type: type/behavior of the SR policy. (default or spray) \ - (default: default) - :param fib_table: VRF where to install the FIB entry for the BSID \ - (default: 0) - :param n_segments: number of segments \ - (default: 0) - :param segments: a vector of IPv6 address composing the segment list \ - (default: []) - """ - return self.api( - self.papi.sr_policy_add, - {'bsid_addr': bsid_addr, - 'weight': weight, - 'is_encap': is_encap, - 'type': type, - 'fib_table': fib_table, - 'n_segments': n_segments, - 'segments': segments - } - ) - - def sr_policy_del( - self, - bsid_addr, - sr_policy_index=0): - """ - :param bsid: bindingSID of the SR Policy - :param sr_policy_index: index of the sr policy (default: 0) - """ - return self.api( - self.papi.sr_policy_del, - {'bsid_addr': bsid_addr, - 'sr_policy_index': sr_policy_index - }) - - def sr_steering_add_del( - self, - is_del, - bsid_addr, - sr_policy_index, - table_id, - prefix_addr, - mask_width, - sw_if_index, - traffic_type): - """ - Steer traffic L2 and L3 traffic through a given SR policy - - :param is_del: delete or add - :param bsid_addr: bindingSID of the SR Policy (alt to sr_policy_index) - :param sr_policy: is the index of the SR Policy (alt to bsid) - :param table_id: is the VRF where to install the FIB entry for the BSID - :param prefix_addr: is the IPv4/v6 address for L3 traffic type - :param mask_width: is the mask for L3 traffic type - :param sw_if_index: is the incoming interface for L2 traffic - :param traffic_type: type of traffic (IPv4: 4, IPv6: 6, L2: 2) - """ - return self.api( - self.papi.sr_steering_add_del, - {'is_del': is_del, - 'bsid_addr': bsid_addr, - 'sr_policy_index': sr_policy_index, - 'table_id': table_id, - 'prefix_addr': prefix_addr, - 'mask_width': mask_width, - 'sw_if_index': sw_if_index, - 'traffic_type': traffic_type - }) - def acl_add_replace(self, acl_index, r, tag='', expected_retval=0): """Add/replace an ACL -- 2.16.6