diff options
author | Ole Troan <ot@cisco.com> | 2021-05-04 12:45:57 +0200 |
---|---|---|
committer | Andrew Yourtchenko <ayourtch@gmail.com> | 2021-07-12 10:41:10 +0000 |
commit | 041372b79b843b54dfad048dda237e64d1a5f127 (patch) | |
tree | 63a4287f21ebfd0f5b3fde8e882b1c2a33464f46 /src/vpp-api | |
parent | 0046e97eb94cbcf278be2c892e4b686da670a414 (diff) |
papi: remove shared memory transport
This patch removes the papi transport shared memory plugin.
It also removes any dependency on CFFI.
Type: feature
Signed-off-by: Ole Troan <ot@cisco.com>
Change-Id: Ia81701c0dc506871e511495d837e41420e1fdf72
Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'src/vpp-api')
-rw-r--r-- | src/vpp-api/python/setup.py | 4 | ||||
-rw-r--r-- | src/vpp-api/python/vpp_papi/vpp_papi.py | 13 | ||||
-rw-r--r-- | src/vpp-api/python/vpp_papi/vpp_transport_shmem.py | 143 |
3 files changed, 6 insertions, 154 deletions
diff --git a/src/vpp-api/python/setup.py b/src/vpp-api/python/setup.py index 05c26bb05e5..8bf6def2227 100644 --- a/src/vpp-api/python/setup.py +++ b/src/vpp-api/python/setup.py @@ -18,11 +18,11 @@ try: except ImportError: from distutils.core import setup, find_packages -requirements = ['cffi >= 1.6'] +requirements = [] setup( name='vpp_papi', - version='1.6.2', + version='2.0.0', description='VPP Python binding', author='Ole Troan', author_email='ot@cisco.com', diff --git a/src/vpp-api/python/vpp_papi/vpp_papi.py b/src/vpp-api/python/vpp_papi/vpp_papi.py index 25f47276732..3465f503e9e 100644 --- a/src/vpp-api/python/vpp_papi/vpp_papi.py +++ b/src/vpp-api/python/vpp_papi/vpp_papi.py @@ -44,6 +44,8 @@ except ModuleNotFoundError: VppTransport = V +from . vpp_transport_socket import VppTransport + logger = logging.getLogger('vpp_papi') logger.addHandler(logging.NullHandler()) @@ -422,16 +424,10 @@ class VPPApiClient: self.async_thread = async_thread self.event_thread = None self.testmode = testmode - self.use_socket = use_socket self.server_address = server_address self._apifiles = apifiles self.stats = {} - if use_socket: - from . vpp_transport_socket import VppTransport - else: - from . vpp_transport_shmem import VppTransport - if not apifiles: # Pick up API definitions from default directory try: @@ -906,11 +902,10 @@ class VPPApiClient: def __repr__(self): return "<VPPApiClient apifiles=%s, testmode=%s, async_thread=%s, " \ - "logger=%s, read_timeout=%s, use_socket=%s, " \ + "logger=%s, read_timeout=%s, " \ "server_address='%s'>" % ( self._apifiles, self.testmode, self.async_thread, - self.logger, self.read_timeout, self.use_socket, - self.server_address) + self.logger, self.read_timeout, self.server_address) def details_iter(self, f, **kwargs): cursor = 0 diff --git a/src/vpp-api/python/vpp_papi/vpp_transport_shmem.py b/src/vpp-api/python/vpp_papi/vpp_transport_shmem.py deleted file mode 100644 index 4719f23b40a..00000000000 --- a/src/vpp-api/python/vpp_papi/vpp_transport_shmem.py +++ /dev/null @@ -1,143 +0,0 @@ -# -# A transport class. With two implementations. -# One for socket and one for shared memory. -# -import logging - -from cffi import FFI -import cffi - -logger = logging.getLogger('vpp_papi.transport') -logger.addHandler(logging.NullHandler()) - -ffi = FFI() -ffi.cdef(""" -typedef void (*vac_callback_t)(unsigned char * data, int len); -typedef void (*vac_error_callback_t)(void *, unsigned char *, int); -int vac_connect(char * name, char * chroot_prefix, vac_callback_t cb, - int rx_qlen); -int vac_disconnect(void); -int vac_read(char **data, int *l, unsigned short timeout); -int vac_write(char *data, int len); -void vac_free(void * msg); - -int vac_get_msg_index(unsigned char * name); -int vac_msg_table_size(void); -int vac_msg_table_max_index(void); - -void vac_rx_suspend (void); -void vac_rx_resume (void); -void vac_set_error_handler(vac_error_callback_t); -void vac_mem_init (size_t size); -""") - -vpp_object = None - -# allow file to be imported so it can be mocked in tests. -# If the shared library fails, VppTransport cannot be initialized. -try: - vpp_api = ffi.dlopen('libvppapiclient.so') -except OSError: - vpp_api = None - - -@ffi.callback("void(unsigned char *, int)") -def vac_callback_sync(data, len): - vpp_object.msg_handler_sync(ffi.buffer(data, len)) - - -@ffi.callback("void(unsigned char *, int)") -def vac_callback_async(data, len): - vpp_object.msg_handler_async(ffi.buffer(data, len)) - - -@ffi.callback("void(void *, unsigned char *, int)") -def vac_error_handler(arg, msg, msg_len): - vpp_object.logger.warning("VPP API client:: %s", ffi.string(msg, msg_len)) - - -class VppTransportShmemIOError(IOError): - """ exception communicating with vpp over shared memory """ - - def __init__(self, rv, descr): - self.rv = rv - self.desc = descr - - super(VppTransportShmemIOError, self).__init__(rv, descr) - - -class VppTransport: - VppTransportShmemIOError = VppTransportShmemIOError - - def __init__(self, parent, read_timeout, server_address): - self.connected = False - self.read_timeout = read_timeout - self.parent = parent - global vpp_object - vpp_object = parent - - vpp_api.vac_mem_init(0) - - # Register error handler - vpp_api.vac_set_error_handler(vac_error_handler) - - # Support legacy CFFI - # from_buffer supported from 1.8.0 - (major, minor, patch) = [int(s) for s in - cffi.__version__.split('.', 3)] - if major >= 1 and minor >= 8: - self.write = self._write_new_cffi - else: - self.write = self._write_legacy_cffi - - def connect(self, name, pfx, msg_handler, rx_qlen): - self.connected = True - if not pfx: - pfx = ffi.NULL - return vpp_api.vac_connect(name.encode('ascii'), pfx, msg_handler, rx_qlen) - - def disconnect(self): - self.connected = False - return vpp_api.vac_disconnect() - - def suspend(self): - vpp_api.vac_rx_suspend() - - def resume(self): - vpp_api.vac_rx_resume() - - def get_callback(self, do_async): - return vac_callback_sync if not do_async else vac_callback_async - - def get_msg_index(self, name): - return vpp_api.vac_get_msg_index(name.encode('ascii')) - - def msg_table_max_index(self): - return vpp_api.vac_msg_table_max_index() - - def _write_new_cffi(self, buf): - """Send a binary-packed message to VPP.""" - if not self.connected: - raise VppTransportShmemIOError(1, 'Not connected') - return vpp_api.vac_write(ffi.from_buffer(buf), len(buf)) - - def _write_legacy_cffi(self, buf): - """Send a binary-packed message to VPP.""" - if not self.connected: - raise VppTransportShmemIOError(1, 'Not connected') - return vpp_api.vac_write(bytes(buf), len(buf)) - - def read(self, timeout=None): - if not self.connected: - raise VppTransportShmemIOError(1, 'Not connected') - if timeout is None: - timeout = self.read_timeout - mem = ffi.new("char **") - size = ffi.new("int *") - rv = vpp_api.vac_read(mem, size, timeout) - if rv: - strerror = 'vac_read failed. It is likely that VPP died.' - raise VppTransportShmemIOError(rv, strerror) - msg = bytes(ffi.buffer(mem[0], size[0])) - vpp_api.vac_free(mem[0]) - return msg |