vat: unload unused vat plugins 64/20564/2
authorDave Barach <dave@barachs.net>
Tue, 9 Jul 2019 14:04:18 +0000 (10:04 -0400)
committerFlorin Coras <florin.coras@gmail.com>
Tue, 9 Jul 2019 15:24:41 +0000 (15:24 +0000)
If the corresponding vpp plugin is absent, return a non-zero
clib_error_t * from vat_plugin_register ("xxx plugin not loaded"). The
vat plugin calls dlclose on the vat plugin, and it disappears.

Depending on the plugin configuration, this can reduce the vpp virtual
size by several gigabytes.

Added a VAT_PLUGIN(<plugin-name>) macro to vat_helper_macros, clean up
boilerplate vat_plugin_register() implementations. Fixed a number of
non-standard vat_plugin_register methods.

Type: refactor

Change-Id: Iac908e5af7d5497c78d6aa9c3c51cdae08374045
Signed-off-by: Dave Barach <dave@barachs.net>
22 files changed:
src/examples/sample-plugin/sample/sample_test.c
src/plugins/acl/acl_test.c
src/plugins/avf/avf_test.c
src/plugins/cdp/cdp_test.c
src/plugins/ct6/ct6_test.c
src/plugins/dpdk/api/dpdk_test.c
src/plugins/flowprobe/flowprobe_test.c
src/plugins/gtpu/gtpu_test.c
src/plugins/http_static/http_static_test.c
src/plugins/ikev2/ikev2_test.c
src/plugins/ioam/lib-pot/pot_test.c
src/plugins/lacp/lacp_test.c
src/plugins/lb/lb_test.c
src/plugins/mactime/mactime_test.c
src/plugins/memif/memif_test.c
src/plugins/nat/nat_test.c
src/plugins/nsh/nsh_test.c
src/plugins/nsim/nsim_test.c
src/plugins/pppoe/pppoe_test.c
src/plugins/stn/stn_test.c
src/plugins/vmxnet3/vmxnet3_test.c
src/vlibapi/vat_helper_macros.h

index 51c2c87..6f645f7 100644 (file)
@@ -33,19 +33,19 @@ uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
 
 /* define message structures */
 #define vl_typedefs
-#include <sample/sample_all_api_h.h> 
+#include <sample/sample_all_api_h.h>
 #undef vl_typedefs
 
 /* declare message handlers for each api */
 
 #define vl_endianfun             /* define message structures */
-#include <sample/sample_all_api_h.h> 
+#include <sample/sample_all_api_h.h>
 #undef vl_endianfun
 
 /* instantiate all the print functions we know about */
 #define vl_print(handle, ...)
 #define vl_printfun
-#include <sample/sample_all_api_h.h> 
+#include <sample/sample_all_api_h.h>
 #undef vl_printfun
 
 /* Get the API version number. */
@@ -81,7 +81,7 @@ _(sample_macswap_enable_disable_reply)
 foreach_standard_reply_retval_handler;
 #undef _
 
-/* 
+/*
  * Table of message reply handlers, must include boilerplate handlers
  * we just generated
  */
@@ -108,12 +108,12 @@ static int api_sample_macswap_enable_disable (vat_main_t * vam)
         else
             break;
     }
-    
+
     if (sw_if_index == ~0) {
         errmsg ("missing interface name / explicit sw_if_index number \n");
         return -99;
     }
-    
+
     /* Construct the API message */
     M(SAMPLE_MACSWAP_ENABLE_DISABLE, mp);
     mp->sw_if_index = ntohl (sw_if_index);
@@ -127,7 +127,7 @@ static int api_sample_macswap_enable_disable (vat_main_t * vam)
     return ret;
 }
 
-/* 
+/*
  * List of messages that the api test plugin sends,
  * and that the data plane plugin processes
  */
@@ -145,35 +145,19 @@ static void sample_api_hookup (vat_main_t *vam)
                            vl_noop_handler,                     \
                            vl_api_##n##_t_endian,               \
                            vl_api_##n##_t_print,                \
-                           sizeof(vl_api_##n##_t), 1); 
+                           sizeof(vl_api_##n##_t), 1);
     foreach_vpe_api_reply_msg;
 #undef _
 
     /* API messages we can send */
 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
     foreach_vpe_api_msg;
-#undef _    
-    
+#undef _
+
     /* Help strings */
 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
     foreach_vpe_api_msg;
 #undef _
 }
 
-clib_error_t * vat_plugin_register (vat_main_t *vam)
-{
-  sample_test_main_t * sm = &sample_test_main;
-  u8 * name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "sample_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~0)
-    sample_api_hookup (vam);
-  
-  vec_free(name);
-  
-  return 0;
-}
+VAT_PLUGIN_REGISTER(sample);
index 19a6f91..9185cc1 100644 (file)
@@ -1489,7 +1489,7 @@ _(acl_plugin_get_conn_table_max_entries, "")
 
 
 static
-void acl_vat_api_hookup (vat_main_t *vam)
+void acl_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 */
@@ -1515,20 +1515,4 @@ void acl_vat_api_hookup (vat_main_t *vam)
 #undef _
 }
 
-clib_error_t * vat_plugin_register (vat_main_t *vam)
-{
-  acl_test_main_t * sm = &acl_test_main;
-  u8 * name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "acl_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~0)
-    acl_vat_api_hookup (vam);
-
-  vec_free(name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER(acl);
index 368d503..17f4308 100644 (file)
@@ -202,7 +202,7 @@ _(avf_create, "<pci-address> [rx-queue-size <size>] "               \
 _(avf_delete, "<sw_if_index>")
 
 static void
-avf_vat_api_hookup (vat_main_t * vam)
+avf_api_hookup (vat_main_t * vam)
 {
   avf_test_main_t *avm __attribute__ ((unused)) = &avf_test_main;
 #define _(N,n)                                                  \
@@ -226,24 +226,7 @@ avf_vat_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  avf_test_main_t *avm = &avf_test_main;
-  u8 *name;
-
-  avm->vat_main = vam;
-
-  name = format (0, "avf_%08x%c", api_version, 0);
-  avm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (avm->msg_id_base != (u16) ~ 0)
-    avf_vat_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (avf);
 
 /*
  * fd.io coding-style-patch-verification: ON
index 33b5449..2e24ddc 100644 (file)
@@ -150,25 +150,7 @@ cdp_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  cdp_test_main_t *sm = &cdp_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "cdp_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    cdp_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (cdp);
 
 /*
  * fd.io coding-style-patch-verification: ON
index 507620e..2f985a6 100644 (file)
@@ -173,25 +173,7 @@ ct6_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  ct6_test_main_t *ctmp = &ct6_test_main;
-  u8 *name;
-
-  ctmp->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "ct6_%08x%c", api_version, 0);
-  ctmp->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (ctmp->msg_id_base != (u16) ~ 0)
-    ct6_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (ct6);
 
 /*
  * fd.io coding-style-patch-verification: ON
index 637b401..4594a9d 100644 (file)
@@ -77,7 +77,7 @@ _(sw_interface_set_dpdk_hqos_tctbl_reply)
 foreach_standard_reply_retval_handler;
 #undef _
 
-/* 
+/*
  * Table of message reply handlers, must include boilerplate handlers
  * we just generated
  */
@@ -336,7 +336,7 @@ api_sw_interface_set_dpdk_hqos_tctbl (vat_main_t * vam)
   return 0;
 }
 
-/* 
+/*
  * List of messages that the api test plugin sends,
  * and that the data plane plugin processes
  */
@@ -361,36 +361,19 @@ static void dpdk_api_hookup (vat_main_t *vam)
                           vl_noop_handler,                      \
                           vl_api_##n##_t_endian,                \
                           vl_api_##n##_t_print,                 \
-                          sizeof(vl_api_##n##_t), 1); 
+                          sizeof(vl_api_##n##_t), 1);
   foreach_vpe_api_reply_msg;
 #undef _
 
   /* API messages we can send */
 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
   foreach_vpe_api_msg;
-#undef _    
-    
+#undef _
+
   /* Help strings */
 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
   foreach_vpe_api_msg;
 #undef _
 }
 
-clib_error_t * vat_plugin_register (vat_main_t *vam)
-{
-  dpdk_test_main_t * dm = &dpdk_test_main;
-  u8 * name;
-
-  dm->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "dpdk_%08x%c", api_version, 0);
-  dm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (dm->msg_id_base != (u16) ~0)
-    dpdk_api_hookup (vam);
-  
-  vec_free(name);
-  
-  return 0;
-}
+VAT_PLUGIN_REGISTER(dpdk);
index 19b7a73..53fdb23 100644 (file)
@@ -206,7 +206,7 @@ _(flowprobe_tx_interface_add_del, "<intfc> [disable]") \
 _(flowprobe_params, "record <[l2] [l3] [l4]> [active <timer> passive <timer>]")
 
 static void
-flowprobe_vat_api_hookup (vat_main_t * vam)
+flowprobe_api_hookup (vat_main_t * vam)
 {
   flowprobe_test_main_t *sm = &flowprobe_test_main;
   /* Hook up handlers for replies from the data plane plug-in */
@@ -232,26 +232,7 @@ flowprobe_vat_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  flowprobe_test_main_t *sm = &flowprobe_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "flowprobe_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  /* Don't attempt to hook up API messages if the data plane plugin is AWOL */
-  if (sm->msg_id_base != (u16) ~ 0)
-    flowprobe_vat_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (flowprobe);
 
 /*
  * fd.io coding-style-patch-verification: ON
index f9812c6..5e9afa2 100644 (file)
@@ -450,7 +450,7 @@ _(gtpu_add_del_tunnel,                                                 \
 _(gtpu_tunnel_dump, "[<intfc> | sw_if_index <nn>]")                    \
 
 static void
-gtpu_vat_api_hookup (vat_main_t *vam)
+gtpu_api_hookup (vat_main_t *vam)
 {
   gtpu_test_main_t * gtm = &gtpu_test_main;
   /* Hook up handlers for replies from the data plane plug-in */
@@ -476,22 +476,4 @@ gtpu_vat_api_hookup (vat_main_t *vam)
 #undef _
 }
 
-clib_error_t * vat_plugin_register (vat_main_t *vam)
-{
-  gtpu_test_main_t * gtm = &gtpu_test_main;
-
-  u8 * name;
-
-  gtm->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "gtpu_%08x%c", api_version, 0);
-  gtm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (gtm->msg_id_base != (u16) ~0)
-    gtpu_vat_api_hookup (vam);
-
-  vec_free(name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER(gtpu);
index 0720463..545980b 100644 (file)
@@ -208,25 +208,7 @@ http_static_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  http_static_test_main_t *htmp = &http_static_test_main;
-  u8 *name;
-
-  htmp->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "http_static_%08x%c", api_version, 0);
-  htmp->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (htmp->msg_id_base != (u16) ~ 0)
-    http_static_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (http_static);
 
 /*
  * fd.io coding-style-patch-verification: ON
index 68c5068..57724b8 100644 (file)
@@ -807,7 +807,7 @@ _(ikev2_initiate_del_child_sa, "<ispi>")                                \
 _(ikev2_initiate_rekey_child_sa, "<ispi>")
 
 static void
-ikev2_vat_api_hookup (vat_main_t * vam)
+ikev2_api_hookup (vat_main_t * vam)
 {
   ikev2_test_main_t *sm = &ikev2_test_main;
   /* Hook up handlers for replies from the data plane plug-in */
@@ -833,24 +833,7 @@ ikev2_vat_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  ikev2_test_main_t *sm = &ikev2_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  name = format (0, "ikev2_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    ikev2_vat_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (ikev2);
 
 /*
  * fd.io coding-style-patch-verification: ON
index e02640b..d0cf49e 100644 (file)
@@ -111,7 +111,7 @@ foreach_standard_reply_retval_handler;
 foreach_custom_reply_retval_handler;
 #undef _
 
-/* 
+/*
  * Table of message reply handlers, must include boilerplate handlers
  * we just generated
  */
@@ -167,7 +167,7 @@ static int api_pot_profile_add (vat_main_t *vam)
         rv = -99;
         goto OUT;
       }
-    
+
     M2(POT_PROFILE_ADD, mp, vec_len(name));
 
     mp->list_name_len = vec_len(name);
@@ -187,11 +187,11 @@ static int api_pot_profile_add (vat_main_t *vam)
       }
     mp->id = id;
     mp->max_bits = bits;
-      
+
     S(mp);
     W (ret);
     return ret;
-  
+
 OUT:
     vec_free(name);
     return(rv);
@@ -206,7 +206,7 @@ static int api_pot_profile_activate (vat_main_t *vam)
     u8 id = 0;
     int rv = 0;
     int ret;
-    
+
     while (unformat_check_input(input) != UNFORMAT_END_OF_INPUT)
       {
         if (unformat(input, "name %s", &name))
@@ -223,17 +223,17 @@ static int api_pot_profile_activate (vat_main_t *vam)
         rv = -99;
         goto OUT;
       }
-    
+
     M2(POT_PROFILE_ACTIVATE, mp, vec_len(name));
 
     mp->list_name_len = vec_len(name);
     clib_memcpy(mp->list_name, name, mp->list_name_len);
     mp->id = id;
-      
+
     S(mp);
     W (ret);
     return ret;
-  
+
 OUT:
     vec_free(name);
     return(rv);
@@ -244,7 +244,7 @@ static int api_pot_profile_del (vat_main_t *vam)
 {
     vl_api_pot_profile_del_t *mp;
     int ret;
-   
+
     M(POT_PROFILE_DEL, mp);
     mp->list_name_len = 0;
     S(mp);
@@ -274,7 +274,7 @@ static int api_pot_profile_show_config_dump (vat_main_t *vam)
     return ret;
 }
 
-/* 
+/*
  * List of messages that the api test plugin sends,
  * and that the data plane plugin processes
  */
@@ -287,7 +287,7 @@ _(pot_profile_activate, "name <name> id [0-1] ")                            \
 _(pot_profile_del, "[id <nn>]")                                         \
 _(pot_profile_show_config_dump, "id [0-1]")
 
-static void 
+static void
 pot_vat_api_hookup (vat_main_t *vam)
 {
     pot_test_main_t * sm = &pot_test_main;
@@ -299,21 +299,22 @@ pot_vat_api_hookup (vat_main_t *vam)
                            vl_noop_handler,                     \
                            vl_api_##n##_t_endian,               \
                            vl_api_##n##_t_print,                \
-                           sizeof(vl_api_##n##_t), 1); 
+                           sizeof(vl_api_##n##_t), 1);
     foreach_vpe_api_reply_msg;
 #undef _
 
     /* API messages we can send */
 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
     foreach_vpe_api_msg;
-#undef _    
-    
+#undef _
+
     /* Help strings */
 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
     foreach_vpe_api_msg;
 #undef _
 }
 
+
 clib_error_t *
 pot_vat_plugin_register (vat_main_t *vam)
 {
@@ -324,11 +325,12 @@ pot_vat_plugin_register (vat_main_t *vam)
 
   name = format (0, "ioam_pot_%08x%c", api_version, 0);
   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+  vec_free(name);
 
   if (sm->msg_id_base != (u16) ~0)
     pot_vat_api_hookup (vam);
-  
-  vec_free(name);
-  
+  else
+    return clib_error_return (0, "ioam_pot plugin not loaded...");
+
   return 0;
 }
index 0a8631d..4e28a6d 100644 (file)
@@ -206,6 +206,10 @@ vat_plugin_register (vat_main_t * vam)
   /* Ask the vpp engine for the first assigned message-id */
   name = format (0, "lacp_%08x%c", api_version, 0);
   lm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+  vec_free (name);
+
+  if (lm->msg_id_base == (u16) ~ 0)
+    return clib_error_return (0, "lacp plugin not loaded...");
 
   /* Get the control ping ID */
 #define _(id,n,crc) \
@@ -217,8 +221,6 @@ vat_plugin_register (vat_main_t * vam)
   if (lm->msg_id_base != (u16) ~ 0)
     lacp_vat_api_hookup (vam);
 
-  vec_free (name);
-
   return 0;
 }
 
index 00ad673..4ac306b 100644 (file)
@@ -349,8 +349,8 @@ _(lb_add_del_vip, "<prefix> "  \
 _(lb_add_del_as, "<vip-prefix> [protocol (tcp|udp) port <n>] "  \
                  "[<address>] [del] [flush]")
 
-static void 
-lb_vat_api_hookup (vat_main_t *vam)
+static void
+lb_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 */
@@ -376,22 +376,4 @@ lb_vat_api_hookup (vat_main_t *vam)
 #undef _
 }
 
-clib_error_t * vat_plugin_register (vat_main_t *vam)
-{
-  lb_test_main_t * lbtm = &lb_test_main;
-
-  u8 * name;
-
-  lbtm->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "lb_%08x%c", api_version, 0);
-  lbtm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (lbtm->msg_id_base != (u16) ~0)
-    lb_vat_api_hookup (vam);
-
-  vec_free(name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER(lb);
index 4557e57..c9c1a47 100644 (file)
@@ -300,25 +300,7 @@ mactime_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  mactime_test_main_t *sm = &mactime_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "mactime_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    mactime_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (mactime);
 
 /*
  * fd.io coding-style-patch-verification: ON
index 510462e..e26094b 100644 (file)
@@ -482,6 +482,10 @@ vat_plugin_register (vat_main_t * vam)
   /* Ask the vpp engine for the first assigned message-id */
   name = format (0, "memif_%08x%c", api_version, 0);
   mm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+  vec_free (name);
+
+  if (mm->msg_id_base == (u16) ~ 0)
+    return clib_error_return (0, "memif plugin not loaded...");
 
   /* Get the control ping ID */
 #define _(id,n,crc) \
@@ -493,8 +497,6 @@ vat_plugin_register (vat_main_t * vam)
   if (mm->msg_id_base != (u16) ~ 0)
     memif_vat_api_hookup (vam);
 
-  vec_free (name);
-
   return 0;
 }
 
index 0371ec4..1dd25b3 100644 (file)
@@ -1171,11 +1171,12 @@ clib_error_t * vat_plugin_register (vat_main_t *vam)
   /* Ask the vpp engine for the first assigned message-id */
   name = format (0, "nat_%08x%c", api_version, 0);
   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+  vec_free(name);
 
   if (sm->msg_id_base != (u16) ~0)
     snat_vat_api_hookup (vam);
-
-  vec_free(name);
+  else
+    return clib_error_return (0, "nat plugin not loaded...");
 
   return 0;
 }
index 0852956..091ad97 100644 (file)
@@ -402,11 +402,12 @@ clib_error_t * vat_plugin_register (vat_main_t *vam)
   /* Ask the vpp engine for the first assigned message-id */
   name = format (0, "nsh_%08x%c", api_version, 0);
   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+  vec_free(name);
 
   if (sm->msg_id_base != (u16) ~0)
     nsh_vat_api_hookup (vam);
-
-  vec_free(name);
+  else
+    return clib_error_return (0, "nsh plugin not loaded...");
 
   return 0;
 }
index e3c95c7..3e38bd0 100644 (file)
@@ -306,25 +306,7 @@ nsim_api_hookup (vat_main_t * vam)
 #undef _
 }
 
-clib_error_t *
-vat_plugin_register (vat_main_t * vam)
-{
-  nsim_test_main_t *sm = &nsim_test_main;
-  u8 *name;
-
-  sm->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "nsim_%08x%c", api_version, 0);
-  sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (sm->msg_id_base != (u16) ~ 0)
-    nsim_api_hookup (vam);
-
-  vec_free (name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER (nsim);
 
 /*
  * fd.io coding-style-patch-verification: ON
index 0d085ed..d8ad19d 100644 (file)
@@ -283,7 +283,7 @@ _(pppoe_add_del_session,                                                 \
 _(pppoe_session_dump, "[<intfc> | sw_if_index <nn>]")                    \
 
 static void
-pppoe_vat_api_hookup (vat_main_t *vam)
+pppoe_api_hookup (vat_main_t *vam)
 {
   pppoe_test_main_t * pem = &pppoe_test_main;
   /* Hook up handlers for replies from the data plane plug-in */
@@ -309,22 +309,4 @@ pppoe_vat_api_hookup (vat_main_t *vam)
 #undef _
 }
 
-clib_error_t * vat_plugin_register (vat_main_t *vam)
-{
-  pppoe_test_main_t * pem = &pppoe_test_main;
-
-  u8 * name;
-
-  pem->vat_main = vam;
-
-  /* Ask the vpp engine for the first assigned message-id */
-  name = format (0, "pppoe_%08x%c", api_version, 0);
-  pem->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
-
-  if (pem->msg_id_base != (u16) ~0)
-    pppoe_vat_api_hookup (vam);
-
-  vec_free(name);
-
-  return 0;
-}
+VAT_PLUGIN_REGISTER(pppoe);
index 8fdbeb9..40ebd77 100644 (file)
@@ -154,6 +154,10 @@ vat_plugin_register (vat_main_t * vam)
 
   name = format (0, "stn_%08x%c", api_version, 0);
   sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+  vec_free (name);
+
+  if (sm->msg_id_base == (u16) ~ 0)
+    return clib_error_return (0, "stn plugin not loaded...");
 
   /* Get the control ping ID */
 #define _(id,n,crc) \
@@ -165,8 +169,6 @@ vat_plugin_register (vat_main_t * vam)
   if (sm->msg_id_base != (u16) ~ 0)
     stn_vat_api_hookup (vam);
 
-  vec_free (name);
-
   return 0;
 }
 
index d32bcee..7a70f61 100644 (file)
@@ -330,6 +330,10 @@ vat_plugin_register (vat_main_t * vam)
 
   name = format (0, "vmxnet3_%08x%c", api_version, 0);
   vxm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
+  vec_free (name);
+
+  if (vxm->msg_id_base == (u16) ~ 0)
+    return clib_error_return (0, "vmxnet3 plugin not loaded...");
 
   /* Get the control ping ID */
 #define _(id,n,crc) \
@@ -338,10 +342,7 @@ vat_plugin_register (vat_main_t * vam)
 #undef _
   vxm->ping_id = vl_msg_api_get_msg_index ((u8 *) (VL_API_CONTROL_PING_CRC));
 
-  if (vxm->msg_id_base != (u16) ~ 0)
-    vmxnet3_vat_api_hookup (vam);
-
-  vec_free (name);
+  vmxnet3_vat_api_hookup (vam);
 
   return 0;
 }
index 5bc6772..0abfa73 100644 (file)
@@ -109,5 +109,26 @@ do {                                                            \
     }                                                           \
 } while(0);
 
+#define VAT_PLUGIN_REGISTER(plug)                               \
+clib_error_t * vat_plugin_register (vat_main_t *vam)            \
+{                                                               \
+  plug##_test_main_t * mp = &plug##_test_main;                  \
+  u8 * name;                                                    \
+                                                                \
+  mp->vat_main = vam;                                           \
+                                                                \
+  /* Ask the vpp engine for the first assigned message-id */    \
+  name = format (0, #plug "_%08x%c", api_version, 0);           \
+  mp->msg_id_base =                                             \
+      vl_client_get_first_plugin_msg_id ((char *) name);        \
+  vec_free(name);                                               \
+                                                                \
+  if (mp->msg_id_base != (u16) ~0)                              \
+    plug##_api_hookup (vam);                                    \
+  else                                                          \
+    return clib_error_return (0, #plug " plugin not loaded...");\
+  return 0;                                                     \
+}
+
 
 #endif /* __vat_helper_macros_h__ */