api: split api generated files
[vpp.git] / src / examples / sample-plugin / sample / sample_test.c
1 /*
2  * Copyright (c) 2015 Cisco and/or its affiliates.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at:
6  *
7  *     http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 /*
16  *------------------------------------------------------------------
17  * sample_test.c - test harness plugin
18  *------------------------------------------------------------------
19  */
20
21 #include <vat/vat.h>
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
24 #include <vppinfra/error.h>
25
26 #define __plugin_msg_base sample_test_main.msg_id_base
27 #include <vlibapi/vat_helper_macros.h>
28
29 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
30
31 /* Declare message IDs */
32 #include <sample/sample.api_enum.h>
33 #include <sample/sample.api_types.h>
34
35 typedef struct {
36     /* API message ID base */
37     u16 msg_id_base;
38     vat_main_t *vat_main;
39 } sample_test_main_t;
40
41 sample_test_main_t sample_test_main;
42
43 static int api_sample_macswap_enable_disable (vat_main_t * vam)
44 {
45     unformat_input_t * i = vam->input;
46     int enable_disable = 1;
47     u32 sw_if_index = ~0;
48     vl_api_sample_macswap_enable_disable_t * mp;
49     int ret;
50
51     /* Parse args required to build the message */
52     while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT) {
53         if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
54             ;
55         else if (unformat (i, "sw_if_index %d", &sw_if_index))
56             ;
57         else if (unformat (i, "disable"))
58             enable_disable = 0;
59         else
60             break;
61     }
62
63     if (sw_if_index == ~0) {
64         errmsg ("missing interface name / explicit sw_if_index number \n");
65         return -99;
66     }
67
68     /* Construct the API message */
69     M(SAMPLE_MACSWAP_ENABLE_DISABLE, mp);
70     mp->sw_if_index = ntohl (sw_if_index);
71     mp->enable_disable = enable_disable;
72
73     /* send it... */
74     S(mp);
75
76     /* Wait for a reply... */
77     W (ret);
78     return ret;
79 }
80
81 /*
82  * List of messages that the api test plugin sends,
83  * and that the data plane plugin processes
84  */
85 #include <sample/sample.api_test.c>