Line data Source code
1 : /*
2 : * Copyright (c) 2016 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 : * vxlan_gpe_test.c - test harness for vxlan_gpe plugin
18 : *------------------------------------------------------------------
19 : */
20 :
21 : #include <vat/vat.h>
22 : #include <vlibapi/api.h>
23 : #include <vlibmemory/api.h>
24 :
25 : #include <vppinfra/error.h>
26 : #include <vnet/format_fns.h>
27 : #include <vnet/ip/ip_types_api.h>
28 :
29 : #define __plugin_msg_base ioam_vxlan_gpe_test_main.msg_id_base
30 : #include <vlibapi/vat_helper_macros.h>
31 :
32 : /* Declare message IDs */
33 : #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_enum.h>
34 : #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_types.h>
35 :
36 : #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
37 : #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
38 :
39 : typedef struct
40 : {
41 : /* API message ID base */
42 : u16 msg_id_base;
43 : vat_main_t *vat_main;
44 : } ioam_vxlan_gpe_test_main_t;
45 :
46 : ioam_vxlan_gpe_test_main_t ioam_vxlan_gpe_test_main;
47 :
48 : static int
49 0 : api_vxlan_gpe_ioam_enable (vat_main_t * vam)
50 : {
51 0 : unformat_input_t *input = vam->input;
52 : vl_api_vxlan_gpe_ioam_enable_t *mp;
53 0 : u32 id = 0;
54 0 : int has_trace_option = 0;
55 0 : int has_pow_option = 0;
56 0 : int has_ppc_option = 0;
57 : int ret;
58 :
59 0 : while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
60 : {
61 0 : if (unformat (input, "trace"))
62 0 : has_trace_option = 1;
63 0 : else if (unformat (input, "pow"))
64 0 : has_pow_option = 1;
65 0 : else if (unformat (input, "ppc encap"))
66 0 : has_ppc_option = PPC_ENCAP;
67 0 : else if (unformat (input, "ppc decap"))
68 0 : has_ppc_option = PPC_DECAP;
69 0 : else if (unformat (input, "ppc none"))
70 0 : has_ppc_option = PPC_NONE;
71 : else
72 0 : break;
73 : }
74 0 : M (VXLAN_GPE_IOAM_ENABLE, mp);
75 0 : mp->id = htons (id);
76 0 : mp->trace_ppc = has_ppc_option;
77 0 : mp->pow_enable = has_pow_option;
78 0 : mp->trace_enable = has_trace_option;
79 :
80 :
81 0 : S (mp);
82 0 : W (ret);
83 0 : return ret;
84 : }
85 :
86 :
87 : static int
88 0 : api_vxlan_gpe_ioam_disable (vat_main_t * vam)
89 : {
90 : vl_api_vxlan_gpe_ioam_disable_t *mp;
91 : int ret;
92 :
93 0 : M (VXLAN_GPE_IOAM_DISABLE, mp);
94 0 : S (mp);
95 0 : W (ret);
96 0 : return ret;
97 : }
98 :
99 : static int
100 0 : api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
101 : {
102 0 : unformat_input_t *line_input = vam->input;
103 : vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
104 : ip46_address_t local, remote;
105 0 : u8 local_set = 0;
106 0 : u8 remote_set = 0;
107 : u32 vni;
108 0 : u8 vni_set = 0;
109 : int ret;
110 :
111 :
112 0 : while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
113 : {
114 0 : if (unformat (line_input, "local %U", unformat_ip46_address, &local))
115 : {
116 0 : local_set = 1;
117 : }
118 0 : else if (unformat (line_input, "remote %U",
119 : unformat_ip46_address, &remote))
120 : {
121 0 : remote_set = 1;
122 : }
123 0 : else if (unformat (line_input, "vni %d", &vni))
124 0 : vni_set = 1;
125 : else
126 : {
127 0 : errmsg ("parse error '%U'\n", format_unformat_error, line_input);
128 0 : return -99;
129 : }
130 : }
131 :
132 0 : if (local_set == 0)
133 : {
134 0 : errmsg ("tunnel local address not specified\n");
135 0 : return -99;
136 : }
137 0 : if (remote_set == 0)
138 : {
139 0 : errmsg ("tunnel remote address not specified\n");
140 0 : return -99;
141 : }
142 0 : if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
143 : {
144 0 : errmsg ("both IPv4 and IPv6 addresses specified");
145 0 : return -99;
146 : }
147 :
148 0 : if (vni_set == 0)
149 : {
150 0 : errmsg ("vni not specified\n");
151 0 : return -99;
152 : }
153 :
154 0 : M (VXLAN_GPE_IOAM_VNI_ENABLE, mp);
155 :
156 0 : ip_address_encode (&local,
157 0 : ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
158 0 : IP46_TYPE_IP6, &mp->local);
159 0 : ip_address_encode (&local,
160 0 : ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
161 0 : IP46_TYPE_IP6, &mp->remote);
162 :
163 0 : mp->vni = ntohl (vni);
164 :
165 0 : S (mp);
166 0 : W (ret);
167 0 : return ret;
168 : }
169 :
170 : static int
171 0 : api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
172 : {
173 0 : unformat_input_t *line_input = vam->input;
174 : vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
175 : ip46_address_t local, remote;
176 0 : u8 local_set = 0;
177 0 : u8 remote_set = 0;
178 : u32 vni;
179 0 : u8 vni_set = 0;
180 : int ret;
181 :
182 :
183 0 : while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
184 : {
185 0 : if (unformat (line_input, "local %U", unformat_ip46_address, &local))
186 : {
187 0 : local_set = 1;
188 : }
189 0 : else if (unformat (line_input, "remote %U",
190 : unformat_ip46_address, &remote))
191 : {
192 0 : remote_set = 1;
193 : }
194 0 : else if (unformat (line_input, "vni %d", &vni))
195 0 : vni_set = 1;
196 : else
197 : {
198 0 : errmsg ("parse error '%U'\n", format_unformat_error, line_input);
199 0 : return -99;
200 : }
201 : }
202 :
203 0 : if (local_set == 0)
204 : {
205 0 : errmsg ("tunnel local address not specified\n");
206 0 : return -99;
207 : }
208 0 : if (remote_set == 0)
209 : {
210 0 : errmsg ("tunnel remote address not specified\n");
211 0 : return -99;
212 : }
213 0 : if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
214 : {
215 0 : errmsg ("both IPv4 and IPv6 addresses specified");
216 0 : return -99;
217 : }
218 :
219 0 : if (vni_set == 0)
220 : {
221 0 : errmsg ("vni not specified\n");
222 0 : return -99;
223 : }
224 :
225 0 : M (VXLAN_GPE_IOAM_VNI_DISABLE, mp);
226 :
227 0 : ip_address_encode (&local,
228 0 : ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
229 0 : IP46_TYPE_IP6, &mp->local);
230 0 : ip_address_encode (&local,
231 0 : ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
232 0 : IP46_TYPE_IP6, &mp->remote);
233 :
234 0 : mp->vni = ntohl (vni);
235 :
236 0 : S (mp);
237 0 : W (ret);
238 0 : return ret;
239 : }
240 :
241 : static int
242 0 : api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
243 : {
244 0 : unformat_input_t *line_input = vam->input;
245 : vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
246 : ip46_address_t local;
247 0 : u8 local_set = 0;
248 0 : u32 outer_fib_index = 0;
249 : int ret;
250 :
251 :
252 0 : while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
253 : {
254 0 : if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
255 : {
256 0 : local_set = 1;
257 : }
258 0 : else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
259 : ;
260 : else
261 : {
262 0 : errmsg ("parse error '%U'\n", format_unformat_error, line_input);
263 0 : return -99;
264 : }
265 : }
266 :
267 0 : if (local_set == 0)
268 : {
269 0 : errmsg ("destination address not specified\n");
270 0 : return -99;
271 : }
272 :
273 0 : M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, mp);
274 :
275 :
276 0 : if (!ip46_address_is_ip4 (&local))
277 : {
278 0 : errmsg ("IPv6 currently unsupported");
279 0 : return -1;
280 : }
281 0 : ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
282 0 : mp->outer_fib_index = htonl (outer_fib_index);
283 :
284 0 : S (mp);
285 0 : W (ret);
286 0 : return ret;
287 : }
288 :
289 : static int
290 0 : api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
291 : {
292 0 : unformat_input_t *line_input = vam->input;
293 : vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
294 : ip46_address_t local;
295 0 : u8 local_set = 0;
296 0 : u32 outer_fib_index = 0;
297 : int ret;
298 :
299 :
300 0 : while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
301 : {
302 0 : if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
303 : {
304 0 : local_set = 1;
305 : }
306 0 : else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
307 : ;
308 : else
309 : {
310 0 : errmsg ("parse error '%U'\n", format_unformat_error, line_input);
311 0 : return -99;
312 : }
313 : }
314 :
315 0 : if (local_set == 0)
316 : {
317 0 : errmsg ("destination address not specified\n");
318 0 : return -99;
319 : }
320 :
321 0 : M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, mp);
322 :
323 :
324 0 : if (!ip46_address_is_ip4 (&local))
325 : {
326 0 : return -1;
327 : }
328 0 : ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
329 :
330 0 : mp->outer_fib_index = htonl (outer_fib_index);
331 :
332 0 : S (mp);
333 0 : W (ret);
334 0 : return ret;
335 : }
336 :
337 : /* Override generated plugin register symbol */
338 : #define vat_plugin_register vxlan_gpe_vat_plugin_register
339 : #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_test.c>
340 :
341 : /*
342 : * fd.io coding-style-patch-verification: ON
343 : *
344 : * Local Variables:
345 : * eval: (c-set-style "gnu")
346 : * End:
347 : */
|