This improves the abstraction behind ofproto and connmgr.
Some of this could even go into fail_open, but I'm not sure that it would
make anything easier to understand.
const struct ofproto_controller *controllers,
size_t n_controllers)
{
+ bool had_controllers = connmgr_has_controllers(mgr);
struct shash new_controllers;
struct ofconn *ofconn, *next_ofconn;
struct ofservice *ofservice, *next_ofservice;
update_in_band_remotes(mgr);
update_fail_open(mgr);
+ if (had_controllers != connmgr_has_controllers(mgr)) {
+ ofproto_flush_flows(mgr->ofproto);
+ }
}
/* Drops the connections between 'mgr' and all of its primary and secondary
void
connmgr_set_fail_mode(struct connmgr *mgr, enum ofproto_fail_mode fail_mode)
{
- mgr->fail_mode = fail_mode;
- update_fail_open(mgr);
+ if (mgr->fail_mode != fail_mode) {
+ mgr->fail_mode = fail_mode;
+ update_fail_open(mgr);
+ if (!connmgr_has_controllers(mgr)) {
+ ofproto_flush_flows(mgr->ofproto);
+ }
+ }
}
\f
/* Fail-open implementation. */
if (mgr->fail_open) {
fail_open_flushed(mgr->fail_open);
}
+
+ /* If there are no controllers and we're in standalone mode, set up a flow
+ * that matches every packet and directs them to OFPP_NORMAL (which goes to
+ * us). Otherwise, the switch is in secure mode and we won't pass any
+ * traffic until a controller has been defined and it tells us to do so. */
+ if (!connmgr_has_controllers(mgr)
+ && mgr->fail_mode == OFPROTO_FAIL_STANDALONE) {
+ union ofp_action action;
+ struct cls_rule rule;
+
+ memset(&action, 0, sizeof action);
+ action.type = htons(OFPAT_OUTPUT);
+ action.output.len = htons(sizeof action);
+ action.output.port = htons(OFPP_NORMAL);
+ cls_rule_init_catchall(&rule, 0);
+ ofproto_add_flow(mgr->ofproto, &rule, &action, 1);
+ }
}
\f
/* Creates a new ofservice for 'target' in 'mgr'. Returns 0 if successful,
return ofproto->datapath_id;
}
-bool
-ofproto_has_primary_controller(const struct ofproto *ofproto)
-{
- return connmgr_has_controllers(ofproto->connmgr);
-}
-
enum ofproto_fail_mode
ofproto_get_fail_mode(const struct ofproto *p)
{
/* Configuration querying. */
uint64_t ofproto_get_datapath_id(const struct ofproto *);
-bool ofproto_has_primary_controller(const struct ofproto *);
enum ofproto_fail_mode ofproto_get_fail_mode(const struct ofproto *);
void ofproto_get_listeners(const struct ofproto *, struct sset *);
bool ofproto_has_snoops(const struct ofproto *);
|| !strcmp(br->cfg->fail_mode, "standalone")
? OFPROTO_FAIL_STANDALONE
: OFPROTO_FAIL_SECURE;
- if (ofproto_get_fail_mode(br->ofproto) != fail_mode
- && !ofproto_has_primary_controller(br->ofproto)) {
- ofproto_flush_flows(br->ofproto);
- }
ofproto_set_fail_mode(br->ofproto, fail_mode);
- /* Delete all flows if we're switching from connected to standalone or vice
- * versa. (XXX Should we delete all flows if we are switching from one
- * controller to another?) */
-
/* Configure OpenFlow controller connection snooping. */
if (!ofproto_has_snoops(br->ofproto)) {
struct sset snoops;
struct ovsrec_controller **controllers;
size_t n_controllers;
- bool had_primary;
struct ofproto_controller *ocs;
size_t n_ocs;
} else {
ofproto_set_extra_in_band_remotes(br->ofproto, managers, n_managers);
}
- had_primary = ofproto_has_primary_controller(br->ofproto);
n_controllers = bridge_get_controllers(br, &controllers);
ofproto_set_controllers(br->ofproto, ocs, n_ocs);
free(ocs[0].target); /* From bridge_ofproto_controller_for_mgmt(). */
free(ocs);
-
- if (had_primary != ofproto_has_primary_controller(br->ofproto)) {
- ofproto_flush_flows(br->ofproto);
- }
-
- /* If there are no controllers and the bridge is in standalone
- * mode, set up a flow that matches every packet and directs
- * them to OFPP_NORMAL (which goes to us). Otherwise, the
- * switch is in secure mode and we won't pass any traffic until
- * a controller has been defined and it tells us to do so. */
- if (!n_controllers
- && ofproto_get_fail_mode(br->ofproto) == OFPROTO_FAIL_STANDALONE) {
- union ofp_action action;
- struct cls_rule rule;
-
- memset(&action, 0, sizeof action);
- action.type = htons(OFPAT_OUTPUT);
- action.output.len = htons(sizeof action);
- action.output.port = htons(OFPP_NORMAL);
- cls_rule_init_catchall(&rule, 0);
- ofproto_add_flow(br->ofproto, &rule, &action, 1);
- }
}
static void