From 943a4b0750a2bee04788cb153ca56fa07d5005d7 Mon Sep 17 00:00:00 2001 From: Florin Coras Date: Wed, 27 Oct 2021 15:17:47 -0700 Subject: interface: handoff refactor and optimizations - move existing ethernet hash functions to hash infra (no l4 awareness) - refactor code to use hash infra and add apis to request l4 aware hashing functions - hashing functions per interface - code cleanup Type: improvement Signed-off-by: Florin Coras Change-Id: Ia9f44db98d83f0f027aeb37718585a2e10ffd2c6 --- src/vnet/CMakeLists.txt | 2 +- src/vnet/handoff.c | 126 +++++++------- src/vnet/handoff.h | 246 --------------------------- src/vnet/hash/crc32_handoff_eth.c | 341 ++++++++++++++++++++++++++++++++++++++ 4 files changed, 412 insertions(+), 303 deletions(-) delete mode 100644 src/vnet/handoff.h create mode 100644 src/vnet/hash/crc32_handoff_eth.c (limited to 'src/vnet') diff --git a/src/vnet/CMakeLists.txt b/src/vnet/CMakeLists.txt index cff723937b2..395f958185e 100644 --- a/src/vnet/CMakeLists.txt +++ b/src/vnet/CMakeLists.txt @@ -56,7 +56,6 @@ list(APPEND VNET_HEADERS devices/netlink.h flow/flow.h global_funcs.h - handoff.h interface/rx_queue_funcs.h interface/tx_queue_funcs.h interface.h @@ -889,6 +888,7 @@ list(APPEND VNET_SOURCES hash/hash.c hash/cli.c hash/crc32_5tuple.c + hash/crc32_handoff_eth.c ) list(APPEND VNET_HEADERS diff --git a/src/vnet/handoff.c b/src/vnet/handoff.c index f64d5ad3a69..15cfd606aba 100644 --- a/src/vnet/handoff.c +++ b/src/vnet/handoff.c @@ -15,13 +15,13 @@ */ #include -#include +#include #include -#include #include typedef struct { + vnet_hash_fn_t hash_fn; uword *workers_bitmap; u32 *workers; } per_inteface_handoff_data_t; @@ -36,14 +36,14 @@ typedef struct /* Worker handoff index */ u32 frame_queue_index; - - u64 (*hash_fn) (ethernet_header_t *); } handoff_main_t; extern handoff_main_t handoff_main; #ifndef CLIB_MARCH_VARIANT + handoff_main_t handoff_main; + #endif /* CLIB_MARCH_VARIANT */ typedef struct @@ -78,12 +78,35 @@ format_worker_handoff_trace (u8 * s, va_list * args) CLIB_UNUSED (vlib_node_t * node) = va_arg (*args, vlib_node_t *); worker_handoff_trace_t *t = va_arg (*args, worker_handoff_trace_t *); - s = - format (s, "worker-handoff: sw_if_index %d, next_worker %d, buffer 0x%x", - t->sw_if_index, t->next_worker_index, t->buffer_index); + s = format (s, "worker-handoff: sw_if_index %d, next_worker %d, buffer 0x%x", + t->sw_if_index, t->next_worker_index, t->buffer_index); return s; } +static void +worker_handoff_trace_frame (vlib_main_t *vm, vlib_node_runtime_t *node, + vlib_buffer_t **bufs, u16 *threads, u32 n_vectors) +{ + worker_handoff_trace_t *t; + vlib_buffer_t **b; + u16 *ti; + + b = bufs; + ti = threads; + + while (n_vectors) + { + t = vlib_add_trace (vm, node, b[0], sizeof (*t)); + t->sw_if_index = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; + t->next_worker_index = ti[0]; + t->buffer_index = vlib_get_buffer_index (vm, b[0]); + + b += 1; + ti += 1; + n_vectors -= 1; + } +} + VLIB_NODE_FN (worker_handoff_node) (vlib_main_t * vm, vlib_node_runtime_t * node, vlib_frame_t * frame) @@ -102,26 +125,16 @@ VLIB_NODE_FN (worker_handoff_node) (vlib_main_t * vm, while (n_left_from > 0) { - u32 sw_if_index0; - u32 hash; - u64 hash_key; per_inteface_handoff_data_t *ihd0; - u32 index0; - + u32 sw_if_index0, hash, index0; + void *data; sw_if_index0 = vnet_buffer (b[0])->sw_if_index[VLIB_RX]; - ASSERT (hm->if_data); ihd0 = vec_elt_at_index (hm->if_data, sw_if_index0); - /* - * Force unknown traffic onto worker 0, - * and into ethernet-input. $$$$ add more hashes. - */ - /* Compute ingress LB hash */ - hash_key = hm->hash_fn ((ethernet_header_t *) - vlib_buffer_get_current (b[0])); - hash = (u32) clib_xxhash (hash_key); + data = vlib_buffer_get_current (b[0]); + ihd0->hash_fn (&data, &hash, 1); /* if input node did not specify next index, then packet should go to ethernet-input */ @@ -133,22 +146,16 @@ VLIB_NODE_FN (worker_handoff_node) (vlib_main_t * vm, ti[0] = hm->first_worker_index + ihd0->workers[index0]; - if (PREDICT_FALSE ((node->flags & VLIB_NODE_FLAG_TRACE) - && (b[0]->flags & VLIB_BUFFER_IS_TRACED))) - { - worker_handoff_trace_t *t = - vlib_add_trace (vm, node, b[0], sizeof (*t)); - t->sw_if_index = sw_if_index0; - t->next_worker_index = ti[0]; - t->buffer_index = vlib_get_buffer_index (vm, b[0]); - } - /* next */ n_left_from -= 1; ti += 1; b += 1; } + if (PREDICT_FALSE (node->flags & VLIB_NODE_FLAG_TRACE)) + worker_handoff_trace_frame (vm, node, bufs, thread_indices, + frame->n_vectors); + n_enq = vlib_buffer_enqueue_to_thread (vm, node, hm->frame_queue_index, from, thread_indices, frame->n_vectors, 1); @@ -159,7 +166,6 @@ VLIB_NODE_FN (worker_handoff_node) (vlib_main_t * vm, return frame->n_vectors; } -/* *INDENT-OFF* */ VLIB_REGISTER_NODE (worker_handoff_node) = { .name = "worker-handoff", .vector_size = sizeof (u32), @@ -174,12 +180,12 @@ VLIB_REGISTER_NODE (worker_handoff_node) = { }, }; -/* *INDENT-ON* */ - #ifndef CLIB_MARCH_VARIANT + int -interface_handoff_enable_disable (vlib_main_t * vm, u32 sw_if_index, - uword * bitmap, int enable_disable) +interface_handoff_enable_disable (vlib_main_t *vm, u32 sw_if_index, + uword *bitmap, u8 is_sym, int is_l4, + int enable_disable) { handoff_main_t *hm = &handoff_main; vnet_sw_interface_t *sw; @@ -212,12 +218,28 @@ interface_handoff_enable_disable (vlib_main_t * vm, u32 sw_if_index, if (enable_disable) { d->workers_bitmap = bitmap; - /* *INDENT-OFF* */ clib_bitmap_foreach (i, bitmap) - { + { vec_add1(d->workers, i); } - /* *INDENT-ON* */ + + if (is_sym) + { + if (is_l4) + return VNET_API_ERROR_UNIMPLEMENTED; + + d->hash_fn = vnet_hash_function_from_name ( + "handoff_eth_sym_crc32c", VNET_HASH_FN_TYPE_ETHERNET); + } + else + { + if (is_l4) + d->hash_fn = + vnet_hash_default_function (VNET_HASH_FN_TYPE_ETHERNET); + else + d->hash_fn = vnet_hash_function_from_name ( + "handoff_eth_crc32c", VNET_HASH_FN_TYPE_ETHERNET); + } } vnet_feature_enable_disable ("device-input", "worker-handoff", @@ -230,12 +252,9 @@ set_interface_handoff_command_fn (vlib_main_t * vm, unformat_input_t * input, vlib_cli_command_t * cmd) { - handoff_main_t *hm = &handoff_main; - u32 sw_if_index = ~0; + u32 sw_if_index = ~0, is_sym = 0, is_l4 = 0; int enable_disable = 1; uword *bitmap = 0; - u32 sym = ~0; - int rv = 0; while (unformat_check_input (input) != UNFORMAT_END_OF_INPUT) @@ -248,9 +267,11 @@ set_interface_handoff_command_fn (vlib_main_t * vm, vnet_get_main (), &sw_if_index)) ; else if (unformat (input, "symmetrical")) - sym = 1; + is_sym = 1; else if (unformat (input, "asymmetrical")) - sym = 0; + is_sym = 0; + else if (unformat (input, "l4")) + is_l4 = 1; else break; } @@ -261,9 +282,8 @@ set_interface_handoff_command_fn (vlib_main_t * vm, if (bitmap == 0) return clib_error_return (0, "Please specify list of workers..."); - rv = - interface_handoff_enable_disable (vm, sw_if_index, bitmap, - enable_disable); + rv = interface_handoff_enable_disable (vm, sw_if_index, bitmap, is_sym, + is_l4, enable_disable); switch (rv) { @@ -287,19 +307,14 @@ set_interface_handoff_command_fn (vlib_main_t * vm, return clib_error_return (0, "unknown return value %d", rv); } - if (sym == 1) - hm->hash_fn = eth_get_sym_key; - else if (sym == 0) - hm->hash_fn = eth_get_key; - return 0; } /* *INDENT-OFF* */ VLIB_CLI_COMMAND (set_interface_handoff_command, static) = { .path = "set interface handoff", - .short_help = - "set interface handoff workers [symmetrical|asymmetrical]", + .short_help = "set interface handoff workers " + " [symmetrical|asymmetrical]", .function = set_interface_handoff_command_fn, }; /* *INDENT-ON* */ @@ -328,7 +343,6 @@ handoff_init (vlib_main_t * vm) } } - hm->hash_fn = eth_get_key; hm->frame_queue_index = ~0; return 0; diff --git a/src/vnet/handoff.h b/src/vnet/handoff.h deleted file mode 100644 index f50b86d5c6d..00000000000 --- a/src/vnet/handoff.h +++ /dev/null @@ -1,246 +0,0 @@ -/* - * 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. - */ - -#ifndef included_vnet_handoff_h -#define included_vnet_handoff_h - -#include -#include -#include -#include -#include - -static inline u64 -ipv4_get_key (ip4_header_t * ip) -{ - u64 hash_key; - - hash_key = *((u64 *) (&ip->address_pair)) ^ ip->protocol; - - return hash_key; -} - -static inline u64 -ipv6_get_key (ip6_header_t * ip) -{ - u64 hash_key; - - hash_key = ip->src_address.as_u64[0] ^ - rotate_left (ip->src_address.as_u64[1], 13) ^ - rotate_left (ip->dst_address.as_u64[0], 26) ^ - rotate_left (ip->dst_address.as_u64[1], 39) ^ ip->protocol; - - return hash_key; -} - -#define MPLS_BOTTOM_OF_STACK_BIT_MASK 0x00000100U -#define MPLS_LABEL_MASK 0xFFFFF000U - -static inline u64 -mpls_get_key (mpls_unicast_header_t * m) -{ - u64 hash_key; - u8 ip_ver; - - - /* find the bottom of the MPLS label stack. */ - if (PREDICT_TRUE (m->label_exp_s_ttl & - clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK))) - { - goto bottom_lbl_found; - } - m++; - - if (PREDICT_TRUE (m->label_exp_s_ttl & - clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK))) - { - goto bottom_lbl_found; - } - m++; - - if (m->label_exp_s_ttl & - clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK)) - { - goto bottom_lbl_found; - } - m++; - - if (m->label_exp_s_ttl & - clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK)) - { - goto bottom_lbl_found; - } - m++; - - if (m->label_exp_s_ttl & - clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK)) - { - goto bottom_lbl_found; - } - - /* the bottom label was not found - use the last label */ - hash_key = m->label_exp_s_ttl & clib_net_to_host_u32 (MPLS_LABEL_MASK); - - return hash_key; - -bottom_lbl_found: - m++; - ip_ver = (*((u8 *) m) >> 4); - - /* find out if it is IPV4 or IPV6 header */ - if (PREDICT_TRUE (ip_ver == 4)) - { - hash_key = ipv4_get_key ((ip4_header_t *) m); - } - else if (PREDICT_TRUE (ip_ver == 6)) - { - hash_key = ipv6_get_key ((ip6_header_t *) m); - } - else - { - /* use the bottom label */ - hash_key = - (m - 1)->label_exp_s_ttl & clib_net_to_host_u32 (MPLS_LABEL_MASK); - } - - return hash_key; - -} - -static inline u64 -eth_get_sym_key (ethernet_header_t * h0) -{ - u64 hash_key; - - if (PREDICT_TRUE (h0->type) == clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) - { - ip4_header_t *ip = (ip4_header_t *) (h0 + 1); - hash_key = - (u64) (ip->src_address.as_u32 ^ - ip->dst_address.as_u32 ^ ip->protocol); - } - else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) - { - ip6_header_t *ip = (ip6_header_t *) (h0 + 1); - hash_key = (u64) (ip->src_address.as_u64[0] ^ - ip->src_address.as_u64[1] ^ - ip->dst_address.as_u64[0] ^ - ip->dst_address.as_u64[1] ^ ip->protocol); - } - else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) - { - hash_key = mpls_get_key ((mpls_unicast_header_t *) (h0 + 1)); - } - else - if (PREDICT_FALSE - ((h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) - || (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD)))) - { - ethernet_vlan_header_t *outer = (ethernet_vlan_header_t *) (h0 + 1); - - outer = (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) ? - outer + 1 : outer; - if (PREDICT_TRUE (outer->type) == - clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) - { - ip4_header_t *ip = (ip4_header_t *) (outer + 1); - hash_key = - (u64) (ip->src_address.as_u32 ^ - ip->dst_address.as_u32 ^ ip->protocol); - } - else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) - { - ip6_header_t *ip = (ip6_header_t *) (outer + 1); - hash_key = - (u64) (ip->src_address.as_u64[0] ^ ip->src_address.as_u64[1] ^ - ip->dst_address.as_u64[0] ^ - ip->dst_address.as_u64[1] ^ ip->protocol); - } - else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) - { - hash_key = mpls_get_key ((mpls_unicast_header_t *) (outer + 1)); - } - else - { - hash_key = outer->type; - } - } - else - { - hash_key = 0; - } - - return hash_key; -} - -static inline u64 -eth_get_key (ethernet_header_t * h0) -{ - u64 hash_key; - - if (PREDICT_TRUE (h0->type) == clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) - { - hash_key = ipv4_get_key ((ip4_header_t *) (h0 + 1)); - } - else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) - { - hash_key = ipv6_get_key ((ip6_header_t *) (h0 + 1)); - } - else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) - { - hash_key = mpls_get_key ((mpls_unicast_header_t *) (h0 + 1)); - } - else if ((h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) || - (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD))) - { - ethernet_vlan_header_t *outer = (ethernet_vlan_header_t *) (h0 + 1); - - outer = (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) ? - outer + 1 : outer; - if (PREDICT_TRUE (outer->type) == - clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) - { - hash_key = ipv4_get_key ((ip4_header_t *) (outer + 1)); - } - else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) - { - hash_key = ipv6_get_key ((ip6_header_t *) (outer + 1)); - } - else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) - { - hash_key = mpls_get_key ((mpls_unicast_header_t *) (outer + 1)); - } - else - { - hash_key = outer->type; - } - } - else - { - hash_key = 0; - } - - return hash_key; -} - -#endif /* included_vnet_handoff_h */ - -/* - * fd.io coding-style-patch-verification: ON - * - * Local Variables: - * eval: (c-set-style "gnu") - * End: - */ diff --git a/src/vnet/hash/crc32_handoff_eth.c b/src/vnet/hash/crc32_handoff_eth.c new file mode 100644 index 00000000000..13fc12ce6ea --- /dev/null +++ b/src/vnet/hash/crc32_handoff_eth.c @@ -0,0 +1,341 @@ +/* + * Copyright (c) 2021 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 +#include +#include +#include +#include +#include +#include + +static inline u64 +ipv4_get_key (ip4_header_t * ip) +{ + u64 hash_key; + + hash_key = *((u64 *) (&ip->address_pair)) ^ ip->protocol; + + return hash_key; +} + +static inline u64 +ipv6_get_key (ip6_header_t * ip) +{ + u64 hash_key; + + hash_key = ip->src_address.as_u64[0] ^ + rotate_left (ip->src_address.as_u64[1], 13) ^ + rotate_left (ip->dst_address.as_u64[0], 26) ^ + rotate_left (ip->dst_address.as_u64[1], 39) ^ ip->protocol; + + return hash_key; +} + +#define MPLS_BOTTOM_OF_STACK_BIT_MASK 0x00000100U +#define MPLS_LABEL_MASK 0xFFFFF000U + +static inline u64 +mpls_get_key (mpls_unicast_header_t * m) +{ + u64 hash_key; + u8 ip_ver; + + + /* find the bottom of the MPLS label stack. */ + if (PREDICT_TRUE (m->label_exp_s_ttl & + clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK))) + { + goto bottom_lbl_found; + } + m++; + + if (PREDICT_TRUE (m->label_exp_s_ttl & + clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK))) + { + goto bottom_lbl_found; + } + m++; + + if (m->label_exp_s_ttl & + clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK)) + { + goto bottom_lbl_found; + } + m++; + + if (m->label_exp_s_ttl & + clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK)) + { + goto bottom_lbl_found; + } + m++; + + if (m->label_exp_s_ttl & + clib_net_to_host_u32 (MPLS_BOTTOM_OF_STACK_BIT_MASK)) + { + goto bottom_lbl_found; + } + + /* the bottom label was not found - use the last label */ + hash_key = m->label_exp_s_ttl & clib_net_to_host_u32 (MPLS_LABEL_MASK); + + return hash_key; + +bottom_lbl_found: + m++; + ip_ver = (*((u8 *) m) >> 4); + + /* find out if it is IPV4 or IPV6 header */ + if (PREDICT_TRUE (ip_ver == 4)) + { + hash_key = ipv4_get_key ((ip4_header_t *) m); + } + else if (PREDICT_TRUE (ip_ver == 6)) + { + hash_key = ipv6_get_key ((ip6_header_t *) m); + } + else + { + /* use the bottom label */ + hash_key = + (m - 1)->label_exp_s_ttl & clib_net_to_host_u32 (MPLS_LABEL_MASK); + } + + return hash_key; + +} + +static inline u64 +eth_get_sym_key (ethernet_header_t * h0) +{ + u64 hash_key; + + if (PREDICT_TRUE (h0->type) == clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) + { + ip4_header_t *ip = (ip4_header_t *) (h0 + 1); + hash_key = + (u64) (ip->src_address.as_u32 ^ + ip->dst_address.as_u32 ^ ip->protocol); + } + else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) + { + ip6_header_t *ip = (ip6_header_t *) (h0 + 1); + hash_key = (u64) (ip->src_address.as_u64[0] ^ + ip->src_address.as_u64[1] ^ + ip->dst_address.as_u64[0] ^ + ip->dst_address.as_u64[1] ^ ip->protocol); + } + else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) + { + hash_key = mpls_get_key ((mpls_unicast_header_t *) (h0 + 1)); + } + else + if (PREDICT_FALSE + ((h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) + || (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD)))) + { + ethernet_vlan_header_t *outer = (ethernet_vlan_header_t *) (h0 + 1); + + outer = (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) ? + outer + 1 : outer; + if (PREDICT_TRUE (outer->type) == + clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) + { + ip4_header_t *ip = (ip4_header_t *) (outer + 1); + hash_key = + (u64) (ip->src_address.as_u32 ^ + ip->dst_address.as_u32 ^ ip->protocol); + } + else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) + { + ip6_header_t *ip = (ip6_header_t *) (outer + 1); + hash_key = + (u64) (ip->src_address.as_u64[0] ^ ip->src_address.as_u64[1] ^ + ip->dst_address.as_u64[0] ^ + ip->dst_address.as_u64[1] ^ ip->protocol); + } + else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) + { + hash_key = mpls_get_key ((mpls_unicast_header_t *) (outer + 1)); + } + else + { + hash_key = outer->type; + } + } + else + { + hash_key = 0; + } + + return hash_key; +} + +static inline u64 +eth_get_key (ethernet_header_t * h0) +{ + u64 hash_key; + + if (PREDICT_TRUE (h0->type) == clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) + { + hash_key = ipv4_get_key ((ip4_header_t *) (h0 + 1)); + } + else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) + { + hash_key = ipv6_get_key ((ip6_header_t *) (h0 + 1)); + } + else if (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) + { + hash_key = mpls_get_key ((mpls_unicast_header_t *) (h0 + 1)); + } + else if ((h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) || + (h0->type == clib_host_to_net_u16 (ETHERNET_TYPE_DOT1AD))) + { + ethernet_vlan_header_t *outer = (ethernet_vlan_header_t *) (h0 + 1); + + outer = (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_VLAN)) ? + outer + 1 : outer; + if (PREDICT_TRUE (outer->type) == + clib_host_to_net_u16 (ETHERNET_TYPE_IP4)) + { + hash_key = ipv4_get_key ((ip4_header_t *) (outer + 1)); + } + else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_IP6)) + { + hash_key = ipv6_get_key ((ip6_header_t *) (outer + 1)); + } + else if (outer->type == clib_host_to_net_u16 (ETHERNET_TYPE_MPLS)) + { + hash_key = mpls_get_key ((mpls_unicast_header_t *) (outer + 1)); + } + else + { + hash_key = outer->type; + } + } + else + { + hash_key = 0; + } + + return hash_key; +} + +void +handoff_eth_crc32c_func (void **p, u32 *hash, u32 n_packets) +{ + u32 n_left_from = n_packets; + + while (n_left_from >= 8) + { + u64 key[4] = {}; + + clib_prefetch_load (p[4]); + clib_prefetch_load (p[5]); + clib_prefetch_load (p[6]); + clib_prefetch_load (p[7]); + + key[0] = eth_get_key ((ethernet_header_t *) p[0]); + key[1] = eth_get_key ((ethernet_header_t *) p[1]); + key[2] = eth_get_key ((ethernet_header_t *) p[2]); + key[3] = eth_get_key ((ethernet_header_t *) p[3]); + + hash[0] = clib_crc32c ((u8 *) &key[0], sizeof (key[0])); + hash[1] = clib_crc32c ((u8 *) &key[1], sizeof (key[1])); + hash[2] = clib_crc32c ((u8 *) &key[2], sizeof (key[2])); + hash[3] = clib_crc32c ((u8 *) &key[3], sizeof (key[3])); + + hash += 4; + n_left_from -= 4; + p += 4; + } + + while (n_left_from > 0) + { + u64 key; + + key = eth_get_key ((ethernet_header_t *) p[0]); + hash[0] = clib_crc32c ((u8 *) &key, sizeof (key)); + + hash += 1; + n_left_from -= 1; + p += 1; + } +} + +VNET_REGISTER_HASH_FUNCTION (handoff_eth_crc32c, static) = { + .name = "handoff-eth-crc32c", + .description = "Ethernet/IPv4/IPv6/MPLS headers", + .priority = 2, + .function[VNET_HASH_FN_TYPE_ETHERNET] = handoff_eth_crc32c_func, +}; + +void +handoff_eth_sym_crc32c_func (void **p, u32 *hash, u32 n_packets) +{ + u32 n_left_from = n_packets; + + while (n_left_from >= 8) + { + u64 key[4] = {}; + + clib_prefetch_load (p[4]); + clib_prefetch_load (p[5]); + clib_prefetch_load (p[6]); + clib_prefetch_load (p[7]); + + key[0] = eth_get_sym_key ((ethernet_header_t *) p[0]); + key[1] = eth_get_sym_key ((ethernet_header_t *) p[1]); + key[2] = eth_get_sym_key ((ethernet_header_t *) p[2]); + key[3] = eth_get_sym_key ((ethernet_header_t *) p[3]); + + hash[0] = clib_crc32c ((u8 *) &key[0], sizeof (key[0])); + hash[1] = clib_crc32c ((u8 *) &key[1], sizeof (key[1])); + hash[2] = clib_crc32c ((u8 *) &key[2], sizeof (key[2])); + hash[3] = clib_crc32c ((u8 *) &key[3], sizeof (key[3])); + + hash += 4; + n_left_from -= 4; + p += 4; + } + + while (n_left_from > 0) + { + u64 key; + + key = eth_get_sym_key ((ethernet_header_t *) p[0]); + hash[0] = clib_crc32c ((u8 *) &key, sizeof (key)); + + hash += 1; + n_left_from -= 1; + p += 1; + } +} + +VNET_REGISTER_HASH_FUNCTION (handoff_eth_sym_crc32c, static) = { + .name = "handoff-eth-sym-crc32c", + .description = "Ethernet/IPv4/IPv6/MPLS headers Symmetric", + .priority = 1, + .function[VNET_HASH_FN_TYPE_ETHERNET] = handoff_eth_sym_crc32c_func, +}; + +/* + * fd.io coding-style-patch-verification: ON + * + * Local Variables: + * eval: (c-set-style "gnu") + * End: + */ -- cgit 1.2.3-korg