From 7e6f3f00edcb2312e86d3341f0775bd12ef75916 Mon Sep 17 00:00:00 2001 From: IWASE Yusuke Date: Wed, 29 Nov 2017 16:23:16 +0900 Subject: 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 Signed-off-by: IWASE Yusuke Signed-off-by: FUJITA Tomonori --- 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 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' % ( + 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: -- cgit v1.2.3