aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/plugins/srv6-ad/test/vpp_srv6.py4
-rw-r--r--src/plugins/srv6-un/CMakeLists.txt21
-rw-r--r--src/plugins/srv6-un/node.c289
-rw-r--r--src/plugins/srv6-un/un.c185
-rw-r--r--src/plugins/srv6-un/un.h65
-rwxr-xr-xsrc/vnet/srv6/sr.h22
-rw-r--r--src/vnet/srv6/sr_api.c2
-rwxr-xr-xsrc/vnet/srv6/sr_localsid.c801
8 files changed, 816 insertions, 573 deletions
diff --git a/src/plugins/srv6-ad/test/vpp_srv6.py b/src/plugins/srv6-ad/test/vpp_srv6.py
index 80e771eea18..d6efedc9f3e 100644
--- a/src/plugins/srv6-ad/test/vpp_srv6.py
+++ b/src/plugins/srv6-ad/test/vpp_srv6.py
@@ -19,7 +19,9 @@ class SRv6LocalSIDBehaviors():
SR_BEHAVIOR_DX4 = 7
SR_BEHAVIOR_DT6 = 8
SR_BEHAVIOR_DT4 = 9
- SR_BEHAVIOR_LAST = 10 # Must always be the last one
+ SR_BEHAVIOR_END_UN_PERF = 10
+ SR_BEHAVIOR_END_UN = 11
+ SR_BEHAVIOR_LAST = 12 # Must always be the last one
class SRv6PolicyType():
diff --git a/src/plugins/srv6-un/CMakeLists.txt b/src/plugins/srv6-un/CMakeLists.txt
deleted file mode 100644
index 9ecf0b3c8d0..00000000000
--- a/src/plugins/srv6-un/CMakeLists.txt
+++ /dev/null
@@ -1,21 +0,0 @@
-# Copyright (c) 2018 Cisco and/or its affiliates.
-# Licensed under the Apache License, Version 2.0 (the "License");
-# you may not use this file except in compliance with the License.
-# You may obtain a copy of the License at:
-#
-# http://www.apache.org/licenses/LICENSE-2.0
-#
-# Unless required by applicable law or agreed to in writing, software
-# distributed under the License is distributed on an "AS IS" BASIS,
-# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-# See the License for the specific language governing permissions and
-# limitations under the License.
-
-add_vpp_plugin(SRv6uN
- SOURCES
- un.c
- node.c
-
- INSTALL_HEADERS
- un.h
-)
diff --git a/src/plugins/srv6-un/node.c b/src/plugins/srv6-un/node.c
deleted file mode 100644
index 9368f2083ef..00000000000
--- a/src/plugins/srv6-un/node.c
+++ /dev/null
@@ -1,289 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#include <vlib/vlib.h>
-#include <vnet/vnet.h>
-#include <vppinfra/error.h>
-#include <srv6-un/un.h>
-
-
-/******************************* Packet tracing *******************************/
-typedef struct
-{
- u32 localsid_index;
-} srv6_un_localsid_trace_t;
-
-
-static u8 *
-format_srv6_un_localsid_trace (u8 * s, va_list * args)
-{
- CLIB_UNUSED (vlib_main_t * vm) = va_arg (*args, vlib_main_t *);
- CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *);
- srv6_un_localsid_trace_t *t = va_arg (*args, srv6_un_localsid_trace_t *);
-
- return format (s, "SRv6-uN-localsid: localsid_index %d", t->localsid_index);
-}
-
-/********************************* Next nodes *********************************/
-typedef enum
-{
- SRV6_UN_LOCALSID_NEXT_ERROR,
- SRV6_UN_LOCALSID_NEXT_IP6LOOKUP,
- SRV6_UN_LOCALSID_N_NEXT,
-} srv6_un_localsid_next_t;
-
-/******************************* Local SID node *******************************/
-
-/**
- * @brief Graph node for applying SRv6 uN.
- */
-static uword
-srv6_un_localsid_fn (vlib_main_t * vm,
- vlib_node_runtime_t * node, vlib_frame_t * frame)
-{
- ip6_sr_main_t *sm = &sr_main;
- u32 n_left_from, next_index, *from, *to_next;
-
- from = vlib_frame_vector_args (frame);
- n_left_from = frame->n_vectors;
- next_index = node->cached_next_index;
-
- u32 thread_index = vm->thread_index;
-
- while (n_left_from > 0)
- {
- u32 n_left_to_next;
- vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
-
- /* Quad - Loop */
- while (n_left_from >= 8 && n_left_to_next >= 4)
- {
- u32 bi0, bi1, bi2, bi3;
- vlib_buffer_t *b0, *b1, *b2, *b3;
- ip6_header_t *ip0, *ip1, *ip2, *ip3;
- u32 next0, next1, next2, next3;
- next0 = next1 = next2 = next3 = SRV6_UN_LOCALSID_NEXT_IP6LOOKUP;
- ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3;
-
- /* Prefetch next iteration. */
- {
- vlib_buffer_t *p4, *p5, *p6, *p7;
-
- p4 = vlib_get_buffer (vm, from[4]);
- p5 = vlib_get_buffer (vm, from[5]);
- p6 = vlib_get_buffer (vm, from[6]);
- p7 = vlib_get_buffer (vm, from[7]);
-
- /* Prefetch the buffer header and packet for the N+4 loop iteration */
- vlib_prefetch_buffer_header (p4, LOAD);
- vlib_prefetch_buffer_header (p5, LOAD);
- vlib_prefetch_buffer_header (p6, LOAD);
- vlib_prefetch_buffer_header (p7, LOAD);
-
- CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, STORE);
- CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, STORE);
- CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, STORE);
- CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, STORE);
- }
-
- to_next[0] = bi0 = from[0];
- to_next[1] = bi1 = from[1];
- to_next[2] = bi2 = from[2];
- to_next[3] = bi3 = from[3];
- from += 4;
- to_next += 4;
- n_left_from -= 4;
- n_left_to_next -= 4;
-
- b0 = vlib_get_buffer (vm, bi0);
- b1 = vlib_get_buffer (vm, bi1);
- b2 = vlib_get_buffer (vm, bi2);
- b3 = vlib_get_buffer (vm, bi3);
-
- ls0 =
- pool_elt_at_index (sm->localsids,
- vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
- ls1 =
- pool_elt_at_index (sm->localsids,
- vnet_buffer (b1)->ip.adj_index[VLIB_TX]);
- ls2 =
- pool_elt_at_index (sm->localsids,
- vnet_buffer (b2)->ip.adj_index[VLIB_TX]);
- ls3 =
- pool_elt_at_index (sm->localsids,
- vnet_buffer (b3)->ip.adj_index[VLIB_TX]);
-
- ip0 = vlib_buffer_get_current (b0);
- ip1 = vlib_buffer_get_current (b1);
- ip2 = vlib_buffer_get_current (b2);
- ip3 = vlib_buffer_get_current (b3);
-
- /* Set Destination Address to Last Segment (index 0) */
- ip0->dst_address.as_u16[2] = ip0->dst_address.as_u16[3];
- ip0->dst_address.as_u16[3] = ip0->dst_address.as_u16[4];
- ip0->dst_address.as_u16[4] = ip0->dst_address.as_u16[5];
- ip0->dst_address.as_u16[5] = ip0->dst_address.as_u16[6];
- ip0->dst_address.as_u16[6] = ip0->dst_address.as_u16[7];
- ip0->dst_address.as_u16[7] = 0x0000;
-
- ip1->dst_address.as_u16[2] = ip1->dst_address.as_u16[3];
- ip1->dst_address.as_u16[3] = ip1->dst_address.as_u16[4];
- ip1->dst_address.as_u16[4] = ip1->dst_address.as_u16[5];
- ip1->dst_address.as_u16[5] = ip1->dst_address.as_u16[6];
- ip1->dst_address.as_u16[6] = ip1->dst_address.as_u16[7];
- ip1->dst_address.as_u16[7] = 0x0000;
-
- ip2->dst_address.as_u16[2] = ip2->dst_address.as_u16[3];
- ip2->dst_address.as_u16[3] = ip2->dst_address.as_u16[4];
- ip2->dst_address.as_u16[4] = ip2->dst_address.as_u16[5];
- ip2->dst_address.as_u16[5] = ip2->dst_address.as_u16[6];
- ip2->dst_address.as_u16[6] = ip2->dst_address.as_u16[7];
- ip2->dst_address.as_u16[7] = 0x0000;
-
- ip3->dst_address.as_u16[2] = ip3->dst_address.as_u16[3];
- ip3->dst_address.as_u16[3] = ip3->dst_address.as_u16[4];
- ip3->dst_address.as_u16[4] = ip3->dst_address.as_u16[5];
- ip3->dst_address.as_u16[5] = ip3->dst_address.as_u16[6];
- ip3->dst_address.as_u16[6] = ip3->dst_address.as_u16[7];
- ip3->dst_address.as_u16[7] = 0x0000;
-
- if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- srv6_un_localsid_trace_t *tr =
- vlib_add_trace (vm, node, b0, sizeof (*tr));
- tr->localsid_index = ls0 - sm->localsids;
- }
-
- if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
- {
- srv6_un_localsid_trace_t *tr =
- vlib_add_trace (vm, node, b1, sizeof (*tr));
- tr->localsid_index = ls1 - sm->localsids;
- }
-
- if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED))
- {
- srv6_un_localsid_trace_t *tr =
- vlib_add_trace (vm, node, b2, sizeof (*tr));
- tr->localsid_index = ls2 - sm->localsids;
- }
-
- if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED))
- {
- srv6_un_localsid_trace_t *tr =
- vlib_add_trace (vm, node, b3, sizeof (*tr));
- tr->localsid_index = ls3 - sm->localsids;
- }
-
- vlib_increment_combined_counter
- (&(sm->sr_ls_valid_counters),
- thread_index, ls0 - sm->localsids,
- 1, vlib_buffer_length_in_chain (vm, b0));
-
- vlib_increment_combined_counter
- (&(sm->sr_ls_valid_counters),
- thread_index, ls1 - sm->localsids,
- 1, vlib_buffer_length_in_chain (vm, b1));
-
- vlib_increment_combined_counter
- (&(sm->sr_ls_valid_counters),
- thread_index, ls2 - sm->localsids,
- 1, vlib_buffer_length_in_chain (vm, b2));
-
- vlib_increment_combined_counter
- (&(sm->sr_ls_valid_counters),
- thread_index, ls3 - sm->localsids,
- 1, vlib_buffer_length_in_chain (vm, b3));
-
- vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
- n_left_to_next, bi0, bi1, bi2, bi3,
- next0, next1, next2, next3);
- }
-
- while (n_left_from > 0 && n_left_to_next > 0)
- {
- u32 bi0;
- vlib_buffer_t *b0;
- ip6_header_t *ip0 = 0;
- u32 next0 = SRV6_UN_LOCALSID_NEXT_IP6LOOKUP;
- ip6_sr_localsid_t *ls0;
- bi0 = from[0];
- to_next[0] = bi0;
- from += 1;
- to_next += 1;
- n_left_from -= 1;
- n_left_to_next -= 1;
-
- b0 = vlib_get_buffer (vm, bi0);
- ip0 = vlib_buffer_get_current (b0);
-
- /* Lookup the SR End behavior based on IP DA (adj) */
- ls0 =
- pool_elt_at_index (sm->localsids,
- vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
-
- /* Set Destination Address to Last Segment (index 0) */
- ip0->dst_address.as_u16[2] = ip0->dst_address.as_u16[3];
- ip0->dst_address.as_u16[3] = ip0->dst_address.as_u16[4];
- ip0->dst_address.as_u16[4] = ip0->dst_address.as_u16[5];
- ip0->dst_address.as_u16[5] = ip0->dst_address.as_u16[6];
- ip0->dst_address.as_u16[6] = ip0->dst_address.as_u16[7];
- ip0->dst_address.as_u16[7] = 0x0000;
-
- if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
- {
- srv6_un_localsid_trace_t *tr =
- vlib_add_trace (vm, node, b0, sizeof (*tr));
- tr->localsid_index = ls0 - sm->localsids;
- }
-
- /* This increments the SRv6 per LocalSID counters. */
- vlib_increment_combined_counter
- (&(sm->sr_ls_valid_counters),
- thread_index, ls0 - sm->localsids,
- 1, vlib_buffer_length_in_chain (vm, b0));
-
- vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
- n_left_to_next, bi0, next0);
-
- }
-
- vlib_put_next_frame (vm, node, next_index, n_left_to_next);
- }
-
- return frame->n_vectors;
-}
-
-/* *INDENT-OFF* */
-VLIB_REGISTER_NODE (srv6_un_localsid_node) = {
- .function = srv6_un_localsid_fn,
- .name = "srv6-un-localsid",
- .vector_size = sizeof (u32),
- .format_trace = format_srv6_un_localsid_trace,
- .type = VLIB_NODE_TYPE_INTERNAL,
- .n_next_nodes = SRV6_UN_LOCALSID_N_NEXT,
- .next_nodes = {
- [SRV6_UN_LOCALSID_NEXT_IP6LOOKUP] = "ip6-lookup",
- [SRV6_UN_LOCALSID_NEXT_ERROR] = "error-drop",
- },
-};
-/* *INDENT-ON* */
-
-/*
-* fd.io coding-style-patch-verification: ON
-*
-* Local Variables:
-* eval: (c-set-style "gnu")
-* End:
-*/
diff --git a/src/plugins/srv6-un/un.c b/src/plugins/srv6-un/un.c
deleted file mode 100644
index 7fd02e2c934..00000000000
--- a/src/plugins/srv6-un/un.c
+++ /dev/null
@@ -1,185 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-/*
- *------------------------------------------------------------------
- * un.c - SRv6 Masquerading Proxy (AM) function
- *------------------------------------------------------------------
- */
-
-#include <vnet/vnet.h>
-#include <vnet/adj/adj.h>
-#include <vnet/plugin/plugin.h>
-#include <vpp/app/version.h>
-#include <srv6-un/un.h>
-
-unsigned char function_name[] = "SRv6-uN";
-unsigned char keyword_str[] = "uN(32b+16b)";
-unsigned char def_str[] = "SRv6 uSID uN";
-unsigned char params_str[] = "";
-u8 prefix_length = 48;
-
-srv6_un_main_t srv6_un_main;
-
-/*****************************************/
-/* SRv6 LocalSID instantiation and removal functions */
-static int
-srv6_un_localsid_creation_fn (ip6_sr_localsid_t * localsid)
-{
- srv6_un_localsid_t *ls_mem = localsid->plugin_mem;
- //Nothing to do here.
- ls_mem->shift = 16;
- return 0;
-}
-
-static int
-srv6_un_localsid_removal_fn (ip6_sr_localsid_t * localsid)
-{
- //Nothing to do here.
-
- /* Clean up local SID memory */
- clib_mem_free (localsid->plugin_mem);
-
- return 0;
-}
-
-/**********************************/
-/* SRv6 LocalSID format functions */
-/*
- * Prints nicely the parameters of a localsid
- * Example: print "Table 5"
- */
-u8 *
-format_srv6_un_localsid (u8 * s, va_list * args)
-{
- srv6_un_localsid_t *ls_mem = va_arg (*args, void *);
-
- return (format (s, "Shift:\t\t%u", ls_mem->shift));
-}
-
-/*
- * Process the parameters of a localsid
- * Example: process from:
- * sr localsid address cafe::1 behavior new_srv6_localsid 5
- * everything from behavior on... so in this case 'new_srv6_localsid 5'
- * Notice that it MUST match the keyword_str and params_str defined above.
- */
-uword
-unformat_srv6_un_localsid (unformat_input_t * input, va_list * args)
-{
- void **plugin_mem_p = va_arg (*args, void **);
- srv6_un_localsid_t *ls_mem;
-
- if (unformat (input, "uN(32b+16b)"))
- {
- /* Allocate a portion of memory */
- ls_mem = clib_mem_alloc_aligned_at_offset (sizeof *ls_mem, 0, 0, 1);
-
- /* Set to zero the memory */
- clib_memset (ls_mem, 0, sizeof *ls_mem);
-
- /* Dont forget to add it to the localsid */
- *plugin_mem_p = ls_mem;
- return 1;
- }
- return 0;
-}
-
-/*************************/
-/* SRv6 LocalSID FIB DPO */
-static u8 *
-format_srv6_un_dpo (u8 * s, va_list * args)
-{
- index_t index = va_arg (*args, index_t);
- CLIB_UNUSED (u32 indent) = va_arg (*args, u32);
-
- return (format (s, "SR: shift-and-forward 16b:[%u]", index));
-}
-
-void
-srv6_un_dpo_lock (dpo_id_t * dpo)
-{
-}
-
-void
-srv6_un_dpo_unlock (dpo_id_t * dpo)
-{
-}
-
-const static dpo_vft_t srv6_un_vft = {
- .dv_lock = srv6_un_dpo_lock,
- .dv_unlock = srv6_un_dpo_unlock,
- .dv_format = format_srv6_un_dpo,
-};
-
-const static char *const srv6_un_ip6_nodes[] = {
- "srv6-un-localsid",
- NULL,
-};
-
-const static char *const *const srv6_un_nodes[DPO_PROTO_NUM] = {
- [DPO_PROTO_IP6] = srv6_un_ip6_nodes,
-};
-
-/**********************/
-static clib_error_t *
-srv6_un_init (vlib_main_t * vm)
-{
- srv6_un_main_t *sm = &srv6_un_main;
- int rv = 0;
-
- sm->vlib_main = vm;
- sm->vnet_main = vnet_get_main ();
-
- /* Create DPO */
- sm->srv6_un16_dpo_type =
- dpo_register_new_type (&srv6_un_vft, srv6_un_nodes);
-
- /* Register SRv6 LocalSID */
- rv = sr_localsid_register_function (vm,
- function_name,
- keyword_str,
- def_str,
- params_str,
- prefix_length,
- &sm->srv6_un16_dpo_type,
- format_srv6_un_localsid,
- unformat_srv6_un_localsid,
- srv6_un_localsid_creation_fn,
- srv6_un_localsid_removal_fn);
- if (rv < 0)
- clib_error_return (0, "SRv6 LocalSID function could not be registered.");
- else
- sm->srv6_localsid_behavior_id = rv;
-
- return 0;
-}
-
-
-/* *INDENT-OFF* */
-VLIB_INIT_FUNCTION (srv6_un_init);
-
-VLIB_PLUGIN_REGISTER () = {
- .version = VPP_BUILD_VER,
- .description = "Segment Routing Shift And Forward uN 16b",
-};
-/* *INDENT-ON* */
-
-/*
-* fd.io coding-style-patch-verification: ON
-*
-* Local Variables:
-* eval: (c-set-style "gnu")
-* End:
-*/
diff --git a/src/plugins/srv6-un/un.h b/src/plugins/srv6-un/un.h
deleted file mode 100644
index 750e2350d74..00000000000
--- a/src/plugins/srv6-un/un.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*
- * Copyright (c) 2015 Cisco and/or its affiliates.
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at:
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-#ifndef __included_srv6_un_h__
-#define __included_srv6_un_h__
-
-#include <vnet/vnet.h>
-#include <vnet/ip/ip.h>
-#include <vnet/srv6/sr.h>
-#include <vnet/srv6/sr_packet.h>
-
-#include <vppinfra/error.h>
-#include <vppinfra/elog.h>
-
-typedef struct
-{
- u16 msg_id_base; /**< API message ID base */
-
- vlib_main_t *vlib_main; /**< [convenience] vlib main */
- vnet_main_t *vnet_main; /**< [convenience] vnet main */
-
- dpo_type_t srv6_un16_dpo_type; /**< DPO type */
-
- u32 srv6_localsid_behavior_id; /**< SRv6 LocalSID behavior number */
-} srv6_un_main_t;
-
-/*
- * This is the memory that will be stored per each localsid
- * the user instantiates
- */
-typedef struct
-{
- u16 shift;
-} srv6_un_localsid_t;
-
-extern srv6_un_main_t srv6_un_main;
-
-format_function_t format_srv6_un_localsid;
-unformat_function_t unformat_srv6_un_localsid;
-
-void srv6_un_dpo_lock (dpo_id_t * dpo);
-void srv6_un_dpo_unlock (dpo_id_t * dpo);
-
-extern vlib_node_registration_t srv6_un_localsid_node;
-
-#endif /* __included_srv6_un_h__ */
-
-/*
-* fd.io coding-style-patch-verification: ON
-*
-* Local Variables:
-* eval: (c-set-style "gnu")
-* End:
-*/
diff --git a/src/vnet/srv6/sr.h b/src/vnet/srv6/sr.h
index f804b190135..41adef30818 100755
--- a/src/vnet/srv6/sr.h
+++ b/src/vnet/srv6/sr.h
@@ -43,7 +43,9 @@
#define SR_BEHAVIOR_DX4 7
#define SR_BEHAVIOR_DT6 8
#define SR_BEHAVIOR_DT4 9
-#define SR_BEHAVIOR_LAST 10 /* Must always be the last one */
+#define SR_BEHAVIOR_END_UN_PERF 10
+#define SR_BEHAVIOR_END_UN 11
+#define SR_BEHAVIOR_LAST 12 /* Must always be the last one */
#define SR_STEER_L2 2
#define SR_STEER_IPV4 4
@@ -139,6 +141,15 @@ typedef struct
u32 nh_adj; /**< Next_adj for xconnect usage only */
+ ip6_address_t usid_block;
+ ip6_address_t usid_block_mask;
+
+ u8 usid_index;
+ u8 usid_len;
+
+ u8 usid_next_index;
+ u8 usid_next_len;
+
void *plugin_mem; /**< Memory to be used by the plugin callback functions */
} ip6_sr_localsid_t;
@@ -231,6 +242,13 @@ typedef struct
u32 sr_policy; /**< SR Policy index */
} ip6_sr_steering_policy_t;
+typedef struct
+{
+ ip6_address_t address;
+ u16 pref_len;
+ u8 padding[2];
+} sr_localsid_key_t;
+
/**
* @brief Segment Routing main datastructure
*/
@@ -334,7 +352,7 @@ extern int
sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
u16 localsid_prefix_len, char end_psp, u8 behavior,
u32 sw_if_index, u32 vlan_index, u32 fib_table,
- ip46_address_t * nh_addr, void *ls_plugin_mem);
+ ip46_address_t * nh_addr, int usid_len, void *ls_plugin_mem);
extern int
sr_steering_policy (int is_del, ip6_address_t * bsid, u32 sr_policy_index,
diff --git a/src/vnet/srv6/sr_api.c b/src/vnet/srv6/sr_api.c
index 142b5c2a4b6..43206271291 100644
--- a/src/vnet/srv6/sr_api.c
+++ b/src/vnet/srv6/sr_api.c
@@ -84,7 +84,7 @@ static void vl_api_sr_localsid_add_del_t_handler
mp->behavior,
ntohl (mp->sw_if_index),
ntohl (mp->vlan_index),
- ntohl (mp->fib_table), &prefix, NULL);
+ ntohl (mp->fib_table), &prefix, 0, NULL);
BAD_SW_IF_INDEX_LABEL;
REPLY_MACRO (VL_API_SR_LOCALSID_ADD_DEL_REPLY);
diff --git a/src/vnet/srv6/sr_localsid.c b/src/vnet/srv6/sr_localsid.c
index 4c21edfe0ef..82f5e3b7c1e 100755
--- a/src/vnet/srv6/sr_localsid.c
+++ b/src/vnet/srv6/sr_localsid.c
@@ -45,6 +45,17 @@
*/
static dpo_type_t sr_localsid_dpo_type;
static dpo_type_t sr_localsid_d_dpo_type;
+static dpo_type_t sr_localsid_un_dpo_type;
+static dpo_type_t sr_localsid_un_perf_dpo_type;
+
+static void
+sr_localsid_key_create (sr_localsid_key_t * key, ip6_address_t * addr,
+ u16 pref_len)
+{
+ clib_memset (key, 0, sizeof (sr_localsid_key_t));
+ clib_memcpy (&key->address, addr, sizeof (ip6_address_t));
+ key->pref_len = pref_len;
+}
/**
* @brief SR localsid add/del
@@ -66,20 +77,22 @@ int
sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
u16 localsid_prefix_len, char end_psp, u8 behavior,
u32 sw_if_index, u32 vlan_index, u32 fib_table,
- ip46_address_t * nh_addr, void *ls_plugin_mem)
+ ip46_address_t * nh_addr, int usid_len, void *ls_plugin_mem)
{
ip6_sr_main_t *sm = &sr_main;
uword *p;
int rv;
u8 pref_length = 128;
sr_localsid_fn_registration_t *plugin = 0;
+ sr_localsid_key_t key;
ip6_sr_localsid_t *ls = 0;
dpo_id_t dpo = DPO_INVALID;
/* Search for the item */
- p = mhash_get (&sm->sr_localsids_index_hash, localsid_addr);
+ sr_localsid_key_create (&key, localsid_addr, localsid_prefix_len);
+ p = mhash_get (&sm->sr_localsids_index_hash, &key);
if (p)
{
@@ -125,7 +138,7 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
/* Delete localsid registry */
pool_put (sm->localsids, ls);
- mhash_unset (&sm->sr_localsids_index_hash, localsid_addr, NULL);
+ mhash_unset (&sm->sr_localsids_index_hash, &key, NULL);
return 0;
}
else /* create with function already existing; complain */
@@ -183,6 +196,23 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
{
case SR_BEHAVIOR_END:
break;
+ case SR_BEHAVIOR_END_UN:
+ case SR_BEHAVIOR_END_UN_PERF:
+ if (usid_len)
+ {
+ int usid_width;
+ clib_memcpy (&ls->usid_block, localsid_addr,
+ sizeof (ip6_address_t));
+
+ usid_width = pref_length - usid_len;
+ ip6_address_mask_from_width (&ls->usid_block_mask, usid_width);
+
+ ls->usid_index = usid_width / 8;
+ ls->usid_len = usid_len / 8;
+ ls->usid_next_index = ls->usid_index + ls->usid_len;
+ ls->usid_next_len = 16 - ls->usid_next_index;
+ }
+ break;
case SR_BEHAVIOR_X:
ls->sw_if_index = sw_if_index;
clib_memcpy (&ls->next_hop.ip6, &nh_addr->ip6, sizeof (ip6_address_t));
@@ -239,6 +269,12 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
if (ls->behavior == SR_BEHAVIOR_END || ls->behavior == SR_BEHAVIOR_X
|| ls->behavior == SR_BEHAVIOR_T)
dpo_set (&dpo, sr_localsid_dpo_type, DPO_PROTO_IP6, ls - sm->localsids);
+ else if (ls->behavior == SR_BEHAVIOR_END_UN)
+ dpo_set (&dpo, sr_localsid_un_dpo_type, DPO_PROTO_IP6,
+ ls - sm->localsids);
+ else if (ls->behavior == SR_BEHAVIOR_END_UN_PERF)
+ dpo_set (&dpo, sr_localsid_un_perf_dpo_type, DPO_PROTO_IP6,
+ ls - sm->localsids);
else if (ls->behavior > SR_BEHAVIOR_D_FIRST
&& ls->behavior < SR_BEHAVIOR_LAST)
dpo_set (&dpo, sr_localsid_d_dpo_type, DPO_PROTO_IP6, ls - sm->localsids);
@@ -260,8 +296,7 @@ sr_cli_localsid (char is_del, ip6_address_t * localsid_addr,
}
/* Set hash key for searching localsid by address */
- mhash_set (&sm->sr_localsids_index_hash, localsid_addr, ls - sm->localsids,
- NULL);
+ mhash_set (&sm->sr_localsids_index_hash, &key, ls - sm->localsids, NULL);
fib_table_entry_special_dpo_add (fib_index, &pfx, FIB_SOURCE_SR,
FIB_ENTRY_FLAG_EXCLUSIVE, &dpo);
@@ -301,6 +336,7 @@ sr_cli_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input,
char address_set = 0;
char behavior = 0;
void *ls_plugin_mem = 0;
+ int usid_size = 0;
int rv;
@@ -349,6 +385,10 @@ sr_cli_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input,
behavior = SR_BEHAVIOR_DT6;
else if (unformat (input, "end.dt4 %u", &sw_if_index))
behavior = SR_BEHAVIOR_DT4;
+ else if (unformat (input, "un %u", &usid_size))
+ behavior = SR_BEHAVIOR_END_UN_PERF;
+ else if (unformat (input, "un.flex %u", &usid_size))
+ behavior = SR_BEHAVIOR_END_UN;
else
{
/* Loop over all the plugin behavior format functions */
@@ -391,6 +431,22 @@ sr_cli_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input,
if (!behavior && end_psp)
behavior = SR_BEHAVIOR_END;
+ if (usid_size)
+ {
+ if (prefix_len < usid_size)
+ return clib_error_return (0,
+ "Error: Prefix length must be greater"
+ " than uSID length.");
+
+ if (usid_size != 16 && usid_size != 32)
+ return clib_error_return (0,
+ "Error: Invalid uSID length (16 or 32).");
+
+ if ((prefix_len - usid_size) & 0x7)
+ return clib_error_return (0,
+ "Error: Prefix Length must be multiple of 8.");
+ }
+
if (!address_set)
return clib_error_return (0,
"Error: SRv6 LocalSID address is mandatory.");
@@ -407,7 +463,19 @@ sr_cli_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input,
rv =
sr_cli_localsid (is_del, &resulting_address, prefix_len, end_psp,
behavior, sw_if_index, vlan_index, fib_index, &next_hop,
- ls_plugin_mem);
+ usid_size, ls_plugin_mem);
+
+ if (behavior == SR_BEHAVIOR_END_UN_PERF)
+ {
+ if (rv == 0)
+ {
+ u16 perf_len;
+ perf_len = prefix_len + usid_size;
+ rv = sr_cli_localsid (is_del, &resulting_address, perf_len, end_psp,
+ SR_BEHAVIOR_END, sw_if_index, vlan_index,
+ fib_index, &next_hop, 0, ls_plugin_mem);
+ }
+ }
switch (rv)
{
@@ -451,6 +519,7 @@ VLIB_CLI_COMMAND (sr_localsid_command, static) = {
"\tbehavior STRING Specifies the behavior\n"
"\n\tBehaviors:\n"
"\tEnd\t-> Endpoint.\n"
+ "\tEnd.uN\t-> Endpoint with uSID.\n"
"\tEnd.X\t-> Endpoint with decapsulation and Layer-3 cross-connect.\n"
"\t\tParameters: '<iface> <ip6_next_hop>'\n"
"\tEnd.DX2\t-> Endpoint with decapsulation and Layer-2 cross-connect.\n"
@@ -491,9 +560,22 @@ show_sr_localsid_command_fn (vlib_main_t * vm, unformat_input_t * input,
switch (ls->behavior)
{
case SR_BEHAVIOR_END:
- vlib_cli_output (vm, "\tAddress: \t%U/%u\n\tBehavior: \tEnd",
+ vlib_cli_output (vm, "\tAddress: \t%U\n\tBehavior: \tEnd",
+ format_ip6_address, &ls->localsid);
+ break;
+ case SR_BEHAVIOR_END_UN:
+ vlib_cli_output (vm,
+ "\tAddress: \t%U\n\tBehavior: \tEnd (flex) [uSID:\t%U/%d, length: %d]",
+ format_ip6_address, &ls->localsid,
+ format_ip6_address, &ls->usid_block,
+ ls->usid_index * 8, ls->usid_len * 8);
+ break;
+ case SR_BEHAVIOR_END_UN_PERF:
+ vlib_cli_output (vm,
+ "\tAddress: \t%U\n\tBehavior: \tEnd [uSID:\t%U/%d, length: %d]",
format_ip6_address, &ls->localsid,
- ls->localsid_prefix_len);
+ format_ip6_address, &ls->usid_block,
+ ls->usid_index * 8, ls->usid_len * 8);
break;
case SR_BEHAVIOR_X:
vlib_cli_output (vm,
@@ -697,6 +779,12 @@ format_sr_localsid_trace (u8 * s, va_list * args)
case SR_BEHAVIOR_END:
s = format (s, "\tBehavior: End\n");
break;
+ case SR_BEHAVIOR_END_UN:
+ s = format (s, "\tBehavior: End.uN (flex)\n");
+ break;
+ case SR_BEHAVIOR_END_UN_PERF:
+ s = format (s, "\tBehavior: End.uN\n");
+ break;
case SR_BEHAVIOR_DX6:
s = format (s, "\tBehavior: Decapsulation with IPv6 L3 xconnect\n");
break;
@@ -837,6 +925,147 @@ end_srh_processing (vlib_node_runtime_t * node,
}
}
+/**
+ * @brief Function doing End uN processing.
+ */
+static_always_inline void
+end_un_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)
+{
+ ip6_address_t *new_dst0;
+ bool next_usid = false;
+ u8 next_usid_index;
+ u8 usid_len;
+ u8 index;
+
+ usid_len = ls0->usid_len;
+ next_usid_index = ls0->usid_next_index;
+
+ /* uSID */
+ for (index = 0; index < usid_len; index++)
+ {
+ if (ip0->dst_address.as_u8[next_usid_index + index] != 0)
+ {
+ next_usid = true;
+ break;
+ }
+ }
+
+ if (PREDICT_TRUE (next_usid))
+ {
+ u8 offset;
+
+ index = ls0->usid_index;
+
+ /* advance next usid */
+ for (offset = 0; offset < ls0->usid_next_len; offset++)
+ {
+ ip0->dst_address.as_u8[index + offset] =
+ ip0->dst_address.as_u8[next_usid_index + offset];
+ }
+
+ for (index = 16 - usid_len; index < 16; index++)
+ {
+ ip0->dst_address.as_u8[index] = 0;
+ }
+
+ return;
+ }
+
+ if (PREDICT_TRUE (sr0 && sr0->type == ROUTING_HEADER_TYPE_SR))
+ {
+ if (sr0->segments_left == 1 && psp)
+ {
+ u32 new_l0, sr_len;
+ u64 *copy_dst0, *copy_src0;
+ u32 copy_len_u64s0 = 0;
+
+ ip0->dst_address.as_u64[0] = sr0->segments->as_u64[0];
+ ip0->dst_address.as_u64[1] = sr0->segments->as_u64[1];
+
+ /* Remove the SRH taking care of the rest of IPv6 ext header */
+ if (prev0)
+ prev0->next_hdr = sr0->protocol;
+ else
+ ip0->protocol = sr0->protocol;
+
+ sr_len = ip6_ext_header_len (sr0);
+ vlib_buffer_advance (b0, sr_len);
+ new_l0 = clib_net_to_host_u16 (ip0->payload_length) - sr_len;
+ ip0->payload_length = clib_host_to_net_u16 (new_l0);
+ copy_src0 = (u64 *) ip0;
+ copy_dst0 = copy_src0 + (sr0->length + 1);
+ /* number of 8 octet units to copy
+ * By default in absence of extension headers it is equal to length of ip6 header
+ * With extension headers it number of 8 octet units of ext headers preceding
+ * SR header
+ */
+ copy_len_u64s0 =
+ (((u8 *) sr0 - (u8 *) ip0) - sizeof (ip6_header_t)) >> 3;
+ copy_dst0[4 + copy_len_u64s0] = copy_src0[4 + copy_len_u64s0];
+ copy_dst0[3 + copy_len_u64s0] = copy_src0[3 + copy_len_u64s0];
+ copy_dst0[2 + copy_len_u64s0] = copy_src0[2 + copy_len_u64s0];
+ copy_dst0[1 + copy_len_u64s0] = copy_src0[1 + copy_len_u64s0];
+ copy_dst0[0 + copy_len_u64s0] = copy_src0[0 + copy_len_u64s0];
+
+ int i;
+ for (i = copy_len_u64s0 - 1; i >= 0; i--)
+ {
+ copy_dst0[i] = copy_src0[i];
+ }
+ }
+ else if (PREDICT_TRUE (sr0->segments_left > 0))
+ {
+ sr0->segments_left -= 1;
+ new_dst0 = (ip6_address_t *) (sr0->segments);
+ new_dst0 += sr0->segments_left;
+ ip0->dst_address.as_u64[0] = new_dst0->as_u64[0];
+ ip0->dst_address.as_u64[1] = new_dst0->as_u64[1];
+ }
+ else
+ {
+ *next0 = SR_LOCALSID_NEXT_ERROR;
+ b0->error = node->errors[SR_LOCALSID_ERROR_NO_MORE_SEGMENTS];
+ }
+ }
+ else
+ {
+ /* Error. Routing header of type != SR */
+ *next0 = SR_LOCALSID_NEXT_ERROR;
+ b0->error = node->errors[SR_LOCALSID_ERROR_NO_SRH];
+ }
+}
+
+static_always_inline void
+end_un_processing (ip6_header_t * ip0, ip6_sr_localsid_t * ls0)
+{
+ u8 next_usid_index;
+ u8 index;
+ u8 offset;
+
+ /* uSID */
+ index = ls0->usid_index;
+ next_usid_index = ls0->usid_next_index;
+
+ /* advance next usid */
+ for (offset = 0; offset < ls0->usid_next_len; offset++)
+ {
+ ip0->dst_address.as_u8[index + offset] =
+ ip0->dst_address.as_u8[next_usid_index + offset];
+ }
+
+ for (index = 16 - ls0->usid_len; index < 16; index++)
+ {
+ ip0->dst_address.as_u8[index] = 0;
+ }
+
+ return;
+}
+
/*
* @brief Function doing SRH processing for D* variants
*/
@@ -1537,6 +1766,538 @@ VLIB_REGISTER_NODE (sr_localsid_node) = {
};
/* *INDENT-ON* */
+/**
+ * @brief SR LocalSID uN graph node. Supports all default SR Endpoint without decaps
+ */
+static uword
+sr_localsid_un_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * from_frame)
+{
+ u32 n_left_from, next_index, *from, *to_next;
+ ip6_sr_main_t *sm = &sr_main;
+ from = vlib_frame_vector_args (from_frame);
+ n_left_from = from_frame->n_vectors;
+ next_index = node->cached_next_index;
+ u32 thread_index = vm->thread_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ /* Quad - Loop */
+ while (n_left_from >= 8 && n_left_to_next >= 4)
+ {
+ u32 bi0, bi1, bi2, bi3;
+ vlib_buffer_t *b0, *b1, *b2, *b3;
+ ip6_header_t *ip0, *ip1, *ip2, *ip3;
+ ip6_sr_header_t *sr0, *sr1, *sr2, *sr3;
+ ip6_ext_header_t *prev0, *prev1, *prev2, *prev3;
+ u32 next0, next1, next2, next3;
+ next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP;
+ ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3;
+
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t *p4, *p5, *p6, *p7;
+
+ p4 = vlib_get_buffer (vm, from[4]);
+ p5 = vlib_get_buffer (vm, from[5]);
+ p6 = vlib_get_buffer (vm, from[6]);
+ p7 = vlib_get_buffer (vm, from[7]);
+
+ /* Prefetch the buffer header and packet for the N+2 loop iteration */
+ vlib_prefetch_buffer_header (p4, LOAD);
+ vlib_prefetch_buffer_header (p5, LOAD);
+ vlib_prefetch_buffer_header (p6, LOAD);
+ vlib_prefetch_buffer_header (p7, LOAD);
+
+ CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, STORE);
+ }
+
+ to_next[0] = bi0 = from[0];
+ to_next[1] = bi1 = from[1];
+ to_next[2] = bi2 = from[2];
+ to_next[3] = bi3 = from[3];
+ from += 4;
+ to_next += 4;
+ n_left_from -= 4;
+ n_left_to_next -= 4;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ b1 = vlib_get_buffer (vm, bi1);
+ b2 = vlib_get_buffer (vm, bi2);
+ b3 = vlib_get_buffer (vm, bi3);
+
+ ip0 = vlib_buffer_get_current (b0);
+ ip1 = vlib_buffer_get_current (b1);
+ ip2 = vlib_buffer_get_current (b2);
+ ip3 = vlib_buffer_get_current (b3);
+
+ sr0 =
+ ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, &prev0);
+ sr1 =
+ ip6_ext_header_find (vm, b1, ip1, IP_PROTOCOL_IPV6_ROUTE, &prev1);
+ sr2 =
+ ip6_ext_header_find (vm, b2, ip2, IP_PROTOCOL_IPV6_ROUTE, &prev2);
+ sr3 =
+ ip6_ext_header_find (vm, b3, ip3, IP_PROTOCOL_IPV6_ROUTE, &prev3);
+
+ ls0 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+ ls1 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b1)->ip.adj_index[VLIB_TX]);
+ ls2 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b2)->ip.adj_index[VLIB_TX]);
+ ls3 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b3)->ip.adj_index[VLIB_TX]);
+
+ end_un_srh_processing (node, b0, ip0, sr0, ls0, &next0,
+ ls0->end_psp, prev0);
+ end_un_srh_processing (node, b1, ip1, sr1, ls1, &next1,
+ ls1->end_psp, prev1);
+ end_un_srh_processing (node, b2, ip2, sr2, ls2, &next2,
+ ls2->end_psp, prev2);
+ end_un_srh_processing (node, b3, ip3, sr3, ls3, &next3,
+ ls3->end_psp, prev3);
+
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls0->behavior;
+ if (ip0 == vlib_buffer_get_current (b0))
+ {
+ if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
+ && sr0->type == ROUTING_HEADER_TYPE_SR)
+ {
+ clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
+ tr->num_segments =
+ sr0->length * 8 / sizeof (ip6_address_t);
+ tr->segments_left = sr0->segments_left;
+ }
+ }
+ else
+ tr->num_segments = 0xFF;
+ }
+
+ if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b1, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls1->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls1->behavior;
+ if (ip1 == vlib_buffer_get_current (b1))
+ {
+ if (ip1->protocol == IP_PROTOCOL_IPV6_ROUTE
+ && sr1->type == ROUTING_HEADER_TYPE_SR)
+ {
+ clib_memcpy (tr->sr, sr1->segments, sr1->length * 8);
+ tr->num_segments =
+ sr1->length * 8 / sizeof (ip6_address_t);
+ tr->segments_left = sr1->segments_left;
+ }
+ }
+ else
+ tr->num_segments = 0xFF;
+ }
+
+ if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b2, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls2->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls2->behavior;
+ if (ip2 == vlib_buffer_get_current (b2))
+ {
+ if (ip2->protocol == IP_PROTOCOL_IPV6_ROUTE
+ && sr2->type == ROUTING_HEADER_TYPE_SR)
+ {
+ clib_memcpy (tr->sr, sr2->segments, sr2->length * 8);
+ tr->num_segments =
+ sr2->length * 8 / sizeof (ip6_address_t);
+ tr->segments_left = sr2->segments_left;
+ }
+ }
+ else
+ tr->num_segments = 0xFF;
+ }
+
+ if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b3, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls3->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls3->behavior;
+ if (ip3 == vlib_buffer_get_current (b3))
+ {
+ if (ip3->protocol == IP_PROTOCOL_IPV6_ROUTE
+ && sr3->type == ROUTING_HEADER_TYPE_SR)
+ {
+ clib_memcpy (tr->sr, sr3->segments, sr3->length * 8);
+ tr->num_segments =
+ sr3->length * 8 / sizeof (ip6_address_t);
+ tr->segments_left = sr3->segments_left;
+ }
+ }
+ else
+ tr->num_segments = 0xFF;
+ }
+
+ vlib_increment_combined_counter
+ (((next0 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b0));
+
+ vlib_increment_combined_counter
+ (((next1 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls1 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b1));
+
+ vlib_increment_combined_counter
+ (((next2 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls2 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b2));
+
+ vlib_increment_combined_counter
+ (((next3 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls3 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b3));
+
+ vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, bi1, bi2, bi3,
+ next0, next1, next2, next3);
+ }
+
+ /* Single loop for potentially the last three packets */
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ ip6_header_t *ip0 = 0;
+ ip6_ext_header_t *prev0;
+ ip6_sr_header_t *sr0;
+ u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP;
+ ip6_sr_localsid_t *ls0;
+
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ ip0 = vlib_buffer_get_current (b0);
+ sr0 =
+ ip6_ext_header_find (vm, b0, ip0, IP_PROTOCOL_IPV6_ROUTE, &prev0);
+
+ /* Lookup the SR End behavior based on IP DA (adj) */
+ ls0 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+
+ /* SRH processing */
+ end_un_srh_processing (node, b0, ip0, sr0, ls0, &next0,
+ ls0->end_psp, prev0);
+
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls0->behavior;
+ if (ip0 == vlib_buffer_get_current (b0))
+ {
+ if (ip0->protocol == IP_PROTOCOL_IPV6_ROUTE
+ && sr0->type == ROUTING_HEADER_TYPE_SR)
+ {
+ clib_memcpy (tr->sr, sr0->segments, sr0->length * 8);
+ tr->num_segments =
+ sr0->length * 8 / sizeof (ip6_address_t);
+ tr->segments_left = sr0->segments_left;
+ }
+ }
+ else
+ tr->num_segments = 0xFF;
+ }
+
+ vlib_increment_combined_counter
+ (((next0 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b0));
+
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+ return from_frame->n_vectors;
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (sr_localsid_un_node) = {
+ .function = sr_localsid_un_fn,
+ .name = "sr-localsid-un",
+ .vector_size = sizeof (u32),
+ .format_trace = format_sr_localsid_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = SR_LOCALSID_N_ERROR,
+ .error_strings = sr_localsid_error_strings,
+ .n_next_nodes = SR_LOCALSID_N_NEXT,
+ .next_nodes = {
+#define _(s,n) [SR_LOCALSID_NEXT_##s] = n,
+ foreach_sr_localsid_next
+#undef _
+ },
+};
+/* *INDENT-ON* */
+
+static uword
+sr_localsid_un_perf_fn (vlib_main_t * vm, vlib_node_runtime_t * node,
+ vlib_frame_t * from_frame)
+{
+ u32 n_left_from, next_index, *from, *to_next;
+ ip6_sr_main_t *sm = &sr_main;
+ from = vlib_frame_vector_args (from_frame);
+ n_left_from = from_frame->n_vectors;
+ next_index = node->cached_next_index;
+ u32 thread_index = vm->thread_index;
+
+ while (n_left_from > 0)
+ {
+ u32 n_left_to_next;
+ vlib_get_next_frame (vm, node, next_index, to_next, n_left_to_next);
+
+ /* Quad - Loop */
+ while (n_left_from >= 8 && n_left_to_next >= 4)
+ {
+ u32 bi0, bi1, bi2, bi3;
+ vlib_buffer_t *b0, *b1, *b2, *b3;
+ ip6_header_t *ip0, *ip1, *ip2, *ip3;
+ u32 next0, next1, next2, next3;
+ next0 = next1 = next2 = next3 = SR_LOCALSID_NEXT_IP6_LOOKUP;
+ ip6_sr_localsid_t *ls0, *ls1, *ls2, *ls3;
+
+ /* Prefetch next iteration. */
+ {
+ vlib_buffer_t *p4, *p5, *p6, *p7;
+
+ p4 = vlib_get_buffer (vm, from[4]);
+ p5 = vlib_get_buffer (vm, from[5]);
+ p6 = vlib_get_buffer (vm, from[6]);
+ p7 = vlib_get_buffer (vm, from[7]);
+
+ /* Prefetch the buffer header and packet for the N+2 loop iteration */
+ vlib_prefetch_buffer_header (p4, LOAD);
+ vlib_prefetch_buffer_header (p5, LOAD);
+ vlib_prefetch_buffer_header (p6, LOAD);
+ vlib_prefetch_buffer_header (p7, LOAD);
+
+ CLIB_PREFETCH (p4->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p5->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p6->data, CLIB_CACHE_LINE_BYTES, STORE);
+ CLIB_PREFETCH (p7->data, CLIB_CACHE_LINE_BYTES, STORE);
+ }
+
+ to_next[0] = bi0 = from[0];
+ to_next[1] = bi1 = from[1];
+ to_next[2] = bi2 = from[2];
+ to_next[3] = bi3 = from[3];
+ from += 4;
+ to_next += 4;
+ n_left_from -= 4;
+ n_left_to_next -= 4;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ b1 = vlib_get_buffer (vm, bi1);
+ b2 = vlib_get_buffer (vm, bi2);
+ b3 = vlib_get_buffer (vm, bi3);
+
+ ip0 = vlib_buffer_get_current (b0);
+ ip1 = vlib_buffer_get_current (b1);
+ ip2 = vlib_buffer_get_current (b2);
+ ip3 = vlib_buffer_get_current (b3);
+
+ ls0 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+ ls1 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b1)->ip.adj_index[VLIB_TX]);
+ ls2 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b2)->ip.adj_index[VLIB_TX]);
+ ls3 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b3)->ip.adj_index[VLIB_TX]);
+
+ end_un_processing (ip0, ls0);
+ end_un_processing (ip1, ls1);
+ end_un_processing (ip2, ls2);
+ end_un_processing (ip3, ls3);
+
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls0->behavior;
+ }
+
+ if (PREDICT_FALSE (b1->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b1, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls1->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls1->behavior;
+ }
+
+ if (PREDICT_FALSE (b2->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b2, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls2->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls2->behavior;
+ }
+
+ if (PREDICT_FALSE (b3->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b3, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls3->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls3->behavior;
+ }
+
+ vlib_increment_combined_counter
+ (((next0 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b0));
+
+ vlib_increment_combined_counter
+ (((next1 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls1 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b1));
+
+ vlib_increment_combined_counter
+ (((next2 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls2 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b2));
+
+ vlib_increment_combined_counter
+ (((next3 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls3 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b3));
+
+ vlib_validate_buffer_enqueue_x4 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, bi1, bi2, bi3,
+ next0, next1, next2, next3);
+ }
+
+ /* Single loop for potentially the last three packets */
+ while (n_left_from > 0 && n_left_to_next > 0)
+ {
+ u32 bi0;
+ vlib_buffer_t *b0;
+ ip6_header_t *ip0 = 0;
+ u32 next0 = SR_LOCALSID_NEXT_IP6_LOOKUP;
+ ip6_sr_localsid_t *ls0;
+
+ bi0 = from[0];
+ to_next[0] = bi0;
+ from += 1;
+ to_next += 1;
+ n_left_from -= 1;
+ n_left_to_next -= 1;
+
+ b0 = vlib_get_buffer (vm, bi0);
+ ip0 = vlib_buffer_get_current (b0);
+
+ /* Lookup the SR End behavior based on IP DA (adj) */
+ ls0 =
+ pool_elt_at_index (sm->localsids,
+ vnet_buffer (b0)->ip.adj_index[VLIB_TX]);
+
+ /* SRH processing */
+ end_un_processing (ip0, ls0);
+
+ if (PREDICT_FALSE (b0->flags & VLIB_BUFFER_IS_TRACED))
+ {
+ sr_localsid_trace_t *tr =
+ vlib_add_trace (vm, node, b0, sizeof (*tr));
+ tr->num_segments = 0;
+ clib_memcpy (tr->localsid.as_u8, ls0->localsid.as_u8,
+ sizeof (tr->localsid.as_u8));
+ tr->behavior = ls0->behavior;
+ }
+
+ vlib_increment_combined_counter
+ (((next0 ==
+ SR_LOCALSID_NEXT_ERROR) ? &(sm->sr_ls_invalid_counters) :
+ &(sm->sr_ls_valid_counters)), thread_index, ls0 - sm->localsids,
+ 1, vlib_buffer_length_in_chain (vm, b0));
+
+ vlib_validate_buffer_enqueue_x1 (vm, node, next_index, to_next,
+ n_left_to_next, bi0, next0);
+ }
+ vlib_put_next_frame (vm, node, next_index, n_left_to_next);
+ }
+ return from_frame->n_vectors;
+}
+
+/* *INDENT-OFF* */
+VLIB_REGISTER_NODE (sr_localsid_un_perf_node) = {
+ .function = sr_localsid_un_perf_fn,
+ .name = "sr-localsid-un-perf",
+ .vector_size = sizeof (u32),
+ .format_trace = format_sr_localsid_trace,
+ .type = VLIB_NODE_TYPE_INTERNAL,
+ .n_errors = SR_LOCALSID_N_ERROR,
+ .error_strings = sr_localsid_error_strings,
+ .n_next_nodes = SR_LOCALSID_N_NEXT,
+ .next_nodes = {
+#define _(s,n) [SR_LOCALSID_NEXT_##s] = n,
+ foreach_sr_localsid_next
+#undef _
+ },
+};
+/* *INDENT-ON* */
+
static u8 *
format_sr_dpo (u8 * s, va_list * args)
{
@@ -1570,6 +2331,23 @@ const static char *const *const sr_loc_d_nodes[DPO_PROTO_NUM] = {
[DPO_PROTO_IP6] = sr_loc_d_ip6_nodes,
};
+const static char *const sr_loc_un_ip6_nodes[] = {
+ "sr-localsid-un",
+ NULL,
+};
+
+const static char *const *const sr_loc_un_nodes[DPO_PROTO_NUM] = {
+ [DPO_PROTO_IP6] = sr_loc_un_ip6_nodes,
+};
+
+const static char *const sr_loc_un_perf_ip6_nodes[] = {
+ "sr-localsid-un-perf",
+ NULL,
+};
+
+const static char *const *const sr_loc_un_perf_nodes[DPO_PROTO_NUM] = {
+ [DPO_PROTO_IP6] = sr_loc_un_perf_ip6_nodes,
+};
/*************************** SR LocalSID plugins ******************************/
/**
@@ -1688,12 +2466,17 @@ sr_localsids_init (vlib_main_t * vm)
/* Init memory for function keys */
ip6_sr_main_t *sm = &sr_main;
mhash_init (&sm->sr_localsids_index_hash, sizeof (uword),
- sizeof (ip6_address_t));
+ sizeof (sr_localsid_key_t));
/* Init SR behaviors DPO type */
sr_localsid_dpo_type = dpo_register_new_type (&sr_loc_vft, sr_loc_nodes);
/* Init SR behaviors DPO type */
sr_localsid_d_dpo_type =
dpo_register_new_type (&sr_loc_vft, sr_loc_d_nodes);
+ /* Init SR bhaviors DPO type */
+ sr_localsid_un_dpo_type =
+ dpo_register_new_type (&sr_loc_vft, sr_loc_un_nodes);
+ sr_localsid_un_perf_dpo_type =
+ dpo_register_new_type (&sr_loc_vft, sr_loc_un_perf_nodes);
/* Init memory for localsid plugins */
sm->plugin_functions_by_key = hash_create_string (0, sizeof (uword));
return 0;