diff options
author | Paul Vinciguerra <pvinci@vinciconsulting.com> | 2019-06-06 14:07:55 -0400 |
---|---|---|
committer | Neale Ranns <nranns@cisco.com> | 2019-06-26 11:36:57 +0000 |
commit | ab05508e1eb96749b68de8ccd2f6f88ff3e64fad (patch) | |
tree | 05f290dfff68a24810d0a3bdb2f7227ac4608114 | |
parent | 941da4a224bbfc153bfe7c2344ae00e294d92798 (diff) |
api: refactor format_vl_api_prefix_t return keys
format_vl_api_prefix_t returns a dict with keys 'address' and 'address_length',
but other format_vl_api_prefix functions return a dict with 'prefix', and 'len'.
Refactor all format_vl_api_prefix_t to return consistent keys 'address' and 'len'.
Type: refactor
Change-Id: I5f9558fc2da8742a303266e011102f5b2db80aad
Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
-rw-r--r-- | extras/vom/vom/api_types.cpp | 4 | ||||
-rw-r--r-- | src/plugins/gbp/gbp_api_print.h | 2 | ||||
-rw-r--r-- | src/plugins/map/map_api.c | 12 | ||||
-rw-r--r-- | src/plugins/nat/nat_api.c | 6 | ||||
-rw-r--r-- | src/vat/api_format.c | 14 | ||||
-rw-r--r-- | src/vnet/ip/ip_types.api | 6 | ||||
-rw-r--r-- | src/vnet/ip/ip_types_api.c | 4 | ||||
-rw-r--r-- | src/vnet/ipip/ipip_api.c | 4 | ||||
-rwxr-xr-x | src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py | 2 | ||||
-rw-r--r-- | src/vpp-api/python/vpp_papi/vpp_format.py | 24 | ||||
-rw-r--r-- | src/vpp/api/types.c | 4 | ||||
-rw-r--r-- | test/test_ip6.py | 42 | ||||
-rw-r--r-- | test/vpp_interface.py | 12 | ||||
-rw-r--r-- | test/vpp_ip.py | 6 |
14 files changed, 72 insertions, 70 deletions
diff --git a/extras/vom/vom/api_types.cpp b/extras/vom/vom/api_types.cpp index 721034fc810..5a46571ddea 100644 --- a/extras/vom/vom/api_types.cpp +++ b/extras/vom/vom/api_types.cpp @@ -192,7 +192,7 @@ from_api(const vapi_type_mac_address& v) route::prefix_t from_api(const vapi_type_prefix& v) { - return route::prefix_t(from_api(v.address), v.address_length); + return route::prefix_t(from_api(v.address), v.len); } vapi_type_prefix @@ -200,7 +200,7 @@ to_api(const route::prefix_t& p) { vapi_type_prefix v; to_api(p.address(), v.address); - v.address_length = p.mask_width(); + v.len = p.mask_width(); return v; } diff --git a/src/plugins/gbp/gbp_api_print.h b/src/plugins/gbp/gbp_api_print.h index 21b351984b8..7598306ec5c 100644 --- a/src/plugins/gbp/gbp_api_print.h +++ b/src/plugins/gbp/gbp_api_print.h @@ -218,7 +218,7 @@ vl_api_gbp_subnet_add_del_t_print (vl_api_gbp_subnet_add_del_t * a, s = format (s, "type %d ", ntohl (a->subnet.type)); s = format (s, "prefix %U/%d", format_vl_api_address, - &a->subnet.prefix.address, a->subnet.prefix.address_length); + &a->subnet.prefix.address, a->subnet.prefix.len); s = format (s, "\n"); diff --git a/src/plugins/map/map_api.c b/src/plugins/map/map_api.c index a64d90cd452..1d2614ccb5d 100644 --- a/src/plugins/map/map_api.c +++ b/src/plugins/map/map_api.c @@ -56,11 +56,11 @@ vl_api_map_add_domain_t_handler (vl_api_map_add_domain_t * mp) u8 *vtag = 0; vtag = vl_api_from_api_to_vec (&mp->tag); rv = - map_create_domain ((ip4_address_t *) & mp->ip4_prefix.prefix, + map_create_domain ((ip4_address_t *) & mp->ip4_prefix.address, mp->ip4_prefix.len, - (ip6_address_t *) & mp->ip6_prefix.prefix, + (ip6_address_t *) & mp->ip6_prefix.address, mp->ip6_prefix.len, - (ip6_address_t *) & mp->ip6_src.prefix, + (ip6_address_t *) & mp->ip6_src.address, mp->ip6_src.len, mp->ea_bits_len, mp->psid_offset, mp->psid_length, &index, ntohs (mp->mtu), flags, vtag); vec_free (vtag); @@ -128,9 +128,9 @@ vl_api_map_domain_dump_t_handler (vl_api_map_domain_dump_t * mp) rmp->_vl_msg_id = htons(VL_API_MAP_DOMAIN_DETAILS + mm->msg_id_base); rmp->context = mp->context; rmp->domain_index = htonl(map_domain_index); - clib_memcpy(&rmp->ip6_prefix.prefix, &d->ip6_prefix, sizeof(rmp->ip6_prefix.prefix)); - clib_memcpy(&rmp->ip4_prefix.prefix, &d->ip4_prefix, sizeof(rmp->ip4_prefix.prefix)); - clib_memcpy(&rmp->ip6_src.prefix, &d->ip6_src, sizeof(rmp->ip6_src.prefix)); + clib_memcpy(&rmp->ip6_prefix.address, &d->ip6_prefix, sizeof(rmp->ip6_prefix.address)); + clib_memcpy(&rmp->ip4_prefix.address, &d->ip4_prefix, sizeof(rmp->ip4_prefix.address)); + clib_memcpy(&rmp->ip6_src.address, &d->ip6_src, sizeof(rmp->ip6_src.address)); rmp->ip6_prefix.len = d->ip6_prefix_len; rmp->ip4_prefix.len = d->ip4_prefix_len; rmp->ip6_src.len = d->ip6_src_len; diff --git a/src/plugins/nat/nat_api.c b/src/plugins/nat/nat_api.c index 1dad4e42728..9cb27448fdf 100644 --- a/src/plugins/nat/nat_api.c +++ b/src/plugins/nat/nat_api.c @@ -3007,7 +3007,7 @@ vl_api_nat64_add_del_prefix_t_handler (vl_api_nat64_add_del_prefix_t * mp) ip6_address_t prefix; int rv = 0; - memcpy (&prefix.as_u8, mp->prefix.prefix, 16); + memcpy (&prefix.as_u8, mp->prefix.address, 16); rv = nat64_add_del_prefix (&prefix, mp->prefix.len, @@ -3022,7 +3022,7 @@ vl_api_nat64_add_del_prefix_t_print (vl_api_nat64_add_del_prefix_t * mp, u8 *s; s = format (0, "SCRIPT: nat64_add_del_prefix %U/%u vrf_id %u %s\n", - format_ip6_address, mp->prefix.prefix, mp->prefix.len, + format_ip6_address, mp->prefix.address, mp->prefix.len, ntohl (mp->vrf_id), mp->is_add ? "" : "del"); FINISH; @@ -3038,7 +3038,7 @@ nat64_api_prefix_walk (nat64_prefix_t * p, void *arg) rmp = vl_msg_api_alloc (sizeof (*rmp)); clib_memset (rmp, 0, sizeof (*rmp)); rmp->_vl_msg_id = ntohs (VL_API_NAT64_PREFIX_DETAILS + sm->msg_id_base); - clib_memcpy (rmp->prefix.prefix, &(p->prefix), 16); + clib_memcpy (rmp->prefix.address, &(p->prefix), 16); rmp->prefix.len = p->plen; rmp->vrf_id = ntohl (p->vrf_id); rmp->context = ctx->context; diff --git a/src/vat/api_format.c b/src/vat/api_format.c index 992060df394..d9c13ad8644 100644 --- a/src/vat/api_format.c +++ b/src/vat/api_format.c @@ -788,8 +788,8 @@ static void vat_json_object_add_prefix (vat_json_node_t * node, const vl_api_prefix_t * prefix) { - vat_json_object_add_uint (node, "address_length", prefix->address_length); - vat_json_object_add_address (node, "prefix", &prefix->address); + vat_json_object_add_uint (node, "len", prefix->len); + vat_json_object_add_address (node, "address", &prefix->address); } static void vl_api_create_loopback_reply_t_handler @@ -2663,7 +2663,7 @@ static void vl_api_ip_address_details_t_handler address = vec_elt_at_index (addresses, vec_len (addresses) - 1); clib_memcpy (&address->ip, &mp->prefix.address.un, sizeof (address->ip)); - address->prefix_length = mp->prefix.address_length; + address->prefix_length = mp->prefix.len; #undef addresses } @@ -19201,8 +19201,7 @@ vl_api_ip_route_details_t_handler (vl_api_ip_route_details_t * mp) print (vam->ofp, "table-id %d, prefix %U/%d", ntohl (mp->route.table_id), - format_ip46_address, - mp->route.prefix.address, mp->route.prefix.address_length); + format_ip46_address, mp->route.prefix.address, mp->route.prefix.len); for (i = 0; i < count; i++) { fp = &mp->route.paths[i]; @@ -19242,8 +19241,7 @@ static void vl_api_ip_route_details_t_handler_json clib_memcpy (&ip4, &mp->route.prefix.address.un.ip4, sizeof (ip4)); vat_json_object_add_ip4 (node, "prefix", ip4); } - vat_json_object_add_uint (node, "mask_length", - mp->route.prefix.address_length); + vat_json_object_add_uint (node, "mask_length", mp->route.prefix.len); vat_json_object_add_uint (node, "path_count", count); for (i = 0; i < count; i++) { @@ -21310,7 +21308,7 @@ api_ip_container_proxy_add_del (vat_main_t * vam) else break; } - if (sw_if_index == ~0 || pfx.address_length == 0) + if (sw_if_index == ~0 || pfx.len == 0) { errmsg ("address and sw_if_index must be set"); return -99; diff --git a/src/vnet/ip/ip_types.api b/src/vnet/ip/ip_types.api index 4c685670d5e..b962e1a6f31 100644 --- a/src/vnet/ip/ip_types.api +++ b/src/vnet/ip/ip_types.api @@ -41,7 +41,7 @@ typedef address { typedef prefix { vl_api_address_t address; - u8 address_length; + u8 len; }; typedef mprefix { @@ -52,11 +52,11 @@ typedef mprefix { }; typedef ip6_prefix { - vl_api_ip6_address_t prefix; + vl_api_ip6_address_t address; u8 len; }; typedef ip4_prefix { - vl_api_ip4_address_t prefix; + vl_api_ip4_address_t address; u8 len; }; diff --git a/src/vnet/ip/ip_types_api.c b/src/vnet/ip/ip_types_api.c index 6ad2c366dff..0343d2001ad 100644 --- a/src/vnet/ip/ip_types_api.c +++ b/src/vnet/ip/ip_types_api.c @@ -196,7 +196,7 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out) out->fp_proto = FIB_PROTOCOL_IP6; break; } - out->fp_len = in->address_length; + out->fp_len = in->len; out->___fp___pad = 0; ip_address_decode (&in->address, &out->fp_addr); } @@ -204,7 +204,7 @@ ip_prefix_decode (const vl_api_prefix_t * in, fib_prefix_t * out) void ip_prefix_encode (const fib_prefix_t * in, vl_api_prefix_t * out) { - out->address_length = in->fp_len; + out->len = in->fp_len; ip_address_encode (&in->fp_addr, fib_proto_to_ip46 (in->fp_proto), &out->address); } diff --git a/src/vnet/ipip/ipip_api.c b/src/vnet/ipip/ipip_api.c index 62a99659eee..d88047560a9 100644 --- a/src/vnet/ipip/ipip_api.c +++ b/src/vnet/ipip/ipip_api.c @@ -180,9 +180,9 @@ vl_api_ipip_6rd_add_tunnel_t_handler (vl_api_ipip_6rd_add_tunnel_t * mp) } else { - rv = sixrd_add_tunnel ((ip6_address_t *) & mp->ip6_prefix.prefix, + rv = sixrd_add_tunnel ((ip6_address_t *) & mp->ip6_prefix.address, mp->ip6_prefix.len, - (ip4_address_t *) & mp->ip4_prefix.prefix, + (ip4_address_t *) & mp->ip4_prefix.address, mp->ip4_prefix.len, (ip4_address_t *) & mp->ip4_src, mp->security_check, diff --git a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py index 74a0a62c021..bddaa9e00c2 100755 --- a/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py +++ b/src/vpp-api/python/vpp_papi/tests/test_vpp_serializer.py @@ -139,7 +139,7 @@ class TestAddType(unittest.TestCase): prefix = VPPType('vl_api_prefix_t', [['vl_api_address_t', 'address'], - ['u8', 'address_length']]) + ['u8', 'len']]) message = VPPMessage('svs', [['vl_api_prefix_t', 'prefix']]) message_addr = VPPMessage('svs_address', diff --git a/src/vpp-api/python/vpp_papi/vpp_format.py b/src/vpp-api/python/vpp_papi/vpp_format.py index 415070c4196..d54106b245c 100644 --- a/src/vpp-api/python/vpp_papi/vpp_format.py +++ b/src/vpp-api/python/vpp_papi/vpp_format.py @@ -45,29 +45,29 @@ def format_vl_api_address_t(args): def format_vl_api_prefix_t(args): if isinstance(args, (ipaddress.IPv4Network, ipaddress.IPv6Network)): - return {'prefix': format_vl_api_address_t( + return {'address': format_vl_api_address_t( text_type(args.network_address)), 'len': int(args.prefixlen)} p, length = args.split('/') return {'address': format_vl_api_address_t(p), - 'address_length': int(length)} + 'len': int(length)} def format_vl_api_ip6_prefix_t(args): if isinstance(args, ipaddress.IPv6Network): - return {'prefix': args.network_address.packed, + return {'address': args.network_address.packed, 'len': int(args.prefixlen)} p, length = args.split('/') - return {'prefix': inet_pton(AF_INET6, p), + return {'address': inet_pton(AF_INET6, p), 'len': int(length)} def format_vl_api_ip4_prefix_t(args): if isinstance(args, ipaddress.IPv4Network): - return {'prefix': args.network_address.packed, + return {'address': args.network_address.packed, 'len': int(args.prefixlen)} p, length = args.split('/') - return {'prefix': inet_pton(AF_INET, p), + return {'address': inet_pton(AF_INET, p), 'len': int(length)} @@ -84,13 +84,13 @@ conversion_table = { }, 'vl_api_ip6_prefix_t': { - 'IPv6Network': lambda o: {'prefix': o.network_address.packed, + 'IPv6Network': lambda o: {'address': o.network_address.packed, 'len': o.prefixlen}, 'str': lambda s: format_vl_api_ip6_prefix_t(s) }, 'vl_api_ip4_prefix_t': { - 'IPv4Network': lambda o: {'prefix': o.network_address.packed, + 'IPv4Network': lambda o: {'address': o.network_address.packed, 'len': o.prefixlen}, 'str': lambda s: format_vl_api_ip4_prefix_t(s) }, @@ -129,16 +129,16 @@ def unformat_api_address_t(o): def unformat_api_prefix_t(o): if isinstance(o.address, ipaddress.IPv4Address): - return ipaddress.IPv4Network((o.address, o.address_length), False) + return ipaddress.IPv4Network((o.address, o.len), False) if isinstance(o.address, ipaddress.IPv6Address): - return ipaddress.IPv6Network((o.address, o.address_length), False) + return ipaddress.IPv6Network((o.address, o.len), False) conversion_unpacker_table = { 'vl_api_ip6_address_t': lambda o: ipaddress.IPv6Address(o), - 'vl_api_ip6_prefix_t': lambda o: ipaddress.IPv6Network((o.prefix, o.len)), + 'vl_api_ip6_prefix_t': lambda o: ipaddress.IPv6Network((o.address, o.len)), 'vl_api_ip4_address_t': lambda o: ipaddress.IPv4Address(o), - 'vl_api_ip4_prefix_t': lambda o: ipaddress.IPv4Network((o.prefix, o.len)), + 'vl_api_ip4_prefix_t': lambda o: ipaddress.IPv4Network((o.address, o.len)), 'vl_api_address_t': lambda o: unformat_api_address_t(o), 'vl_api_prefix_t': lambda o: unformat_api_prefix_t(o), 'vl_api_mac_address_t': lambda o: macaddress.MACAddress(o), diff --git a/src/vpp/api/types.c b/src/vpp/api/types.c index 3d556b72bfd..f9993b1883b 100644 --- a/src/vpp/api/types.c +++ b/src/vpp/api/types.c @@ -89,7 +89,7 @@ format_vl_api_prefix (u8 * s, va_list * args) const vl_api_prefix_t *pfx = va_arg (*args, vl_api_prefix_t *); s = format (s, "%U/%d", format_vl_api_address, - &pfx->address, pfx->address_length); + &pfx->address, pfx->len); return s; } @@ -167,7 +167,7 @@ unformat_vl_api_prefix (unformat_input_t * input, va_list * args) vl_api_prefix_t *pfx = va_arg (*args, vl_api_prefix_t *); if (unformat (input, "%U/%d", unformat_vl_api_address, &pfx->address, - &pfx->address_length)) + &pfx->len)) return (1); return (0); } diff --git a/test/test_ip6.py b/test/test_ip6.py index 35061b0b53c..f8295513516 100644 --- a/test/test_ip6.py +++ b/test/test_ip6.py @@ -615,7 +615,7 @@ class TestIPv6(TestIPv6ND): # the options are nested in the scapy packet in way that i cannot # decipher how to decode. this 1st layer of option always returns # nested classes, so a direct obj1=obj2 comparison always fails. - # however, the getlayer(.., 2) does give one instnace. + # however, the getlayer(.., 2) does give one instance. # so we cheat here and construct a new opt instance for comparison rd = ICMPv6NDOptPrefixInfo( prefixlen=raos.prefixlen, @@ -628,7 +628,9 @@ class TestIPv6(TestIPv6ND): rd = rx.getlayer( ICMPv6NDOptPrefixInfo, ii + 2) else: - self.assertEqual(pi_opt, raos) + self.assertEqual(pi_opt, raos, 'Expected: %s, received: %s' + % (pi_opt.show(dump=True), + raos.show(dump=True))) def send_and_expect_ra(self, intf, pkts, remark, dst_ip=None, filter_out_fn=is_ipv6_misc, @@ -743,8 +745,8 @@ class TestIPv6(TestIPv6ND): # # Configure The RA to announce the links prefix # - self.pg0.ip6_ra_prefix(self.pg0.local_ip6, - self.pg0.local_ip6_prefix_len) + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, + self.pg0.local_ip6_prefix_len)) # # RAs should now contain the prefix information option @@ -769,8 +771,8 @@ class TestIPv6(TestIPv6ND): # Change the prefix info to not off-link # L-flag is clear # - self.pg0.ip6_ra_prefix(self.pg0.local_ip6, - self.pg0.local_ip6_prefix_len, + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, + self.pg0.local_ip6_prefix_len), off_link=1) opt = ICMPv6NDOptPrefixInfo( @@ -789,8 +791,8 @@ class TestIPv6(TestIPv6ND): # Change the prefix info to not off-link, no-autoconfig # L and A flag are clear in the advert # - self.pg0.ip6_ra_prefix(self.pg0.local_ip6, - self.pg0.local_ip6_prefix_len, + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, + self.pg0.local_ip6_prefix_len), off_link=1, no_autoconfig=1) @@ -810,8 +812,8 @@ class TestIPv6(TestIPv6ND): # Change the flag settings back to the defaults # L and A flag are set in the advert # - self.pg0.ip6_ra_prefix(self.pg0.local_ip6, - self.pg0.local_ip6_prefix_len) + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, + self.pg0.local_ip6_prefix_len)) opt = ICMPv6NDOptPrefixInfo( prefixlen=self.pg0.local_ip6_prefix_len, @@ -829,8 +831,8 @@ class TestIPv6(TestIPv6ND): # Change the prefix info to not off-link, no-autoconfig # L and A flag are clear in the advert # - self.pg0.ip6_ra_prefix(self.pg0.local_ip6, - self.pg0.local_ip6_prefix_len, + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, + self.pg0.local_ip6_prefix_len), off_link=1, no_autoconfig=1) @@ -850,8 +852,8 @@ class TestIPv6(TestIPv6ND): # Use the reset to defaults option to revert to defaults # L and A flag are clear in the advert # - self.pg0.ip6_ra_prefix(self.pg0.local_ip6, - self.pg0.local_ip6_prefix_len, + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, + self.pg0.local_ip6_prefix_len), use_default=1) opt = ICMPv6NDOptPrefixInfo( @@ -869,8 +871,8 @@ class TestIPv6(TestIPv6ND): # # Advertise Another prefix. With no L-flag/A-flag # - self.pg0.ip6_ra_prefix(self.pg1.local_ip6, - self.pg1.local_ip6_prefix_len, + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6, + self.pg1.local_ip6_prefix_len), off_link=1, no_autoconfig=1) @@ -899,8 +901,8 @@ class TestIPv6(TestIPv6ND): # Remove the first prefix-info - expect the second is still in the # advert # - self.pg0.ip6_ra_prefix(self.pg0.local_ip6, - self.pg0.local_ip6_prefix_len, + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg0.local_ip6, + self.pg0.local_ip6_prefix_len), is_no=1) opt = ICMPv6NDOptPrefixInfo( @@ -918,8 +920,8 @@ class TestIPv6(TestIPv6ND): # # Remove the second prefix-info - expect no prefix-info in the adverts # - self.pg0.ip6_ra_prefix(self.pg1.local_ip6, - self.pg1.local_ip6_prefix_len, + self.pg0.ip6_ra_prefix('%s/%s' % (self.pg1.local_ip6, + self.pg1.local_ip6_prefix_len), is_no=1) self.pg0.ip6_ra_config(send_unicast=1) diff --git a/test/vpp_interface.py b/test/vpp_interface.py index 7b9de828e6c..e8100d362ec 100644 --- a/test/vpp_interface.py +++ b/test/vpp_interface.py @@ -349,14 +349,16 @@ class VppInterface(object): suppress=suppress, send_unicast=send_unicast) - # TODO: This should accept ipaddress object. - def ip6_ra_prefix(self, address, address_length, is_no=0, + def ip6_ra_prefix(self, prefix, is_no=0, off_link=0, no_autoconfig=0, use_default=0): - """Configure IPv6 RA suppress on the VPP interface.""" + """Configure IPv6 RA suppress on the VPP interface. + + prefix can be a string in the format of '<address>/<length_in_bits>' + or ipaddress.ipnetwork object (if strict.)""" + self.test.vapi.sw_interface_ip6nd_ra_prefix( sw_if_index=self.sw_if_index, - prefix={'address': address, - 'address_length': address_length}, + prefix=prefix, use_default=use_default, off_link=off_link, no_autoconfig=no_autoconfig, is_no=is_no) diff --git a/test/vpp_ip.py b/test/vpp_ip.py index 5396e8457e2..3bdfa62d223 100644 --- a/test/vpp_ip.py +++ b/test/vpp_ip.py @@ -163,7 +163,7 @@ class VppIpPrefix(): def encode(self): return {'address': self.addr.encode(), - 'address_length': self.len} + 'len': self.len} @property def version(self): @@ -191,9 +191,9 @@ class VppIpPrefix(): def __eq__(self, other): if isinstance(other, self.__class__): return (self.len == other.len and self.addr == other.addr) - elif hasattr(other, "address") and hasattr(other, "address_length"): + elif hasattr(other, "address") and hasattr(other, "len"): # vl_api_prefix_t - return self.len == other.address_length and \ + return self.len == other.len and \ self.addr == other.address else: _log.error( |