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>
This commit is contained in:
Takeshi 2015-08-18 16:54:48 +08:00 committed by FUJITA Tomonori
parent 59da77306c
commit 2281b7a6ae
2 changed files with 24 additions and 5 deletions

@ -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)

@ -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]