From: Cian Ferriter <cian.ferri...@intel.com> As a first pass, all standard header fields defined in the P4 input file are hashed.
This file uses the bit_width of each field similar to the packets.h.h file to decide between calling the 32bit or 64bit OVS hashing function. This implementation was built around the Ethernet/IPv4 case as a first pass and so may not work with other header structures defined in P4. In the cases that the bit_width of a field is not 8, 16, 32 or 64 bits, this solution assumes the bit_width is 48 bits to deal with Ethernet addresses. The flexibility of this can be increased in later iterations. Pointers were used rather than the 'MINIFLOW_GET' macros as this method doesn't work for the Ethernet addresses. Signed-off-by: Cian Ferriter <cian.ferri...@intel.com> --- p4c_bm/plugin/ovs/inc/lib/hash.c.h | 51 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 p4c_bm/plugin/ovs/inc/lib/hash.c.h diff --git a/p4c_bm/plugin/ovs/inc/lib/hash.c.h b/p4c_bm/plugin/ovs/inc/lib/hash.c.h new file mode 100644 index 0000000..8dfe0bc --- /dev/null +++ b/p4c_bm/plugin/ovs/inc/lib/hash.c.h @@ -0,0 +1,51 @@ +/* + * Copyright (c) 2016 Nicira, Inc. + * + * 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 OVS_LIB_HASH_C_H +#define OVS_LIB_HASH_C_H 1 + +/* -- Used in lib/flow.c -- */ +#define OVS_HASH_FIELDS \ +//:: for header_name in ordered_header_instances_regular: + const struct _${header_name}_header *_${header_name}_header_ptr; \ +//:: #endfor + \ +//:: for header_name in ordered_header_instances_regular: + _${header_name}_header_ptr = MINIFLOW_GET_ADDRESS(flow, _${header_name}); \ +//:: #endfor + \ + if (flow) { \ +//:: for header_name in ordered_header_instances_regular: +//:: for field_name, bit_width in ordered_header_instances_non_virtual_field__name_width[header_name]: +//:: if bit_width == 8: + hash = hash_add(hash, _${header_name}_header_ptr->${field_name}); \ +//:: elif bit_width == 16: + hash = hash_add(hash, _${header_name}_header_ptr->${field_name}); \ +//:: elif bit_width == 32: + hash = hash_add(hash, _${header_name}_header_ptr->${field_name}); \ +//:: elif bit_width == 64: + hash = hash_add64(hash, _${header_name}_header_ptr->${field_name}); \ +//:: else: +//:: # NOTE: we assume that all fields are, at least, byte aligned. + hash = hash_add64(hash, *(uint64_t *)_${header_name}_header_ptr->${field_name}.data & 0xffffffffffff); \ +//:: #endif +//:: #endfor + \ +//:: #endfor + } \ + \ + +#endif /* OVS_LIB_HASH_C_H */ -- 2.7.4 (Apple Git-66) _______________________________________________ dev mailing list dev@openvswitch.org http://openvswitch.org/mailman/listinfo/dev