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