diff options
-rw-r--r-- | src/pkg/debian/control.in | 1 | ||||
-rw-r--r-- | src/plugins/srv6-mobile/extra/Dockerfile.j2 | 1 | ||||
-rw-r--r-- | src/plugins/srv6-mobile/extra/Dockerfile.j2.release | 1 | ||||
-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 | ||||
-rw-r--r-- | test/requirements-3.txt | 2 | ||||
-rw-r--r-- | test/requirements.txt | 1 |
8 files changed, 7 insertions, 159 deletions
diff --git a/src/pkg/debian/control.in b/src/pkg/debian/control.in index 006b01c00c2..1ce63a7d004 100644 --- a/src/pkg/debian/control.in +++ b/src/pkg/debian/control.in @@ -70,7 +70,6 @@ Description: Vector Packet Processing--runtime dpdk plugin 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 e8120bb736b..8e42af09d56 100644 --- a/src/plugins/srv6-mobile/extra/Dockerfile.j2 +++ b/src/plugins/srv6-mobile/extra/Dockerfile.j2 @@ -12,7 +12,6 @@ RUN set -eux; \ 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 7507f50403b..aec520bfb85 100644 --- a/src/plugins/srv6-mobile/extra/Dockerfile.j2.release +++ b/src/plugins/srv6-mobile/extra/Dockerfile.j2.release @@ -15,7 +15,6 @@ RUN set -eux; \ 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 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 diff --git a/test/requirements-3.txt b/test/requirements-3.txt index c25ac86c1d1..a6c2bc9abf0 100644 --- a/test/requirements-3.txt +++ b/test/requirements-3.txt @@ -54,7 +54,7 @@ cffi==1.14.5 \ --hash=sha256:d42b11d692e11b6634f7613ad8df5d6d5f8875f5d48939520d351007b3c13406 \ --hash=sha256:f2d45f97ab6bb54753eab54fffe75aaf3de4ff2341c9daee1987ee1837636f1d \ --hash=sha256:fd78e5fee591709f32ef6edb9a015b4aa1a5022598e36227500c8f4e02328d9c \ - # via -r requirements.txt, cryptography + # via cryptography chardet==4.0.0 \ --hash=sha256:0d6f53a15db4120f2b08c94f11e7d93d2c911ee118b6b30a04ec3ee8310179fa \ --hash=sha256:f864054d66fd9118f2e67044ac8981a54775ec5b67aed0441892edb553d21da5 \ diff --git a/test/requirements.txt b/test/requirements.txt index b8e36eeee85..f7b7c185446 100644 --- a/test/requirements.txt +++ b/test/requirements.txt @@ -1,6 +1,5 @@ pip-tools==5.1.2 # BSD Keep this in sync with Makefile's PIP_TOOLS_VERSION -cffi # MIT cryptography!=2.0 # BSD/Apache-2.0 deprecation>=2.0.6 # Apache-2.0 faulthandler; python_version < '3.3' # # BSD License (2 clause) |