2 * tracedump.c - tracedump vpp-api-test plug-in
4 * Copyright (c) <current-year> <your-organization>
5 * Licensed under the Apache License, Version 2.0 (the "License");
6 * you may not use this file except in compliance with the License.
7 * You may obtain a copy of the License at:
9 * http://www.apache.org/licenses/LICENSE-2.0
11 * Unless required by applicable law or agreed to in writing, software
12 * distributed under the License is distributed on an "AS IS" BASIS,
13 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 * See the License for the specific language governing permissions and
15 * limitations under the License.
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 #include <vppinfra/error.h>
21 #include <vnet/api_errno.h>
24 #define __plugin_msg_base tracedump_test_main.msg_id_base
25 #include <vlibapi/vat_helper_macros.h>
27 /* Declare message IDs */
28 #include <tracedump/tracedump.api_enum.h>
29 #include <tracedump/tracedump.api_types.h>
33 /* API message ID base */
36 } tracedump_test_main_t;
38 tracedump_test_main_t tracedump_test_main;
42 api_trace_set_filters (vat_main_t * vam)
44 unformat_input_t *i = vam->input;
45 vl_api_trace_set_filters_t *mp;
56 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
58 if (unformat (i, "none"))
60 else if (unformat (i, "include_node %u", &node_index))
61 flag = TRACE_FF_INCLUDE_NODE;
62 else if (unformat (i, "exclude_node %u", &node_index))
63 flag = TRACE_FF_EXCLUDE_NODE;
64 else if (unformat (i, "include_classifier %u", &classifier))
65 flag = TRACE_FF_INCLUDE_CLASSIFIER;
66 else if (unformat (i, "exclude_classifier %u", &classifier))
67 flag = TRACE_FF_EXCLUDE_CLASSIFIER;
68 else if (unformat (i, "count %u", &count))
72 clib_warning ("Unknown input: %U\n", format_unformat_error, i);
77 M (TRACE_SET_FILTERS, mp);
78 mp->flag = htonl (flag);
79 mp->node_index = htonl (node_index);
80 mp->count = htonl (count);
81 mp->classifier_table_index = htonl (classifier);
92 api_trace_capture_packets (vat_main_t * vam)
94 unformat_input_t *i = vam->input;
95 vl_api_trace_capture_packets_t *mp;
98 bool pre_capture_clear;
104 pre_capture_clear = use_filter = verbose = false;
106 while (unformat_check_input (i) != UNFORMAT_END_OF_INPUT)
108 if (unformat (i, "node_index %u", &node_index))
110 else if (unformat (i, "max %u", &max))
112 else if (unformat (i, "pre_capture_clear"))
113 pre_capture_clear = false;
114 else if (unformat (i, "use_filter"))
116 else if (unformat (i, "verbose"))
120 clib_warning ("Unknown input: %U\n", format_unformat_error, i);
125 M (TRACE_CAPTURE_PACKETS, mp);
126 mp->node_index = htonl (node_index);
127 mp->max_packets = htonl (max);
128 mp->use_filter = use_filter;
129 mp->verbose = verbose;
130 mp->pre_capture_clear = pre_capture_clear;
141 vl_api_trace_details_t_handler (vl_api_trace_details_t * dmp)
144 u32 thread_id, position;
146 thread_id = clib_net_to_host_u32 (dmp->thread_id);
147 position = clib_net_to_host_u32 (dmp->position);
148 packet_number = clib_net_to_host_u32 (dmp->packet_number);
151 "thread %d position %d more_this_thread %d more_threads %d done %d\n",
152 thread_id, position, (u32) dmp->more_this_thread,
153 (u32) dmp->more_threads, (u32) dmp->done);
154 fformat (stdout, "Packet %d\n%U\n\n",
155 packet_number, vl_api_format_string, (&dmp->trace_data));
159 vl_api_trace_v2_details_t_handler (vl_api_trace_v2_details_t *dmp)
161 u32 thread_id, position;
163 thread_id = clib_net_to_host_u32 (dmp->thread_id);
164 position = clib_net_to_host_u32 (dmp->position);
165 fformat (stdout, "thread %d position %d more %d", thread_id, position,
167 fformat (stdout, "Packet %d\n%U\n\n", position, vl_api_format_string,
172 vl_api_trace_dump_reply_t_handler (vl_api_trace_dump_reply_t * rmp)
174 tracedump_test_main_t *ttm = &tracedump_test_main;
175 vat_main_t *vam = ttm->vat_main;
176 vl_api_trace_dump_t *mp;
177 i32 retval = (i32) clib_net_to_host_u32 (rmp->retval);
178 u32 thread_id, position;
180 if (retval != 0 || rmp->done)
182 vam->result_ready = 1;
183 vam->retval = retval;
185 /* Clear the cache */
186 if (retval == 0 && rmp->flush_only == 0)
190 mp->thread_id = 0xFFFFFFFF;
191 mp->position = 0xFFFFFFFF;
197 /* Figure out where the next batch starts */
198 thread_id = clib_host_to_net_u32 (rmp->last_thread_id);
199 position = clib_host_to_net_u32 (rmp->last_position);
201 if (rmp->more_threads)
211 mp->thread_id = clib_host_to_net_u32 (thread_id);
212 mp->position = clib_host_to_net_u32 (position);
213 mp->max_records = clib_host_to_net_u32 (10);
218 api_trace_dump (vat_main_t *vam)
220 vl_api_trace_dump_t *mp;
227 mp->max_records = clib_host_to_net_u32 (10);
236 api_trace_v2_dump (vat_main_t *vam)
238 vl_api_trace_v2_dump_t *mp;
241 M (TRACE_V2_DUMP, mp);
245 mp->max = clib_host_to_net_u32 (10);
254 api_trace_clear_capture (vat_main_t *vam)
256 vl_api_trace_clear_capture_t *mp;
259 M (TRACE_CLEAR_CAPTURE, mp);
266 api_trace_clear_cache (vat_main_t *vam)
268 vl_api_trace_clear_capture_t *mp;
271 M (TRACE_CLEAR_CACHE, mp);
278 api_trace_set_filter_function (vat_main_t *vam)
280 vl_api_trace_set_filter_function_t *mp;
283 M (TRACE_SET_FILTER_FUNCTION, mp);
290 api_trace_filter_function_dump (vat_main_t *vam)
292 vl_api_trace_filter_function_dump_t *mp;
295 M (TRACE_FILTER_FUNCTION_DUMP, mp);
302 vl_api_trace_filter_function_details_t_handler (
303 vl_api_trace_filter_function_details_t *dmp)
305 fformat (stdout, "name: %U, selected: %u\n\n", vl_api_format_string,
306 &dmp->name, dmp->selected);
310 #include <tracedump/tracedump.api.h>
313 #include <tracedump/tracedump.api.h>
315 #define vl_calcsizefun
316 #include <tracedump/tracedump.api.h>
317 #undef vl_calcsizefun
320 manual_setup_message_id_table (vat_main_t * vam)
322 vl_msg_api_config (&(vl_msg_api_msg_config_t){
323 .id = VL_API_TRACE_DETAILS + tracedump_test_main.msg_id_base,
324 .name = "trace_details",
325 .handler = vl_api_trace_details_t_handler,
326 .endian = vl_api_trace_details_t_endian,
327 .format_fn = vl_api_trace_details_t_format,
328 .size = sizeof (vl_api_trace_details_t),
330 .tojson = vl_api_trace_details_t_tojson,
331 .fromjson = vl_api_trace_details_t_fromjson,
332 .calc_size = vl_api_trace_details_t_calc_size,
336 #define VL_API_LOCAL_SETUP_MESSAGE_ID_TABLE manual_setup_message_id_table
337 #define VL_API_TRACE_DUMP_REPLY_T_HANDLER
339 #include <tracedump/tracedump.api_test.c>
342 * fd.io coding-style-patch-verification: ON
345 * eval: (c-set-style "gnu")