From patchwork Mon Dec 14 02:19:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Tonghao Zhang X-Patchwork-Id: 1415729 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=openvswitch.org (client-ip=140.211.166.138; helo=whitealder.osuosl.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.a=rsa-sha256 header.s=20161025 header.b=W2NTl0Ax; dkim-atps=neutral Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CvQC76dpTz9sTX for ; Mon, 14 Dec 2020 13:22:26 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 0CAE286BE2; Mon, 14 Dec 2020 02:22:25 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id NXvRmrqaIyN2; Mon, 14 Dec 2020 02:22:21 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by whitealder.osuosl.org (Postfix) with ESMTP id 0040686BB2; Mon, 14 Dec 2020 02:22:20 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id BA206C088E; Mon, 14 Dec 2020 02:22:20 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from whitealder.osuosl.org (smtp1.osuosl.org [140.211.166.138]) by lists.linuxfoundation.org (Postfix) with ESMTP id 5270FC013B for ; Mon, 14 Dec 2020 02:22:19 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 3F65886BAD for ; Mon, 14 Dec 2020 02:22:19 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from whitealder.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id WSzpLgzjJnO4 for ; Mon, 14 Dec 2020 02:22:16 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from mail-pj1-f66.google.com (mail-pj1-f66.google.com [209.85.216.66]) by whitealder.osuosl.org (Postfix) with ESMTPS id 38BBB86C0C for ; Mon, 14 Dec 2020 02:22:16 +0000 (UTC) Received: by mail-pj1-f66.google.com with SMTP id h7so4104552pjk.1 for ; Sun, 13 Dec 2020 18:22:16 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=GBs/+nAptoV0TdG/fXoq3CgI3CJn9JgTroXv1K3JWZY=; b=W2NTl0AxmtS8aAn/C+DuyWm7U8Zv0q0iNEKKbq77mFusmnd1l1SjfNFE5OoOpBU3dT OiCMwQFt6f6ur87786x2ly0I6Yr5AF8tUanSPHoovdABQIJKDLtkHxKZjiGr/9I3V2og xCIRti9CbA25ZdZBQq9zE5r+7vDy7daiB8bMI7BcOlXPwvk6Xd0SZKpZxhgkXmedHY/m CesvwAn7WXEs7FdKeQfg4yQvjjqGPMS945MyH2BwXq3FVxjgfav4cI3XjJCF+2nzW8hm PPsqAKZL8WSEvqxc1NCK9v5fzEDNCh93U0LlyatHr8LUWKl0L98XdgJilutwFYz/STyA Qrng== 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:in-reply-to :references; bh=GBs/+nAptoV0TdG/fXoq3CgI3CJn9JgTroXv1K3JWZY=; b=NQcFIqPK66lZcJmBeJ3qS+pYPPE8zvSZGzAW686M2tFSZPzcfeNhfFfY/xJcc8QK13 SJZDDkNaT9QmRSAnxRjILM62c1jbqvpj3VOVtp8LKcS067CpaUIykcSBgJ4sXHO/himI mkxrWA9kv4UNwPSio58ERagTWML4iuVqMY7I1De7G/fz5VzmRJ3q+raAD/UZGETyu3sd oGyvM08G1RaqapT9B/IGaQnF9x1esNp8ZqRCQI965YlAIAbejJlRR9dQp1y+ZhDnMv1l NXSJ2Tfo6d/fsdpcAhzkiaDupmdHe+roxZ/giBu+IuDwq1CKG3LLvi2h4ZS5zUxwY0n1 7grg== X-Gm-Message-State: AOAM532WzVjZrS6iYsc9d9wscmvP1GKJBWB0KSXnPRT1Dbtun/SImVgH 3r0JpgW8khS9flU4MPSwlXk= X-Google-Smtp-Source: ABdhPJzd6rF6tOZ1CTXJY+ngDo2xVd2OK6c5zVRexBB9CuFFb31tmhD8EWjT2desRZVg0UuocVdsNg== X-Received: by 2002:a17:90b:4a4c:: with SMTP id lb12mr3325316pjb.162.1607912535786; Sun, 13 Dec 2020 18:22:15 -0800 (PST) Received: from localhost.localdomain ([50.236.19.102]) by smtp.gmail.com with ESMTPSA id z7sm18019540pfq.193.2020.12.13.18.22.12 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sun, 13 Dec 2020 18:22:15 -0800 (PST) From: xiangxia.m.yue@gmail.com To: blp@ovn.org, i.maximets@ovn.org, u9012063@gmail.com, elibr@nvidia.com Date: Mon, 14 Dec 2020 10:19:59 +0800 Message-Id: <20201214022001.84273-3-xiangxia.m.yue@gmail.com> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20201214022001.84273-1-xiangxia.m.yue@gmail.com> References: <20201214022001.84273-1-xiangxia.m.yue@gmail.com> Cc: dev@openvswitch.org Subject: [ovs-dev] [PATCH ovs v1 2/4] dpctl: Add --consistent option. X-BeenThere: ovs-dev@openvswitch.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" From: Tonghao Zhang openvswitch is reactive, and then flows will be installed when receiving packets. This patch add --consistent for dpctl commands to allow user installing flows which will not be deleted. * This feature can be used with dpdk rte isolate offload mode. (e.g. receiving only tunnel packets.) * And users use it to debug openvswitch. Signed-off-by: Tonghao Zhang --- lib/dpctl.c | 24 ++++++++++++++++++++++++ lib/dpctl.h | 3 +++ lib/odp-util.c | 11 +++++++++++ lib/odp-util.h | 1 + lib/uuid.h | 3 +++ ofproto/ofproto-dpif-upcall.c | 7 +++++++ 6 files changed, 49 insertions(+) diff --git a/lib/dpctl.c b/lib/dpctl.c index 33202813b..d907eddb4 100644 --- a/lib/dpctl.c +++ b/lib/dpctl.c @@ -1146,6 +1146,12 @@ dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags, ufid_present = true; } + if (ufid_present && dpctl_p->consistent) { + dpctl_error(dpctl_p, -1, + "ufid and consistent are enabled at same time."); + return -1; + } + simap_init(&port_names); DPIF_PORT_FOR_EACH (&dpif_port, &port_dump, dpif) { simap_put(&port_names, dpif_port.name, odp_to_u32(dpif_port.port_no)); @@ -1169,6 +1175,11 @@ dpctl_put_flow(int argc, const char *argv[], enum dpif_flow_put_flags flags, goto out_freeactions; } + if (dpctl_p->consistent) { + odp_flow_key_hash_local(key.data, key.size, &ufid); + ufid_present = true; + } + if (!ufid_present && dpctl_p->is_appctl) { /* Generating UFID for this flow so it could be offloaded to HW. We're * not doing that if invoked from ovs-dpctl utility because @@ -1326,6 +1337,17 @@ dpctl_del_flow(int argc, const char *argv[], struct dpctl_params *dpctl_p) goto out; } + if (ufid_present && dpctl_p->consistent) { + dpctl_error(dpctl_p, -1, + "ufid and consistent are enabled at same time."); + goto out; + } + + if (dpctl_p->consistent) { + odp_flow_key_hash_local(key.data, key.size, &ufid); + ufid_present = ufid_generated = true; + } + if (!ufid_present && dpctl_p->is_appctl) { /* While adding flow via appctl we're generating UFID to make HW * offloading possible. Generating UFID here to be sure that such @@ -2670,6 +2692,8 @@ dpctl_unixctl_handler(struct unixctl_conn *conn, int argc, const char *argv[], } else if (!strcmp(arg, "--no-names")) { dpctl_p.names = false; set_names = true; + } else if (!strcmp(arg, "--consistent")) { + dpctl_p.consistent = true; } else { ds_put_format(&ds, "Unrecognized option %s", argv[1]); error = true; diff --git a/lib/dpctl.h b/lib/dpctl.h index 9d0052152..b042663cc 100644 --- a/lib/dpctl.h +++ b/lib/dpctl.h @@ -42,6 +42,9 @@ struct dpctl_params { /* --names: Use port names in output? */ bool names; + /* --consistent: Install consistent flow. */ + bool consistent; + /* Callback for printing. This function is called from dpctl_run_command() * to output data. The 'aux' parameter is set to the 'aux' * member. The 'error' parameter is true if 'string' is an error diff --git a/lib/odp-util.c b/lib/odp-util.c index 252a91bfa..ddf30077c 100644 --- a/lib/odp-util.c +++ b/lib/odp-util.c @@ -6592,6 +6592,17 @@ odp_flow_key_hash(const void *key, size_t key_len, ovs_u128 *hash) } hash_bytes128(key, key_len, secret, hash); uuid_set_bits_v4((struct uuid *)hash); + + /* Clean up the first bit. */ + hash->u32[0] &= ~0x1; +} + +void +odp_flow_key_hash_local(const void *key, size_t key_len, ovs_u128 *hash) +{ + odp_flow_key_hash(key, key_len, hash); + /* If setting 1, it means flows are consistent. */ + hash->u32[0] |= 0x1; } static void diff --git a/lib/odp-util.h b/lib/odp-util.h index 623a66aa2..dc0ad2332 100644 --- a/lib/odp-util.h +++ b/lib/odp-util.h @@ -244,6 +244,7 @@ void odp_flow_key_from_flow(const struct odp_flow_key_parms *, struct ofpbuf *); void odp_flow_key_from_mask(const struct odp_flow_key_parms *, struct ofpbuf *); void odp_flow_key_hash(const void *key, size_t key_len, ovs_u128 *hash); +void odp_flow_key_hash_local(const void *key, size_t key_len, ovs_u128 *hash); /* Estimated space needed for metadata. */ enum { ODP_KEY_METADATA_SIZE = 9 * 8 }; diff --git a/lib/uuid.h b/lib/uuid.h index fa49354f6..1aab3231e 100644 --- a/lib/uuid.h +++ b/lib/uuid.h @@ -42,6 +42,9 @@ extern "C" { ((unsigned int) ((UUID)->parts[2] & 0xffff)), \ ((unsigned int) ((UUID)->parts[3])) +#define UUID_LOCAL(ufid) \ + (((ufid)->u32[0] & 0x1) == 0x1) + /* Returns a hash value for 'uuid'. This hash value is the same regardless of * whether we are running on a 32-bit or 64-bit or big-endian or little-endian * architecture. */ diff --git a/ofproto/ofproto-dpif-upcall.c b/ofproto/ofproto-dpif-upcall.c index 19b92dfe0..c8ea16c18 100644 --- a/ofproto/ofproto-dpif-upcall.c +++ b/ofproto/ofproto-dpif-upcall.c @@ -2685,6 +2685,10 @@ revalidate(struct revalidator *revalidator) bool already_dumped; int error; + if (f->ufid_present && UUID_LOCAL(&(f)->ufid)) { + continue; + } + if (ukey_acquire(udpif, f, &ukey, &error)) { if (error == EBUSY) { /* Another thread is processing this flow, so don't bother @@ -2794,6 +2798,9 @@ revalidator_sweep__(struct revalidator *revalidator, bool purge) CMAP_FOR_EACH(ukey, cmap_node, &umap->cmap) { enum ukey_state ukey_state; + if (ukey->ufid_present && UUID_LOCAL(&(ukey)->ufid)) { + continue; + } /* Handler threads could be holding a ukey lock while it installs a * new flow, so don't hang around waiting for access to it. */ if (ovs_mutex_trylock(&ukey->mutex)) {