diff options
-rw-r--r-- | ryu/topology/event.py | 20 | ||||
-rw-r--r-- | ryu/topology/switches.py | 5 |
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: |