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