5f9769
From 07b0f0468faeeb1e149dcc3e4926a54cbb9bb367 Mon Sep 17 00:00:00 2001
5f9769
From: Dumitru Ceara <dceara@redhat.com>
5f9769
Date: Wed, 3 Feb 2021 20:36:52 +0100
5f9769
Subject: [PATCH 3/4] northd: Allow backwards compatibility for
5f9769
 Logical_Switch_Port.up.
5f9769
5f9769
In general, ovn-northd expects ovn-controller to set Port_Binding.up
5f9769
before it declares the logical switch port as being up.
5f9769
5f9769
Even though the recommended upgrade procedure for OVN states that
5f9769
ovn-controllers should be upgraded before ovn-northd, there are cases
5f9769
when CMSs don't follow this guideline.
5f9769
5f9769
This would cause all existing and bound Logical_Switch_Ports to be
5f9769
declared "down" until ovn-controllers are upgraded.
5f9769
5f9769
To avoid this situation, ovn-controllers now explicitly set
5f9769
Chassis.other_config:port-up-notif in their own chassis record.  Based
5f9769
on this value, ovn-northd can determine if it needs to use the old type
5f9769
of logic or the new one (Port_Binding.up) when setting LSP.up.
5f9769
5f9769
Note:
5f9769
In case of downgrading ovn-controller before ovn-northd, if
5f9769
ovn-controller is forcefully stopped it will not clear its chassis
5f9769
record from the SB. Older versions will not have the capability to
5f9769
clear the other_config:port-up-notif value so LSPs will be declared
5f9769
"down" until ovn-northd is downgraded as well.  As this
5f9769
upgrade/downgrade procedure is not the recommended one, we don't try
5f9769
to deal with this scenario.
5f9769
5f9769
Signed-off-by: Dumitru Ceara <dceara@redhat.com>
5f9769
Signed-off-by: Numan Siddique <numans@ovn.org>
5f9769
(cherry picked from upstream commit a99af0367acc744321747bad33bf598d06a612de)
5f9769
5f9769
Change-Id: Iaec681d05abec490b7e7cb330f1ca8f00149cefb
5f9769
---
5f9769
 controller/chassis.c    |  7 +++++++
5f9769
 include/ovn/automake.mk |  1 +
5f9769
 include/ovn/features.h  | 22 ++++++++++++++++++++++
5f9769
 northd/ovn-northd.c     | 13 ++++++++++++-
5f9769
 ovn-sb.xml              |  5 +++++
5f9769
 tests/ovn-controller.at | 17 +++++++++++++++++
5f9769
 tests/ovn-northd.at     | 22 ++++++++++++++++++++++
5f9769
 7 files changed, 86 insertions(+), 1 deletion(-)
5f9769
 create mode 100644 include/ovn/features.h
5f9769
5f9769
diff --git a/controller/chassis.c b/controller/chassis.c
5f9769
index b4d4b0e..0937e33 100644
5f9769
--- a/controller/chassis.c
5f9769
+++ b/controller/chassis.c
5f9769
@@ -28,6 +28,7 @@
5f9769
 #include "lib/ovn-sb-idl.h"
5f9769
 #include "ovn-controller.h"
5f9769
 #include "lib/util.h"
5f9769
+#include "ovn/features.h"
5f9769
 
5f9769
 VLOG_DEFINE_THIS_MODULE(chassis);
5f9769
 
5f9769
@@ -293,6 +294,7 @@ chassis_build_other_config(struct smap *config, const char *bridge_mappings,
5f9769
     smap_replace(config, "iface-types", iface_types);
5f9769
     smap_replace(config, "ovn-chassis-mac-mappings", chassis_macs);
5f9769
     smap_replace(config, "is-interconn", is_interconn ? "true" : "false");
5f9769
+    smap_replace(config, OVN_FEATURE_PORT_UP_NOTIF, "true");
5f9769
 }
5f9769
 
5f9769
 /*
5f9769
@@ -363,6 +365,11 @@ chassis_other_config_changed(const char *bridge_mappings,
5f9769
         return true;
5f9769
     }
5f9769
 
5f9769
+    if (!smap_get_bool(&chassis_rec->other_config, OVN_FEATURE_PORT_UP_NOTIF,
5f9769
+                       false)) {
5f9769
+        return true;
5f9769
+    }
5f9769
+
5f9769
     return false;
5f9769
 }
5f9769
 
5f9769
diff --git a/include/ovn/automake.mk b/include/ovn/automake.mk
5f9769
index 54b0e2c..582241a 100644
5f9769
--- a/include/ovn/automake.mk
5f9769
+++ b/include/ovn/automake.mk
5f9769
@@ -2,5 +2,6 @@ ovnincludedir = $(includedir)/ovn
5f9769
 ovninclude_HEADERS = \
5f9769
 	include/ovn/actions.h \
5f9769
 	include/ovn/expr.h \
5f9769
+	include/ovn/features.h \
5f9769
 	include/ovn/lex.h  \
5f9769
 	include/ovn/logical-fields.h
5f9769
diff --git a/include/ovn/features.h b/include/ovn/features.h
5f9769
new file mode 100644
5f9769
index 0000000..10ee46f
5f9769
--- /dev/null
5f9769
+++ b/include/ovn/features.h
5f9769
@@ -0,0 +1,22 @@
5f9769
+/* Copyright (c) 2021, Red Hat, Inc.
5f9769
+ *
5f9769
+ * Licensed under the Apache License, Version 2.0 (the "License");
5f9769
+ * you may not use this file except in compliance with the License.
5f9769
+ * You may obtain a copy of the License at:
5f9769
+ *
5f9769
+ *     http://www.apache.org/licenses/LICENSE-2.0
5f9769
+ *
5f9769
+ * Unless required by applicable law or agreed to in writing, software
5f9769
+ * distributed under the License is distributed on an "AS IS" BASIS,
5f9769
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
5f9769
+ * See the License for the specific language governing permissions and
5f9769
+ * limitations under the License.
5f9769
+ */
5f9769
+
5f9769
+#ifndef OVN_FEATURES_H
5f9769
+#define OVN_FEATURES_H 1
5f9769
+
5f9769
+/* ovn-controller supported feature names. */
5f9769
+#define OVN_FEATURE_PORT_UP_NOTIF "port-up-notif"
5f9769
+
5f9769
+#endif
5f9769
diff --git a/northd/ovn-northd.c b/northd/ovn-northd.c
5f9769
index 0dc920b..62d45f9 100644
5f9769
--- a/northd/ovn-northd.c
5f9769
+++ b/northd/ovn-northd.c
5f9769
@@ -38,6 +38,7 @@
5f9769
 #include "lib/ovn-util.h"
5f9769
 #include "lib/lb.h"
5f9769
 #include "ovn/actions.h"
5f9769
+#include "ovn/features.h"
5f9769
 #include "ovn/logical-fields.h"
5f9769
 #include "packets.h"
5f9769
 #include "openvswitch/poll-loop.h"
5f9769
@@ -13057,7 +13058,17 @@ handle_port_binding_changes(struct northd_context *ctx, struct hmap *ports,
5f9769
             continue;
5f9769
         }
5f9769
 
5f9769
-        bool up = ((sb->up && (*sb->up)) || lsp_is_router(op->nbsp));
5f9769
+        bool up = false;
5f9769
+
5f9769
+        if (lsp_is_router(op->nbsp)) {
5f9769
+            up = true;
5f9769
+        } else if (sb->chassis) {
5f9769
+            up = smap_get_bool(&sb->chassis->other_config,
5f9769
+                               OVN_FEATURE_PORT_UP_NOTIF, false)
5f9769
+                 ? sb->n_up && sb->up[0]
5f9769
+                 : true;
5f9769
+        }
5f9769
+
5f9769
         if (!op->nbsp->up || *op->nbsp->up != up) {
5f9769
             nbrec_logical_switch_port_set_up(op->nbsp, &up, 1);
5f9769
         }
5f9769
diff --git a/ovn-sb.xml b/ovn-sb.xml
5f9769
index 4c82d51..980a096 100644
5f9769
--- a/ovn-sb.xml
5f9769
+++ b/ovn-sb.xml
5f9769
@@ -322,6 +322,11 @@
5f9769
       table. See ovn-controller(8) for more information.
5f9769
     </column>
5f9769
 
5f9769
+    <column name="other_config" key="port-up-notif">
5f9769
+      ovn-controller populates this key with true
5f9769
+      when it supports Port_Binding.up.
5f9769
+    </column>
5f9769
+
5f9769
     <group title="Common Columns">
5f9769
       The overall purpose of these columns is described under Common
5f9769
       Columns at the beginning of this document.
5f9769
diff --git a/tests/ovn-controller.at b/tests/ovn-controller.at
5f9769
index 1b46799..f818f9c 100644
5f9769
--- a/tests/ovn-controller.at
5f9769
+++ b/tests/ovn-controller.at
5f9769
@@ -414,3 +414,20 @@ OVS_WAIT_UNTIL([ovs-vsctl get Bridge br-int external_ids:ovn-nb-cfg], [0], [1])
5f9769
 
5f9769
 OVN_CLEANUP([hv1])
5f9769
 AT_CLEANUP
5f9769
+
5f9769
+AT_SETUP([ovn -- features])
5f9769
+AT_KEYWORDS([features])
5f9769
+ovn_start
5f9769
+
5f9769
+net_add n1
5f9769
+sim_add hv1
5f9769
+ovs-vsctl add-br br-phys
5f9769
+ovn_attach n1 br-phys 192.168.0.1
5f9769
+
5f9769
+# Wait for ovn-controller to register in the SB.
5f9769
+OVS_WAIT_UNTIL([
5f9769
+    test "$(ovn-sbctl get chassis hv1 other_config:port-up-notif)" = '"true"'
5f9769
+])
5f9769
+
5f9769
+OVN_CLEANUP([hv1])
5f9769
+AT_CLEANUP
5f9769
diff --git a/tests/ovn-northd.at b/tests/ovn-northd.at
5f9769
index c00225e..d52aeed 100644
5f9769
--- a/tests/ovn-northd.at
5f9769
+++ b/tests/ovn-northd.at
5f9769
@@ -2452,3 +2452,25 @@ check ovn-nbctl --wait=sb sync
5f9769
 AT_CHECK([grep -qE 'duplicate logical.*port p1' northd/ovn-northd.log], [0])
5f9769
 
5f9769
 AT_CLEANUP
5f9769
+
5f9769
+AT_SETUP([ovn -- Port_Binding.up backwards compatibility])
5f9769
+ovn_start
5f9769
+
5f9769
+ovn-nbctl ls-add ls1
5f9769
+ovn-nbctl --wait=sb lsp-add ls1 lsp1
5f9769
+
5f9769
+# Simulate the fact that lsp1 had been previously bound on hv1 by an
5f9769
+# ovn-controller running an older version.
5f9769
+ovn-sbctl \
5f9769
+    --id=@e create encap chassis_name=hv1 ip="192.168.0.1" type="geneve" \
5f9769
+    -- --id=@c create chassis name=hv1 encaps=@e \
5f9769
+    -- set Port_Binding lsp1 chassis=@c
5f9769
+
5f9769
+wait_for_ports_up lsp1
5f9769
+
5f9769
+# Simulate the fact that hv1 is aware of Port_Binding.up, ovn-northd
5f9769
+# should transition the port state to down.
5f9769
+check ovn-sbctl set chassis hv1 other_config:port-up-notif=true
5f9769
+wait_row_count nb:Logical_Switch_Port 1 up=false name=lsp1
5f9769
+
5f9769
+AT_CLEANUP
5f9769
-- 
5f9769
1.8.3.1
5f9769