summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorPaul Vinciguerra <pvinci@vinciconsulting.com>2020-04-28 00:27:38 -0400
committerPaul Vinciguerra <pvinci@vinciconsulting.com>2020-04-28 15:43:28 +0000
commite64e5fff4ddea88f386657c5d95ae8dc78138d20 (patch)
treea4b91682810f8d64dfe2ae0934c21d1f67b94f9d /src
parent58db6e16cf4f3bb1740ca2f62d7d887baad58d63 (diff)
tests: implement ipaddress convenience methods
Add vpp specific properties to ip addresses for use in the api. .vapi_af -- returns [ADDRESS_IP4, ADDRESS_IP6] .vapi_af_name -- returns the string ['ip4', 'ip6'] Update tests to demonstrate usage. Type: feature Change-Id: I43447a1522769d99f89debdc714c51700068d771 Signed-off-by: Paul Vinciguerra <pvinci@vinciconsulting.com>
Diffstat (limited to 'src')
-rw-r--r--src/vnet/ip-neighbor/ip_neighbor.api16
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_format.py5
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_papi.py30
3 files changed, 42 insertions, 9 deletions
diff --git a/src/vnet/ip-neighbor/ip_neighbor.api b/src/vnet/ip-neighbor/ip_neighbor.api
index fc8f8222189..473024a49ea 100644
--- a/src/vnet/ip-neighbor/ip_neighbor.api
+++ b/src/vnet/ip-neighbor/ip_neighbor.api
@@ -41,7 +41,7 @@ enum ip_neighbor_flags: u8
/** \brief IP neighbor
@param sw_if_index - interface used to reach neighbor
- @param flags - flags for the nieghbor
+ @param flags - flags for the neighbor
@param mac_address - l2 address of the neighbor
@param ip_address - ip4 or ip6 address of the neighbor
*/
@@ -56,7 +56,7 @@ typedef ip_neighbor {
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param is_add - 1 to add neighbor, 0 to delete
- @param neighbor - the neighor to add/remove
+ @param neighbor - the neighbor to add/remove
*/
define ip_neighbor_add_del
{
@@ -70,7 +70,7 @@ define ip_neighbor_add_del
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
@param retval - return value
- @param stats_index - the index to use for this neighbor in the stats segement
+ @param stats_index - the index to use for this neighbor in the stats segment
*/
define ip_neighbor_add_del_reply
{
@@ -79,10 +79,10 @@ define ip_neighbor_add_del_reply
u32 stats_index;
};
-/** \brief Dump IP neighboors
+/** \brief Dump IP neighbors
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
- @param sw_if_index - the interface to dump neighboors, ~0 == all
+ @param sw_if_index - the interface to dump neighbors, ~0 == all
@param af - address family is ipv[6|4]
*/
define ip_neighbor_dump
@@ -93,7 +93,7 @@ define ip_neighbor_dump
vl_api_address_family_t af;
};
-/** \brief IP neighboors dump response
+/** \brief IP neighbors dump response
@param context - sender context which was passed in the request
@param age - time between last update and sending this message, in seconds
@param neighbour - the neighbor
@@ -132,7 +132,7 @@ autoreply define ip_neighbor_config
has a different set of neighbours it than VPP
currently has. The CP would thus like to 'replace' VPP's set
only by specifying what the new set shall be, i.e. it is not
- going to delete anything that already eixts, rather, is wants any
+ going to delete anything that already exists, rather, it wants any
unspecified neighbors deleted implicitly.
The CP declares the start of this procedure with this replace_begin
API Call, and when it has populated all neighbours it wants, it calls
@@ -163,7 +163,7 @@ autoreply define ip_neighbor_replace_end
u32 context;
};
-/** \brief Register for IP4 ARP resolution event on receing ARP reply or
+/** \brief Register for IP4 ARP resolution event on receiving ARP reply or
MAC/IP info from ARP requests in L2 BDs
@param client_index - opaque cookie to identify the sender
@param context - sender context, to match reply w/ request
diff --git a/src/vpp-api/python/vpp_papi/vpp_format.py b/src/vpp-api/python/vpp_papi/vpp_format.py
index 3e836c9da6b..4c26463bbb5 100644
--- a/src/vpp-api/python/vpp_papi/vpp_format.py
+++ b/src/vpp-api/python/vpp_papi/vpp_format.py
@@ -27,6 +27,11 @@ except NameError:
ADDRESS_IP4 = 0
ADDRESS_IP6 = 1
+
+def verify_enum_hint(e):
+ return (e.ADDRESS_IP4.value == ADDRESS_IP4) and\
+ (e.ADDRESS_IP6.value == ADDRESS_IP6)
+
#
# Type conversion for input arguments and return values
#
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index 7f6efbbae07..6c17fa88c95 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -17,6 +17,7 @@
from __future__ import print_function
from __future__ import absolute_import
import ctypes
+import ipaddress
import sys
import multiprocessing as mp
import os
@@ -28,6 +29,7 @@ import fnmatch
import weakref
import atexit
import time
+from . vpp_format import verify_enum_hint
from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType
from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias
@@ -77,6 +79,26 @@ else:
return d.items()
+def add_convenience_methods():
+ # provide convenience methods to IP[46]Address.vapi_af
+ def _vapi_af(self):
+ if 6 == self._version:
+ return VppEnum.vl_api_address_family_t.ADDRESS_IP6.value
+ if 4 == self._version:
+ return VppEnum.vl_api_address_family_t.ADDRESS_IP4.value
+ raise ValueError("Invalid _version.")
+
+ def _vapi_af_name(self):
+ if 6 == self._version:
+ return 'ip6'
+ if 4 == self._version:
+ return 'ip4'
+ raise ValueError("Invalid _version.")
+
+ ipaddress._IPAddressBase.vapi_af = property(_vapi_af)
+ ipaddress._IPAddressBase.vapi_af_name = property(_vapi_af_name)
+
+
class VppApiDynamicMethodHolder(object):
pass
@@ -113,6 +135,7 @@ class VPPRuntimeError(RuntimeError):
class VPPValueError(ValueError):
pass
+
class VPPApiJSONFiles(object):
@classmethod
def find_api_dir(cls, dirs):
@@ -295,6 +318,7 @@ class VPPApiJSONFiles(object):
self.logger.error('Not implemented error for {}'.format(m[0]))
return messages, services
+
class VPPApiClient(object):
"""VPP interface.
@@ -383,16 +407,20 @@ class VPPApiClient(object):
# Basic sanity check
if len(self.messages) == 0 and not testmode:
raise VPPValueError(1, 'Missing JSON message definitions')
+ if not(verify_enum_hint(VppEnum.vl_api_address_family_t)):
+ raise VPPRuntimeError("Invalid address family hints. "
+ "Cannot continue.")
self.transport = VppTransport(self, read_timeout=read_timeout,
server_address=server_address)
# Make sure we allow VPP to clean up the message rings.
atexit.register(vpp_atexit, weakref.ref(self))
+ add_convenience_methods()
+
def get_function(self, name):
return getattr(self._api, name)
-
class ContextId(object):
"""Multiprocessing-safe provider of unique context IDs."""
def __init__(self):