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 * trace_api.c - iOAM Trace related APIs to create
18 * and maintain profiles
19 *------------------------------------------------------------------
22 #include <vnet/vnet.h>
23 #include <vnet/plugin/plugin.h>
24 #include <ioam/lib-trace/trace_util.h>
25 #include <ioam/lib-trace/trace_config.h>
26 #include <vlibapi/api_helper_macros.h>
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
31 /* define message IDs */
32 #include <ioam/lib-trace/trace_msg_enum.h>
34 /* define message structures */
36 #include <ioam/lib-trace/trace_all_api_h.h>
39 /* define generated endian-swappers */
41 #include <ioam/lib-trace/trace_all_api_h.h>
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
47 #include <ioam/lib-trace/trace_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-trace/trace_all_api_h.h>
55 /* List of message types that this plugin understands */
57 #define foreach_trace_plugin_api_msg \
58 _(TRACE_PROFILE_ADD, trace_profile_add) \
59 _(TRACE_PROFILE_DEL, trace_profile_del) \
60 _(TRACE_PROFILE_SHOW_CONFIG, trace_profile_show_config)
62 static void vl_api_trace_profile_add_t_handler
63 (vl_api_trace_profile_add_t * mp)
66 vl_api_trace_profile_add_reply_t *rmp;
67 trace_profile *profile = NULL;
69 profile = trace_profile_find ();
73 trace_profile_create (profile, mp->trace_type, mp->num_elts,
74 mp->trace_tsp, ntohl (mp->node_id),
75 ntohl (mp->app_data));
84 REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
88 static void vl_api_trace_profile_del_t_handler
89 (vl_api_trace_profile_del_t * mp)
92 vl_api_trace_profile_del_reply_t *rmp;
94 clear_trace_profiles ();
96 REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
99 static void vl_api_trace_profile_show_config_t_handler
100 (vl_api_trace_profile_show_config_t * mp)
102 vl_api_trace_profile_show_config_reply_t *rmp;
104 trace_profile *profile = trace_profile_find ();
107 REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
108 rmp->trace_type = profile->trace_type;
109 rmp->num_elts = profile->num_elts;
110 rmp->trace_tsp = profile->trace_tsp;
111 rmp->node_id = htonl (profile->node_id);
112 rmp->app_data = htonl (profile->app_data);
117 REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
119 rmp->num_elts = 0; rmp->trace_tsp = 0;
120 rmp->node_id = 0; rmp->app_data = 0;
125 /* Set up the API message handling tables */
126 static clib_error_t *
127 trace_plugin_api_hookup (vlib_main_t * vm)
129 trace_main_t *sm = &trace_main;
131 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
133 vl_api_##n##_t_handler, \
135 vl_api_##n##_t_endian, \
136 vl_api_##n##_t_print, \
137 sizeof(vl_api_##n##_t), 1);
138 foreach_trace_plugin_api_msg;
144 #define vl_msg_name_crc_list
145 #include <ioam/lib-trace/trace_all_api_h.h>
146 #undef vl_msg_name_crc_list
149 setup_message_id_table (trace_main_t * sm, api_main_t * am)
151 #define _(id,n,crc) \
152 vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
153 foreach_vl_msg_name_crc_trace;
157 static clib_error_t *
158 trace_init (vlib_main_t * vm)
160 trace_main_t *sm = &trace_main;
161 clib_error_t *error = 0;
164 bzero (sm, sizeof (trace_main));
165 (void) trace_util_init ();
168 sm->vnet_main = vnet_get_main ();
170 name = format (0, "ioam_trace_%08x%c", api_version, 0);
172 /* Ask for a correctly-sized block of API message decode slots */
173 sm->msg_id_base = vl_msg_api_get_msg_ids
174 ((char *) name, VL_MSG_FIRST_AVAILABLE);
176 error = trace_plugin_api_hookup (vm);
178 /* Add our API messages to the global name_crc hash table */
179 setup_message_id_table (sm, &api_main);
186 VLIB_INIT_FUNCTION (trace_init);
189 * fd.io coding-style-patch-verification: ON
192 * eval: (c-set-style "gnu")