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>
diff --git a/src/pkg/debian/control.in b/src/pkg/debian/control.in
index 006b01c..1ce63a7 100644
--- a/src/pkg/debian/control.in
+++ b/src/pkg/debian/control.in
@@ -70,7 +70,6 @@
Package: python3-vpp-api
Architecture: any
Depends: vpp (= ${source:Version}),
- python3-cffi,
${python3:Depends},
${misc:Depends}
Description: VPP Python3 API bindings
diff --git a/src/plugins/srv6-mobile/extra/Dockerfile.j2 b/src/plugins/srv6-mobile/extra/Dockerfile.j2
index e8120bb..8e42af0 100644
--- a/src/plugins/srv6-mobile/extra/Dockerfile.j2
+++ b/src/plugins/srv6-mobile/extra/Dockerfile.j2
@@ -12,7 +12,6 @@
net-tools \
iproute2 \
tcpdump \
- python3-cffi \
asciidoc \
xmlto \
libssl-dev \
diff --git a/src/plugins/srv6-mobile/extra/Dockerfile.j2.release b/src/plugins/srv6-mobile/extra/Dockerfile.j2.release
index 7507f50..aec520b 100644
--- a/src/plugins/srv6-mobile/extra/Dockerfile.j2.release
+++ b/src/plugins/srv6-mobile/extra/Dockerfile.j2.release
@@ -15,7 +15,6 @@
net-tools \
iproute2 \
tcpdump \
- python3-cffi \
python2.7 \
libssl-dev \
netcat; \
diff --git a/src/vpp-api/python/setup.py b/src/vpp-api/python/setup.py
index 05c26bb..8bf6def 100644
--- a/src/vpp-api/python/setup.py
+++ b/src/vpp-api/python/setup.py
@@ -18,11 +18,11 @@
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 25f4727..3465f50 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 @@
VppTransport = V
+from . vpp_transport_socket import VppTransport
+
logger = logging.getLogger('vpp_papi')
logger.addHandler(logging.NullHandler())
@@ -422,16 +424,10 @@
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 @@
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 4719f23..0000000
--- 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