X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=utilities%2Fovs-openflowd.c;h=a58a9d219467b7f034523b6fb1196f193125270b;hb=a328a943f173391cd9a9a54e257c8dabcd463402;hp=d2e0336f36aa4ce228527759ec7949b9f1fe265b;hpb=195c8086244e33ec42fd9fc8354eaedfd849bbba;p=sliver-openvswitch.git diff --git a/utilities/ovs-openflowd.c b/utilities/ovs-openflowd.c index d2e0336f3..a58a9d219 100644 --- a/utilities/ovs-openflowd.c +++ b/utilities/ovs-openflowd.c @@ -40,7 +40,6 @@ #include "poll-loop.h" #include "rconn.h" #include "stream-ssl.h" -#include "svec.h" #include "timeval.h" #include "unixctl.h" #include "util.h" @@ -63,7 +62,7 @@ struct ofsettings { uint64_t datapath_id; /* Datapath ID. */ char *dp_name; /* Name of local datapath. */ char *dp_type; /* Type of local datapath. */ - struct svec ports; /* Set of ports to add to datapath (if any). */ + struct sset ports; /* Set of ports to add to datapath (if any). */ /* Description strings. */ const char *mfr_desc; /* Manufacturer. */ @@ -73,13 +72,13 @@ struct ofsettings { const char *dp_desc; /* Datapath description. */ /* Related vconns and network devices. */ - struct svec snoops; /* Listen for controller snooping conns. */ + struct sset snoops; /* Listen for controller snooping conns. */ /* Failure behavior. */ int max_idle; /* Idle time for flows in fail-open mode. */ /* NetFlow. */ - struct svec netflow; /* NetFlow targets. */ + struct sset netflow; /* NetFlow targets. */ }; static unixctl_cb_func ovs_openflowd_exit; @@ -96,6 +95,7 @@ main(int argc, char *argv[]) int error; struct dpif *dpif; struct netflow_options nf_options; + const char *port; bool exiting; proctitle_init(argc, argv); @@ -119,35 +119,33 @@ main(int argc, char *argv[]) error = dpif_create_and_open(s.dp_name, s.dp_type, &dpif); if (error) { - ovs_fatal(error, "could not create datapath"); + VLOG_FATAL("could not create datapath (%s)", strerror(error)); } /* Add ports to the datapath if requested by the user. */ - if (s.ports.n) { - const char *port; - size_t i; + SSET_FOR_EACH (port, &s.ports) { + struct netdev *netdev; - SVEC_FOR_EACH (i, port, &s.ports) { - struct netdev *netdev; - - error = netdev_open_default(port, &netdev); - if (error) { - ovs_fatal(error, "%s: failed to open network device", port); - } - - error = dpif_port_add(dpif, netdev, NULL); - if (error) { - ovs_fatal(error, "failed to add %s as a port", port); - } + error = netdev_open_default(port, &netdev); + if (error) { + VLOG_FATAL("%s: failed to open network device (%s)", + port, strerror(error)); + } - netdev_close(netdev); + error = dpif_port_add(dpif, netdev, NULL); + if (error) { + VLOG_FATAL("failed to add %s as a port (%s)", + port, strerror(error)); } + + netdev_close(netdev); } /* Start OpenFlow processing. */ error = ofproto_create(s.dp_name, s.dp_type, NULL, NULL, &ofproto); if (error) { - ovs_fatal(error, "could not initialize openflow switch"); + VLOG_FATAL("could not initialize openflow switch (%s)", + strerror(error)); } if (s.datapath_id) { ofproto_set_datapath_id(ofproto, s.datapath_id); @@ -156,14 +154,15 @@ main(int argc, char *argv[]) s.serial_desc, s.dp_desc); error = ofproto_set_snoops(ofproto, &s.snoops); if (error) { - ovs_fatal(error, - "failed to configure controller snooping connections"); + VLOG_FATAL("failed to configure controller snooping connections (%s)", + strerror(error)); } memset(&nf_options, 0, sizeof nf_options); nf_options.collectors = s.netflow; error = ofproto_set_netflow(ofproto, &nf_options); if (error) { - ovs_fatal(error, "failed to configure NetFlow collectors"); + VLOG_FATAL("failed to configure NetFlow collectors (%s)", + strerror(error)); } ofproto_set_controllers(ofproto, s.controllers, s.n_controllers); ofproto_set_fail_mode(ofproto, s.fail_mode); @@ -174,7 +173,7 @@ main(int argc, char *argv[]) while (!exiting && (s.run_forever || ofproto_is_alive(ofproto))) { error = ofproto_run(ofproto); if (error) { - ovs_fatal(error, "unrecoverable datapath error"); + VLOG_FATAL("unrecoverable datapath error (%s)", strerror(error)); } unixctl_server_run(unixctl); dp_run(); @@ -206,6 +205,21 @@ ovs_openflowd_exit(struct unixctl_conn *conn, const char *args OVS_UNUSED, /* User interface. */ +/* Breaks 'ports' apart at commas and adds each resulting word to 'ports'. */ +static void +parse_ports(const char *s_, struct sset *ports) +{ + char *s = xstrdup(s_); + char *save_ptr = NULL; + char *token; + + for (token = strtok_r(s, ",", &save_ptr); token != NULL; + token = strtok_r(NULL, ",", &save_ptr)) { + sset_add(ports, token); + } + free(s); +} + static void parse_options(int argc, char *argv[], struct ofsettings *s) { @@ -272,7 +286,8 @@ parse_options(int argc, char *argv[], struct ofsettings *s) }; char *short_options = long_options_to_short_options(long_options); struct ofproto_controller controller_opts; - struct svec controllers; + struct sset controllers; + const char *name; int i; /* Set defaults that we can figure out before parsing options. */ @@ -290,11 +305,11 @@ parse_options(int argc, char *argv[], struct ofsettings *s) s->sw_desc = NULL; s->serial_desc = NULL; s->dp_desc = NULL; - svec_init(&controllers); - svec_init(&s->snoops); + sset_init(&controllers); + sset_init(&s->snoops); s->max_idle = 0; - svec_init(&s->netflow); - svec_init(&s->ports); + sset_init(&s->netflow); + sset_init(&s->ports); for (;;) { int c; @@ -306,8 +321,8 @@ parse_options(int argc, char *argv[], struct ofsettings *s) switch (c) { case OPT_DATAPATH_ID: if (!dpid_from_string(optarg, &s->datapath_id)) { - ovs_fatal(0, "argument to --datapath-id must be " - "exactly 16 hex digits and may not be all-zero"); + VLOG_FATAL("argument to --datapath-id must be exactly 16 hex " + "digits and may not be all-zero"); } break; @@ -338,15 +353,15 @@ parse_options(int argc, char *argv[], struct ofsettings *s) || !strcmp(optarg, "secure")) { s->fail_mode = OFPROTO_FAIL_SECURE; } else { - ovs_fatal(0, "--fail argument must be \"standalone\" " - "or \"secure\""); + VLOG_FATAL("--fail argument must be \"standalone\" " + "or \"secure\""); } break; case OPT_INACTIVITY_PROBE: controller_opts.probe_interval = atoi(optarg); if (controller_opts.probe_interval < 5) { - ovs_fatal(0, "--inactivity-probe argument must be at least 5"); + VLOG_FATAL("--inactivity-probe argument must be at least 5"); } break; @@ -356,8 +371,8 @@ parse_options(int argc, char *argv[], struct ofsettings *s) } else { s->max_idle = atoi(optarg); if (s->max_idle < 1 || s->max_idle > 65535) { - ovs_fatal(0, "--max-idle argument must be between 1 and " - "65535 or the word 'permanent'"); + VLOG_FATAL("--max-idle argument must be between 1 and " + "65535 or the word 'permanent'"); } } break; @@ -365,7 +380,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s) case OPT_MAX_BACKOFF: controller_opts.max_backoff = atoi(optarg); if (controller_opts.max_backoff < 1) { - ovs_fatal(0, "--max-backoff argument must be at least 1"); + VLOG_FATAL("--max-backoff argument must be at least 1"); } else if (controller_opts.max_backoff > 3600) { controller_opts.max_backoff = 3600; } @@ -375,7 +390,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s) if (optarg) { controller_opts.rate_limit = atoi(optarg); if (controller_opts.rate_limit < 1) { - ovs_fatal(0, "--rate-limit argument must be at least 1"); + VLOG_FATAL("--rate-limit argument must be at least 1"); } } else { controller_opts.rate_limit = 1000; @@ -385,7 +400,7 @@ parse_options(int argc, char *argv[], struct ofsettings *s) case OPT_BURST_LIMIT: controller_opts.burst_limit = atoi(optarg); if (controller_opts.burst_limit < 1) { - ovs_fatal(0, "--burst-limit argument must be at least 1"); + VLOG_FATAL("--burst-limit argument must be at least 1"); } break; @@ -398,19 +413,19 @@ parse_options(int argc, char *argv[], struct ofsettings *s) break; case OPT_NETFLOW: - svec_add(&s->netflow, optarg); + sset_add(&s->netflow, optarg); break; case 'l': - svec_add(&controllers, optarg); + sset_add(&controllers, optarg); break; case OPT_SNOOP: - svec_add(&s->snoops, optarg); + sset_add(&s->snoops, optarg); break; case OPT_PORTS: - svec_split(&s->ports, optarg, ","); + parse_ports(optarg, &s->ports); break; case OPT_UNIXCTL: @@ -454,8 +469,8 @@ parse_options(int argc, char *argv[], struct ofsettings *s) argc -= optind; argv += optind; if (argc < 2) { - ovs_fatal(0, "need at least two non-option arguments; " - "use --help for usage"); + VLOG_FATAL("need at least two non-option arguments; " + "use --help for usage"); } /* Rate limiting. */ @@ -469,25 +484,28 @@ parse_options(int argc, char *argv[], struct ofsettings *s) /* 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)); + if (sset_is_empty(&controllers)) { + sset_add_and_free(&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]); + sset_add(&controllers, argv[i]); } } /* Set up controllers. */ - s->n_controllers = controllers.n; + s->n_controllers = sset_count(&controllers); s->controllers = xmalloc(s->n_controllers * sizeof *s->controllers); - for (i = 0; i < s->n_controllers; i++) { + i = 0; + SSET_FOR_EACH (name, &controllers) { s->controllers[i] = controller_opts; - s->controllers[i].target = controllers.names[i]; + s->controllers[i].target = xstrdup(name); + i++; } + sset_destroy(&controllers); } static void