FD.io VPP  v17.01.1-3-gc6833f8
Vector Packet Processing
trace_util.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 #include <vnet/vnet.h>
16 #include <stdint.h>
17 #include <time.h>
18 #include <string.h>
19 #include <vppinfra/mem.h>
20 #include "trace_util.h"
21 
23 
24 static int
26 {
27 
28  memset (profile, 0, sizeof (trace_profile));
29  profile->trace_tsp = TSP_MICROSECONDS; /* Micro seconds */
30  ip6_trace_profile_cleanup (); /* lib-trace_TODO: Remove this once IOAM-IPv6 transport is a plugin */
31  return 0;
32 
33 }
34 
35 static int
37 {
38  int rv;
39 
40  trace_main_t *sm = &trace_main;
41  rv = trace_profile_cleanup (&(sm->profile));
42  return (rv);
43 }
44 
45 int
47 {
48  int rv;
49 
51  return (rv);
52 }
53 
54 
55 int
56 trace_profile_create (trace_profile * profile, u8 trace_type, u8 num_elts,
57  u32 trace_tsp, u32 node_id, u32 app_data)
58 {
59 
60  if (!trace_type || !num_elts || !(node_id))
61  {
62  return (-1);
63  }
64  if (profile && !profile->valid)
65  {
66  //rv = trace_profile_cleanup (profile);
67  profile->trace_type = trace_type;
68  profile->num_elts = num_elts;
69  profile->trace_tsp = trace_tsp;
70  profile->node_id = node_id;
71  profile->app_data = app_data;
72  profile->valid = 1;
73 
74  /* lib-trace_TODO: Remove this once IOAM-IPv6 transport is a plugin */
76  return (0);
77  }
78 
79  return (-1);
80 }
81 
82 
83 
86  unformat_input_t * input,
87  vlib_cli_command_t * cmd)
88 {
89 
91  return 0;
92 }
93 
94 void
96 {
98 }
99 
100 /* *INDENT-OFF* */
101 VLIB_CLI_COMMAND(clear_trace_profile_command) =
102 {
103 .path = "clear ioam-trace profile",
104 .short_help = "clear ioam-trace profile [<index>|all]",
106 };
107 /* *INDENT-ON* */
108 
109 static clib_error_t *
111  unformat_input_t * input,
112  vlib_cli_command_t * cmd)
113 {
114  u8 trace_type = 0;
115  u8 num_elts = 0;
116  u32 node_id = 0;
117  u32 app_data = 0;
118  u32 trace_tsp = 0;
119  trace_profile *profile = NULL;
121  {
122  if (unformat (input, "trace-type 0x%x", &trace_type));
123  else if (unformat (input, "trace-elts %d", &num_elts));
124  else if (unformat (input, "trace-tsp %d", &trace_tsp));
125  else if (unformat (input, "node-id 0x%x", &node_id));
126  else if (unformat (input, "app-data 0x%x", &app_data));
127  else
128  break;
129  }
130  profile = trace_profile_find ();
131  if (profile)
132  {
133  trace_profile_create (profile, trace_type, num_elts, trace_tsp,
134  node_id, app_data);
135  }
136  return 0;
137 }
138 
139 /* *INDENT-OFF* */
140 VLIB_CLI_COMMAND (set_trace_profile_command, static) =
141 {
142 .path = "set ioam-trace profile",
143 .short_help = "set ioam-trace \
144  trace-type <0x1f|0x3|0x9|0x11|0x19> trace-elts <nn> trace-tsp <0|1|2|3> \
145  node-id <node id in hex> app-data <app_data in hex>",
146 .function = set_trace_profile_command_fn,
147 };
148 /* *INDENT-ON* */
149 
150 static clib_error_t *
152  unformat_input_t * input,
153  vlib_cli_command_t * cmd)
154 {
155  trace_profile *p = NULL;
156  u8 *s = 0;
157  p = trace_profile_find ();
158  if (!(p && p->valid))
159  {
160  s = format (s, "\nTrace configuration not valid\n");
161  vlib_cli_output (vm, "%v", s);
162  vec_free (s);
163  return 0;
164  }
165  s = format (s, " HOP BY HOP OPTIONS - TRACE CONFIG - \n");
166  s = format (s, " Trace Type : 0x%x (%d)\n",
167  p->trace_type, p->trace_type);
168  s =
169  format (s, " Trace timestamp precision : %d (%s)\n",
170  p->trace_tsp,
171  (p->trace_tsp ==
172  TSP_SECONDS) ? "Seconds" : ((p->trace_tsp ==
174  "Milliseconds"
175  : (((p->trace_tsp ==
177  "Microseconds" :
178  "Nanoseconds"))));
179  s = format (s, " Num of trace nodes : %d\n", p->num_elts);
180  s =
181  format (s, " Node-id : 0x%x (%d)\n",
182  p->node_id, p->node_id);
183  s =
184  format (s, " App Data : 0x%x (%d)\n",
185  p->app_data, p->app_data);
186  vlib_cli_output (vm, "%v", s);
187  vec_free (s);
188  return 0;
189 }
190 
191 /* *INDENT-OFF* */
192 VLIB_CLI_COMMAND (show_trace_profile_command, static) =
193 {
194 .path = "show ioam-trace profile",
195 .short_help = "show ioam-trace profile",
197 };
198 /* *INDENT-ON* */
199 
200 /*
201  * fd.io coding-style-patch-verification: ON
202  *
203  * Local Variables:
204  * eval: (c-set-style "gnu")
205  * End:
206  */
clib_error_t * clear_trace_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: trace_util.c:85
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
trace_main_t trace_main
Definition: trace_util.c:22
static int trace_profile_cleanup(trace_profile *profile)
Definition: trace_util.c:25
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
#define NULL
Definition: clib.h:55
static clib_error_t * show_trace_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: trace_util.c:151
#define TSP_SECONDS
Definition: trace_util.h:234
int ip6_trace_profile_setup()
trace_profile profile
Definition: trace_util.h:55
void clear_trace_profiles(void)
Definition: trace_util.c:95
static int trace_main_profiles_reset(void)
Definition: trace_util.c:36
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:576
int ip6_trace_profile_cleanup(void)
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:300
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
unsigned int u32
Definition: types.h:88
#define TSP_MILLISECONDS
Definition: trace_util.h:235
static clib_error_t * set_trace_profile_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: trace_util.c:110
int trace_util_init(void)
Definition: trace_util.c:46
unsigned char u8
Definition: types.h:56
#define TSP_MICROSECONDS
Definition: trace_util.h:236
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
static trace_profile * trace_profile_find(void)
Definition: trace_util.h:78
struct _unformat_input_t unformat_input_t
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:56