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;
24 extern ip6_hop_by_hop_ioam_main_t ip6_hop_by_hop_ioam_main;
27 trace_profile_cleanup (trace_profile * profile)
30 ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
32 memset (profile, 0, sizeof (trace_profile));
33 profile->trace_tsp = TSP_MICROSECONDS; /* Micro seconds */
34 hm->options_size[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] = 0;
37 ip6_ioam_set_rewrite (&hm->rewrite, hm->has_trace_option,
38 hm->has_pot_option, hm->has_ppc_option)))
45 trace_main_profiles_reset (void)
49 trace_main_t *sm = &trace_main;
50 rv = trace_profile_cleanup (&(sm->profile));
55 trace_util_init (void)
59 rv = trace_main_profiles_reset ();
65 trace_profile_create (trace_profile * profile, u8 trace_type, u8 num_elts,
66 u32 trace_tsp, u32 node_id, u32 app_data)
70 ip6_hop_by_hop_ioam_main_t *hm = &ip6_hop_by_hop_ioam_main;
72 if (profile && !profile->valid)
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;
82 if (ioam_trace_get_sizeof_handler (&trace_size) < 0)
85 hm->options_size[HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST] = trace_size;
87 if (hm->has_trace_option)
91 ip6_ioam_set_rewrite (&hm->rewrite, hm->has_trace_option,
92 hm->has_pot_option, hm->has_ppc_option)))
105 clear_trace_profile_command_fn (vlib_main_t * vm,
106 unformat_input_t * input,
107 vlib_cli_command_t * cmd)
110 trace_main_profiles_reset ();
115 clear_trace_profiles (void)
117 clear_trace_profile_command_fn (0, 0, 0);
121 VLIB_CLI_COMMAND(clear_trace_profile_command) =
123 .path = "clear ioam-trace profile",
124 .short_help = "clear ioam-trace profile [<index>|all]",
125 .function = clear_trace_profile_command_fn,
129 static clib_error_t *
130 set_trace_profile_command_fn (vlib_main_t * vm,
131 unformat_input_t * input,
132 vlib_cli_command_t * cmd)
139 trace_profile *profile = NULL;
140 while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT)
142 if (unformat (input, "trace-type 0x%x", &trace_type));
143 else if (unformat (input, "trace-elts %d", &num_elts));
144 else if (unformat (input, "trace-tsp %d", &trace_tsp));
145 else if (unformat (input, "node-id 0x%x", &node_id));
146 else if (unformat (input, "app-data 0x%x", &app_data));
148 return clib_error_return (0, "unknown input `%U'",
149 format_unformat_error, input);
151 profile = trace_profile_find ();
154 trace_profile_create (profile, trace_type, num_elts, trace_tsp,
161 VLIB_CLI_COMMAND (set_trace_profile_command) =
163 .path = "set ioam-trace profile",.short_help = "set ioam-trace \
164 trace-type <0x1f|0x3|0x9|0x11|0x19> trace-elts <nn> trace-tsp <0|1|2|3> node-id <node id in hex> app-data <app_data in hex>",.function = set_trace_profile_command_fn,};
168 static clib_error_t *
169 show_trace_profile_command_fn (vlib_main_t * vm,
170 unformat_input_t * input,
171 vlib_cli_command_t * cmd)
173 trace_profile *p = NULL;
175 p = trace_profile_find ();
178 s = format (s, " HOP BY HOP OPTIONS - TRACE CONFIG - \n");
179 s = format (s, " Trace Type : 0x%x (%d)\n",
180 p->trace_type, p->trace_type);
182 format (s, " Trace timestamp precision : %d (%s)\n",
185 TSP_SECONDS) ? "Seconds" : ((p->trace_tsp ==
192 s = format (s, " Num of trace nodes : %d\n", p->num_elts);
194 format (s, " Node-id : 0x%x (%d)\n",
195 p->node_id, p->node_id);
197 format (s, " App Data : 0x%x (%d)\n",
198 p->app_data, p->app_data);
199 if (!(p && p->valid))
201 s = format (s, "\nTrace configuration not valid\n");
203 vlib_cli_output (vm, "%v", s);
209 VLIB_CLI_COMMAND (show_trace_profile_command) =
211 .path = "show ioam-trace profile",.short_help =
212 "show ioam-trace profile",.function = show_trace_profile_command_fn,};
216 * fd.io coding-style-patch-verification: ON
219 * eval: (c-set-style "gnu")