FD.io VPP  v16.12-rc0-308-g931be3a
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 
25 
26 static int
28 {
29  int rv;
31 
32  memset (profile, 0, sizeof (trace_profile));
33  profile->trace_tsp = TSP_MICROSECONDS; /* Micro seconds */
35  if (0 !=
36  (rv =
39  return (-1);
40  return 0;
41 
42 }
43 
44 static int
46 {
47  int rv;
48 
49  trace_main_t *sm = &trace_main;
50  rv = trace_profile_cleanup (&(sm->profile));
51  return (rv);
52 }
53 
54 int
56 {
57  int rv;
58 
60  return (rv);
61 }
62 
63 
64 int
65 trace_profile_create (trace_profile * profile, u8 trace_type, u8 num_elts,
66  u32 trace_tsp, u32 node_id, u32 app_data)
67 {
68  u32 trace_size = 0;
69  int rv;
71 
72  if (profile && !profile->valid)
73  {
74  //rv = trace_profile_cleanup (profile);
75  profile->trace_type = trace_type;
76  profile->num_elts = num_elts;
77  profile->trace_tsp = trace_tsp;
78  profile->node_id = node_id;
79  profile->app_data = app_data;
80  profile->valid = 1;
81 
82  if (ioam_trace_get_sizeof_handler (&trace_size) < 0)
83  return (-1);
84 
86 
87  if (hm->has_trace_option)
88  {
89  if (0 !=
90  (rv =
92  hm->has_pot_option,
93  hm->has_seqno_option)))
94  return (-1);
95 
96  }
97  return (0);
98  }
99 
100  return (-1);
101 }
102 
103 
104 
105 clib_error_t *
107  unformat_input_t * input,
108  vlib_cli_command_t * cmd)
109 {
110 
112  return 0;
113 }
114 
115 void
117 {
119 }
120 
121 /* *INDENT-OFF* */
122 VLIB_CLI_COMMAND(clear_trace_profile_command) =
123 {
124 .path = "clear ioam-trace profile",
125 .short_help = "clear ioam-trace profile [<index>|all]",
127 };
128 /* *INDENT-ON* */
129 
130 static clib_error_t *
132  unformat_input_t * input,
133  vlib_cli_command_t * cmd)
134 {
135  u8 trace_type = 0;
136  u8 num_elts = 0;
137  u32 node_id = 0;
138  u32 app_data = 0;
139  u32 trace_tsp = 0;
140  trace_profile *profile = NULL;
142  {
143  if (unformat (input, "trace-type 0x%x", &trace_type));
144  else if (unformat (input, "trace-elts %d", &num_elts));
145  else if (unformat (input, "trace-tsp %d", &trace_tsp));
146  else if (unformat (input, "node-id 0x%x", &node_id));
147  else if (unformat (input, "app-data 0x%x", &app_data));
148  else
149  break;
150  }
151  profile = trace_profile_find ();
152  if (profile)
153  {
154  trace_profile_create (profile, trace_type, num_elts, trace_tsp,
155  node_id, app_data);
156  }
157  return 0;
158 }
159 
160 /* *INDENT-OFF* */
161 VLIB_CLI_COMMAND (set_trace_profile_command, static) =
162 {
163 .path = "set ioam-trace profile",
164 .short_help = "set ioam-trace \
165  trace-type <0x1f|0x3|0x9|0x11|0x19> trace-elts <nn> trace-tsp <0|1|2|3> \
166  node-id <node id in hex> app-data <app_data in hex>",
167 .function = set_trace_profile_command_fn,
168 };
169 /* *INDENT-ON* */
170 
171 static clib_error_t *
173  unformat_input_t * input,
174  vlib_cli_command_t * cmd)
175 {
176  trace_profile *p = NULL;
177  u8 *s = 0;
178  p = trace_profile_find ();
179  if (!(p && p->valid))
180  {
181  s = format (s, "\nTrace configuration not valid\n");
182  vlib_cli_output (vm, "%v", s);
183  vec_free (s);
184  return 0;
185  }
186  s = format (s, " HOP BY HOP OPTIONS - TRACE CONFIG - \n");
187  s = format (s, " Trace Type : 0x%x (%d)\n",
188  p->trace_type, p->trace_type);
189  s =
190  format (s, " Trace timestamp precision : %d (%s)\n",
191  p->trace_tsp,
192  (p->trace_tsp ==
193  TSP_SECONDS) ? "Seconds" : ((p->trace_tsp ==
195  "Milliseconds"
196  : (((p->trace_tsp ==
198  "Microseconds" :
199  "Nanoseconds"))));
200  s = format (s, " Num of trace nodes : %d\n", p->num_elts);
201  s =
202  format (s, " Node-id : 0x%x (%d)\n",
203  p->node_id, p->node_id);
204  s =
205  format (s, " App Data : 0x%x (%d)\n",
206  p->app_data, p->app_data);
207  vlib_cli_output (vm, "%v", s);
208  vec_free (s);
209  return 0;
210 }
211 
212 /* *INDENT-OFF* */
213 VLIB_CLI_COMMAND (show_trace_profile_command, static) =
214 {
215 .path = "show ioam-trace profile",
216 .short_help = "show ioam-trace profile",
218 };
219 /* *INDENT-ON* */
220 
221 /*
222  * fd.io coding-style-patch-verification: ON
223  *
224  * Local Variables:
225  * eval: (c-set-style "gnu")
226  * End:
227  */
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:106
uword unformat(unformat_input_t *i, char *fmt,...)
Definition: unformat.c:966
#define TSP_MICROSECONDS
trace_main_t trace_main
Definition: trace_util.c:22
static int trace_profile_cleanup(trace_profile *profile)
Definition: trace_util.c:27
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
#define TSP_SECONDS
#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:172
#define TSP_MILLISECONDS
trace_profile profile
Definition: trace_util.h:56
int ip6_ioam_set_rewrite(u8 **rwp, int has_trace_option, int has_pot_option, int has_seqno_option)
u8 options_size[MAX_IP6_HBH_OPTION]
int ioam_trace_get_sizeof_handler(u32 *result)
void clear_trace_profiles(void)
Definition: trace_util.c:116
static int trace_main_profiles_reset(void)
Definition: trace_util.c:45
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:575
#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
static trace_profile * trace_profile_find(void)
Definition: trace_util.h:80
#define HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST
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:131
int trace_util_init(void)
Definition: trace_util.c:55
unsigned char u8
Definition: types.h:56
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169
ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:418
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:65