summaryrefslogtreecommitdiffstats
path: root/vpp-api/python/vpp_papi/pneum_wrap.c
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2016-11-10 14:22:49 -0500
committerDamjan Marion <dmarion.lists@gmail.com>2016-11-21 18:11:41 +0000
commit557d128b68a1213e056f5eed9fe6f230ca3f3144 (patch)
tree6b31ac462efacf3f6937788c9b7af1420497c9fc /vpp-api/python/vpp_papi/pneum_wrap.c
parentfca670b0ec9f74aa977fe479a5517ad6367ee898 (diff)
Add client-side msg_name_and_crc -> msg_index table
vppapigen now generates per-message crcs. Verified that whitespace and real changes in message A don't change the crc for message B, etc. Fixed the sample and flowperpkt plugins to participate. Others need the same treatment. They don't build due to python/java language binding build issues. To use the scheme: Client connects as usual. Then call: u32 vl_api_get_msg_index(char * name_and_crc) name_and_crc is a string like: "flowperpkt_tx_interface_add_del_753301f3", aka the message name with _%08x <expected crc> appended. Try these vpp-api-test commands to play with it: vat# dump_msg_api_table <snip> [366]: punt_reply_cca27fbe [367]: ipsec_spd_dump_5e9ae88e [368]: ipsec_spd_details_6f7821b0 [369]: sample_macswap_enable_disable_0f2813e2 [370]: sample_macswap_enable_disable_reply_476738e5 [371]: flowperpkt_tx_interface_add_del_753301f3 [372]: flowperpkt_tx_interface_add_del_reply_d47e6e0b vat# get_msg_id sample_macswap_enable_disable_reply_476738e5 'sample_macswap_enable_disable_reply_476738e5' has message index 370 vat# get_msg_id sample_macswap_enable_disable_reply_476738e3 'sample_macswap_enable_disable_reply_476738e3' not found CRCs may vary, etc. vppapigen is used to build a set of JSON representations of each API file from vpp-api/Makefile.am and that is in turn used by each language binding (Java, Python, Lua). Change-Id: I3d64582e779dac5f20cddec79c562c288d8fd9c6 Signed-off-by: Dave Barach <dave@barachs.net> Signed-off-by: Ole Troan <ot@cisco.com>
Diffstat (limited to 'vpp-api/python/vpp_papi/pneum_wrap.c')
-rw-r--r--vpp-api/python/vpp_papi/pneum_wrap.c69
1 files changed, 51 insertions, 18 deletions
diff --git a/vpp-api/python/vpp_papi/pneum_wrap.c b/vpp-api/python/vpp_papi/pneum_wrap.c
index 18c4f233869..5763707b517 100644
--- a/vpp-api/python/vpp_papi/pneum_wrap.c
+++ b/vpp-api/python/vpp_papi/pneum_wrap.c
@@ -15,11 +15,12 @@
#include <Python.h>
#include "../pneum/pneum.h"
+#include <vppinfra/hash.h>
static PyObject *pneum_callback = NULL;
-int
-wrap_pneum_callback (char *data, int len)
+static void
+wrap_pneum_callback (unsigned char * data, int len)
{
PyGILState_STATE gstate;
PyObject *result;//, *arglist;
@@ -38,7 +39,6 @@ wrap_pneum_callback (char *data, int len)
PyErr_Print();
PyGILState_Release(gstate);
- return (0);
}
static PyObject *
@@ -46,22 +46,28 @@ wrap_connect (PyObject *self, PyObject *args)
{
char * name, * chroot_prefix = NULL;
int rv;
- PyObject * temp;
+ PyObject * temp = NULL;
+ pneum_callback_t cb = NULL;
- if (!PyArg_ParseTuple(args, "sO|s:wrap_connect", &name, &temp, &chroot_prefix))
+ if (!PyArg_ParseTuple(args, "s|Os:wrap_connect",
+ &name, &temp, &chroot_prefix))
return (NULL);
- if (!PyCallable_Check(temp)) {
- PyErr_SetString(PyExc_TypeError, "parameter must be callable");
- return NULL;
- }
-
- Py_XINCREF(temp); /* Add a reference to new callback */
- Py_XDECREF(pneum_callback); /* Dispose of previous callback */
- pneum_callback = temp; /* Remember new callback */
-
+ if (temp)
+ {
+ if (!PyCallable_Check(temp))
+ {
+ PyErr_SetString(PyExc_TypeError, "parameter must be callable");
+ return NULL;
+ }
+
+ Py_XINCREF(temp); /* Add a reference to new callback */
+ Py_XDECREF(pneum_callback); /* Dispose of previous callback */
+ pneum_callback = temp; /* Remember new callback */
+ cb = wrap_pneum_callback;
+ }
Py_BEGIN_ALLOW_THREADS
- rv = pneum_connect(name, chroot_prefix);
+ rv = pneum_connect(name, chroot_prefix, cb);
Py_END_ALLOW_THREADS
return PyLong_FromLong(rv);
}
@@ -90,8 +96,6 @@ wrap_write (PyObject *self, PyObject *args)
return PyLong_FromLong(rv);
}
-void vl_msg_api_free(void *);
-
static PyObject *
wrap_read (PyObject *self, PyObject *args)
{
@@ -110,15 +114,44 @@ wrap_read (PyObject *self, PyObject *args)
#endif
if (!ret) { Py_RETURN_NONE; }
- vl_msg_api_free(data);
+ pneum_free(data);
return ret;
}
+static PyObject *
+wrap_msg_table (PyObject *self, PyObject *args)
+{
+ int i = 0, rv = 0;
+ hash_pair_t *hp;
+ uword *h = pneum_msg_table_get_hash();
+ PyObject *ret = PyList_New(pneum_msg_table_size());
+ if (!ret) goto error;
+ hash_foreach_pair (hp, h,
+ ({
+ PyObject *item = PyTuple_New(2);
+ if (!item) goto error;
+ rv = PyTuple_SetItem(item, 0, PyLong_FromLong((u32)hp->value[0]));
+ if (rv) goto error;
+ rv = PyTuple_SetItem(item, 1, PyString_FromString((char *)hp->key));
+ if (rv) goto error;
+ PyList_SetItem(ret, i, item);
+ i++;
+ }));
+
+ return ret;
+
+ error:
+ /* TODO: Raise exception */
+ printf("msg_table failed");
+ Py_RETURN_NONE;
+}
+
static PyMethodDef vpp_api_Methods[] = {
{"connect", wrap_connect, METH_VARARGS, "Connect to the VPP API."},
{"disconnect", wrap_disconnect, METH_VARARGS, "Disconnect from the VPP API."},
{"write", wrap_write, METH_VARARGS, "Write data to the VPP API."},
{"read", wrap_read, METH_VARARGS, "Read data from the VPP API."},
+ {"msg_table", wrap_msg_table, METH_VARARGS, "Get API dictionary."},
{NULL, NULL, 0, NULL} /* Sentinel */
};