https://jira.opencord.org/browse/CORD-1174
Inclusion of generation_id validation during master/slave election.
Addressed Review comments
Change-Id: Ib9e15617fb70204d47cf5f3b06ae94fa3e0e7ea3
diff --git a/ofagent/agent.py b/ofagent/agent.py
index 354683a..55c8bfb 100644
--- a/ofagent/agent.py
+++ b/ofagent/agent.py
@@ -32,6 +32,9 @@
class Agent(protocol.ClientFactory):
+ generation_is_defined = False
+ cached_generation_id = None
+
def __init__(self,
controller_endpoint,
datapath_id,
diff --git a/ofagent/of_protocol_handler.py b/ofagent/of_protocol_handler.py
index f4af2b9..bc6aa66 100644
--- a/ofagent/of_protocol_handler.py
+++ b/ofagent/of_protocol_handler.py
@@ -141,16 +141,22 @@
raise NotImplementedError()
def handle_role_request(self, req):
- # https://jira.opencord.org/browse/CORD-1174
- # Need to handle generator_id
if req.role == ofp.OFPCR_ROLE_MASTER or req.role == ofp.OFPCR_ROLE_SLAVE:
- self.role = req.role
- self.cxn.send(ofp.message.role_reply(
- xid=req.xid, role=req.role, generation_id=req.generation_id))
+ if self.agent.generation_is_defined and (
+ ((req.generation_id - self.agent.cached_generation_id) & 0xffffffffffffffff) if abs(
+ req.generation_id - self.agent.cached_generation_id) > 0x7fffffffffffffff else (
+ req.generation_id - self.agent.cached_generation_id)) < 0:
+ self.cxn.send(ofp.message.bad_request_error_msg(code=ofp.OFPRRFC_STALE))
+ else:
+ self.agent.generation_is_defined = True
+ self.agent.cached_generation_id = req.generation_id
+ self.role = req.role
+ self.cxn.send(ofp.message.role_reply(
+ xid=req.xid, role=req.role, generation_id=req.generation_id))
elif req.role == ofp.OFPCR_ROLE_EQUAL:
- self.role = req.role
- self.cxn.send(ofp.message.role_reply(
- xid=req.xid, role=req.role))
+ self.role = req.role
+ self.cxn.send(ofp.message.role_reply(
+ xid=req.xid, role=req.role))
def handle_packet_out_request(self, req):
if self.role == ofp.OFPCR_ROLE_MASTER or self.role == ofp.OFPCR_ROLE_EQUAL: