static void failover_periodic_cb(void *context_) { struct failover_context *context = context_; char *curr_peer = NULL; char *prev_peer = NULL; if (rconn_is_connected(context->remote_rconn)) return; if (!is_timed_out(context->peers[context->index], context->settings->max_backoff)) { return; } rconn_disconnect(context->remote_rconn); prev_peer = (char *)context->settings->controller_names[context->index]; context->index = (context->index + 1) % context->settings->num_controllers; curr_peer = (char *)context->settings->controller_names[context->index]; rconn_connect(context->remote_rconn, context->settings->controller_names[context->index]); context->peers[context->index]->epoch = time_now(); VLOG_INFO("Switching over to %s, from %s", curr_peer, prev_peer); }
/* Creates a new rconn, connects it (reliably) to 'name', and returns it. */ struct rconn * rconn_new(const char *name, int inactivity_probe_interval, int max_backoff) { struct rconn *rc = rconn_create(inactivity_probe_interval, max_backoff); rconn_connect(rc, name); return rc; }
int main(int argc, char *argv[]) { struct rconn *rconn; int error; set_program_name(argv[0]); register_fault_handlers(); time_init(); vlog_init(); parse_options(argc, argv); signal(SIGPIPE, SIG_IGN); if (argc - optind != 1) { ofp_fatal(0, "missing controller argument; use --help for usage"); } rconn = rconn_create(60, max_backoff); error = rconn_connect(rconn, argv[optind]); if (error == EAFNOSUPPORT) { ofp_fatal(0, "no support for %s vconn", argv[optind]); } error = dp_new(&dp, dpid, rconn); if (listen_pvconn_name) { struct pvconn *listen_pvconn; int retval; retval = pvconn_open(listen_pvconn_name, &listen_pvconn); if (retval && retval != EAGAIN) { ofp_fatal(retval, "opening %s", listen_pvconn_name); } dp_add_listen_pvconn(dp, listen_pvconn); } if (error) { ofp_fatal(error, "could not create datapath"); } if (port_list) { add_ports(dp, port_list); } die_if_already_running(); daemonize(); error = vlog_server_listen(NULL, NULL); if (error) { ofp_fatal(error, "could not listen for vlog connections"); } for (;;) { dp_run(dp); dp_wait(dp); poll_block(); } return 0; }