X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=lib%2Fflow.c;h=fc09a77a7743064e912f302f51889edb687df24a;hb=0ab14c8e284b7c5c68aff1ccc6795a1d4b58bd49;hp=e6607bf1514474adde953ffe41f4afe099ba79ae;hpb=1006cda6d4c36f4e10cab9714d4d625e141a4cad;p=openvswitch diff --git a/lib/flow.c b/lib/flow.c index e6607bf1..fc09a77a 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -852,3 +852,39 @@ flow_hash_symmetric_l4(const struct flow *flow, uint32_t basis) } return hash_bytes(&fields, sizeof fields, basis); } + +/* Hashes the portions of 'flow' designated by 'fields'. */ +uint32_t +flow_hash_fields(const struct flow *flow, enum nx_hash_fields fields, + uint16_t basis) +{ + switch (fields) { + + case NX_HASH_FIELDS_ETH_SRC: + return hash_bytes(flow->dl_src, sizeof flow->dl_src, basis); + + case NX_HASH_FIELDS_SYMMETRIC_L4: + return flow_hash_symmetric_l4(flow, basis); + } + + NOT_REACHED(); +} + +/* Returns a string representation of 'fields'. */ +const char * +flow_hash_fields_to_str(enum nx_hash_fields fields) +{ + switch (fields) { + case NX_HASH_FIELDS_ETH_SRC: return "eth_src"; + case NX_HASH_FIELDS_SYMMETRIC_L4: return "symmetric_l4"; + default: return ""; + } +} + +/* Returns true if the value of 'fields' is supported. Otherwise false. */ +bool +flow_hash_fields_valid(enum nx_hash_fields fields) +{ + return fields == NX_HASH_FIELDS_ETH_SRC + || fields == NX_HASH_FIELDS_SYMMETRIC_L4; +}