blob: fee34bfe402a7684de1094921894792d9a27f05e [file] [log] [blame]
Dave Barachb852bfa2016-01-04 15:27:42 -05001;;; 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)ca46d8c2016-03-18 07:22:15 -070018(define-skeleton skel-plugin-test
Dave Barachb852bfa2016-01-04 15:27:42 -050019"Insert a plug-in vpp-api-test skeleton "
20nil
21'(if (not (boundp 'plugin-name))
22 (setq plugin-name (read-string "Plugin name: ")))
23'(setq PLUGIN-NAME (upcase plugin-name))
Dave Barachfed79e82017-02-10 11:57:46 -050024'(setq capital-oh-en "ON")
Dave Barach82842442018-10-31 09:54:34 -040025'(setq main-p (concat (substring plugin-name 0 1) "tmp"))
Dave Barachfed79e82017-02-10 11:57:46 -050026"/*
Dave Barach4ec6f6b2019-10-01 12:10:57 -040027 * " plugin-name ".c - " plugin-name " vpp-api-test plug-in
Dave Barachb852bfa2016-01-04 15:27:42 -050028 *
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 Barachb852bfa2016-01-04 15:27:42 -050045#include <vppinfra/error.h>
Dave Barach913f4c92019-05-29 09:59:51 -040046#include <stdbool.h>
Dave Barachb852bfa2016-01-04 15:27:42 -050047
Dave Barach4ec6f6b2019-10-01 12:10:57 -040048#define __plugin_msg_base " plugin-name"_test_main.msg_id_base
49#include <vlibapi/vat_helper_macros.h>
50
Dave Barachb852bfa2016-01-04 15:27:42 -050051uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
52
53/* Declare message IDs */
Dave Barach4ec6f6b2019-10-01 12:10:57 -040054#include <" plugin-name "/" plugin-name ".api_enum.h>
55#include <" plugin-name "/" plugin-name ".api_types.h>
Dave Barachb852bfa2016-01-04 15:27:42 -050056
Dave Barach913f4c92019-05-29 09:59:51 -040057typedef struct
Dave Barachfed79e82017-02-10 11:57:46 -050058{
59 /* API message ID base */
60 u16 msg_id_base;
61 vat_main_t *vat_main;
Dave Barachb852bfa2016-01-04 15:27:42 -050062} " plugin-name "_test_main_t;
63
64" plugin-name "_test_main_t " plugin-name "_test_main;
65
Dave Barachb852bfa2016-01-04 15:27:42 -050066static int api_" plugin-name "_enable_disable (vat_main_t * vam)
67{
Dave Barachfed79e82017-02-10 11:57:46 -050068 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 Barachb852bfa2016-01-04 15:27:42 -050073
Dave Barachfed79e82017-02-10 11:57:46 -050074 /* Parse args required to build the message */
Dave Barach913f4c92019-05-29 09:59:51 -040075 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
Dave Barachfed79e82017-02-10 11:57:46 -050076 {
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 Barachb852bfa2016-01-04 15:27:42 -050085 }
Dave Barach913f4c92019-05-29 09:59:51 -040086
87 if (sw_if_index == ~0)
Dave Barachfed79e82017-02-10 11:57:46 -050088 {
89 errmsg (\"missing interface name / explicit sw_if_index number \\n\");
90 return -99;
Dave Barachb852bfa2016-01-04 15:27:42 -050091 }
Dave Barach913f4c92019-05-29 09:59:51 -040092
Dave Barachfed79e82017-02-10 11:57:46 -050093 /* 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 Barachb852bfa2016-01-04 15:27:42 -050097
Dave Barachfed79e82017-02-10 11:57:46 -050098 /* send it... */
99 S(mp);
Dave Barachb852bfa2016-01-04 15:27:42 -0500100
Dave Barachfed79e82017-02-10 11:57:46 -0500101 /* Wait for a reply... */
102 W (ret);
103 return ret;
Dave Barachb852bfa2016-01-04 15:27:42 -0500104}
105
Dave Barach913f4c92019-05-29 09:59:51 -0400106/*
Dave Barach4ec6f6b2019-10-01 12:10:57 -0400107 * List of messages that the " plugin-name" test plugin sends,
Dave Barachb852bfa2016-01-04 15:27:42 -0500108 * and that the data plane plugin processes
109 */
Dave Barach4ec6f6b2019-10-01 12:10:57 -0400110#include <" plugin-name "/" plugin-name ".api_test.c>
Dave Barachb852bfa2016-01-04 15:27:42 -0500111
Dave Barachfed79e82017-02-10 11:57:46 -0500112/*
113 * fd.io coding-style-patch-verification: " capital-oh-en "
114 *
115 * Local Variables:
116 * eval: (c-set-style \"gnu\")
117 * End:
118 */
Dave Barachb852bfa2016-01-04 15:27:42 -0500119")