FD.io VPP  v21.01.1
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 /* define message IDs */
31 #include <ioam/lib-trace/trace.api_enum.h>
32 #include <ioam/lib-trace/trace.api_types.h>
33 
36 {
37  int rv = 0;
38  vl_api_trace_profile_add_reply_t *rmp;
39  trace_profile *profile = NULL;
40 
41  profile = trace_profile_find ();
42  if (profile)
43  {
44  rv =
45  trace_profile_create (profile, mp->trace_type, mp->num_elts,
46  mp->trace_tsp, ntohl (mp->node_id),
47  ntohl (mp->app_data));
48  if (rv != 0)
49  goto ERROROUT;
50  }
51  else
52  {
53  rv = -3;
54  }
55 ERROROUT:
56  REPLY_MACRO (VL_API_TRACE_PROFILE_ADD_REPLY);
57 }
58 
59 
62 {
63  int rv = 0;
64  vl_api_trace_profile_del_reply_t *rmp;
65 
67 
68  REPLY_MACRO (VL_API_TRACE_PROFILE_DEL_REPLY);
69 }
70 
73 {
75  int rv = 0;
76  trace_profile *profile = trace_profile_find ();
77  if (profile->valid)
78  {
79  REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
80  rmp->trace_type = profile->trace_type;
81  rmp->num_elts = profile->num_elts;
82  rmp->trace_tsp = profile->trace_tsp;
83  rmp->node_id = htonl (profile->node_id);
84  rmp->app_data = htonl (profile->app_data);
85  );
86  }
87  else
88  {
89  REPLY_MACRO2 (VL_API_TRACE_PROFILE_SHOW_CONFIG_REPLY,
90  rmp->trace_type = 0;
91  rmp->num_elts = 0; rmp->trace_tsp = 0;
92  rmp->node_id = 0; rmp->app_data = 0;
93  );
94  }
95 }
96 
97 #include <ioam/lib-trace/trace.api.c>
98 static clib_error_t *
100 {
101  trace_main_t *sm = &trace_main;
102 
103  bzero (sm, sizeof (trace_main));
104  (void) trace_util_init ();
105 
106  sm->vlib_main = vm;
107  sm->vnet_main = vnet_get_main ();
108 
109  /* Ask for a correctly-sized block of API message decode slots */
111 
112  return 0;
113 }
114 
116 
117 /*
118  * fd.io coding-style-patch-verification: ON
119  *
120  * Local Variables:
121  * eval: (c-set-style "gnu")
122  * End:
123  */
static void vl_api_trace_profile_show_config_t_handler(vl_api_trace_profile_show_config_t *mp)
Definition: trace_api.c:72
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
Show trace Profile.
Definition: trace.api:49
#define REPLY_MACRO2(t, body)
trace_main_t trace_main
Definition: trace_util.c:23
static trace_profile * trace_profile_find(void)
Definition: trace_config.h:24
vlib_main_t * vm
Definition: in2out_ed.c:1580
vnet_main_t * vnet_main
Definition: trace_util.h:62
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
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
static void setup_message_id_table(api_main_t *am)
Definition: bfd_api.c:409
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:61
static void vl_api_trace_profile_add_t_handler(vl_api_trace_profile_add_t *mp)
Definition: trace_api.c:35
int trace_util_init(void)
Definition: trace_util.c:47
static clib_error_t * trace_init(vlib_main_t *vm)
Definition: trace_api.c:99
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