}
rr->role = ntohl(orr->role);
- if (raw == OFPRAW_OFPT12_ROLE_REPLY
- || orr->role == htonl(OFPCR12_ROLE_NOCHANGE)) {
+ if (raw == OFPRAW_OFPT12_ROLE_REQUEST
+ ? orr->role == htonl(OFPCR12_ROLE_NOCHANGE)
+ : orr->generation_id == htonll(UINT64_MAX)) {
rr->have_generation_id = false;
rr->generation_id = 0;
} else {
buf = ofpraw_alloc_reply(OFPRAW_OFPT12_ROLE_REPLY, request, 0);
orr = ofpbuf_put_zeros(buf, sizeof *orr);
- orr->role = htonl(rr->role);
- /*
- * OpenFlow specification does not specify use of generation_id field
- * on reply messages. Intuitively, it would seem a good idea to return
- * the current value. However, the current value is undefined
- * initially, and there is no way to insert an undefined value in the
- * message. Therefore we leave the generation_id zeroed on reply
- * messages.
- *
- * A request for clarification has been filed with the Open Networking
- * Foundation as EXT-272.
- */
- orr->generation_id = htonll(0);
+ orr->role = htonl(rr->role);
+ orr->generation_id = htonll(rr->have_generation_id
+ ? rr->generation_id
+ : UINT64_MAX);
} else if (raw == OFPRAW_NXT_ROLE_REQUEST) {
struct nx_role_request *nrr;
return ofconn->type;
}
+/* If a master election id is defined, stores it into '*idp' and returns
+ * true. Otherwise, stores UINT64_MAX into '*idp' and returns false. */
+bool
+ofconn_get_master_election_id(const struct ofconn *ofconn, uint64_t *idp)
+{
+ *idp = (ofconn->connmgr->master_election_id_defined
+ ? ofconn->connmgr->master_election_id
+ : UINT64_MAX);
+ return ofconn->connmgr->master_election_id_defined;
+}
+
/* Sets the master election id.
*
* Returns true if successful, false if the id is stale
}
reply.role = ofconn_get_role(ofconn);
- reply.have_generation_id = false;
- reply.generation_id = 0;
+ reply.have_generation_id = ofconn_get_master_election_id(
+ ofconn, &reply.generation_id);
buf = ofputil_encode_role_reply(oh, &reply);
ofconn_send_reply(ofconn, buf);
AT_KEYWORDS([ofp-print])
AT_CHECK([ovs-ofctl ofp-print "\
03 19 00 18 00 00 00 02 00 00 00 03 00 00 00 00 \
-00 00 00 00 00 00 00 00 \
+12 34 56 78 ab cd ef 90 \
"], [0], [dnl
-OFPT_ROLE_REPLY (OF1.2) (xid=0x2): role=slave
+OFPT_ROLE_REPLY (OF1.2) (xid=0x2): role=slave generation_id=1311768467750121360
])
AT_CLEANUP
# Become slave (generation_id is initially undefined, so 2^63+2 should not be stale)
ovs-appctl -t ovs-ofctl ofctl/send 031800180000000300000003000000008000000000000002
echo >>expout "send: OFPT_ROLE_REQUEST (OF1.2) (xid=0x3): role=slave generation_id=9223372036854775810"
-echo >>expout "OFPT_ROLE_REPLY (OF1.2) (xid=0x3): role=slave"
+echo >>expout "OFPT_ROLE_REPLY (OF1.2) (xid=0x3): role=slave generation_id=9223372036854775810"
# Try to become the master using a stale generation ID
ovs-appctl -t ovs-ofctl ofctl/send 031800180000000400000002000000000000000000000002
# Become master using a valid generation ID
ovs-appctl -t ovs-ofctl ofctl/send 031800180000000500000002000000000000000000000001
echo >>expout "send: OFPT_ROLE_REQUEST (OF1.2) (xid=0x5): role=master generation_id=1"
-echo >>expout "OFPT_ROLE_REPLY (OF1.2) (xid=0x5): role=master"
+echo >>expout "OFPT_ROLE_REPLY (OF1.2) (xid=0x5): role=master generation_id=1"
ovs-appctl -t ovs-ofctl ofctl/barrier
echo >>expout "OFPT_BARRIER_REPLY (OF1.2) (xid=0x3):"