mirror of
https://github.com/faucetsdn/ryu.git
synced 2026-05-05 12:26:11 +02:00
controller: Implement EventOFPPortStateChange
To notify ofp_port state change, this patch implements ofp_event.EventOFPPortStateChange. This event performs like EventOFPPortStatus, but ofp_handler will send this event after updating "ports" dict of datapath instances. And, this patch suppresses the warning when user app accessing to datapath.ports for backward compatibility. Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
This commit is contained in:
parent
af2ae13ae3
commit
9774eb60af
@ -150,25 +150,6 @@ class Datapath(ofproto_protocol.ProtocolDesc):
|
||||
self.ofp_brick = ryu.base.app_manager.lookup_service_brick('ofp_event')
|
||||
self.set_state(HANDSHAKE_DISPATCHER)
|
||||
|
||||
def _get_ports(self):
|
||||
if (self.ofproto_parser is not None and
|
||||
self.ofproto_parser.ofproto.OFP_VERSION >= 0x04):
|
||||
message = (
|
||||
'Datapath#ports is kept for compatibility with the previous '
|
||||
'openflow versions (< 1.3). '
|
||||
'This is not updated by the EventOFPPortStatus message. '
|
||||
'If you want to be updated, you should use '
|
||||
'\'ryu.controller.dpset\' or \'ryu.topology.switches\'.'
|
||||
)
|
||||
warnings.warn(message, stacklevel=2)
|
||||
return self._ports
|
||||
|
||||
def _set_ports(self, ports):
|
||||
self._ports = ports
|
||||
|
||||
# To show warning when Datapath#ports is read
|
||||
ports = property(_get_ports, _set_ports)
|
||||
|
||||
@_deactivate
|
||||
def close(self):
|
||||
if self.state != DEAD_DISPATCHER:
|
||||
|
||||
@ -86,4 +86,12 @@ class EventOFPStateChange(event.EventBase):
|
||||
self.datapath = dp
|
||||
|
||||
|
||||
class EventOFPPortStateChange(event.EventBase):
|
||||
def __init__(self, dp, reason, port_no):
|
||||
super(EventOFPPortStateChange, self).__init__()
|
||||
self.datapath = dp
|
||||
self.reason = reason
|
||||
self.port_no = port_no
|
||||
|
||||
|
||||
handler.register_service('ryu.controller.ofp_handler')
|
||||
|
||||
@ -245,6 +245,24 @@ class OFPHandler(ryu.base.app_manager.RyuApp):
|
||||
datapath = msg.datapath
|
||||
datapath.acknowledge_echo_reply(msg.xid)
|
||||
|
||||
@set_ev_handler(ofp_event.EventOFPPortStatus, MAIN_DISPATCHER)
|
||||
def port_status_handler(self, ev):
|
||||
msg = ev.msg
|
||||
datapath = msg.datapath
|
||||
ofproto = datapath.ofproto
|
||||
|
||||
if msg.reason in [ofproto.OFPPR_ADD, ofproto.OFPPR_MODIFY]:
|
||||
datapath.ports[msg.desc.port_no] = msg.desc
|
||||
elif msg.reason == ofproto.OFPPR_DELETE:
|
||||
datapath.ports.pop(msg.desc.port_no, None)
|
||||
else:
|
||||
return
|
||||
|
||||
self.send_event_to_observers(
|
||||
ofp_event.EventOFPPortStateChange(
|
||||
datapath, msg.reason, msg.desc.port_no),
|
||||
datapath.state)
|
||||
|
||||
@set_ev_handler(ofp_event.EventOFPErrorMsg,
|
||||
[HANDSHAKE_DISPATCHER, CONFIG_DISPATCHER, MAIN_DISPATCHER])
|
||||
def error_msg_handler(self, ev):
|
||||
|
||||
@ -72,7 +72,7 @@ class Test_Datapath(unittest.TestCase):
|
||||
self.assertTrue(issubclass(msg.category, UserWarning))
|
||||
|
||||
def test_ports_accessibility_v13(self):
|
||||
self._test_ports_accessibility(ofproto_v1_3_parser, 2)
|
||||
self._test_ports_accessibility(ofproto_v1_3_parser, 0)
|
||||
|
||||
def test_ports_accessibility_v12(self):
|
||||
self._test_ports_accessibility(ofproto_v1_2_parser, 0)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user