From cb034b9b374927c7552e36dcbc306d8456b2a0cb Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Wed, 28 Dec 2016 18:38:59 +0100 Subject: Move java,lua api and remaining plugins to src/ Change-Id: I1c3b87e886603678368428ae56a6bd3327cbc90d Signed-off-by: Damjan Marion --- src/examples/sample-plugin/sample/sample.c | 255 +++++++++++++++++++++++++++++ 1 file changed, 255 insertions(+) create mode 100644 src/examples/sample-plugin/sample/sample.c (limited to 'src/examples/sample-plugin/sample/sample.c') diff --git a/src/examples/sample-plugin/sample/sample.c b/src/examples/sample-plugin/sample/sample.c new file mode 100644 index 00000000..603cb2d0 --- /dev/null +++ b/src/examples/sample-plugin/sample/sample.c @@ -0,0 +1,255 @@ +/* + * 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. + */ +/* + *------------------------------------------------------------------ + * sample.c - simple MAC-swap API / debug CLI handling + *------------------------------------------------------------------ + */ + +#include +#include +#include + +#include +#include +#include + +/* define message IDs */ +#include + +/* define message structures */ +#define vl_typedefs +#include +#undef vl_typedefs + +/* define generated endian-swappers */ +#define vl_endianfun +#include +#undef vl_endianfun + +/* instantiate all the print functions we know about */ +#define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) +#define vl_printfun +#include +#undef vl_printfun + +/* Get the API version number */ +#define vl_api_version(n,v) static u32 api_version=(v); +#include +#undef vl_api_version + +/* + * A handy macro to set up a message reply. + * Assumes that the following variables are available: + * mp - pointer to request message + * rmp - pointer to reply message type + * rv - return value + */ + +#define REPLY_MACRO(t) \ +do { \ + unix_shared_memory_queue_t * q = \ + vl_api_client_index_to_input_queue (mp->client_index); \ + if (!q) \ + return; \ + \ + rmp = vl_msg_api_alloc (sizeof (*rmp)); \ + rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ + rmp->context = mp->context; \ + rmp->retval = ntohl(rv); \ + \ + vl_msg_api_send_shmem (q, (u8 *)&rmp); \ +} while(0); + + +/* List of message types that this plugin understands */ + +#define foreach_sample_plugin_api_msg \ +_(SAMPLE_MACSWAP_ENABLE_DISABLE, sample_macswap_enable_disable) + +/* + * This routine exists to convince the vlib plugin framework that + * we haven't accidentally copied a random .dll into the plugin directory. + * + * Also collects global variable pointers passed from the vpp engine + */ + +clib_error_t * +vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h, + int from_early_init) +{ + sample_main_t * sm = &sample_main; + clib_error_t * error = 0; + + sm->vlib_main = vm; + sm->vnet_main = h->vnet_main; + sm->ethernet_main = h->ethernet_main; + + return error; +} + +/* Action function shared between message handler and debug CLI */ + +int sample_macswap_enable_disable (sample_main_t * sm, u32 sw_if_index, + int enable_disable) +{ + vnet_sw_interface_t * sw; + int rv = 0; + + /* Utterly wrong? */ + if (pool_is_free_index (sm->vnet_main->interface_main.sw_interfaces, + sw_if_index)) + return VNET_API_ERROR_INVALID_SW_IF_INDEX; + + /* Not a physical port? */ + sw = vnet_get_sw_interface (sm->vnet_main, sw_if_index); + if (sw->type != VNET_SW_INTERFACE_TYPE_HARDWARE) + return VNET_API_ERROR_INVALID_SW_IF_INDEX; + + vnet_feature_enable_disable ("device-input", "sample", + sw_if_index, enable_disable, 0, 0); + + return rv; +} + +static clib_error_t * +macswap_enable_disable_command_fn (vlib_main_t * vm, + unformat_input_t * input, + vlib_cli_command_t * cmd) +{ + sample_main_t * sm = &sample_main; + u32 sw_if_index = ~0; + int enable_disable = 1; + + int rv; + + while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) { + if (unformat (input, "disable")) + enable_disable = 0; + else if (unformat (input, "%U", unformat_vnet_sw_interface, + sm->vnet_main, &sw_if_index)) + ; + else + break; + } + + if (sw_if_index == ~0) + return clib_error_return (0, "Please specify an interface..."); + + rv = sample_macswap_enable_disable (sm, sw_if_index, enable_disable); + + switch(rv) { + case 0: + break; + + case VNET_API_ERROR_INVALID_SW_IF_INDEX: + return clib_error_return + (0, "Invalid interface, only works on physical ports"); + break; + + case VNET_API_ERROR_UNIMPLEMENTED: + return clib_error_return (0, "Device driver doesn't support redirection"); + break; + + default: + return clib_error_return (0, "sample_macswap_enable_disable returned %d", + rv); + } + return 0; +} + +VLIB_CLI_COMMAND (sr_content_command, static) = { + .path = "sample macswap", + .short_help = + "sample macswap [disable]", + .function = macswap_enable_disable_command_fn, +}; + +/* API message handler */ +static void vl_api_sample_macswap_enable_disable_t_handler +(vl_api_sample_macswap_enable_disable_t * mp) +{ + vl_api_sample_macswap_enable_disable_reply_t * rmp; + sample_main_t * sm = &sample_main; + int rv; + + rv = sample_macswap_enable_disable (sm, ntohl(mp->sw_if_index), + (int) (mp->enable_disable)); + + REPLY_MACRO(VL_API_SAMPLE_MACSWAP_ENABLE_DISABLE_REPLY); +} + +/* Set up the API message handling tables */ +static clib_error_t * +sample_plugin_api_hookup (vlib_main_t *vm) +{ + sample_main_t * sm = &sample_main; +#define _(N,n) \ + vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \ + #n, \ + vl_api_##n##_t_handler, \ + vl_noop_handler, \ + vl_api_##n##_t_endian, \ + vl_api_##n##_t_print, \ + sizeof(vl_api_##n##_t), 1); + foreach_sample_plugin_api_msg; +#undef _ + + return 0; +} + +#define vl_msg_name_crc_list +#include +#undef vl_msg_name_crc_list + +static void +setup_message_id_table (sample_main_t * sm, api_main_t *am) +{ +#define _(id,n,crc) \ + vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); + foreach_vl_msg_name_crc_sample; +#undef _ +} + +static clib_error_t * sample_init (vlib_main_t * vm) +{ + sample_main_t * sm = &sample_main; + clib_error_t * error = 0; + u8 * name; + + name = format (0, "sample_%08x%c", api_version, 0); + + /* Ask for a correctly-sized block of API message decode slots */ + sm->msg_id_base = vl_msg_api_get_msg_ids + ((char *) name, VL_MSG_FIRST_AVAILABLE); + + error = sample_plugin_api_hookup (vm); + + /* Add our API messages to the global name_crc hash table */ + setup_message_id_table (sm, &api_main); + + vec_free(name); + + return error; +} + +VLIB_INIT_FUNCTION (sample_init); + +VNET_FEATURE_INIT (sample, static) = +{ + .arc_name = "device-input", + .node_name = "sample", + .runs_before = VNET_FEATURES ("ethernet-input"), +}; -- cgit 1.2.3-korg From a4cb12b30d51be3463315688179297404783fe8d Mon Sep 17 00:00:00 2001 From: Anlu Yan Date: Tue, 14 Feb 2017 18:07:40 -0800 Subject: Fix sample plugin breakage. Add vat_helper_macros.h to be installed in /usr/include/vlibapi Define a version for the sample plugin (separate from the VPP versioning). Hook up vnet_main in plugin init. Change-Id: I293b9dc824d0813ea2bb8747d535e4210a88b385 Signed-off-by: Anlu Yan --- src/examples/sample-plugin/sample/sample.c | 27 +++++++-------------------- src/examples/sample-plugin/sample/sample.h | 4 ++-- src/vlib-api.am | 2 +- 3 files changed, 10 insertions(+), 23 deletions(-) (limited to 'src/examples/sample-plugin/sample/sample.c') diff --git a/src/examples/sample-plugin/sample/sample.c b/src/examples/sample-plugin/sample/sample.c index 603cb2d0..7588dbc0 100644 --- a/src/examples/sample-plugin/sample/sample.c +++ b/src/examples/sample-plugin/sample/sample.c @@ -79,26 +79,11 @@ do { \ #define foreach_sample_plugin_api_msg \ _(SAMPLE_MACSWAP_ENABLE_DISABLE, sample_macswap_enable_disable) -/* - * This routine exists to convince the vlib plugin framework that - * we haven't accidentally copied a random .dll into the plugin directory. - * - * Also collects global variable pointers passed from the vpp engine - */ - -clib_error_t * -vlib_plugin_register (vlib_main_t * vm, vnet_plugin_handoff_t * h, - int from_early_init) -{ - sample_main_t * sm = &sample_main; - clib_error_t * error = 0; - - sm->vlib_main = vm; - sm->vnet_main = h->vnet_main; - sm->ethernet_main = h->ethernet_main; - - return error; -} +/* *INDENT-OFF* */ +VLIB_PLUGIN_REGISTER () = { + .version = SAMPLE_PLUGIN_BUILD_VER, +}; +/* *INDENT-ON* */ /* Action function shared between message handler and debug CLI */ @@ -229,6 +214,8 @@ static clib_error_t * sample_init (vlib_main_t * vm) clib_error_t * error = 0; u8 * name; + sm->vnet_main = vnet_get_main (); + name = format (0, "sample_%08x%c", api_version, 0); /* Ask for a correctly-sized block of API message decode slots */ diff --git a/src/examples/sample-plugin/sample/sample.h b/src/examples/sample-plugin/sample/sample.h index 6137ffff..c9778f74 100644 --- a/src/examples/sample-plugin/sample/sample.h +++ b/src/examples/sample-plugin/sample/sample.h @@ -28,13 +28,13 @@ typedef struct { u16 msg_id_base; /* convenience */ - vlib_main_t * vlib_main; vnet_main_t * vnet_main; - ethernet_main_t * ethernet_main; } sample_main_t; sample_main_t sample_main; extern vlib_node_registration_t sample_node; +#define SAMPLE_PLUGIN_BUILD_VER "1.0" + #endif /* __included_sample_h__ */ diff --git a/src/vlib-api.am b/src/vlib-api.am index 6312f93d..c05929b1 100644 --- a/src/vlib-api.am +++ b/src/vlib-api.am @@ -34,7 +34,7 @@ libvlibapi_la_SOURCES = \ vlibapi/api_shared.c \ vlibapi/node_serialize.c -nobase_include_HEADERS += vlibapi/api.h vlibapi/api_helper_macros.h +nobase_include_HEADERS += vlibapi/api.h vlibapi/api_helper_macros.h vlibapi/vat_helper_macros.h libvlibmemoryclient_la_DEPENDENCIES = libvppinfra.la libsvm.la libvlib.la libvlibmemory.la libvlibapi.la libvlibmemoryclient_la_LIBADD = $(libvlibmemoryclient_la_DEPENDENCIES) -lpthread -- cgit 1.2.3-korg From b614d08368cc0b04e01c5222d4c11a88845394e5 Mon Sep 17 00:00:00 2001 From: Eyal Bari Date: Thu, 16 Mar 2017 10:02:57 +0200 Subject: API:replaced all REPLY_MACRO's with api_helper_macros.h Change-Id: I08ab1fd0abdd1db4aff11a38c9c0134b01368e11 Signed-off-by: Eyal Bari --- src/examples/sample-plugin/sample/sample.c | 25 +------ src/plugins/acl/acl.c | 83 ++++------------------ src/plugins/flowperpkt/flowperpkt.c | 41 +---------- .../ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c | 27 +------ src/plugins/ioam/export/ioam_export.c | 26 +------ src/plugins/ioam/ip6/ioam_cache.c | 26 +------ src/plugins/ioam/lib-pot/pot_api.c | 41 +---------- src/plugins/ioam/udp-ping/udp_ping_api.c | 41 +---------- src/plugins/lb/api.c | 27 ++----- src/plugins/snat/snat.c | 2 +- src/vlibapi/api_helper_macros.h | 8 +-- 11 files changed, 39 insertions(+), 308 deletions(-) (limited to 'src/examples/sample-plugin/sample/sample.c') diff --git a/src/examples/sample-plugin/sample/sample.c b/src/examples/sample-plugin/sample/sample.c index 7588dbc0..01852746 100644 --- a/src/examples/sample-plugin/sample/sample.c +++ b/src/examples/sample-plugin/sample/sample.c @@ -50,29 +50,8 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ diff --git a/src/plugins/acl/acl.c b/src/plugins/acl/acl.c index b6af7380..0d06531d 100644 --- a/src/plugins/acl/acl.c +++ b/src/plugins/acl/acl.c @@ -57,61 +57,8 @@ acl_main_t acl_main; -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - -#define REPLY_MACRO2(t, body) \ -do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+am->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - -#define REPLY_MACRO3(t, n, body) \ -do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \ - rmp->_vl_msg_id = ntohs((t)+am->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE am->msg_id_base +#include /* List of message types that this plugin understands */ @@ -1409,7 +1356,7 @@ vl_api_acl_add_replace_t_handler (vl_api_acl_add_replace_t * mp) static void vl_api_acl_del_t_handler (vl_api_acl_del_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_acl_del_reply_t *rmp; int rv; @@ -1421,8 +1368,8 @@ vl_api_acl_del_t_handler (vl_api_acl_del_t * mp) static void vl_api_acl_interface_add_del_t_handler (vl_api_acl_interface_add_del_t * mp) { - acl_main_t *sm = &acl_main; - vnet_interface_main_t *im = &sm->vnet_main->interface_main; + acl_main_t *am = &acl_main; + vnet_interface_main_t *im = &am->vnet_main->interface_main; u32 sw_if_index = ntohl (mp->sw_if_index); vl_api_acl_interface_add_del_reply_t *rmp; int rv = -1; @@ -1441,11 +1388,11 @@ static void vl_api_acl_interface_set_acl_list_t_handler (vl_api_acl_interface_set_acl_list_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_acl_interface_set_acl_list_reply_t *rmp; int rv = 0; int i; - vnet_interface_main_t *im = &sm->vnet_main->interface_main; + vnet_interface_main_t *im = &am->vnet_main->interface_main; u32 sw_if_index = ntohl (mp->sw_if_index); if (pool_is_free_index(im->sw_interfaces, sw_if_index)) @@ -1667,7 +1614,7 @@ vl_api_macip_acl_add_t_handler (vl_api_macip_acl_add_t * mp) static void vl_api_macip_acl_del_t_handler (vl_api_macip_acl_del_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_macip_acl_del_reply_t *rmp; int rv; @@ -1680,10 +1627,10 @@ static void vl_api_macip_acl_interface_add_del_t_handler (vl_api_macip_acl_interface_add_del_t * mp) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; vl_api_macip_acl_interface_add_del_reply_t *rmp; int rv = -1; - vnet_interface_main_t *im = &sm->vnet_main->interface_main; + vnet_interface_main_t *im = &am->vnet_main->interface_main; u32 sw_if_index = ntohl (mp->sw_if_index); if (pool_is_free_index(im->sw_interfaces, sw_if_index)) @@ -1819,9 +1766,9 @@ vl_api_macip_acl_interface_get_t_handler (vl_api_macip_acl_interface_get_t * static clib_error_t * acl_plugin_api_hookup (vlib_main_t * vm) { - acl_main_t *sm = &acl_main; + acl_main_t *am = &acl_main; #define _(N,n) \ - vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \ + vl_msg_api_set_handlers((VL_API_##N + am->msg_id_base), \ #n, \ vl_api_##n##_t_handler, \ vl_noop_handler, \ @@ -1839,10 +1786,10 @@ acl_plugin_api_hookup (vlib_main_t * vm) #undef vl_msg_name_crc_list static void -setup_message_id_table (acl_main_t * sm, api_main_t * am) +setup_message_id_table (acl_main_t * am, api_main_t * apim) { #define _(id,n,crc) \ - vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base); + vl_msg_api_add_msg_name_crc (apim, #n "_" #crc, id + am->msg_id_base); foreach_vl_msg_name_crc_acl; #undef _ } @@ -1852,11 +1799,11 @@ register_match_action_nexts (u32 next_in_ip4, u32 next_in_ip6, u32 next_out_ip4, u32 next_out_ip6) { acl_main_t *am = &acl_main; - u32 act = am->n_match_actions; if (am->n_match_actions == 255) { return ~0; } + u32 act = am->n_match_actions; am->n_match_actions++; am->acl_in_ip4_match_next[act] = next_in_ip4; am->acl_in_ip6_match_next[act] = next_in_ip6; diff --git a/src/plugins/flowperpkt/flowperpkt.c b/src/plugins/flowperpkt/flowperpkt.c index 6b292eef..587972f7 100644 --- a/src/plugins/flowperpkt/flowperpkt.c +++ b/src/plugins/flowperpkt/flowperpkt.c @@ -58,6 +58,9 @@ flowperpkt_main_t flowperpkt_main; #include #undef vl_api_version +#define REPLY_MSG_ID_BASE fm->msg_id_base +#include + /* Define the per-interface configurable features */ /* *INDENT-OFF* */ VNET_FEATURE_INIT (flow_perpacket_ipv4, static) = @@ -75,28 +78,6 @@ VNET_FEATURE_INIT (flow_perpacket_l2, static) = }; /* *INDENT-ON* */ -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+fm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - /* Macro to finish up custom dump fns */ #define FINISH \ vec_add1 (s, 0); \ @@ -104,22 +85,6 @@ do { \ vec_free (s); \ return handle; -#define VALIDATE_SW_IF_INDEX(mp) \ - do { u32 __sw_if_index = ntohl(mp->sw_if_index); \ - vnet_main_t *__vnm = vnet_get_main(); \ - if (pool_is_free_index(__vnm->interface_main.sw_interfaces, \ - __sw_if_index)) { \ - rv = VNET_API_ERROR_INVALID_SW_IF_INDEX; \ - goto bad_sw_if_index; \ - } \ -} while(0); - -#define BAD_SW_IF_INDEX_LABEL \ -do { \ -bad_sw_if_index: \ - ; \ -} while (0); - /** * @brief Create an IPFIX template packet rewrite string * @param frm flow_report_main_t * diff --git a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c index f05b5303..b703b8d0 100644 --- a/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c +++ b/src/plugins/ioam/export-vxlan-gpe/vxlan_gpe_ioam_export.c @@ -53,33 +53,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ - - #define foreach_vxlan_gpe_ioam_export_plugin_api_msg \ _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE, vxlan_gpe_ioam_export_enable_disable) diff --git a/src/plugins/ioam/export/ioam_export.c b/src/plugins/ioam/export/ioam_export.c index eeeb9738..46ac3d4a 100644 --- a/src/plugins/ioam/export/ioam_export.c +++ b/src/plugins/ioam/export/ioam_export.c @@ -52,32 +52,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ - #define foreach_ioam_export_plugin_api_msg \ _(IOAM_EXPORT_IP6_ENABLE_DISABLE, ioam_export_ip6_enable_disable) diff --git a/src/plugins/ioam/ip6/ioam_cache.c b/src/plugins/ioam/ip6/ioam_cache.c index 9e90ff9a..a4079e84 100644 --- a/src/plugins/ioam/ip6/ioam_cache.c +++ b/src/plugins/ioam/ip6/ioam_cache.c @@ -53,32 +53,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+cm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - +#define REPLY_MSG_ID_BASE cm->msg_id_base +#include /* List of message types that this plugin understands */ - #define foreach_ioam_cache_plugin_api_msg \ _(IOAM_CACHE_IP6_ENABLE_DISABLE, ioam_cache_ip6_enable_disable) diff --git a/src/plugins/ioam/lib-pot/pot_api.c b/src/plugins/ioam/lib-pot/pot_api.c index 04c2aaa5..cc1b7b76 100644 --- a/src/plugins/ioam/lib-pot/pot_api.c +++ b/src/plugins/ioam/lib-pot/pot_api.c @@ -51,47 +51,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - -#define REPLY_MACRO2(t, body) \ -do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this plugin understands */ - #define foreach_pot_plugin_api_msg \ _(POT_PROFILE_ADD, pot_profile_add) \ _(POT_PROFILE_ACTIVATE, pot_profile_activate) \ diff --git a/src/plugins/ioam/udp-ping/udp_ping_api.c b/src/plugins/ioam/udp-ping/udp_ping_api.c index 8cb8cc96..6e5ef61e 100644 --- a/src/plugins/ioam/udp-ping/udp_ping_api.c +++ b/src/plugins/ioam/udp-ping/udp_ping_api.c @@ -51,47 +51,10 @@ #include #undef vl_api_version -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ - do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ - } while(0); - -#define REPLY_MACRO2(t, body) \ - do { \ - unix_shared_memory_queue_t * q; \ - rv = vl_msg_api_pd_handler (mp, rv); \ - q = vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - do {body;} while (0); \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ - } while(0); +#define REPLY_MSG_ID_BASE sm->msg_id_base +#include /* List of message types that this module understands */ - #define foreach_udp_ping_api_msg \ _(UDP_PING_ADD_DEL_REQ, udp_ping_add_del_req) \ _(UDP_PING_EXPORT_REQ, udp_ping_export_req) \ diff --git a/src/plugins/lb/api.c b/src/plugins/lb/api.c index 06c53fa1..9e3bcd65 100644 --- a/src/plugins/lb/api.c +++ b/src/plugins/lb/api.c @@ -51,6 +51,10 @@ typedef enum { #include #undef vl_msg_name_crc_list + +#define REPLY_MSG_ID_BASE lbm->msg_id_base +#include + static void setup_message_id_table (lb_main_t * lbm, api_main_t * am) { @@ -67,29 +71,6 @@ setup_message_id_table (lb_main_t * lbm, api_main_t * am) vec_free (s); \ return handle; -/* - * A handy macro to set up a message reply. - * Assumes that the following variables are available: - * mp - pointer to request message - * rmp - pointer to reply message type - * rv - return value - */ - -#define REPLY_MACRO(t) \ -do { \ - unix_shared_memory_queue_t * q = \ - vl_api_client_index_to_input_queue (mp->client_index); \ - if (!q) \ - return; \ - \ - rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = ntohs((t)+lbm->msg_id_base); \ - rmp->context = mp->context; \ - rmp->retval = ntohl(rv); \ - \ - vl_msg_api_send_shmem (q, (u8 *)&rmp); \ -} while(0); - static void vl_api_lb_conf_t_handler (vl_api_lb_conf_t * mp) diff --git a/src/plugins/snat/snat.c b/src/plugins/snat/snat.c index 57274bbe..d42303f6 100644 --- a/src/plugins/snat/snat.c +++ b/src/plugins/snat/snat.c @@ -47,7 +47,7 @@ snat_main_t snat_main; #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__) -#define REPLY_MSG_ID_BASE (sm->msg_id_base) +#define REPLY_MSG_ID_BASE sm->msg_id_base #include /* Get the API version number */ diff --git a/src/vlibapi/api_helper_macros.h b/src/vlibapi/api_helper_macros.h index aacea7c1..a492c3f4 100644 --- a/src/vlibapi/api_helper_macros.h +++ b/src/vlibapi/api_helper_macros.h @@ -36,7 +36,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ \ @@ -52,7 +52,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp)); \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ do {body;} while (0); \ @@ -68,7 +68,7 @@ do { \ return; \ \ rmp = vl_msg_api_alloc (sizeof (*rmp) + n); \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ do {body;} while (0); \ @@ -97,7 +97,7 @@ do { \ rv = VNET_API_ERROR_TABLE_TOO_BIG; \ is_error = 1; \ } \ - rmp->_vl_msg_id = htons((t)+REPLY_MSG_ID_BASE); \ + rmp->_vl_msg_id = htons((t)+(REPLY_MSG_ID_BASE)); \ rmp->context = mp->context; \ rmp->retval = ntohl(rv); \ if (!is_error) \ -- cgit 1.2.3-korg From 1bfb0ddace3ebb9010275e4bdd847c8c493ff4b3 Mon Sep 17 00:00:00 2001 From: Damjan Marion Date: Wed, 22 Mar 2017 11:08:39 +0100 Subject: vlib: add description field in plugin registration Change-Id: I88b322a5d602f3d6d3310e971479180a89430e0e Signed-off-by: Damjan Marion --- src/examples/sample-plugin/sample/sample.c | 1 + src/plugins/acl/acl.c | 1 + src/plugins/dpdk/main.c | 1 + src/plugins/flowperpkt/flowperpkt.c | 1 + src/plugins/ila/ila.c | 1 + src/plugins/ioam/encap/ip6_ioam_trace.c | 1 + src/plugins/ixge/ixge.c | 1 + src/plugins/lb/lb.c | 1 + src/plugins/sixrd/sixrd.c | 3 ++- src/plugins/snat/snat.c | 1 + src/vlib/unix/plugin.c | 14 +++++++++----- src/vlib/unix/plugin.h | 1 + 12 files changed, 21 insertions(+), 6 deletions(-) (limited to 'src/examples/sample-plugin/sample/sample.c') diff --git a/src/examples/sample-plugin/sample/sample.c b/src/examples/sample-plugin/sample/sample.c index 01852746..2f8ac4c9 100644 --- a/src/examples/sample-plugin/sample/sample.c +++ b/src/examples/sample-plugin/sample/sample.c @@ -61,6 +61,7 @@ _(SAMPLE_MACSWAP_ENABLE_DISABLE, sample_macswap_enable_disable) /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = SAMPLE_PLUGIN_BUILD_VER, + .description = "Sample of VPP Plugin", }; /* *INDENT-ON* */ diff --git a/src/plugins/acl/acl.c b/src/plugins/acl/acl.c index 476fbc33..4a4dd434 100644 --- a/src/plugins/acl/acl.c +++ b/src/plugins/acl/acl.c @@ -80,6 +80,7 @@ _(MACIP_ACL_INTERFACE_GET, macip_acl_interface_get) /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, + .description = "Access Control Lists", }; /* *INDENT-ON* */ diff --git a/src/plugins/dpdk/main.c b/src/plugins/dpdk/main.c index 8073a50a..7ee2a785 100644 --- a/src/plugins/dpdk/main.c +++ b/src/plugins/dpdk/main.c @@ -91,5 +91,6 @@ VLIB_INIT_FUNCTION (dpdk_main_init); /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, + .description = "Data Plane Development Kit (DPDK)", }; /* *INDENT-ON* */ diff --git a/src/plugins/flowperpkt/flowperpkt.c b/src/plugins/flowperpkt/flowperpkt.c index 587972f7..3e5fc8b0 100644 --- a/src/plugins/flowperpkt/flowperpkt.c +++ b/src/plugins/flowperpkt/flowperpkt.c @@ -448,6 +448,7 @@ _(FLOWPERPKT_TX_INTERFACE_ADD_DEL, flowperpkt_tx_interface_add_del) /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, + .description = "Flow per Packet", }; /* *INDENT-ON* */ diff --git a/src/plugins/ila/ila.c b/src/plugins/ila/ila.c index 52c7ea55..edbf3017 100644 --- a/src/plugins/ila/ila.c +++ b/src/plugins/ila/ila.c @@ -825,6 +825,7 @@ ila_interface (u32 sw_if_index, u8 disable) /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, + .description = "Identifier-locator addressing for IPv6", }; /* *INDENT-ON* */ diff --git a/src/plugins/ioam/encap/ip6_ioam_trace.c b/src/plugins/ioam/encap/ip6_ioam_trace.c index 57d3ec5d..299ee88f 100644 --- a/src/plugins/ioam/encap/ip6_ioam_trace.c +++ b/src/plugins/ioam/encap/ip6_ioam_trace.c @@ -411,6 +411,7 @@ VLIB_CLI_COMMAND (ip6_show_ioam_trace_cmd, static) = { /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, + .description = "Inbound OAM", }; /* *INDENT-ON* */ diff --git a/src/plugins/ixge/ixge.c b/src/plugins/ixge/ixge.c index 4eebc457..f3c5cc09 100644 --- a/src/plugins/ixge/ixge.c +++ b/src/plugins/ixge/ixge.c @@ -2935,6 +2935,7 @@ ixge_set_next_node (ixge_rx_next_t next, char *name) VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, .default_disabled = 1, + .description = "Intel 82599 Family Native Driver (experimental)", }; /* *INDENT-ON* */ diff --git a/src/plugins/lb/lb.c b/src/plugins/lb/lb.c index dc3f5be1..add81236 100644 --- a/src/plugins/lb/lb.c +++ b/src/plugins/lb/lb.c @@ -734,6 +734,7 @@ int lb_vip_del(u32 vip_index) /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, + .description = "Load Balancer", }; /* *INDENT-ON* */ diff --git a/src/plugins/sixrd/sixrd.c b/src/plugins/sixrd/sixrd.c index 67a9a3ad..98387525 100644 --- a/src/plugins/sixrd/sixrd.c +++ b/src/plugins/sixrd/sixrd.c @@ -356,8 +356,9 @@ VLIB_CLI_COMMAND(show_sixrd_stats_command, static) = { }; /* *INDENT-OFF* */ -VLIB_PLUGIN_REGISTER () = { +VLIB_PLUGIN_REGISTER () ={ .version = VPP_BUILD_VER, + .description = "IPv6 Rapid Deployment on IPv4 Infrastructure (RFC5969)", }; /* *INDENT-ON* */ diff --git a/src/plugins/snat/snat.c b/src/plugins/snat/snat.c index d42303f6..70b6a6e2 100644 --- a/src/plugins/snat/snat.c +++ b/src/plugins/snat/snat.c @@ -107,6 +107,7 @@ VNET_FEATURE_INIT (ip4_snat_out2in_fast, static) = { /* *INDENT-OFF* */ VLIB_PLUGIN_REGISTER () = { .version = VPP_BUILD_VER, + .description = "Network Address Translation", }; /* *INDENT-ON* */ diff --git a/src/vlib/unix/plugin.c b/src/vlib/unix/plugin.c index e9846e3b..9b341cc8 100644 --- a/src/vlib/unix/plugin.c +++ b/src/vlib/unix/plugin.c @@ -105,13 +105,13 @@ load_one_plugin (plugin_main_t * pm, plugin_info_t * pi, int from_early_init) } if (reg->default_disabled && pc->is_enabled == 0) { - clib_warning ("Plugin disabled: %s (default)", pi->name); + clib_warning ("Plugin disabled (default): %s", pi->name); goto error; } } else if (reg->default_disabled) { - clib_warning ("Plugin disabled: %s (default)", pi->name); + clib_warning ("Plugin disabled (default): %s", pi->name); goto error; } @@ -184,7 +184,10 @@ load_one_plugin (plugin_main_t * pm, plugin_info_t * pi, int from_early_init) (char *) pi->name, reg->early_init); } - clib_warning ("Loaded plugin: %s", pi->name); + if (reg->description) + clib_warning ("Loaded plugin: %s (%s)", pi->name, reg->description); + else + clib_warning ("Loaded plugin: %s", pi->name); return 0; error: @@ -374,7 +377,7 @@ vlib_plugins_show_cmd_fn (vlib_main_t * vm, plugin_info_t *pi; s = format (s, " Plugin path is: %s\n\n", pm->plugin_path); - s = format (s, " %-41s%s\n", "Plugin", "Version"); + s = format (s, " %-41s%-33s%s\n", "Plugin", "Version", "Description"); /* *INDENT-OFF* */ hash_foreach_mem (key, value, pm->plugin_by_name_hash, @@ -382,7 +385,8 @@ vlib_plugins_show_cmd_fn (vlib_main_t * vm, if (key != 0) { pi = vec_elt_at_index (pm->plugin_info, value); - s = format (s, "%3d. %-40s %s\n", index, key, pi->version); + s = format (s, "%3d. %-40s %-32s %s\n", index, key, pi->version, + pi->reg->description ? pi->reg->description : ""); index++; } }); diff --git a/src/vlib/unix/plugin.h b/src/vlib/unix/plugin.h index 01fec356..d9801ec4 100644 --- a/src/vlib/unix/plugin.h +++ b/src/vlib/unix/plugin.h @@ -62,6 +62,7 @@ typedef CLIB_PACKED(struct { const char version[32]; const char version_required[32]; const char *early_init; + const char *description; }) vlib_plugin_registration_t; /* *INDENT-ON* */ -- cgit 1.2.3-korg From 583dc8d3e23a780c85ebe48ea59f0338aad4df17 Mon Sep 17 00:00:00 2001 From: Ray Kinsella Date: Thu, 8 Jun 2017 15:54:19 +0100 Subject: Sample plugin: Add sample plugin documentation Added some user documentation to sample plugin. Change-Id: I518910f80499307e8fcac8dcef7baaeab5ea8e35 Signed-off-by: Ray Kinsella --- README.md | 2 +- doxygen/Makefile | 3 +- doxygen/user_doc.md | 1 + src/examples/sample-plugin/sample/sample.c | 30 ++++++++--- src/examples/sample-plugin/sample_plugin_doc.md | 66 +++++++++++++++++++++++++ 5 files changed, 92 insertions(+), 10 deletions(-) create mode 100644 src/examples/sample-plugin/sample_plugin_doc.md (limited to 'src/examples/sample-plugin/sample/sample.c') diff --git a/README.md b/README.md index 7f429d12..596494b9 100644 --- a/README.md +++ b/README.md @@ -45,7 +45,7 @@ Directory name | Description @ref src/vppinfra | VPP core library test | Unit tests @ref src/vpp/api | Not-yet-relocated API bindings - +@ref src/examples | VPP example code ## Getting started diff --git a/doxygen/Makefile b/doxygen/Makefile index abaca185..b6ba5887 100644 --- a/doxygen/Makefile +++ b/doxygen/Makefile @@ -74,8 +74,7 @@ DOXY_INPUT := $(subst $(WS_ROOT)/,,$(DOXY_INPUT)) # These must be left-anchored paths for the regexp below to work. DOXY_EXCLUDE ?= \ $(DOXY_SRC)/vlib/buffer.c \ - $(DOXY_SRC)/vpp-api/lua \ - $(DOXY_SRC)/examples/sample-plugin + $(DOXY_SRC)/vpp-api/lua # Generate a regexp for filenames to exclude DOXY_EXCLUDE_REGEXP = ($(subst .,\.,$(shell echo '$(strip $(DOXY_EXCLUDE))' | sed -e 's/ /|/g'))) diff --git a/doxygen/user_doc.md b/doxygen/user_doc.md index becc2e0a..c0a05bd9 100644 --- a/doxygen/user_doc.md +++ b/doxygen/user_doc.md @@ -16,3 +16,4 @@ Several modules provide operational, dataplane-user focused documentation. - @subpage span_doc - @subpage srv6_doc - @subpage srmpls_doc +- @subpage sample_plugin_doc diff --git a/src/examples/sample-plugin/sample/sample.c b/src/examples/sample-plugin/sample/sample.c index 2f8ac4c9..3929ac23 100644 --- a/src/examples/sample-plugin/sample/sample.c +++ b/src/examples/sample-plugin/sample/sample.c @@ -12,10 +12,9 @@ * See the License for the specific language governing permissions and * limitations under the License. */ -/* - *------------------------------------------------------------------ - * sample.c - simple MAC-swap API / debug CLI handling - *------------------------------------------------------------------ +/** + * @file + * @brief Sample Plugin, plugin API / trace / CLI handling. */ #include @@ -65,7 +64,11 @@ VLIB_PLUGIN_REGISTER () = { }; /* *INDENT-ON* */ -/* Action function shared between message handler and debug CLI */ +/** + * @brief Enable/disable the macswap plugin. + * + * Action function shared between message handler and debug CLI. + */ int sample_macswap_enable_disable (sample_main_t * sm, u32 sw_if_index, int enable_disable) @@ -135,6 +138,9 @@ macswap_enable_disable_command_fn (vlib_main_t * vm, return 0; } +/** + * @brief CLI command to enable/disable the sample macswap plugin. + */ VLIB_CLI_COMMAND (sr_content_command, static) = { .path = "sample macswap", .short_help = @@ -142,7 +148,9 @@ VLIB_CLI_COMMAND (sr_content_command, static) = { .function = macswap_enable_disable_command_fn, }; -/* API message handler */ +/** + * @brief Plugin API message handler. + */ static void vl_api_sample_macswap_enable_disable_t_handler (vl_api_sample_macswap_enable_disable_t * mp) { @@ -156,7 +164,9 @@ static void vl_api_sample_macswap_enable_disable_t_handler REPLY_MACRO(VL_API_SAMPLE_MACSWAP_ENABLE_DISABLE_REPLY); } -/* Set up the API message handling tables */ +/** + * @brief Set up the API message handling tables. + */ static clib_error_t * sample_plugin_api_hookup (vlib_main_t *vm) { @@ -188,6 +198,9 @@ setup_message_id_table (sample_main_t * sm, api_main_t *am) #undef _ } +/** + * @brief Initialize the sample plugin. + */ static clib_error_t * sample_init (vlib_main_t * vm) { sample_main_t * sm = &sample_main; @@ -214,6 +227,9 @@ static clib_error_t * sample_init (vlib_main_t * vm) VLIB_INIT_FUNCTION (sample_init); +/** + * @brief Hook the sample plugin into the VPP graph hierarchy. + */ VNET_FEATURE_INIT (sample, static) = { .arc_name = "device-input", diff --git a/src/examples/sample-plugin/sample_plugin_doc.md b/src/examples/sample-plugin/sample_plugin_doc.md new file mode 100644 index 00000000..9348094c --- /dev/null +++ b/src/examples/sample-plugin/sample_plugin_doc.md @@ -0,0 +1,66 @@ +# Sample plugin for VPP {#sample_plugin_doc} + +## Overview + +This is the VPP sample plugin demonstrates how to create a new plugin that integrates +with VPP. The sample code implements a trival macswap algorithim that demonstrates plugin +runtime integration with the VPP graph hierachy, api and cli. + +For deeper dive information see the annotations in the sample code itself. See [sample.c](@ref sample.c) + +## How to build and run the sample plugin. + +Now (re)build VPP. + + $ make wipe + +Define environmental variable 'VPP_WITH_SAMPLE_PLUGIN=yes' with a process scope + + $ VPP_WITH_SAMPLE_PLUGIN=yes make build + +or a session scope, and build VPP. + + $ export VPP_WITH_SAMPLE_PLUGIN=yes + & make build + +Now run VPP and make sure the plugin is loaded. + + $ make run + ... + load_one_plugin:184: Loaded plugin: memif_plugin.so (Packet Memory Interface (experimetal)) + load_one_plugin:184: Loaded plugin: sample_plugin.so (Sample of VPP Plugin) + load_one_plugin:184: Loaded plugin: snat_plugin.so (Network Address Translation) + ... + DBGvpp# + +## How to create a new plugin + +To create a new plugin based on the sample plugin, copy and rename the sample plugin directory and automake config. + + cp -r src/examples/sample-plugin/sample src/plugins/newplugin + cp src/examples/sample-plugin/sample.am src/plugins/newplugin.am + +Add the following entry to the plugins section of `src/configure.ac`. + + PLUGIN_ENABLED(newplugin) + +Add the following entry to the plugins section of `src/plugins/Makefile.am` + + if ENABLE_NEWPLUGIN + include newplugin.am + endif + +Now (re)build VPP. + + $ make wipe + $ make build + +## Configuration + +To enable the sample plugin + + sample macswap + +To disable the sample plugin + + sample macswap disable -- cgit 1.2.3-korg