Ejemplo n.º 1
0
def create_discovery_packet(dpid, portno, ttl_):

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo
    cid.fill(4, array.array('B', struct.pack('!Q', dpid))[2:8])
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2, array.array('B', struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()
    # To insure that the LLDP src mac address is not a multicast
    # address, since we have no control on choice of dpid
    eth.src = '\x00' + struct.pack('!Q', dpid)[3:8]
    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth
def create_discovery_packet(dpid, portno, ttl_):    

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo 
    cid.fill(chassis_id.SUB_LOCAL, array.array('B', 'dpid:' + hex(long(dpid))[2:-1]))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2,array.array('B',struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()
    # To insure that the LLDP src mac address is not a multicast
    # address, since we have no control on choice of dpid
    eth.src = '\x00' + struct.pack('!Q',dpid)[3:8]
    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth
Ejemplo n.º 3
0
def create_discovery_packet(dpid, portno, vlan_id, ttl_):    

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo 
    cid.fill(chassis_id.SUB_LOCAL, array.array('B', 'dpid:' + hex(long(dpid))[2:-1]))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2,array.array('B',struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()
    eth.src = '\x00' + struct.pack('!Q',dpid)[3:8]
    eth.dst = NDP_MULTICAST
    
    if(vlan_id != None):
        
        vlan_packet = vlan()
        vlan_packet.id = vlan_id
        vlan_packet.pcp = 0
        vlan_packet.c = 0
        vlan_packet.eth_type = ethernet.LLDP_TYPE
        vlan_packet.set_payload(discovery_packet)

        eth.set_payload(vlan_packet)
        eth.type = ethernet.VLAN_TYPE
        eth.eth_type = ethernet.LLDP_TYPE
    
    else:
        eth.set_payload(discovery_packet)
        eth.type = ethernet.LLDP_TYPE
        

    return eth
Ejemplo n.º 4
0
def create_discovery_packet(dpid, hwaddr, portno, ttl_):

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo
    cid.fill(chassis_id.SUB_NETWORK, array.array('B', struct.pack('!Q', dpid)))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2, array.array('B', struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()

    # Ideally, LLDPs sent out of a port shud have its hwaddr. But,
    # if the switch is reporting MAC address same as DPID, then we
    # shud distinguish from it using local MAC addr. This also
    # insures that the LLDP src mac addr is not a multicast addr.
    if hwaddr == struct.pack('!Q', dpid)[2:8]:
        eth.src = struct.pack('!Q', dpid | 0x020000000000)[2:8]
    else:
        eth.src = hwaddr

    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth
Ejemplo n.º 5
0
def create_discovery_packet(dpid, hwaddr, portno, ttl_):

    # Create lldp packet
    discovery_packet = lldp()
    cid = chassis_id()

    # nbo 
    cid.fill(chassis_id.SUB_NETWORK, array.array('B', struct.pack('!Q',dpid)))
    discovery_packet.add_tlv(cid)

    pid = port_id()
    pid.fill(2,array.array('B',struct.pack('!H', portno)))
    discovery_packet.add_tlv(pid)

    ttlv = ttl()
    ttlv.fill(ttl_)
    discovery_packet.add_tlv(ttlv)

    discovery_packet.add_tlv(end_tlv())

    eth = ethernet()

    # Ideally, LLDPs sent out of a port shud have its hwaddr. But,
    # if the switch is reporting MAC address same as DPID, then we
    # shud distinguish from it using local MAC addr. This also
    # insures that the LLDP src mac addr is not a multicast addr.
    if hwaddr == struct.pack('!Q',dpid)[2:8]:
        eth.src = struct.pack('!Q', dpid | 0x020000000000)[2:8]
    else:
        eth.src = hwaddr

    eth.dst = NDP_MULTICAST
    eth.set_payload(discovery_packet)
    eth.type = ethernet.LLDP_TYPE

    return eth