ofproto: Improve abstraction by adding function ofproto_parse_name().
authorBen Pfaff <blp@nicira.com>
Mon, 11 Apr 2011 22:08:19 +0000 (15:08 -0700)
committerBen Pfaff <blp@nicira.com>
Wed, 11 May 2011 19:26:08 +0000 (12:26 -0700)
This means that ovs-ofctl and ovs-openflowd don't have to use the dpif
layer at all, making it easier to change the ofproto implementation.

ofproto/automake.mk
ofproto/names.c [new file with mode: 0644]
ofproto/ofproto.h
utilities/automake.mk
utilities/ovs-ofctl.c
utilities/ovs-openflowd.c

index ef45e9f273ad189fb717d7bd05fd875ce644396c..815355123a85eb8d3da8b84f8ff9bb2c6d26067e 100644 (file)
@@ -15,6 +15,7 @@ ofproto_libofproto_a_SOURCES = \
        ofproto/fail-open.h \
        ofproto/in-band.c \
        ofproto/in-band.h \
+       ofproto/names.c \
        ofproto/netflow.c \
        ofproto/netflow.h \
        ofproto/ofproto.c \
diff --git a/ofproto/names.c b/ofproto/names.c
new file mode 100644 (file)
index 0000000..724b184
--- /dev/null
@@ -0,0 +1,35 @@
+/*
+ * Copyright (c) 2011 Nicira Networks.
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at:
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+#include <config.h>
+
+#include "ofproto/ofproto.h"
+
+#include "dpif.h"
+
+/* This function is in a separate file because it is the only ofproto function
+ * required by ovs-ofctl, which allows ovs-ofctl to avoid linking in extra
+ * baggage. */
+
+/* Parses 'ofproto_name', which is of the form [type@]name into component
+ * pieces that are suitable for passing to ofproto_create().  The caller must
+ * free 'name' and 'type'. */
+void
+ofproto_parse_name(const char *ofproto_name, char **name, char **type)
+{
+    dp_parse_name(ofproto_name, name, type);
+}
+
index 2b8011daa88a6f59742ff52751f5ee203b440abd..4c54873a104a58faa1df7a86f9a513da7e920862 100644 (file)
@@ -93,6 +93,8 @@ struct ofproto_controller {
 #define DEFAULT_SERIAL_DESC "None"
 #define DEFAULT_DP_DESC "None"
 
+void ofproto_parse_name(const char *name, char **dp_name, char **dp_type);
+
 int ofproto_create(const char *datapath, const char *datapath_type,
                    struct ofproto **ofprotop);
 void ofproto_destroy(struct ofproto *);
index fc3a19de64a872fe4d0676934e3ce605f97f6ff4..cb06f5a3e8523739422586a07a92e4bfd86bbb97 100644 (file)
@@ -78,7 +78,10 @@ utilities_ovs_dpctl_SOURCES = utilities/ovs-dpctl.c
 utilities_ovs_dpctl_LDADD = lib/libopenvswitch.a
 
 utilities_ovs_ofctl_SOURCES = utilities/ovs-ofctl.c
-utilities_ovs_ofctl_LDADD = lib/libopenvswitch.a $(SSL_LIBS)
+utilities_ovs_ofctl_LDADD = \
+       ofproto/libofproto.a \
+       lib/libopenvswitch.a \
+       $(SSL_LIBS)
 
 utilities_ovs_openflowd_SOURCES = utilities/ovs-openflowd.c
 utilities_ovs_openflowd_LDADD = \
index bc8cc6bd8e8391b22d1d6d1c8b66d5cf3b3f3f3b..660fc3aedca00054ce028b7385d46bbdee2e8d4e 100644 (file)
@@ -32,7 +32,6 @@
 #include "command-line.h"
 #include "compiler.h"
 #include "dirs.h"
-#include "dpif.h"
 #include "dynamic-string.h"
 #include "netlink.h"
 #include "nx-match.h"
@@ -41,6 +40,7 @@
 #include "ofp-print.h"
 #include "ofp-util.h"
 #include "ofpbuf.h"
+#include "ofproto/ofproto.h"
 #include "openflow/nicira-ext.h"
 #include "openflow/openflow.h"
 #include "random.h"
@@ -220,12 +220,17 @@ static void
 open_vconn__(const char *name, const char *default_suffix,
              struct vconn **vconnp)
 {
-    struct dpif *dpif;
+    char *datapath_name, *datapath_type, *socket_name;
+    char *bridge_path;
     struct stat s;
-    char *bridge_path, *datapath_name, *datapath_type;
 
     bridge_path = xasprintf("%s/%s.%s", ovs_rundir(), name, default_suffix);
-    dp_parse_name(name, &datapath_name, &datapath_type);
+
+    ofproto_parse_name(name, &datapath_name, &datapath_type);
+    socket_name = xasprintf("%s/%s.%s",
+                            ovs_rundir(), datapath_name, default_suffix);
+    free(datapath_name);
+    free(datapath_type);
 
     if (strstr(name, ":")) {
         run(vconn_open_block(name, OFP_VERSION, vconnp),
@@ -234,36 +239,18 @@ open_vconn__(const char *name, const char *default_suffix,
         open_vconn_socket(name, vconnp);
     } else if (!stat(bridge_path, &s) && S_ISSOCK(s.st_mode)) {
         open_vconn_socket(bridge_path, vconnp);
-    } else if (!dpif_open(datapath_name, datapath_type, &dpif)) {
-        char dpif_name[IF_NAMESIZE + 1];
-        char *socket_name;
-
-        run(dpif_port_get_name(dpif, ODPP_LOCAL, dpif_name, sizeof dpif_name),
-            "obtaining name of %s", dpif_name);
-        dpif_close(dpif);
-        if (strcmp(dpif_name, name)) {
-            VLOG_DBG("datapath %s is named %s", name, dpif_name);
-        }
-
-        socket_name = xasprintf("%s/%s.%s",
-                                ovs_rundir(), dpif_name, default_suffix);
-        if (stat(socket_name, &s)) {
-            ovs_fatal(errno, "cannot connect to %s: stat failed on %s",
-                      name, socket_name);
-        } else if (!S_ISSOCK(s.st_mode)) {
+    } else if (!stat(socket_name, &s)) {
+        if (!S_ISSOCK(s.st_mode)) {
             ovs_fatal(0, "cannot connect to %s: %s is not a socket",
                       name, socket_name);
         }
-
         open_vconn_socket(socket_name, vconnp);
-        free(socket_name);
     } else {
         ovs_fatal(0, "%s is not a valid connection method", name);
     }
 
-    free(datapath_name);
-    free(datapath_type);
     free(bridge_path);
+    free(socket_name);
 }
 
 static void
index 4e83036729d2959e582a40c493dc87ae287af02e..2d2446e137c61231ae85f212a96f2ad9582c6ccc 100644 (file)
@@ -28,7 +28,6 @@
 #include "compiler.h"
 #include "daemon.h"
 #include "dirs.h"
-#include "dpif.h"
 #include "dummy.h"
 #include "leak-checker.h"
 #include "list.h"
@@ -472,7 +471,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
     }
 
     /* Local vconns. */
-    dp_parse_name(argv[0], &s->dp_name, &s->dp_type);
+    ofproto_parse_name(argv[0], &s->dp_name, &s->dp_type);
 
     /* Figure out controller names. */
     s->run_forever = false;