At Thu, 11 Jun 2015 02:30:40 +0800,
Yi Tseng wrote:
> 
> Signed-off-by: Takeshi <[email protected]>
> ---
>  ryu/topology/api.py      |  7 +++++
>  ryu/topology/event.py    | 23 +++++++++++++++++
>  ryu/topology/switches.py | 66
> +++++++++++++++++++++++++++++++++++++++++++++++-
>  3 files changed, 95 insertions(+), 1 deletion(-)

> diff --git a/ryu/topology/switches.py b/ryu/topology/switches.py
> index 63335f2..ab7f9f6 100644
> --- a/ryu/topology/switches.py
> +++ b/ryu/topology/switches.py
> @@ -157,6 +157,35 @@ class Link(object):
>      def __str__(self):
>          return 'Link: %s to %s' % (self.src, self.dst)
> 
> +class Host(object):
> +    # This is data class passed by EventHostXXXX
> +    def __init__(self, dpid, port, mac):
> +        super(Host, self).__init__()
> +        self.dpid = dpid
> +        self.port = port
> +        self.mac = mac
> +
> +    def to_dict(self):
> +        d = {
> +            'dpid': self.dpid,
> +            'port': self.port,
> +            'mac': self.mac
> +            }
> +        return d
> +
> +    # this type is used for key value of LinkState

Really? And why are you ignoring dpid and port in comparison
operators?

> +    def __eq__(self, other):
> +        return self.mac == other.mac
> +
> +    def __ne__(self, other):
> +        return not self.__eq__(other)
> +
> +    def __hash__(self):
> +        return hash(self.mac)
> +
> +    def __str__(self):
> +        return 'Host<Mac address=%s>' % (self.mac, )
> +
> 
>  class PortState(dict):
>      # dict: int port_no -> OFPPort port
> @@ -451,6 +480,7 @@ class Switches(app_manager.RyuApp):
>          self.port_state = {}          # datapath_id => ports
>          self.ports = PortDataState()  # Port class -> PortData class
>          self.links = LinkState()      # Link class -> timestamp
> +        self.hosts = {}
>          self.is_active = True
> 
>          self.link_discovery = self.CONF.observe_links
> @@ -689,7 +719,25 @@ class Switches(app_manager.RyuApp):
>              src_dpid, src_port_no = LLDPPacket.lldp_parse(msg.data)
>          except LLDPPacket.LLDPUnknownFormat as e:
>              # This handler can receive all the packtes which can be
> -            # not-LLDP packet. Ignore it silently
> +            # not-LLDP packet.
> +            # Check if it's new host
> +
> +            dpid = msg.datapath.id
> +            port = -1
> +
> +            if msg.datapath.ofproto.OFP_VERSION ==
> ofproto_v1_0.OFP_VERSION:
> +                port = msg.in_port
> +            elif msg.datapath.ofproto.OFP_VERSION >=
> ofproto_v1_2.OFP_VERSION:
> +                port = msg.match['in_port']
> +
> +            pkt = packet.Packet(msg.data)
> +            eth = pkt.get_protocols(ethernet.ethernet)[0]
> +            mac = eth.src
> +
> +            if mac not in self.hosts and port != -1:
> +                LOG.debug('Found host(mac=%s) from dpid=%d, port=%d', mac,
> dpid, port)
> +                self.hosts[mac] = Host(dpid, port, mac)
> +
>              return
> 
>          dst_dpid = msg.datapath.id

--
IWAMOTO Toshihiro

------------------------------------------------------------------------------
_______________________________________________
Ryu-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/ryu-devel

Reply via email to