FD.io VPP  v19.04.2-12-g66b1689
Vector Packet Processing
trace_api.c
Go to the documentation of this file.
1 /*
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:
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
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.
14  */
15 /*
16  *------------------------------------------------------------------
17  * trace_api.c - iOAM Trace related APIs to create
18  * and maintain profiles
19  *------------------------------------------------------------------
20  */
21 
22 #include <vnet/vnet.h>
23 #include <vnet/plugin/plugin.h>
27 #include <vlibapi/api.h>
28 #include <vlibmemory/api.h>
29 
30 
31 /* define message IDs */
33 
34 /* define message structures */
35 #define vl_typedefs
37 #undef vl_typedefs
38 
39 /* define generated endian-swappers */
40 #define vl_endianfun
42 #undef vl_endianfun
43 
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #define vl_printfun
48 #undef vl_printfun
49 
50 /* Get the API version number */
51 #define vl_api_version(n,v) static u32 api_version=(v);
53 #undef vl_api_version
54 
55 /* List of message types that this plugin understands */
56 
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)
61 
64 {
65  int rv = 0;
66  vl_api_trace_profile_add_reply_t *rmp;
67  trace_profile *profile = NULL;
68 
69  profile = trace_profile_find ();
70  if (profile)
71  {
72  rv =
73  trace_profile_create (profile, mp->trace_type, mp->num_elts,
74  mp->trace_tsp, ntohl (mp->node_id),
75  ntohl (mp->app_data));
76  if (rv != 0)
77  goto ERROROUT;
78  }
79  else
80  {
81  rv = -3;
82  }
83 ERROROUT:
84  REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
85 }
86 
87 
90 {
91  int rv = 0;
92  vl_api_trace_profile_del_reply_t *rmp;
93 
95 
96  REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
97 }
98 
101 {
103  int rv = 0;
104  trace_profile *profile = trace_profile_find ();
105  if (profile->valid)
106  {
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);
113  );
114  }
115  else
116  {
117  REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
118  rmp->trace_type = 0;
119  rmp->num_elts = 0; rmp->trace_tsp = 0;
120  rmp->node_id = 0; rmp->app_data = 0;
121  );
122  }
123 }
124 
125 /* Set up the API message handling tables */
126 static clib_error_t *
128 {
129  trace_main_t *sm = &trace_main;
130 #define _(N,n) \
131  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
132  #n, \
133  vl_api_##n##_t_handler, \
134  vl_noop_handler, \
135  vl_api_##n##_t_endian, \
136  vl_api_##n##_t_print, \
137  sizeof(vl_api_##n##_t), 1);
139 #undef _
140 
141  return 0;
142 }
143 
144 #define vl_msg_name_crc_list
146 #undef vl_msg_name_crc_list
147 
148 static void
150 {
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;
154 #undef _
155 }
156 
157 static clib_error_t *
159 {
160  trace_main_t *sm = &trace_main;
161  clib_error_t *error = 0;
162  u8 *name;
163 
164  bzero (sm, sizeof (trace_main));
165  (void) trace_util_init ();
166 
167  sm->vlib_main = vm;
168  sm->vnet_main = vnet_get_main ();
169 
170  name = format (0, "ioam_trace_%08x%c", api_version, 0);
171 
172  /* Ask for a correctly-sized block of API message decode slots */
174  ((char *) name, VL_MSG_FIRST_AVAILABLE);
175 
176  error = trace_plugin_api_hookup (vm);
177 
178  /* Add our API messages to the global name_crc hash table */
180 
181  vec_free (name);
182 
183  return error;
184 }
185 
187 
188 /*
189  * fd.io coding-style-patch-verification: ON
190  *
191  * Local Variables:
192  * eval: (c-set-style "gnu")
193  * End:
194  */
static void vl_api_trace_profile_show_config_t_handler(vl_api_trace_profile_show_config_t *mp)
Definition: trace_api.c:100
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
Show trace Profile.
Definition: trace.api:49
#define REPLY_MACRO2(t, body)
#define NULL
Definition: clib.h:58
static clib_error_t * trace_plugin_api_hookup(vlib_main_t *vm)
Definition: trace_api.c:127
trace_main_t trace_main
Definition: trace_util.c:23
static trace_profile * trace_profile_find(void)
Definition: trace_config.h:24
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
unsigned char u8
Definition: types.h:56
vnet_main_t * vnet_main
Definition: trace_util.h:62
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:163
Delete trace Profile.
Definition: trace.api:40
void clear_trace_profiles(void)
Definition: trace_util.c:96
iOAM6 Trace - Set the iOAM6 trace profile
Definition: trace.api:26
#define REPLY_MACRO(t)
u16 msg_id_base
Definition: trace_util.h:58
u8 name[64]
Definition: memclnt.api:152
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:202
vlib_main_t * vm
Definition: buffer.c:312
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
Show trace config response.
Definition: trace.api:63
static void vl_api_trace_profile_del_t_handler(vl_api_trace_profile_del_t *mp)
Definition: trace_api.c:89
static void setup_message_id_table(trace_main_t *sm, api_main_t *am)
Definition: trace_api.c:149
#define foreach_trace_plugin_api_msg
Definition: trace_api.c:57
static void vl_api_trace_profile_add_t_handler(vl_api_trace_profile_add_t *mp)
Definition: trace_api.c:63
int trace_util_init(void)
Definition: trace_util.c:47
static clib_error_t * trace_init(vlib_main_t *vm)
Definition: trace_api.c:158
api_main_t api_main
Definition: api_shared.c:35
int trace_profile_create(trace_profile *profile, u8 trace_type, u8 num_elts, u32 trace_tsp, u32 node_id, u32 app_data)
Definition: trace_util.c:57
vlib_main_t * vlib_main
Definition: trace_util.h:61
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:880