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_ioam_export.c - ioam export API / debug CLI handling
18 *------------------------------------------------------------------
21 #include <vnet/vnet.h>
22 #include <vnet/plugin/plugin.h>
23 #include <ioam/export-common/ioam_export.h>
24 #include <vnet/vxlan-gpe/vxlan_gpe.h>
26 #include <vlibapi/api.h>
27 #include <vlibmemory/api.h>
28 #include <vlibsocket/api.h>
30 #include <ioam/lib-vxlan-gpe/vxlan_gpe_ioam.h>
32 /* define message IDs */
33 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_msg_enum.h>
35 /* define message structures */
37 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
40 /* define generated endian-swappers */
42 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
45 /* instantiate all the print functions we know about */
46 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
48 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
51 /* Get the API version number */
52 #define vl_api_version(n,v) static u32 api_version=(v);
53 #include <ioam/export-vxlan-gpe/vxlan_gpe_ioam_export_all_api_h.h>
57 * A handy macro to set up a message reply.
58 * Assumes that the following variables are available:
59 * mp - pointer to request message
60 * rmp - pointer to reply message type
64 #define REPLY_MACRO(t) \
66 unix_shared_memory_queue_t * q = \
67 vl_api_client_index_to_input_queue (mp->client_index); \
71 rmp = vl_msg_api_alloc (sizeof (*rmp)); \
72 rmp->_vl_msg_id = ntohs((t)+sm->msg_id_base); \
73 rmp->context = mp->context; \
74 rmp->retval = ntohl(rv); \
76 vl_msg_api_send_shmem (q, (u8 *)&rmp); \
80 /* List of message types that this plugin understands */
83 #define foreach_vxlan_gpe_ioam_export_plugin_api_msg \
84 _(VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE, vxlan_gpe_ioam_export_enable_disable)
86 ioam_export_main_t vxlan_gpe_ioam_export_main;
88 extern void vxlan_gpe_set_next_override (uword next);
89 /* Action function shared between message handler and debug CLI */
91 vxlan_gpe_ioam_export_enable_disable (ioam_export_main_t * em,
93 ip4_address_t * collector_address,
94 ip4_address_t * src_address)
96 vlib_main_t *vm = em->vlib_main;
97 u32 node_index = vxlan_export_node.index;
98 vlib_node_t *vxlan_gpe_decap_ioam_node = NULL;
102 if (em->my_hbh_slot == ~0)
104 /* Hook this export node to vxlan-gpe-decap-ioam-v4 */
105 vxlan_gpe_decap_ioam_node =
106 vlib_get_node_by_name (vm, (u8 *) "vxlan-gpe-decap-ioam-v4");
107 if (!vxlan_gpe_decap_ioam_node)
109 /* node does not exist give up */
113 vlib_node_add_next (vm, vxlan_gpe_decap_ioam_node->index,
116 if (1 == ioam_export_header_create (em, collector_address, src_address))
118 ioam_export_thread_buffer_init (em, vm);
119 vxlan_gpe_set_next_override (em->my_hbh_slot);
120 /* Turn on the export buffer check process */
121 vlib_process_signal_event (vm, em->export_process_node_index, 1, 0);
131 vxlan_gpe_set_next_override (VXLAN_GPE_DECAP_IOAM_V4_NEXT_POP);
132 ioam_export_header_cleanup (em, collector_address, src_address);
133 ioam_export_thread_buffer_free (em);
134 /* Turn off the export buffer check process */
135 vlib_process_signal_event (vm, em->export_process_node_index, 2, 0);
142 /* API message handler */
143 static void vl_api_vxlan_gpe_ioam_export_enable_disable_t_handler
144 (vl_api_vxlan_gpe_ioam_export_enable_disable_t * mp)
146 vl_api_vxlan_gpe_ioam_export_enable_disable_reply_t *rmp;
147 ioam_export_main_t *sm = &vxlan_gpe_ioam_export_main;
150 rv = vxlan_gpe_ioam_export_enable_disable (sm, (int) (mp->is_disable),
152 mp->collector_address,
156 REPLY_MACRO (VL_API_VXLAN_GPE_IOAM_EXPORT_ENABLE_DISABLE_REPLY);
157 } /* API message handler */
161 /* Set up the API message handling tables */
162 static clib_error_t *
163 vxlan_gpe_ioam_export_plugin_api_hookup (vlib_main_t * vm)
165 ioam_export_main_t *sm = &vxlan_gpe_ioam_export_main;
167 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
169 vl_api_##n##_t_handler, \
171 vl_api_##n##_t_endian, \
172 vl_api_##n##_t_print, \
173 sizeof(vl_api_##n##_t), 1);
174 foreach_vxlan_gpe_ioam_export_plugin_api_msg;
181 static clib_error_t *
182 set_vxlan_gpe_ioam_export_ipfix_command_fn (vlib_main_t * vm,
183 unformat_input_t * input,
184 vlib_cli_command_t * cmd)
186 ioam_export_main_t *em = &vxlan_gpe_ioam_export_main;
187 ip4_address_t collector, src;
190 collector.as_u32 = 0;
193 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
195 if (unformat (input, "collector %U", unformat_ip4_address, &collector))
197 else if (unformat (input, "src %U", unformat_ip4_address, &src))
199 else if (unformat (input, "disable"))
205 if (collector.as_u32 == 0)
206 return clib_error_return (0, "collector address required");
209 return clib_error_return (0, "src address required");
211 em->ipfix_collector.as_u32 = collector.as_u32;
212 em->src_address.as_u32 = src.as_u32;
214 vlib_cli_output (vm, "Collector %U, src address %U",
215 format_ip4_address, &em->ipfix_collector,
216 format_ip4_address, &em->src_address);
218 /* Turn on the export timer process */
219 // vlib_process_signal_event (vm, flow_report_process_node.index,
222 vxlan_gpe_ioam_export_enable_disable (em, is_disable, &collector, &src))
224 return clib_error_return (0, "Unable to set ioam vxlan-gpe export");
231 VLIB_CLI_COMMAND (set_vxlan_gpe_ioam_ipfix_command, static) =
233 .path = "set vxlan-gpe-ioam export ipfix",
234 .short_help = "set vxlan-gpe-ioam export ipfix collector <ip4-address> src <ip4-address>",
235 .function = set_vxlan_gpe_ioam_export_ipfix_command_fn,
240 static clib_error_t *
241 vxlan_gpe_ioam_export_init (vlib_main_t * vm)
243 ioam_export_main_t *em = &vxlan_gpe_ioam_export_main;
244 clib_error_t *error = 0;
247 em->set_id = IPFIX_VXLAN_IOAM_EXPORT_ID;
249 name = format (0, "vxlan_gpe_ioam_export_%08x%c", api_version, 0);
251 /* Ask for a correctly-sized block of API message decode slots */
252 em->msg_id_base = vl_msg_api_get_msg_ids
253 ((char *) name, VL_MSG_FIRST_AVAILABLE);
254 em->unix_time_0 = (u32) time (0); /* Store starting time */
255 em->vlib_time_0 = vlib_time_now (vm);
257 error = vxlan_gpe_ioam_export_plugin_api_hookup (vm);
258 em->my_hbh_slot = ~0;
260 em->vnet_main = vnet_get_main ();
261 ioam_export_reset_next_node (em);
267 VLIB_INIT_FUNCTION (vxlan_gpe_ioam_export_init);
271 * fd.io coding-style-patch-verification: ON
274 * eval: (c-set-style "gnu")