summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--ryu/controller/controller.py19
-rw-r--r--ryu/controller/ofp_event.py8
-rw-r--r--ryu/controller/ofp_handler.py18
-rw-r--r--ryu/tests/unit/controller/test_controller.py2
4 files changed, 27 insertions, 20 deletions
diff --git a/ryu/controller/controller.py b/ryu/controller/controller.py
index 1ae72876..177b2892 100644
--- a/ryu/controller/controller.py
+++ b/ryu/controller/controller.py
@@ -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:
diff --git a/ryu/controller/ofp_event.py b/ryu/controller/ofp_event.py
index 16eb493a..aa2b6c1c 100644
--- a/ryu/controller/ofp_event.py
+++ b/ryu/controller/ofp_event.py
@@ -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')
diff --git a/ryu/controller/ofp_handler.py b/ryu/controller/ofp_handler.py
index edff696d..b524a285 100644
--- a/ryu/controller/ofp_handler.py
+++ b/ryu/controller/ofp_handler.py
@@ -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):
diff --git a/ryu/tests/unit/controller/test_controller.py b/ryu/tests/unit/controller/test_controller.py
index 0eeb30df..27a2bce6 100644
--- a/ryu/tests/unit/controller/test_controller.py
+++ b/ryu/tests/unit/controller/test_controller.py
@@ -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)