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 | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 27 | * " plugin-name ".c - skeleton vpp-api-test plug-in |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 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> |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 46 | #include <stdbool.h> |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 47 | |
| 48 | uword unformat_sw_if_index (unformat_input_t * input, va_list * args); |
| 49 | |
| 50 | /* Declare message IDs */ |
| 51 | #include <" plugin-name "/" plugin-name "_msg_enum.h> |
| 52 | |
| 53 | /* define message structures */ |
| 54 | #define vl_typedefs |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 55 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 56 | #undef vl_typedefs |
| 57 | |
| 58 | /* declare message handlers for each api */ |
| 59 | |
| 60 | #define vl_endianfun /* define message structures */ |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 61 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 62 | #undef vl_endianfun |
| 63 | |
| 64 | /* instantiate all the print functions we know about */ |
| 65 | #define vl_print(handle, ...) |
| 66 | #define vl_printfun |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 67 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 68 | #undef vl_printfun |
| 69 | |
| 70 | /* Get the API version number. */ |
| 71 | #define vl_api_version(n,v) static u32 api_version=(v); |
| 72 | #include <" plugin-name "/" plugin-name "_all_api_h.h> |
| 73 | #undef vl_api_version |
| 74 | |
| 75 | |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 76 | typedef struct |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 77 | { |
| 78 | /* API message ID base */ |
| 79 | u16 msg_id_base; |
| 80 | vat_main_t *vat_main; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 81 | } " plugin-name "_test_main_t; |
| 82 | |
| 83 | " plugin-name "_test_main_t " plugin-name "_test_main; |
| 84 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 85 | #define __plugin_msg_base " plugin-name"_test_main.msg_id_base |
| 86 | #include <vlibapi/vat_helper_macros.h> |
| 87 | |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 88 | #define foreach_standard_reply_retval_handler \\ |
| 89 | _(" plugin-name "_enable_disable_reply) |
| 90 | |
| 91 | #define _(n) \\ |
| 92 | static void vl_api_##n##_t_handler \\ |
| 93 | (vl_api_##n##_t * mp) \\ |
| 94 | { \\ |
| 95 | vat_main_t * vam = " plugin-name "_test_main.vat_main; \\ |
| 96 | i32 retval = ntohl(mp->retval); \\ |
| 97 | if (vam->async_mode) { \\ |
| 98 | vam->async_errors += (retval < 0); \\ |
| 99 | } else { \\ |
| 100 | vam->retval = retval; \\ |
| 101 | vam->result_ready = 1; \\ |
| 102 | } \\ |
| 103 | } |
| 104 | foreach_standard_reply_retval_handler; |
| 105 | #undef _ |
| 106 | |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 107 | /* |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 108 | * Table of message reply handlers, must include boilerplate handlers |
| 109 | * we just generated |
| 110 | */ |
| 111 | #define foreach_vpe_api_reply_msg \\ |
| 112 | _(" PLUGIN-NAME "_ENABLE_DISABLE_REPLY, " plugin-name "_enable_disable_reply) |
| 113 | |
| 114 | |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 115 | static int api_" plugin-name "_enable_disable (vat_main_t * vam) |
| 116 | { |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 117 | unformat_input_t * i = vam->input; |
| 118 | int enable_disable = 1; |
| 119 | u32 sw_if_index = ~0; |
| 120 | vl_api_" plugin-name "_enable_disable_t * mp; |
| 121 | int ret; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 122 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 123 | /* Parse args required to build the message */ |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 124 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 125 | { |
| 126 | if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index)) |
| 127 | ; |
| 128 | else if (unformat (i, \"sw_if_index %d\", &sw_if_index)) |
| 129 | ; |
| 130 | else if (unformat (i, \"disable\")) |
| 131 | enable_disable = 0; |
| 132 | else |
| 133 | break; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 134 | } |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 135 | |
| 136 | if (sw_if_index == ~0) |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 137 | { |
| 138 | errmsg (\"missing interface name / explicit sw_if_index number \\n\"); |
| 139 | return -99; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 140 | } |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 141 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 142 | /* Construct the API message */ |
| 143 | M(" PLUGIN-NAME "_ENABLE_DISABLE, mp); |
| 144 | mp->sw_if_index = ntohl (sw_if_index); |
| 145 | mp->enable_disable = enable_disable; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 146 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 147 | /* send it... */ |
| 148 | S(mp); |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 149 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 150 | /* Wait for a reply... */ |
| 151 | W (ret); |
| 152 | return ret; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 153 | } |
| 154 | |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 155 | /* |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 156 | * List of messages that the api test plugin sends, |
| 157 | * and that the data plane plugin processes |
| 158 | */ |
| 159 | #define foreach_vpe_api_msg \\ |
| 160 | _(" plugin-name "_enable_disable, \"<intfc> [disable]\") |
| 161 | |
Dave Barach | 99617f7 | 2017-03-04 08:35:48 -0500 | [diff] [blame] | 162 | static void " plugin-name "_api_hookup (vat_main_t *vam) |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 163 | { |
Dave Barach | 8284244 | 2018-10-31 09:54:34 -0400 | [diff] [blame] | 164 | " plugin-name "_test_main_t * " main-p " = &" plugin-name "_test_main; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 165 | /* Hook up handlers for replies from the data plane plug-in */ |
| 166 | #define _(N,n) \\ |
Dave Barach | 8284244 | 2018-10-31 09:54:34 -0400 | [diff] [blame] | 167 | 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] | 168 | #n, \\ |
| 169 | vl_api_##n##_t_handler, \\ |
| 170 | vl_noop_handler, \\ |
| 171 | vl_api_##n##_t_endian, \\ |
| 172 | vl_api_##n##_t_print, \\ |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 173 | sizeof(vl_api_##n##_t), 1); |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 174 | foreach_vpe_api_reply_msg; |
| 175 | #undef _ |
| 176 | |
| 177 | /* API messages we can send */ |
| 178 | #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n); |
| 179 | foreach_vpe_api_msg; |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 180 | #undef _ |
| 181 | |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 182 | /* Help strings */ |
| 183 | #define _(n,h) hash_set_mem (vam->help_by_name, #n, h); |
| 184 | foreach_vpe_api_msg; |
| 185 | #undef _ |
| 186 | } |
| 187 | |
Dave Barach | e5a7d59 | 2019-07-09 14:22:21 -0400 | [diff] [blame^] | 188 | VAT_PLUGIN_REGISTER(" plugin-name"); |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 189 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 190 | /* |
| 191 | * fd.io coding-style-patch-verification: " capital-oh-en " |
| 192 | * |
| 193 | * Local Variables: |
| 194 | * eval: (c-set-style \"gnu\") |
| 195 | * End: |
| 196 | */ |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 197 | ") |