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>
26 #include <vnet/format_fns.h>
27 #include <vnet/ip/ip_types_api.h>
29 #define __plugin_msg_base ioam_vxlan_gpe_test_main.msg_id_base
30 #include <vlibapi/vat_helper_macros.h>
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>
36 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam_packet.h>
37 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
41 /* API message ID base */
44 } ioam_vxlan_gpe_test_main_t;
46 ioam_vxlan_gpe_test_main_t ioam_vxlan_gpe_test_main;
49 api_vxlan_gpe_ioam_enable (vat_main_t * vam)
51 unformat_input_t *input = vam->input;
52 vl_api_vxlan_gpe_ioam_enable_t *mp;
54 int has_trace_option = 0;
55 int has_pow_option = 0;
56 int has_ppc_option = 0;
59 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
61 if (unformat (input, "trace"))
63 else if (unformat (input, "pow"))
65 else if (unformat (input, "ppc encap"))
66 has_ppc_option = PPC_ENCAP;
67 else if (unformat (input, "ppc decap"))
68 has_ppc_option = PPC_DECAP;
69 else if (unformat (input, "ppc none"))
70 has_ppc_option = PPC_NONE;
74 M (VXLAN_GPE_IOAM_ENABLE, mp);
76 mp->trace_ppc = has_ppc_option;
77 mp->pow_enable = has_pow_option;
78 mp->trace_enable = has_trace_option;
88 api_vxlan_gpe_ioam_disable (vat_main_t * vam)
90 vl_api_vxlan_gpe_ioam_disable_t *mp;
93 M (VXLAN_GPE_IOAM_DISABLE, mp);
100 api_vxlan_gpe_ioam_vni_enable (vat_main_t * vam)
102 unformat_input_t *line_input = vam->input;
103 vl_api_vxlan_gpe_ioam_vni_enable_t *mp;
104 ip46_address_t local, remote;
112 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
114 if (unformat (line_input, "local %U", unformat_ip46_address, &local))
118 else if (unformat (line_input, "remote %U",
119 unformat_ip46_address, &remote))
123 else if (unformat (line_input, "vni %d", &vni))
127 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
134 errmsg ("tunnel local address not specified\n");
139 errmsg ("tunnel remote address not specified\n");
142 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
144 errmsg ("both IPv4 and IPv6 addresses specified");
150 errmsg ("vni not specified\n");
154 M (VXLAN_GPE_IOAM_VNI_ENABLE, mp);
156 ip_address_encode (&local,
157 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
158 IP46_TYPE_IP6, &mp->local);
159 ip_address_encode (&local,
160 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
161 IP46_TYPE_IP6, &mp->remote);
163 mp->vni = ntohl (vni);
171 api_vxlan_gpe_ioam_vni_disable (vat_main_t * vam)
173 unformat_input_t *line_input = vam->input;
174 vl_api_vxlan_gpe_ioam_vni_disable_t *mp;
175 ip46_address_t local, remote;
183 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
185 if (unformat (line_input, "local %U", unformat_ip46_address, &local))
189 else if (unformat (line_input, "remote %U",
190 unformat_ip46_address, &remote))
194 else if (unformat (line_input, "vni %d", &vni))
198 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
205 errmsg ("tunnel local address not specified\n");
210 errmsg ("tunnel remote address not specified\n");
213 if (ip46_address_is_ip4 (&local) != ip46_address_is_ip4 (&remote))
215 errmsg ("both IPv4 and IPv6 addresses specified");
221 errmsg ("vni not specified\n");
225 M (VXLAN_GPE_IOAM_VNI_DISABLE, mp);
227 ip_address_encode (&local,
228 ip46_address_is_ip4 (&local) ? IP46_TYPE_IP4 :
229 IP46_TYPE_IP6, &mp->local);
230 ip_address_encode (&local,
231 ip46_address_is_ip4 (&remote) ? IP46_TYPE_IP4 :
232 IP46_TYPE_IP6, &mp->remote);
234 mp->vni = ntohl (vni);
242 api_vxlan_gpe_ioam_transit_enable (vat_main_t * vam)
244 unformat_input_t *line_input = vam->input;
245 vl_api_vxlan_gpe_ioam_transit_enable_t *mp;
246 ip46_address_t local;
248 u32 outer_fib_index = 0;
252 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
254 if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
258 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
262 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
269 errmsg ("destination address not specified\n");
273 M (VXLAN_GPE_IOAM_TRANSIT_ENABLE, mp);
276 if (!ip46_address_is_ip4 (&local))
278 errmsg ("IPv6 currently unsupported");
281 ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
282 mp->outer_fib_index = htonl (outer_fib_index);
290 api_vxlan_gpe_ioam_transit_disable (vat_main_t * vam)
292 unformat_input_t *line_input = vam->input;
293 vl_api_vxlan_gpe_ioam_transit_disable_t *mp;
294 ip46_address_t local;
296 u32 outer_fib_index = 0;
300 while (unformat_check_input (line_input) != UNFORMAT_END_OF_INPUT)
302 if (unformat (line_input, "dst-ip %U", unformat_ip46_address, &local))
306 else if (unformat (line_input, "outer-fib-index %d", &outer_fib_index))
310 errmsg ("parse error '%U'\n", format_unformat_error, line_input);
317 errmsg ("destination address not specified\n");
321 M (VXLAN_GPE_IOAM_TRANSIT_DISABLE, mp);
324 if (!ip46_address_is_ip4 (&local))
328 ip_address_encode (&local, IP46_TYPE_IP4, &mp->dst_addr);
330 mp->outer_fib_index = htonl (outer_fib_index);
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>
342 * fd.io coding-style-patch-verification: ON
345 * eval: (c-set-style "gnu")