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 /* Declare message IDs */
28 #include <ioam/lib-vxlan-gpe/vxlan_gpe_msg_enum.h>
30 /* define message structures */
32 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
35 /* declare message handlers for each api */
37 #define vl_endianfun /* define message structures */
38 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
41 /* instantiate all the print functions we know about */
42 #define vl_print(handle, ...)
44 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
47 /* Get the API version number. */
48 #define vl_api_version(n,v) static u32 api_version=(v);
49 #include <ioam/lib-vxlan-gpe/vxlan_gpe_all_api_h.h>
51 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
52 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
56 /* API message ID base */
59 } vxlan_gpe_test_main_t;
61 vxlan_gpe_test_main_t vxlan_gpe_test_main;
63 #define foreach_standard_reply_retval_handler \
64 _(vxlan_gpe_ioam_enable_reply) \
65 _(vxlan_gpe_ioam_disable_reply) \
66 _(vxlan_gpe_ioam_vni_enable_reply) \
67 _(vxlan_gpe_ioam_vni_disable_reply) \
68 _(vxlan_gpe_ioam_transit_enable_reply) \
69 _(vxlan_gpe_ioam_transit_disable_reply)
72 static void vl_api_##n##_t_handler \
73 (vl_api_##n##_t * mp) \
75 vat_main_t * vam = vxlan_gpe_test_main.vat_main; \
76 i32 retval = ntohl(mp->retval); \
77 if (vam->async_mode) { \
78 vam->async_errors += (retval < 0); \
80 vam->retval = retval; \
81 vam->result_ready = 1; \
84 foreach_standard_reply_retval_handler;
88 * Table of message reply handlers, must include boilerplate handlers
91 #define foreach_vpe_api_reply_msg \
92 _(VXLAN_GPE_IOAM_ENABLE_REPLY, vxlan_gpe_ioam_enable_reply) \
93 _(VXLAN_GPE_IOAM_DISABLE_REPLY, vxlan_gpe_ioam_disable_reply) \
94 _(VXLAN_GPE_IOAM_VNI_ENABLE_REPLY, vxlan_gpe_ioam_vni_enable_reply) \
95 _(VXLAN_GPE_IOAM_VNI_DISABLE_REPLY, vxlan_gpe_ioam_vni_disable_reply) \
96 _(VXLAN_GPE_IOAM_TRANSIT_ENABLE_REPLY, vxlan_gpe_ioam_transit_enable_reply) \
97 _(VXLAN_GPE_IOAM_TRANSIT_DISABLE_REPLY, vxlan_gpe_ioam_transit_disable_reply) \
100 /* M: construct, but don't yet send a message */
104 vam->result_ready = 0; \
105 mp = vl_msg_api_alloc(sizeof(*mp)); \
106 memset (mp, 0, sizeof (*mp)); \
107 mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
108 mp->client_index = vam->my_client_index; \
113 vam->result_ready = 0; \
114 mp = vl_msg_api_alloc(sizeof(*mp)+(n)); \
115 memset (mp, 0, sizeof (*mp)); \
116 mp->_vl_msg_id = ntohs (VL_API_##T + sm->msg_id_base); \
117 mp->client_index = vam->my_client_index; \
120 /* S: send a message */
121 #define S (vl_msg_api_send_shmem (vam->vl_input_queue, (u8 *)&mp))
123 /* W: wait for results, with timeout */
126 timeout = vat_time_now (vam) + 1.0; \
128 while (vat_time_now (vam) < timeout) { \
129 if (vam->result_ready == 1) { \
130 return (vam->retval); \
138 api_vxlan_gpe_ioam_enable (vat_main_t * vam)
140 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
142 unformat_input_t *input = vam->input;
143 vl_api_vxlan_gpe_ioam_enable_t *mp;
146 int has_trace_option = 0;
147 int has_pow_option = 0;
148 int has_ppc_option = 0;
150 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
152 if (unformat (input, "trace"))
153 has_trace_option = 1;
154 else if (unformat (input, "pow"))
156 else if (unformat (input, "ppc encap"))
157 has_ppc_option = PPC_ENCAP;
158 else if (unformat (input, "ppc decap"))
159 has_ppc_option = PPC_DECAP;
160 else if (unformat (input, "ppc none"))
161 has_ppc_option = PPC_NONE;
165 M (VXLAN_GPE_IOAM_ENABLE, vxlan_gpe_ioam_enable);
167 mp->trace_ppc = has_ppc_option;
168 mp->pow_enable = has_pow_option;
169 mp->trace_enable = has_trace_option;
180 api_vxlan_gpe_ioam_disable (vat_main_t * vam)
182 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
183 vl_api_vxlan_gpe_ioam_disable_t *mp;
186 M (VXLAN_GPE_IOAM_DISABLE, vxlan_gpe_ioam_disable);
193 api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
195 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
197 unformat_input_t *line_input = vam->input;
198 vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
199 ip4_address_t local4, remote4;
200 ip6_address_t local6, remote6;
201 u8 ipv4_set = 0, ipv6_set = 0;
209 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
211 if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
216 else if (unformat (line_input, "remote %U",
217 unformat_ip4_address, &remote4))
222 else if (unformat (line_input, "local %U",
223 unformat_ip6_address, &local6))
228 else if (unformat (line_input, "remote %U",
229 unformat_ip6_address, &remote6))
235 else if (unformat (line_input, "vni %d", &vni))
239 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
246 errmsg ("tunnel local address not specified\n");
251 errmsg ("tunnel remote address not specified\n");
254 if (ipv4_set && ipv6_set)
256 errmsg ("both IPv4 and IPv6 addresses specified");
262 errmsg ("vni not specified\n");
266 M (VXLAN_GPE_IOAM_VNI_ENABLE, vxlan_gpe_ioam_vni_enable);
271 clib_memcpy (&mp->local, &local6, sizeof (local6));
272 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
276 clib_memcpy (&mp->local, &local4, sizeof (local4));
277 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
280 mp->vni = ntohl (vni);
281 mp->is_ipv6 = ipv6_set;
290 api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
292 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
294 unformat_input_t *line_input = vam->input;
295 vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
296 ip4_address_t local4, remote4;
297 ip6_address_t local6, remote6;
298 u8 ipv4_set = 0, ipv6_set = 0;
306 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
308 if (unformat (line_input, "local %U", unformat_ip4_address, &local4))
313 else if (unformat (line_input, "remote %U",
314 unformat_ip4_address, &remote4))
319 else if (unformat (line_input, "local %U",
320 unformat_ip6_address, &local6))
325 else if (unformat (line_input, "remote %U",
326 unformat_ip6_address, &remote6))
332 else if (unformat (line_input, "vni %d", &vni))
336 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
343 errmsg ("tunnel local address not specified\n");
348 errmsg ("tunnel remote address not specified\n");
351 if (ipv4_set && ipv6_set)
353 errmsg ("both IPv4 and IPv6 addresses specified");
359 errmsg ("vni not specified\n");
363 M (VXLAN_GPE_IOAM_VNI_DISABLE, vxlan_gpe_ioam_vni_disable);
368 clib_memcpy (&mp->local, &local6, sizeof (local6));
369 clib_memcpy (&mp->remote, &remote6, sizeof (remote6));
373 clib_memcpy (&mp->local, &local4, sizeof (local4));
374 clib_memcpy (&mp->remote, &remote4, sizeof (remote4));
377 mp->vni = ntohl (vni);
378 mp->is_ipv6 = ipv6_set;
387 api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
389 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
391 unformat_input_t *line_input = vam->input;
392 vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
393 ip4_address_t local4;
394 ip6_address_t local6;
395 u8 ipv4_set = 0, ipv6_set = 0;
397 u32 outer_fib_index = 0;
401 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
403 if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
408 else if (unformat (line_input, "dst-ip %U",
409 unformat_ip6_address, &local6))
415 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
419 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
426 errmsg ("destination address not specified\n");
429 if (ipv4_set && ipv6_set)
431 errmsg ("both IPv4 and IPv6 addresses specified");
436 M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, vxlan_gpe_ioam_transit_enable);
441 errmsg ("IPv6 currently unsupported");
446 clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
449 mp->outer_fib_index = htonl (outer_fib_index);
450 mp->is_ipv6 = ipv6_set;
459 api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
461 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
463 unformat_input_t *line_input = vam->input;
464 vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
465 ip4_address_t local4;
466 ip6_address_t local6;
467 u8 ipv4_set = 0, ipv6_set = 0;
473 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
475 if (unformat (line_input, "dst-ip %U", unformat_ip4_address, &local4))
480 else if (unformat (line_input, "dst-ip %U",
481 unformat_ip6_address, &local6))
487 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
491 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
498 errmsg ("destination address not specified\n");
501 if (ipv4_set && ipv6_set)
503 errmsg ("both IPv4 and IPv6 addresses specified");
508 M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, vxlan_gpe_ioam_transit_disable);
517 clib_memcpy (&mp->dst_addr, &local4, sizeof (local4));
520 mp->outer_fib_index = htonl (outer_fib_index);
521 mp->is_ipv6 = ipv6_set;
531 * List of messages that the api test plugin sends,
532 * and that the data plane plugin processes
534 #define foreach_vpe_api_msg \
535 _(vxlan_gpe_ioam_enable, ""\
536 "[trace] [pow] [ppc <encap|ppc decap>]") \
537 _(vxlan_gpe_ioam_disable, "") \
538 _(vxlan_gpe_ioam_vni_enable, ""\
539 "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
540 _(vxlan_gpe_ioam_vni_disable, ""\
541 "local <local_vtep_ip> remote <remote_vtep_ip> vni <vnid>") \
542 _(vxlan_gpe_ioam_transit_enable, ""\
543 "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
544 _(vxlan_gpe_ioam_transit_disable, ""\
545 "dst-ip <dst_ip> [outer-fib-index <outer_fib_index>]") \
549 vat_api_hookup (vat_main_t * vam)
551 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
552 /* Hook up handlers for replies from the data plane plug-in */
554 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
556 vl_api_##n##_t_handler, \
558 vl_api_##n##_t_endian, \
559 vl_api_##n##_t_print, \
560 sizeof(vl_api_##n##_t), 1);
561 foreach_vpe_api_reply_msg;
564 /* API messages we can send */
565 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
570 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
576 vat_plugin_register (vat_main_t * vam)
578 vxlan_gpe_test_main_t *sm = &vxlan_gpe_test_main;
583 name = format (0, "ioam_vxlan_gpe_%08x%c", api_version, 0);
584 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
586 if (sm->msg_id_base != (u16) ~ 0)
587 vat_api_hookup (vam);
595 * fd.io coding-style-patch-verification: ON
598 * eval: (c-set-style "gnu")