summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorIWASE Yusuke <iwase.yusuke0@gmail.com>2017-11-29 16:23:16 +0900
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2017-12-11 22:33:41 +0900
commit7e6f3f00edcb2312e86d3341f0775bd12ef75916 (patch)
tree2f890f9a8da44223ff25bebc56a2b0ef20a8e776
parent63f81837fd73cc31edbfe9ba6814ae3f38e34a16 (diff)
topology: Enable to detect migrations of hosts
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.elzoghbi@gmail.com> Signed-off-by: IWASE Yusuke <iwase.yusuke0@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/topology/event.py20
-rw-r--r--ryu/topology/switches.py5
2 files changed, 25 insertions, 0 deletions
diff --git a/ryu/topology/event.py b/ryu/topology/event.py
index e7b682c9..d4b29b68 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 7264075a..5f14440e 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: