adl: move allow/deny list function to plugin
[vpp.git] / src / plugins / adl / adl_test.c
1 /*
2  * adl.c - adl vpp-api-test plug-in
3  *
4  * Copyright (c) 2020 Cisco Systems and/or affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  *     http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 #include <vat/vat.h>
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
21 #include <stdbool.h>
22
23 #define __plugin_msg_base adl_test_main.msg_id_base
24 #include <vlibapi/vat_helper_macros.h>
25
26 uword unformat_sw_if_index (unformat_input_t * input, va_list * args);
27
28 /* Declare message IDs */
29 #include <adl/adl.api_enum.h>
30 #include <adl/adl.api_types.h>
31
32 typedef struct
33 {
34   /* API message ID base */
35   u16 msg_id_base;
36   vat_main_t *vat_main;
37 } adl_test_main_t;
38
39 adl_test_main_t adl_test_main;
40
41 static int
42 api_adl_interface_enable_disable (vat_main_t * vam)
43 {
44   unformat_input_t *i = vam->input;
45   int enable_disable = 1;
46   u32 sw_if_index = ~0;
47   vl_api_adl_interface_enable_disable_t *mp;
48   int ret;
49
50   /* Parse args required to build the message */
51   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
52     {
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     {
65       errmsg ("missing interface name / explicit sw_if_index number \n");
66       return -99;
67     }
68
69   /* Construct the API message */
70   M (ADL_INTERFACE_ENABLE_DISABLE, mp);
71   mp->sw_if_index = ntohl (sw_if_index);
72   mp->enable_disable = enable_disable;
73
74   /* send it... */
75   S (mp);
76
77   /* Wait for a reply... */
78   W (ret);
79   return ret;
80 }
81
82 static int
83 api_adl_allowlist_enable_disable (vat_main_t * vam)
84 {
85   unformat_input_t *i = vam->input;
86   u32 sw_if_index = ~0;
87   vl_api_adl_allowlist_enable_disable_t *mp;
88   u32 fib_id = ~0;
89   int ip4 = 0;
90   int ip6 = 0;
91   int default_adl = 0;
92   int ret;
93
94   /* Parse args required to build the message */
95   while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
96     {
97       if (unformat (i, "%U", unformat_sw_if_index, vam, &sw_if_index))
98         ;
99       else if (unformat (i, "sw_if_index %d", &sw_if_index))
100         ;
101       else if (unformat (i, "fib-id %d", &fib_id))
102         ;
103       else if (unformat (i, "ip4"))
104         ip4 = 1;
105       else if (unformat (i, "ip6"))
106         ip6 = 1;
107       else if (unformat (i, "default"))
108         default_adl = 1;
109       else
110         break;
111     }
112
113   if (sw_if_index == ~0)
114     {
115       errmsg ("missing interface name / explicit sw_if_index number \n");
116       return -99;
117     }
118
119   if (fib_id == ~0)
120     {
121       errmsg ("FIB id must be specified...\n");
122       return -99;
123     }
124
125   /* Construct the API message */
126   M (ADL_ALLOWLIST_ENABLE_DISABLE, mp);
127   mp->sw_if_index = ntohl (sw_if_index);
128   mp->fib_id = ntohl (fib_id);
129   mp->ip4 = ip4;
130   mp->ip6 = ip6;
131   mp->default_adl = default_adl;
132
133   /* send it... */
134   S (mp);
135
136   /* Wait for a reply... */
137   W (ret);
138   return ret;
139 }
140
141 /*
142  * List of messages that the adl test plugin sends,
143  * and that the data plane plugin processes
144  */
145 #include <adl/adl.api_test.c>
146
147 /*
148  * fd.io coding-style-patch-verification: ON
149  *
150  * Local Variables:
151  * eval: (c-set-style "gnu")
152  * End:
153  */