diff options
author | Simon Horman <horms@verge.net.au> | 2014-01-29 12:06:11 +0900 |
---|---|---|
committer | FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp> | 2014-01-29 12:43:15 +0900 |
commit | fd0f72b40d1d6ce4e39493e971f49d51809a424b (patch) | |
tree | 26d9b39985a719ccaf96196c73c667bcceb88243 | |
parent | 3043c904371ef6f1138a1e8c1c3071b82f7aff01 (diff) |
Add OF1.4 role request and reply message support
Signed-off-by: Simon Horman <horms@verge.net.au>
Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r-- | ryu/ofproto/ofproto_v1_4_parser.py | 97 |
1 files changed, 97 insertions, 0 deletions
diff --git a/ryu/ofproto/ofproto_v1_4_parser.py b/ryu/ofproto/ofproto_v1_4_parser.py index c0b00397..55de6844 100644 --- a/ryu/ofproto/ofproto_v1_4_parser.py +++ b/ryu/ofproto/ofproto_v1_4_parser.py @@ -3007,3 +3007,100 @@ class OFPActionPopPbb(OFPAction): (type_, len_) = struct.unpack_from( ofproto.OFP_ACTION_HEADER_PACK_STR, buf, offset) return cls() + + +@_set_msg_type(ofproto.OFPT_ROLE_REQUEST) +class OFPRoleRequest(MsgBase): + """ + Role request message + + The controller uses this message to change its role. + + ================ ====================================================== + Attribute Description + ================ ====================================================== + role One of the following values. + OFPCR_ROLE_NOCHANGE + OFPCR_ROLE_EQUAL + OFPCR_ROLE_MASTER + OFPCR_ROLE_SLAVE + generation_id Master Election Generation ID + ================ ====================================================== + + Example:: + + def send_role_request(self, datapath): + ofp = datapath.ofproto + ofp_parser = datapath.ofproto_parser + + req = ofp_parser.OFPRoleRequest(datapath, ofp.OFPCR_ROLE_EQUAL, 0) + datapath.send_msg(req) + """ + def __init__(self, datapath, role=None, generation_id=None): + super(OFPRoleRequest, self).__init__(datapath) + self.role = role + self.generation_id = generation_id + + def _serialize_body(self): + assert self.role is not None + assert self.generation_id is not None + msg_pack_into(ofproto.OFP_ROLE_REQUEST_PACK_STR, + self.buf, ofproto.OFP_HEADER_SIZE, + self.role, self.generation_id) + + +@_register_parser +@_set_msg_type(ofproto.OFPT_ROLE_REPLY) +class OFPRoleReply(MsgBase): + """ + Role reply message + + The switch responds with this message to a role request. + + ================ ====================================================== + Attribute Description + ================ ====================================================== + role One of the following values. + OFPCR_ROLE_NOCHANGE + OFPCR_ROLE_EQUAL + OFPCR_ROLE_MASTER + OFPCR_ROLE_SLAVE + generation_id Master Election Generation ID + ================ ====================================================== + + Example:: + + @set_ev_cls(ofp_event.EventOFPRoleReply, MAIN_DISPATCHER) + def role_reply_handler(self, ev): + msg = ev.msg + ofp = dp.ofproto + + if msg.role == ofp.OFPCR_ROLE_NOCHANGE: + role = 'NOCHANGE' + elif msg.role == ofp.OFPCR_ROLE_EQUAL: + role = 'EQUAL' + elif msg.role == ofp.OFPCR_ROLE_MASTER: + role = 'MASTER' + elif msg.role == ofp.OFPCR_ROLE_SLAVE: + role = 'SLAVE' + else: + role = 'unknown' + + self.logger.debug('OFPRoleReply received: ' + 'role=%s generation_id=%d', + role, msg.generation_id) + """ + def __init__(self, datapath, role=None, generation_id=None): + super(OFPRoleReply, self).__init__(datapath) + self.role = role + self.generation_id = generation_id + + @classmethod + def parser(cls, datapath, version, msg_type, msg_len, xid, buf): + msg = super(OFPRoleReply, cls).parser(datapath, version, + msg_type, msg_len, xid, + buf) + (msg.role, msg.generation_id) = struct.unpack_from( + ofproto.OFP_ROLE_REQUEST_PACK_STR, msg.buf, + ofproto.OFP_HEADER_SIZE) + return msg |