Skip to content

Commit

Permalink
dummy: Introduce new --enable-dummy=system option.
Browse files Browse the repository at this point in the history
Until now there have been two variants for --enable-dummy:

    * --enable-dummy: This adds support for "dummy" dpif and netdev.

    * --enable-dummy=override: In addition, this replaces *every* existing
      dpif and netdev by the dummy type.

The latter is useful for testing but it defeats the possibility of using
the userspace native tunneling implementation (because all the tunnel
netdevs get replaced by dummy netdevs).  Thus, this commit adds a third
variant:

    * --enable-dummy=system: This replaces the "system" dpif and netdev
      by dummies but leaves the others untouched.

Signed-off-by: Ben Pfaff <[email protected]>
Acked-by: Alex Wang <[email protected]>
  • Loading branch information
blp committed Jun 16, 2015
1 parent 7a82d30 commit 8420c7a
Show file tree
Hide file tree
Showing 5 changed files with 75 additions and 38 deletions.
18 changes: 13 additions & 5 deletions lib/dpif-netdev.c
Original file line number Diff line number Diff line change
Expand Up @@ -3688,21 +3688,29 @@ dpif_dummy_register__(const char *type)
dp_register_provider(class);
}

static void
dpif_dummy_override(const char *type)
{
if (!dp_unregister_provider(type)) {
dpif_dummy_register__(type);
}
}

void
dpif_dummy_register(bool override)
dpif_dummy_register(enum dummy_level level)
{
if (override) {
if (level == DUMMY_OVERRIDE_ALL) {
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);
}
dpif_dummy_override(type);
}
sset_destroy(&types);
} else if (level == DUMMY_OVERRIDE_SYSTEM) {
dpif_dummy_override("system");
}

dpif_dummy_register__("dummy");
Expand Down
28 changes: 20 additions & 8 deletions lib/dummy.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2010, 2011, 2012, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -15,23 +15,35 @@
*/

#include <config.h>

#include "dummy.h"
#include <string.h>
#include "util.h"

/* Enables support for "dummy" network devices and dpifs, which are useful for
* 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.
* 'arg' is parsed to determine the override level (see the definition of enum
* dummy_level).
*
* There is no strong reason why dummy devices shouldn't always be enabled. */
void
dummy_enable(bool override)
dummy_enable(const char *arg)
{
netdev_dummy_register(override);
dpif_dummy_register(override);
enum dummy_level level;

if (!arg || !arg[0]) {
level = DUMMY_OVERRIDE_NONE;
} else if (!strcmp(arg, "system")) {
level = DUMMY_OVERRIDE_SYSTEM;
} else if (!strcmp(arg, "override")) {
level = DUMMY_OVERRIDE_ALL;
} else {
ovs_fatal(0, "%s: unknown dummy level", arg);
}

netdev_dummy_register(level);
dpif_dummy_register(level);
timeval_dummy_register();
vlandev_dummy_enable();
}
Expand Down
19 changes: 15 additions & 4 deletions lib/dummy.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright (c) 2010, 2011, 2012, 2013 Nicira, Inc.
* Copyright (c) 2010, 2011, 2012, 2013, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -19,12 +19,23 @@

#include <stdbool.h>

/* Degree of dummy support.
*
* Beyond enabling support for dummies, it can be useful to replace some kinds
* of bridges and netdevs, or all kinds, by dummies. This enum expresses the
* degree to which this should happen. */
enum dummy_level {
DUMMY_OVERRIDE_NONE, /* Support dummy but don't force its use. */
DUMMY_OVERRIDE_SYSTEM, /* Replace "system" by dummy. */
DUMMY_OVERRIDE_ALL, /* Replace all types by dummy. */
};

/* For client programs to call directly to enable dummy support. */
void dummy_enable(bool override);
void dummy_enable(const char *arg);

/* Implementation details. */
void dpif_dummy_register(bool override);
void netdev_dummy_register(bool override);
void dpif_dummy_register(enum dummy_level);
void netdev_dummy_register(enum dummy_level);
void timeval_dummy_register(void);
void vlandev_dummy_enable(void);

Expand Down
44 changes: 25 additions & 19 deletions lib/netdev-dummy.c
Original file line number Diff line number Diff line change
Expand Up @@ -1426,8 +1426,27 @@ netdev_dummy_ip4addr(struct unixctl_conn *conn, int argc OVS_UNUSED,

}

static void
netdev_dummy_override(const char *type)
{
if (!netdev_unregister_provider(type)) {
struct netdev_class *class;
int error;

class = xmemdup(&dummy_class, sizeof dummy_class);
class->type = xstrdup(type);
error = netdev_register_provider(class);
if (error) {
VLOG_ERR("%s: failed to register netdev provider (%s)",
type, ovs_strerror(error));
free(CONST_CAST(char *, class->type));
free(class);
}
}
}

void
netdev_dummy_register(bool override)
netdev_dummy_register(enum dummy_level level)
{
unixctl_command_register("netdev-dummy/receive", "name packet|flow...",
2, INT_MAX, netdev_dummy_receive, NULL);
Expand All @@ -1441,33 +1460,20 @@ netdev_dummy_register(bool override)
"[netdev] ipaddr/mask-prefix-len", 2, 2,
netdev_dummy_ip4addr, NULL);


if (override) {
if (level == DUMMY_OVERRIDE_ALL) {
struct sset types;
const char *type;

sset_init(&types);
netdev_enumerate_types(&types);
SSET_FOR_EACH (type, &types) {
if (!strcmp(type, "patch")) {
continue;
}
if (!netdev_unregister_provider(type)) {
struct netdev_class *class;
int error;

class = xmemdup(&dummy_class, sizeof dummy_class);
class->type = xstrdup(type);
error = netdev_register_provider(class);
if (error) {
VLOG_ERR("%s: failed to register netdev provider (%s)",
type, ovs_strerror(error));
free(CONST_CAST(char *, class->type));
free(class);
}
if (strcmp(type, "patch")) {
netdev_dummy_override(type);
}
}
sset_destroy(&types);
} else if (level == DUMMY_OVERRIDE_SYSTEM) {
netdev_dummy_override("system");
}
netdev_register_provider(&dummy_class);

Expand Down
4 changes: 2 additions & 2 deletions vswitchd/ovs-vswitchd.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014 Nicira, Inc.
/* Copyright (c) 2008, 2009, 2010, 2011, 2012, 2013, 2014, 2015 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -204,7 +204,7 @@ parse_options(int argc, char *argv[], char **unixctl_pathp)
break;

case OPT_ENABLE_DUMMY:
dummy_enable(optarg && !strcmp(optarg, "override"));
dummy_enable(optarg);
break;

case OPT_DISABLE_SYSTEM:
Expand Down

0 comments on commit 8420c7a

Please sign in to comment.