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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 *------------------------------------------------------------------
17 * vxlan_gpe_test.c - test harness for vxlan_gpe plugin
18 *------------------------------------------------------------------
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
25 #include <vppinfra/error.h>
27 #define __plugin_msg_base vxlan_gpe_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
30 /* Declare message IDs */
31 #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_enum.h>
32 #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api_types.h>
34 #define vl_endianfun /* define message structures */
36 #define vl_api_version(n,v) static u32 api_version=(v);
37 #define vl_print(handle, ...)
38 #include <ioam/lib-vxlan-gpe/ioam_vxlan_gpe.api.h>
43 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
44 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
48 /* API message ID base */
51 } vxlan_gpe_test_main_t;
53 vxlan_gpe_test_main_t vxlan_gpe_test_main;
55 #define foreach_standard_reply_retval_handler \
56 _(vxlan_gpe_ioam_enable_reply) \
57 _(vxlan_gpe_ioam_disable_reply) \
58 _(vxlan_gpe_ioam_vni_enable_reply) \
59 _(vxlan_gpe_ioam_vni_disable_reply) \
60 _(vxlan_gpe_ioam_transit_enable_reply) \
61 _(vxlan_gpe_ioam_transit_disable_reply)
64 static void vl_api_##n##_t_handler \
65 (vl_api_##n##_t * mp) \
67 vat_main_t * vam = vxlan_gpe_test_main.vat_main; \
68 i32 retval = ntohl(mp->retval); \
69 if (vam->async_mode) { \
70 vam->async_errors += (retval < 0); \
72 vam->retval = retval; \
73 vam->result_ready = 1; \
76 foreach_standard_reply_retval_handler;
80 * Table of message reply handlers, must include boilerplate handlers
83 #define foreach_vpe_api_reply_msg \
84 _(VXLAN_GPE_IOAM_ENABLE_REPLY, vxlan_gpe_ioam_enable_reply) \
85 _(VXLAN_GPE_IOAM_DISABLE_REPLY, vxlan_gpe_ioam_disable_reply) \
86 _(VXLAN_GPE_IOAM_VNI_ENABLE_REPLY, vxlan_gpe_ioam_vni_enable_reply) \
87 _(VXLAN_GPE_IOAM_VNI_DISABLE_REPLY, vxlan_gpe_ioam_vni_disable_reply) \
88 _(VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY, vxlan_gpe_ioam_transit_enable_reply) \
89 _(VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY, vxlan_gpe_ioam_transit_disable_reply) \
92 api_vxlan_gpe_ioam_enable (vat_main_t * vam)
94 unformat_input_t *input = vam->input;
95 vl_api_vxlan_gpe_ioam_enable_t *mp;
97 int has_trace_option = 0;
98 int has_pow_option = 0;
99 int has_ppc_option = 0;
102 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
104 if (unformat (input, "trace"))
105 has_trace_option = 1;
106 else if (unformat (input, "pow"))
108 else if (unformat (input, "ppc encap"))
109 has_ppc_option = PPC_ENCAP;
110 else if (unformat (input, "ppc decap"))
111 has_ppc_option = PPC_DECAP;
112 else if (unformat (input, "ppc none"))
113 has_ppc_option = PPC_NONE;
117 M (VXLAN_GPE_IOAM_ENABLE, mp);
119 mp->trace_ppc = has_ppc_option;
120 mp->pow_enable = has_pow_option;
121 mp->trace_enable = has_trace_option;
131 api_vxlan_gpe_ioam_disable (vat_main_t * vam)
133 vl_api_vxlan_gpe_ioam_disable_t *mp;
136 M (VXLAN_GPE_IOAM_DISABLE, mp);
143 api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
145 unformat_input_t *line_input = vam->input;
146 vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
147 ip4_address_t local4, remote4;
148 ip6_address_t local6, remote6;
149 u8 ipv4_set = 0, ipv6_set = 0;
157 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
159 if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
164 else if (unformat (line_input, "remote %U",
165 unformat_ip4_address, &remote4))
170 else if (unformat (line_input, "local %U",
171 unformat_ip6_address, &local6))
176 else if (unformat (line_input, "remote %U",
177 unformat_ip6_address, &remote6))
183 else if (unformat (line_input, "vni %d", &vni))
187 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
194 errmsg ("tunnel local address not specified\n");
199 errmsg ("tunnel remote address not specified\n");
202 if (ipv4_set && ipv6_set)
204 errmsg ("both IPv4 and IPv6 addresses specified");
210 errmsg ("vni not specified\n");
214 M (VXLAN_GPE_IOAM_VNI_ENABLE, mp);
219 clib_memcpy (&mp->local, &local6, sizeof (local6));
220 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
224 clib_memcpy (&mp->local, &local4, sizeof (local4));
225 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
228 mp->vni = ntohl (vni);
229 mp->is_ipv6 = ipv6_set;
237 api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
239 unformat_input_t *line_input = vam->input;
240 vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
241 ip4_address_t local4, remote4;
242 ip6_address_t local6, remote6;
243 u8 ipv4_set = 0, ipv6_set = 0;
251 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
253 if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
258 else if (unformat (line_input, "remote %U",
259 unformat_ip4_address, &remote4))
264 else if (unformat (line_input, "local %U",
265 unformat_ip6_address, &local6))
270 else if (unformat (line_input, "remote %U",
271 unformat_ip6_address, &remote6))
277 else if (unformat (line_input, "vni %d", &vni))
281 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
288 errmsg ("tunnel local address not specified\n");
293 errmsg ("tunnel remote address not specified\n");
296 if (ipv4_set && ipv6_set)
298 errmsg ("both IPv4 and IPv6 addresses specified");
304 errmsg ("vni not specified\n");
308 M (VXLAN_GPE_IOAM_VNI_DISABLE, mp);
313 clib_memcpy (&mp->local, &local6, sizeof (local6));
314 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
318 clib_memcpy (&mp->local, &local4, sizeof (local4));
319 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
322 mp->vni = ntohl (vni);
323 mp->is_ipv6 = ipv6_set;
331 api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
333 unformat_input_t *line_input = vam->input;
334 vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
335 ip4_address_t local4;
336 ip6_address_t local6;
337 u8 ipv4_set = 0, ipv6_set = 0;
339 u32 outer_fib_index = 0;
343 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
345 if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
350 else if (unformat (line_input, "dst-ip %U",
351 unformat_ip6_address, &local6))
357 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
361 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
368 errmsg ("destination address not specified\n");
371 if (ipv4_set && ipv6_set)
373 errmsg ("both IPv4 and IPv6 addresses specified");
378 M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, mp);
383 errmsg ("IPv6 currently unsupported");
388 clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
391 mp->outer_fib_index = htonl (outer_fib_index);
392 mp->is_ipv6 = ipv6_set;
400 api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
402 unformat_input_t *line_input = vam->input;
403 vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
404 ip4_address_t local4;
405 ip6_address_t local6;
406 u8 ipv4_set = 0, ipv6_set = 0;
408 u32 outer_fib_index = 0;
412 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
414 if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
419 else if (unformat (line_input, "dst-ip %U",
420 unformat_ip6_address, &local6))
426 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
430 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
437 errmsg ("destination address not specified\n");
440 if (ipv4_set && ipv6_set)
442 errmsg ("both IPv4 and IPv6 addresses specified");
447 M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, mp);
456 clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
459 mp->outer_fib_index = htonl (outer_fib_index);
460 mp->is_ipv6 = ipv6_set;
468 * List of messages that the api test plugin sends,
469 * and that the data plane plugin processes
471 #define foreach_vpe_api_msg \
472 _(vxlan_gpe_ioam_enable, ""\
473 "[trace] [pow] [ppc <encap|ppc decap>]") \
474 _(vxlan_gpe_ioam_disable, "") \
475 _(vxlan_gpe_ioam_vni_enable, ""\
476 "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
477 _(vxlan_gpe_ioam_vni_disable, ""\
478 "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
479 _(vxlan_gpe_ioam_transit_enable, ""\
480 "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
481 _(vxlan_gpe_ioam_transit_disable, ""\
482 "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
486 vxlan_gpe_vat_api_hookup (vat_main_t * vam)
488 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
489 /* Hook up handlers for replies from the data plane plug-in */
491 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
493 vl_api_##n##_t_handler, \
495 vl_api_##n##_t_endian, \
496 vl_api_##n##_t_print, \
497 sizeof(vl_api_##n##_t), 1);
498 foreach_vpe_api_reply_msg;
501 /* API messages we can send */
502 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
507 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
513 vxlan_gpe_vat_plugin_register (vat_main_t * vam)
515 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
520 name = format (0, "ioam_vxlan_gpe_%08x%c", api_version, 0);
521 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
523 if (sm->msg_id_base != (u16) ~ 0)
524 vxlan_gpe_vat_api_hookup (vam);
532 * fd.io coding-style-patch-verification: ON
535 * eval: (c-set-style "gnu")