FD.io VPP  v18.01-8-g0eacf49
Vector Packet Processing
udp_ping_node.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 #include <vnet/vnet.h>
17 #include <vlib/vlib.h>
18 #include <vlibapi/api.h>
19 #include <vlibmemory/api.h>
20 
21 #include <vnet/ip/ip.h>
22 #include <vnet/ip/ip6_hop_by_hop.h>
26 #include <ioam/udp-ping/udp_ping.h>
28 #include <vnet/srv6/sr_packet.h>
29 
30 typedef enum
31 {
40 
42 
43 uword
46 
47 extern int
50 
51 typedef struct
52 {
61 
62 /* packet trace format function */
63 static u8 *
64 format_udp_ping_trace (u8 * s, va_list * args)
65 {
66  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
67  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
68  udp_ping_trace_t *t = va_arg (*args, udp_ping_trace_t *);
69 
70  s = format (s, "udp-ping-local: src %U, dst %U, src_port %u, dst_port %u "
71  "handle %u, next_index %u, msg_type %u",
74  t->src_port, t->dst_port,
75  t->handle, t->next_index, t->msg_type);
76  return s;
77 }
78 
79 /* *INDENT-OFF* */
81 {
82  .function = udp_ping_process,
83  .type = VLIB_NODE_TYPE_PROCESS,
84  .name = "udp-ping-process",
85 };
86 /* *INDENT-ON* */
87 
88 void
90 {
91  int i;
92  ip46_udp_ping_flow *flow = NULL;
93  u16 min_interval = 0x1e9;
94 
95  for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
96  {
97  if (pool_is_free_index (udp_ping_main.ip46_flow, i))
98  continue;
99 
100  flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
101 
102  if (min_interval > flow->udp_data.interval)
103  min_interval = flow->udp_data.interval;
104  }
105 
106  if (udp_ping_main.timer_interval != min_interval)
107  {
108  udp_ping_main.timer_interval = min_interval;
109  vlib_process_signal_event (udp_ping_main.vlib_main,
110  udp_ping_node.index, EVENT_SIG_RECHECK, 0);
111  }
112 }
113 
114 void
115 ip46_udp_ping_set_flow (ip46_address_t src, ip46_address_t dst,
116  u16 start_src_port, u16 end_src_port,
117  u16 start_dst_port, u16 end_dst_port,
118  u16 interval, u8 fault_det, u8 is_disable)
119 {
120  u8 found = 0;
121  ip46_udp_ping_flow *flow = NULL;
122  int i;
123 
124  for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
125  {
126  if (pool_is_free_index (udp_ping_main.ip46_flow, i))
127  continue;
128 
129  flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
130  if ((0 == udp_ping_compare_flow (src, dst,
131  start_src_port, end_src_port,
132  start_dst_port, end_dst_port, flow)))
133  {
134  found = 1;
135  break;
136  }
137  }
138 
139  if (found)
140  {
141  u16 cur_interval;
142  if (is_disable)
143  {
144  cur_interval = flow->udp_data.interval;
146  pool_put_index (udp_ping_main.ip46_flow, i);
147  if (udp_ping_main.timer_interval == interval)
149  return;
150  }
151 
152  cur_interval = flow->udp_data.interval;
153  flow->udp_data.interval = interval;
154  if (udp_ping_main.timer_interval > interval)
155  {
156  udp_ping_main.timer_interval = interval;
157  vlib_process_signal_event (udp_ping_main.vlib_main,
158  udp_ping_node.index,
159  EVENT_SIG_RECHECK, 0);
160  }
161  else if (udp_ping_main.timer_interval == cur_interval)
163 
164  return;
165  }
166 
167  /* Delete operation and item not found */
168  if (is_disable)
169  return;
170 
171  /* Alloc new session */
172  pool_get_aligned (udp_ping_main.ip46_flow, flow, CLIB_CACHE_LINE_BYTES);
173  udp_ping_populate_flow (src, dst,
174  start_src_port, end_src_port,
175  start_dst_port, end_dst_port,
176  interval, fault_det, flow);
177 
178  udp_ping_create_rewrite (flow, (flow - udp_ping_main.ip46_flow));
179 
180  if (udp_ping_main.timer_interval > interval)
181  {
182  udp_ping_main.timer_interval = interval;
183  vlib_process_signal_event (udp_ping_main.vlib_main,
184  udp_ping_node.index, EVENT_SIG_RECHECK, 0);
185  }
186  return;
187 }
188 
189 uword
190 unformat_port_range (unformat_input_t * input, va_list * args)
191 {
192  u16 *start_port, *end_port;
193  uword c;
194  u8 colon_present = 0;
195 
196  start_port = va_arg (*args, u16 *);
197  end_port = va_arg (*args, u16 *);
198 
199  *start_port = *end_port = 0;
200  /* Get start port */
201  while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
202  {
203  switch (c)
204  {
205  case '0' ... '9':
206  *start_port = ((*start_port) * 10) + (c - '0');
207  break;
208 
209  case ':':
210  colon_present = 1;
211  break;
212 
213  default:
214  return 0;
215  }
216 
217  if (colon_present)
218  break;
219  }
220 
221  if (!colon_present)
222  return 0;
223 
224  /* Get end port */
225  while ((c = unformat_get_input (input)) != UNFORMAT_END_OF_INPUT)
226  {
227  switch (c)
228  {
229  case '0' ... '9':
230  *end_port = ((*end_port) * 10) + (c - '0');
231  break;
232 
233  default:
234  return 1;
235  }
236  }
237 
238  if (end_port < start_port)
239  return 0;
240 
241  return 1;
242 }
243 
244 static clib_error_t *
246  unformat_input_t * input, vlib_cli_command_t * cmd)
247 {
248  ip46_address_t dst, src;
249  u16 start_src_port, end_src_port;
250  u16 start_dst_port, end_dst_port;
251  u32 interval;
252  u8 is_disable = 0;
253  u8 fault_det = 0;
254 
256  {
257  if (unformat
258  (input, "src %U", unformat_ip46_address, &src, IP46_TYPE_ANY))
259  ;
260  else if (unformat (input, "src-port-range %U",
261  unformat_port_range, &start_src_port, &end_src_port))
262  ;
263  else
264  if (unformat
265  (input, "dst %U", unformat_ip46_address, &dst, IP46_TYPE_ANY))
266  ;
267  else if (unformat (input, "dst-port-range %U",
268  unformat_port_range, &start_dst_port, &end_dst_port))
269  ;
270  else if (unformat (input, "interval %d", &interval))
271  ;
272  else if (unformat (input, "fault-detect"))
273  fault_det = 1;
274  else if (unformat (input, "disable"))
275  is_disable = 1;
276  else
277  break;
278  }
279 
280  ip46_udp_ping_set_flow (src, dst, start_src_port, end_src_port,
281  start_dst_port, end_dst_port, (u16) interval,
282  fault_det, is_disable);
283 
284  return 0;
285 }
286 
287 /* *INDENT-OFF* */
288 VLIB_CLI_COMMAND (set_udp_ping_command, static) =
289 {
290  .path = "set udp-ping",
291  .short_help =
292  "set udp-ping src <local IPv6 address> src-port-range <local port range> \
293  dst <remote IPv6 address> dst-port-range <destination port range> \
294  interval <time interval in sec for which ping packet will be sent> \
295  [disable]",
296  .function = set_udp_ping_command_fn,
297 };
298 /* *INDENT-ON* */
299 
300 static clib_error_t *
302  unformat_input_t * input,
303  vlib_cli_command_t * cmd)
304 {
305  u8 *s = 0;
306  int i, j;
307  ip46_udp_ping_flow *ip46_flow;
308  u16 src_port, dst_port;
309  udp_ping_flow_data *stats;
310 
311  s = format (s, "UDP-Ping data:\n");
312 
313  for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
314  {
315  if (pool_is_free_index (udp_ping_main.ip46_flow, i))
316  continue;
317 
318  ip46_flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
319  s = format (s, "Src: %U, Dst: %U\n",
320  format_ip46_address, &ip46_flow->src, IP46_TYPE_ANY,
321  format_ip46_address, &ip46_flow->dst, IP46_TYPE_ANY);
322 
323  s = format (s, "Start src port: %u, End src port: %u\n",
324  ip46_flow->udp_data.start_src_port,
325  ip46_flow->udp_data.end_src_port);
326  s = format (s, "Start dst port: %u, End dst port: %u\n",
327  ip46_flow->udp_data.start_dst_port,
328  ip46_flow->udp_data.end_dst_port);
329  s = format (s, "Interval: %u\n", ip46_flow->udp_data.interval);
330 
331  j = 0;
332  for (src_port = ip46_flow->udp_data.start_src_port;
333  src_port <= ip46_flow->udp_data.end_src_port; src_port++)
334  {
335  for (dst_port = ip46_flow->udp_data.start_dst_port;
336  dst_port <= ip46_flow->udp_data.end_dst_port; dst_port++)
337  {
338  stats = ip46_flow->udp_data.stats + j;
339  s =
340  format (s, "\nSrc Port - %u, Dst Port - %u, Flow CTX - %u\n",
341  src_port, dst_port, stats->flow_ctx);
342  s =
343  format (s, "Path State - %s\n",
344  (stats->retry > MAX_PING_RETRIES) ? "Down" : "Up");
345  s = format (s, "Path Data:\n");
346  s = print_analyse_flow (s,
347  &ip46_flow->udp_data.
348  stats[j].analyse_data);
349  j++;
350  }
351  }
352  s = format (s, "\n\n");
353  }
354 
355  vlib_cli_output (vm, "%v", s);
356  vec_free (s);
357  return 0;
358 }
359 
360 /* *INDENT-OFF* */
361 VLIB_CLI_COMMAND (show_udp_ping_cmd, static) =
362 {
363  .path = "show udp-ping summary",
364  .short_help = "Summary of udp-ping",
365  .function = show_udp_ping_summary_cmd_fn,
366 };
367 /* *INDENT-ON* */
368 
369 /**
370  * @brief UDP-Ping Process node.
371  * @node udp-ping-process
372  *
373  * This is process node which wakes up when periodically to send
374  * out udp probe packets for all configured sessions.
375  *
376  * @param vm vlib_main_t corresponding to the current thread.
377  * @param node vlib_node_runtime_t data for this node.
378  * @param frame vlib_frame_t whose contents should be dispatched.
379  *
380  */
381 uword
384 {
385  f64 now;
386  uword *event_data = 0;
387  int i;
388  ip46_udp_ping_flow *ip46_flow;
389 
390  while (1)
391  {
392  vec_reset_length (event_data);
394  (void) vlib_process_get_events (vm, &event_data);
395  now = vlib_time_now (vm);
396 
397  for (i = 0; i < vec_len (udp_ping_main.ip46_flow); i++)
398  {
399  if (pool_is_free_index (udp_ping_main.ip46_flow, i))
400  continue;
401 
402  ip46_flow = pool_elt_at_index (udp_ping_main.ip46_flow, i);
403  if (ip46_flow->udp_data.next_send_time < now)
404  udp_ping_send_ip6_pak (udp_ping_main.vlib_main, ip46_flow);
405  }
406  }
407  return 0;
408 }
409 
410 /**
411  * @brief HopByHop analyse function for udp-ping response.
412  *
413  * Walks through all hbh options present in udp-ping response
414  * and uses analyser library for the analysis.
415  *
416  */
417 void
419  u32 flow_id,
420  u16 src_port,
421  u16 dst_port,
423  ip6_hop_by_hop_option_t * limit0, u16 len)
424 {
425  u8 type0;
426  ip46_udp_ping_flow *ip46_flow;
427  u16 flow_index;
428  ioam_analyser_data_t *data;
429  ioam_e2e_option_t *e2e;
430  ioam_trace_option_t *trace;
431 
432  /* If the packet doesnt match UDP session then return */
433  if (PREDICT_FALSE (pool_is_free_index (udp_ping_main.ip46_flow, flow_id)))
434  return;
435 
436  ip46_flow = udp_ping_main.ip46_flow + flow_id;
437  /* Check port is within range */
438  if (PREDICT_FALSE ((src_port < ip46_flow->udp_data.start_src_port) ||
439  (src_port > ip46_flow->udp_data.end_src_port) ||
440  (dst_port < ip46_flow->udp_data.start_dst_port) ||
441  (dst_port > ip46_flow->udp_data.end_dst_port)))
442  return;
443 
444  flow_index = (src_port - ip46_flow->udp_data.start_src_port) *
445  (ip46_flow->udp_data.end_dst_port - ip46_flow->udp_data.start_dst_port +
446  1);
447  flow_index += (dst_port - ip46_flow->udp_data.start_dst_port);
448  data = &(ip46_flow->udp_data.stats[flow_index].analyse_data);
449 
450  data->pkt_counter++;
451  data->bytes_counter += len;
452 
453  vnet_buffer (b0)->l2_classify.opaque_index =
454  ip46_flow->udp_data.stats[flow_index].flow_ctx;
455 
456  while (opt0 < limit0)
457  {
458  type0 = opt0->type;
459  switch (type0)
460  {
462  /* Add trace for here as it hasnt been done yet */
463  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ~0;
464  trace = (ioam_trace_option_t *) opt0;
465  if (PREDICT_FALSE
466  (trace->trace_hdr.ioam_trace_type & BIT_LOOPBACK_REPLY))
467  {
468  ip6_ioam_analyse_hbh_trace_loopback (data, &trace->trace_hdr,
469  (trace->hdr.length - 2));
470  return;
471  }
474  opt0);
475  (void) ip6_ioam_analyse_hbh_trace (data, &trace->trace_hdr, len,
476  (trace->hdr.length - 2));
477  break;
479  e2e = (ioam_e2e_option_t *) opt0;
480  (void) ip6_ioam_analyse_hbh_e2e (data, &e2e->e2e_hdr, len);
481  break;
482  case 0: /* Pad1 */
483  opt0 = (ip6_hop_by_hop_option_t *) ((u8 *) opt0) + 1;
484  continue;
485  case 1: /* PadN */
486  break;
487  default:
488  break;
489  }
490  opt0 = (ip6_hop_by_hop_option_t *) (((u8 *) opt0) + opt0->length +
491  sizeof (ip6_hop_by_hop_option_t));
492  }
493  ip46_flow->udp_data.stats[flow_index].retry = 0;
494 }
495 
496 /**
497  * @brief UDP-Ping request/response handler function.
498  *
499  * Checks udp-ping packet type - request/response and handles them.
500  * If not udp-ping packet then, strips off hbh options and enques
501  * packet to protocol registered node to enable next protocol processing.
502  *
503  */
504 void
506  ip6_header_t * ip0,
507  ip6_hop_by_hop_header_t * hbh0, u16 * next0)
508 {
509  ip6_main_t *im = &ip6_main;
510  ip_lookup_main_t *lm = &im->lookup_main;
511 
512  *next0 = UDP_PING_NEXT_IP6_DROP;
513 
514  if (PREDICT_TRUE (hbh0->protocol == IP_PROTOCOL_UDP))
515  {
517  ip6_hop_by_hop_option_t *limit0;
518  u16 p_len0;
519  udp_ping_t *udp0;
520 
521  /* Check for udp ping packet */
522  udp0 = (udp_ping_t *) ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
523  opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
524  if ((udp0->ping_data.probe_marker1 ==
525  clib_host_to_net_u32 (UDP_PING_PROBE_MARKER1)) &&
526  (udp0->ping_data.probe_marker2 ==
527  clib_host_to_net_u32 (UDP_PING_PROBE_MARKER2)))
528  {
529  if (udp0->ping_data.msg_type == UDP_PING_PROBE)
530  {
531  udp_ping_create_reply_from_probe_ip6 (ip0, hbh0, udp0);
532  /* Skip e2e processing */
533  vnet_buffer (b0)->l2_classify.opaque_index = 0x7FFFFFFF;
534  *next0 = UDP_PING_NEXT_IP6_LOOKUP;
535  return;
536  }
537 
538  /* Reply */
539  opt0 = (ip6_hop_by_hop_option_t *) (hbh0 + 1);
540  limit0 = (ip6_hop_by_hop_option_t *)
541  ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
542  p_len0 = clib_net_to_host_u16 (ip0->payload_length);
544  clib_net_to_host_u16 (udp0->
545  ping_data.sender_handle),
546  clib_net_to_host_u16 (udp0->udp.dst_port),
547  clib_net_to_host_u16 (udp0->udp.src_port),
548  opt0, limit0, p_len0);
549 
550  /* UDP Ping packet, so return */
551  return;
552  }
553  }
554 
555  /* If next header is SR, then destination may get overwritten to
556  * remote address. So pass it to SR processing as it may be local packet
557  * afterall
558  */
560  goto end;
561 
562  /* Other case remove hbh-ioam headers */
563  u64 *copy_dst0, *copy_src0;
564  u16 new_l0;
565 
566  vlib_buffer_advance (b0, (hbh0->length + 1) << 3);
567 
568  new_l0 = clib_net_to_host_u16 (ip0->payload_length) -
569  ((hbh0->length + 1) << 3);
570 
571  ip0->payload_length = clib_host_to_net_u16 (new_l0);
572 
573  ip0->protocol = hbh0->protocol;
574 
575  copy_src0 = (u64 *) ip0;
576  copy_dst0 = copy_src0 + (hbh0->length + 1);
577  copy_dst0[4] = copy_src0[4];
578  copy_dst0[3] = copy_src0[3];
579  copy_dst0[2] = copy_src0[2];
580  copy_dst0[1] = copy_src0[1];
581  copy_dst0[0] = copy_src0[0];
582 
583 end:
584  *next0 = lm->local_next_by_ip_protocol[hbh0->protocol];
585  return;
586 }
587 
588 /**
589  * @brief udp ping request/response packet receive node.
590  * @node udp-ping-local
591  *
592  * This function receives udp ping request/response packets and process them.
593  * For request packets, response is created and sent.
594  * For response packets, they are analysed and results stored.
595  *
596  * @param vm vlib_main_t corresponding to the current thread.
597  * @param node vlib_node_runtime_t data for this node.
598  * @param frame vlib_frame_t whose contents should be dispatched.
599  *
600  * @par Graph mechanics: buffer, next index usage
601  *
602  * <em>Uses:</em>
603  * - <code>udp_ping_local_analyse(p0, ip0, hbh0, &next0)</code>
604  * - Checks packet type - request/respnse and process them.
605  *
606  * <em>Next Index:</em>
607  * - Dispatches the packet to ip6-lookup/ip6-drop depending on type of packet.
608  */
609 static uword
611  vlib_node_runtime_t * node, vlib_frame_t * frame)
612 {
613  udp_ping_next_t next_index;
614  u32 *from, *to_next, n_left_from, n_left_to_next;
615 
616  from = vlib_frame_vector_args (frame);
617  n_left_from = frame->n_vectors;
618  next_index = node->cached_next_index;
619 
620  while (n_left_from > 0)
621  {
622  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
623 
624  while (n_left_from >= 4 && n_left_to_next >= 2)
625  {
626  vlib_buffer_t *p0, *p1;
627  ip6_header_t *ip0, *ip1;
628  ip6_hop_by_hop_header_t *hbh0, *hbh1;
629  u16 next0, next1;
630  u32 pi0, pi1;
631 
632  /* Prefetch next iteration. */
633  {
634  vlib_buffer_t *p2, *p3;
635 
636  p2 = vlib_get_buffer (vm, from[2]);
637  p3 = vlib_get_buffer (vm, from[3]);
638 
639  vlib_prefetch_buffer_header (p2, LOAD);
640  vlib_prefetch_buffer_header (p3, LOAD);
641 
642  /* Prefetch 3 cache lines as we need to look deep into packet */
643  CLIB_PREFETCH (p2->data, 3 * CLIB_CACHE_LINE_BYTES, STORE);
644  CLIB_PREFETCH (p3->data, 3 * CLIB_CACHE_LINE_BYTES, STORE);
645  }
646 
647  pi0 = to_next[0] = from[0];
648  pi1 = to_next[1] = from[1];
649  from += 2;
650  n_left_from -= 2;
651  to_next += 2;
652  n_left_to_next -= 2;
653 
654  p0 = vlib_get_buffer (vm, pi0);
655  p1 = vlib_get_buffer (vm, pi1);
656 
657  ip0 = vlib_buffer_get_current (p0);
658  ip1 = vlib_buffer_get_current (p1);
659 
660  hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
661  hbh1 = (ip6_hop_by_hop_header_t *) (ip1 + 1);
662 
663  udp_ping_local_analyse (p0, ip0, hbh0, &next0);
664  udp_ping_local_analyse (p1, ip1, hbh1, &next1);
665 
666  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
667  {
668  if (p0->flags & VLIB_BUFFER_IS_TRACED)
669  {
670  udp_ping_trace_t *t0 =
671  vlib_add_trace (vm, node, p0, sizeof (*t0));
672  udp_ping_t *udp0;
673 
674  /* Check for udp ping packet */
675  udp0 =
676  (udp_ping_t *) ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
677  t0->src = ip0->src_address;
678  t0->dst = ip0->dst_address;
679  t0->src_port = clib_net_to_host_u16 (udp0->udp.src_port);
680  t0->dst_port = clib_net_to_host_u16 (udp0->udp.dst_port);
681  t0->handle =
682  clib_net_to_host_u16 (udp0->ping_data.sender_handle);
683  t0->msg_type = udp0->ping_data.msg_type;
684  t0->next_index = next0;
685  }
686  if (p1->flags & VLIB_BUFFER_IS_TRACED)
687  {
688  udp_ping_trace_t *t1 =
689  vlib_add_trace (vm, node, p1, sizeof (*t1));
690  udp_ping_t *udp1;
691 
692  /* Check for udp ping packet */
693  udp1 =
694  (udp_ping_t *) ((u8 *) hbh1 + ((hbh1->length + 1) << 3));
695  t1->src = ip1->src_address;
696  t1->dst = ip1->dst_address;
697  t1->src_port = clib_net_to_host_u16 (udp1->udp.src_port);
698  t1->dst_port = clib_net_to_host_u16 (udp1->udp.dst_port);
699  t1->handle =
700  clib_net_to_host_u16 (udp1->ping_data.sender_handle);
701  t1->msg_type = udp1->ping_data.msg_type;
702  t1->next_index = next1;
703  }
704  }
705 
706  vlib_validate_buffer_enqueue_x2 (vm, node, next_index,
707  to_next, n_left_to_next,
708  pi0, pi1, next0, next1);
709  }
710 
711  while (n_left_from > 0 && n_left_to_next > 0)
712  {
713  vlib_buffer_t *p0;
714  ip6_header_t *ip0;
716  u16 next0;
717  u32 pi0;
718 
719  pi0 = from[0];
720  to_next[0] = pi0;
721  from += 1;
722  to_next += 1;
723  n_left_from -= 1;
724  n_left_to_next -= 1;
725 
726  p0 = vlib_get_buffer (vm, pi0);
727  ip0 = vlib_buffer_get_current (p0);
728  hbh0 = (ip6_hop_by_hop_header_t *) (ip0 + 1);
729 
730  udp_ping_local_analyse (p0, ip0, hbh0, &next0);
731 
732  if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE)))
733  {
734  if (p0->flags & VLIB_BUFFER_IS_TRACED)
735  {
736  udp_ping_trace_t *t0 =
737  vlib_add_trace (vm, node, p0, sizeof (*t0));
738  udp_ping_t *udp0;
739 
740  /* Check for udp ping packet */
741  udp0 =
742  (udp_ping_t *) ((u8 *) hbh0 + ((hbh0->length + 1) << 3));
743  t0->src = ip0->src_address;
744  t0->dst = ip0->dst_address;
745  t0->src_port = clib_net_to_host_u16 (udp0->udp.src_port);
746  t0->dst_port = clib_net_to_host_u16 (udp0->udp.dst_port);
747  t0->handle =
748  clib_net_to_host_u16 (udp0->ping_data.sender_handle);
749  t0->msg_type = udp0->ping_data.msg_type;
750  t0->next_index = next0;
751  }
752  }
753 
754  vlib_validate_buffer_enqueue_x1 (vm, node, next_index,
755  to_next, n_left_to_next,
756  pi0, next0);
757  }
758 
759  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
760  }
761 
762  return frame->n_vectors;
763 }
764 
765 /* *INDENT-OFF* */
766 /*
767  * Node for udp-ping-local
768  */
770 {
771  .function = udp_ping_local_node_fn,
772  .name = "udp-ping-local",
773  .vector_size = sizeof (u32),
774  .format_trace = format_udp_ping_trace,
775  .type = VLIB_NODE_TYPE_INTERNAL,
776  .n_next_nodes = UDP_PING_N_NEXT,
777  .next_nodes =
778  {
779  [UDP_PING_NEXT_DROP] = "error-drop",
780  [UDP_PING_NEXT_PUNT] = "error-punt",
781  [UDP_PING_NEXT_UDP_LOOKUP] = "ip6-udp-lookup",
782  [UDP_PING_NEXT_ICMP] = "ip6-icmp-input",
783  [UDP_PING_NEXT_IP6_LOOKUP] = "ip6-lookup",
784  [UDP_PING_NEXT_IP6_DROP] = "ip6-drop",
785  },
786 };
787 /* *INDENT-ON* */
788 
789 static clib_error_t *
791 {
792  clib_error_t *error = 0;
793 
794  udp_ping_main.vlib_main = vm;
795  udp_ping_main.vnet_main = vnet_get_main ();
796  udp_ping_main.timer_interval = 1e9;
797 
798  if ((error = vlib_call_init_function (vm, ip_main_init)))
799  return (error);
800 
801  ip6_register_protocol (IP_PROTOCOL_IP6_HOP_BY_HOP_OPTIONS,
802  udp_ping_local.index);
803  return 0;
804 }
805 
807 
808 /*
809  * fd.io coding-style-patch-verification: ON
810  *
811  * Local Variables:
812  * eval: (c-set-style "gnu")
813  * End:
814  */
udp_ping_data ping_data
udp-ping main data-structure.
Definition: udp_ping.h:102
sll srl srl sll sra u16x4 i
Definition: vector_sse2.h:337
#define CLIB_UNUSED(x)
Definition: clib.h:79
ioam_analyser_data_t analyse_data
Analysed data.
Definition: udp_ping.h:44
static int ip6_ioam_analyse_hbh_e2e(ioam_analyser_data_t *data, ioam_e2e_packet_t *e2e, u16 len)
Definition: ioam_analyse.h:415
static u8 * print_analyse_flow(u8 *s, ioam_analyser_data_t *record)
Definition: ioam_analyse.h:449
static f64 vlib_process_wait_for_event_or_clock(vlib_main_t *vm, f64 dt)
Suspend a cooperative multi-tasking thread Waits for an event, or for the indicated number of seconds...
Definition: node_funcs.h:699
void ip6_register_protocol(u32 protocol, u32 node_index)
Definition: ip6_forward.c:1656
static vlib_cli_command_t trace
(constructor) VLIB_CLI_COMMAND (trace)
Definition: memory_vlib.c:1679
#define UDP_PING_PROBE_MARKER2
ip6_address_t src
Definition: udp_ping_node.c:53
vnet_main_t * vnet_get_main(void)
Definition: misc.c:47
static vlib_node_registration_t udp_ping_local
(constructor) VLIB_REGISTER_NODE (udp_ping_local)
static uword unformat_get_input(unformat_input_t *input)
Definition: format.h:190
#define PREDICT_TRUE(x)
Definition: clib.h:106
ip46_udp_ping_flow * ip46_flow
Vector od udp-ping data.
Definition: udp_ping.h:105
u32 bytes_counter
Num of bytes matching this flow.
Definition: ioam_analyse.h:109
u16 start_dst_port
Defines start port of the dest port range.
Definition: udp_ping.h:73
#define NULL
Definition: clib.h:55
static f64 vlib_time_now(vlib_main_t *vm)
Definition: main.h:224
void udp_ping_free_flow_data(ip46_udp_ping_flow *flow)
format_function_t format_ip46_address
Definition: format.h:61
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:419
static u8 * format_udp_ping_trace(u8 *s, va_list *args)
Definition: udp_ping_node.c:64
static clib_error_t * show_udp_ping_summary_cmd_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
ip6_address_t dst
Definition: udp_ping_node.c:54
u16 interval
Interval for which ping packet to be sent.
Definition: udp_ping.h:62
udp_ping_flow udp_data
Per flow data.
Definition: udp_ping.h:94
void ip46_udp_ping_set_flow(ip46_address_t src, ip46_address_t dst, u16 start_src_port, u16 end_src_port, u16 start_dst_port, u16 end_dst_port, u16 interval, u8 fault_det, u8 is_disable)
int udp_ping_compare_flow(ip46_address_t src, ip46_address_t dst, u16 start_src_port, u16 end_src_port, u16 start_dst_port, u16 end_dst_port, ip46_udp_ping_flow *flow)
ip6_address_t src_address
Definition: ip6_packet.h:341
uword unformat_port_range(unformat_input_t *input, va_list *args)
#define vec_reset_length(v)
Reset vector length to zero NULL-pointer tolerant.
u16 end_src_port
Defines end port of the src port range.
Definition: udp_ping.h:70
#define MAX_PING_RETRIES
Definition: udp_ping.h:21
f64 next_send_time
Time at which next udp-ping probe has to be sent out.
Definition: udp_ping.h:59
vnet_main_t * vnet_main
Pointer to vnet main for convenience.
Definition: udp_ping.h:114
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:111
#define HBH_OPTION_TYPE_IOAM_EDGE_TO_EDGE
static uword vlib_process_get_events(vlib_main_t *vm, uword **data_vector)
Return the first event type which has occurred and a vector of per-event data of that type...
Definition: node_funcs.h:542
void udp_ping_send_ip6_pak(vlib_main_t *vm, ip46_udp_ping_flow *flow)
Create and send ipv6 udp-ping probe packet.
uword udp_ping_process(vlib_main_t *vm, vlib_node_runtime_t *rt, vlib_frame_t *f)
UDP-Ping Process node.
udp-ping data.
Definition: udp_ping.h:85
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:171
u32 pkt_counter
Num of pkts matching this flow.
Definition: ioam_analyse.h:106
udp_ping_next_t
Definition: udp_ping_node.c:30
unsigned long u64
Definition: types.h:89
u16 start_src_port
Defines start port of the src port range.
Definition: udp_ping.h:67
#define IPPROTO_IPV6_ROUTE
Definition: sr_packet.h:113
udp_header_t udp
void udp_ping_create_rewrite(ip46_udp_ping_flow *flow, u16 ctx)
#define vlib_call_init_function(vm, x)
Definition: init.h:162
void udp_ping_analyse_hbh(vlib_buffer_t *b0, u32 flow_id, u16 src_port, u16 dst_port, ip6_hop_by_hop_option_t *opt0, ip6_hop_by_hop_option_t *limit0, u16 len)
HopByHop analyse function for udp-ping response.
static uword udp_ping_local_node_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *frame)
udp ping request/response packet receive node.
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:459
static void vlib_process_signal_event(vlib_main_t *vm, uword node_index, uword type_opaque, uword data)
Definition: node_funcs.h:950
struct _unformat_input_t unformat_input_t
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:195
ip46_address_t dst
Remote destination IPv4/6 address to be used.
Definition: udp_ping.h:91
#define PREDICT_FALSE(x)
Definition: clib.h:105
u8 local_next_by_ip_protocol[256]
Table mapping ip protocol to ip[46]-local node next index.
Definition: lookup.h:150
#define vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, next0, next1)
Finish enqueueing two buffers forward in the graph.
Definition: buffer_node.h:70
#define vlib_validate_buffer_enqueue_x1(vm, node, next_index, to_next, n_left_to_next, bi0, next0)
Finish enqueueing one buffer forward in the graph.
Definition: buffer_node.h:218
#define vlib_get_next_frame(vm, node, next_index, vectors, n_vectors_left)
Get pointer to next frame vector data by (vlib_node_runtime_t, next_index).
Definition: node_funcs.h:364
#define pool_get_aligned(P, E, A)
Allocate an object E from a pool P (general version).
Definition: pool.h:188
u32 flow_ctx
This is used by ioam e2e for identifying flow and add seq number.
Definition: udp_ping.h:47
clib_error_t * ip_main_init(vlib_main_t *vm)
Definition: ip_init.c:45
#define UNFORMAT_END_OF_INPUT
Definition: format.h:143
svmdb_client_t * c
u16 n_vectors
Definition: node.h:344
format_function_t format_ip6_address
Definition: format.h:95
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:82
vlib_main_t * vm
Definition: buffer.c:283
void udp_ping_populate_flow(ip46_address_t src, ip46_address_t dst, u16 start_src_port, u16 end_src_port, u16 start_dst_port, u16 end_dst_port, u16 interval, u8 fault_det, ip46_udp_ping_flow *flow)
#define vec_free(V)
Free vector&#39;s memory (no header).
Definition: vec.h:336
#define VLIB_BUFFER_IS_TRACED
Definition: buffer.h:93
static void udp_ping_create_reply_from_probe_ip6(ip6_header_t *ip, ip6_hop_by_hop_header_t *hbh, udp_ping_t *udp)
Create and send ipv6 udp-ping response packet.
Definition: udp_ping_util.h:48
#define pool_is_free_index(P, I)
Use free bitmap to query whether given index is free.
Definition: pool.h:268
void vlib_put_next_frame(vlib_main_t *vm, vlib_node_runtime_t *r, u32 next_index, u32 n_vectors_left)
Release pointer to next frame vector data.
Definition: main.c:454
#define UDP_PING_PROBE
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:154
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:456
u16 end_dst_port
Defines end port of the dest port range.
Definition: udp_ping.h:76
static clib_error_t * set_udp_ping_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
#define pool_put_index(p, i)
Free pool element with given index.
Definition: pool.h:294
unsigned int u32
Definition: types.h:88
vlib_main_t * vlib_main
Pointer to VLib main for the node - ipfix-collector.
Definition: udp_ping.h:111
ip6_main_t ip6_main
Definition: ip6_forward.c:3009
ip_lookup_main_t lookup_main
Definition: ip6.h:158
void udp_ping_local_analyse(vlib_buffer_t *b0, ip6_header_t *ip0, ip6_hop_by_hop_header_t *hbh0, u16 *next0)
UDP-Ping request/response handler function.
u64 timer_interval
Stores the time interval at which process node has to wake up.
Definition: udp_ping.h:108
udp-ping session data.
Definition: udp_ping.h:28
ip46_address_t src
Local source IPv4/6 address to be used.
Definition: udp_ping.h:88
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:208
#define VLIB_NODE_FLAG_TRACE
Definition: node.h:259
#define BIT_LOOPBACK_REPLY
Definition: trace_util.h:95
#define HBH_OPTION_TYPE_IOAM_TRACE_DATA_LIST
unformat_function_t unformat_ip46_address
Definition: format.h:71
u64 uword
Definition: types.h:112
static void * vlib_add_trace(vlib_main_t *vm, vlib_node_runtime_t *r, vlib_buffer_t *b, u32 n_data_bytes)
Definition: trace_funcs.h:55
Definition: defs.h:47
unsigned short u16
Definition: types.h:57
u16 payload_length
Definition: ip6_packet.h:332
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
double f64
Definition: types.h:142
unsigned char u8
Definition: types.h:56
Analysed iOAM data.
Definition: ioam_analyse.h:97
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:267
static int ip6_ioam_analyse_hbh_trace(ioam_analyser_data_t *data, ioam_trace_hdr_t *trace, u16 pak_len, u16 trace_len)
Definition: ioam_analyse.h:282
static clib_error_t * udp_ping_init(vlib_main_t *vm)
void udp_ping_calculate_timer_interval(void)
Definition: udp_ping_node.c:89
udp_ping_main_t udp_ping_main
Definition: udp_ping_node.c:41
#define vnet_buffer(b)
Definition: buffer.h:326
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:143
u8 data[0]
Packet data.
Definition: buffer.h:159
u16 retry
Number of times ping response was dropped.
Definition: udp_ping.h:39
u16 flags
Copy of main node flags.
Definition: node.h:450
udp_ping_flow_data * stats
Ping statistics.
Definition: udp_ping.h:79
static void ip6_ioam_analyse_hbh_trace_loopback(ioam_analyser_data_t *data, ioam_trace_hdr_t *trace, u16 trace_len)
Definition: ioam_analyse.h:213
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:67
#define EVENT_SIG_RECHECK
Definition: udp_ping.h:23
u32 flags
buffer flags: VLIB_BUFFER_FREE_LIST_INDEX_MASK: bits used to store free list index, VLIB_BUFFER_IS_TRACED: trace this buffer.
Definition: buffer.h:75
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:680
#define UDP_PING_PROBE_MARKER1
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:57
static vlib_node_registration_t udp_ping_node
(constructor) VLIB_REGISTER_NODE (udp_ping_node)
Definition: udp_ping_node.c:80
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:972
int ip6_hbh_ioam_trace_data_list_handler(vlib_buffer_t *b, ip6_header_t *ip, ip6_hop_by_hop_option_t *opt)
ip6_address_t dst_address
Definition: ip6_packet.h:341
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:169