X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=ofproto%2Ffail-open.c;h=541bb054bd37bae7db3a0836337cbdeebf7dd04a;hb=4675d8759d28bcc6971a76cf3e36fa4ee8e40650;hp=ff77de87ec7ce8d7a4d859f7947e018955f5ed49;hpb=2f6d344525463ebe52f6bbd0e9a4cc22e33dacbe;p=sliver-openvswitch.git diff --git a/ofproto/fail-open.c b/ofproto/fail-open.c index ff77de87e..541bb054b 100644 --- a/ofproto/fail-open.c +++ b/ofproto/fail-open.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. @@ -18,21 +18,24 @@ #include "fail-open.h" #include #include +#include "classifier.h" +#include "connmgr.h" #include "flow.h" #include "mac-learning.h" #include "odp-util.h" +#include "ofp-util.h" #include "ofpbuf.h" #include "ofproto.h" +#include "ofproto-provider.h" #include "pktbuf.h" #include "poll-loop.h" #include "rconn.h" -#include "status.h" #include "timeval.h" #include "vconn.h" - -#define THIS_MODULE VLM_fail_open #include "vlog.h" +VLOG_DEFINE_THIS_MODULE(fail_open); + /* * Fail-open mode. * @@ -49,8 +52,8 @@ * connection to the controller, and thus the whole network would go down for * that period of time. * - * So, instead, we add some special caseswhen we are connected to a controller, - * but not yet sure that it has admitted us: + * So, instead, we add some special cases when we are connected to a + * controller, but not yet sure that it has admitted us: * * - We set up flows immediately ourselves, but simultaneously send out an * OFPT_PACKET_IN to the controller. We put a special bogus buffer-id in @@ -68,21 +71,38 @@ struct fail_open { struct ofproto *ofproto; - struct rconn *controller; - int trigger_duration; + struct connmgr *connmgr; int last_disconn_secs; - struct status_category *ss_cat; long long int next_bogus_packet_in; struct rconn_packet_counter *bogus_packet_counter; }; static void fail_open_recover(struct fail_open *); -/* Returns true if 'fo' should be in fail-open mode, otherwise false. */ -static inline bool -should_fail_open(const struct fail_open *fo) +/* Returns the number of seconds of disconnection after which fail-open mode + * should activate. */ +static int +trigger_duration(const struct fail_open *fo) { - return rconn_failure_duration(fo->controller) >= fo->trigger_duration; + if (!connmgr_has_controllers(fo->connmgr)) { + /* Shouldn't ever arrive here, but if we do, never fail open. */ + return INT_MAX; + } else { + /* Otherwise, every controller must have a chance to send an + * inactivity probe and reconnect before we fail open, so take the + * maximum probe interval and multiply by 3: + * + * - The first interval is the idle time before sending an inactivity + * probe. + * + * - The second interval is the time allowed for a response to the + * inactivity probe. + * + * - The third interval is the time allowed to reconnect after no + * response is received. + */ + return connmgr_get_max_probe_interval(fo->connmgr) * 3; + } } /* Returns true if 'fo' is currently in fail-open mode, otherwise false. */ @@ -93,7 +113,7 @@ fail_open_is_active(const struct fail_open *fo) } static void -send_bogus_packet_in(struct fail_open *fo) +send_bogus_packet_ins(struct fail_open *fo) { uint8_t mac[ETH_ADDR_LEN]; struct ofpbuf *opi; @@ -107,17 +127,17 @@ send_bogus_packet_in(struct fail_open *fo) ofpbuf_uninit(&b); /* Send. */ - rconn_send_with_limit(fo->controller, opi, fo->bogus_packet_counter, 1); + connmgr_broadcast(fo->connmgr, opi); } -/* Enter fail-open mode if we should be in it. Handle reconnecting to a - * controller from fail-open mode. */ +/* Enter fail-open mode if we should be in it. */ void fail_open_run(struct fail_open *fo) { + int disconn_secs = connmgr_failure_duration(fo->connmgr); + /* Enter fail-open mode if 'fo' is not in it but should be. */ - if (should_fail_open(fo)) { - int disconn_secs = rconn_failure_duration(fo->controller); + if (disconn_secs >= trigger_duration(fo)) { if (!fail_open_is_active(fo)) { VLOG_WARN("Could not connect to controller (or switch failed " "controller's post-connection admission control " @@ -137,10 +157,10 @@ fail_open_run(struct fail_open *fo) /* Schedule a bogus packet-in if we're connected and in fail-open. */ if (fail_open_is_active(fo)) { - if (rconn_is_connected(fo->controller)) { + if (connmgr_is_any_controller_connected(fo->connmgr)) { bool expired = time_msec() >= fo->next_bogus_packet_in; if (expired) { - send_bogus_packet_in(fo); + send_bogus_packet_ins(fo); } if (expired || fo->next_bogus_packet_in == LLONG_MAX) { fo->next_bogus_packet_in = time_msec() + 2000; @@ -157,7 +177,8 @@ fail_open_run(struct fail_open *fo) void fail_open_maybe_recover(struct fail_open *fo) { - if (rconn_is_admitted(fo->controller)) { + if (fail_open_is_active(fo) + && connmgr_is_any_controller_admitted(fo->connmgr)) { fail_open_recover(fo); } } @@ -165,34 +186,32 @@ fail_open_maybe_recover(struct fail_open *fo) static void fail_open_recover(struct fail_open *fo) { - if (fail_open_is_active(fo)) { - flow_t flow; + struct cls_rule rule; - VLOG_WARN("No longer in fail-open mode"); - fo->last_disconn_secs = 0; - fo->next_bogus_packet_in = LLONG_MAX; + VLOG_WARN("No longer in fail-open mode"); + fo->last_disconn_secs = 0; + fo->next_bogus_packet_in = LLONG_MAX; - memset(&flow, 0, sizeof flow); - ofproto_delete_flow(fo->ofproto, &flow, OFPFW_ALL, FAIL_OPEN_PRIORITY); - } + cls_rule_init_catchall(&rule, FAIL_OPEN_PRIORITY); + ofproto_delete_flow(fo->ofproto, &rule); } void fail_open_wait(struct fail_open *fo) { if (fo->next_bogus_packet_in != LLONG_MAX) { - poll_timer_wait(fo->next_bogus_packet_in - time_msec()); + poll_timer_wait_until(fo->next_bogus_packet_in); } } void fail_open_flushed(struct fail_open *fo) { - int disconn_secs = rconn_failure_duration(fo->controller); - bool open = disconn_secs >= fo->trigger_duration; + int disconn_secs = connmgr_failure_duration(fo->connmgr); + bool open = disconn_secs >= trigger_duration(fo); if (open) { union ofp_action action; - flow_t flow; + struct cls_rule rule; /* Set up a flow that matches every packet and directs them to * OFPP_NORMAL. */ @@ -200,54 +219,34 @@ fail_open_flushed(struct fail_open *fo) action.type = htons(OFPAT_OUTPUT); action.output.len = htons(sizeof action); action.output.port = htons(OFPP_NORMAL); - memset(&flow, 0, sizeof flow); - ofproto_add_flow(fo->ofproto, &flow, OFPFW_ALL, FAIL_OPEN_PRIORITY, - &action, 1, 0); - } -} -static void -fail_open_status_cb(struct status_reply *sr, void *fo_) -{ - struct fail_open *fo = fo_; - int cur_duration = rconn_failure_duration(fo->controller); - - status_reply_put(sr, "trigger-duration=%d", fo->trigger_duration); - status_reply_put(sr, "current-duration=%d", cur_duration); - status_reply_put(sr, "triggered=%s", - cur_duration >= fo->trigger_duration ? "true" : "false"); + cls_rule_init_catchall(&rule, FAIL_OPEN_PRIORITY); + ofproto_add_flow(fo->ofproto, &rule, &action, 1); + } } +/* Creates and returns a new struct fail_open for 'ofproto' and 'mgr'. */ struct fail_open * -fail_open_create(struct ofproto *ofproto, - int trigger_duration, struct switch_status *switch_status, - struct rconn *controller) +fail_open_create(struct ofproto *ofproto, struct connmgr *mgr) { struct fail_open *fo = xmalloc(sizeof *fo); fo->ofproto = ofproto; - fo->controller = controller; - fo->trigger_duration = trigger_duration; + fo->connmgr = mgr; fo->last_disconn_secs = 0; - fo->ss_cat = switch_status_register(switch_status, "fail-open", - fail_open_status_cb, fo); fo->next_bogus_packet_in = LLONG_MAX; fo->bogus_packet_counter = rconn_packet_counter_create(); return fo; } -void -fail_open_set_trigger_duration(struct fail_open *fo, int trigger_duration) -{ - fo->trigger_duration = trigger_duration; -} - +/* Destroys 'fo'. */ void fail_open_destroy(struct fail_open *fo) { if (fo) { - fail_open_recover(fo); - /* We don't own fo->controller. */ - switch_status_unregister(fo->ss_cat); + if (fail_open_is_active(fo)) { + fail_open_recover(fo); + } + /* We don't own fo->connmgr. */ rconn_packet_counter_destroy(fo->bogus_packet_counter); free(fo); }