Catalli's threaded switch
[sliver-openvswitch.git] / utilities / ovs-openflowd.c
index ebfc3c3..5d780e1 100644 (file)
 #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 {
     /* Controller configuration. */
     struct ofproto_controller *controllers;
     size_t n_controllers;
+    enum ofproto_fail_mode fail_mode;
 
     /* Datapath. */
     uint64_t datapath_id;       /* Datapath ID. */
@@ -68,15 +69,11 @@ 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. */
 };
@@ -96,8 +93,6 @@ main(int argc, char *argv[])
 
     proctitle_init(argc, argv);
     set_program_name(argv[0]);
-    time_init();
-    vlog_init();
     parse_options(argc, argv, &s);
     signal(SIGPIPE, SIG_IGN);
 
@@ -141,16 +136,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,
@@ -162,26 +147,35 @@ 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_controllers(ofproto, s.controllers, s.n_controllers);
+    ofproto_set_fail_mode(ofproto, s.fail_mode);
 
     daemonize_complete();
 
+#ifdef THREADED
+    /* Data thread started */
+    fprintf(stdout, "THREADED version running!\n");
+    dp_start();
+#endif
+
+    /* The following loop polls on protocol messages 
+     * and on messages related to topology changes */
     while (ofproto_is_alive(ofproto)) {
         error = ofproto_run(ofproto);
         if (error) {
             ovs_fatal(error, "unrecoverable datapath error");
         }
         unixctl_server_run(unixctl);
+#ifndef THREADED
         dp_run();
+#endif
         netdev_run();
 
         ofproto_wait(ofproto);
         unixctl_server_wait(unixctl);
+#ifndef THREADED
         dp_wait();
+#endif
         netdev_wait();
         poll_block();
     }
@@ -214,8 +208,6 @@ 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,
@@ -242,8 +234,6 @@ 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},
@@ -262,27 +252,28 @@ 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;
+    int i;
 
     /* Set defaults that we can figure out before parsing options. */
     controller_opts.target = NULL;
     controller_opts.max_backoff = 8;
     controller_opts.probe_interval = 5;
-    controller_opts.fail = OFPROTO_FAIL_STANDALONE;
     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->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 (;;) {
@@ -331,10 +322,10 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
 
         case OPT_FAIL_MODE:
             if (!strcmp(optarg, "open") || !strcmp(optarg, "standalone")) {
-                controller_opts.fail = OFPROTO_FAIL_STANDALONE;
+                s->fail_mode = OFPROTO_FAIL_STANDALONE;
             } else if (!strcmp(optarg, "closed")
                        || !strcmp(optarg, "secure")) {
-                controller_opts.fail = OFPROTO_FAIL_SECURE;
+                s->fail_mode = OFPROTO_FAIL_SECURE;
             } else {
                 ovs_fatal(0, "--fail argument must be \"standalone\" "
                           "or \"secure\"");
@@ -387,14 +378,6 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
             }
             break;
 
-        case OPT_STP:
-            s->enable_stp = true;
-            break;
-
-        case OPT_NO_STP:
-            s->enable_stp = false;
-            break;
-
         case OPT_OUT_OF_BAND:
             controller_opts.band = OFPROTO_OUT_OF_BAND;
             break;
@@ -408,7 +391,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:
@@ -451,8 +434,8 @@ 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");
     }
 
@@ -471,19 +454,28 @@ parse_options(int argc, char *argv[], struct ofsettings *s)
     /* Local vconns. */
     dp_parse_name(argv[0], &s->dp_name, &s->dp_type);
 
-    /* Controllers. */
-    s->n_controllers = argc > 1 ? argc - 1 : 1;
+    /* Figure out controller names. */
+    if (!controllers.n) {
+        svec_add_nocopy(&controllers,
+                        xasprintf("punix:%s/%s.mgmt", ovs_rundir, s->dp_name));
+    }
+    for (i = 1; i < argc; i++) {
+        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);
     if (argc > 1) {
         size_t i;
 
         for (i = 0; i < s->n_controllers; i++) {
             s->controllers[i] = controller_opts;
-            s->controllers[i].target = argv[i + 1];
+            s->controllers[i].target = controllers.names[i];
         }
-    } else {
-        s->controllers[0] = controller_opts;
-        s->controllers[0].target = "discover";
     }
 
     /* Sanity check. */