/* -f, --fail: Behavior when the connection to the controller fails. */
static enum fail_mode fail_mode = FAIL_OPEN;
-/* -d, --fail-open-delay: Number of seconds after which to fail open, when
- * fail_mode is FAIL_OPEN. */
-static int fail_open_delay = 30;
+/* --inactivity-probe: Number of seconds without receiving a message from the
+ controller before sending an inactivity probe. */
+static int probe_interval = 15;
/* --max-idle: Idle time to assign to flows created by learning switch when in
* fail-open mode. */
static void relay_destroy(struct relay *);
static bool local_hook(struct relay *r);
+static bool failing_open(struct relay *r);
static bool fail_open_hook(struct relay *r);
int
{
struct vconn *listen_vconn;
struct netdev *of_device;
+ struct relay *controller_relay;
const char *nl_name;
char of_name[16];
int retval;
daemonize();
- relay_create(rconn_new(argv[optind], 1), rconn_new(argv[optind + 1], 1),
- false);
+ controller_relay = relay_create(rconn_new(argv[optind], 1, 0),
+ rconn_new(argv[optind + 1], 1,
+ probe_interval),
+ false);
for (;;) {
struct relay *r, *n;
new_management_connection(nl_name, new_remote);
}
}
+ failing_open(controller_relay);
/* Wait for something to happen. */
LIST_FOR_EACH (r, struct relay, node, &relays) {
return true;
}
+/* Causess 'r' to enter or leave fail-open mode, if appropriate. Returns true
+ * if 'r' is in fail-open fail, false otherwise. */
static bool
-fail_open_hook(struct relay *r)
+failing_open(struct relay *r)
{
- struct buffer *msg = r->halves[HALF_LOCAL].rxbuf;
struct rconn *local = r->halves[HALF_LOCAL].rconn;
struct rconn *remote = r->halves[HALF_REMOTE].rconn;
int disconnected_duration;
}
disconnected_duration = rconn_disconnected_duration(remote);
- if (disconnected_duration < fail_open_delay) {
+ if (disconnected_duration < probe_interval * 3) {
/* It's not time to fail open yet. */
if (r->lswitch && rconn_is_connected(remote)) {
/* We're connected, so drop the learning switch. */
"failing open", disconnected_duration);
r->lswitch = lswitch_create(local, true, max_idle);
}
-
- /* Do switching. */
- lswitch_process_packet(r->lswitch, local, msg);
- rconn_run(local);
return true;
}
+static bool
+fail_open_hook(struct relay *r)
+{
+ if (!failing_open(r)) {
+ return false;
+ } else {
+ struct buffer *msg = r->halves[HALF_LOCAL].rxbuf;
+ struct rconn *local = r->halves[HALF_LOCAL].rconn;
+ lswitch_process_packet(r->lswitch, local, msg);
+ rconn_run(local);
+ return true;
+ }
+}
+
static void
parse_options(int argc, char *argv[])
{
- enum { OPT_MAX_IDLE = UCHAR_MAX + 1 };
+ enum { OPT_INACTIVITY_PROBE = UCHAR_MAX + 1, OPT_MAX_IDLE };
static struct option long_options[] = {
{"fail", required_argument, 0, 'f'},
- {"fail-open-delay", required_argument, 0, 'd'},
+ {"inactivity-probe", required_argument, 0, OPT_INACTIVITY_PROBE},
{"max-idle", required_argument, 0, OPT_MAX_IDLE},
{"listen", required_argument, 0, 'l'},
{"detach", no_argument, 0, 'D'},
}
break;
- case 'd':
- fail_open_delay = atoi(optarg);
- if (fail_open_delay < 1) {
- fatal(0,
- "-d or --fail-open-delay argument must be at least 1");
+ case OPT_INACTIVITY_PROBE:
+ probe_interval = atoi(optarg);
+ if (probe_interval < 5) {
+ fatal(0, "--inactivity-probe argument must be at least 5");
}
break;
" -f, --fail=open|closed when controller connection fails:\n"
" closed: drop all packets\n"
" open (default): act as learning switch\n"
- " -d, --fail-open-delay=SECS number of seconds after which to\n"
- " fail open if --fail=open (default: 30)\n"
+ " --inactivity-probe=SECS time between inactivity probes\n"
" --max-idle=SECS max idle for flows set up by secchan\n"
" -l, --listen=METHOD allow management connections on METHOD\n"
" (a passive OpenFlow connection method)\n"