[ovs-dev] [PATCH] bundle: add nw_src/dst hash method

wenxu at ucloud.cn wenxu at ucloud.cn
Thu Feb 23 05:19:11 UTC 2017


From: wenxu <wenxu at ucloud.cn>

Add this feature to help only nw_src or nw_dst hash senario.

Signed-off-by: wenxu <wenxu at ucloud.cn>
---
 include/openflow/nicira-ext.h |  7 ++++++-
 lib/bundle.c                  |  4 ++++
 lib/flow.c                    | 38 +++++++++++++++++++++++++++++++++++++-
 3 files changed, 47 insertions(+), 2 deletions(-)

diff --git a/include/openflow/nicira-ext.h b/include/openflow/nicira-ext.h
index 9d53623..71a1de0 100644
--- a/include/openflow/nicira-ext.h
+++ b/include/openflow/nicira-ext.h
@@ -103,8 +103,13 @@ enum nx_hash_fields {
      *  - NXM_OF_TCP_SRC / NXM_OF_TCP_DST
      *  - NXM_OF_UDP_SRC / NXM_OF_UDP_DST
      */
-    NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP
+    NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP,
 
+    /* Network source address (NXM_OF_IP_SRC) only. */
+    NX_HASH_FIELDS_NW_SRC,
+
+    /* Network destination address (NXM_OF_IP_DST) only. */
+    NX_HASH_FIELDS_NW_DST
 
 };
 
diff --git a/lib/bundle.c b/lib/bundle.c
index 70a743b..6c00b86 100644
--- a/lib/bundle.c
+++ b/lib/bundle.c
@@ -191,6 +191,10 @@ bundle_parse__(const char *s, char **save_ptr,
         bundle->fields = NX_HASH_FIELDS_SYMMETRIC_L3L4;
     } else if (!strcasecmp(fields, "symmetric_l3l4+udp")) {
         bundle->fields = NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP;
+    } else if (!strcasecmp(fields, "nw_src")) {
+        bundle->fields = NX_HASH_FIELDS_NW_SRC;
+    } else if (!strcasecmp(fields, "nw_dst")) {
+        bundle->fields = NX_HASH_FIELDS_NW_DST;
     } else {
         return xasprintf("%s: unknown fields `%s'", s, fields);
     }
diff --git a/lib/flow.c b/lib/flow.c
index fb7bfeb..ff01366 100644
--- a/lib/flow.c
+++ b/lib/flow.c
@@ -1879,6 +1879,22 @@ flow_mask_hash_fields(const struct flow *flow, struct flow_wildcards *wc,
         }
         break;
 
+    case NX_HASH_FIELDS_NW_SRC:
+        if (flow->dl_type == htons(ETH_TYPE_IP)) {
+            memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src);
+        } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
+            memset(&wc->masks.ipv6_src, 0xff, sizeof wc->masks.ipv6_src);
+        }
+        break;
+
+    case NX_HASH_FIELDS_NW_DST:
+        if (flow->dl_type == htons(ETH_TYPE_IP)) {
+            memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst);
+        } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) {
+            memset(&wc->masks.ipv6_dst, 0xff, sizeof wc->masks.ipv6_dst);
+        }
+        break;
+
     default:
         OVS_NOT_REACHED();
     }
@@ -1903,6 +1919,22 @@ flow_hash_fields(const struct flow *flow, enum nx_hash_fields fields,
     case NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP:
         return flow_hash_symmetric_l3l4(flow, basis, true);
 
+    case NX_HASH_FIELDS_NW_SRC:
+        if (flow->dl_type == htons(ETH_TYPE_IP))
+            return jhash_bytes(&flow->nw_src, sizeof flow->nw_src, basis);
+        else if (flow->dl_type == htons(ETH_TYPE_IPV6))
+            return jhash_bytes(&flow->ipv6_src, sizeof flow->ipv6_src, basis);
+        else
+            return 0;
+
+    case NX_HASH_FIELDS_NW_DST:
+        if (flow->dl_type == htons(ETH_TYPE_IP))
+            return jhash_bytes(&flow->nw_dst, sizeof flow->nw_dst, basis);
+        else if (flow->dl_type == htons(ETH_TYPE_IPV6))
+            return jhash_bytes(&flow->ipv6_dst, sizeof flow->ipv6_dst, basis);
+        else
+            return 0;
+
     }
 
     OVS_NOT_REACHED();
@@ -1917,6 +1949,8 @@ flow_hash_fields_to_str(enum nx_hash_fields fields)
     case NX_HASH_FIELDS_SYMMETRIC_L4: return "symmetric_l4";
     case NX_HASH_FIELDS_SYMMETRIC_L3L4: return "symmetric_l3l4";
     case NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP: return "symmetric_l3l4+udp";
+    case NX_HASH_FIELDS_NW_SRC: return "nw_src";
+    case NX_HASH_FIELDS_NW_DST: return "nw_dst";
     default: return "<unknown>";
     }
 }
@@ -1928,7 +1962,9 @@ flow_hash_fields_valid(enum nx_hash_fields fields)
     return fields == NX_HASH_FIELDS_ETH_SRC
         || fields == NX_HASH_FIELDS_SYMMETRIC_L4
         || fields == NX_HASH_FIELDS_SYMMETRIC_L3L4
-        || fields == NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP;
+        || fields == NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP
+        || fields == NX_HASH_FIELDS_NW_SRC
+        || fields == NX_HASH_FIELDS_NW_DST;
 }
 
 /* Returns a hash value for the bits of 'flow' that are active based on
-- 
1.8.3.1




More information about the dev mailing list