import atexit
import time
from . vpp_format import verify_enum_hint
-from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType
+from . vpp_serializer import VPPType, VPPEnumType, VPPEnumFlagType, VPPUnionType
from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias
try:
logger = logging.getLogger('vpp_papi')
logger.addHandler(logging.NullHandler())
-__all__ = ('FuncWrapper', 'VPP', 'VppApiDynamicMethodHolder',
- 'VppEnum', 'VppEnumType',
+__all__ = ('FuncWrapper', 'VppApiDynamicMethodHolder',
+ 'VppEnum', 'VppEnumType', 'VppEnumFlag',
'VPPIOError', 'VPPRuntimeError', 'VPPValueError',
'VPPApiClient', )
pass
+@metaclass(VppEnumType)
+class VppEnumFlag:
+ pass
+
+
def vpp_atexit(vpp_weakref):
"""Clean up VPP connection on shutdown."""
vpp_instance = vpp_weakref()
vpp_instance.disconnect()
-
-
def add_convenience_methods():
# provide convenience methods to IP[46]Address.vapi_af
def _vapi_af(self):
types[t[0]] = {'type': 'enum', 'data': t}
except KeyError:
pass
-
+ try:
+ for t in api['enumflags']:
+ t[0] = 'vl_api_' + t[0] + '_t'
+ types[t[0]] = {'type': 'enum', 'data': t}
+ except KeyError:
+ pass
try:
for t in api['unions']:
t[0] = 'vl_api_' + t[0] + '_t'
VPPEnumType(t[0], t[1:])
except ValueError:
unresolved[k] = v
+ if not vpp_get_type(k):
+ if v['type'] == 'enumflag':
+ try:
+ VPPEnumFlagType(t[0], t[1:])
+ except ValueError:
+ unresolved[k] = v
elif v['type'] == 'union':
try:
VPPUnionType(t[0], t[1:])
VPPIOError = VPPIOError
- def __init__(self, apifiles=None, testmode=False, async_thread=True,
+ def __init__(self, *, apifiles=None, testmode=False, async_thread=True,
logger=None, loglevel=None,
- read_timeout=5, use_socket=False,
+ read_timeout=5, use_socket=True,
server_address='/run/vpp/api.sock'):
"""Create a VPP API object.
n[1]['avg'], n[1]['max'])
return s
+ def get_field_options(self, msg, fld_name):
+ # when there is an option, the msgdef has 3 elements.
+ # ['u32', 'ring_size', {'default': 1024}]
+ for _def in self.messages[msg].msgdef:
+ if isinstance(_def, list) and \
+ len(_def) == 3 and \
+ _def[1] == fld_name:
+ return _def[2]
+
def _call_vpp(self, i, msgdef, service, **kwargs):
"""Given a message, send the message and await a reply.
while True:
kwargs['cursor'] = cursor
rv, details = f(**kwargs)
- #
- # Convert to yield from details when we only support python 3
- #
for d in details:
yield d
if rv.retval == 0 or rv.retval != -165:
break
cursor = rv.cursor
-
-# Provide the old name for backward compatibility.
-VPP = VPPApiClient
-
-# vim: tabstop=8 expandtab shiftwidth=4 softtabstop=4