test-openflowd: Allow specifying port type on --ports option.
authorBen Pfaff <blp@nicira.com>
Thu, 18 Aug 2011 18:20:12 +0000 (11:20 -0700)
committerBen Pfaff <blp@nicira.com>
Tue, 13 Sep 2011 18:46:09 +0000 (11:46 -0700)
This allows a command like "test-openflowd --enable-dummy dummy@br0
--ports=dummy@eth0,dummy@eth1,dummy@eth2" to create a dummy datapath with
a number of dummy ports.  This is more useful for testing than a dummy
datapath with just an internal port, since output to "flood" and "normal"
has less pathological results.

lib/netdev.c
lib/netdev.h
tests/test-openflowd.c

index 9fba077..0074de0 100644 (file)
@@ -359,6 +359,25 @@ netdev_enumerate(struct sset *sset)
     return error;
 }
 
+/* Parses 'netdev_name_', which is of the form [type@]name into its component
+ * pieces.  'name' and 'type' must be freed by the caller. */
+void
+netdev_parse_name(const char *netdev_name_, char **name, char **type)
+{
+    char *netdev_name = xstrdup(netdev_name_);
+    char *separator;
+
+    separator = strchr(netdev_name, '@');
+    if (separator) {
+        *separator = '\0';
+        *type = netdev_name;
+        *name = xstrdup(separator + 1);
+    } else {
+        *name = netdev_name;
+        *type = xstrdup("system");
+    }
+}
+
 /* Attempts to set up 'netdev' for receiving packets with netdev_recv().
  * Returns 0 if successful, otherwise a positive errno value.  EOPNOTSUPP
  * indicates that the network device does not implement packet reception
index 2644708..11b6925 100644 (file)
@@ -92,6 +92,8 @@ bool netdev_is_open(const char *name);
 
 int netdev_enumerate(struct sset *);
 
+void netdev_parse_name(const char *netdev_name, char **name, char **type);
+
 /* Options. */
 int netdev_set_config(struct netdev *, const struct shash *args);
 int netdev_get_config(const struct netdev *, struct shash *);
index 016e1cb..3cc3a75 100644 (file)
@@ -123,12 +123,16 @@ main(int argc, char *argv[])
     /* Add ports to the datapath if requested by the user. */
     SSET_FOR_EACH (port, &s.ports) {
         struct netdev *netdev;
+        char *name, *type;
 
-        error = netdev_open(port, "system", &netdev);
+        netdev_parse_name(port, &name, &type);
+        error = netdev_open(name, type, &netdev);
         if (error) {
             VLOG_FATAL("%s: failed to open network device (%s)",
                        port, strerror(error));
         }
+        free(name);
+        free(type);
 
         error = ofproto_port_add(ofproto, netdev, NULL);
         if (error) {