From patchwork Wed Sep 12 06:59:36 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Martin Xu X-Patchwork-Id: 968857 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=openvswitch.org (client-ip=140.211.169.12; helo=mail.linuxfoundation.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="XjapTAzM"; dkim-atps=neutral Received: from mail.linuxfoundation.org (mail.linuxfoundation.org [140.211.169.12]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 429CMR3dGzz9sB5 for ; Wed, 12 Sep 2018 16:59:47 +1000 (AEST) Received: from mail.linux-foundation.org (localhost [127.0.0.1]) by mail.linuxfoundation.org (Postfix) with ESMTP id 3EE21D99; Wed, 12 Sep 2018 06:59:44 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@mail.linuxfoundation.org Received: from smtp1.linuxfoundation.org (smtp1.linux-foundation.org [172.17.192.35]) by mail.linuxfoundation.org (Postfix) with ESMTPS id D3605D82 for ; Wed, 12 Sep 2018 06:59:42 +0000 (UTC) X-Greylist: whitelisted by SQLgrey-1.7.6 Received: from mail-pl1-f179.google.com (mail-pl1-f179.google.com [209.85.214.179]) by smtp1.linuxfoundation.org (Postfix) with ESMTPS id 3F4C213A for ; Wed, 12 Sep 2018 06:59:42 +0000 (UTC) Received: by mail-pl1-f179.google.com with SMTP id j8-v6so498107pll.12 for ; Tue, 11 Sep 2018 23:59:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=mC6iGvbupkBSx685EPSMloHv+htBPWWR/AQ1m+TMRaY=; b=XjapTAzMfl+xG0Xw4r4Qo7SBnPJz0KEQLXxGj4Mk47ypTLZt0CpC9h/bZmRbG4Nu75 3Xu2d2S1mQyk4sMTv21F0GSD4KOGETLFq1BVBdD8bPgJAZp5G5Q+DHpqxg+/RFWmoIo4 oABo0kp+q6n3ptD85f2sT+X1YmJqSHlLGCRl2NEAUl9YJvp9t9tq1BJDSTpulNilE4Zj u0FCcOQl7H4GanSWf6Cinq93faWj9cBVAmYr7BfUCNkclAet7H5QsoncKjR7lVEhoz4i zkm8KF7kgstpJxXQU+ZzbcAbK1m4+c4qcFerjSSqx8EhXP+r0nZlmMf0P8L3YHaaHBBk nbew== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=mC6iGvbupkBSx685EPSMloHv+htBPWWR/AQ1m+TMRaY=; b=nzmKAG9KI9eLe2P6UgCi64rx1ENbKfWiRD31ZyBP6cKi2HzMXsLC3uun+z1kAzTC+f BF+QS+ztR1b1YJDTRl1C/2JQmvBxnmTFfa4GSVCDvxM84YE9dFFhHTdLoqsZXqdGn2zG /nvZ6O5oAhQkUfvgnTwlC2a/rbMVLYeLES2LbHJztEpM1zDk76SUSY8uIARbs2q7e6pI +Wilzja+00JFJLW7bcJpW9UbopTEDbxg2qOI7Ud6zsiKNhgyQKqRT8s7j32Q2sgt45tP tsXHTjo2vB2jFBdHnke1JILE3NI5aCVtzB9G6SCliObOS76i7fNRl7nHg4DgvqM+ixWR da3A== X-Gm-Message-State: APzg51C3oxDsuD+Zzl3g6YnH2ufSGBEtFzFFGmwsruMue2t/aSunjVAn yWz6v3+9By3VBYF5QTwz1zXhU5O2 X-Google-Smtp-Source: ANB0VdYY/ZniIK6+msrtgYsUd1eBo/wITJRdIS5t79qXpUZAMW9u+lbIKirEctSjOeRL+dOz+W6KEA== X-Received: by 2002:a17:902:a58c:: with SMTP id az12-v6mr491437plb.339.1536735581541; Tue, 11 Sep 2018 23:59:41 -0700 (PDT) Received: from vm1-rhel74-local.eng.vmware.com ([66.170.99.1]) by smtp.gmail.com with ESMTPSA id j184-v6sm241954pge.77.2018.09.11.23.59.40 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 11 Sep 2018 23:59:40 -0700 (PDT) From: Martin Xu To: dev@openvswitch.org Date: Tue, 11 Sep 2018 23:59:36 -0700 Message-Id: <1536735576-45741-1-git-send-email-martinxu9.ovs@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE autolearn=ham version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on smtp1.linux-foundation.org Subject: [ovs-dev] [PATCH v2] bundle: add symmetric_l3 hash method for multipath X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: ovs-dev-bounces@openvswitch.org Errors-To: ovs-dev-bounces@openvswitch.org Add a symmetric_l3 hash method that uses both network destination address and network source address. VMware-BZ: #2112940 Signed-off-by: Martin Xu CC: Ben Pfaff --- include/openflow/nicira-ext.h | 4 +++- lib/bundle.c | 2 ++ lib/flow.c | 44 ++++++++++++++++++++++++++++++++++++++++++- lib/flow.h | 1 + lib/multipath.c | 2 ++ utilities/ovs-ofctl.8.in | 2 ++ 6 files changed, 53 insertions(+), 2 deletions(-) diff --git a/include/openflow/nicira-ext.h b/include/openflow/nicira-ext.h index 1f5cbbf..dc12101 100644 --- a/include/openflow/nicira-ext.h +++ b/include/openflow/nicira-ext.h @@ -109,8 +109,10 @@ enum nx_hash_fields { NX_HASH_FIELDS_NW_SRC, /* Network destination address (NXM_OF_IP_DST) only. */ - NX_HASH_FIELDS_NW_DST + NX_HASH_FIELDS_NW_DST, + /* Both network destination and source destination addresses. */ + NX_HASH_FIELDS_SYMMETRIC_L3 }; /* NXT_PACKET_IN (analogous to OFPT_PACKET_IN). diff --git a/lib/bundle.c b/lib/bundle.c index edf6676..558e890 100644 --- a/lib/bundle.c +++ b/lib/bundle.c @@ -198,6 +198,8 @@ bundle_parse__(const char *s, const struct ofputil_port_map *port_map, bundle->fields = NX_HASH_FIELDS_NW_SRC; } else if (!strcasecmp(fields, "nw_dst")) { bundle->fields = NX_HASH_FIELDS_NW_DST; + } else if (!strcasecmp(fields, "symmetric_l3")) { + bundle->fields = NX_HASH_FIELDS_SYMMETRIC_L3; } else { return xasprintf("%s: unknown fields `%s'", s, fields); } diff --git a/lib/flow.c b/lib/flow.c index 77ed3d9..92eea51 100644 --- a/lib/flow.c +++ b/lib/flow.c @@ -2301,6 +2301,34 @@ flow_hash_symmetric_l3l4(const struct flow *flow, uint32_t basis, return hash_finish(hash, basis); } +/* Hashes 'flow' based on its nw_dst and nw_src for multipath. */ +uint32_t +flow_hash_symmetric_l3(const struct flow *flow, uint32_t basis) +{ + struct { + union { + ovs_be32 ipv4_addr; + struct in6_addr ipv6_addr; + }; + } fields; + + int i; + + memset(&fields, 0, sizeof fields); + if (flow->dl_type == htons(ETH_TYPE_IP)) { + fields.ipv4_addr = flow->nw_src ^ flow->nw_dst; + } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) { + const uint8_t *a = &flow->ipv6_src.s6_addr[0]; + const uint8_t *b = &flow->ipv6_dst.s6_addr[0]; + uint8_t *ipv6_addr = &fields.ipv6_addr.s6_addr[0]; + + for (i = 0; i < 16; i++) { + ipv6_addr[i] = a[i] ^ b[i]; + } + } + return jhash_bytes(&fields, sizeof fields, basis); +} + /* Initialize a flow with random fields that matter for nx_hash_fields. */ void flow_random_hash_fields(struct flow *flow) @@ -2416,6 +2444,16 @@ flow_mask_hash_fields(const struct flow *flow, struct flow_wildcards *wc, } break; + case NX_HASH_FIELDS_SYMMETRIC_L3: + if (flow->dl_type == htons(ETH_TYPE_IP)) { + memset(&wc->masks.nw_src, 0xff, sizeof wc->masks.nw_src); + memset(&wc->masks.nw_dst, 0xff, sizeof wc->masks.nw_dst); + } else if (flow->dl_type == htons(ETH_TYPE_IPV6)) { + memset(&wc->masks.ipv6_src, 0xff, sizeof wc->masks.ipv6_src); + memset(&wc->masks.ipv6_dst, 0xff, sizeof wc->masks.ipv6_dst); + } + break; + default: OVS_NOT_REACHED(); } @@ -2458,6 +2496,8 @@ flow_hash_fields(const struct flow *flow, enum nx_hash_fields fields, return basis; } + case NX_HASH_FIELDS_SYMMETRIC_L3: + return flow_hash_symmetric_l3(flow, basis); } OVS_NOT_REACHED(); @@ -2474,6 +2514,7 @@ flow_hash_fields_to_str(enum nx_hash_fields fields) 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"; + case NX_HASH_FIELDS_SYMMETRIC_L3: return "symmetric_l3"; default: return ""; } } @@ -2487,7 +2528,8 @@ flow_hash_fields_valid(enum nx_hash_fields fields) || fields == NX_HASH_FIELDS_SYMMETRIC_L3L4 || fields == NX_HASH_FIELDS_SYMMETRIC_L3L4_UDP || fields == NX_HASH_FIELDS_NW_SRC - || fields == NX_HASH_FIELDS_NW_DST; + || fields == NX_HASH_FIELDS_NW_DST + || fields == NX_HASH_FIELDS_SYMMETRIC_L3; } /* Returns a hash value for the bits of 'flow' that are active based on diff --git a/lib/flow.h b/lib/flow.h index d03f1ba..1f6c1d6 100644 --- a/lib/flow.h +++ b/lib/flow.h @@ -241,6 +241,7 @@ uint32_t flow_hash_symmetric_l4(const struct flow *flow, uint32_t basis); uint32_t flow_hash_symmetric_l2(const struct flow *flow, uint32_t basis); uint32_t flow_hash_symmetric_l3l4(const struct flow *flow, uint32_t basis, bool inc_udp_ports ); +uint32_t flow_hash_symmetric_l3(const struct flow *flow, uint32_t basis); /* Initialize a flow with random fields that matter for nx_hash_fields. */ void flow_random_hash_fields(struct flow *); diff --git a/lib/multipath.c b/lib/multipath.c index 659c0bd..e6ba4c6 100644 --- a/lib/multipath.c +++ b/lib/multipath.c @@ -171,6 +171,8 @@ multipath_parse__(struct ofpact_multipath *mp, const char *s_, char *s) mp->fields = NX_HASH_FIELDS_NW_SRC; } else if (!strcasecmp(fields, "nw_dst")) { mp->fields = NX_HASH_FIELDS_NW_DST; + } else if (!strcasecmp(fields, "symmetric_l3")) { + mp->fields = NX_HASH_FIELDS_SYMMETRIC_L3; } else { return xasprintf("%s: unknown fields `%s'", s_, fields); } diff --git a/utilities/ovs-ofctl.8.in b/utilities/ovs-ofctl.8.in index 4850f4a..e93ce59 100644 --- a/utilities/ovs-ofctl.8.in +++ b/utilities/ovs-ofctl.8.in @@ -1421,6 +1421,8 @@ and IPv6, which hash to a constant zero. Like \fBsymmetric_l3l4+udp\fR, but UDP ports are included in the hash. This is a more effective hash when asymmetric UDP protocols such as VXLAN are not a consideration. +.IP \fBsymmetric_l3\fR +Hashes Network source address and Network destination address. .IP \fBnw_src\fR Hashes Network source address only. .IP \fBnw_dst\fR