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