/*
- * Copyright (c) 2009, 2010, 2011, 2012 Nicira, Inc.
+ * Copyright (c) 2009, 2010, 2011, 2012, 2013 Nicira, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
/* OpenFlow connections. */
struct hmap controllers; /* Controller "struct ofconn"s. */
struct list all_conns; /* Contains "struct ofconn"s. */
+ uint64_t master_election_id; /* monotonically increasing sequence number
+ * for master election */
+ bool master_election_id_defined;
/* OpenFlow listeners. */
struct hmap services; /* Contains "struct ofservice"s. */
hmap_init(&mgr->controllers);
list_init(&mgr->all_conns);
+ mgr->master_election_id = 0;
+ mgr->master_election_id_defined = false;
hmap_init(&mgr->services);
mgr->snoops = NULL;
SSET_FOR_EACH (name, sset) {
struct pvconn *pvconn;
int error;
- error = pvconn_open(name, 0, &pvconn, 0);
+ error = pvconn_open(name, 0, 0, &pvconn);
if (!error) {
pvconns[n_pvconns++] = pvconn;
} else {
return ofconn->type;
}
+/* Sets the master election id.
+ *
+ * Returns true if successful, false if the id is stale
+ */
+bool
+ofconn_set_master_election_id(struct ofconn *ofconn, uint64_t id)
+{
+ if (ofconn->connmgr->master_election_id_defined
+ &&
+ /* Unsigned difference interpreted as a two's complement signed
+ * value */
+ (int64_t)(id - ofconn->connmgr->master_election_id) < 0) {
+ return false;
+ }
+ ofconn->connmgr->master_election_id = id;
+ ofconn->connmgr->master_election_id_defined = true;
+
+ return true;
+}
+
/* Returns the role configured for 'ofconn'.
*
* The default role, if no other role has been set, is NX_ROLE_OTHER. */
struct pvconn *pvconn;
int error;
- error = pvconn_open(target, allowed_versions, &pvconn, dscp);
+ error = pvconn_open(target, allowed_versions, dscp, &pvconn);
if (error) {
return error;
}