/*
- * 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. */
ofconn_send_error(const struct ofconn *ofconn,
const struct ofp_header *request, enum ofperr error)
{
+ static struct vlog_rate_limit err_rl = VLOG_RATE_LIMIT_INIT(10, 10);
struct ofpbuf *reply;
reply = ofperr_encode_reply(error, request);
- if (reply) {
- static struct vlog_rate_limit err_rl = VLOG_RATE_LIMIT_INIT(10, 10);
-
- if (!VLOG_DROP_INFO(&err_rl)) {
- const char *type_name;
- size_t request_len;
- enum ofpraw raw;
-
- request_len = ntohs(request->length);
- type_name = (!ofpraw_decode_partial(&raw, request,
- MIN(64, request_len))
- ? ofpraw_get_name(raw)
- : "invalid");
-
- VLOG_INFO("%s: sending %s error reply to %s message",
- rconn_get_name(ofconn->rconn), ofperr_to_string(error),
- type_name);
- }
- ofconn_send_reply(ofconn, reply);
+ if (!VLOG_DROP_INFO(&err_rl)) {
+ const char *type_name;
+ size_t request_len;
+ enum ofpraw raw;
+
+ request_len = ntohs(request->length);
+ type_name = (!ofpraw_decode_partial(&raw, request,
+ MIN(64, request_len))
+ ? ofpraw_get_name(raw)
+ : "invalid");
+
+ VLOG_INFO("%s: sending %s error reply to %s message",
+ rconn_get_name(ofconn->rconn), ofperr_to_string(error),
+ type_name);
}
+ ofconn_send_reply(ofconn, reply);
}
/* Same as pktbuf_retrieve(), using the pktbuf owned by 'ofconn'. */
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;
}