Ejemplo n.º 1
0
    def create_discovery_packet(self, dpid, port_num, port_addr):
        """
        Build discovery packet
        """

        chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL)
        chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1])
        # Maybe this should be a MAC.  But a MAC of what?  Local port, maybe?

        port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num))

        ttl = pkt.ttl(ttl=self._ttl)

        sysdesc = pkt.system_description()
        sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1])

        discovery_packet = pkt.lldp()
        discovery_packet.tlvs.append(chassis_id)
        discovery_packet.tlvs.append(port_id)
        discovery_packet.tlvs.append(ttl)
        discovery_packet.tlvs.append(sysdesc)
        discovery_packet.tlvs.append(pkt.end_tlv())

        eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE)
        eth.src = port_addr
        eth.dst = pkt.ETHERNET.NDP_MULTICAST
        eth.payload = discovery_packet

        po = of.ofp_packet_out(action=of.ofp_action_output(port=port_num))
        po.data = eth.pack()
        return po.pack()
Ejemplo n.º 2
0
    def _create_discovery_packet(dpid, port_num, port_addr, ttl):
        """
    Build discovery packet
    """

        chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL)
        chassis_id.id = ('dpid:' + hex(int(dpid))[2:]).encode()
        # Maybe this should be a MAC.  But a MAC of what?  Local port, maybe?

        port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num))

        ttl = pkt.ttl(ttl=ttl)

        sysdesc = pkt.system_description()
        sysdesc.payload = ('dpid:' + hex(int(dpid))[2:]).encode()

        discovery_packet = pkt.lldp()
        discovery_packet.tlvs.append(chassis_id)
        discovery_packet.tlvs.append(port_id)
        discovery_packet.tlvs.append(ttl)
        discovery_packet.tlvs.append(sysdesc)
        discovery_packet.tlvs.append(pkt.end_tlv())

        eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE)
        eth.src = port_addr
        eth.dst = pkt.ETHERNET.NDP_MULTICAST
        eth.payload = discovery_packet

        return eth
Ejemplo n.º 3
0
  def create_discovery_packet (self, dpid):
    """
    Build discovery packet
    """
    chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_LOCAL)
    chassis_id.id = bytes('dpid:' + hex(long(dpid))[2:-1])

    # Maybe this should be a MAC.  But a MAC of what?  Local port, maybe?
    port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(255))
    ttl = pkt.ttl(ttl = 120)
    sysdesc = pkt.system_description()
    sysdesc.payload = bytes('dpid:' + hex(long(dpid))[2:-1])

    discovery_packet = pkt.lldp()
    discovery_packet.tlvs.append(chassis_id)
    discovery_packet.tlvs.append(port_id)
    discovery_packet.tlvs.append(ttl)
    discovery_packet.tlvs.append(sysdesc)
    discovery_packet.tlvs.append(pkt.end_tlv())
    
    eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE)
    eth.src = "0x000000"
    eth.dst = pkt.ETHERNET.NDP_MULTICAST
    eth.payload = discovery_packet
    #---------------Made changes-----------------------
    actionSet = []
    selectedDpid = dpid
    #print'Sending PacketOut to SWitch', selectedDpid
    
    #:need to for all ports in one swtich
    for p in _portInfo:
      #packetOut floods exclueding the ingress (secure port to Controller)
      if p.port_num!=65534 and p.dpid == selectedDpid:
        actionSet.append(of.ofp_action_dl_addr.set_src(p.port_addr))
        actionSet.append(of.ofp_action_output(port=p.port_num))
    #print'actionSet-------->',actionSet
    po = of.ofp_packet_out(action = actionSet)
    po.data = eth.pack()
    return po.pack()
Ejemplo n.º 4
0
    def _create_lldp_packet(self, dpid, port_num, port_addr):
        """ Creating LLDP packet """

        chassis_id = pkt.chassis_id(subtype=pkt.chassis_id.SUB_CHASSIS, id=str(dpid))

        port_id = pkt.port_id(subtype=pkt.port_id.SUB_PORT, id=str(port_num))

        ttl = pkt.ttl(ttl=1)

        lldp_packet = pkt.lldp()
        lldp_packet.tlvs.append(chassis_id)
        lldp_packet.tlvs.append(port_id)
        lldp_packet.tlvs.append(ttl)
        lldp_packet.tlvs.append(pkt.end_tlv())

        eth = pkt.ethernet(type=pkt.ethernet.LLDP_TYPE)
        eth.src = port_addr
        eth.dst = pkt.ETHERNET.LLDP_MULTICAST
        eth.payload = lldp_packet

        po = of.ofp_packet_out(action=of.ofp_action_output(port=port_num))
        po.data = eth.pack()
        return po.pack()