[ovs-dev] [PATCH 2/2] openflowd: Update for changes to dpif and netdev.

Jesse Gross jesse at nicira.com
Fri Jan 22 19:52:42 UTC 2010


Openflowd had been a bit neglected as changes were made to the dpif
and netdev interfaces over time.  This brings it up to date with all
the latest changes.
---
 utilities/ovs-openflowd.c |   40 ++++++++++++++++++++++++++++++----------
 1 files changed, 30 insertions(+), 10 deletions(-)

diff --git a/utilities/ovs-openflowd.c b/utilities/ovs-openflowd.c
index 2c688cb..9812d21 100644
--- a/utilities/ovs-openflowd.c
+++ b/utilities/ovs-openflowd.c
@@ -63,6 +63,7 @@ struct ofsettings {
     /* Datapath. */
     uint64_t datapath_id;       /* Datapath ID. */
     const char *dp_name;        /* Name of local datapath. */
+    const char *dp_type;        /* Type of local datapath. */
     struct svec ports;          /* Set of ports to add to datapath (if any). */
 
     /* Description strings. */
@@ -110,6 +111,7 @@ main(int argc, char *argv[])
     struct ofproto *ofproto;
     struct ofsettings s;
     int error;
+    struct dpif *dpif;
     struct netflow_options nf_options;
 
     set_program_name(argv[0]);
@@ -130,28 +132,32 @@ main(int argc, char *argv[])
     VLOG_INFO("Open vSwitch version %s", VERSION BUILDNR);
     VLOG_INFO("OpenFlow protocol version 0x%02x", OFP_VERSION);
 
-    /* Create the datapath and add ports to it, if requested by the user. */
+    error = dpif_create_and_open(s.dp_name, s.dp_type, &dpif);
+    if (error) {
+        ovs_fatal(error, "could not create datapath");
+    }
+
+    /* Add ports to the datapath if requested by the user. */
     if (s.ports.n) {
-        struct dpif *dpif;
         const char *port;
         size_t i;
-
-        error = dpif_create_and_open(s.dp_name, NULL, &dpif);
-        if (error) {
-            ovs_fatal(error, "could not create datapath");
-        }
+        struct netdev *netdev;
 
         SVEC_FOR_EACH (i, port, &s.ports) {
+            error = netdev_open_default(port, &netdev);
+            if (error) {
+                ovs_fatal(error, "failed to open %s as a device", port);
+            }
+
             error = dpif_port_add(dpif, port, 0, NULL);
             if (error) {
                 ovs_fatal(error, "failed to add %s as a port", port);
             }
         }
-        dpif_close(dpif);
     }
 
     /* Start OpenFlow processing. */
-    error = ofproto_create(s.dp_name, NULL, NULL, NULL, &ofproto);
+    error = ofproto_create(s.dp_name, s.dp_type, NULL, NULL, &ofproto);
     if (error) {
         ovs_fatal(error, "could not initialize openflow switch");
     }
@@ -225,6 +231,8 @@ main(int argc, char *argv[])
         poll_block();
     }
 
+    dpif_close(dpif);
+
     return 0;
 }
 
@@ -298,6 +306,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
         {0, 0, 0, 0},
     };
     char *short_options = long_options_to_short_options(long_options);
+    char *datapath_arg, *dp_separator;
 
     /* Set defaults that we can figure out before parsing options. */
     s->datapath_id = 0;
@@ -498,7 +507,18 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
     }
 
     /* Local and remote vconns. */
-    s->dp_name = argv[0];
+    datapath_arg = xstrdup(argv[0]);
+    dp_separator = strchr(datapath_arg, ':');
+    if (dp_separator) {
+        *dp_separator = '\0';
+        s->dp_type = datapath_arg;
+        s->dp_name = dp_separator + 1;
+    } else {
+        s->dp_name = datapath_arg;
+        s->dp_type = NULL;
+    }
+
+
     s->controller_name = argc > 1 ? xstrdup(argv[1]) : NULL;
 
     /* Set accept_controller_regex. */
-- 
1.6.3.3





More information about the dev mailing list