FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
ioam_cache.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 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 /*
16  *------------------------------------------------------------------
17  * ioam_cache.c - ioam ip6 API / debug CLI handling
18  *------------------------------------------------------------------
19  */
20 
21 #include <vnet/vnet.h>
22 #include <vnet/plugin/plugin.h>
23 #include <ioam/ip6/ioam_cache.h>
24 
25 #include <vlibapi/api.h>
26 #include <vlibmemory/api.h>
27 #include <vnet/ip/ip6_hop_by_hop.h>
28 
29 #include "ioam_cache.h"
30 
31 /* define message IDs */
33 
34 /* define message structures */
35 #define vl_typedefs
37 #undef vl_typedefs
38 
39 /* define generated endian-swappers */
40 #define vl_endianfun
42 #undef vl_endianfun
43 
44 /* instantiate all the print functions we know about */
45 #define vl_print(handle, ...) vlib_cli_output (handle, __VA_ARGS__)
46 #define vl_printfun
48 #undef vl_printfun
49 
50 /* Get the API version number */
51 #define vl_api_version(n,v) static u32 api_version=(v);
53 #undef vl_api_version
54 
55 #define REPLY_MSG_ID_BASE cm->msg_id_base
57 
59 
60 /* List of message types that this plugin understands */
61 #define foreach_ioam_cache_plugin_api_msg \
62 _(IOAM_CACHE_IP6_ENABLE_DISABLE, ioam_cache_ip6_enable_disable)
63 
64 static u8 *
66 {
67  ioam_e2e_id_option_t *e2e = (ioam_e2e_id_option_t *) opt;
68 
69  if (e2e)
70  {
71  s =
72  format (s, "IP6_HOP_BY_HOP E2E ID = %U\n", format_ip6_address,
73  &(e2e->id));
74  }
75 
76 
77  return s;
78 }
79 
80 static u8 *
82 {
83  ioam_e2e_cache_option_t *e2e = (ioam_e2e_cache_option_t *) opt;
84 
85  if (e2e)
86  {
87  s =
88  format (s, "IP6_HOP_BY_HOP E2E CACHE = pool:%d idx:%d\n",
89  e2e->pool_id, e2e->pool_index);
90  }
91 
92 
93  return s;
94 }
95 
96 /* Action function shared between message handler and debug CLI */
97 int
99  ip6_address_t * sr_localsid, u8 is_disable)
100 {
101  vlib_main_t *vm = em->vlib_main;
102 
103  if (is_disable == 0)
104  {
106  em->sr_localsid_cache.as_u64[0] = sr_localsid->as_u64[0];
107  em->sr_localsid_cache.as_u64[1] = sr_localsid->as_u64[1];
113 
114  }
115  else
116  {
119  em->sr_localsid_cache.as_u64[0] = 0;
120  em->sr_localsid_cache.as_u64[1] = 0;
123  }
124 
125  return 0;
126 }
127 
128 /* Action function shared between message handler and debug CLI */
129 int
131  u8 criteria,
132  u8 no_of_responses,
133  ip6_address_t * sr_localsid,
134  u8 is_disable)
135 {
136  vlib_main_t *vm = em->vlib_main;
137 
138  if (is_disable == 0)
139  {
141  em->criteria_oneway = criteria;
142  em->wait_for_responses = no_of_responses;
143  em->sr_localsid_ts.as_u64[0] = sr_localsid->as_u64[0];
144  em->sr_localsid_ts.as_u64[1] = sr_localsid->as_u64[1];
151 
152  /* Turn on the cleanup process */
153  // vlib_process_signal_event (vm, em->cleanup_process_node_index, 1, 0);
154  }
155  else
156  {
159  em->sr_localsid_ts.as_u64[0] = 0;
160  em->sr_localsid_ts.as_u64[1] = 0;
165  }
166 
167  return 0;
168 }
169 
170 /* API message handler */
173 {
174  vl_api_ioam_cache_ip6_enable_disable_reply_t *rmp;
176  ip6_address_t sr_localsid;
177  int rv;
178 
179  sr_localsid.as_u64[0] = 0;
180  sr_localsid.as_u64[1] = 0;
181  rv =
182  ioam_cache_ip6_enable_disable (cm, &sr_localsid, (int) (mp->is_disable));
183  REPLY_MACRO (VL_API_IOAM_CACHE_IP6_ENABLE_DISABLE_REPLY);
184 }
185 
186 /* Set up the API message handling tables */
187 static clib_error_t *
189 {
191 #define _(N,n) \
192  vl_msg_api_set_handlers((VL_API_##N + sm->msg_id_base), \
193  #n, \
194  vl_api_##n##_t_handler, \
195  vl_noop_handler, \
196  vl_api_##n##_t_endian, \
197  vl_api_##n##_t_print, \
198  sizeof(vl_api_##n##_t), 1);
200 #undef _
201 
202  return 0;
203 }
204 
205 #define vl_msg_name_crc_list
207 #undef vl_msg_name_crc_list
208 
209 static void
211 {
212 #define _(id,n,crc) \
213  vl_msg_api_add_msg_name_crc (am, #n "_" #crc, id + sm->msg_id_base);
214  foreach_vl_msg_name_crc_ioam_cache;
215 #undef _
216 }
217 
218 static clib_error_t *
220  unformat_input_t * input, vlib_cli_command_t * cmd)
221 {
223  u8 is_disable = 0;
224  ip6_address_t sr_localsid;
225  u8 address_set = 0;
226 
228  {
229  if (unformat (input, "disable"))
230  is_disable = 1;
231  else if (!address_set
232  && unformat (input, "sr_localsid %U", unformat_ip6_address,
233  &sr_localsid))
234  address_set = 1;
235  else
236  break;
237  }
238 
239  if (is_disable == 0 && !address_set)
240  return clib_error_return (0, "Error: SRv6 LocalSID address is mandatory");
241 
242  ioam_cache_ip6_enable_disable (em, &sr_localsid, is_disable);
243 
244  return 0;
245 }
246 
247 /* *INDENT_OFF* */
248 VLIB_CLI_COMMAND (set_ioam_cache_command, static) =
249 {
250 .path = "set ioam ip6 cache",.short_help =
251  "set ioam ip6 cache sr_localsid <ip6 address> [disable]",.function =
253 /* *INDENT_ON* */
254 
255 #define IOAM_TS_WAIT_FOR_RESPONSES 3
256 static clib_error_t *
258  unformat_input_t * input,
259  vlib_cli_command_t * cmd)
260 {
262  u8 is_disable = 0;
263  u8 one_way = 0;
264  ip6_address_t sr_localsid;
265  u8 address_set = 0;
266  u8 no_of_responses = IOAM_TS_WAIT_FOR_RESPONSES;
267 
269  {
270  if (unformat (input, "disable"))
271  is_disable = 1;
272  else if (unformat (input, "rtt"))
273  one_way = 0;
274  else if (unformat (input, "oneway"))
275  one_way = 1;
276  else if (unformat (input, "wait_for_responses %d", &no_of_responses))
277  ;
278  else if (!address_set
279  && unformat (input, "sr_localsid %U", unformat_ip6_address,
280  &sr_localsid))
281  address_set = 1;
282  else
283  break;
284  }
285  if (is_disable == 0 && !address_set)
286  return clib_error_return (0,
287  "Error: SRv6 LocalSID address is mandatory to receive response.");
288 
289  ioam_tunnel_select_ip6_enable_disable (em, one_way, no_of_responses,
290  &sr_localsid, is_disable);
291 
292  return 0;
293 }
294 
295 /* *INDENT_OFF* */
296 VLIB_CLI_COMMAND (set_ioam_cache_ts_command, static) =
297 {
298 .path = "set ioam ip6 sr-tunnel-select",.short_help =
299  "set ioam ip6 sr-tunnel-select [disable] [oneway|rtt] [wait_for_responses <n|default 3>] \
300  [sr_localsid <ip6 address>]",.function = set_ioam_tunnel_select_command_fn};
301 /* *INDENT_ON* */
302 
303 static void
305 {
307  ioam_cache_entry_t *entry = 0;
308  ioam_cache_ts_entry_t *ts_entry = 0;
309  int no_of_threads = vec_len (vlib_worker_threads);
310  int i;
311 
312  pool_foreach (entry, cm->ioam_rewrite_pool, (
313  {
314  vlib_cli_output (vm, "%U",
315  format_ioam_cache_entry,
316  entry);
317  }));
318 
319  if (cm->ts_stats)
320  for (i = 0; i < no_of_threads; i++)
321  {
322  vlib_cli_output (vm, "Number of entries in thread-%d selection pool: %lu\n \
323  (pool found to be full: %lu times)", i,
324  cm->ts_stats[i].inuse, cm->ts_stats[i].add_failed);
325 
326  if (verbose == 1)
328  pool_foreach (ts_entry, cm->ioam_ts_pool[i], (
329  {
330  vlib_cli_output (vm,
331  "%U",
332  format_ioam_cache_ts_entry,
333  ts_entry,
334  (u32)
335  i);
336  }
337  ));
339  }
340 
341 }
342 
343 static clib_error_t *
345  unformat_input_t * input,
346  vlib_cli_command_t * cmd)
347 {
348  u8 verbose = 0;
349 
351  {
352  if (unformat (input, "verbose"))
353  verbose = 1;
354  else
355  return clib_error_return (0, "unknown input `%U'",
356  format_unformat_error, input);
357  }
358  ioam_cache_table_print (vm, verbose);
359 
360 
361  return 0;
362 }
363 
364 /* *INDENT_OFF* */
365 VLIB_CLI_COMMAND (show_ioam_cache_command, static) =
366 {
367 .path = "show ioam ip6 cache",.short_help =
368  "show ioam ip6 cache [verbose]",.function = show_ioam_cache_command_fn};
369 /* *INDENT_ON* */
370 
371 static clib_error_t *
373 {
374  vlib_node_t *node;
376  clib_error_t *error = 0;
377  u8 *name;
378  u32 cache_node_index = ioam_cache_node.index;
379  u32 ts_node_index = ioam_cache_ts_node.index;
380  vlib_node_t *ip6_hbyh_node = NULL, *ip6_hbh_pop_node = NULL, *error_node =
381  NULL;
382 
383  name = format (0, "ioam_cache_%08x%c", api_version, 0);
384 
385  clib_memset (&ioam_cache_main, 0, sizeof (ioam_cache_main));
386  /* Ask for a correctly-sized block of API message decode slots */
388  ((char *) name, VL_MSG_FIRST_AVAILABLE);
389 
390  error = ioam_cache_plugin_api_hookup (vm);
391 
392  /* Add our API messages to the global name_crc hash table */
394 
395  /* Hook this node to ip6-hop-by-hop */
396  ip6_hbyh_node = vlib_get_node_by_name (vm, (u8 *) "ip6-hop-by-hop");
397  em->cache_hbh_slot =
398  vlib_node_add_next (vm, ip6_hbyh_node->index, cache_node_index);
399  em->ts_hbh_slot =
400  vlib_node_add_next (vm, ip6_hbyh_node->index, ts_node_index);
401 
402  ip6_hbh_pop_node = vlib_get_node_by_name (vm, (u8 *) "ip6-pop-hop-by-hop");
403  em->ip6_hbh_pop_node_index = ip6_hbh_pop_node->index;
404 
405  error_node = vlib_get_node_by_name (vm, (u8 *) "error-drop");
406  em->error_node_index = error_node->index;
407  em->vlib_main = vm;
408 
409  node = vlib_get_node_by_name (vm, (u8 *) "ip6-add-from-cache-hop-by-hop");
411 
412  node = vlib_get_node_by_name (vm, (u8 *) "ip6-add-syn-hop-by-hop");
414 
415  vec_free (name);
416 
417  return error;
418 }
419 
421 
422 /*
423  * fd.io coding-style-patch-verification: ON
424  *
425  * Local Variables:
426  * eval: (c-set-style "gnu")
427  * End:
428  */
ip6_address_t sr_localsid_ts
Definition: ioam_cache.h:198
int ioam_tunnel_select_ip6_enable_disable(ioam_cache_main_t *em, u8 criteria, u8 no_of_responses, ip6_address_t *sr_localsid, u8 is_disable)
Definition: ioam_cache.c:130
static clib_error_t * set_ioam_cache_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ioam_cache.c:219
ioam_cache_entry_t * ioam_rewrite_pool
Definition: ioam_cache.h:172
static int ioam_cache_ts_table_init(vlib_main_t *vm)
Definition: ioam_cache.h:528
void ip6_hbh_set_next_override(uword next)
Definition: ip6_forward.c:2741
u64 as_u64[2]
Definition: ip6_packet.h:51
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
u32 index
Definition: node.h:280
int ip6_hbh_register_option(u8 option, int options(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt), u8 *trace(u8 *s, ip6_hop_by_hop_option_t *opt))
Definition: ip6_forward.c:2749
#define IOAM_TS_WAIT_FOR_RESPONSES
Definition: ioam_cache.c:255
static int ioam_cache_table_init(vlib_main_t *vm)
Definition: ioam_cache.h:449
static int ioam_cache_table_destroy(vlib_main_t *vm)
Definition: ioam_cache.h:468
static clib_error_t * show_ioam_cache_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ioam_cache.c:344
int i
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
static uword vlib_node_add_next(vlib_main_t *vm, uword node, uword next_node)
Definition: node_funcs.h:1092
unsigned char u8
Definition: types.h:56
static clib_error_t * set_ioam_tunnel_select_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Definition: ioam_cache.c:257
static void setup_message_id_table(ioam_cache_main_t *sm, api_main_t *am)
Definition: ioam_cache.c:210
#define vlib_worker_thread_barrier_sync(X)
Definition: threads.h:204
Definition: ioam_cache.h:99
int ioam_cache_ip6_enable_disable(ioam_cache_main_t *em, ip6_address_t *sr_localsid, u8 is_disable)
Definition: ioam_cache.c:98
ip6_address_t sr_localsid_cache
Definition: ioam_cache.h:180
static int ip6_ioam_ts_cache_set_rewrite(void)
Definition: ioam_cache.h:853
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
static void vl_api_ioam_cache_ip6_enable_disable_t_handler(vl_api_ioam_cache_ip6_enable_disable_t *mp)
Definition: ioam_cache.c:172
#define clib_error_return(e, args...)
Definition: error.h:99
u32 ip6_reset_ts_hbh_node_index
Definition: ioam_cache.h:210
unsigned int u32
Definition: types.h:88
#define HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE_ID
Definition: ioam_cache.h:266
static u8 * ioam_e2e_cache_trace_handler(u8 *s, ip6_hop_by_hop_option_t *opt)
Definition: ioam_cache.c:81
vlib_node_registration_t ioam_cache_ts_node
(constructor) VLIB_REGISTER_NODE (ioam_cache_ts_node)
ioam_cache_ts_pool_stats_t * ts_stats
Definition: ioam_cache.h:188
int ip6_hbh_unregister_option(u8 option)
Definition: ip6_forward.c:2773
vnet_crypto_main_t * cm
Definition: quic_crypto.c:41
vlib_worker_thread_t * vlib_worker_threads
Definition: threads.c:37
Definition: ioam_cache.h:125
ioam_cache_ts_entry_t ** ioam_ts_pool
Definition: ioam_cache.h:187
vlib_node_registration_t ioam_cache_node
(constructor) VLIB_REGISTER_NODE (ioam_cache_node)
static int ip6_ioam_ts_cache_cleanup_rewrite(void)
Definition: ioam_cache.h:892
struct _unformat_input_t unformat_input_t
u32 ip6_hbh_pop_node_index
Definition: ioam_cache.h:205
#define REPLY_MACRO(t)
u8 name[64]
Definition: memclnt.api:152
API main structure, used by both vpp and binary API clients.
Definition: api_common.h:203
unformat_function_t unformat_ip6_address
Definition: format.h:91
static clib_error_t * ioam_cache_init(vlib_main_t *vm)
Definition: ioam_cache.c:372
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
format_function_t format_ip6_address
Definition: format.h:93
vlib_main_t * vm
Definition: buffer.c:323
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:341
vlib_node_t * vlib_get_node_by_name(vlib_main_t *vm, u8 *name)
Definition: node.c:45
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
void ioam_cache_ts_timer_node_enable(vlib_main_t *vm, u8 enable)
static u8 * ioam_e2e_id_trace_handler(u8 *s, ip6_hop_by_hop_option_t *opt)
Definition: ioam_cache.c:65
#define foreach_ioam_cache_plugin_api_msg
Definition: ioam_cache.c:61
static int ioam_cache_ts_table_destroy(vlib_main_t *vm)
Definition: ioam_cache.h:603
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
vlib_main_t * vlib_main
Definition: ioam_cache.h:201
ioam_cache_main_t ioam_cache_main
Definition: ioam_cache.c:58
u8 * format_unformat_error(u8 *s, va_list *va)
Definition: unformat.c:91
void vlib_worker_thread_barrier_release(vlib_main_t *vm)
Definition: threads.c:1520
static void ioam_cache_table_print(vlib_main_t *vm, u8 verbose)
Definition: ioam_cache.c:304
u32 ip6_add_from_cache_hbh_node_index
Definition: ioam_cache.h:209
#define HBH_OPTION_TYPE_IOAM_E2E_CACHE_ID
Definition: ioam_cache.h:267
api_main_t api_main
Definition: api_shared.c:35
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
static clib_error_t * ioam_cache_plugin_api_hookup(vlib_main_t *vm)
Definition: ioam_cache.c:188
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
u16 vl_msg_api_get_msg_ids(const char *name, int n)
Definition: api_shared.c:957