Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 1 | ;;; plugin-test-skel.el - vpp-api-test plug-in skeleton |
| 2 | ;;; |
| 3 | ;;; Copyright (c) 2016 Cisco and/or its affiliates. |
| 4 | ;;; Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | ;;; you may not use this file except in compliance with the License. |
| 6 | ;;; You may obtain a copy of the License at: |
| 7 | ;;; |
| 8 | ;;; http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | ;;; |
| 10 | ;;; Unless required by applicable law or agreed to in writing, software |
| 11 | ;;; distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | ;;; WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | ;;; See the License for the specific language governing permissions and |
| 14 | ;;; limitations under the License. |
| 15 | |
| 16 | (require 'skeleton) |
| 17 | |
Keith Burns (alagalah) | ca46d8c | 2016-03-18 07:22:15 -0700 | [diff] [blame] | 18 | (define-skeleton skel-plugin-test |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 19 | "Insert a plug-in vpp-api-test skeleton " |
| 20 | nil |
| 21 | '(if (not (boundp 'plugin-name)) |
| 22 | (setq plugin-name (read-string "Plugin name: "))) |
| 23 | '(setq PLUGIN-NAME (upcase plugin-name)) |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 24 | '(setq capital-oh-en "ON") |
| 25 | "/* |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 26 | * " plugin-name ".c - skeleton vpp-api-test plug-in |
| 27 | * |
| 28 | * Copyright (c) <current-year> <your-organization> |
| 29 | * Licensed under the Apache License, Version 2.0 (the \"License\"); |
| 30 | * you may not use this file except in compliance with the License. |
| 31 | * You may obtain a copy of the License at: |
| 32 | * |
| 33 | * http://www.apache.org/licenses/LICENSE-2.0 |
| 34 | * |
| 35 | * Unless required by applicable law or agreed to in writing, software |
| 36 | * distributed under the License is distributed on an \"AS IS\" BASIS, |
| 37 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 38 | * See the License for the specific language governing permissions and |
| 39 | * limitations under the License. |
| 40 | */ |
| 41 | #include <vat/vat.h> |
| 42 | #include <vlibapi/api.h> |
| 43 | #include <vlibmemory/api.h> |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 44 | #include <vppinfra/error.h> |
| 45 | |
| 46 | uword unformat_sw_if_index (unformat_input_t * input, va_list * args); |
| 47 | |
| 48 | /* Declare message IDs */ |
| 49 | #include <" plugin-name "/" plugin-name "_msg_enum.h> |
| 50 | |
| 51 | /* define message structures */ |
| 52 | #define vl_typedefs |
| 53 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
| 54 | #undef vl_typedefs |
| 55 | |
| 56 | /* declare message handlers for each api */ |
| 57 | |
| 58 | #define vl_endianfun /* define message structures */ |
| 59 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
| 60 | #undef vl_endianfun |
| 61 | |
| 62 | /* instantiate all the print functions we know about */ |
| 63 | #define vl_print(handle, ...) |
| 64 | #define vl_printfun |
| 65 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
| 66 | #undef vl_printfun |
| 67 | |
| 68 | /* Get the API version number. */ |
| 69 | #define vl_api_version(n,v) static u32 api_version=(v); |
| 70 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
| 71 | #undef vl_api_version |
| 72 | |
| 73 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 74 | typedef struct |
| 75 | { |
| 76 | /* API message ID base */ |
| 77 | u16 msg_id_base; |
| 78 | vat_main_t *vat_main; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 79 | } " plugin-name "_test_main_t; |
| 80 | |
| 81 | " plugin-name "_test_main_t " plugin-name "_test_main; |
| 82 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 83 | #define __plugin_msg_base " plugin-name"_test_main.msg_id_base |
| 84 | #include <vlibapi/vat_helper_macros.h> |
| 85 | |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 86 | #define foreach_standard_reply_retval_handler \\ |
| 87 | _(" plugin-name "_enable_disable_reply) |
| 88 | |
| 89 | #define _(n) \\ |
| 90 | static void vl_api_##n##_t_handler \\ |
| 91 | (vl_api_##n##_t * mp) \\ |
| 92 | { \\ |
| 93 | vat_main_t * vam = " plugin-name "_test_main.vat_main; \\ |
| 94 | i32 retval = ntohl(mp->retval); \\ |
| 95 | if (vam->async_mode) { \\ |
| 96 | vam->async_errors += (retval < 0); \\ |
| 97 | } else { \\ |
| 98 | vam->retval = retval; \\ |
| 99 | vam->result_ready = 1; \\ |
| 100 | } \\ |
| 101 | } |
| 102 | foreach_standard_reply_retval_handler; |
| 103 | #undef _ |
| 104 | |
| 105 | /* |
| 106 | * Table of message reply handlers, must include boilerplate handlers |
| 107 | * we just generated |
| 108 | */ |
| 109 | #define foreach_vpe_api_reply_msg \\ |
| 110 | _(" PLUGIN-NAME "_ENABLE_DISABLE_REPLY, " plugin-name "_enable_disable_reply) |
| 111 | |
| 112 | |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 113 | static int api_" plugin-name "_enable_disable (vat_main_t * vam) |
| 114 | { |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 115 | unformat_input_t * i = vam->input; |
| 116 | int enable_disable = 1; |
| 117 | u32 sw_if_index = ~0; |
| 118 | vl_api_" plugin-name "_enable_disable_t * mp; |
| 119 | int ret; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 120 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 121 | /* Parse args required to build the message */ |
| 122 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
| 123 | { |
| 124 | if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index)) |
| 125 | ; |
| 126 | else if (unformat (i, \"sw_if_index %d\", &sw_if_index)) |
| 127 | ; |
| 128 | else if (unformat (i, \"disable\")) |
| 129 | enable_disable = 0; |
| 130 | else |
| 131 | break; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 132 | } |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 133 | |
| 134 | if (sw_if_index == ~0) |
| 135 | { |
| 136 | errmsg (\"missing interface name / explicit sw_if_index number \\n\"); |
| 137 | return -99; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 138 | } |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 139 | |
| 140 | /* Construct the API message */ |
| 141 | M(" PLUGIN-NAME "_ENABLE_DISABLE, mp); |
| 142 | mp->sw_if_index = ntohl (sw_if_index); |
| 143 | mp->enable_disable = enable_disable; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 144 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 145 | /* send it... */ |
| 146 | S(mp); |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 147 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 148 | /* Wait for a reply... */ |
| 149 | W (ret); |
| 150 | return ret; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 151 | } |
| 152 | |
| 153 | /* |
| 154 | * List of messages that the api test plugin sends, |
| 155 | * and that the data plane plugin processes |
| 156 | */ |
| 157 | #define foreach_vpe_api_msg \\ |
| 158 | _(" plugin-name "_enable_disable, \"<intfc> [disable]\") |
| 159 | |
Dave Barach | 99617f7 | 2017-03-04 08:35:48 -0500 | [diff] [blame] | 160 | static void " plugin-name "_api_hookup (vat_main_t *vam) |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 161 | { |
| 162 | " plugin-name "_test_main_t * sm = &" plugin-name "_test_main; |
| 163 | /* Hook up handlers for replies from the data plane plug-in */ |
| 164 | #define _(N,n) \\ |
| 165 | vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \\ |
| 166 | #n, \\ |
| 167 | vl_api_##n##_t_handler, \\ |
| 168 | vl_noop_handler, \\ |
| 169 | vl_api_##n##_t_endian, \\ |
| 170 | vl_api_##n##_t_print, \\ |
| 171 | sizeof(vl_api_##n##_t), 1); |
| 172 | foreach_vpe_api_reply_msg; |
| 173 | #undef _ |
| 174 | |
| 175 | /* API messages we can send */ |
| 176 | #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n); |
| 177 | foreach_vpe_api_msg; |
| 178 | #undef _ |
| 179 | |
| 180 | /* Help strings */ |
| 181 | #define _(n,h) hash_set_mem (vam->help_by_name, #n, h); |
| 182 | foreach_vpe_api_msg; |
| 183 | #undef _ |
| 184 | } |
| 185 | |
| 186 | clib_error_t * vat_plugin_register (vat_main_t *vam) |
| 187 | { |
| 188 | " plugin-name "_test_main_t * sm = &" plugin-name "_test_main; |
| 189 | u8 * name; |
| 190 | |
| 191 | sm->vat_main = vam; |
| 192 | |
| 193 | /* Ask the vpp engine for the first assigned message-id */ |
| 194 | name = format (0, \"" plugin-name "_%08x%c\", api_version, 0); |
| 195 | sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name); |
| 196 | |
| 197 | if (sm->msg_id_base != (u16) ~0) |
Dave Barach | 99617f7 | 2017-03-04 08:35:48 -0500 | [diff] [blame] | 198 | " plugin-name "_api_hookup (vam); |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 199 | |
| 200 | vec_free(name); |
| 201 | |
| 202 | return 0; |
| 203 | } |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 204 | /* |
| 205 | * fd.io coding-style-patch-verification: " capital-oh-en " |
| 206 | * |
| 207 | * Local Variables: |
| 208 | * eval: (c-set-style \"gnu\") |
| 209 | * End: |
| 210 | */ |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 211 | ") |