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:
7 * http://www.apache.org/licenses/LICENSE-2.0
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.
15 #include <vnet/vnet.h>
19 #include <vppinfra/mem.h>
20 #include "trace_util.h"
22 trace_main_t trace_main;
25 trace_profile_cleanup (trace_profile * profile)
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 */
36 trace_main_profiles_reset (void)
40 trace_main_t *sm = &trace_main;
41 rv = trace_profile_cleanup (&(sm->profile));
46 trace_util_init (void)
50 rv = trace_main_profiles_reset ();
56 trace_profile_create (trace_profile * profile, u8 trace_type, u8 num_elts,
57 u32 trace_tsp, u32 node_id, u32 app_data)
60 if (!trace_type || !num_elts || !(node_id))
64 if (profile && !profile->valid)
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;
74 /* lib-trace_TODO: Remove this once IOAM-IPv6 transport is a plugin */
75 ip6_trace_profile_setup ();
85 clear_trace_profile_command_fn (vlib_main_t * vm,
86 unformat_input_t * input,
87 vlib_cli_command_t * cmd)
90 trace_main_profiles_reset ();
95 clear_trace_profiles (void)
97 clear_trace_profile_command_fn (0, 0, 0);
101 VLIB_CLI_COMMAND(clear_trace_profile_command) =
103 .path = "clear ioam-trace profile",
104 .short_help = "clear ioam-trace profile [<index>|all]",
105 .function = clear_trace_profile_command_fn,
109 static clib_error_t *
110 set_trace_profile_command_fn (vlib_main_t * vm,
111 unformat_input_t * input,
112 vlib_cli_command_t * cmd)
119 trace_profile *profile = NULL;
120 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
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));
130 profile = trace_profile_find ();
133 trace_profile_create (profile, trace_type, num_elts, trace_tsp,
140 VLIB_CLI_COMMAND (set_trace_profile_command, static) =
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,
150 static clib_error_t *
151 show_trace_profile_command_fn (vlib_main_t * vm,
152 unformat_input_t * input,
153 vlib_cli_command_t * cmd)
155 trace_profile *p = NULL;
157 p = trace_profile_find ();
158 if (!(p && p->valid))
160 s = format (s, "\nTrace configuration not valid\n");
161 vlib_cli_output (vm, "%v", s);
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);
169 format (s, " Trace timestamp precision : %d (%s)\n",
172 TSP_SECONDS) ? "Seconds" : ((p->trace_tsp ==
179 s = format (s, " Num of trace nodes : %d\n", p->num_elts);
181 format (s, " Node-id : 0x%x (%d)\n",
182 p->node_id, p->node_id);
184 format (s, " App Data : 0x%x (%d)\n",
185 p->app_data, p->app_data);
186 vlib_cli_output (vm, "%v", s);
192 VLIB_CLI_COMMAND (show_trace_profile_command, static) =
194 .path = "show ioam-trace profile",
195 .short_help = "show ioam-trace profile",
196 .function = show_trace_profile_command_fn,
201 * fd.io coding-style-patch-verification: ON
204 * eval: (c-set-style "gnu")