X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=utilities%2Fovs-openflowd.c;h=486eae288e9e56ab3cd2d9823d18cb9d546b8dd4;hb=25608d9720000ba2f4b4a881ca2a8cf519404f96;hp=70430c0356f86d52b112f983f1e8369fa646d634;hpb=79c9f2ee7883b52860c76c3730725f5731402874;p=openvswitch diff --git a/utilities/ovs-openflowd.c b/utilities/ovs-openflowd.c index 70430c03..486eae28 100644 --- a/utilities/ovs-openflowd.c +++ b/utilities/ovs-openflowd.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2008, 2009, 2010 Nicira Networks. + * Copyright (c) 2008, 2009, 2010, 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. @@ -29,6 +29,7 @@ #include "daemon.h" #include "dirs.h" #include "dpif.h" +#include "dummy.h" #include "leak-checker.h" #include "list.h" #include "netdev.h" @@ -44,14 +45,19 @@ #include "unixctl.h" #include "util.h" #include "vconn.h" - #include "vlog.h" -#define THIS_MODULE VLM_openflowd + +VLOG_DEFINE_THIS_MODULE(openflowd); /* Settings that may be configured by the user. */ struct ofsettings { + const char *unixctl_path; /* File name for unixctl socket. */ + /* Controller configuration. */ - struct ofproto_controller controller; + struct ofproto_controller *controllers; + size_t n_controllers; + enum ofproto_fail_mode fail_mode; + bool run_forever; /* Continue running even with no controller? */ /* Datapath. */ uint64_t datapath_id; /* Datapath ID. */ @@ -67,19 +73,17 @@ struct ofsettings { const char *dp_desc; /* Datapath description. */ /* Related vconns and network devices. */ - struct svec listeners; /* Listen for management connections. */ struct svec snoops; /* Listen for controller snooping conns. */ /* Failure behavior. */ int max_idle; /* Idle time for flows in fail-open mode. */ - /* Spanning tree protocol. */ - bool enable_stp; - /* NetFlow. */ struct svec netflow; /* NetFlow targets. */ }; +static unixctl_cb_func ovs_openflowd_exit; + static void parse_options(int argc, char *argv[], struct ofsettings *); static void usage(void) NO_RETURN; @@ -92,11 +96,10 @@ main(int argc, char *argv[]) int error; struct dpif *dpif; struct netflow_options nf_options; + bool exiting; proctitle_init(argc, argv); set_program_name(argv[0]); - time_init(); - vlog_init(); parse_options(argc, argv, &s); signal(SIGPIPE, SIG_IGN); @@ -104,11 +107,13 @@ main(int argc, char *argv[]) daemonize_start(); /* Start listening for ovs-appctl requests. */ - error = unixctl_server_create(NULL, &unixctl); + error = unixctl_server_create(s.unixctl_path, &unixctl); if (error) { exit(EXIT_FAILURE); } + unixctl_command_register("exit", ovs_openflowd_exit, &exiting); + VLOG_INFO("Open vSwitch version %s", VERSION BUILDNR); VLOG_INFO("OpenFlow protocol version 0x%02x", OFP_VERSION); @@ -121,18 +126,21 @@ main(int argc, char *argv[]) if (s.ports.n) { const char *port; size_t i; - struct netdev *netdev; SVEC_FOR_EACH (i, port, &s.ports) { + struct netdev *netdev; + error = netdev_open_default(port, &netdev); if (error) { - ovs_fatal(error, "failed to open %s as a device", port); + ovs_fatal(error, "%s: failed to open network device", port); } - error = dpif_port_add(dpif, port, 0, NULL); + error = dpif_port_add(dpif, netdev, NULL); if (error) { ovs_fatal(error, "failed to add %s as a port", port); } + + netdev_close(netdev); } } @@ -146,16 +154,6 @@ main(int argc, char *argv[]) } ofproto_set_desc(ofproto, s.mfr_desc, s.hw_desc, s.sw_desc, s.serial_desc, s.dp_desc); - if (!s.listeners.n) { - svec_add_nocopy(&s.listeners, xasprintf("punix:%s/%s.mgmt", - ovs_rundir, s.dp_name)); - } else if (s.listeners.n == 1 && !strcmp(s.listeners.names[0], "none")) { - svec_clear(&s.listeners); - } - error = ofproto_set_listeners(ofproto, &s.listeners); - if (error) { - ovs_fatal(error, "failed to configure management connections"); - } error = ofproto_set_snoops(ofproto, &s.snoops); if (error) { ovs_fatal(error, @@ -167,15 +165,13 @@ main(int argc, char *argv[]) if (error) { ovs_fatal(error, "failed to configure NetFlow collectors"); } - error = ofproto_set_stp(ofproto, s.enable_stp); - if (error) { - ovs_fatal(error, "failed to configure STP"); - } - ofproto_set_controller(ofproto, &s.controller); + ofproto_set_controllers(ofproto, s.controllers, s.n_controllers); + ofproto_set_fail_mode(ofproto, s.fail_mode); daemonize_complete(); - while (ofproto_is_alive(ofproto)) { + exiting = false; + while (!exiting && (s.run_forever || ofproto_is_alive(ofproto))) { error = ofproto_run(ofproto); if (error) { ovs_fatal(error, "unrecoverable datapath error"); @@ -188,6 +184,9 @@ main(int argc, char *argv[]) unixctl_server_wait(unixctl); dp_wait(); netdev_wait(); + if (exiting) { + poll_immediate_wake(); + } poll_block(); } @@ -195,6 +194,15 @@ main(int argc, char *argv[]) return 0; } + +static void +ovs_openflowd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED, + void *exiting_) +{ + bool *exiting = exiting_; + *exiting = true; + unixctl_command_reply(conn, 200, NULL); +} /* User interface. */ @@ -219,14 +227,15 @@ parse_options(int argc, char *argv[], struct ofsettings *s) OPT_RATE_LIMIT, OPT_BURST_LIMIT, OPT_BOOTSTRAP_CA_CERT, - OPT_STP, - OPT_NO_STP, OPT_OUT_OF_BAND, OPT_IN_BAND, OPT_NETFLOW, OPT_PORTS, + OPT_UNIXCTL, + OPT_ENABLE_DUMMY, VLOG_OPTION_ENUMS, - LEAK_CHECKER_OPTION_ENUMS + LEAK_CHECKER_OPTION_ENUMS, + DAEMON_OPTION_ENUMS }; static struct option long_options[] = { {"datapath-id", required_argument, 0, OPT_DATAPATH_ID}, @@ -247,12 +256,12 @@ parse_options(int argc, char *argv[], struct ofsettings *s) {"snoop", required_argument, 0, OPT_SNOOP}, {"rate-limit", optional_argument, 0, OPT_RATE_LIMIT}, {"burst-limit", required_argument, 0, OPT_BURST_LIMIT}, - {"stp", no_argument, 0, OPT_STP}, - {"no-stp", no_argument, 0, OPT_NO_STP}, {"out-of-band", no_argument, 0, OPT_OUT_OF_BAND}, {"in-band", no_argument, 0, OPT_IN_BAND}, {"netflow", required_argument, 0, OPT_NETFLOW}, {"ports", required_argument, 0, OPT_PORTS}, + {"unixctl", required_argument, 0, OPT_UNIXCTL}, + {"enable-dummy", no_argument, 0, OPT_ENABLE_DUMMY}, {"verbose", optional_argument, 0, 'v'}, {"help", no_argument, 0, 'h'}, {"version", no_argument, 0, 'V'}, @@ -266,26 +275,30 @@ parse_options(int argc, char *argv[], struct ofsettings *s) {0, 0, 0, 0}, }; char *short_options = long_options_to_short_options(long_options); + struct ofproto_controller controller_opts; + struct svec controllers; + int i; /* Set defaults that we can figure out before parsing options. */ - s->controller.max_backoff = 8; - s->controller.probe_interval = 5; - s->controller.fail = OFPROTO_FAIL_STANDALONE; - s->controller.band = OFPROTO_IN_BAND; - s->controller.accept_re = NULL; - s->controller.update_resolv_conf = true; - s->controller.rate_limit = 0; - s->controller.burst_limit = 0; + controller_opts.target = NULL; + controller_opts.max_backoff = 8; + controller_opts.probe_interval = 5; + controller_opts.band = OFPROTO_IN_BAND; + controller_opts.accept_re = NULL; + controller_opts.update_resolv_conf = true; + controller_opts.rate_limit = 0; + controller_opts.burst_limit = 0; + s->unixctl_path = NULL; + s->fail_mode = OFPROTO_FAIL_STANDALONE; s->datapath_id = 0; s->mfr_desc = NULL; s->hw_desc = NULL; s->sw_desc = NULL; s->serial_desc = NULL; s->dp_desc = NULL; - svec_init(&s->listeners); + svec_init(&controllers); svec_init(&s->snoops); s->max_idle = 0; - s->enable_stp = false; svec_init(&s->netflow); svec_init(&s->ports); for (;;) { @@ -325,26 +338,28 @@ parse_options(int argc, char *argv[], struct ofsettings *s) break; case OPT_ACCEPT_VCONN: - s->controller.accept_re = optarg; + controller_opts.accept_re = optarg; break; case OPT_NO_RESOLV_CONF: - s->controller.update_resolv_conf = false; + controller_opts.update_resolv_conf = false; break; case OPT_FAIL_MODE: - if (!strcmp(optarg, "open")) { - s->controller.fail = OFPROTO_FAIL_STANDALONE; - } else if (!strcmp(optarg, "closed")) { - s->controller.fail = OFPROTO_FAIL_SECURE; + if (!strcmp(optarg, "open") || !strcmp(optarg, "standalone")) { + s->fail_mode = OFPROTO_FAIL_STANDALONE; + } else if (!strcmp(optarg, "closed") + || !strcmp(optarg, "secure")) { + s->fail_mode = OFPROTO_FAIL_SECURE; } else { - ovs_fatal(0, "--fail argument must be \"open\" or \"closed\""); + ovs_fatal(0, "--fail argument must be \"standalone\" " + "or \"secure\""); } break; case OPT_INACTIVITY_PROBE: - s->controller.probe_interval = atoi(optarg); - if (s->controller.probe_interval < 5) { + controller_opts.probe_interval = atoi(optarg); + if (controller_opts.probe_interval < 5) { ovs_fatal(0, "--inactivity-probe argument must be at least 5"); } break; @@ -362,46 +377,38 @@ parse_options(int argc, char *argv[], struct ofsettings *s) break; case OPT_MAX_BACKOFF: - s->controller.max_backoff = atoi(optarg); - if (s->controller.max_backoff < 1) { + controller_opts.max_backoff = atoi(optarg); + if (controller_opts.max_backoff < 1) { ovs_fatal(0, "--max-backoff argument must be at least 1"); - } else if (s->controller.max_backoff > 3600) { - s->controller.max_backoff = 3600; + } else if (controller_opts.max_backoff > 3600) { + controller_opts.max_backoff = 3600; } break; case OPT_RATE_LIMIT: if (optarg) { - s->controller.rate_limit = atoi(optarg); - if (s->controller.rate_limit < 1) { + controller_opts.rate_limit = atoi(optarg); + if (controller_opts.rate_limit < 1) { ovs_fatal(0, "--rate-limit argument must be at least 1"); } } else { - s->controller.rate_limit = 1000; + controller_opts.rate_limit = 1000; } break; case OPT_BURST_LIMIT: - s->controller.burst_limit = atoi(optarg); - if (s->controller.burst_limit < 1) { + controller_opts.burst_limit = atoi(optarg); + if (controller_opts.burst_limit < 1) { ovs_fatal(0, "--burst-limit argument must be at least 1"); } break; - case OPT_STP: - s->enable_stp = true; - break; - - case OPT_NO_STP: - s->enable_stp = false; - break; - case OPT_OUT_OF_BAND: - s->controller.band = OFPROTO_OUT_OF_BAND; + controller_opts.band = OFPROTO_OUT_OF_BAND; break; case OPT_IN_BAND: - s->controller.band = OFPROTO_IN_BAND; + controller_opts.band = OFPROTO_IN_BAND; break; case OPT_NETFLOW: @@ -409,7 +416,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s) break; case 'l': - svec_add(&s->listeners, optarg); + svec_add(&controllers, optarg); break; case OPT_SNOOP: @@ -420,6 +427,14 @@ parse_options(int argc, char *argv[], struct ofsettings *s) svec_split(&s->ports, optarg, ","); break; + case OPT_UNIXCTL: + s->unixctl_path = optarg; + break; + + case OPT_ENABLE_DUMMY: + dummy_enable(); + break; + case 'h': usage(); @@ -452,30 +467,59 @@ parse_options(int argc, char *argv[], struct ofsettings *s) argc -= optind; argv += optind; - if (argc < 1 || argc > 2) { - ovs_fatal(0, "need one or two non-option arguments; " + if (argc < 1) { + ovs_fatal(0, "need at least one non-option arguments; " "use --help for usage"); } - /* Local and remote vconns. */ - dp_parse_name(argv[0], &s->dp_name, &s->dp_type); - - s->controller.target = argc > 1 ? argv[1] : "discover"; - if (!strcmp(s->controller.target, "discover") - && s->controller.band == OFPROTO_OUT_OF_BAND) { - ovs_fatal(0, "Cannot perform discovery with out-of-band control"); - } - /* Set accept_controller_regex. */ - if (!s->controller.accept_re) { - s->controller.accept_re + if (!controller_opts.accept_re) { + controller_opts.accept_re = stream_ssl_is_configured() ? "^ssl:.*" : "^tcp:.*"; } /* Rate limiting. */ - if (s->controller.rate_limit && s->controller.rate_limit < 100) { + if (controller_opts.rate_limit && controller_opts.rate_limit < 100) { VLOG_WARN("Rate limit set to unusually low value %d", - s->controller.rate_limit); + controller_opts.rate_limit); + } + + /* Local vconns. */ + dp_parse_name(argv[0], &s->dp_name, &s->dp_type); + + /* Figure out controller names. */ + s->run_forever = false; + if (!controllers.n) { + svec_add_nocopy(&controllers, xasprintf("punix:%s/%s.mgmt", + ovs_rundir(), s->dp_name)); + } + for (i = 1; i < argc; i++) { + if (!strcmp(argv[i], "none")) { + s->run_forever = true; + } else { + svec_add(&controllers, argv[i]); + } + } + if (argc < 2) { + svec_add(&controllers, "discover"); + } + + /* Set up controllers. */ + s->n_controllers = controllers.n; + s->controllers = xmalloc(s->n_controllers * sizeof *s->controllers); + for (i = 0; i < s->n_controllers; i++) { + s->controllers[i] = controller_opts; + s->controllers[i].target = controllers.names[i]; + } + + /* Sanity check. */ + if (controller_opts.band == OFPROTO_OUT_OF_BAND) { + for (i = 0; i < s->n_controllers; i++) { + if (!strcmp(s->controllers[i].target, "discover")) { + ovs_fatal(0, "Cannot perform discovery with out-of-band " + "control"); + } + } } } @@ -483,10 +527,11 @@ static void usage(void) { printf("%s: an OpenFlow switch implementation.\n" - "usage: %s [OPTIONS] DATAPATH [CONTROLLER]\n" - "DATAPATH is a local datapath (e.g. \"dp0\").\n" - "CONTROLLER is an active OpenFlow connection method; if it is\n" - "omitted, then ovs-openflowd performs controller discovery.\n", + "usage: %s [OPTIONS] [TYPE@]DATAPATH [CONTROLLER...]\n" + "where DATAPATH is a local datapath (e.g. \"dp0\")\n" + "optionally with an explicit TYPE (default: \"system\").\n" + "Each CONTROLLER is an active OpenFlow connection method. If\n" + "none is given, ovs-openflowd performs controller discovery.\n", program_name, program_name); vconn_usage(true, true, true); printf("\nOpenFlow options:\n" @@ -520,6 +565,7 @@ usage(void) daemon_usage(); vlog_usage(); printf("\nOther options:\n" + " --unixctl=SOCKET override default control socket name\n" " -h, --help display this help message\n" " -V, --version display version information\n"); leak_checker_usage();