From patchwork Sun Oct 11 12:05:59 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dumitru Ceara X-Patchwork-Id: 1380315 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.133; helo=hemlock.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=redhat.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=RI/d70rW; dkim-atps=neutral Received: from hemlock.osuosl.org (smtp2.osuosl.org [140.211.166.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4C8LBD2l5fz9sS8 for ; Sun, 11 Oct 2020 23:06:12 +1100 (AEDT) Received: from localhost (localhost [127.0.0.1]) by hemlock.osuosl.org (Postfix) with ESMTP id 93679873BE; Sun, 11 Oct 2020 12:06:10 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from hemlock.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id 2v88IIk48u-U; Sun, 11 Oct 2020 12:06:09 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by hemlock.osuosl.org (Postfix) with ESMTP id A96A38732D; Sun, 11 Oct 2020 12:06:09 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id 8FB37C07FF; Sun, 11 Oct 2020 12:06:09 +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 20D05C07FF for ; Sun, 11 Oct 2020 12:06:08 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by whitealder.osuosl.org (Postfix) with ESMTP id 1005B87745 for ; Sun, 11 Oct 2020 12:06:08 +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 ift70Lq8S3-K for ; Sun, 11 Oct 2020 12:06:07 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [216.205.24.124]) by whitealder.osuosl.org (Postfix) with ESMTPS id D3440876F6 for ; Sun, 11 Oct 2020 12:06:06 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1602417965; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=AEdGwtKqPEMWAsrpUNsDNjz+giboQ+CZ2DQORr4QD6M=; b=RI/d70rWxyesjRgQNAeQ9rr91E0UlmfjX0/o2bJXdTa3O1GRKuVO6PaymYhrrsg8flZp6b oRR7srRgwPZ7220m6FKMnChXw2r0s3dNnmLsYkPLsy2KqXLKcnff/1CCvNGUFrS2ESsNxS gShPX690SULsfRZbKtjOqE9Z93Q22jI= Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-399-k293DYUWOGycznqCH1bFvg-1; Sun, 11 Oct 2020 08:06:03 -0400 X-MC-Unique: k293DYUWOGycznqCH1bFvg-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.phx2.redhat.com [10.5.11.14]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 5BC20107ACF8; Sun, 11 Oct 2020 12:06:02 +0000 (UTC) Received: from dceara.remote.csb (ovpn-112-46.ams2.redhat.com [10.36.112.46]) by smtp.corp.redhat.com (Postfix) with ESMTP id 652725D9DC; Sun, 11 Oct 2020 12:06:01 +0000 (UTC) From: Dumitru Ceara To: dev@openvswitch.org Date: Sun, 11 Oct 2020 14:05:59 +0200 Message-Id: <20201011120554.3374.75656.stgit@dceara.remote.csb> In-Reply-To: <20201011120456.3374.30821.stgit@dceara.remote.csb> References: <20201011120456.3374.30821.stgit@dceara.remote.csb> User-Agent: StGit/0.17.1-dirty MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.14 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=dceara@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Cc: hzhou@ovn.org Subject: [ovs-dev] [PATCH v5 ovn 3/4] ofctrl.c: Simplify active desired flow selection. 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: , Errors-To: ovs-dev-bounces@openvswitch.org Sender: "dev" Always consider the first "desired flow" in the list of flows that refer an "installed flow" as the active flow. This simplifies the logic of the flow update code and is used in a further commit to implement a partial ordering of desired flows within installed flows. Signed-off-by: Dumitru Ceara --- controller/ofctrl.c | 92 +++++++++++++++++++++------------------------------ 1 file changed, 37 insertions(+), 55 deletions(-) diff --git a/controller/ofctrl.c b/controller/ofctrl.c index 20cf3ac..74f98e3 100644 --- a/controller/ofctrl.c +++ b/controller/ofctrl.c @@ -188,6 +188,8 @@ struct sb_flow_ref { * relationship is 1 to N. A link is added when a flow addition is processed. * A link is removed when a flow deletion is processed, the desired flow * table is cleared, or the installed flow table is cleared. + * The first desired_flow in the list is the active one, the one that is + * actually installed. */ struct installed_flow { struct ovn_flow flow; @@ -199,11 +201,6 @@ struct installed_flow { * installed flow, e.g. when there are conflict/duplicated ACLs that * generates same match conditions). */ struct ovs_list desired_refs; - - /* The corresponding flow in desired table. It must be one of the flows in - * desired_refs list. If there are more than one flows in references list, - * this is the one that is actually installed. */ - struct desired_flow *desired_flow; }; typedef bool @@ -231,6 +228,8 @@ static struct installed_flow *installed_flow_lookup( const struct ovn_flow *target); static void installed_flow_destroy(struct installed_flow *); static struct installed_flow *installed_flow_dup(struct desired_flow *); +static struct desired_flow *installed_flow_get_active( + struct installed_flow *f); static uint32_t ovn_flow_match_hash(const struct ovn_flow *); static char *ovn_flow_to_string(const struct ovn_flow *); @@ -796,24 +795,6 @@ ofctrl_recv(const struct ofp_header *oh, enum ofptype type) log_openflow_rl(&rl, VLL_DBG, oh, "OpenFlow packet ignored"); } } - -/* Returns true if a desired flow is active (the one currently installed - * among the list of desired flows that are linked to the same installed - * flow). */ -static inline bool -desired_flow_is_active(struct desired_flow *d) -{ - return (d->installed_flow && d->installed_flow->desired_flow == d); -} - -/* Set a desired flow as the active one among the list of desired flows - * that are linked to the same installed flow. */ -static inline void -desired_flow_set_active(struct desired_flow *d) -{ - ovs_assert(d->installed_flow); - d->installed_flow->desired_flow = d; -} static bool flow_action_has_conj(const struct ovn_flow *f) @@ -831,27 +812,22 @@ flow_action_has_conj(const struct ovn_flow *f) /* Adds the desired flow to the list of desired flows that have same match * conditions as the installed flow. * - * If the newly added desired flow is the first one in the list, it is also set - * as the active one. - * * It is caller's responsibility to make sure the link between the pair didn't - * exist before. */ -static void + * exist before. + * + * Returns true if the newly added desired flow is selected to be the active + * one. + */ +static bool link_installed_to_desired(struct installed_flow *i, struct desired_flow *d) { - ovs_assert(i->desired_flow != d); - if (ovs_list_is_empty(&i->desired_refs)) { - ovs_assert(!i->desired_flow); - i->desired_flow = d; - } - ovs_list_insert(&i->desired_refs, &d->installed_ref_list_node); d->installed_flow = i; + ovs_list_push_back(&i->desired_refs, &d->installed_ref_list_node); + return installed_flow_get_active(i) == d; } /* Replaces 'old_desired' with 'new_desired' in the list of desired flows * that have same match conditions as the installed flow. - * - * If 'old_desired' was the active flow, 'new_desired' becomes the active one. */ static void replace_installed_to_desired(struct installed_flow *i, @@ -863,24 +839,22 @@ replace_installed_to_desired(struct installed_flow *i, &old_desired->installed_ref_list_node); old_desired->installed_flow = NULL; new_desired->installed_flow = i; - if (i->desired_flow == old_desired) { - i->desired_flow = new_desired; - } } -static void +/* Removes the desired flow from the list of desired flows that have the same + * match conditions as the installed flow. + * + * Returns true if the desired flow was the previously active flow. + */ +static bool unlink_installed_to_desired(struct installed_flow *i, struct desired_flow *d) { - ovs_assert(i && i->desired_flow && !ovs_list_is_empty(&i->desired_refs)); + struct desired_flow *old_active = installed_flow_get_active(i); + ovs_assert(d && d->installed_flow == i); ovs_list_remove(&d->installed_ref_list_node); d->installed_flow = NULL; - if (i->desired_flow == d) { - i->desired_flow = ovs_list_is_empty(&i->desired_refs) ? NULL : - CONTAINER_OF(ovs_list_front(&i->desired_refs), - struct desired_flow, - installed_ref_list_node); - } + return old_active == d; } static void @@ -1280,7 +1254,6 @@ installed_flow_dup(struct desired_flow *src) { struct installed_flow *dst = xmalloc(sizeof *dst); ovs_list_init(&dst->desired_refs); - dst->desired_flow = NULL; dst->flow.table_id = src->flow.table_id; dst->flow.priority = src->flow.priority; minimatch_clone(&dst->flow.match, &src->flow.match); @@ -1292,6 +1265,17 @@ installed_flow_dup(struct desired_flow *src) } static struct desired_flow * +installed_flow_get_active(struct installed_flow *f) +{ + if (!ovs_list_is_empty(&f->desired_refs)) { + return CONTAINER_OF(ovs_list_front(&f->desired_refs), + struct desired_flow, + installed_ref_list_node); + } + return NULL; +} + +static struct desired_flow * desired_flow_lookup__(struct ovn_desired_flow_table *flow_table, const struct ovn_flow *target, desired_flow_match_cb match_cb, @@ -1439,8 +1423,7 @@ static void installed_flow_destroy(struct installed_flow *f) { if (f) { - ovs_assert(ovs_list_is_empty(&f->desired_refs)); - ovs_assert(!f->desired_flow); + ovs_assert(!installed_flow_get_active(f)); ovn_flow_uninit(&f->flow); free(f); } @@ -1898,10 +1881,10 @@ update_installed_flows_by_track(struct ovn_desired_flow_table *flow_table, /* The desired flow was deleted */ if (f->installed_flow) { struct installed_flow *i = f->installed_flow; - bool was_active = desired_flow_is_active(f); - unlink_installed_to_desired(i, f); + bool was_active = unlink_installed_to_desired(i, f); + struct desired_flow *d = installed_flow_get_active(i); - if (!i->desired_flow) { + if (!d) { installed_flow_del(&i->flow, msgs); ovn_flow_log(&i->flow, "removing installed (tracked)"); @@ -1912,7 +1895,6 @@ update_installed_flows_by_track(struct ovn_desired_flow_table *flow_table, * installed flow, so update the OVS flow for the new * active flow (at least the cookie will be different, * even if the actions are the same). */ - struct desired_flow *d = i->desired_flow; ovn_flow_log(&i->flow, "updating installed (tracked)"); installed_flow_mod(&i->flow, &d->flow, msgs); } @@ -1931,7 +1913,7 @@ update_installed_flows_by_track(struct ovn_desired_flow_table *flow_table, hmap_insert(&installed_flows, &new_node->match_hmap_node, new_node->flow.hash); link_installed_to_desired(new_node, f); - } else if (desired_flow_is_active(f)) { + } else if (installed_flow_get_active(i) == f) { /* The installed flow is installed for f, but f has change * tracked, so it must have been modified. */ ovn_flow_log(&i->flow, "updating installed (tracked)");