tracenode: filtering feature
[vpp.git] / src / plugins / tracenode / test.c
1 /*
2  * Copyright (c) 2023 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 #include <vat/vat.h>
16 #include <vlibapi/api.h>
17 #include <vlibmemory/api.h>
18 #include <vppinfra/error.h>
19 #include <vnet/api_errno.h>
20 #include <stdbool.h>
21
22 #define __plugin_msg_base tracenode_test_main.msg_id_base
23 #include <vlibapi/vat_helper_macros.h>
24
25 /* Declare message IDs */
26 #include <tracenode/tracenode.api_enum.h>
27 #include <tracenode/tracenode.api_types.h>
28
29 typedef struct
30 {
31   /* API message ID base */
32   u16 msg_id_base;
33   vat_main_t *vat_main;
34 } tracenode_test_main_t;
35
36 tracenode_test_main_t tracenode_test_main;
37
38 int
39 api_tracenode_enable_disable (vat_main_t *vam)
40 {
41   unformat_input_t *i = vam->input;
42   vl_api_tracenode_enable_disable_t *mp;
43   u32 sw_if_index;
44   bool is_pcap, enable;
45
46   sw_if_index = ~0;
47   is_pcap = false;
48   enable = true;
49
50   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
51     {
52       if (unformat (i, "disable"))
53         enable = 0;
54       else if (unformat (i, "pcap"))
55         is_pcap = 1;
56       else if (unformat (i, "%U", unformat_vnet_sw_interface, vnet_get_main (),
57                          &sw_if_index))
58         {
59           if (sw_if_index == 0)
60             {
61               clib_warning ("Local interface not supported...");
62               return -99;
63             }
64         }
65
66       else
67         {
68           clib_warning ("Unknown input: %U\n", format_unformat_error, i);
69           return -99;
70         }
71     }
72
73   M (TRACENODE_ENABLE_DISABLE, mp);
74   mp->sw_if_index = htonl (sw_if_index);
75   mp->is_pcap = is_pcap;
76   mp->enable = enable;
77
78   int ret = 0;
79   S (mp);
80   W (ret);
81
82   return ret;
83 }
84
85 #include <tracenode/tracenode.api_test.c>
86
87 /*
88  * fd.io coding-style-patch-verification: ON
89  *
90  * Local Variables:
91  * eval: (c-set-style "gnu")
92  * End:
93  */