PAPI: Expose API enums to tests / applications
e.g:
from vpp_papi import VppEnum
VppEnum.vl_api_address_family_t.ADDRESS_IP4
Change-Id: I10c22d57234a1a06e98a889cf80b19085b468ed3
Signed-off-by: Ole Troan <ot@cisco.com>
diff --git a/test/vpp_ip.py b/test/vpp_ip.py
index e44e6b5..e92c919 100644
--- a/test/vpp_ip.py
+++ b/test/vpp_ip.py
@@ -5,11 +5,7 @@
from ipaddress import ip_address
from socket import AF_INET, AF_INET6
-
-
-class IpAddressFamily:
- ADDRESS_IP4 = 0
- ADDRESS_IP6 = 1
+from vpp_papi import VppEnum
class DpoProto:
@@ -86,12 +82,12 @@
def encode(self):
if self.addr.version is 6:
return {
- 'af': IpAddressFamily.ADDRESS_IP6,
+ 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP6,
'un': self.addr.encode()
}
else:
return {
- 'af': IpAddressFamily.ADDRESS_IP4,
+ 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP4,
'un': self.addr.encode()
}
@@ -101,10 +97,12 @@
elif hasattr(other, "af") and hasattr(other, "un"):
# a vp_api_address_t
if 4 is self.version:
- return other.af == IpAddressFamily.ADDRESS_IP4 and \
+ return other.af == \
+ VppEnum.vl_api_address_family_t.ADDRESS_IP4 and \
other.un == self.addr
else:
- return other.af == IpAddressFamily.ADDRESS_IP6 and \
+ return other.af == \
+ VppEnum.vl_api_address_family_t.ADDRESS_IP6 and \
other.un == self.addr
else:
raise Exception("Comparing VppIpAddress:%s with unknown type: %s" %
@@ -202,7 +200,7 @@
if 6 is self.ip_saddr.version:
prefix = {
- 'af': IpAddressFamily.ADDRESS_IP6,
+ 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP6,
'grp_address': {
'ip6': {
'address': self.ip_gaddr.packed
@@ -217,7 +215,7 @@
}
else:
prefix = {
- 'af': IpAddressFamily.ADDRESS_IP4,
+ 'af': VppEnum.vl_api_address_family_t.ADDRESS_IP4,
'grp_address': {
'ip4': {
'address': self.ip_gaddr.packed