Currently, the topology library does not update the position of a host
which was detected before even if the host migrated to another port.

This patch enables to detect the migrations of the hosts when the host
is detected on another port.

Reported-by: Mahmoud Elzoghbi <mahmoud.said.elzog...@gmail.com>
Signed-off-by: IWASE Yusuke <iwase.yusu...@gmail.com>
---
 ryu/topology/event.py    | 20 ++++++++++++++++++++
 ryu/topology/switches.py |  5 +++++
 2 files changed, 25 insertions(+)

diff --git a/ryu/topology/event.py b/ryu/topology/event.py
index e7b682c..d4b29b6 100644
--- a/ryu/topology/event.py
+++ b/ryu/topology/event.py
@@ -170,4 +170,24 @@ class EventHostAdd(EventHostBase):
     def __init__(self, host):
         super(EventHostAdd, self).__init__(host)
 
+
+# Note: Currently, EventHostDelete will never be raised, because we have no
+# appropriate way to detect the disconnection of hosts. Just defined for
+# future use.
+class EventHostDelete(EventHostBase):
+    def __init__(self, host):
+        super(EventHostDelete, self).__init__(host)
+
+
+class EventHostMove(event.EventBase):
+    def __init__(self, src, dst):
+        super(EventHostMove, self).__init__()
+        self.src = src
+        self.dst = dst
+
+    def __str__(self):
+        return '%s<src=%s, dst=%s>' % (
+            self.__class__.__name__, self.src, self.dst)
+
+
 handler.register_service('ryu.topology.switches')
diff --git a/ryu/topology/switches.py b/ryu/topology/switches.py
index 7264075..5f14440 100644
--- a/ryu/topology/switches.py
+++ b/ryu/topology/switches.py
@@ -868,6 +868,11 @@ class Switches(app_manager.RyuApp):
             self.hosts.add(host)
             ev = event.EventHostAdd(host)
             self.send_event_to_observers(ev)
+        elif self.hosts[host_mac].port != port:
+            # assumes the host is moved to another port
+            ev = event.EventHostMove(src=self.hosts[host_mac], dst=host)
+            self.hosts[host_mac] = host
+            self.send_event_to_observers(ev)
 
         # arp packet, update ip address
         if eth.ethertype == ether_types.ETH_TYPE_ARP:
-- 
2.7.4


------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Ryu-devel mailing list
Ryu-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to