From a75531e53e03d9fe9915f8041759601c07e47914 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Thu, 18 Aug 2011 11:20:12 -0700 Subject: [PATCH] test-openflowd: Allow specifying port type on --ports option. 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 | 19 +++++++++++++++++++ lib/netdev.h | 2 ++ tests/test-openflowd.c | 6 +++++- 3 files changed, 26 insertions(+), 1 deletion(-) diff --git a/lib/netdev.c b/lib/netdev.c index 9fba077b6..0074de025 100644 --- a/lib/netdev.c +++ b/lib/netdev.c @@ -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 diff --git a/lib/netdev.h b/lib/netdev.h index 2644708b3..11b6925d3 100644 --- a/lib/netdev.h +++ b/lib/netdev.h @@ -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 *); diff --git a/tests/test-openflowd.c b/tests/test-openflowd.c index 016e1cbed..3cc3a751a 100644 --- a/tests/test-openflowd.c +++ b/tests/test-openflowd.c @@ -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) { -- 2.43.0