FD.io VPP  v19.08.3-2-gbabecb413
Vector Packet Processing
sr_localsid.c
Go to the documentation of this file.
1 /*
2  * sr_localsid.c: ipv6 segment routing Endpoint behaviors
3  *
4  * Copyright (c) 2016 Cisco and/or its affiliates.
5  * Licensed under the Apache License, Version 2.0 (the "License");
6  * you may not use this file except in compliance with the License.
7  * You may obtain a copy of the License at:
8  *
9  * http://www.apache.org/licenses/LICENSE-2.0
10  *
11  * Unless required by applicable law or agreed to in writing, software
12  * distributed under the License is distributed on an "AS IS" BASIS,
13  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14  * See the License for the specific language governing permissions and
15  * limitations under the License.
16  */
17 
18 /**
19  * @file
20  * @brief Processing of packets with a SRH
21  *
22  * CLI to define new Segment Routing End processing functions.
23  * Graph node to support such functions.
24  *
25  * Each function associates an SRv6 segment (IPv6 address) with an specific
26  * Segment Routing function.
27  *
28  */
29 
30 #include <vlib/vlib.h>
31 #include <vnet/vnet.h>
32 #include <vnet/srv6/sr.h>
33 #include <vnet/ip/ip.h>
34 #include <vnet/srv6/sr_packet.h>
35 #include <vnet/ip/ip6_packet.h>
36 #include <vnet/fib/ip6_fib.h>
37 #include <vnet/dpo/dpo.h>
38 #include <vnet/adj/adj.h>
39 
40 #include <vppinfra/error.h>
41 #include <vppinfra/elog.h>
42 
43 /**
44  * @brief Dynamically added SR localsid DPO type
45  */
48 
49 /**
50  * @brief SR localsid add/del
51  *
52  * Function to add or delete SR LocalSIDs.
53  *
54  * @param is_del Boolean of whether its a delete instruction
55  * @param localsid_addr IPv6 address of the localsid
56  * @param is_decap Boolean of whether decapsulation is allowed in this function
57  * @param behavior Type of behavior (function) for this localsid
58  * @param sw_if_index Only for L2/L3 xconnect. OIF. In VRF variant the fib_table.
59  * @param vlan_index Only for L2 xconnect. Outgoing VLAN tag.
60  * @param fib_table FIB table in which we should install the localsid entry
61  * @param nh_addr Next Hop IPv4/IPv6 address. Only for L2/L3 xconnect.
62  *
63  * @return 0 on success, error otherwise.
64  */
65 int
66 sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
67  char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index,
68  u32 fib_table, ip46_address_t * nh_addr, void *ls_plugin_mem)
69 {
70  ip6_sr_main_t *sm = &sr_main;
71  uword *p;
72  int rv;
73 
74  ip6_sr_localsid_t *ls = 0;
75 
76  dpo_id_t dpo = DPO_INVALID;
77 
78  /* Search for the item */
79  p = mhash_get (&sm->sr_localsids_index_hash, localsid_addr);
80 
81  if (p)
82  {
83  if (is_del)
84  {
85  /* Retrieve localsid */
86  ls = pool_elt_at_index (sm->localsids, p[0]);
87  /* Delete FIB entry */
88  fib_prefix_t pfx = {
90  .fp_len = 128,
91  .fp_addr = {
92  .ip6 = *localsid_addr,
93  }
94  };
95 
97  fib_table),
98  &pfx, FIB_SOURCE_SR);
99 
100  /* In case it is a Xconnect iface remove the (OIF, NHOP) adj */
101  if (ls->behavior == SR_BEHAVIOR_X || ls->behavior == SR_BEHAVIOR_DX6
102  || ls->behavior == SR_BEHAVIOR_DX4)
103  adj_unlock (ls->nh_adj);
104 
105  if (ls->behavior >= SR_BEHAVIOR_LAST)
106  {
107  sr_localsid_fn_registration_t *plugin = 0;
108  plugin = pool_elt_at_index (sm->plugin_functions,
109  ls->behavior - SR_BEHAVIOR_LAST);
110 
111  /* Callback plugin removal function */
112  rv = plugin->removal (ls);
113  }
114 
115  /* Delete localsid registry */
116  pool_put (sm->localsids, ls);
117  mhash_unset (&sm->sr_localsids_index_hash, localsid_addr, NULL);
118  return 0;
119  }
120  else /* create with function already existing; complain */
121  return -1;
122  }
123  else
124  /* delete; localsid does not exist; complain */
125  if (is_del)
126  return -2;
127 
128  /* Check whether there exists a FIB entry with such address */
129  fib_prefix_t pfx = {
131  .fp_len = 128,
132  };
133 
134  pfx.fp_addr.as_u64[0] = localsid_addr->as_u64[0];
135  pfx.fp_addr.as_u64[1] = localsid_addr->as_u64[1];
136 
137  /* Lookup the FIB index associated to the table id provided */
138  u32 fib_index = fib_table_find (FIB_PROTOCOL_IP6, fib_table);
139  if (fib_index == ~0)
140  return -3;
141 
142  /* Lookup the localsid in such FIB table */
143  fib_node_index_t fei = fib_table_lookup_exact_match (fib_index, &pfx);
144  if (FIB_NODE_INDEX_INVALID != fei)
145  return -4; //There is an entry for such address (the localsid addr)
146 
147  /* Create a new localsid registry */
148  pool_get (sm->localsids, ls);
149  clib_memset (ls, 0, sizeof (*ls));
150 
151  clib_memcpy (&ls->localsid, localsid_addr, sizeof (ip6_address_t));
152  ls->end_psp = end_psp;
153  ls->behavior = behavior;
154  ls->nh_adj = (u32) ~ 0;
155  ls->fib_table = fib_table;
156  switch (behavior)
157  {
158  case SR_BEHAVIOR_END:
159  break;
160  case SR_BEHAVIOR_X:
161  ls->sw_if_index = sw_if_index;
162  clib_memcpy (&ls->next_hop.ip6, &nh_addr->ip6, sizeof (ip6_address_t));
163  break;
164  case SR_BEHAVIOR_T:
165  ls->vrf_index = fib_table_find (FIB_PROTOCOL_IP6, sw_if_index);
166  break;
167  case SR_BEHAVIOR_DX4:
168  ls->sw_if_index = sw_if_index;
169  clib_memcpy (&ls->next_hop.ip4, &nh_addr->ip4, sizeof (ip4_address_t));
170  break;
171  case SR_BEHAVIOR_DX6:
172  ls->sw_if_index = sw_if_index;
173  clib_memcpy (&ls->next_hop.ip6, &nh_addr->ip6, sizeof (ip6_address_t));
174  break;
175  case SR_BEHAVIOR_DT6:
176  ls->vrf_index = fib_table_find (FIB_PROTOCOL_IP6, sw_if_index);
177  break;
178  case SR_BEHAVIOR_DT4:
179  ls->vrf_index = fib_table_find (FIB_PROTOCOL_IP4, sw_if_index);
180  break;
181  case SR_BEHAVIOR_DX2:
182  ls->sw_if_index = sw_if_index;
183  ls->vlan_index = vlan_index;
184  break;
185  }
186 
187  /* Figure out the adjacency magic for Xconnect variants */
188  if (ls->behavior == SR_BEHAVIOR_X || ls->behavior == SR_BEHAVIOR_DX4
189  || ls->behavior == SR_BEHAVIOR_DX6)
190  {
191  adj_index_t nh_adj_index = ADJ_INDEX_INVALID;
192 
193  /* Retrieve the adjacency corresponding to the (OIF, next_hop) */
194  if (ls->behavior == SR_BEHAVIOR_DX6 || ls->behavior == SR_BEHAVIOR_X)
196  nh_addr, sw_if_index);
197 
198  else if (ls->behavior == SR_BEHAVIOR_DX4)
200  nh_addr, sw_if_index);
201 
202  /* Check for ADJ creation error. If so panic */
203  if (nh_adj_index == ADJ_INDEX_INVALID)
204  {
205  pool_put (sm->localsids, ls);
206  return -5;
207  }
208 
209  ls->nh_adj = nh_adj_index;
210  }
211 
212  /* Set DPO */
213  if (ls->behavior == SR_BEHAVIOR_END || ls->behavior == SR_BEHAVIOR_X
214  || ls->behavior == SR_BEHAVIOR_T)
216  else if (ls->behavior > SR_BEHAVIOR_D_FIRST
217  && ls->behavior < SR_BEHAVIOR_LAST)
219  else if (ls->behavior >= SR_BEHAVIOR_LAST)
220  {
221  sr_localsid_fn_registration_t *plugin = 0;
222  plugin = pool_elt_at_index (sm->plugin_functions,
223  ls->behavior - SR_BEHAVIOR_LAST);
224  /* Copy the unformat memory result */
225  ls->plugin_mem = ls_plugin_mem;
226  /* Callback plugin creation function */
227  rv = plugin->creation (ls);
228  if (rv)
229  {
230  pool_put (sm->localsids, ls);
231  return -6;
232  }
233  dpo_set (&dpo, plugin->dpo, DPO_PROTO_IP6, ls - sm->localsids);
234  }
235 
236  /* Set hash key for searching localsid by address */
237  mhash_set (&sm->sr_localsids_index_hash, localsid_addr, ls - sm->localsids,
238  NULL);
239 
242  dpo_reset (&dpo);
243 
244  /* Set counter to zero */
246  ls - sm->localsids);
248  ls - sm->localsids);
249 
251  ls - sm->localsids);
253  ls - sm->localsids);
254 
255  return 0;
256 }
257 
258 /**
259  * @brief SR LocalSID CLI function.
260  *
261  * @see sr_cli_localsid
262  */
263 static clib_error_t *
265  vlib_cli_command_t * cmd)
266 {
267  vnet_main_t *vnm = vnet_get_main ();
268  ip6_sr_main_t *sm = &sr_main;
269  u32 sw_if_index = (u32) ~ 0, vlan_index = (u32) ~ 0, fib_index = 0;
270  int is_del = 0;
271  int end_psp = 0;
272  ip6_address_t resulting_address;
273  ip46_address_t next_hop;
274  char address_set = 0;
275  char behavior = 0;
276  void *ls_plugin_mem = 0;
277 
278  int rv;
279 
280  clib_memset (&resulting_address, 0, sizeof (ip6_address_t));
281  ip46_address_reset (&next_hop);
282 
284  {
285  if (unformat (input, "del"))
286  is_del = 1;
287  else if (!address_set
288  && unformat (input, "address %U", unformat_ip6_address,
289  &resulting_address))
290  address_set = 1;
291  else if (!address_set
292  && unformat (input, "addr %U", unformat_ip6_address,
293  &resulting_address))
294  address_set = 1;
295  else if (unformat (input, "fib-table %u", &fib_index));
296  else if (vlan_index == (u32) ~ 0
297  && unformat (input, "vlan %u", &vlan_index));
298  else if (!behavior && unformat (input, "behavior"))
299  {
300  if (unformat (input, "end.x %U %U",
301  unformat_vnet_sw_interface, vnm, &sw_if_index,
302  unformat_ip6_address, &next_hop.ip6))
303  behavior = SR_BEHAVIOR_X;
304  else if (unformat (input, "end.t %u", &sw_if_index))
305  behavior = SR_BEHAVIOR_T;
306  else if (unformat (input, "end.dx6 %U %U",
307  unformat_vnet_sw_interface, vnm, &sw_if_index,
308  unformat_ip6_address, &next_hop.ip6))
309  behavior = SR_BEHAVIOR_DX6;
310  else if (unformat (input, "end.dx4 %U %U",
311  unformat_vnet_sw_interface, vnm, &sw_if_index,
312  unformat_ip4_address, &next_hop.ip4))
313  behavior = SR_BEHAVIOR_DX4;
314  else if (unformat (input, "end.dx2 %U",
315  unformat_vnet_sw_interface, vnm, &sw_if_index))
316  behavior = SR_BEHAVIOR_DX2;
317  else if (unformat (input, "end.dt6 %u", &sw_if_index))
318  behavior = SR_BEHAVIOR_DT6;
319  else if (unformat (input, "end.dt4 %u", &sw_if_index))
320  behavior = SR_BEHAVIOR_DT4;
321  else
322  {
323  /* Loop over all the plugin behavior format functions */
324  sr_localsid_fn_registration_t *plugin = 0, **vec_plugins = 0;
325  sr_localsid_fn_registration_t **plugin_it = 0;
326 
327  /* Create a vector out of the plugin pool as recommended */
328  /* *INDENT-OFF* */
329  pool_foreach (plugin, sm->plugin_functions,
330  {
331  vec_add1 (vec_plugins, plugin);
332  });
333  /* *INDENT-ON* */
334 
335  vec_foreach (plugin_it, vec_plugins)
336  {
337  if (unformat
338  (input, "%U", (*plugin_it)->ls_unformat, &ls_plugin_mem))
339  {
340  behavior = (*plugin_it)->sr_localsid_function_number;
341  break;
342  }
343  }
344  }
345 
346  if (!behavior)
347  {
348  if (unformat (input, "end"))
349  behavior = SR_BEHAVIOR_END;
350  else
351  break;
352  }
353  }
354  else if (!end_psp && unformat (input, "psp"))
355  end_psp = 1;
356  else
357  break;
358  }
359 
360  if (!behavior && end_psp)
361  behavior = SR_BEHAVIOR_END;
362 
363  if (!address_set)
364  return clib_error_return (0,
365  "Error: SRv6 LocalSID address is mandatory.");
366  if (!is_del && !behavior)
367  return clib_error_return (0,
368  "Error: SRv6 LocalSID behavior is mandatory.");
369  if (vlan_index != (u32) ~ 0)
370  return clib_error_return (0,
371  "Error: SRv6 End.DX2 with rewrite VLAN tag not supported by now.");
372  if (end_psp && !(behavior == SR_BEHAVIOR_END || behavior == SR_BEHAVIOR_X))
373  return clib_error_return (0,
374  "Error: SRv6 PSP only compatible with End and End.X");
375 
376  rv = sr_cli_localsid (is_del, &resulting_address, end_psp, behavior,
377  sw_if_index, vlan_index, fib_index, &next_hop,
378  ls_plugin_mem);
379 
380  switch (rv)
381  {
382  case 0:
383  break;
384  case 1:
385  return 0;
386  case -1:
387  return clib_error_return (0,
388  "Identical localsid already exists. Requested localsid not created.");
389  case -2:
390  return clib_error_return (0,
391  "The requested localsid could not be deleted. SR localsid not found");
392  case -3:
393  return clib_error_return (0, "FIB table %u does not exist", fib_index);
394  case -4:
395  return clib_error_return (0, "There is already one FIB entry for the"
396  "requested localsid non segment routing related");
397  case -5:
398  return clib_error_return (0,
399  "Could not create ARP/ND entry for such next_hop. Internal error.");
400  case -6:
401  return clib_error_return (0,
402  "Error on the plugin based localsid creation.");
403  default:
404  return clib_error_return (0, "BUG: sr localsid returns %d", rv);
405  }
406  return 0;
407 }
408 
409 /* *INDENT-OFF* */
410 VLIB_CLI_COMMAND (sr_localsid_command, static) = {
411  .path = "sr localsid",
412  .short_help = "sr localsid (del) address XX:XX::YY:YY"
413  "(fib-table 8) behavior STRING",
414  .long_help =
415  "Create SR LocalSID and binds it to a particular behavior\n"
416  "Arguments:\n"
417  "\tlocalSID IPv6_addr(128b) LocalSID IPv6 address\n"
418  "\t(fib-table X) Optional. VRF where to install SRv6 localsid\n"
419  "\tbehavior STRING Specifies the behavior\n"
420  "\n\tBehaviors:\n"
421  "\tEnd\t-> Endpoint.\n"
422  "\tEnd.X\t-> Endpoint with decapsulation and Layer-3 cross-connect.\n"
423  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
424  "\tEnd.DX2\t-> Endpoint with decapsulation and Layer-2 cross-connect.\n"
425  "\t\tParameters: '<iface>'\n"
426  "\tEnd.DX6\t-> Endpoint with decapsulation and IPv6 cross-connect.\n"
427  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
428  "\tEnd.DX4\t-> Endpoint with decapsulation and IPv4 cross-connect.\n"
429  "\t\tParameters: '<iface> <ip4_next_hop>'\n"
430  "\tEnd.DT6\t-> Endpoint with decapsulation and specific IPv6 table lookup.\n"
431  "\t\tParameters: '<ip6_fib_table>'\n"
432  "\tEnd.DT4\t-> Endpoint with decapsulation and specific IPv4 table lookup.\n"
433  "\t\tParameters: '<ip4_fib_table>'\n",
434  .function = sr_cli_localsid_command_fn,
435 };
436 /* *INDENT-ON* */
437 
438 /**
439  * @brief CLI function to 'show' all SR LocalSIDs on console.
440  */
441 static clib_error_t *
443  vlib_cli_command_t * cmd)
444 {
445  vnet_main_t *vnm = vnet_get_main ();
446  ip6_sr_main_t *sm = &sr_main;
447  ip6_sr_localsid_t **localsid_list = 0;
448  ip6_sr_localsid_t *ls;
449  int i;
450 
451  vlib_cli_output (vm, "SRv6 - My LocalSID Table:");
452  vlib_cli_output (vm, "=========================");
453  /* *INDENT-OFF* */
454  pool_foreach (ls, sm->localsids, ({ vec_add1 (localsid_list, ls); }));
455  /* *INDENT-ON* */
456  for (i = 0; i < vec_len (localsid_list); i++)
457  {
458  ls = localsid_list[i];
459  switch (ls->behavior)
460  {
461  case SR_BEHAVIOR_END:
462  vlib_cli_output (vm, "\tAddress: \t%U\n\tBehavior: \tEnd",
464  break;
465  case SR_BEHAVIOR_X:
466  vlib_cli_output (vm,
467  "\tAddress: \t%U\n\tBehavior: \tX (Endpoint with Layer-3 cross-connect)"
468  "\n\tIface: \t%U\n\tNext hop: \t%U",
471  format_ip6_address, &ls->next_hop.ip6);
472  break;
473  case SR_BEHAVIOR_T:
474  vlib_cli_output (vm,
475  "\tAddress: \t%U\n\tBehavior: \tT (Endpoint with specific IPv6 table lookup)"
476  "\n\tTable: \t%u",
480  break;
481  case SR_BEHAVIOR_DX4:
482  vlib_cli_output (vm,
483  "\tAddress: \t%U\n\tBehavior: \tDX4 (Endpoint with decapsulation and IPv4 cross-connect)"
484  "\n\tIface: \t%U\n\tNext hop: \t%U",
487  format_ip4_address, &ls->next_hop.ip4);
488  break;
489  case SR_BEHAVIOR_DX6:
490  vlib_cli_output (vm,
491  "\tAddress: \t%U\n\tBehavior: \tDX6 (Endpoint with decapsulation and IPv6 cross-connect)"
492  "\n\tIface: \t%U\n\tNext hop: \t%U",
495  format_ip6_address, &ls->next_hop.ip6);
496  break;
497  case SR_BEHAVIOR_DX2:
498  if (ls->vlan_index == (u32) ~ 0)
499  vlib_cli_output (vm,
500  "\tAddress: \t%U\n\tBehavior: \tDX2 (Endpoint with decapulation and Layer-2 cross-connect)"
501  "\n\tIface: \t%U", format_ip6_address,
503  ls->sw_if_index);
504  else
505  vlib_cli_output (vm,
506  "Unsupported yet. (DX2 with egress VLAN rewrite)");
507  break;
508  case SR_BEHAVIOR_DT6:
509  vlib_cli_output (vm,
510  "\tAddress: \t%U\n\tBehavior: \tDT6 (Endpoint with decapsulation and specific IPv6 table lookup)"
511  "\n\tTable: %u", format_ip6_address, &ls->localsid,
514  break;
515  case SR_BEHAVIOR_DT4:
516  vlib_cli_output (vm,
517  "\tAddress: \t%U\n\tBehavior: \tDT4 (Endpoint with decapsulation and specific IPv4 table lookup)"
518  "\n\tTable: \t%u", format_ip6_address,
519  &ls->localsid,
522  break;
523  default:
524  if (ls->behavior >= SR_BEHAVIOR_LAST)
525  {
528  ls->behavior - SR_BEHAVIOR_LAST);
529 
530  vlib_cli_output (vm, "\tAddress: \t%U\n"
531  "\tBehavior: \t%s (%s)\n\t%U",
533  plugin->keyword_str, plugin->def_str,
534  plugin->ls_format, ls->plugin_mem);
535  }
536  else
537  //Should never get here...
538  vlib_cli_output (vm, "Internal error");
539  break;
540  }
541  if (ls->end_psp)
542  vlib_cli_output (vm, "\tPSP: \tTrue\n");
543 
544  /* Print counters */
545  vlib_counter_t valid, invalid;
548  vlib_cli_output (vm, "\tGood traffic: \t[%Ld packets : %Ld bytes]\n",
549  valid.packets, valid.bytes);
550  vlib_cli_output (vm, "\tBad traffic: \t[%Ld packets : %Ld bytes]\n",
551  invalid.packets, invalid.bytes);
552  vlib_cli_output (vm, "--------------------");
553  }
554  return 0;
555 }
556 
557 /* *INDENT-OFF* */
558 VLIB_CLI_COMMAND (show_sr_localsid_command, static) = {
559  .path = "show sr localsids",
560  .short_help = "show sr localsids",
561  .function = show_sr_localsid_command_fn,
562 };
563 /* *INDENT-ON* */
564 
565 /**
566  * @brief Function to 'clear' ALL SR localsid counters
567  */
568 static clib_error_t *
570  unformat_input_t * input,
571  vlib_cli_command_t * cmd)
572 {
573  ip6_sr_main_t *sm = &sr_main;
574 
577 
578  return 0;
579 }
580 
581 /* *INDENT-OFF* */
582 VLIB_CLI_COMMAND (clear_sr_localsid_counters_command, static) = {
583  .path = "clear sr localsid-counters",
584  .short_help = "clear sr localsid-counters",
586 };
587 /* *INDENT-ON* */
588 
589 /************************ SR LocalSID graphs node ****************************/
590 /**
591  * @brief SR localsid node trace
592  */
593 typedef struct
594 {
597  u8 sr[256];
601 
602 #define foreach_sr_localsid_error \
603 _(NO_INNER_HEADER, "(SR-Error) No inner IP header") \
604 _(NO_MORE_SEGMENTS, "(SR-Error) No more segments") \
605 _(NO_SRH, "(SR-Error) No SR header") \
606 _(NO_PSP, "(SR-Error) PSP Not available (segments left > 0)") \
607 _(NOT_LS, "(SR-Error) Decaps not available (segments left > 0)") \
608 _(L2, "(SR-Error) SRv6 decapsulated a L2 frame without dest")
609 
610 typedef enum
611 {
612 #define _(sym,str) SR_LOCALSID_ERROR_##sym,
614 #undef _
617 
618 static char *sr_localsid_error_strings[] = {
619 #define _(sym,string) string,
621 #undef _
622 };
623 
624 #define foreach_sr_localsid_next \
625 _(ERROR, "error-drop") \
626 _(IP6_LOOKUP, "ip6-lookup") \
627 _(IP4_LOOKUP, "ip4-lookup") \
628 _(IP6_REWRITE, "ip6-rewrite") \
629 _(IP4_REWRITE, "ip4-rewrite") \
630 _(INTERFACE_OUTPUT, "interface-output")
631 
632 typedef enum
633 {
634 #define _(s,n) SR_LOCALSID_NEXT_##s,
636 #undef _
639 
640 /**
641  * @brief SR LocalSID graph node trace function
642  *
643  * @see sr_localsid
644  */
645 u8 *
646 format_sr_localsid_trace (u8 * s, va_list * args)
647 {
648  CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
649  CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
650  sr_localsid_trace_t *t = va_arg (*args, sr_localsid_trace_t *);
651 
652  s =
653  format (s, "SR-LOCALSID:\n\tLocalsid: %U\n", format_ip6_address,
654  &t->localsid);
655  switch (t->behavior)
656  {
657  case SR_BEHAVIOR_END:
658  s = format (s, "\tBehavior: End\n");
659  break;
660  case SR_BEHAVIOR_DX6:
661  s = format (s, "\tBehavior: Decapsulation with IPv6 L3 xconnect\n");
662  break;
663  case SR_BEHAVIOR_DX4:
664  s = format (s, "\tBehavior: Decapsulation with IPv4 L3 xconnect\n");
665  break;
666  case SR_BEHAVIOR_X:
667  s = format (s, "\tBehavior: IPv6 L3 xconnect\n");
668  break;
669  case SR_BEHAVIOR_T:
670  s = format (s, "\tBehavior: IPv6 specific table lookup\n");
671  break;
672  case SR_BEHAVIOR_DT6:
673  s = format (s, "\tBehavior: Decapsulation with IPv6 Table lookup\n");
674  break;
675  case SR_BEHAVIOR_DT4:
676  s = format (s, "\tBehavior: Decapsulation with IPv4 Table lookup\n");
677  break;
678  case SR_BEHAVIOR_DX2:
679  s = format (s, "\tBehavior: Decapsulation with L2 xconnect\n");
680  break;
681  default:
682  s = format (s, "\tBehavior: defined in plugin\n"); //TODO
683  break;
684  }
685  if (t->num_segments != 0xFF)
686  {
687  if (t->num_segments > 0)
688  {
689  s = format (s, "\tSegments left: %d\n", t->segments_left);
690  s = format (s, "\tSID list: [in ietf order]");
691  int i = 0;
692  for (i = 0; i < t->num_segments; i++)
693  {
694  s = format (s, "\n\t-> %U", format_ip6_address,
695  (ip6_address_t *) & t->sr[i *
696  sizeof (ip6_address_t)]);
697  }
698  }
699  }
700  return s;
701 }
702 
703 /**
704  * @brief Function doing End processing.
705  */
708  vlib_buffer_t * b0,
709  ip6_header_t * ip0,
710  ip6_sr_header_t * sr0,
711  ip6_sr_localsid_t * ls0,
712  u32 * next0, u8 psp, ip6_ext_header_t * prev0)
713 {
714  ip6_address_t *new_dst0;
715 
716  if (PREDICT_TRUE (sr0 && sr0->type == ROUTING_HEADER_TYPE_SR))
717  {
718  if (sr0->segments_left == 1 && psp)
719  {
720  u32 new_l0, sr_len;
721  u64 *copy_dst0, *copy_src0;
722  u32 copy_len_u64s0 = 0;
723 
724  ip0->dst_address.as_u64[0] = sr0->segments->as_u64[0];
725  ip0->dst_address.as_u64[1] = sr0->segments->as_u64[1];
726 
727  /* Remove the SRH taking care of the rest of IPv6 ext header */
728  if (prev0)
729  prev0->next_hdr = sr0->protocol;
730  else
731  ip0->protocol = sr0->protocol;
732 
733  sr_len = ip6_ext_header_len (sr0);
734  vlib_buffer_advance (b0, sr_len);
735  new_l0 = clib_net_to_host_u16 (ip0->payload_length) - sr_len;
736  ip0->payload_length = clib_host_to_net_u16 (new_l0);
737  copy_src0 = (u64 *) ip0;
738  copy_dst0 = copy_src0 + (sr0->length + 1);
739  /* number of 8 octet units to copy
740  * By default in absence of extension headers it is equal to length of ip6 header
741  * With extension headers it number of 8 octet units of ext headers preceding
742  * SR header
743  */
744  copy_len_u64s0 =
745  (((u8 *) sr0 - (u8 *) ip0) - sizeof (ip6_header_t)) >> 3;
746  copy_dst0[4 + copy_len_u64s0] = copy_src0[4 + copy_len_u64s0];
747  copy_dst0[3 + copy_len_u64s0] = copy_src0[3 + copy_len_u64s0];
748  copy_dst0[2 + copy_len_u64s0] = copy_src0[2 + copy_len_u64s0];
749  copy_dst0[1 + copy_len_u64s0] = copy_src0[1 + copy_len_u64s0];
750  copy_dst0[0 + copy_len_u64s0] = copy_src0[0 + copy_len_u64s0];
751 
752  int i;
753  for (i = copy_len_u64s0 - 1; i >= 0; i--)
754  {
755  copy_dst0[i] = copy_src0[i];
756  }
757 
758  if (ls0->behavior == SR_BEHAVIOR_X)
759  {
760  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
761  *next0 = SR_LOCALSID_NEXT_IP6_REWRITE;
762  }
763  else if (ls0->behavior == SR_BEHAVIOR_T)
764  {
765  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index;
766  }
767  }
768  else if (PREDICT_TRUE (sr0->segments_left > 0))
769  {
770  sr0->segments_left -= 1;
771  new_dst0 = (ip6_address_t *) (sr0->segments);
772  new_dst0 += sr0->segments_left;
773  ip0->dst_address.as_u64[0] = new_dst0->as_u64[0];
774  ip0->dst_address.as_u64[1] = new_dst0->as_u64[1];
775 
776  if (ls0->behavior == SR_BEHAVIOR_X)
777  {
778  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
779  *next0 = SR_LOCALSID_NEXT_IP6_REWRITE;
780  }
781  else if (ls0->behavior == SR_BEHAVIOR_T)
782  {
783  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index;
784  }
785  }
786  else
787  {
788  *next0 = SR_LOCALSID_NEXT_ERROR;
789  b0->error = node->errors[SR_LOCALSID_ERROR_NO_MORE_SEGMENTS];
790  }
791  }
792  else
793  {
794  /* Error. Routing header of type != SR */
795  *next0 = SR_LOCALSID_NEXT_ERROR;
796  b0->error = node->errors[SR_LOCALSID_ERROR_NO_SRH];
797  }
798 }
799 
800 /*
801  * @brief Function doing SRH processing for D* variants
802  */
805  vlib_buffer_t * b0,
806  ip6_header_t * ip0,
807  ip6_sr_header_t * sr0,
808  ip6_sr_localsid_t * ls0, u32 * next0)
809 {
810  /* Compute the size of the IPv6 header with all Ext. headers */
811  u8 next_proto;
812  ip6_ext_header_t *next_ext_header;
813  u16 total_size = 0;
814 
815  next_proto = ip0->protocol;
816  next_ext_header = (void *) (ip0 + 1);
817  total_size = sizeof (ip6_header_t);
818  while (ip6_ext_hdr (next_proto))
819  {
820  total_size += ip6_ext_header_len (next_ext_header);
821  next_proto = next_ext_header->next_hdr;
822  next_ext_header = ip6_ext_next_header (next_ext_header);
823  }
824 
825  /* Ensure this is the last segment. Otherwise drop. */
826  if (sr0 && sr0->segments_left != 0)
827  {
828  *next0 = SR_LOCALSID_NEXT_ERROR;
829  b0->error = node->errors[SR_LOCALSID_ERROR_NOT_LS];
830  return;
831  }
832 
833  switch (next_proto)
834  {
835  case IP_PROTOCOL_IPV6:
836  /* Encap-End IPv6. Pop outer IPv6 header. */
837  if (ls0->behavior == SR_BEHAVIOR_DX6)
838  {
839  vlib_buffer_advance (b0, total_size);
840  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
841  *next0 = SR_LOCALSID_NEXT_IP6_REWRITE;
842  return;
843  }
844  else if (ls0->behavior == SR_BEHAVIOR_DT6)
845  {
846  vlib_buffer_advance (b0, total_size);
847  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index;
848  return;
849  }
850  break;
851  case IP_PROTOCOL_IP_IN_IP:
852  /* Encap-End IPv4. Pop outer IPv6 header */
853  if (ls0->behavior == SR_BEHAVIOR_DX4)
854  {
855  vlib_buffer_advance (b0, total_size);
856  vnet_buffer (b0)->ip.adj_index[VLIB_TX] = ls0->nh_adj;
857  *next0 = SR_LOCALSID_NEXT_IP4_REWRITE;
858  return;
859  }
860  else if (ls0->behavior == SR_BEHAVIOR_DT4)
861  {
862  vlib_buffer_advance (b0, total_size);
863  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->vrf_index;
864  *next0 = SR_LOCALSID_NEXT_IP4_LOOKUP;
865  return;
866  }
867  break;
868  case IP_PROTOCOL_IP6_NONXT:
869  /* L2 encaps */
870  if (ls0->behavior == SR_BEHAVIOR_DX2)
871  {
872  vlib_buffer_advance (b0, total_size);
873  vnet_buffer (b0)->sw_if_index[VLIB_TX] = ls0->sw_if_index;
874  *next0 = SR_LOCALSID_NEXT_INTERFACE_OUTPUT;
875  return;
876  }
877  break;
878  }
879  *next0 = SR_LOCALSID_NEXT_ERROR;
880  b0->error = node->errors[SR_LOCALSID_ERROR_NO_INNER_HEADER];
881  return;
882 }
883 
884 /**
885  * @brief SR LocalSID graph node. Supports all default SR Endpoint variants with decaps
886  */
887 static uword
889  vlib_frame_t * from_frame)
890 {
891  u32 n_left_from, next_index, *from, *to_next;
892  ip6_sr_main_t *sm = &sr_main;
893  from = vlib_frame_vector_args (from_frame);
894  n_left_from = from_frame->n_vectors;
895  next_index = node->cached_next_index;
896  u32 thread_index = vm->thread_index;
897 
898  while (n_left_from > 0)
899  {
900  u32 n_left_to_next;
901  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
902 
903  /* Quad - Loop */
904  while (n_left_from >= 8 && n_left_to_next >= 4)
905  {
906  u32 bi0, bi1, bi2, bi3;
907  vlib_buffer_t *b0, *b1, *b2, *b3;
908  ip6_header_t *ip0, *ip1, *ip2, *ip3;
909  ip6_sr_header_t *sr0, *sr1, *sr2, *sr3;
910  u32 next0, next1, next2, next3;
911  next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP;
912  ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3;
913 
914  /* Prefetch next iteration. */
915  {
916  vlib_buffer_t *p4, *p5, *p6, *p7;
917 
918  p4 = vlib_get_buffer (vm, from[4]);
919  p5 = vlib_get_buffer (vm, from[5]);
920  p6 = vlib_get_buffer (vm, from[6]);
921  p7 = vlib_get_buffer (vm, from[7]);
922 
923  /* Prefetch the buffer header and packet for the N+4 loop iteration */
924  vlib_prefetch_buffer_header (p4, LOAD);
925  vlib_prefetch_buffer_header (p5, LOAD);
926  vlib_prefetch_buffer_header (p6, LOAD);
927  vlib_prefetch_buffer_header (p7, LOAD);
928 
933  }
934 
935  to_next[0] = bi0 = from[0];
936  to_next[1] = bi1 = from[1];
937  to_next[2] = bi2 = from[2];
938  to_next[3] = bi3 = from[3];
939  from += 4;
940  to_next += 4;
941  n_left_from -= 4;
942  n_left_to_next -= 4;
943 
944  b0 = vlib_get_buffer (vm, bi0);
945  b1 = vlib_get_buffer (vm, bi1);
946  b2 = vlib_get_buffer (vm, bi2);
947  b3 = vlib_get_buffer (vm, bi3);
948 
949  ls0 =
951  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
952  ls1 =
954  vnet_buffer (b1)->ip.adj_index[VLIB_TX]);
955  ls2 =
957  vnet_buffer (b2)->ip.adj_index[VLIB_TX]);
958  ls3 =
960  vnet_buffer (b3)->ip.adj_index[VLIB_TX]);
961 
962  ip0 = vlib_buffer_get_current (b0);
963  ip1 = vlib_buffer_get_current (b1);
964  ip2 = vlib_buffer_get_current (b2);
965  ip3 = vlib_buffer_get_current (b3);
966 
967  sr0 =
968  ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, NULL);
969  sr1 =
970  ip6_ext_header_find (vm, b1, ip1, IP_PROTOCOL_IPV6_ROUTE, NULL);
971  sr2 =
972  ip6_ext_header_find (vm, b2, ip2, IP_PROTOCOL_IPV6_ROUTE, NULL);
973  sr3 =
974  ip6_ext_header_find (vm, b3, ip3, IP_PROTOCOL_IPV6_ROUTE, NULL);
975 
976  end_decaps_srh_processing (node, b0, ip0, sr0, ls0, &next0);
977  end_decaps_srh_processing (node, b1, ip1, sr1, ls1, &next1);
978  end_decaps_srh_processing (node, b2, ip2, sr2, ls2, &next2);
979  end_decaps_srh_processing (node, b3, ip3, sr3, ls3, &next3);
980 
981  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
982  {
983  sr_localsid_trace_t *tr =
984  vlib_add_trace (vm, node, b0, sizeof (*tr));
985  tr->num_segments = 0;
987  sizeof (tr->localsid.as_u8));
988  tr->behavior = ls0->behavior;
989  if (ip0 == vlib_buffer_get_current (b0))
990  {
991  if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
992  && sr0->type == ROUTING_HEADER_TYPE_SR)
993  {
994  clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
995  tr->num_segments =
996  sr0->length * 8 / sizeof (ip6_address_t);
997  tr->segments_left = sr0->segments_left;
998  }
999  }
1000  else
1001  tr->num_segments = 0xFF;
1002  }
1003 
1004  if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
1005  {
1006  sr_localsid_trace_t *tr =
1007  vlib_add_trace (vm, node, b1, sizeof (*tr));
1008  tr->num_segments = 0;
1010  sizeof (tr->localsid.as_u8));
1011  tr->behavior = ls1->behavior;
1012  if (ip1 == vlib_buffer_get_current (b1))
1013  {
1014  if (ip1->protocol == IP_PROTOCOL_IPV6_ROUTE
1015  && sr1->type == ROUTING_HEADER_TYPE_SR)
1016  {
1017  clib_memcpy (tr->sr, sr1->segments, sr1->length * 8);
1018  tr->num_segments =
1019  sr1->length * 8 / sizeof (ip6_address_t);
1020  tr->segments_left = sr1->segments_left;
1021  }
1022  }
1023  else
1024  tr->num_segments = 0xFF;
1025  }
1026 
1027  if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED))
1028  {
1029  sr_localsid_trace_t *tr =
1030  vlib_add_trace (vm, node, b2, sizeof (*tr));
1031  tr->num_segments = 0;
1033  sizeof (tr->localsid.as_u8));
1034  tr->behavior = ls2->behavior;
1035  if (ip2 == vlib_buffer_get_current (b2))
1036  {
1037  if (ip2->protocol == IP_PROTOCOL_IPV6_ROUTE
1038  && sr2->type == ROUTING_HEADER_TYPE_SR)
1039  {
1040  clib_memcpy (tr->sr, sr2->segments, sr2->length * 8);
1041  tr->num_segments =
1042  sr2->length * 8 / sizeof (ip6_address_t);
1043  tr->segments_left = sr2->segments_left;
1044  }
1045  }
1046  else
1047  tr->num_segments = 0xFF;
1048  }
1049 
1050  if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED))
1051  {
1052  sr_localsid_trace_t *tr =
1053  vlib_add_trace (vm, node, b3, sizeof (*tr));
1054  tr->num_segments = 0;
1056  sizeof (tr->localsid.as_u8));
1057  tr->behavior = ls3->behavior;
1058  if (ip3 == vlib_buffer_get_current (b3))
1059  {
1060  if (ip3->protocol == IP_PROTOCOL_IPV6_ROUTE
1061  && sr3->type == ROUTING_HEADER_TYPE_SR)
1062  {
1063  clib_memcpy (tr->sr, sr3->segments, sr3->length * 8);
1064  tr->num_segments =
1065  sr3->length * 8 / sizeof (ip6_address_t);
1066  tr->segments_left = sr3->segments_left;
1067  }
1068  }
1069  else
1070  tr->num_segments = 0xFF;
1071  }
1072 
1074  (((next0 ==
1075  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1076  &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
1077  1, vlib_buffer_length_in_chain (vm, b0));
1078 
1080  (((next1 ==
1081  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1082  &(sm->sr_ls_valid_counters)), thread_index, ls1 - sm->localsids,
1083  1, vlib_buffer_length_in_chain (vm, b1));
1084 
1086  (((next2 ==
1087  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1088  &(sm->sr_ls_valid_counters)), thread_index, ls2 - sm->localsids,
1089  1, vlib_buffer_length_in_chain (vm, b2));
1090 
1092  (((next3 ==
1093  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1094  &(sm->sr_ls_valid_counters)), thread_index, ls3 - sm->localsids,
1095  1, vlib_buffer_length_in_chain (vm, b3));
1096 
1097  vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
1098  n_left_to_next, bi0, bi1, bi2, bi3,
1099  next0, next1, next2, next3);
1100  }
1101 
1102  /* Single loop for potentially the last three packets */
1103  while (n_left_from > 0 && n_left_to_next > 0)
1104  {
1105  u32 bi0;
1106  vlib_buffer_t *b0;
1107  ip6_header_t *ip0;
1108  ip6_sr_header_t *sr0;
1109  u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP;
1110  ip6_sr_localsid_t *ls0;
1111 
1112  bi0 = from[0];
1113  to_next[0] = bi0;
1114  from += 1;
1115  to_next += 1;
1116  n_left_from -= 1;
1117  n_left_to_next -= 1;
1118 
1119  b0 = vlib_get_buffer (vm, bi0);
1120  ip0 = vlib_buffer_get_current (b0);
1121 
1122  /* Lookup the SR End behavior based on IP DA (adj) */
1123  ls0 =
1125  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1126 
1127  /* Find SRH as well as previous header */
1128  sr0 =
1129  ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, NULL);
1130 
1131  /* SRH processing and End variants */
1132  end_decaps_srh_processing (node, b0, ip0, sr0, ls0, &next0);
1133 
1134  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1135  {
1136  sr_localsid_trace_t *tr =
1137  vlib_add_trace (vm, node, b0, sizeof (*tr));
1138  tr->num_segments = 0;
1140  sizeof (tr->localsid.as_u8));
1141  tr->behavior = ls0->behavior;
1142  if (ip0 == vlib_buffer_get_current (b0))
1143  {
1144  if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
1145  && sr0->type == ROUTING_HEADER_TYPE_SR)
1146  {
1147  clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
1148  tr->num_segments =
1149  sr0->length * 8 / sizeof (ip6_address_t);
1150  tr->segments_left = sr0->segments_left;
1151  }
1152  }
1153  else
1154  tr->num_segments = 0xFF;
1155  }
1156 
1157  /* Increase the counters */
1159  (((next0 ==
1160  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1161  &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
1162  1, vlib_buffer_length_in_chain (vm, b0));
1163 
1164  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1165  n_left_to_next, bi0, next0);
1166  }
1167  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1168  }
1169  return from_frame->n_vectors;
1170 }
1171 
1172 /* *INDENT-OFF* */
1174  .function = sr_localsid_d_fn,
1175  .name = "sr-localsid-d",
1176  .vector_size = sizeof (u32),
1177  .format_trace = format_sr_localsid_trace,
1179  .n_errors = SR_LOCALSID_N_ERROR,
1180  .error_strings = sr_localsid_error_strings,
1181  .n_next_nodes = SR_LOCALSID_N_NEXT,
1182  .next_nodes = {
1183 #define _(s,n) [SR_LOCALSID_NEXT_##s] = n,
1185 #undef _
1186  },
1187 };
1188 /* *INDENT-ON* */
1189 
1190 /**
1191  * @brief SR LocalSID graph node. Supports all default SR Endpoint without decaps
1192  */
1193 static uword
1195  vlib_frame_t * from_frame)
1196 {
1197  u32 n_left_from, next_index, *from, *to_next;
1198  ip6_sr_main_t *sm = &sr_main;
1199  from = vlib_frame_vector_args (from_frame);
1200  n_left_from = from_frame->n_vectors;
1201  next_index = node->cached_next_index;
1202  u32 thread_index = vm->thread_index;
1203 
1204  while (n_left_from > 0)
1205  {
1206  u32 n_left_to_next;
1207  vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
1208 
1209  /* Quad - Loop */
1210  while (n_left_from >= 8 && n_left_to_next >= 4)
1211  {
1212  u32 bi0, bi1, bi2, bi3;
1213  vlib_buffer_t *b0, *b1, *b2, *b3;
1214  ip6_header_t *ip0, *ip1, *ip2, *ip3;
1215  ip6_sr_header_t *sr0, *sr1, *sr2, *sr3;
1216  ip6_ext_header_t *prev0, *prev1, *prev2, *prev3;
1217  u32 next0, next1, next2, next3;
1218  next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP;
1219  ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3;
1220 
1221  /* Prefetch next iteration. */
1222  {
1223  vlib_buffer_t *p4, *p5, *p6, *p7;
1224 
1225  p4 = vlib_get_buffer (vm, from[4]);
1226  p5 = vlib_get_buffer (vm, from[5]);
1227  p6 = vlib_get_buffer (vm, from[6]);
1228  p7 = vlib_get_buffer (vm, from[7]);
1229 
1230  /* Prefetch the buffer header and packet for the N+2 loop iteration */
1231  vlib_prefetch_buffer_header (p4, LOAD);
1232  vlib_prefetch_buffer_header (p5, LOAD);
1233  vlib_prefetch_buffer_header (p6, LOAD);
1234  vlib_prefetch_buffer_header (p7, LOAD);
1235 
1240  }
1241 
1242  to_next[0] = bi0 = from[0];
1243  to_next[1] = bi1 = from[1];
1244  to_next[2] = bi2 = from[2];
1245  to_next[3] = bi3 = from[3];
1246  from += 4;
1247  to_next += 4;
1248  n_left_from -= 4;
1249  n_left_to_next -= 4;
1250 
1251  b0 = vlib_get_buffer (vm, bi0);
1252  b1 = vlib_get_buffer (vm, bi1);
1253  b2 = vlib_get_buffer (vm, bi2);
1254  b3 = vlib_get_buffer (vm, bi3);
1255 
1256  ip0 = vlib_buffer_get_current (b0);
1257  ip1 = vlib_buffer_get_current (b1);
1258  ip2 = vlib_buffer_get_current (b2);
1259  ip3 = vlib_buffer_get_current (b3);
1260 
1261  sr0 =
1262  ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, &prev0);
1263  sr1 =
1264  ip6_ext_header_find (vm, b1, ip1, IP_PROTOCOL_IPV6_ROUTE, &prev1);
1265  sr2 =
1266  ip6_ext_header_find (vm, b2, ip2, IP_PROTOCOL_IPV6_ROUTE, &prev2);
1267  sr3 =
1268  ip6_ext_header_find (vm, b3, ip3, IP_PROTOCOL_IPV6_ROUTE, &prev3);
1269 
1270  ls0 =
1272  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1273  ls1 =
1275  vnet_buffer (b1)->ip.adj_index[VLIB_TX]);
1276  ls2 =
1278  vnet_buffer (b2)->ip.adj_index[VLIB_TX]);
1279  ls3 =
1281  vnet_buffer (b3)->ip.adj_index[VLIB_TX]);
1282 
1283  end_srh_processing (node, b0, ip0, sr0, ls0, &next0, ls0->end_psp,
1284  prev0);
1285  end_srh_processing (node, b1, ip1, sr1, ls1, &next1, ls1->end_psp,
1286  prev1);
1287  end_srh_processing (node, b2, ip2, sr2, ls2, &next2, ls2->end_psp,
1288  prev2);
1289  end_srh_processing (node, b3, ip3, sr3, ls3, &next3, ls3->end_psp,
1290  prev3);
1291 
1292  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1293  {
1294  sr_localsid_trace_t *tr =
1295  vlib_add_trace (vm, node, b0, sizeof (*tr));
1296  tr->num_segments = 0;
1298  sizeof (tr->localsid.as_u8));
1299  tr->behavior = ls0->behavior;
1300  if (ip0 == vlib_buffer_get_current (b0))
1301  {
1302  if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
1303  && sr0->type == ROUTING_HEADER_TYPE_SR)
1304  {
1305  clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
1306  tr->num_segments =
1307  sr0->length * 8 / sizeof (ip6_address_t);
1308  tr->segments_left = sr0->segments_left;
1309  }
1310  }
1311  else
1312  tr->num_segments = 0xFF;
1313  }
1314 
1315  if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
1316  {
1317  sr_localsid_trace_t *tr =
1318  vlib_add_trace (vm, node, b1, sizeof (*tr));
1319  tr->num_segments = 0;
1321  sizeof (tr->localsid.as_u8));
1322  tr->behavior = ls1->behavior;
1323  if (ip1 == vlib_buffer_get_current (b1))
1324  {
1325  if (ip1->protocol == IP_PROTOCOL_IPV6_ROUTE
1326  && sr1->type == ROUTING_HEADER_TYPE_SR)
1327  {
1328  clib_memcpy (tr->sr, sr1->segments, sr1->length * 8);
1329  tr->num_segments =
1330  sr1->length * 8 / sizeof (ip6_address_t);
1331  tr->segments_left = sr1->segments_left;
1332  }
1333  }
1334  else
1335  tr->num_segments = 0xFF;
1336  }
1337 
1338  if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED))
1339  {
1340  sr_localsid_trace_t *tr =
1341  vlib_add_trace (vm, node, b2, sizeof (*tr));
1342  tr->num_segments = 0;
1344  sizeof (tr->localsid.as_u8));
1345  tr->behavior = ls2->behavior;
1346  if (ip2 == vlib_buffer_get_current (b2))
1347  {
1348  if (ip2->protocol == IP_PROTOCOL_IPV6_ROUTE
1349  && sr2->type == ROUTING_HEADER_TYPE_SR)
1350  {
1351  clib_memcpy (tr->sr, sr2->segments, sr2->length * 8);
1352  tr->num_segments =
1353  sr2->length * 8 / sizeof (ip6_address_t);
1354  tr->segments_left = sr2->segments_left;
1355  }
1356  }
1357  else
1358  tr->num_segments = 0xFF;
1359  }
1360 
1361  if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED))
1362  {
1363  sr_localsid_trace_t *tr =
1364  vlib_add_trace (vm, node, b3, sizeof (*tr));
1365  tr->num_segments = 0;
1367  sizeof (tr->localsid.as_u8));
1368  tr->behavior = ls3->behavior;
1369  if (ip3 == vlib_buffer_get_current (b3))
1370  {
1371  if (ip3->protocol == IP_PROTOCOL_IPV6_ROUTE
1372  && sr3->type == ROUTING_HEADER_TYPE_SR)
1373  {
1374  clib_memcpy (tr->sr, sr3->segments, sr3->length * 8);
1375  tr->num_segments =
1376  sr3->length * 8 / sizeof (ip6_address_t);
1377  tr->segments_left = sr3->segments_left;
1378  }
1379  }
1380  else
1381  tr->num_segments = 0xFF;
1382  }
1383 
1385  (((next0 ==
1386  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1387  &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
1388  1, vlib_buffer_length_in_chain (vm, b0));
1389 
1391  (((next1 ==
1392  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1393  &(sm->sr_ls_valid_counters)), thread_index, ls1 - sm->localsids,
1394  1, vlib_buffer_length_in_chain (vm, b1));
1395 
1397  (((next2 ==
1398  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1399  &(sm->sr_ls_valid_counters)), thread_index, ls2 - sm->localsids,
1400  1, vlib_buffer_length_in_chain (vm, b2));
1401 
1403  (((next3 ==
1404  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1405  &(sm->sr_ls_valid_counters)), thread_index, ls3 - sm->localsids,
1406  1, vlib_buffer_length_in_chain (vm, b3));
1407 
1408  vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
1409  n_left_to_next, bi0, bi1, bi2, bi3,
1410  next0, next1, next2, next3);
1411  }
1412 
1413  /* Single loop for potentially the last three packets */
1414  while (n_left_from > 0 && n_left_to_next > 0)
1415  {
1416  u32 bi0;
1417  vlib_buffer_t *b0;
1418  ip6_header_t *ip0 = 0;
1419  ip6_ext_header_t *prev0;
1420  ip6_sr_header_t *sr0;
1421  u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP;
1422  ip6_sr_localsid_t *ls0;
1423 
1424  bi0 = from[0];
1425  to_next[0] = bi0;
1426  from += 1;
1427  to_next += 1;
1428  n_left_from -= 1;
1429  n_left_to_next -= 1;
1430 
1431  b0 = vlib_get_buffer (vm, bi0);
1432  ip0 = vlib_buffer_get_current (b0);
1433  sr0 =
1434  ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, &prev0);
1435 
1436  /* Lookup the SR End behavior based on IP DA (adj) */
1437  ls0 =
1439  vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
1440 
1441  /* SRH processing */
1442  end_srh_processing (node, b0, ip0, sr0, ls0, &next0, ls0->end_psp,
1443  prev0);
1444 
1445  if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
1446  {
1447  sr_localsid_trace_t *tr =
1448  vlib_add_trace (vm, node, b0, sizeof (*tr));
1449  tr->num_segments = 0;
1451  sizeof (tr->localsid.as_u8));
1452  tr->behavior = ls0->behavior;
1453  if (ip0 == vlib_buffer_get_current (b0))
1454  {
1455  if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
1456  && sr0->type == ROUTING_HEADER_TYPE_SR)
1457  {
1458  clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
1459  tr->num_segments =
1460  sr0->length * 8 / sizeof (ip6_address_t);
1461  tr->segments_left = sr0->segments_left;
1462  }
1463  }
1464  else
1465  tr->num_segments = 0xFF;
1466  }
1467 
1469  (((next0 ==
1470  SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
1471  &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
1472  1, vlib_buffer_length_in_chain (vm, b0));
1473 
1474  vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
1475  n_left_to_next, bi0, next0);
1476  }
1477  vlib_put_next_frame (vm, node, next_index, n_left_to_next);
1478  }
1479  return from_frame->n_vectors;
1480 }
1481 
1482 /* *INDENT-OFF* */
1484  .function = sr_localsid_fn,
1485  .name = "sr-localsid",
1486  .vector_size = sizeof (u32),
1487  .format_trace = format_sr_localsid_trace,
1489  .n_errors = SR_LOCALSID_N_ERROR,
1490  .error_strings = sr_localsid_error_strings,
1491  .n_next_nodes = SR_LOCALSID_N_NEXT,
1492  .next_nodes = {
1493 #define _(s,n) [SR_LOCALSID_NEXT_##s] = n,
1495 #undef _
1496  },
1497 };
1498 /* *INDENT-ON* */
1499 
1500 static u8 *
1501 format_sr_dpo (u8 * s, va_list * args)
1502 {
1503  index_t index = va_arg (*args, index_t);
1504  CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
1505 
1506  return (format (s, "SR: localsid_index:[%d]", index));
1507 }
1508 
1509 const static dpo_vft_t sr_loc_vft = {
1510  .dv_lock = sr_dpo_lock,
1511  .dv_unlock = sr_dpo_unlock,
1512  .dv_format = format_sr_dpo,
1513 };
1514 
1515 const static char *const sr_loc_ip6_nodes[] = {
1516  "sr-localsid",
1517  NULL,
1518 };
1519 
1520 const static char *const *const sr_loc_nodes[DPO_PROTO_NUM] = {
1522 };
1523 
1524 const static char *const sr_loc_d_ip6_nodes[] = {
1525  "sr-localsid-d",
1526  NULL,
1527 };
1528 
1529 const static char *const *const sr_loc_d_nodes[DPO_PROTO_NUM] = {
1531 };
1532 
1533 
1534 /*************************** SR LocalSID plugins ******************************/
1535 /**
1536  * @brief SR LocalSID plugin registry
1537  */
1538 int
1540  u8 * keyword_str, u8 * def_str,
1541  u8 * params_str, dpo_type_t * dpo,
1542  format_function_t * ls_format,
1543  unformat_function_t * ls_unformat,
1544  sr_plugin_callback_t * creation_fn,
1545  sr_plugin_callback_t * removal_fn)
1546 {
1547  ip6_sr_main_t *sm = &sr_main;
1548  uword *p;
1549 
1551 
1552  /* Did this function exist? If so update it */
1553  p = hash_get_mem (sm->plugin_functions_by_key, fn_name);
1554  if (p)
1555  {
1556  plugin = pool_elt_at_index (sm->plugin_functions, p[0]);
1557  }
1558  /* Else create a new one and set hash key */
1559  else
1560  {
1561  pool_get (sm->plugin_functions, plugin);
1562  hash_set_mem (sm->plugin_functions_by_key, fn_name,
1563  plugin - sm->plugin_functions);
1564  }
1565 
1566  clib_memset (plugin, 0, sizeof (*plugin));
1567 
1568  plugin->sr_localsid_function_number = (plugin - sm->plugin_functions);
1570  plugin->ls_format = ls_format;
1571  plugin->ls_unformat = ls_unformat;
1572  plugin->creation = creation_fn;
1573  plugin->removal = removal_fn;
1574  clib_memcpy (&plugin->dpo, dpo, sizeof (dpo_type_t));
1575  plugin->function_name = format (0, "%s%c", fn_name, 0);
1576  plugin->keyword_str = format (0, "%s%c", keyword_str, 0);
1577  plugin->def_str = format (0, "%s%c", def_str, 0);
1578  plugin->params_str = format (0, "%s%c", params_str, 0);
1579 
1580  return plugin->sr_localsid_function_number;
1581 }
1582 
1583 /**
1584  * @brief CLI function to 'show' all available SR LocalSID behaviors
1585  */
1586 static clib_error_t *
1588  unformat_input_t * input,
1589  vlib_cli_command_t * cmd)
1590 {
1591  ip6_sr_main_t *sm = &sr_main;
1593  sr_localsid_fn_registration_t **plugins_vec = 0;
1594  int i;
1595 
1596  vlib_cli_output (vm,
1597  "SR LocalSIDs behaviors:\n-----------------------\n\n");
1598 
1599  /* *INDENT-OFF* */
1600  pool_foreach (plugin, sm->plugin_functions,
1601  ({ vec_add1 (plugins_vec, plugin); }));
1602  /* *INDENT-ON* */
1603 
1604  /* Print static behaviors */
1605  vlib_cli_output (vm, "Default behaviors:\n"
1606  "\tEnd\t-> Endpoint.\n"
1607  "\tEnd.X\t-> Endpoint with Layer-3 cross-connect.\n"
1608  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
1609  "\tEnd.T\t-> Endpoint with specific IPv6 table lookup.\n"
1610  "\t\tParameters: '<fib_table>'\n"
1611  "\tEnd.DX2\t-> Endpoint with decapsulation and Layer-2 cross-connect.\n"
1612  "\t\tParameters: '<iface>'\n"
1613  "\tEnd.DX6\t-> Endpoint with decapsulation and IPv6 cross-connect.\n"
1614  "\t\tParameters: '<iface> <ip6_next_hop>'\n"
1615  "\tEnd.DX4\t-> Endpoint with decapsulation and IPv4 cross-connect.\n"
1616  "\t\tParameters: '<iface> <ip4_next_hop>'\n"
1617  "\tEnd.DT6\t-> Endpoint with decapsulation and specific IPv6 table lookup.\n"
1618  "\t\tParameters: '<ip6_fib_table>'\n"
1619  "\tEnd.DT4\t-> Endpoint with decapsulation and specific IPv4 table lookup.\n"
1620  "\t\tParameters: '<ip4_fib_table>'\n");
1621  vlib_cli_output (vm, "Plugin behaviors:\n");
1622  for (i = 0; i < vec_len (plugins_vec); i++)
1623  {
1624  plugin = plugins_vec[i];
1625  vlib_cli_output (vm, "\t%s\t-> %s.\n", plugin->keyword_str,
1626  plugin->def_str);
1627  vlib_cli_output (vm, "\t\tParameters: '%s'\n", plugin->params_str);
1628  }
1629  return 0;
1630 }
1631 
1632 /* *INDENT-OFF* */
1633 VLIB_CLI_COMMAND (show_sr_localsid_behaviors_command, static) = {
1634  .path = "show sr localsids behaviors",
1635  .short_help = "show sr localsids behaviors",
1637 };
1638 /* *INDENT-ON* */
1639 
1640 /**
1641  * @brief SR LocalSID initialization
1642  */
1643 clib_error_t *
1645 {
1646  /* Init memory for function keys */
1647  ip6_sr_main_t *sm = &sr_main;
1648  mhash_init (&sm->sr_localsids_index_hash, sizeof (uword),
1649  sizeof (ip6_address_t));
1650  /* Init SR behaviors DPO type */
1652  /* Init SR behaviors DPO type */
1654  dpo_register_new_type (&sr_loc_vft, sr_loc_d_nodes);
1655  /* Init memory for localsid plugins */
1656  sm->plugin_functions_by_key = hash_create_string (0, sizeof (uword));
1657  return 0;
1658 }
1659 
1661 /*
1662 * fd.io coding-style-patch-verification: ON
1663 *
1664 * Local Variables:
1665 * eval: (c-set-style "gnu")
1666 * End:
1667 */
u8 * function_name
Function name.
Definition: sr.h:136
#define SR_BEHAVIOR_D_FIRST
Definition: sr.h:40
sr_localsid_error_t
Definition: sr_localsid.c:610
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:124
fib_protocol_t fp_proto
protocol type
Definition: fib_types.h:212
ip6_sr_main_t sr_main
Definition: sr.c:31
dpo_lock_fn_t dv_lock
A reference counting lock function.
Definition: dpo.h:406
u32 vlan_index
VLAN tag (not an index)
Definition: sr.h:118
u32 nh_adj
Next_adj for xconnect usage only.
Definition: sr.h:122
#define CLIB_UNUSED(x)
Definition: clib.h:83
A virtual function table regisitered for a DPO type.
Definition: dpo.h:401
static const char *const sr_loc_ip6_nodes[]
Definition: sr_localsid.c:1515
void vlib_validate_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
validate a combined counter
Definition: counter.c:108
fib_node_index_t fib_table_lookup_exact_match(u32 fib_index, const fib_prefix_t *prefix)
Perfom an exact match in the non-forwarding table.
Definition: fib_table.c:95
#define SR_BEHAVIOR_X
Definition: sr.h:38
static void vlib_increment_combined_counter(vlib_combined_counter_main_t *cm, u32 thread_index, u32 index, u64 n_packets, u64 n_bytes)
Increment a combined counter.
Definition: counter.h:220
SR LocalSID.
Definition: sr.h:102
vnet_main_t * vnet_get_main(void)
Definition: misc.c:46
#define PREDICT_TRUE(x)
Definition: clib.h:113
void sr_dpo_unlock(dpo_id_t *dpo)
no-op unlock function.
Definition: sr.c:47
int sr_cli_localsid(char is_del, ip6_address_t *localsid_addr, char end_psp, u8 behavior, u32 sw_if_index, u32 vlan_index, u32 fib_table, ip46_address_t *nh_addr, void *ls_plugin_mem)
SR localsid add/del.
Definition: sr_localsid.c:66
u8 as_u8[16]
Definition: ip6_packet.h:48
u64 as_u64[2]
Definition: ip6_packet.h:51
unsigned long u64
Definition: types.h:89
unsigned char params_str[32]
uword mhash_unset(mhash_t *h, void *key, uword *old_value)
Definition: mhash.c:346
clib_memset(h->entries, 0, sizeof(h->entries[0]) *entries)
format_function_t * ls_format
LocalSID format function.
Definition: sr.h:146
ip6_address_t localsid
Definition: sr_localsid.c:595
u32 thread_index
Definition: main.h:218
u32 index_t
A Data-Path Object is an object that represents actions that are applied to packets are they are swit...
Definition: dpo.h:41
#define SR_BEHAVIOR_DT6
Definition: sr.h:44
static_always_inline void end_decaps_srh_processing(vlib_node_runtime_t *node, vlib_buffer_t *b0, ip6_header_t *ip0, ip6_sr_header_t *sr0, ip6_sr_localsid_t *ls0, u32 *next0)
Definition: sr_localsid.c:804
#define vlib_validate_buffer_enqueue_x4(vm, node, next_index, to_next, n_left_to_next, bi0, bi1, bi2, bi3, next0, next1, next2, next3)
Finish enqueueing four buffers forward in the graph.
Definition: buffer_node.h:138
Combined counter to hold both packets and byte differences.
Definition: counter_types.h:26
static void * ip6_ext_next_header(ip6_ext_header_t *ext_hdr)
Definition: ip6_packet.h:552
int i
#define hash_set_mem(h, key, value)
Definition: hash.h:275
u8 * format(u8 *s, const char *fmt,...)
Definition: format.c:424
u16 behavior
Behavior associated to this localsid.
Definition: sr.h:108
unformat_function_t unformat_vnet_sw_interface
#define ROUTING_HEADER_TYPE_SR
Definition: sr_packet.h:117
unsigned char keyword_str[32]
vlib_error_t * errors
Vector of errors for this node.
Definition: node.h:470
static uword vlib_buffer_length_in_chain(vlib_main_t *vm, vlib_buffer_t *b)
Get length in bytes of the buffer chain.
Definition: buffer_funcs.h:366
#define pool_get(P, E)
Allocate an object E from a pool P (unspecified alignment).
Definition: pool.h:236
vlib_combined_counter_main_t sr_ls_invalid_counters
Definition: sr.h:229
vlib_combined_counter_main_t sr_ls_valid_counters
Definition: sr.h:228
static char * sr_localsid_error_strings[]
Definition: sr_localsid.c:618
static clib_error_t * show_sr_localsid_behaviors_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI function to &#39;show&#39; all available SR LocalSID behaviors.
Definition: sr_localsid.c:1587
format_function_t format_vnet_sw_if_index_name
unsigned char u8
Definition: types.h:56
#define SR_BEHAVIOR_DT4
Definition: sr.h:45
static const char *const sr_loc_d_ip6_nodes[]
Definition: sr_localsid.c:1524
#define clib_memcpy(d, s, n)
Definition: string.h:180
u8 *() format_function_t(u8 *s, va_list *args)
Definition: format.h:48
static const char *const *const sr_loc_nodes[DPO_PROTO_NUM]
Definition: sr_localsid.c:1520
format_function_t format_ip4_address
Definition: format.h:75
#define static_always_inline
Definition: clib.h:100
static clib_error_t * sr_cli_localsid_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
SR LocalSID CLI function.
Definition: sr_localsid.c:264
void vlib_clear_combined_counters(vlib_combined_counter_main_t *cm)
Clear a collection of combined counters.
Definition: counter.c:61
enum dpo_type_t_ dpo_type_t
Common types of data-path objects New types can be dynamically added using dpo_register_new_type() ...
#define pool_foreach(VAR, POOL, BODY)
Iterate through pool.
Definition: pool.h:493
unformat_function_t unformat_ip4_address
Definition: format.h:70
vl_api_interface_index_t sw_if_index
Definition: gre.api:50
#define VLIB_INIT_FUNCTION(x)
Definition: init.h:173
#define SR_BEHAVIOR_LAST
Definition: sr.h:46
#define vlib_prefetch_buffer_header(b, type)
Prefetch buffer metadata.
Definition: buffer.h:203
Aggregate type for a prefix.
Definition: fib_types.h:203
#define clib_error_return(e, args...)
Definition: error.h:99
void adj_unlock(adj_index_t adj_index)
Release a reference counting lock on the adjacency.
Definition: adj.c:347
unsigned int u32
Definition: types.h:88
u32 fib_table_find(fib_protocol_t proto, u32 table_id)
Get the index of the FIB for a Table-ID.
Definition: fib_table.c:1080
dpo_type_t dpo_register_new_type(const dpo_vft_t *vft, const char *const *const *nodes)
Create and register a new DPO type.
Definition: dpo.c:342
static void * ip6_ext_header_find(vlib_main_t *vm, vlib_buffer_t *b, ip6_header_t *ip6_header, u8 header_type, ip6_ext_header_t **prev_ext_header)
Definition: ip6_packet.h:578
#define hash_create_string(elts, value_bytes)
Definition: hash.h:690
vl_api_fib_path_type_t type
Definition: fib_types.api:123
vlib_error_t error
Error code for buffers to be enqueued to error handler.
Definition: buffer.h:136
The identity of a DPO is a combination of its type and its instance number/index of objects of that t...
Definition: dpo.h:170
Definition: fib_entry.h:285
#define ADJ_INDEX_INVALID
Invalid ADJ index - used when no adj is known likewise blazoned capitals INVALID speak volumes where ...
Definition: adj_types.h:36
#define pool_elt_at_index(p, i)
Returns pointer to element at given index.
Definition: pool.h:514
static void vlib_zero_combined_counter(vlib_combined_counter_main_t *cm, u32 index)
Clear a combined counter Clears the set of per-thread counters.
Definition: counter.h:285
counter_t packets
packet counter
Definition: counter_types.h:28
vlib_node_registration_t sr_localsid_d_node
(constructor) VLIB_REGISTER_NODE (sr_localsid_d_node)
Definition: sr_localsid.c:1173
ip46_address_t fp_addr
The address type is not deriveable from the fp_addr member.
Definition: fib_types.h:226
#define SR_BEHAVIOR_END
Definition: sr.h:37
u8 * format_sr_localsid_trace(u8 *s, va_list *args)
SR LocalSID graph node trace function.
Definition: sr_localsid.c:646
struct _unformat_input_t unformat_input_t
unsigned short u16
Definition: types.h:57
SR LocalSID behavior registration.
Definition: sr.h:132
unsigned char def_str[64]
static void * vlib_buffer_get_current(vlib_buffer_t *b)
Get pointer to current data to process.
Definition: buffer.h:229
#define pool_put(P, E)
Free an object E in pool P.
Definition: pool.h:286
char end_psp
Combined with End.PSP?
Definition: sr.h:106
static dpo_type_t sr_localsid_d_dpo_type
Definition: sr_localsid.c:47
#define PREDICT_FALSE(x)
Definition: clib.h:112
void sr_dpo_lock(dpo_id_t *dpo)
no-op lock function.
Definition: sr.c:38
static u8 * format_sr_dpo(u8 *s, va_list *args)
Definition: sr_localsid.c:1501
static_always_inline void end_srh_processing(vlib_node_runtime_t *node, vlib_buffer_t *b0, ip6_header_t *ip0, ip6_sr_header_t *sr0, ip6_sr_localsid_t *ls0, u32 *next0, u8 psp, ip6_ext_header_t *prev0)
Function doing End processing.
Definition: sr_localsid.c:707
#define SR_BEHAVIOR_DX4
Definition: sr.h:43
uword() unformat_function_t(unformat_input_t *input, va_list *args)
Definition: format.h:233
#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
static uword mhash_set(mhash_t *h, void *key, uword new_value, uword *old_value)
Definition: mhash.h:117
#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:338
static uword sr_localsid_d_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
SR LocalSID graph node.
Definition: sr_localsid.c:888
#define ip6_ext_header_len(p)
Definition: ip6_packet.h:548
unformat_function_t unformat_ip6_address
Definition: format.h:91
ip6_sr_localsid_t * localsids
Definition: sr.h:204
The fine-grained event logger allows lightweight, thread-safe event logging at minimum cost...
#define VLIB_REGISTER_NODE(x,...)
Definition: node.h:169
#define UNFORMAT_END_OF_INPUT
Definition: format.h:145
void mhash_init(mhash_t *h, uword n_value_bytes, uword n_key_bytes)
Definition: mhash.c:168
static clib_error_t * show_sr_localsid_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
CLI function to &#39;show&#39; all SR LocalSIDs on console.
Definition: sr_localsid.c:442
u16 n_vectors
Definition: node.h:397
format_function_t format_ip6_address
Definition: format.h:93
int() sr_plugin_callback_t(ip6_sr_localsid_t *localsid)
Definition: sr.h:127
static void vlib_get_combined_counter(const vlib_combined_counter_main_t *cm, u32 index, vlib_counter_t *result)
Get the value of a combined counter, never called in the speed path Scrapes the entire set of per-thr...
Definition: counter.h:259
#define CLIB_PREFETCH(addr, size, type)
Definition: cache.h:80
vlib_main_t * vm
Definition: buffer.c:323
static clib_error_t * clear_sr_localsid_counters_command_fn(vlib_main_t *vm, unformat_input_t *input, vlib_cli_command_t *cmd)
Function to &#39;clear&#39; ALL SR localsid counters.
Definition: sr_localsid.c:569
void fib_table_entry_delete(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source)
Delete a FIB entry.
Definition: fib_table.c:869
u8 data[]
Packet data.
Definition: buffer.h:181
u32 fib_node_index_t
A typedef of a node index.
Definition: fib_types.h:30
unformat_function_t * ls_unformat
LocalSID unformat function.
Definition: sr.h:148
u32 adj_index_t
An index for adjacencies.
Definition: adj_types.h:30
int sr_localsid_register_function(vlib_main_t *vm, u8 *fn_name, u8 *keyword_str, u8 *def_str, u8 *params_str, dpo_type_t *dpo, format_function_t *ls_format, unformat_function_t *ls_unformat, sr_plugin_callback_t *creation_fn, sr_plugin_callback_t *removal_fn)
SR LocalSID plugin registry.
Definition: sr_localsid.c:1539
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:456
void dpo_set(dpo_id_t *dpo, dpo_type_t type, dpo_proto_t proto, index_t index)
Set/create a DPO ID The DPO will be locked.
Definition: dpo.c:186
static u8 ip6_ext_hdr(u8 nexthdr)
Definition: ip6_packet.h:527
#define VLIB_CLI_COMMAND(x,...)
Definition: cli.h:161
fib_node_index_t fib_table_entry_special_dpo_add(u32 fib_index, const fib_prefix_t *prefix, fib_source_t source, fib_entry_flag_t flags, const dpo_id_t *dpo)
Add a &#39;special&#39; entry to the FIB that links to the DPO passed A special entry is an entry that the FI...
Definition: fib_table.c:307
u16 cached_next_index
Next frame index that vector arguments were last enqueued to last time this node ran.
Definition: node.h:515
dpo_type_t dpo
DPO type registration.
Definition: sr.h:144
u8 * def_str
Behavior definition (i.e.
Definition: sr.h:140
static uword * mhash_get(mhash_t *h, const void *key)
Definition: mhash.h:110
void * plugin_mem
Memory to be used by the plugin callback functions.
Definition: sr.h:124
u32 fib_table_get_table_id(u32 fib_index, fib_protocol_t proto)
Get the Table-ID of the FIB from protocol and index.
Definition: fib_table.c:1069
static const char *const *const sr_loc_d_nodes[DPO_PROTO_NUM]
Definition: sr_localsid.c:1529
u32 vrf_index
vrf only
Definition: sr.h:113
static void vlib_buffer_advance(vlib_buffer_t *b, word l)
Advance current data pointer by the supplied (signed!) amount.
Definition: buffer.h:248
u32 fib_table
FIB table where localsid is registered.
Definition: sr.h:116
#define SR_BEHAVIOR_DX2
Definition: sr.h:41
SR localsid node trace.
Definition: sr_localsid.c:593
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
u16 sr_localsid_function_number
SR LocalSID plugin function (>SR_BEHAVIOR_LAST)
Definition: sr.h:134
#define ip46_address_reset(ip46)
Definition: ip6_packet.h:91
counter_t bytes
byte counter
Definition: counter_types.h:29
Definition: defs.h:47
#define DPO_PROTO_NUM
Definition: dpo.h:70
SRv6 and SR-MPLS.
Definition: fib_entry.h:63
u16 payload_length
Definition: ip6_packet.h:374
vl_api_address_t ip
Definition: l2.api:489
#define FIB_NODE_INDEX_INVALID
Definition: fib_types.h:31
#define SR_BEHAVIOR_T
Definition: sr.h:39
#define vec_len(v)
Number of elements in vector (rvalue-only, NULL tolerant)
ip6_address_t segments[0]
Definition: sr_packet.h:149
sr_plugin_callback_t * creation
Function within plugin that will be called after localsid creation.
Definition: sr.h:150
VLIB buffer representation.
Definition: buffer.h:102
u64 uword
Definition: types.h:112
static void * vlib_frame_vector_args(vlib_frame_t *f)
Get pointer to frame vector data.
Definition: node_funcs.h:244
#define DPO_INVALID
An initialiser for DPOs declared on the stack.
Definition: dpo.h:197
clib_error_t * sr_localsids_init(vlib_main_t *vm)
SR LocalSID initialization.
Definition: sr_localsid.c:1644
#define hash_get_mem(h, key)
Definition: hash.h:269
#define vnet_buffer(b)
Definition: buffer.h:365
vlib_node_registration_t sr_localsid_node
(constructor) VLIB_REGISTER_NODE (sr_localsid_node)
Definition: sr_localsid.c:1483
Segment Routing data structures definitions.
Segment Routing main datastructure.
Definition: sr.h:189
adj_index_t adj_nbr_add_or_lock(fib_protocol_t nh_proto, vnet_link_t link_type, const ip46_address_t *nh_addr, u32 sw_if_index)
Neighbour Adjacency sub-type.
Definition: adj_nbr.c:218
void dpo_reset(dpo_id_t *dpo)
reset a DPO ID The DPO will be unlocked.
Definition: dpo.c:232
#define vec_foreach(var, vec)
Vector iterator.
static uword sr_localsid_fn(vlib_main_t *vm, vlib_node_runtime_t *node, vlib_frame_t *from_frame)
SR LocalSID graph node.
Definition: sr_localsid.c:1194
#define foreach_sr_localsid_next
Definition: sr_localsid.c:624
ip46_address_t next_hop
Next_hop for xconnect usage only.
Definition: sr.h:120
mhash_t sr_localsids_index_hash
Definition: sr.h:207
u8 * params_str
Behavior parameters (i.e.
Definition: sr.h:142
#define foreach_sr_localsid_error
Definition: sr_localsid.c:602
u32 sw_if_index
xconnect only
Definition: sr.h:112
#define CLIB_CACHE_LINE_BYTES
Definition: cache.h:59
sr_plugin_callback_t * removal
Function within plugin that will be called before localsid removal.
Definition: sr.h:152
ip6_address_t localsid
LocalSID IPv6 address.
Definition: sr.h:104
void vlib_cli_output(vlib_main_t *vm, char *fmt,...)
Definition: cli.c:772
static dpo_type_t sr_localsid_dpo_type
Dynamically added SR localsid DPO type.
Definition: sr_localsid.c:46
static vlib_buffer_t * vlib_get_buffer(vlib_main_t *vm, u32 buffer_index)
Translate buffer index into buffer pointer.
Definition: buffer_funcs.h:85
u8 * keyword_str
Behavior keyword (i.e.
Definition: sr.h:138
sr_localsid_fn_registration_t * plugin_functions
Definition: sr.h:222
uword unformat(unformat_input_t *i, const char *fmt,...)
Definition: unformat.c:978
sr_localsid_next_t
Definition: sr_localsid.c:632
#define SR_BEHAVIOR_DX6
Definition: sr.h:42
ip6_address_t dst_address
Definition: ip6_packet.h:383
static uword unformat_check_input(unformat_input_t *i)
Definition: format.h:171
uword * plugin_functions_by_key
Definition: sr.h:225