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>
24 #include <vlibsocket/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/vxlan_gpe_msg_enum.h>
33 /* define message structures */
35 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
38 /* declare message handlers for each api */
40 #define vl_endianfun /* define message structures */
41 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...)
47 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
50 /* Get the API version number. */
51 #define vl_api_version(n,v) static u32 api_version=(v);
52 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
54 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
55 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
59 /* API message ID base */
62 } vxlan_gpe_test_main_t;
64 vxlan_gpe_test_main_t vxlan_gpe_test_main;
66 #define foreach_standard_reply_retval_handler \
67 _(vxlan_gpe_ioam_enable_reply) \
68 _(vxlan_gpe_ioam_disable_reply) \
69 _(vxlan_gpe_ioam_vni_enable_reply) \
70 _(vxlan_gpe_ioam_vni_disable_reply) \
71 _(vxlan_gpe_ioam_transit_enable_reply) \
72 _(vxlan_gpe_ioam_transit_disable_reply)
75 static void vl_api_##n##_t_handler \
76 (vl_api_##n##_t * mp) \
78 vat_main_t * vam = vxlan_gpe_test_main.vat_main; \
79 i32 retval = ntohl(mp->retval); \
80 if (vam->async_mode) { \
81 vam->async_errors += (retval < 0); \
83 vam->retval = retval; \
84 vam->result_ready = 1; \
87 foreach_standard_reply_retval_handler;
91 * Table of message reply handlers, must include boilerplate handlers
94 #define foreach_vpe_api_reply_msg \
95 _(VXLAN_GPE_IOAM_ENABLE_REPLY, vxlan_gpe_ioam_enable_reply) \
96 _(VXLAN_GPE_IOAM_DISABLE_REPLY, vxlan_gpe_ioam_disable_reply) \
97 _(VXLAN_GPE_IOAM_VNI_ENABLE_REPLY, vxlan_gpe_ioam_vni_enable_reply) \
98 _(VXLAN_GPE_IOAM_VNI_DISABLE_REPLY, vxlan_gpe_ioam_vni_disable_reply) \
99 _(VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY, vxlan_gpe_ioam_transit_enable_reply) \
100 _(VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY, vxlan_gpe_ioam_transit_disable_reply) \
103 api_vxlan_gpe_ioam_enable (vat_main_t * vam)
105 unformat_input_t *input = vam->input;
106 vl_api_vxlan_gpe_ioam_enable_t *mp;
109 int has_trace_option = 0;
110 int has_pow_option = 0;
111 int has_ppc_option = 0;
113 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
115 if (unformat (input, "trace"))
116 has_trace_option = 1;
117 else if (unformat (input, "pow"))
119 else if (unformat (input, "ppc encap"))
120 has_ppc_option = PPC_ENCAP;
121 else if (unformat (input, "ppc decap"))
122 has_ppc_option = PPC_DECAP;
123 else if (unformat (input, "ppc none"))
124 has_ppc_option = PPC_NONE;
128 M (VXLAN_GPE_IOAM_ENABLE, vxlan_gpe_ioam_enable);
130 mp->trace_ppc = has_ppc_option;
131 mp->pow_enable = has_pow_option;
132 mp->trace_enable = has_trace_option;
143 api_vxlan_gpe_ioam_disable (vat_main_t * vam)
145 vl_api_vxlan_gpe_ioam_disable_t *mp;
148 M (VXLAN_GPE_IOAM_DISABLE, vxlan_gpe_ioam_disable);
155 api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
157 unformat_input_t *line_input = vam->input;
158 vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
159 ip4_address_t local4, remote4;
160 ip6_address_t local6, remote6;
161 u8 ipv4_set = 0, ipv6_set = 0;
169 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
171 if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
176 else if (unformat (line_input, "remote %U",
177 unformat_ip4_address, &remote4))
182 else if (unformat (line_input, "local %U",
183 unformat_ip6_address, &local6))
188 else if (unformat (line_input, "remote %U",
189 unformat_ip6_address, &remote6))
195 else if (unformat (line_input, "vni %d", &vni))
199 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
206 errmsg ("tunnel local address not specified\n");
211 errmsg ("tunnel remote address not specified\n");
214 if (ipv4_set && ipv6_set)
216 errmsg ("both IPv4 and IPv6 addresses specified");
222 errmsg ("vni not specified\n");
226 M (VXLAN_GPE_IOAM_VNI_ENABLE, vxlan_gpe_ioam_vni_enable);
231 clib_memcpy (&mp->local, &local6, sizeof (local6));
232 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
236 clib_memcpy (&mp->local, &local4, sizeof (local4));
237 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
240 mp->vni = ntohl (vni);
241 mp->is_ipv6 = ipv6_set;
250 api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
252 unformat_input_t *line_input = vam->input;
253 vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
254 ip4_address_t local4, remote4;
255 ip6_address_t local6, remote6;
256 u8 ipv4_set = 0, ipv6_set = 0;
264 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
266 if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
271 else if (unformat (line_input, "remote %U",
272 unformat_ip4_address, &remote4))
277 else if (unformat (line_input, "local %U",
278 unformat_ip6_address, &local6))
283 else if (unformat (line_input, "remote %U",
284 unformat_ip6_address, &remote6))
290 else if (unformat (line_input, "vni %d", &vni))
294 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
301 errmsg ("tunnel local address not specified\n");
306 errmsg ("tunnel remote address not specified\n");
309 if (ipv4_set && ipv6_set)
311 errmsg ("both IPv4 and IPv6 addresses specified");
317 errmsg ("vni not specified\n");
321 M (VXLAN_GPE_IOAM_VNI_DISABLE, vxlan_gpe_ioam_vni_disable);
326 clib_memcpy (&mp->local, &local6, sizeof (local6));
327 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
331 clib_memcpy (&mp->local, &local4, sizeof (local4));
332 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
335 mp->vni = ntohl (vni);
336 mp->is_ipv6 = ipv6_set;
345 api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
347 unformat_input_t *line_input = vam->input;
348 vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
349 ip4_address_t local4;
350 ip6_address_t local6;
351 u8 ipv4_set = 0, ipv6_set = 0;
353 u32 outer_fib_index = 0;
357 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
359 if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
364 else if (unformat (line_input, "dst-ip %U",
365 unformat_ip6_address, &local6))
371 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
375 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
382 errmsg ("destination address not specified\n");
385 if (ipv4_set && ipv6_set)
387 errmsg ("both IPv4 and IPv6 addresses specified");
392 M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, vxlan_gpe_ioam_transit_enable);
397 errmsg ("IPv6 currently unsupported");
402 clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
405 mp->outer_fib_index = htonl (outer_fib_index);
406 mp->is_ipv6 = ipv6_set;
415 api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
417 unformat_input_t *line_input = vam->input;
418 vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
419 ip4_address_t local4;
420 ip6_address_t local6;
421 u8 ipv4_set = 0, ipv6_set = 0;
423 u32 outer_fib_index = 0;
427 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
429 if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
434 else if (unformat (line_input, "dst-ip %U",
435 unformat_ip6_address, &local6))
441 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
445 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
452 errmsg ("destination address not specified\n");
455 if (ipv4_set && ipv6_set)
457 errmsg ("both IPv4 and IPv6 addresses specified");
462 M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, vxlan_gpe_ioam_transit_disable);
471 clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
474 mp->outer_fib_index = htonl (outer_fib_index);
475 mp->is_ipv6 = ipv6_set;
485 * List of messages that the api test plugin sends,
486 * and that the data plane plugin processes
488 #define foreach_vpe_api_msg \
489 _(vxlan_gpe_ioam_enable, ""\
490 "[trace] [pow] [ppc <encap|ppc decap>]") \
491 _(vxlan_gpe_ioam_disable, "") \
492 _(vxlan_gpe_ioam_vni_enable, ""\
493 "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
494 _(vxlan_gpe_ioam_vni_disable, ""\
495 "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
496 _(vxlan_gpe_ioam_transit_enable, ""\
497 "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
498 _(vxlan_gpe_ioam_transit_disable, ""\
499 "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
503 vxlan_gpe_vat_api_hookup (vat_main_t * vam)
505 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
506 /* Hook up handlers for replies from the data plane plug-in */
508 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
510 vl_api_##n##_t_handler, \
512 vl_api_##n##_t_endian, \
513 vl_api_##n##_t_print, \
514 sizeof(vl_api_##n##_t), 1);
515 foreach_vpe_api_reply_msg;
518 /* API messages we can send */
519 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
524 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
530 vat_plugin_register (vat_main_t * vam)
532 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
537 name = format (0, "ioam_vxlan_gpe_%08x%c", api_version, 0);
538 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
540 if (sm->msg_id_base != (u16) ~ 0)
541 vxlan_gpe_vat_api_hookup (vam);
549 * fd.io coding-style-patch-verification: ON
552 * eval: (c-set-style "gnu")