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 * 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>
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27 #include <vnet/ip/ip6_hop_by_hop.h>
30 /* define message IDs */
31 #include <ioam/export/ioam_export_msg_enum.h>
33 /* define message structures */
35 #include <ioam/export/ioam_export_all_api_h.h>
38 /* define generated endian-swappers */
40 #include <ioam/export/ioam_export_all_api_h.h>
43 /* instantiate all the print functions we know about */
44 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #include <ioam/export/ioam_export_all_api_h.h>
49 /* Get the API version number */
50 #define vl_api_version(n,v) static u32 api_version=(v);
51 #include <ioam/export/ioam_export_all_api_h.h>
54 #define REPLY_MSG_ID_BASE sm->msg_id_base
55 #include <vlibapi/api_helper_macros.h>
57 /* List of message types that this plugin understands */
58 #define foreach_ioam_export_plugin_api_msg \
59 _(IOAM_EXPORT_IP6_ENABLE_DISABLE, ioam_export_ip6_enable_disable)
61 ioam_export_main_t ioam_export_main;
63 extern vlib_node_registration_t export_node;
65 /* Action function shared between message handler and debug CLI */
68 ioam_export_ip6_enable_disable (ioam_export_main_t * em,
70 ip4_address_t * collector_address,
71 ip4_address_t * src_address)
73 vlib_main_t *vm = em->vlib_main;
77 if (1 == ioam_export_header_create (em, collector_address, src_address))
79 ioam_export_thread_buffer_init (em, vm);
80 ip6_hbh_set_next_override (em->my_hbh_slot);
81 /* Turn on the export buffer check process */
82 vlib_process_signal_event (vm, em->export_process_node_index, 1, 0);
92 ip6_hbh_set_next_override (IP6_LOOKUP_NEXT_POP_HOP_BY_HOP);
93 ioam_export_header_cleanup (em, collector_address, src_address);
94 ioam_export_thread_buffer_free (em);
95 /* Turn off the export buffer check process */
96 vlib_process_signal_event (vm, em->export_process_node_index, 2, 0);
103 /* API message handler */
104 static void vl_api_ioam_export_ip6_enable_disable_t_handler
105 (vl_api_ioam_export_ip6_enable_disable_t * mp)
107 vl_api_ioam_export_ip6_enable_disable_reply_t *rmp;
108 ioam_export_main_t *sm = &ioam_export_main;
111 rv = ioam_export_ip6_enable_disable (sm, (int) (mp->is_disable),
113 mp->collector_address,
114 (ip4_address_t *) mp->src_address);
116 REPLY_MACRO (VL_API_IOAM_EXPORT_IP6_ENABLE_DISABLE_REPLY);
119 /* Set up the API message handling tables */
120 static clib_error_t *
121 ioam_export_plugin_api_hookup (vlib_main_t * vm)
123 ioam_export_main_t *sm = &ioam_export_main;
125 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
127 vl_api_##n##_t_handler, \
129 vl_api_##n##_t_endian, \
130 vl_api_##n##_t_print, \
131 sizeof(vl_api_##n##_t), 1);
132 foreach_ioam_export_plugin_api_msg;
138 #define vl_msg_name_crc_list
139 #include <ioam/export/ioam_export_all_api_h.h>
140 #undef vl_msg_name_crc_list
143 setup_message_id_table (ioam_export_main_t * sm, api_main_t * am)
145 #define _(id,n,crc) \
146 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
147 foreach_vl_msg_name_crc_ioam_export;
151 static clib_error_t *
152 set_ioam_export_ipfix_command_fn (vlib_main_t * vm,
153 unformat_input_t * input,
154 vlib_cli_command_t * cmd)
156 ioam_export_main_t *em = &ioam_export_main;
157 ip4_address_t collector, src;
160 collector.as_u32 = 0;
163 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
165 if (unformat (input, "collector %U", unformat_ip4_address, &collector))
167 else if (unformat (input, "src %U", unformat_ip4_address, &src))
169 else if (unformat (input, "disable"))
175 if (collector.as_u32 == 0)
176 return clib_error_return (0, "collector address required");
179 return clib_error_return (0, "src address required");
181 em->ipfix_collector.as_u32 = collector.as_u32;
182 em->src_address.as_u32 = src.as_u32;
184 vlib_cli_output (vm, "Collector %U, src address %U",
185 format_ip4_address, &em->ipfix_collector,
186 format_ip4_address, &em->src_address);
188 /* Turn on the export timer process */
189 // vlib_process_signal_event (vm, flow_report_process_node.index,
191 ioam_export_ip6_enable_disable (em, is_disable, &collector, &src);
197 VLIB_CLI_COMMAND (set_ipfix_command, static) =
199 .path = "set ioam export ipfix",.short_help =
200 "set ioam export ipfix collector <ip4-address> src <ip4-address>",.
201 function = set_ioam_export_ipfix_command_fn,};
205 static clib_error_t *
206 ioam_export_init (vlib_main_t * vm)
208 ioam_export_main_t *em = &ioam_export_main;
209 clib_error_t *error = 0;
211 u32 node_index = export_node.index;
212 vlib_node_t *ip6_hbyh_node = NULL;
215 em->vnet_main = vnet_get_main ();
216 em->set_id = IPFIX_IOAM_EXPORT_ID;
217 ioam_export_reset_next_node (em);
219 name = format (0, "ioam_export_%08x%c", api_version, 0);
221 /* Ask for a correctly-sized block of API message decode slots */
222 em->msg_id_base = vl_msg_api_get_msg_ids
223 ((char *) name, VL_MSG_FIRST_AVAILABLE);
224 em->unix_time_0 = (u32) time (0); /* Store starting time */
225 em->vlib_time_0 = vlib_time_now (vm);
227 error = ioam_export_plugin_api_hookup (vm);
229 /* Add our API messages to the global name_crc hash table */
230 setup_message_id_table (em, &api_main);
232 /* Hook this export node to ip6-hop-by-hop */
233 ip6_hbyh_node = vlib_get_node_by_name (vm, (u8 *) "ip6-hop-by-hop");
234 em->my_hbh_slot = vlib_node_add_next (vm, ip6_hbyh_node->index, node_index);
240 VLIB_INIT_FUNCTION (ioam_export_init);
243 * fd.io coding-style-patch-verification: ON
246 * eval: (c-set-style "gnu")