aboutsummaryrefslogtreecommitdiffstats
path: root/vpp-api/python/pneum/pneum.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/pneum/pneum.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/pneum/pneum.c')
-rw-r--r--vpp-api/python/pneum/pneum.c58
1 files changed, 37 insertions, 21 deletions
diff --git a/vpp-api/python/pneum/pneum.c b/vpp-api/python/pneum/pneum.c
index ebe47b2f419..3b5455304e5 100644
--- a/vpp-api/python/pneum/pneum.c
+++ b/vpp-api/python/pneum/pneum.c
@@ -52,7 +52,7 @@ typedef struct {
pneum_main_t pneum_main;
-extern int wrap_pneum_callback(char *data, int len);
+pneum_callback_t pneum_callback;
/*
* Satisfy external references when -lvlib is not available.
@@ -62,24 +62,16 @@ void vlib_cli_output (struct vlib_main_t * vm, char * fmt, ...)
clib_warning ("vlib_cli_output called...");
}
-#define vl_api_version(n,v) static u32 vpe_api_version = v;
-#include <vpp-api/vpe.api.h>
-#undef vl_api_version
void
-vl_client_add_api_signatures (vl_api_memclnt_create_t *mp)
+pneum_free (void * msg)
{
- /*
- * Send the main API signature in slot 0. This bit of code must
- * match the checks in ../vpe/api/api.c: vl_msg_api_version_check().
- */
- mp->api_versions[0] = clib_host_to_net_u32 (vpe_api_version);
+ vl_msg_api_free (msg);
}
static void
pneum_api_handler (void *msg)
{
u16 id = ntohs(*((u16 *)msg));
-
if (id == VL_API_RX_THREAD_EXIT) {
pneum_main_t *pm = &pneum_main;
vl_msg_api_free(msg);
@@ -91,8 +83,9 @@ pneum_api_handler (void *msg)
clib_warning("Message ID %d has wrong length: %d\n", id, l);
/* Call Python callback */
- (void)wrap_pneum_callback(msg, l);
- vl_msg_api_free(msg);
+ ASSERT(pneum_callback);
+ (pneum_callback)(msg, l);
+ pneum_free(msg);
}
static void *
@@ -115,8 +108,22 @@ pneum_rx_thread_fn (void *arg)
pthread_exit(0);
}
+uword *
+pneum_msg_table_get_hash (void)
+{
+ api_main_t *am = &api_main;
+ return (am->msg_index_by_name_and_crc);
+}
+
int
-pneum_connect (char * name, char * chroot_prefix)
+pneum_msg_table_size(void)
+{
+ api_main_t *am = &api_main;
+ return hash_elts(am->msg_index_by_name_and_crc);
+}
+
+int
+pneum_connect (char * name, char * chroot_prefix, pneum_callback_t cb)
{
int rv = 0;
pneum_main_t *pm = &pneum_main;
@@ -134,12 +141,15 @@ pneum_connect (char * name, char * chroot_prefix)
return (-1);
}
- /* Start the rx queue thread */
- rv = pthread_create(&pm->rx_thread_handle, NULL, pneum_rx_thread_fn, 0);
- if (rv) {
- clib_warning("pthread_create returned %d", rv);
- vl_client_api_unmap();
- return (-1);
+ if (cb) {
+ /* Start the rx queue thread */
+ rv = pthread_create(&pm->rx_thread_handle, NULL, pneum_rx_thread_fn, 0);
+ if (rv) {
+ clib_warning("pthread_create returned %d", rv);
+ vl_client_api_unmap();
+ return (-1);
+ }
+ pneum_callback = cb;
}
pm->connected_to_vlib = 1;
@@ -164,6 +174,7 @@ pneum_disconnect (void)
if (pm->connected_to_vlib) {
vl_client_disconnect();
vl_client_api_unmap();
+ pneum_callback = 0;
}
memset (pm, 0, sizeof (*pm));
@@ -175,8 +186,11 @@ pneum_read (char **p, int *l)
{
unix_shared_memory_queue_t *q;
api_main_t *am = &api_main;
+ pneum_main_t *pm = &pneum_main;
uword msg;
+ if (!pm->connected_to_vlib) return -1;
+
*l = 0;
if (am->our_pid == 0) return (-1);
@@ -219,7 +233,9 @@ pneum_write (char *p, int l)
api_main_t *am = &api_main;
vl_api_header_t *mp = vl_msg_api_alloc(l);
unix_shared_memory_queue_t *q;
+ pneum_main_t *pm = &pneum_main;
+ if (!pm->connected_to_vlib) return -1;
if (!mp) return (-1);
memcpy(mp, p, l);
mp->client_index = pneum_client_index();
@@ -228,7 +244,7 @@ pneum_write (char *p, int l)
if (rv != 0) {
printf("vpe_api_write fails: %d\n", rv);
/* Clear message */
- vl_msg_api_free(mp);
+ pneum_free(mp);
}
return (rv);
}