diff options
author | Neale Ranns <nranns@cisco.com> | 2019-07-19 11:44:53 +0000 |
---|---|---|
committer | Damjan Marion <dmarion@me.com> | 2019-07-24 14:42:27 +0000 |
commit | 1dbcf30b7d9691e9223c71c5fa594e7831e4ea32 (patch) | |
tree | d722f71afdac2ef8e86be5501e5fd89fc41e6364 /src/vnet | |
parent | 1e5ca9b918dfe988eb0247ec35fc188bfabb4dcb (diff) |
fib: Support the POP of a Psuedo Wire Control Word
Type: feature
Change-Id: Ib24547a7c4c73ceb5383d1ca8f14ec40e6a90f01
Signed-off-by: Neale Ranns <nranns@cisco.com>
Diffstat (limited to 'src/vnet')
-rw-r--r-- | src/vnet/CMakeLists.txt | 1 | ||||
-rw-r--r-- | src/vnet/dpo/dpo.c | 2 | ||||
-rw-r--r-- | src/vnet/dpo/dpo.h | 2 | ||||
-rw-r--r-- | src/vnet/dpo/pw_cw.c | 315 | ||||
-rw-r--r-- | src/vnet/dpo/pw_cw.h | 80 | ||||
-rw-r--r-- | src/vnet/fib/fib_api.c | 2 | ||||
-rw-r--r-- | src/vnet/fib/fib_path.c | 13 | ||||
-rw-r--r-- | src/vnet/fib/fib_path.h | 8 | ||||
-rw-r--r-- | src/vnet/fib/fib_types.api | 6 | ||||
-rw-r--r-- | src/vnet/fib/fib_types.c | 4 | ||||
-rw-r--r-- | src/vnet/fib/fib_types.h | 5 |
11 files changed, 435 insertions, 3 deletions
diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt index 68e806ed412..91a5a77dc00 100644 --- a/src/vnet/CMakeLists.txt +++ b/src/vnet/CMakeLists.txt @@ -1365,6 +1365,7 @@ list(APPEND VNET_SOURCES dpo/mpls_label_dpo.c dpo/l3_proxy_dpo.c dpo/dvr_dpo.c + dpo/pw_cw.c ) list(APPEND VNET_MULTIARCH_SOURCES diff --git a/src/vnet/dpo/dpo.c b/src/vnet/dpo/dpo.c index 13ae37a74a8..d5865d13a1d 100644 --- a/src/vnet/dpo/dpo.c +++ b/src/vnet/dpo/dpo.c @@ -43,6 +43,7 @@ #include <vnet/dpo/dvr_dpo.h> #include <vnet/dpo/l3_proxy_dpo.h> #include <vnet/dpo/ip6_ll_dpo.h> +#include <vnet/dpo/pw_cw.h> /** * Array of char* names for the DPO types and protos @@ -588,6 +589,7 @@ dpo_module_init (vlib_main_t * vm) mpls_disp_dpo_module_init(); dvr_dpo_module_init(); l3_proxy_dpo_module_init(); + pw_cw_dpo_module_init(); return (NULL); } diff --git a/src/vnet/dpo/dpo.h b/src/vnet/dpo/dpo.h index 0eeca67b74b..73ad9ad0ff0 100644 --- a/src/vnet/dpo/dpo.h +++ b/src/vnet/dpo/dpo.h @@ -124,6 +124,7 @@ typedef enum dpo_type_t_ { DPO_BIER_DISP_TABLE, DPO_BIER_DISP_ENTRY, DPO_IP6_LL, + DPO_PW_CW, DPO_LAST, } __attribute__((packed)) dpo_type_t; @@ -159,6 +160,7 @@ typedef enum dpo_type_t_ { [DPO_BIER_DISP_ENTRY] = "bier-disp-entry", \ [DPO_BIER_DISP_TABLE] = "bier-disp-table", \ [DPO_IP6_LL] = "ip6-link-local", \ + [DPO_PW_CW] = "PW-CW", \ } /** diff --git a/src/vnet/dpo/pw_cw.c b/src/vnet/dpo/pw_cw.c new file mode 100644 index 00000000000..8c16c33cf24 --- /dev/null +++ b/src/vnet/dpo/pw_cw.c @@ -0,0 +1,315 @@ +/* + * Copyright (c) 2016 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 <vnet/dpo/pw_cw.h> +#include <vnet/fib/fib_node.h> + +#ifndef CLIB_MARCH_VARIANT + +/* + * pool of all MPLS Label DPOs + */ +pw_cw_dpo_t *pw_cw_dpo_pool; + +static pw_cw_dpo_t * +pw_cw_dpo_alloc (void) +{ + pw_cw_dpo_t *pwcw; + + pool_get_aligned_zero(pw_cw_dpo_pool, pwcw, 8); + + return (pwcw); +} + +static index_t +pw_cw_dpo_get_index (pw_cw_dpo_t *pwcw) +{ + return (pwcw - pw_cw_dpo_pool); +} + +void +pw_cw_dpo_create (const dpo_id_t *parent, + dpo_id_t *dpo) +{ + pw_cw_dpo_t *pwcw; + + pwcw = pw_cw_dpo_alloc(); + + /* + * stack this disposition object on the parent given + */ + dpo_stack(DPO_PW_CW, + parent->dpoi_proto, + &pwcw->pwcw_parent, + parent); + + /* + * set up the return DPO to refer to this object + */ + dpo_set(dpo, + DPO_PW_CW, + parent->dpoi_proto, + pw_cw_dpo_get_index(pwcw)); +} + +u8* +format_pw_cw_dpo (u8 *s, va_list *args) +{ + index_t pwcwi = va_arg (*args, index_t); + u32 indent = va_arg (*args, u32); + pw_cw_dpo_t *pwcw; + + if (pool_is_free_index(pw_cw_dpo_pool, pwcwi)) + { + /* + * the packet trace can be printed after the DPO has been deleted + */ + return (format(s, "pw-cw[???,%d]:", pwcwi)); + } + + pwcw = pw_cw_dpo_get(pwcwi); + s = format(s, "pw-cw[%d]:", pwcwi); + + s = format(s, "\n%U", format_white_space, indent); + s = format(s, "%U", format_dpo_id, &pwcw->pwcw_parent, indent+2); + + return (s); +} + +static void +pw_cw_dpo_lock (dpo_id_t *dpo) +{ + pw_cw_dpo_t *pwcw; + + pwcw = pw_cw_dpo_get(dpo->dpoi_index); + + pwcw->pwcw_locks++; +} + +static void +pw_cw_dpo_unlock (dpo_id_t *dpo) +{ + pw_cw_dpo_t *pwcw; + + pwcw = pw_cw_dpo_get(dpo->dpoi_index); + + pwcw->pwcw_locks--; + + if (0 == pwcw->pwcw_locks) + { + dpo_reset(&pwcw->pwcw_parent); + pool_put(pw_cw_dpo_pool, pwcw); + } +} +#endif /* CLIB_MARCH_VARIANT */ + +/** + * @brief A struct to hold tracing information for the MPLS label imposition + * node. + */ +typedef struct pw_cw_trace_t_ +{ + /** + * The CW popped + */ + u32 cw; +} pw_cw_trace_t; + +always_inline uword +pw_cw_pop_inline (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * from_frame) +{ + u32 n_left_from, next_index, * from, * to_next; + + from = vlib_frame_vector_args(from_frame); + n_left_from = from_frame->n_vectors; + next_index = node->cached_next_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); + + while (n_left_from >= 4 && n_left_to_next >= 2) + { + pw_cw_dpo_t *pwcw0, *pwcw1; + u32 bi0, pwcwi0, bi1, pwcwi1; + vlib_buffer_t * b0, *b1; + u32 next0, next1; + + bi0 = to_next[0] = from[0]; + bi1 = to_next[1] = from[1]; + + /* Prefetch next iteration. */ + { + vlib_buffer_t * p2, * p3; + + p2 = vlib_get_buffer(vm, from[2]); + p3 = vlib_get_buffer(vm, from[3]); + + vlib_prefetch_buffer_header(p2, STORE); + vlib_prefetch_buffer_header(p3, STORE); + + CLIB_PREFETCH(p2->data, sizeof(pw_cw_t), STORE); + CLIB_PREFETCH(p3->data, sizeof(pw_cw_t), STORE); + } + + from += 2; + to_next += 2; + n_left_from -= 2; + n_left_to_next -= 2; + + b0 = vlib_get_buffer(vm, bi0); + b1 = vlib_get_buffer(vm, bi1); + + /* get the next parent DPO for the next pop */ + pwcwi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; + pwcwi1 = vnet_buffer(b1)->ip.adj_index[VLIB_TX]; + pwcw0 = pw_cw_dpo_get(pwcwi0); + pwcw1 = pw_cw_dpo_get(pwcwi1); + + next0 = pwcw0->pwcw_parent.dpoi_next_node; + next1 = pwcw1->pwcw_parent.dpoi_next_node; + + vnet_buffer(b0)->ip.adj_index[VLIB_TX] = pwcw0->pwcw_parent.dpoi_index; + vnet_buffer(b1)->ip.adj_index[VLIB_TX] = pwcw1->pwcw_parent.dpoi_index; + + if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) + { + pw_cw_trace_t *tr = vlib_add_trace(vm, node, b0, sizeof(*tr)); + + tr->cw = *((pw_cw_t*) vlib_buffer_get_current(b0)); + } + if (PREDICT_FALSE(b1->flags & VLIB_BUFFER_IS_TRACED)) + { + pw_cw_trace_t *tr = vlib_add_trace(vm, node, b1, sizeof(*tr)); + + tr->cw = *((pw_cw_t*) vlib_buffer_get_current(b1)); + } + + /* pop the PW CW */ + vlib_buffer_advance (b0, sizeof(pw_cw_t)); + vlib_buffer_advance (b1, sizeof(pw_cw_t)); + + vlib_validate_buffer_enqueue_x2(vm, node, next_index, to_next, + n_left_to_next, + bi0, bi1, next0, next1); + } + + while (n_left_from > 0 && n_left_to_next > 0) + { + pw_cw_dpo_t *pwcw0; + vlib_buffer_t * b0; + u32 bi0, pwcwi0; + u32 next0; + + 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); + + pwcwi0 = vnet_buffer(b0)->ip.adj_index[VLIB_TX]; + pwcw0 = pw_cw_dpo_get(pwcwi0); + next0 = pwcw0->pwcw_parent.dpoi_next_node; + vnet_buffer(b0)->ip.adj_index[VLIB_TX] = pwcw0->pwcw_parent.dpoi_index; + + if (PREDICT_FALSE(b0->flags & VLIB_BUFFER_IS_TRACED)) + { + pw_cw_trace_t *tr = vlib_add_trace(vm, node, b0, sizeof(*tr)); + + tr->cw = *((pw_cw_t*) vlib_buffer_get_current(b0)); + } + + vlib_buffer_advance (b0, sizeof(pw_cw_t)); + + 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; +} + +static u8 * +format_pw_cw_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 *); + CLIB_UNUSED(pw_cw_trace_t * t); + + t = va_arg(*args, pw_cw_trace_t *); + + s = format(s, "cw:0x%x", t->cw); + + return (s); +} + +VLIB_NODE_FN (pw_cw_node) (vlib_main_t * vm, + vlib_node_runtime_t * node, + vlib_frame_t * frame) +{ + return (pw_cw_pop_inline(vm, node, frame)); +} + +VLIB_REGISTER_NODE(pw_cw_node) = { + .name = "pw-cw-pop", + .vector_size = sizeof(u32), + .format_trace = format_pw_cw_trace, +}; + +#ifndef CLIB_MARCH_VARIANT +static void +pw_cw_dpo_mem_show (void) +{ + fib_show_memory_usage("PW-CW", + pool_elts(pw_cw_dpo_pool), + pool_len(pw_cw_dpo_pool), + sizeof(pw_cw_dpo_t)); +} + +const static dpo_vft_t pwcw_vft = { + .dv_lock = pw_cw_dpo_lock, + .dv_unlock = pw_cw_dpo_unlock, + .dv_format = format_pw_cw_dpo, + .dv_mem_show = pw_cw_dpo_mem_show, +}; + +const static char* const pw_cw_proto_nodes[] = +{ + "pw-cw-pop", + NULL, +}; + +const static char* const * const pw_cw_nodes[DPO_PROTO_NUM] = +{ + [DPO_PROTO_IP4] = pw_cw_proto_nodes, + [DPO_PROTO_IP6] = pw_cw_proto_nodes, + [DPO_PROTO_MPLS] = pw_cw_proto_nodes, + [DPO_PROTO_ETHERNET] = pw_cw_proto_nodes, +}; + +void +pw_cw_dpo_module_init (void) +{ + dpo_register(DPO_PW_CW, &pwcw_vft, pw_cw_nodes); +} + +#endif /* CLIB_MARCH_VARIANT */ diff --git a/src/vnet/dpo/pw_cw.h b/src/vnet/dpo/pw_cw.h new file mode 100644 index 00000000000..96f8c72c9d0 --- /dev/null +++ b/src/vnet/dpo/pw_cw.h @@ -0,0 +1,80 @@ +/* + * Copyright (c) 2019 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 __PW_CW_DPO_H__ +#define __PW_CW_DPO_H__ + +#include <vnet/vnet.h> +#include <vnet/mpls/packet.h> +#include <vnet/dpo/dpo.h> + +/** + * A Psuedo Wire Control Word is 4 bytes + */ +typedef u32 pw_cw_t; + +/** + * A representation of a Psuedo Wire Control Word pop DPO + */ +typedef struct pw_cw_dpo_t +{ + /** + * Next DPO in the graph + */ + dpo_id_t pwcw_parent; + + /** + * Number of locks/users of the label + */ + u16 pwcw_locks; +} pw_cw_dpo_t; + +/** + * @brief Assert that the MPLS label object is less than a cache line in size. + * Should this get any bigger then we will need to reconsider how many labels + * can be pushed in one object. + */ +STATIC_ASSERT_SIZEOF(pw_cw_dpo_t, 2 * sizeof(u64)); + +/* #define STATIC_ASSERT_ALIGNOF(d, s) \ */ +/* STATIC_ASSERT (alignof (d) == sizeof(s), "Align of " #d " must be " # s " bytes") */ + +/* STATIC_ASSERT_AIGNOF(pw_cw_dpo_t, u64); */ + +/** + * @brief Create an PW CW pop + * + * @param parent The parent of the created MPLS label object + * @param dpo The PW CW DPO created + */ +extern void pw_cw_dpo_create(const dpo_id_t *paremt, + dpo_id_t *dpo); + +extern u8* format_pw_cw_dpo(u8 *s, va_list *args); + +/* + * Encapsulation violation for fast data-path access + */ +extern pw_cw_dpo_t *pw_cw_dpo_pool; + +static inline pw_cw_dpo_t * +pw_cw_dpo_get (index_t index) +{ + return (pool_elt_at_index(pw_cw_dpo_pool, index)); +} + +extern void pw_cw_dpo_module_init(void); + +#endif diff --git a/src/vnet/fib/fib_api.c b/src/vnet/fib/fib_api.c index e776235bc00..e020b26fd6e 100644 --- a/src/vnet/fib/fib_api.c +++ b/src/vnet/fib/fib_api.c @@ -186,6 +186,8 @@ fib_api_path_decode (vl_api_fib_path_t *in, out->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_HOST; if (in->flags & FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED) out->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; + if (in->flags & FIB_API_PATH_FLAG_POP_PW_CW) + out->frp_flags |= FIB_ROUTE_PATH_POP_PW_CW; switch (in->type) { diff --git a/src/vnet/fib/fib_path.c b/src/vnet/fib/fib_path.c index eebba1b1548..ed7bc0262fc 100644 --- a/src/vnet/fib/fib_path.c +++ b/src/vnet/fib/fib_path.c @@ -26,6 +26,7 @@ #include <vnet/dpo/dvr_dpo.h> #include <vnet/dpo/ip_null_dpo.h> #include <vnet/dpo/classify_dpo.h> +#include <vnet/dpo/pw_cw.h> #include <vnet/adj/adj.h> #include <vnet/adj/adj_mcast.h> @@ -1233,6 +1234,8 @@ fib_path_route_flags_to_cfg_flags (const fib_route_path_t *rpath) { fib_path_cfg_flags_t cfg_flags = FIB_PATH_CFG_FLAG_NONE; + if (rpath->frp_flags & FIB_ROUTE_PATH_POP_PW_CW) + cfg_flags |= FIB_PATH_CFG_FLAG_POP_PW_CW; if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_HOST) cfg_flags |= FIB_PATH_CFG_FLAG_RESOLVE_HOST; if (rpath->frp_flags & FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED) @@ -2381,6 +2384,16 @@ fib_path_stack_mpls_disp (fib_node_index_t path_index, case FIB_PATH_TYPE_DVR: break; } + + if (path->fp_cfg_flags & FIB_PATH_CFG_FLAG_POP_PW_CW) + { + dpo_id_t tmp = DPO_INVALID; + + dpo_copy(&tmp, dpo); + + pw_cw_dpo_create(&tmp, dpo); + dpo_reset(&tmp); + } } void diff --git a/src/vnet/fib/fib_path.h b/src/vnet/fib/fib_path.h index 50aca9e1cf5..76f876d8f10 100644 --- a/src/vnet/fib/fib_path.h +++ b/src/vnet/fib/fib_path.h @@ -96,9 +96,13 @@ typedef enum fib_path_cfg_attribute_t_ { */ FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC, /** + * The path pops a Psuedo Wire Control Word + */ + FIB_PATH_CFG_ATTRIBUTE_POP_PW_CW, + /** * Marker. Add new types before this one, then update it. */ - FIB_PATH_CFG_ATTRIBUTE_LAST = FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC, + FIB_PATH_CFG_ATTRIBUTE_LAST = FIB_PATH_CFG_ATTRIBUTE_POP_PW_CW, } __attribute__ ((packed)) fib_path_cfg_attribute_t; /** @@ -119,6 +123,7 @@ typedef enum fib_path_cfg_attribute_t_ { [FIB_PATH_CFG_ATTRIBUTE_INTF_RX] = "interface-rx", \ [FIB_PATH_CFG_ATTRIBUTE_RPF_ID] = "rpf-id", \ [FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC] = "deag-src", \ + [FIB_PATH_CFG_ATTRIBUTE_POP_PW_CW] = "pop-pw-cw", \ } #define FOR_EACH_FIB_PATH_CFG_ATTRIBUTE(_item) \ @@ -143,6 +148,7 @@ typedef enum fib_path_cfg_flags_t_ { FIB_PATH_CFG_FLAG_INTF_RX = (1 << FIB_PATH_CFG_ATTRIBUTE_INTF_RX), FIB_PATH_CFG_FLAG_RPF_ID = (1 << FIB_PATH_CFG_ATTRIBUTE_RPF_ID), FIB_PATH_CFG_FLAG_DEAG_SRC = (1 << FIB_PATH_CFG_ATTRIBUTE_DEAG_SRC), + FIB_PATH_CFG_FLAG_POP_PW_CW = (1 << FIB_PATH_CFG_ATTRIBUTE_POP_PW_CW), } __attribute__ ((packed)) fib_path_cfg_flags_t; typedef enum fib_path_format_flags_t_ diff --git a/src/vnet/fib/fib_types.api b/src/vnet/fib/fib_types.api index 9073192c3c4..4a5cea79064 100644 --- a/src/vnet/fib/fib_types.api +++ b/src/vnet/fib/fib_types.api @@ -44,9 +44,11 @@ enum fib_path_flags { FIB_API_PATH_FLAG_NONE = 0, /* the path must resolve via an attached route */ - FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED, + FIB_API_PATH_FLAG_RESOLVE_VIA_ATTACHED = 1, /* the path must resolve via a host route */ - FIB_API_PATH_FLAG_RESOLVE_VIA_HOST, + FIB_API_PATH_FLAG_RESOLVE_VIA_HOST = 2, + /* pop a Pseudo Wire Control Word as well */ + FIB_API_PATH_FLAG_POP_PW_CW = 4, }; /* \brief A description of the 'next-hop' for a path diff --git a/src/vnet/fib/fib_types.c b/src/vnet/fib/fib_types.c index 4b1280f6fa8..386aece8753 100644 --- a/src/vnet/fib/fib_types.c +++ b/src/vnet/fib/fib_types.c @@ -537,6 +537,10 @@ unformat_fib_route_path (unformat_input_t * input, va_list * args) { rpath->frp_flags |= FIB_ROUTE_PATH_RESOLVE_VIA_ATTACHED; } + else if (unformat (input, "pop-pw-cw")) + { + rpath->frp_flags |= FIB_ROUTE_PATH_POP_PW_CW; + } else if (unformat (input, "ip4-lookup-in-table %d", &rpath->frp_fib_index)) diff --git a/src/vnet/fib/fib_types.h b/src/vnet/fib/fib_types.h index 77b133fa9db..980fe3d1d0a 100644 --- a/src/vnet/fib/fib_types.h +++ b/src/vnet/fib/fib_types.h @@ -383,6 +383,11 @@ typedef enum fib_route_path_flags_t_ FIB_ROUTE_PATH_ICMP_UNREACH = (1 << 15), FIB_ROUTE_PATH_ICMP_PROHIBIT = (1 << 16), FIB_ROUTE_PATH_CLASSIFY = (1 << 17), + + /** + * Pop a Psuedo Wire Control Word + */ + FIB_ROUTE_PATH_POP_PW_CW = (1 << 18), } fib_route_path_flags_t; /** |