summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorTakeshi <a86487817@gmail.com>2015-08-18 16:54:48 +0800
committerFUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>2015-08-20 18:14:19 +0900
commit2281b7a6aeb13bc3b10f1b77fbc7754769911c8f (patch)
treecf6b369634d84d147ee4c354bbc73637f4dec374
parent59da77306ce5b0b83a84dd96561dca66e577cdeb (diff)
Add EventHostAdd event.
This event is generated when a new host is added to a switch. Signed-off-by: Takeshi <a86487817@gmail.com> Signed-off-by: FUJITA Tomonori <fujita.tomonori@lab.ntt.co.jp>
-rw-r--r--ryu/topology/event.py14
-rw-r--r--ryu/topology/switches.py15
2 files changed, 24 insertions, 5 deletions
diff --git a/ryu/topology/event.py b/ryu/topology/event.py
index 83881c00..6afbe78f 100644
--- a/ryu/topology/event.py
+++ b/ryu/topology/event.py
@@ -149,3 +149,17 @@ class EventHostReply(event.EventReplyBase):
def __str__(self):
return 'EventHostReply<dst=%s, dpid=%s, hosts=%s>' % \
(self.dst, self.dpid, len(self.hosts))
+
+
+class EventHostBase(event.EventBase):
+ def __init__(self, host):
+ super(EventHostBase, self).__init__()
+ self.host = host
+
+ def __str__(self):
+ return '%s<%s>' % (self.__class__.__name__, self.host)
+
+
+class EventHostAdd(EventHostBase):
+ def __init__(self, host):
+ super(EventHostAdd, self).__init__(host)
diff --git a/ryu/topology/switches.py b/ryu/topology/switches.py
index 31b4b0c8..382e5554 100644
--- a/ryu/topology/switches.py
+++ b/ryu/topology/switches.py
@@ -496,7 +496,8 @@ class Switches(app_manager.RyuApp):
_EVENTS = [event.EventSwitchEnter, event.EventSwitchLeave,
event.EventPortAdd, event.EventPortDelete,
event.EventPortModify,
- event.EventLinkAdd, event.EventLinkDelete]
+ event.EventLinkAdd, event.EventLinkDelete,
+ event.EventHostAdd]
DEFAULT_TTL = 120 # unused. ignored.
LLDP_PACKET_LEN = len(LLDPPacket.lldp_packet(0, 0, DONTCARE_STR, 0))
@@ -841,18 +842,22 @@ class Switches(app_manager.RyuApp):
host_mac = eth.src
host = Host(host_mac, port)
- # arp packet, update both location and ip
- if eth.ethertype == ether_types.ETH_TYPE_ARP:
+ if host_mac not in self.hosts:
self.hosts.add(host)
+ ev = event.EventHostAdd(host)
+ self.send_event_to_observers(ev)
+
+ # arp packet, update ip address
+ if eth.ethertype == ether_types.ETH_TYPE_ARP:
arp_pkt = pkt.get_protocols(arp.arp)[0]
self.hosts.update_ip(host, ip_v4=arp_pkt.src_ip)
- # ipv4 packet, update ip only
+ # ipv4 packet, update ipv4 address
elif eth.ethertype == ether_types.ETH_TYPE_IP:
ipv4_pkt = pkt.get_protocols(ipv4.ipv4)[0]
self.hosts.update_ip(host, ip_v4=ipv4_pkt.src)
- # ipv6 packet, update ip only
+ # ipv6 packet, update ipv6 address
elif eth.ethertype == ether_types.ETH_TYPE_IPV6:
# TODO: need to handle NDP
ipv6_pkt = pkt.get_protocols(ipv6.ipv6)[0]