summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDave Barach <dave@barachs.net>2017-01-20 19:50:09 -0500
committerDamjan Marion <dmarion.lists@gmail.com>2017-01-23 15:17:25 +0000
commitfe6bdfd84573cd8813a211f9094ee734f088ce16 (patch)
tree68c109d579ebbcb64c2a0e9af379aaf0522c0c0b
parent675a69cdf6eb1a8e60613bef4a918fe1b354c276 (diff)
binary-api debug CLI works with plugins
Change-Id: I81f33f5153d5afac94b66b5a8cb91da77463af79 Signed-off-by: Dave Barach <dave@barachs.net>
-rw-r--r--src/examples/sample-plugin/sample/sample_test.c37
-rw-r--r--src/plugins/acl/acl_test.c51
-rw-r--r--src/plugins/flowperpkt/flowperpkt_test.c45
-rw-r--r--src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_test.c46
-rw-r--r--src/plugins/ioam/export/ioam_export_test.c44
-rw-r--r--src/plugins/ioam/lib-pot/pot_test.c48
-rw-r--r--src/plugins/ioam/lib-trace/trace_test.c48
-rw-r--r--src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c56
-rw-r--r--src/plugins/lb/lb_test.c35
-rw-r--r--src/plugins/snat/snat_test.c57
-rw-r--r--src/vat/api_format.c95
-rw-r--r--src/vat/vat.h33
-rw-r--r--src/vlib/unix/plugin.c9
-rw-r--r--src/vlibapi/api_helper_macros.h1
-rw-r--r--src/vlibapi/vat_helper_macros.h76
-rw-r--r--src/vpp-api-test.am3
-rw-r--r--src/vpp.am6
-rw-r--r--src/vpp/api/api_main.c39
-rw-r--r--src/vpp/api/plugin.c201
-rw-r--r--src/vpp/api/plugin.h61
20 files changed, 476 insertions, 515 deletions
diff --git a/src/examples/sample-plugin/sample/sample_test.c b/src/examples/sample-plugin/sample/sample_test.c
index dd1b0215751..a47710ee1c3 100644
--- a/src/examples/sample-plugin/sample/sample_test.c
+++ b/src/examples/sample-plugin/sample/sample_test.c
@@ -23,6 +23,7 @@
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
+#include <vlibapi/vat_helper_macros.h>
uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
@@ -87,42 +88,6 @@ foreach_standard_reply_retval_handler;
_(SAMPLE_MACSWAP_ENABLE_DISABLE_REPLY, sample_macswap_enable_disable_reply)
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
static int api_sample_macswap_enable_disable (vat_main_t * vam)
{
sample_test_main_t * sm = &sample_test_main;
diff --git a/src/plugins/acl/acl_test.c b/src/plugins/acl/acl_test.c
index a0e413e16da..5cacf7162bc 100644
--- a/src/plugins/acl/acl_test.c
+++ b/src/plugins/acl/acl_test.c
@@ -25,6 +25,7 @@
#include <vppinfra/error.h>
#include <vnet/ip/ip.h>
#include <arpa/inet.h>
+#include <vlibapi/vat_helper_macros.h>
uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
@@ -259,42 +260,6 @@ _(MACIP_ACL_INTERFACE_ADD_DEL_REPLY, macip_acl_interface_add_del_reply) \
_(MACIP_ACL_INTERFACE_GET_REPLY, macip_acl_interface_get_reply) \
_(ACL_PLUGIN_GET_VERSION_REPLY, acl_plugin_get_version_reply)
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
static int api_acl_plugin_get_version (vat_main_t * vam)
{
acl_test_main_t * sm = &acl_test_main;
@@ -520,7 +485,6 @@ static int api_acl_add_replace (vat_main_t * vam)
static int api_acl_del (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_acl_del_t * mp;
@@ -544,7 +508,6 @@ static int api_acl_del (vat_main_t * vam)
static int api_macip_acl_del (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_acl_del_t * mp;
@@ -568,7 +531,6 @@ static int api_macip_acl_del (vat_main_t * vam)
static int api_acl_interface_add_del (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_acl_interface_add_del_t * mp;
@@ -636,7 +598,6 @@ static int api_acl_interface_add_del (vat_main_t * vam)
static int api_macip_acl_interface_add_del (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_macip_acl_interface_add_del_t * mp;
@@ -687,7 +648,6 @@ static int api_macip_acl_interface_add_del (vat_main_t * vam)
static int api_acl_interface_set_acl_list (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_acl_interface_set_acl_list_t * mp;
@@ -746,7 +706,6 @@ static int api_acl_interface_set_acl_list (vat_main_t * vam)
static int api_acl_interface_list_dump (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
u32 sw_if_index = ~0;
@@ -775,7 +734,6 @@ static int api_acl_interface_list_dump (vat_main_t * vam)
static int api_acl_dump (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
u32 acl_index = ~0;
@@ -802,7 +760,6 @@ static int api_acl_dump (vat_main_t * vam)
static int api_macip_acl_dump (vat_main_t * vam)
{
- acl_test_main_t * sm = &acl_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
u32 acl_index = ~0;
@@ -978,8 +935,8 @@ _(macip_acl_interface_add_del, "<intfc> | sw_if_index <if-idx> [add|del] acl <ac
_(macip_acl_interface_get, "")
-
-void vat_api_hookup (vat_main_t *vam)
+static
+void acl_vat_api_hookup (vat_main_t *vam)
{
acl_test_main_t * sm = &acl_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -1016,7 +973,7 @@ clib_error_t * vat_plugin_register (vat_main_t *vam)
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~0)
- vat_api_hookup (vam);
+ acl_vat_api_hookup (vam);
vec_free(name);
diff --git a/src/plugins/flowperpkt/flowperpkt_test.c b/src/plugins/flowperpkt/flowperpkt_test.c
index 716818ffe0a..9211ebe32dd 100644
--- a/src/plugins/flowperpkt/flowperpkt_test.c
+++ b/src/plugins/flowperpkt/flowperpkt_test.c
@@ -19,6 +19,7 @@
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
+#include <vlibapi/vat_helper_macros.h>
/**
* @file vpp_api_test plugin
@@ -88,47 +89,9 @@ foreach_standard_reply_retval_handler;
_(FLOWPERPKT_TX_INTERFACE_ADD_DEL_REPLY, \
flowperpkt_tx_interface_add_del_reply)
-
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
static int
api_flowperpkt_tx_interface_add_del (vat_main_t * vam)
{
- flowperpkt_test_main_t *sm = &flowperpkt_test_main;
unformat_input_t *i = vam->input;
f64 timeout;
int enable_disable = 1;
@@ -177,8 +140,8 @@ api_flowperpkt_tx_interface_add_del (vat_main_t * vam)
#define foreach_vpe_api_msg \
_(flowperpkt_tx_interface_add_del, "<intfc> [disable]")
-void
-vat_api_hookup (vat_main_t * vam)
+static void
+flowperpkt_vat_api_hookup (vat_main_t * vam)
{
flowperpkt_test_main_t *sm = &flowperpkt_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -218,7 +181,7 @@ vat_plugin_register (vat_main_t * vam)
/* Don't attempt to hook up API messages if the data plane plugin is AWOL */
if (sm->msg_id_base != (u16) ~ 0)
- vat_api_hookup (vam);
+ flowperpkt_vat_api_hookup (vam);
vec_free (name);
diff --git a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_test.c b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_test.c
index 494263d9a1a..5b641cc7ce7 100644
--- a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_test.c
+++ b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_test.c
@@ -23,7 +23,7 @@
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
-
+#include <vlibapi/vat_helper_macros.h>
/* Declare message IDs */
#include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_msg_enum.h>
@@ -86,47 +86,9 @@ foreach_standard_reply_retval_handler;
#define foreach_vpe_api_reply_msg \
_(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY, vxlan_gpe_ioam_export_enable_disable_reply)
-
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
static int
api_vxlan_gpe_ioam_export_enable_disable (vat_main_t * vam)
{
- export_test_main_t *sm = &export_test_main;
unformat_input_t *i = vam->input;
f64 timeout;
int is_disable = 0;
@@ -160,8 +122,8 @@ api_vxlan_gpe_ioam_export_enable_disable (vat_main_t * vam)
#define foreach_vpe_api_msg \
_(vxlan_gpe_ioam_export_enable_disable, "<intfc> [disable]")
-void
-vat_api_hookup (vat_main_t * vam)
+static void
+vxlan_gpe_ioam_vat_api_hookup (vat_main_t * vam)
{
export_test_main_t *sm = &export_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -199,7 +161,7 @@ vat_plugin_register (vat_main_t * vam)
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~ 0)
- vat_api_hookup (vam);
+ vxlan_gpe_ioam_vat_api_hookup (vam);
vec_free (name);
diff --git a/src/plugins/ioam/export/ioam_export_test.c b/src/plugins/ioam/export/ioam_export_test.c
index f991fc0c795..a4ec80d0713 100644
--- a/src/plugins/ioam/export/ioam_export_test.c
+++ b/src/plugins/ioam/export/ioam_export_test.c
@@ -23,6 +23,7 @@
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
+#include <vlibapi/vat_helper_macros.h>
/* Declare message IDs */
@@ -87,46 +88,9 @@ foreach_standard_reply_retval_handler;
_(IOAM_EXPORT_IP6_ENABLE_DISABLE_REPLY, ioam_export_ip6_enable_disable_reply)
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
static int
api_ioam_export_ip6_enable_disable (vat_main_t * vam)
{
- export_test_main_t *sm = &export_test_main;
unformat_input_t *i = vam->input;
f64 timeout;
int is_disable = 0;
@@ -159,8 +123,8 @@ api_ioam_export_ip6_enable_disable (vat_main_t * vam)
#define foreach_vpe_api_msg \
_(ioam_export_ip6_enable_disable, "<intfc> [disable]")
-void
-vat_api_hookup (vat_main_t * vam)
+static void
+ioam_export_vat_api_hookup (vat_main_t * vam)
{
export_test_main_t *sm = &export_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -198,7 +162,7 @@ vat_plugin_register (vat_main_t * vam)
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~ 0)
- vat_api_hookup (vam);
+ ioam_export_vat_api_hookup (vam);
vec_free (name);
diff --git a/src/plugins/ioam/lib-pot/pot_test.c b/src/plugins/ioam/lib-pot/pot_test.c
index 2e87023896e..9f9d0c99bcf 100644
--- a/src/plugins/ioam/lib-pot/pot_test.c
+++ b/src/plugins/ioam/lib-pot/pot_test.c
@@ -23,6 +23,7 @@
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
+#include <vlibapi/vat_helper_macros.h>
/* Declare message IDs */
#include <ioam/lib-pot/pot_msg_enum.h>
@@ -118,48 +119,9 @@ _(POT_PROFILE_ACTIVATE_REPLY, pot_profile_activate_reply) \
_(POT_PROFILE_DEL_REPLY, pot_profile_del_reply) \
_(POT_PROFILE_SHOW_CONFIG_DETAILS, pot_profile_show_config_details)
-
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
-
static int api_pot_profile_add (vat_main_t *vam)
{
#define MAX_BITS 64
- pot_test_main_t * sm = &pot_test_main;
unformat_input_t *input = vam->input;
vl_api_pot_profile_add_t *mp;
u8 *name = NULL;
@@ -234,7 +196,6 @@ OUT:
static int api_pot_profile_activate (vat_main_t *vam)
{
#define MAX_BITS 64
- pot_test_main_t * sm = &pot_test_main;
unformat_input_t *input = vam->input;
vl_api_pot_profile_activate_t *mp;
u8 *name = NULL;
@@ -275,7 +236,6 @@ OUT:
static int api_pot_profile_del (vat_main_t *vam)
{
- pot_test_main_t * sm = &pot_test_main;
vl_api_pot_profile_del_t *mp;
f64 timeout;
@@ -287,7 +247,6 @@ static int api_pot_profile_del (vat_main_t *vam)
static int api_pot_profile_show_config_dump (vat_main_t *vam)
{
- pot_test_main_t * sm = &pot_test_main;
unformat_input_t *input = vam->input;
vl_api_pot_profile_show_config_dump_t *mp;
f64 timeout;
@@ -320,7 +279,8 @@ _(pot_profile_activate, "name <name> id [0-1] ") \
_(pot_profile_del, "[id <nn>]") \
_(pot_profile_show_config_dump, "id [0-1]")
-void vat_api_hookup (vat_main_t *vam)
+static void
+pot_vat_api_hookup (vat_main_t *vam)
{
pot_test_main_t * sm = &pot_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -357,7 +317,7 @@ clib_error_t * vat_plugin_register (vat_main_t *vam)
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~0)
- vat_api_hookup (vam);
+ pot_vat_api_hookup (vam);
vec_free(name);
diff --git a/src/plugins/ioam/lib-trace/trace_test.c b/src/plugins/ioam/lib-trace/trace_test.c
index 111dd461b5b..f4f1d4d54e2 100644
--- a/src/plugins/ioam/lib-trace/trace_test.c
+++ b/src/plugins/ioam/lib-trace/trace_test.c
@@ -23,6 +23,7 @@
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
+#include <vlibapi/vat_helper_macros.h>
/* Declare message IDs */
#include <ioam/lib-trace/trace_msg_enum.h>
@@ -115,48 +116,9 @@ _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
_(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
_(TRACE_PROFILE_SHOW_CONFIG_REPLY, trace_profile_show_config_reply)
-
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
-
static int
api_trace_profile_add (vat_main_t * vam)
{
- trace_test_main_t *sm = &trace_test_main;
unformat_input_t *input = vam->input;
vl_api_trace_profile_add_t *mp;
u8 trace_type = 0;
@@ -204,7 +166,6 @@ api_trace_profile_add (vat_main_t * vam)
static int
api_trace_profile_del (vat_main_t * vam)
{
- trace_test_main_t *sm = &trace_test_main;
vl_api_trace_profile_del_t *mp;
f64 timeout;
@@ -217,7 +178,6 @@ api_trace_profile_del (vat_main_t * vam)
static int
api_trace_profile_show_config (vat_main_t * vam)
{
- trace_test_main_t *sm = &trace_test_main;
vl_api_trace_profile_show_config_t *mp;
f64 timeout;
M (TRACE_PROFILE_SHOW_CONFIG, trace_profile_show_config);
@@ -237,8 +197,8 @@ _(trace_profile_del, "[id <nn>]") \
_(trace_profile_show_config, "[id <nn>]")
-void
-vat_api_hookup (vat_main_t * vam)
+static void
+ioam_trace_vat_api_hookup (vat_main_t * vam)
{
trace_test_main_t *sm = &trace_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -276,7 +236,7 @@ vat_plugin_register (vat_main_t * vam)
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~ 0)
- vat_api_hookup (vam);
+ ioam_trace_vat_api_hookup (vam);
vec_free (name);
diff --git a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c
index b5fee7246b4..7c4088ee71a 100644
--- a/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c
+++ b/src/plugins/ioam/lib-vxlan-gpe/vxlan_gpe_test.c
@@ -23,6 +23,7 @@
#include <vlibmemory/api.h>
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
+#include <vlibapi/vat_helper_macros.h>
/* Declare message IDs */
#include <ioam/lib-vxlan-gpe/vxlan_gpe_msg_enum.h>
@@ -96,49 +97,9 @@ _(VXLAN_GPE_IOAM_VNI_DISABLE_REPLY, vxlan_gpe_ioam_vni_disable_reply) \
_(VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY, vxlan_gpe_ioam_transit_enable_reply) \
_(VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY, vxlan_gpe_ioam_transit_disable_reply) \
-
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
-
static int
api_vxlan_gpe_ioam_enable (vat_main_t * vam)
{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
unformat_input_t *input = vam->input;
vl_api_vxlan_gpe_ioam_enable_t *mp;
f64 timeout;
@@ -179,7 +140,6 @@ api_vxlan_gpe_ioam_enable (vat_main_t * vam)
static int
api_vxlan_gpe_ioam_disable (vat_main_t * vam)
{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
vl_api_vxlan_gpe_ioam_disable_t *mp;
f64 timeout;
@@ -192,8 +152,6 @@ api_vxlan_gpe_ioam_disable (vat_main_t * vam)
static int
api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
ip4_address_t local4, remote4;
@@ -289,8 +247,6 @@ api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
static int
api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
ip4_address_t local4, remote4;
@@ -386,8 +342,6 @@ api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
static int
api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
ip4_address_t local4;
@@ -458,8 +412,6 @@ api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
static int
api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
{
- vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
-
unformat_input_t *line_input = vam->input;
vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
ip4_address_t local4;
@@ -545,8 +497,8 @@ _(vxlan_gpe_ioam_transit_disable, ""\
"dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
-void
-vat_api_hookup (vat_main_t * vam)
+static void
+vxlan_gpe_vat_api_hookup (vat_main_t * vam)
{
vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -584,7 +536,7 @@ vat_plugin_register (vat_main_t * vam)
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~ 0)
- vat_api_hookup (vam);
+ vxlan_gpe_vat_api_hookup (vam);
vec_free (name);
diff --git a/src/plugins/lb/lb_test.c b/src/plugins/lb/lb_test.c
index 8c2eaa91ce9..7e3519a8e4f 100644
--- a/src/plugins/lb/lb_test.c
+++ b/src/plugins/lb/lb_test.c
@@ -19,6 +19,7 @@
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
#include <lb/lb.h>
+#include <vlibapi/vat_helper_macros.h>
//TODO: Move that to vat/plugin_api.c
//////////////////////////
@@ -127,35 +128,8 @@ foreach_standard_reply_retval_handler;
_(LB_ADD_DEL_VIP_REPLY, lb_add_del_vip_reply) \
_(LB_ADD_DEL_AS_REPLY, lb_add_del_as_reply)
-/* M: construct, but don't yet send a message */
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memcpy (mp, &mps, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + lbtm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
static int api_lb_conf (vat_main_t * vam)
{
- lb_test_main_t *lbtm = &lb_test_main;
unformat_input_t *i = vam->input;
f64 timeout;
vl_api_lb_conf_t mps, *mp;
@@ -177,7 +151,6 @@ static int api_lb_conf (vat_main_t * vam)
static int api_lb_add_del_vip (vat_main_t * vam)
{
- lb_test_main_t *lbtm = &lb_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_lb_add_del_vip_t mps, *mp;
@@ -215,7 +188,6 @@ static int api_lb_add_del_vip (vat_main_t * vam)
static int api_lb_add_del_as (vat_main_t * vam)
{
- lb_test_main_t *lbtm = &lb_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_lb_add_del_as_t mps, *mp;
@@ -246,7 +218,8 @@ _(lb_conf, "<ip4-src-addr> <ip6-src-address> <sticky_buckets_per_core> <flow_tim
_(lb_add_del_vip, "<ip-prefix> [gre4|gre6] <new_table_len> [del]") \
_(lb_add_del_as, "<vip-ip-prefix> <address> [del]")
-void vat_api_hookup (vat_main_t *vam)
+static void
+lb_vat_api_hookup (vat_main_t *vam)
{
lb_test_main_t * lbtm = &lb_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -285,7 +258,7 @@ clib_error_t * vat_plugin_register (vat_main_t *vam)
lbtm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (lbtm->msg_id_base != (u16) ~0)
- vat_api_hookup (vam);
+ lb_vat_api_hookup (vam);
vec_free(name);
diff --git a/src/plugins/snat/snat_test.c b/src/plugins/snat/snat_test.c
index 013d7d9b700..b601d7d9c86 100644
--- a/src/plugins/snat/snat_test.c
+++ b/src/plugins/snat/snat_test.c
@@ -21,6 +21,7 @@
#include <vlibsocket/api.h>
#include <vppinfra/error.h>
#include <vnet/ip/ip.h>
+#include <vlibapi/vat_helper_macros.h>
uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
@@ -103,44 +104,8 @@ _(SNAT_INTERFACE_ADDR_DETAILS, snat_interface_addr_details) \
_(SNAT_IPFIX_ENABLE_DISABLE_REPLY, \
snat_ipfix_enable_disable_reply)
-/* M: construct, but don't yet send a message */
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- } \
- return -99; \
-} while(0);
-
static int api_snat_add_address_range (vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
ip4_address_t start_addr, end_addr;
@@ -200,7 +165,6 @@ static int api_snat_add_address_range (vat_main_t * vam)
static int api_snat_interface_add_del_feature (vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_snat_interface_add_del_feature_t * mp;
@@ -246,7 +210,6 @@ static int api_snat_interface_add_del_feature (vat_main_t * vam)
static int api_snat_add_static_mapping(vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_snat_add_static_mapping_t * mp;
@@ -338,7 +301,6 @@ static void vl_api_snat_static_mapping_details_t_handler
static int api_snat_static_mapping_dump(vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
f64 timeout;
vl_api_snat_static_mapping_dump_t * mp;
@@ -398,7 +360,6 @@ static void vl_api_snat_show_config_reply_t_handler
static int api_snat_show_config(vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
f64 timeout;
vl_api_snat_show_config_t * mp;
@@ -425,7 +386,6 @@ static void vl_api_snat_address_details_t_handler
static int api_snat_address_dump(vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
f64 timeout;
vl_api_snat_address_dump_t * mp;
@@ -460,7 +420,6 @@ static void vl_api_snat_interface_details_t_handler
static int api_snat_interface_dump(vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
f64 timeout;
vl_api_snat_interface_dump_t * mp;
@@ -485,7 +444,6 @@ static int api_snat_interface_dump(vat_main_t * vam)
static int api_snat_set_workers (vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_snat_set_workers_t * mp;
@@ -523,7 +481,6 @@ static void vl_api_snat_worker_details_t_handler
static int api_snat_worker_dump(vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
f64 timeout;
vl_api_snat_worker_dump_t * mp;
@@ -548,7 +505,6 @@ static int api_snat_worker_dump(vat_main_t * vam)
static int api_snat_ipfix_enable_disable (vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_snat_add_del_interface_addr_t * mp;
@@ -597,7 +553,6 @@ static void vl_api_snat_interface_addr_details_t_handler
static int api_snat_interface_addr_dump(vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
f64 timeout;
vl_api_snat_interface_addr_dump_t * mp;
@@ -622,7 +577,6 @@ static int api_snat_interface_addr_dump(vat_main_t * vam)
static int api_snat_add_del_interface_addr (vat_main_t * vam)
{
- snat_test_main_t * sm = &snat_test_main;
unformat_input_t * i = vam->input;
f64 timeout;
vl_api_snat_ipfix_enable_disable_t * mp;
@@ -677,7 +631,8 @@ _(snat_interface_addr_dump, "") \
_(snat_ipfix_enable_disable, "[domain <id>] [src_port <n>] " \
"[disable]")
-void vat_api_hookup (vat_main_t *vam)
+static void
+snat_vat_api_hookup (vat_main_t *vam)
{
snat_test_main_t * sm __attribute__((unused)) = &snat_test_main;
/* Hook up handlers for replies from the data plane plug-in */
@@ -693,7 +648,9 @@ void vat_api_hookup (vat_main_t *vam)
#undef _
/* API messages we can send */
-#define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
+#define _(n,h) \
+ hash_set_mem (vam->function_by_name, #n, api_##n); \
+ clib_warning ("vam %llx add '%s' handler %llx", vam, #n, api_##n);
foreach_vpe_api_msg;
#undef _
@@ -715,7 +672,7 @@ clib_error_t * vat_plugin_register (vat_main_t *vam)
sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
if (sm->msg_id_base != (u16) ~0)
- vat_api_hookup (vam);
+ snat_vat_api_hookup (vam);
vec_free(name);
diff --git a/src/vat/api_format.c b/src/vat/api_format.c
index 1babaf406f5..653cf79f3db 100644
--- a/src/vat/api_format.c
+++ b/src/vat/api_format.c
@@ -70,6 +70,46 @@
#include <vpp/api/vpe_all_api_h.h>
#undef vl_printfun
+#include <vlibapi/vat_helper_macros.h>
+
+f64
+vat_time_now (vat_main_t * vam)
+{
+#if VPP_API_TEST_BUILTIN
+ return vlib_time_now (vam->vlib_main);
+#else
+ return clib_time_now (&vam->clib_time);
+#endif
+}
+
+void
+errmsg (char *fmt, ...)
+{
+ vat_main_t *vam = &vat_main;
+ va_list va;
+ u8 *s;
+
+ va_start (va, fmt);
+ s = va_format (0, fmt, &va);
+ va_end (va);
+
+ vec_add1 (s, 0);
+
+#if VPP_API_TEST_BUILTIN
+ vlib_cli_output (vam->vlib_main, (char *) s);
+#else
+ {
+ if (vam->ifp != stdin)
+ fformat (vam->ofp, "%s(%d): \n", vam->current_file,
+ vam->input_line_number);
+ fformat (vam->ofp, (char *) s);
+ fflush (vam->ofp);
+ }
+#endif
+
+ vec_free (s);
+}
+
static uword
api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
{
@@ -88,8 +128,6 @@ api_unformat_sw_if_index (unformat_input_t * input, va_list * args)
return 1;
}
-void vat_suspend (vlib_main_t * vm, f64 interval);
-
#if VPP_API_TEST_BUILTIN == 0
/* Parse an IP4 address %d.%d.%d.%d. */
uword
@@ -3867,59 +3905,6 @@ _(SW_INTERFACE_SET_DPDK_HQOS_TCTBL_REPLY, \
sw_interface_set_dpdk_hqos_tctbl_reply)
#endif
-/* M: construct, but don't yet send a message */
-
-#define M(T,t) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-#define M2(T,t,n) \
-do { \
- vam->result_ready = 0; \
- mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)+(n)); \
- memset (mp, 0, sizeof (*mp)); \
- mp->_vl_msg_id = ntohs (VL_API_##T); \
- mp->client_index = vam->my_client_index; \
-} while(0);
-
-
-/* S: send a message */
-#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
-
-/* W: wait for results, with timeout */
-#define W \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- return (vam->retval); \
- } \
- vat_suspend (vam->vlib_main, 1e-3); \
- } \
- return -99; \
-} while(0);
-
-/* W2: wait for results, with timeout */
-#define W2(body) \
-do { \
- timeout = vat_time_now (vam) + 1.0; \
- \
- while (vat_time_now (vam) < timeout) { \
- if (vam->result_ready == 1) { \
- (body); \
- return (vam->retval); \
- } \
- vat_suspend (vam->vlib_main, 1e-3); \
- } \
- return -99; \
-} while(0);
-
typedef struct
{
u8 *name;
diff --git a/src/vat/vat.h b/src/vat/vat.h
index 64be2f7f97f..3d7d96ae566 100644
--- a/src/vat/vat.h
+++ b/src/vat/vat.h
@@ -190,36 +190,11 @@ typedef struct
vlib_main_t *vlib_main;
} vat_main_t;
-vat_main_t vat_main;
-
-static inline f64
-vat_time_now (vat_main_t * vam)
-{
-#if VPP_API_TEST_BUILTIN
- return vlib_time_now (vam->vlib_main);
-#else
- return clib_time_now (&vam->clib_time);
-#endif
-}
-
-#if VPP_API_TEST_BUILTIN
-#define errmsg(fmt,args...) \
-do { \
- vat_main_t *__vam = &vat_main; \
- vlib_cli_output (__vam->vlib_main, fmt, ##args); \
- } while(0);
-#else
-#define errmsg(fmt,args...) \
-do { \
- vat_main_t *__vam = &vat_main; \
- if(__vam->ifp != stdin) \
- fformat(__vam->ofp,"%s(%d): \n", __vam->current_file, \
- __vam->input_line_number); \
- fformat(__vam->ofp, fmt "\n", ##args); \
- fflush(__vam->ofp); \
-} while(0);
-#endif
+extern vat_main_t vat_main;
+void vat_suspend (vlib_main_t * vm, f64 interval);
+f64 vat_time_now (vat_main_t * vam);
+void errmsg (char *fmt, ...);
void vat_api_hookup (vat_main_t * vam);
int api_sw_interface_dump (vat_main_t * vam);
void do_one_file (vat_main_t * vam);
diff --git a/src/vlib/unix/plugin.c b/src/vlib/unix/plugin.c
index 987f7d052e5..40399090983 100644
--- a/src/vlib/unix/plugin.c
+++ b/src/vlib/unix/plugin.c
@@ -264,10 +264,15 @@ vlib_plugins_show_cmd_fn (vlib_main_t * vm,
return 0;
}
+/* *INDENT-OFF* */
VLIB_CLI_COMMAND (plugins_show_cmd, static) =
{
-.path = "show plugins",.short_help = "show loaded plugins",.function =
- vlib_plugins_show_cmd_fn,};
+ .path = "show plugins",
+ .short_help = "show loaded plugins",
+ .function = vlib_plugins_show_cmd_fn,
+};
+/* *INDENT-ON* */
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vlibapi/api_helper_macros.h b/src/vlibapi/api_helper_macros.h
index 16f34cfc762..7f94e446e18 100644
--- a/src/vlibapi/api_helper_macros.h
+++ b/src/vlibapi/api_helper_macros.h
@@ -17,7 +17,6 @@
*------------------------------------------------------------------
*/
-
#ifndef __api_helper_macros_h__
#define __api_helper_macros_h__
diff --git a/src/vlibapi/vat_helper_macros.h b/src/vlibapi/vat_helper_macros.h
new file mode 100644
index 00000000000..7199364a389
--- /dev/null
+++ b/src/vlibapi/vat_helper_macros.h
@@ -0,0 +1,76 @@
+/*
+ *------------------------------------------------------------------
+ * vat_helper_macros.h - collect api client helper macros in one place
+ *
+ * Copyright (c) 2016 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ *------------------------------------------------------------------
+ */
+#ifndef __vat_helper_macros_h__
+#define __vat_helper_macros_h__
+
+/* M: construct, but don't yet send a message */
+
+#define M(T,t) \
+do { \
+ vam->result_ready = 0; \
+ mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)); \
+ memset (mp, 0, sizeof (*mp)); \
+ mp->_vl_msg_id = ntohs (VL_API_##T); \
+ mp->client_index = vam->my_client_index; \
+} while(0);
+
+#define M2(T,t,n) \
+do { \
+ vam->result_ready = 0; \
+ mp = vl_msg_api_alloc_as_if_client(sizeof(*mp)+(n)); \
+ memset (mp, 0, sizeof (*mp)); \
+ mp->_vl_msg_id = ntohs (VL_API_##T); \
+ mp->client_index = vam->my_client_index; \
+} while(0);
+
+
+/* S: send a message */
+#define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
+
+/* W: wait for results, with timeout */
+#define W \
+do { \
+ timeout = vat_time_now (vam) + 1.0; \
+ \
+ while (vat_time_now (vam) < timeout) { \
+ if (vam->result_ready == 1) { \
+ return (vam->retval); \
+ } \
+ vat_suspend (vam->vlib_main, 1e-5); \
+ } \
+ return -99; \
+} while(0);
+
+/* W2: wait for results, with timeout */
+#define W2(body) \
+do { \
+ timeout = vat_time_now (vam) + 1.0; \
+ \
+ while (vat_time_now (vam) < timeout) { \
+ if (vam->result_ready == 1) { \
+ (body); \
+ return (vam->retval); \
+ } \
+ vat_suspend (vam->vlib_main, 1e-5); \
+ } \
+ return -99; \
+} while(0);
+
+
+#endif /* __vat_helper_macros_h__ */
diff --git a/src/vpp-api-test.am b/src/vpp-api-test.am
index 326100561c7..f0d5df62791 100644
--- a/src/vpp-api-test.am
+++ b/src/vpp-api-test.am
@@ -44,7 +44,10 @@ vpp_api_test_LDADD = \
libvnet.la \
-lpthread -lm -lrt -ldl -lcrypto
+vpp_api_test_LDFLAGS = -Wl,--export-dynamic
+
vpp_json_test_LDADD = libvppinfra.la -lm
+vpp_json_test_LDFLAGS = -Wl,--export-dynamic
nobase_include_HEADERS += \
vat/vat.h \
diff --git a/src/vpp.am b/src/vpp.am
index 425f1e32925..0b605ec5e32 100644
--- a/src/vpp.am
+++ b/src/vpp.am
@@ -28,7 +28,9 @@ bin_vpp_SOURCES += \
if WITH_APICLI
bin_vpp_SOURCES += \
vpp/api/api_format.c \
- vpp/api/api_main.c
+ vpp/api/api_main.c \
+ vpp/api/plugin.c \
+ vpp/api/plugin.h
endif
# comment out to disable stats upload to gmond
@@ -78,6 +80,8 @@ bin_vpp_LDADD = \
libvppinfra.la \
-lrt -lm -lpthread -ldl
+bin_vpp_LDFLAGS = -Wl,--export-dynamic
+
if ENABLE_TESTS
noinst_PROGRAMS += bin/test_client
diff --git a/src/vpp/api/api_main.c b/src/vpp/api/api_main.c
index fd6998f4536..7bf7e8b7170 100644
--- a/src/vpp/api/api_main.c
+++ b/src/vpp/api/api_main.c
@@ -42,11 +42,17 @@ static clib_error_t *
api_main_init (vlib_main_t * vm)
{
vat_main_t *vam = &vat_main;
+ int rv;
+ int vat_plugin_init (vat_main_t * vam);
vam->vlib_main = vm;
vam->my_client_index = (u32) ~ 0;
init_error_string_table (vam);
vat_api_hookup (vam);
+ clib_warning ("vam %llx", vam);
+ rv = vat_plugin_init (vam);
+ if (rv)
+ clib_warning ("vat_plugin_init returned %d", rv);
return 0;
}
@@ -183,6 +189,39 @@ api_cli_output (void *notused, const char *fmt, ...)
vec_free (s);
}
+u16
+vl_client_get_first_plugin_msg_id (char *plugin_name)
+{
+ api_main_t *am = &api_main;
+ vl_api_msg_range_t *rp;
+ uword *p;
+
+ p = hash_get_mem (am->msg_range_by_name, plugin_name);
+ if (p == 0)
+ return ~0;
+
+ rp = vec_elt_at_index (am->msg_ranges, p[0]);
+
+ return (rp->first_msg_id);
+}
+
+uword
+unformat_sw_if_index (unformat_input_t * input, va_list * args)
+{
+ u32 *result = va_arg (*args, u32 *);
+ vnet_main_t *vnm = vnet_get_main ();
+ u32 sw_if_index = ~0;
+ u8 *if_name;
+ uword *p;
+
+ if (unformat (input, "%U", unformat_vnet_sw_interface, vnm, &sw_if_index))
+ {
+ *result = sw_if_index;
+ return 1;
+ }
+ return 0;
+}
+
/*
* fd.io coding-style-patch-verification: ON
*
diff --git a/src/vpp/api/plugin.c b/src/vpp/api/plugin.c
new file mode 100644
index 00000000000..c1cc928c217
--- /dev/null
+++ b/src/vpp/api/plugin.c
@@ -0,0 +1,201 @@
+/*
+ * Copyright (c) 2015 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * plugin.c: plugin handling
+ */
+
+#include <vat/vat.h>
+#include <vat/plugin.h>
+#include <dlfcn.h>
+#include <dirent.h>
+
+plugin_main_t vat_plugin_main;
+
+static int
+load_one_plugin (plugin_main_t * pm, plugin_info_t * pi)
+{
+ void *handle, *register_handle;
+ clib_error_t *(*fp) (vat_main_t *);
+ clib_error_t *error;
+
+ handle = dlopen ((char *) pi->name, RTLD_LAZY);
+
+ /*
+ * Note: this can happen if the plugin has an undefined symbol reference,
+ * so print a warning. Otherwise, the poor slob won't know what happened.
+ * Ask me how I know that...
+ */
+ if (handle == 0)
+ {
+ clib_warning ("%s", dlerror ());
+ return -1;
+ }
+
+ pi->handle = handle;
+
+ register_handle = dlsym (pi->handle, "vat_plugin_register");
+ if (register_handle == 0)
+ return 0;
+
+ fp = register_handle;
+
+ error = (*fp) (pm->vat_main);
+
+ if (error)
+ {
+ clib_error_report (error);
+ dlclose (handle);
+ return 1;
+ }
+
+ clib_warning ("Loaded plugin: %s", pi->name);
+
+ return 0;
+}
+
+static u8 **
+split_plugin_path (plugin_main_t * pm)
+{
+ int i;
+ u8 **rv = 0;
+ u8 *path = pm->plugin_path;
+ u8 *this = 0;
+
+ for (i = 0; i < vec_len (pm->plugin_path); i++)
+ {
+ if (path[i] != ':')
+ {
+ vec_add1 (this, path[i]);
+ continue;
+ }
+ vec_add1 (this, 0);
+ vec_add1 (rv, this);
+ this = 0;
+ }
+ if (this)
+ {
+ vec_add1 (this, 0);
+ vec_add1 (rv, this);
+ }
+ return rv;
+}
+
+int
+vat_load_new_plugins (plugin_main_t * pm)
+{
+ DIR *dp;
+ struct dirent *entry;
+ struct stat statb;
+ uword *p;
+ plugin_info_t *pi;
+ u8 **plugin_path;
+ int i;
+
+ plugin_path = split_plugin_path (pm);
+
+ for (i = 0; i < vec_len (plugin_path); i++)
+ {
+ dp = opendir ((char *) plugin_path[i]);
+
+ if (dp == 0)
+ continue;
+
+ while ((entry = readdir (dp)))
+ {
+ u8 *plugin_name;
+
+ if (pm->plugin_name_filter)
+ {
+ int j;
+ for (j = 0; j < vec_len (pm->plugin_name_filter); j++)
+ if (entry->d_name[j] != pm->plugin_name_filter[j])
+ goto next;
+ }
+
+ plugin_name = format (0, "%s/%s%c", plugin_path[i],
+ entry->d_name, 0);
+
+ /* unreadable */
+ if (stat ((char *) plugin_name, &statb) < 0)
+ {
+ ignore:
+ vec_free (plugin_name);
+ continue;
+ }
+
+ /* a dir or other things which aren't plugins */
+ if (!S_ISREG (statb.st_mode))
+ goto ignore;
+
+ p = hash_get_mem (pm->plugin_by_name_hash, plugin_name);
+ if (p == 0)
+ {
+ vec_add2 (pm->plugin_info, pi, 1);
+ pi->name = plugin_name;
+ pi->file_info = statb;
+
+ if (load_one_plugin (pm, pi))
+ {
+ vec_free (plugin_name);
+ _vec_len (pm->plugin_info) = vec_len (pm->plugin_info) - 1;
+ continue;
+ }
+ memset (pi, 0, sizeof (*pi));
+ hash_set_mem (pm->plugin_by_name_hash, plugin_name,
+ pi - pm->plugin_info);
+ }
+ next:
+ ;
+ }
+ closedir (dp);
+ vec_free (plugin_path[i]);
+ }
+ vec_free (plugin_path);
+ return 0;
+}
+
+#define QUOTE_(x) #x
+#define QUOTE(x) QUOTE_(x)
+
+/*
+ * Load plugins from /usr/lib/vpp_api_test_plugins by default
+ */
+char *vat_plugin_path = "/usr/lib/vpp_api_test_plugins";
+
+char *vat_plugin_name_filter = 0;
+
+int
+vat_plugin_init (vat_main_t * vam)
+{
+ plugin_main_t *pm = &vat_plugin_main;
+
+
+ pm->plugin_path = format (0, "%s%c", vat_plugin_path, 0);
+ if (vat_plugin_name_filter)
+ pm->plugin_name_filter = format (0, "%s%c", vat_plugin_name_filter, 0);
+
+ pm->plugin_by_name_hash = hash_create_string (0, sizeof (uword));
+ pm->vat_main = vam;
+
+ return vat_load_new_plugins (pm);
+}
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */
diff --git a/src/vpp/api/plugin.h b/src/vpp/api/plugin.h
new file mode 100644
index 00000000000..559ec52f128
--- /dev/null
+++ b/src/vpp/api/plugin.h
@@ -0,0 +1,61 @@
+/*
+ * Copyright (c) 2015 Cisco and/or its affiliates.
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+/*
+ * plugin.h: plugin handling
+ */
+
+#ifndef __included_plugin_h__
+#define __included_plugin_h__
+
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+typedef struct
+{
+ u8 *name;
+ struct stat file_info;
+ void *handle;
+} plugin_info_t;
+
+typedef struct
+{
+ /* loaded plugin info */
+ plugin_info_t *plugin_info;
+ uword *plugin_by_name_hash;
+
+ /* path and name filter */
+ u8 *plugin_path;
+ u8 *plugin_name_filter;
+
+ /* convenience */
+ vat_main_t *vat_main;
+
+} plugin_main_t;
+
+plugin_main_t vat_plugin_main;
+
+int vat_plugin_init (vat_main_t * vam);
+int vat_load_new_plugins (plugin_main_t * pm);
+
+#endif
+
+/*
+ * fd.io coding-style-patch-verification: ON
+ *
+ * Local Variables:
+ * eval: (c-set-style "gnu")
+ * End:
+ */