This commit provides an option to enable or disable packet processing
coming from the datapath.

This option is useful during Open vSwitch upgrades. Typically we want
to restart openvswitch, add the openflow flows and then start packet
processing. The next commit will use these commands in Open vSwitch
startup scripts.

Bug #16086.
Signed-off-by: Gurucharan Shetty <gshe...@nicira.com>
---
 ofproto/ofproto-dpif.c |   21 ++++++++++++++++++++-
 vswitchd/bridge.c      |    7 +++++++
 vswitchd/vswitch.xml   |    9 +++++++++
 3 files changed, 36 insertions(+), 1 deletion(-)

diff --git a/ofproto/ofproto-dpif.c b/ofproto/ofproto-dpif.c
index c4f7d25..a31b186 100644
--- a/ofproto/ofproto-dpif.c
+++ b/ofproto/ofproto-dpif.c
@@ -72,6 +72,8 @@ COVERAGE_DEFINE(facet_suppress);
  * flow translation. */
 #define MAX_RESUBMIT_RECURSION 64
 
+extern bool recv_set_enable;
+
 /* Number of implemented OpenFlow tables. */
 enum { N_TABLES = 255 };
 enum { TBL_INTERNAL = N_TABLES - 1 };    /* Used for internal hidden rules. */
@@ -671,6 +673,7 @@ struct dpif_backer {
     struct tag_set revalidate_set; /* Revalidate only matching facets. */
 
     struct hmap drop_keys; /* Set of dropped odp keys. */
+    bool recv_set_enable; /* Enables or disables receiving packets. */
 };
 
 /* All existing ofproto_backer instances, indexed by ofproto->up.type. */
@@ -937,6 +940,21 @@ type_run(const char *type)
 
     dpif_run(backer->dpif);
 
+    /* Enable or disable receiving packets on 'dpif' based on user
+     * configuration. */
+    if (backer->recv_set_enable != recv_set_enable) {
+        backer->recv_set_enable = recv_set_enable;
+        error = dpif_recv_set(backer->dpif, recv_set_enable);
+        if (error) {
+            VLOG_ERR("Failed to %s receiving packets in dpif",
+                     recv_set_enable ? "enable" : "disable");
+            return error;
+        }
+        if (recv_set_enable) {
+            backer->need_revalidate = REV_RECONFIGURE;
+        }
+    }
+
     /* The most natural place to push facet statistics is when they're pulled
      * from the datapath.  However, when there are many flows in the datapath,
      * this expensive operation can occur so frequently, that it reduces our
@@ -1331,7 +1349,8 @@ open_dpif_backer(const char *type, struct dpif_backer 
**backerp)
 
     shash_add(&all_dpif_backers, type, backer);
 
-    error = dpif_recv_set(backer->dpif, true);
+    backer->recv_set_enable = recv_set_enable;
+    error = dpif_recv_set(backer->dpif, recv_set_enable);
     if (error) {
         VLOG_ERR("failed to listen on datapath of type %s: %s",
                  type, strerror(error));
diff --git a/vswitchd/bridge.c b/vswitchd/bridge.c
index e10036c..80e22fb 100644
--- a/vswitchd/bridge.c
+++ b/vswitchd/bridge.c
@@ -183,6 +183,9 @@ static long long int iface_stats_timer = LLONG_MIN;
 #define OFP_PORT_ACTION_WINDOW 10
 static bool reconfiguring = false;
 
+/* The default value of true enables receving packets on 'dpif'. */
+bool recv_set_enable = true;
+
 static void add_del_bridges(const struct ovsrec_open_vswitch *);
 static void bridge_update_ofprotos(void);
 static void bridge_create(const struct ovsrec_bridge *);
@@ -2321,6 +2324,10 @@ bridge_run(void)
      * returns immediately. */
     bridge_init_ofproto(cfg);
 
+    /* Enables or disables receiving packets on 'dpif'. */
+    recv_set_enable = smap_get_bool(&cfg->other_config,
+                                    "dpif-packet-receive", true);
+
     /* Let each datapath type do the work that it needs to do. */
     sset_init(&types);
     ofproto_enumerate_types(&types);
diff --git a/vswitchd/vswitch.xml b/vswitchd/vswitch.xml
index 4396779..fa033f6 100644
--- a/vswitchd/vswitch.xml
+++ b/vswitchd/vswitch.xml
@@ -104,6 +104,15 @@
           column or to <code>false</code> to explicitly disable it.
         </column>
 
+        <column name="other_config" key="dpif-packet-receive"
+                type='{"type": "boolean"}'>
+          Packets are received from the datapath by default. Set this value to
+          <code>false</code> to stop receiving packets from the datapath and
+          <code>true</code> to start receiving packets. This option is useful
+          during openvswitch upgrades and is used to restore flows before
+          processing the packets.
+        </column>
+
         <column name="statistics" key="cpu"
                 type='{"type": "integer", "minInteger": 1}'>
           <p>
-- 
1.7.9.5

_______________________________________________
dev mailing list
dev@openvswitch.org
http://openvswitch.org/mailman/listinfo/dev

Reply via email to