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_test.c - test harness for trace plugin
18 *------------------------------------------------------------------
22 #include <vlibapi/api.h>
23 #include <vlibmemory/api.h>
25 #include <vppinfra/error.h>
27 #define __plugin_msg_base trace_test_main.msg_id_base
28 #include <vlibapi/vat_helper_macros.h>
30 /* Declare message IDs */
31 #include <ioam/lib-trace/trace.api_enum.h>
32 #include <ioam/lib-trace/trace.api_types.h>
34 #define vl_endianfun /* define message structures */
36 #define vl_api_version(n,v) static u32 api_version=(v);
37 #define vl_print(handle, ...)
38 #include <ioam/lib-trace/trace.api.h>
45 /* API message ID base */
50 trace_test_main_t trace_test_main;
52 #define foreach_standard_reply_retval_handler \
53 _(trace_profile_add_reply) \
54 _(trace_profile_del_reply)
56 #define foreach_custom_reply_handler \
57 _(trace_profile_show_config_reply, \
60 errmsg(" Trace Type : 0x%x (%d)\n",mp->trace_type, mp->trace_type); \
61 errmsg(" Trace timestamp precision : %d \n",mp->trace_tsp); \
62 errmsg(" Node Id : 0x%x (%d)\n",htonl(mp->node_id), htonl(mp->node_id)); \
63 errmsg(" App Data : 0x%x (%d)\n",htonl(mp->app_data), htonl(mp->app_data)); \
65 else errmsg("No valid trace profile configuration found\n");)
67 static void vl_api_##n##_t_handler \
68 (vl_api_##n##_t * mp) \
70 vat_main_t * vam = trace_test_main.vat_main; \
71 i32 retval = ntohl(mp->retval); \
72 if (vam->async_mode) { \
73 vam->async_errors += (retval < 0); \
75 vam->retval = retval; \
76 vam->result_ready = 1; \
79 foreach_standard_reply_retval_handler;
83 static void vl_api_##n##_t_handler \
84 (vl_api_##n##_t * mp) \
86 vat_main_t * vam = trace_test_main.vat_main; \
87 i32 retval = ntohl(mp->retval); \
88 if (vam->async_mode) { \
89 vam->async_errors += (retval < 0); \
91 vam->retval = retval; \
92 vam->result_ready = 1; \
94 if(retval>=0)do{body;} while(0); \
95 else errmsg("Error, retval: %d",retval); \
97 foreach_custom_reply_handler;
100 * Table of message reply handlers, must include boilerplate handlers
103 #define foreach_vpe_api_reply_msg \
104 _(TRACE_PROFILE_ADD_REPLY, trace_profile_add_reply) \
105 _(TRACE_PROFILE_DEL_REPLY, trace_profile_del_reply) \
106 _(TRACE_PROFILE_SHOW_CONFIG_REPLY, trace_profile_show_config_reply)
109 api_trace_profile_add (vat_main_t * vam)
111 unformat_input_t *input = vam->input;
112 vl_api_trace_profile_add_t *mp;
120 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
122 if (unformat (input, "trace-type 0x%x", &trace_type))
124 else if (unformat (input, "trace-elts %d", &num_elts))
126 else if (unformat (input, "trace-tsp %d", &trace_tsp))
128 else if (unformat (input, "node-id 0x%x", &node_id))
130 else if (unformat (input, "app-data 0x%x", &app_data))
138 M (TRACE_PROFILE_ADD, mp);
140 mp->trace_type = trace_type;
141 mp->trace_tsp = trace_tsp;
142 mp->node_id = htonl (node_id);
143 mp->app_data = htonl (app_data);
144 mp->num_elts = num_elts;
154 api_trace_profile_del (vat_main_t * vam)
156 vl_api_trace_profile_del_t *mp;
159 M (TRACE_PROFILE_DEL, mp);
166 api_trace_profile_show_config (vat_main_t * vam)
168 vl_api_trace_profile_show_config_t *mp;
171 M (TRACE_PROFILE_SHOW_CONFIG, mp);
178 * List of messages that the api test plugin sends,
179 * and that the data plane plugin processes
181 #define foreach_vpe_api_msg \
182 _(trace_profile_add, ""\
183 "trace-type <0x1f|0x3|0x9|0x11|0x19> trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> app-data <app_data in hex>") \
184 _(trace_profile_del, "[id <nn>]") \
185 _(trace_profile_show_config, "[id <nn>]")
189 ioam_trace_vat_api_hookup (vat_main_t * vam)
191 trace_test_main_t *sm = &trace_test_main;
192 /* Hook up handlers for replies from the data plane plug-in */
194 vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
196 vl_api_##n##_t_handler, \
198 vl_api_##n##_t_endian, \
199 vl_api_##n##_t_print, \
200 sizeof(vl_api_##n##_t), 1);
201 foreach_vpe_api_reply_msg;
204 /* API messages we can send */
205 #define _(n,h) hash_set_mem (vam->function_by_name, #n, api_##n);
210 #define _(n,h) hash_set_mem (vam->help_by_name, #n, h);
216 trace_vat_plugin_register (vat_main_t * vam)
218 trace_test_main_t *sm = &trace_test_main;
223 name = format (0, "ioam_trace_%08x%c", api_version, 0);
224 sm->msg_id_base = vl_client_get_first_plugin_msg_id ((char *) name);
226 if (sm->msg_id_base != (u16) ~ 0)
227 ioam_trace_vat_api_hookup (vam);
235 * fd.io coding-style-patch-verification: ON
238 * eval: (c-set-style "gnu")