aboutsummaryrefslogtreecommitdiffstats
path: root/src/vpp-api/python/vpp_papi/vpp_papi.py
diff options
context:
space:
mode:
Diffstat (limited to 'src/vpp-api/python/vpp_papi/vpp_papi.py')
-rw-r--r--src/vpp-api/python/vpp_papi/vpp_papi.py46
1 files changed, 43 insertions, 3 deletions
diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py
index 32abe14da94..4de257c6924 100644
--- a/src/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/src/vpp-api/python/vpp_papi/vpp_papi.py
@@ -29,6 +29,8 @@ import atexit
from . vpp_serializer import VPPType, VPPEnumType, VPPUnionType, BaseTypes
from . vpp_serializer import VPPMessage, vpp_get_type, VPPTypeAlias
+logger = logging.getLogger(__name__)
+
if sys.version[0] == '2':
import Queue as queue
else:
@@ -63,6 +65,19 @@ else:
return d.items()
+def call_logger(msgdef, kwargs):
+ s = 'Calling {}('.format(msgdef.name)
+ for k, v in kwargs.items():
+ s += '{}:{} '.format(k, v)
+ s += ')'
+ return s
+
+
+def return_logger(r):
+ s = 'Return from {}'.format(r)
+ return s
+
+
class VppApiDynamicMethodHolder(object):
pass
@@ -493,10 +508,31 @@ class VPP(object):
else:
raise VPPIOError(2, 'RPC reply message received in event handler')
+ def has_context(self, msg):
+ if len(msg) < 10:
+ return False
+
+ header = VPPType('header_with_context', [['u16', 'msgid'],
+ ['u32', 'client_index'],
+ ['u32', 'context']])
+
+ (i, ci, context), size = header.unpack(msg, 0)
+ if self.id_names[i] == 'rx_thread_exit':
+ return
+
+ #
+ # Decode message and returns a tuple.
+ #
+ msgobj = self.id_msgdef[i]
+ if 'context' in msgobj.field_by_name and context >= 0:
+ return True
+ return False
+
def decode_incoming_msg(self, msg, no_type_conversion=False):
if not msg:
self.logger.warning('vpp_api.read failed')
return
+
(i, ci), size = self.header.unpack(msg, 0)
if self.id_names[i] == 'rx_thread_exit':
return
@@ -537,7 +573,7 @@ class VPP(object):
raise VPPValueError('Invalid argument {} to {}'
.format(list(d), msg.name))
- def _call_vpp(self, i, msg, multipart, **kwargs):
+ def _call_vpp(self, i, msgdef, multipart, **kwargs):
"""Given a message, send the message and await a reply.
msgdef - the message packing definition
@@ -567,8 +603,11 @@ class VPP(object):
kwargs['client_index'] = self.transport.socket_index
except AttributeError:
pass
- self.validate_args(msg, kwargs)
- b = msg.pack(kwargs)
+ self.validate_args(msgdef, kwargs)
+
+ logging.debug(call_logger(msgdef, kwargs))
+
+ b = msgdef.pack(kwargs)
self.transport.suspend()
self.transport.write(b)
@@ -601,6 +640,7 @@ class VPP(object):
self.transport.resume()
+ logger.debug(return_logger(rl))
return rl
def _call_vpp_async(self, i, msg, **kwargs):