def _port_added(self, port):
     """
     Adds the port to a list of ports used to 
     connect two switches.
     """
     lldp_data = LLDPPacket.lldp_packet(
         port.dpid, port.port_no, port.hw_addr, self.DEFAULT_TTL)
     self.ports.add_port(port, lldp_data)
    def _lldp_handler(self, msg):
        """
        Will react to LLDP packets by parsing then and creating 
        events so that the controller knows to update its topology
        representation.
        """
        try:
            # Attempt to parse the packet as an LLDP packet
            # Will fail if it is not an LLDP packet
            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
            #print("Not LLDP Packet")
            return

        dst_dpid = msg.datapath.id
        if msg.datapath.ofproto.OFP_VERSION == ofproto_v1_0.OFP_VERSION:
            dst_port_no = msg.in_port
        elif msg.datapath.ofproto.OFP_VERSION >= ofproto_v1_2.OFP_VERSION:
            dst_port_no = msg.match['in_port']
        else:
            LOG.error('cannot accept LLDP. unsupported version. %x',
                      msg.datapath.ofproto.OFP_VERSION)

        src = self._get_port(src_dpid, src_port_no)
        if not src or src.dpid == dst_dpid:
            return
        try:
            self.ports.lldp_received(src)
        except KeyError:
            # There are races between EventOFPPacketIn and
            # EventDPPortAdd. So packet-in event can happend before
            # port add event. In that case key error can happend.
            # LOG.debug('lldp_received: KeyError %s', e)
            pass

        dst = self._get_port(dst_dpid, dst_port_no)
        if not dst:
            return

        old_peer = self.links.get_peer(src)
        if old_peer and old_peer != dst:
            old_link = Link(src, old_peer)
            self.send_event_to_observers(event.EventLinkDelete(old_link))

        link = Link(src, dst)
        if link not in self.links:
            self.send_event_to_observers(event.EventLinkAdd(link))
	    if src_dpid not in self.switch_ports:
		self.switch_ports[src_dpid] = []
	    if src_port_no not in self.switch_ports[src_dpid]:
	        self.switch_ports[src_dpid].append(src_port_no)
	    if dst_dpid not in self.switch_ports:
		self.switch_ports[dst_dpid] = []
	    if dst_port_no not in self.switch_ports[dst_dpid]:
		self.switch_ports[dst_dpid].append(dst_port_no)

        if not self.links.update_link(src, dst):
            self.ports.move_front(dst)
            self.lldp_event.set()