From patchwork Mon Sep 7 06:45:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Han Zhou X-Patchwork-Id: 1358621 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.136; helo=silver.osuosl.org; envelope-from=ovs-dev-bounces@openvswitch.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=ovn.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BlJm90jjvz9sR4 for ; Mon, 7 Sep 2020 16:49:13 +1000 (AEST) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 718612051E; Mon, 7 Sep 2020 06:49:11 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id km9-M00pmj32; Mon, 7 Sep 2020 06:48:56 +0000 (UTC) Received: from lists.linuxfoundation.org (lf-lists.osuosl.org [140.211.9.56]) by silver.osuosl.org (Postfix) with ESMTP id D35FE204E0; Mon, 7 Sep 2020 06:47:25 +0000 (UTC) Received: from lf-lists.osuosl.org (localhost [127.0.0.1]) by lists.linuxfoundation.org (Postfix) with ESMTP id ABE94C0893; Mon, 7 Sep 2020 06:47:25 +0000 (UTC) X-Original-To: dev@openvswitch.org Delivered-To: ovs-dev@lists.linuxfoundation.org Received: from silver.osuosl.org (smtp3.osuosl.org [140.211.166.136]) by lists.linuxfoundation.org (Postfix) with ESMTP id A0525C0051 for ; Mon, 7 Sep 2020 06:47:24 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by silver.osuosl.org (Postfix) with ESMTP id 723FF20533 for ; Mon, 7 Sep 2020 06:47:24 +0000 (UTC) X-Virus-Scanned: amavisd-new at osuosl.org Received: from silver.osuosl.org ([127.0.0.1]) by localhost (.osuosl.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id SF+jV8h6e8Ky for ; Mon, 7 Sep 2020 06:47:17 +0000 (UTC) X-Greylist: domain auto-whitelisted by SQLgrey-1.7.6 Received: from relay11.mail.gandi.net (relay11.mail.gandi.net [217.70.178.231]) by silver.osuosl.org (Postfix) with ESMTPS id 948BE20763 for ; Mon, 7 Sep 2020 06:46:38 +0000 (UTC) Received: from localhost.localdomain.localdomain (unknown [73.241.94.255]) (Authenticated sender: hzhou@ovn.org) by relay11.mail.gandi.net (Postfix) with ESMTPSA id 01F6F10000A; Mon, 7 Sep 2020 06:46:34 +0000 (UTC) From: Han Zhou To: dev@openvswitch.org Date: Sun, 6 Sep 2020 23:45:40 -0700 Message-Id: <1599461142-84752-8-git-send-email-hzhou@ovn.org> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1599461142-84752-1-git-send-email-hzhou@ovn.org> References: <1599461142-84752-1-git-send-email-hzhou@ovn.org> Cc: Han Zhou Subject: [ovs-dev] [PATCH ovn v2 7/9] ofctrl.c: Refactor - move openflow msg construction to functions. 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" These functions will be reused in multiple places in a future patch. Signed-off-by: Han Zhou --- controller/ofctrl.c | 103 ++++++++++++++++++++++++++++++---------------------- 1 file changed, 60 insertions(+), 43 deletions(-) diff --git a/controller/ofctrl.c b/controller/ofctrl.c index ecea081..bc6a115 100644 --- a/controller/ofctrl.c +++ b/controller/ofctrl.c @@ -1480,6 +1480,63 @@ add_meter(struct ovn_extend_table_info *m_desired, free(mm.meter.bands); } +static void +installed_flow_add(struct ovn_flow *d, struct ovs_list *msgs) +{ + /* Send flow_mod to add flow. */ + struct ofputil_flow_mod fm = { + .match = d->match, + .priority = d->priority, + .table_id = d->table_id, + .ofpacts = d->ofpacts, + .ofpacts_len = d->ofpacts_len, + .new_cookie = htonll(d->cookie), + .command = OFPFC_ADD, + }; + add_flow_mod(&fm, msgs); +} + +static void +installed_flow_mod(struct ovn_flow *i, struct ovn_flow *d, + struct ovs_list *msgs) +{ + /* Update actions in installed flow. */ + struct ofputil_flow_mod fm = { + .match = i->match, + .priority = i->priority, + .table_id = i->table_id, + .ofpacts = d->ofpacts, + .ofpacts_len = d->ofpacts_len, + .command = OFPFC_MODIFY_STRICT, + }; + /* Update cookie if it is changed. */ + if (i->cookie != d->cookie) { + fm.modify_cookie = true; + fm.new_cookie = htonll(d->cookie); + /* Use OFPFC_ADD so that cookie can be updated. */ + fm.command = OFPFC_ADD; + } + add_flow_mod(&fm, msgs); + + /* Replace 'i''s actions and cookie by 'd''s. */ + free(i->ofpacts); + i->ofpacts = xmemdup(d->ofpacts, d->ofpacts_len); + i->ofpacts_len = d->ofpacts_len; + i->cookie = d->cookie; +} + +static void +installed_flow_del(struct ovn_flow *i, struct ovs_list *msgs) +{ + struct ofputil_flow_mod fm = { + .match = i->match, + .priority = i->priority, + .table_id = i->table_id, + .command = OFPFC_DELETE_STRICT, + }; + add_flow_mod(&fm, msgs); +} + /* The flow table can be updated if the connection to the switch is up and * in the correct state and not backlogged with existing flow_mods. (Our * criteria for being backlogged appear very conservative, but the socket @@ -1605,46 +1662,16 @@ ofctrl_put(struct ovn_desired_flow_table *flow_table, if (!d) { /* Installed flow is no longer desirable. Delete it from the * switch and from installed_flows. */ - struct ofputil_flow_mod fm = { - .match = i->flow.match, - .priority = i->flow.priority, - .table_id = i->flow.table_id, - .command = OFPFC_DELETE_STRICT, - }; - add_flow_mod(&fm, &msgs); + installed_flow_del(&i->flow, &msgs); ovn_flow_log(&i->flow, "removing installed"); - hmap_remove(&installed_flows, &i->match_hmap_node); installed_flow_destroy(i); } else { if (!ofpacts_equal(i->flow.ofpacts, i->flow.ofpacts_len, d->flow.ofpacts, d->flow.ofpacts_len) || i->flow.cookie != d->flow.cookie) { - /* Update actions in installed flow. */ - struct ofputil_flow_mod fm = { - .match = i->flow.match, - .priority = i->flow.priority, - .table_id = i->flow.table_id, - .ofpacts = d->flow.ofpacts, - .ofpacts_len = d->flow.ofpacts_len, - .command = OFPFC_MODIFY_STRICT, - }; - /* Update cookie if it is changed. */ - if (i->flow.cookie != d->flow.cookie) { - fm.modify_cookie = true; - fm.new_cookie = htonll(d->flow.cookie); - /* Use OFPFC_ADD so that cookie can be updated. */ - fm.command = OFPFC_ADD, - i->flow.cookie = d->flow.cookie; - } - add_flow_mod(&fm, &msgs); ovn_flow_log(&i->flow, "updating installed"); - - /* Replace 'i''s actions by 'd''s. */ - free(i->flow.ofpacts); - i->flow.ofpacts = xmemdup(d->flow.ofpacts, - d->flow.ofpacts_len); - i->flow.ofpacts_len = d->flow.ofpacts_len; + installed_flow_mod(&i->flow, &d->flow, &msgs); } link_installed_to_desired(i, d); @@ -1657,17 +1684,7 @@ ofctrl_put(struct ovn_desired_flow_table *flow_table, HMAP_FOR_EACH (d, match_hmap_node, &flow_table->match_flow_table) { i = installed_flow_lookup(&d->flow); if (!i) { - /* Send flow_mod to add flow. */ - struct ofputil_flow_mod fm = { - .match = d->flow.match, - .priority = d->flow.priority, - .table_id = d->flow.table_id, - .ofpacts = d->flow.ofpacts, - .ofpacts_len = d->flow.ofpacts_len, - .new_cookie = htonll(d->flow.cookie), - .command = OFPFC_ADD, - }; - add_flow_mod(&fm, &msgs); + installed_flow_add(&d->flow, &msgs); ovn_flow_log(&d->flow, "adding installed"); /* Copy 'd' from 'flow_table' to installed_flows. */