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));
160 vl_api_trace_dump_reply_t_handler (vl_api_trace_dump_reply_t * rmp)
162 tracedump_test_main_t *ttm = &tracedump_test_main;
163 vat_main_t *vam = ttm->vat_main;
164 vl_api_trace_dump_t *mp;
165 i32 retval = (i32) clib_net_to_host_u32 (rmp->retval);
166 u32 thread_id, position;
168 if (retval != 0 || rmp->done)
170 vam->result_ready = 1;
171 vam->retval = retval;
173 /* Clear the cache */
174 if (retval == 0 && rmp->flush_only == 0)
178 mp->thread_id = 0xFFFFFFFF;
179 mp->position = 0xFFFFFFFF;
185 /* Figure out where the next batch starts */
186 thread_id = clib_host_to_net_u32 (rmp->last_thread_id);
187 position = clib_host_to_net_u32 (rmp->last_position);
189 if (rmp->more_threads)
199 mp->thread_id = clib_host_to_net_u32 (thread_id);
200 mp->position = clib_host_to_net_u32 (position);
201 mp->max_records = clib_host_to_net_u32 (10);
206 api_trace_dump (vat_main_t * vam)
208 vl_api_trace_dump_t *mp;
215 mp->max_records = clib_host_to_net_u32 (10);
224 api_trace_clear_capture (vat_main_t * vam)
226 vl_api_trace_clear_capture_t *mp;
229 M (TRACE_CLEAR_CAPTURE, mp);
238 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
240 #include <tracedump/tracedump.api.h>
243 #include <tracedump/tracedump.api.h>
247 manual_setup_message_id_table (vat_main_t * vam)
249 vl_msg_api_set_handlers (VL_API_TRACE_DETAILS
250 + tracedump_test_main.msg_id_base, "trace_details",
251 vl_api_trace_details_t_handler, vl_noop_handler,
252 vl_api_trace_details_t_endian,
253 vl_api_trace_details_t_print,
254 sizeof (vl_api_trace_details_t), 1);
257 #define VL_API_LOCAL_SETUP_MESSAGE_ID_TABLE manual_setup_message_id_table
258 #define VL_API_TRACE_DUMP_REPLY_T_HANDLER
260 #include <tracedump/tracedump.api_test.c>
263 * fd.io coding-style-patch-verification: ON
266 * eval: (c-set-style "gnu")