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 | 4ec6f6b | 2019-10-01 12:10:57 -0400 | [diff] [blame] | 27 | * " plugin-name ".c - " plugin-name " 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 | |
Dave Barach | 4ec6f6b | 2019-10-01 12:10:57 -0400 | [diff] [blame] | 48 | #define __plugin_msg_base " plugin-name"_test_main.msg_id_base |
| 49 | #include <vlibapi/vat_helper_macros.h> |
| 50 | |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 51 | uword unformat_sw_if_index (unformat_input_t * input, va_list * args); |
| 52 | |
| 53 | /* Declare message IDs */ |
Dave Barach | 4ec6f6b | 2019-10-01 12:10:57 -0400 | [diff] [blame] | 54 | #include <" plugin-name "/" plugin-name ".api_enum.h> |
| 55 | #include <" plugin-name "/" plugin-name ".api_types.h> |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 56 | |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 57 | typedef struct |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 58 | { |
| 59 | /* API message ID base */ |
| 60 | u16 msg_id_base; |
| 61 | vat_main_t *vat_main; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 62 | } " plugin-name "_test_main_t; |
| 63 | |
| 64 | " plugin-name "_test_main_t " plugin-name "_test_main; |
| 65 | |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 66 | static int api_" plugin-name "_enable_disable (vat_main_t * vam) |
| 67 | { |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 68 | unformat_input_t * i = vam->input; |
| 69 | int enable_disable = 1; |
| 70 | u32 sw_if_index = ~0; |
| 71 | vl_api_" plugin-name "_enable_disable_t * mp; |
| 72 | int ret; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 73 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 74 | /* Parse args required to build the message */ |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 75 | while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 76 | { |
| 77 | if (unformat (i, \"%U\", unformat_sw_if_index, vam, &sw_if_index)) |
| 78 | ; |
| 79 | else if (unformat (i, \"sw_if_index %d\", &sw_if_index)) |
| 80 | ; |
| 81 | else if (unformat (i, \"disable\")) |
| 82 | enable_disable = 0; |
| 83 | else |
| 84 | break; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 85 | } |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 86 | |
| 87 | if (sw_if_index == ~0) |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 88 | { |
| 89 | errmsg (\"missing interface name / explicit sw_if_index number \\n\"); |
| 90 | return -99; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 91 | } |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 92 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 93 | /* Construct the API message */ |
| 94 | M(" PLUGIN-NAME "_ENABLE_DISABLE, mp); |
| 95 | mp->sw_if_index = ntohl (sw_if_index); |
| 96 | mp->enable_disable = enable_disable; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 97 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 98 | /* send it... */ |
| 99 | S(mp); |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 100 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 101 | /* Wait for a reply... */ |
| 102 | W (ret); |
| 103 | return ret; |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 104 | } |
| 105 | |
Dave Barach | 913f4c9 | 2019-05-29 09:59:51 -0400 | [diff] [blame] | 106 | /* |
Dave Barach | 4ec6f6b | 2019-10-01 12:10:57 -0400 | [diff] [blame] | 107 | * List of messages that the " plugin-name" test plugin sends, |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 108 | * and that the data plane plugin processes |
| 109 | */ |
Dave Barach | 4ec6f6b | 2019-10-01 12:10:57 -0400 | [diff] [blame] | 110 | #include <" plugin-name "/" plugin-name ".api_test.c> |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 111 | |
Dave Barach | fed79e8 | 2017-02-10 11:57:46 -0500 | [diff] [blame] | 112 | /* |
| 113 | * fd.io coding-style-patch-verification: " capital-oh-en " |
| 114 | * |
| 115 | * Local Variables: |
| 116 | * eval: (c-set-style \"gnu\") |
| 117 | * End: |
| 118 | */ |
Dave Barach | b852bfa | 2016-01-04 15:27:42 -0500 | [diff] [blame] | 119 | ") |