Plain "--enable-dummy" just creates new dummy dpif and netdev classes.
This commit makes "--enable-dummy=override" go a step farther and actually
delete and replace all the existing dpif and netdev classes by copies of
the dummy class.
This is useful for testing in an environment where changing the classes in
Bridge or Interface records is challenging.
Requested-by: Andrew Lambeth <wal@nicira.com>
Tested-by: Andrew Lambeth <wal@nicira.com>
Signed-off-by: Ben Pfaff <blp@nicira.com>
#include "poll-loop.h"
#include "random.h"
#include "shash.h"
+#include "sset.h"
#include "timeval.h"
#include "util.h"
#include "vlog.h"
int port_no; /* Index into dp_netdev's 'ports'. */
struct list node; /* Element in dp_netdev's 'port_list'. */
struct netdev *netdev;
- bool internal; /* Internal port? */
+ char *type; /* Port type as requested by user. */
};
/* A flow in dp_netdev's 'flow_table'. */
const struct nlattr *actions,
size_t actions_len);
-static struct dpif_class dpif_dummy_class;
-
static struct dpif_netdev *
dpif_netdev_cast(const struct dpif *dpif)
{
{
struct dp_netdev_port *port;
struct netdev *netdev;
- bool internal;
+ const char *open_type;
int mtu;
int error;
/* XXX reject devices already in some dp_netdev. */
- if (type[0] == '\0' || !strcmp(type, "system") || !strcmp(type, "dummy")) {
- internal = false;
- } else if (!strcmp(type, "internal")) {
- internal = true;
- } else {
- VLOG_WARN("%s: unsupported port type %s", devname, type);
- return EINVAL;
- }
/* Open and validate network device. */
- if (dp->class == &dpif_dummy_class) {
- type = "dummy";
- } else if (internal) {
- type = "tap";
- }
-
- error = netdev_open(devname, type, &netdev);
+ open_type = (strcmp(type, "internal") ? type
+ : dp->class != &dpif_netdev_class ? "dummy"
+ : "tap");
+ error = netdev_open(devname, open_type, &netdev);
if (error) {
return error;
}
port = xmalloc(sizeof *port);
port->port_no = port_no;
port->netdev = netdev;
- port->internal = internal;
+ port->type = xstrdup(type);
error = netdev_get_mtu(netdev, &mtu);
if (!error) {
struct dp_netdev *dp = get_dp_netdev(dpif);
int port_no;
- if (dpif->dpif_class == &dpif_dummy_class) {
+ if (dpif->dpif_class != &dpif_netdev_class) {
/* If the port name contains a number, try to assign that port number.
* This can make writing unit tests easier because port numbers are
* predictable. */
name = xstrdup(netdev_get_name(port->netdev));
netdev_close(port->netdev);
+ free(port->type);
free(name);
free(port);
struct dpif_port *dpif_port)
{
dpif_port->name = xstrdup(netdev_get_name(port->netdev));
- dpif_port->type = xstrdup(port->internal ? "internal"
- : netdev_get_type(port->netdev));
+ dpif_port->type = xstrdup(port->type);
dpif_port->port_no = port->port_no;
}
free(state->name);
state->name = xstrdup(netdev_get_name(port->netdev));
dpif_port->name = state->name;
- dpif_port->type = (char *) (port->internal ? "internal"
- : netdev_get_type(port->netdev));
+ dpif_port->type = port->type;
dpif_port->port_no = port->port_no;
state->port_no = port_no + 1;
return 0;
dpif_netdev_recv_purge,
};
+static void
+dpif_dummy_register__(const char *type)
+{
+ struct dpif_class *class;
+
+ class = xmalloc(sizeof *class);
+ *class = dpif_netdev_class;
+ class->type = xstrdup(type);
+ dp_register_provider(class);
+}
+
void
-dpif_dummy_register(void)
+dpif_dummy_register(bool override)
{
- if (!dpif_dummy_class.type) {
- dpif_dummy_class = dpif_netdev_class;
- dpif_dummy_class.type = "dummy";
- dp_register_provider(&dpif_dummy_class);
+ if (override) {
+ struct sset types;
+ const char *type;
+
+ sset_init(&types);
+ dp_enumerate_types(&types);
+ SSET_FOR_EACH (type, &types) {
+ if (!dp_unregister_provider(type)) {
+ dpif_dummy_register__(type);
+ }
+ }
+ sset_destroy(&types);
}
+
+ dpif_dummy_register__("dummy");
}
/*
- * Copyright (c) 2010, 2011 Nicira Networks.
+ * Copyright (c) 2010, 2011, 2012 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* testing. A client program might call this function if it is designed
* specifically for testing or the user enables it on the command line.
*
+ * If 'override' is false, then "dummy" dpif and netdev classes will be
+ * created. If 'override' is true, then in addition all existing dpif and
+ * netdev classes will be deleted and replaced by dummy classes.
+ *
* There is no strong reason why dummy devices shouldn't always be enabled. */
void
-dummy_enable(void)
+dummy_enable(bool override)
{
- netdev_dummy_register();
- dpif_dummy_register();
+ netdev_dummy_register(override);
+ dpif_dummy_register(override);
timeval_dummy_register();
}
+
/*
- * Copyright (c) 2010, 2011 Nicira Networks.
+ * Copyright (c) 2010, 2011, 2012 Nicira Networks.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
#ifndef DUMMY_H
#define DUMMY_H 1
+#include <stdbool.h>
+
/* For client programs to call directly to enable dummy support. */
-void dummy_enable(void);
+void dummy_enable(bool override);
/* Implementation details. */
-void dpif_dummy_register(void);
-void netdev_dummy_register(void);
+void dpif_dummy_register(bool override);
+void netdev_dummy_register(bool override);
void timeval_dummy_register(void);
#endif /* dummy.h */
#include "packets.h"
#include "poll-loop.h"
#include "shash.h"
+#include "sset.h"
#include "unixctl.h"
#include "vlog.h"
}
void
-netdev_dummy_register(void)
+netdev_dummy_register(bool override)
{
- netdev_register_provider(&dummy_class);
unixctl_command_register("netdev-dummy/receive", "NAME PACKET|FLOW...",
2, INT_MAX, netdev_dummy_receive, NULL);
+
+ if (override) {
+ struct sset types;
+ const char *type;
+
+ sset_init(&types);
+ netdev_enumerate_types(&types);
+ SSET_FOR_EACH (type, &types) {
+ if (!netdev_unregister_provider(type)) {
+ struct netdev_class *class;
+
+ class = xmalloc(sizeof *class);
+ *class = dummy_class;
+ class->type = xstrdup(type);
+ netdev_register_provider(class);
+ }
+ }
+ sset_destroy(&types);
+ }
+ netdev_register_provider(&dummy_class);
}
-/* Copyright (c) 2008, 2009, 2010, 2011 Nicira Networks
+/* Copyright (c) 2008, 2009, 2010, 2011, 2012 Nicira Networks
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
STREAM_SSL_LONG_OPTIONS,
{"peer-ca-cert", required_argument, NULL, OPT_PEER_CA_CERT},
{"bootstrap-ca-cert", required_argument, NULL, OPT_BOOTSTRAP_CA_CERT},
- {"enable-dummy", no_argument, NULL, OPT_ENABLE_DUMMY},
+ {"enable-dummy", optional_argument, NULL, OPT_ENABLE_DUMMY},
{"disable-system", no_argument, NULL, OPT_DISABLE_SYSTEM},
{NULL, 0, NULL, 0},
};
break;
case OPT_ENABLE_DUMMY:
- dummy_enable();
+ dummy_enable(optarg && !strcmp(optarg, "override"));
break;
case OPT_DISABLE_SYSTEM: