papi: change default to use socket transport instead of shared memory transport
[vpp.git] / src / vpp-api / python / vpp_papi / vpp_papi.py
index e22b88b..25f4727 100644 (file)
@@ -31,7 +31,7 @@ import weakref
 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:
@@ -47,8 +47,8 @@ except ModuleNotFoundError:
 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', )
 
@@ -72,6 +72,11 @@ class VppEnum:
     pass
 
 
+@metaclass(VppEnumType)
+class VppEnumFlag:
+    pass
+
+
 def vpp_atexit(vpp_weakref):
     """Clean up VPP connection on shutdown."""
     vpp_instance = vpp_weakref()
@@ -80,8 +85,6 @@ def vpp_atexit(vpp_weakref):
         vpp_instance.disconnect()
 
 
-
-
 def add_convenience_methods():
     # provide convenience methods to IP[46]Address.vapi_af
     def _vapi_af(self):
@@ -281,7 +284,12 @@ class VPPApiJSONFiles:
                 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'
@@ -318,6 +326,12 @@ class VPPApiJSONFiles:
                             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:])
@@ -372,9 +386,9 @@ class VPPApiClient:
     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.
 
@@ -672,6 +686,15 @@ class VPPApiClient:
                                                            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.
 
@@ -894,16 +917,8 @@ class VPPApiClient:
         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