How to use the nox.lib.packet.ethernet.ethernet function in nox

To help you get started, we’ve selected a few nox examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github bigswitch / snac-nox / src / nox / apps / discovery / discovery.py View on Github external
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
github bigswitch / snac-nox / src / nox / lib / util.py View on Github external
def f(event):
        if event.reason == openflow.OFPR_NO_MATCH:
            reason = openflow.OFPR_NO_MATCH
        elif event.reason == openflow.OFPR_ACTION:
            reason = openflow.OFPR_ACTION
        else:
            print 'packet_in reason type %u unknown...just passing along' % event.reason
            reason = event.reason

        if event.buffer_id == UINT32_MAX:
            buffer_id = None
        else:
            buffer_id = event.buffer_id

        try:
            packet = ethernet(array.array('B', event.buf))
        except IncompletePacket, e:
            log.err('Incomplete Ethernet header',system='pyapi')
        
        ret = handler(event.datapath_id, event.in_port, reason,
                      event.total_len, buffer_id, packet)
        if ret == None:
            return CONTINUE
        return ret
    return f
github GlobalNOC / OESS / nox / src / nox / netapps / nddi / nddi_dbus.py View on Github external
def fire_send_fv_packets(self):

        time_val = time() * 1000
        logger.info("Sending FV Packets rate: " + str(self.sg.fv_pkt_rate) + " with vlan: " + str(self.sg.VLAN_ID) + " packets: " + str(len(self.sg.packets)))

        for pkt in self.sg.packets:
            logger.info("Packet:")
            packet = ethernet()
            packet.src = '\x00' + struct.pack('!Q',pkt[0])[3:8]
            packet.dst = NDP_MULTICAST

            payload = struct.pack('QHQHq',pkt[0],pkt[1],pkt[2],pkt[3],time_val)

            if(self.sg.VLAN_ID != None and self.sg.VLAN_ID != 65535):
                vlan_packet = vlan()
                vlan_packet.id = self.sg.VLAN_ID
                vlan_packet.c = 0
                vlan_packet.pcp = 0
                vlan_packet.eth_type = 0x88b6
                vlan_packet.set_payload(payload)

                packet.set_payload(vlan_packet)
                packet.type = ethernet.VLAN_TYPE
github GlobalNOC / OESS / nox / src / nox / netapps / discovery / discovery.py View on Github external
# 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
github CPqD / RouteFlow / nox / src / nox / lib / util.py View on Github external
def f(event):
        if event.reason == openflow.OFPR_NO_MATCH:
            reason = openflow.OFPR_NO_MATCH
        elif event.reason == openflow.OFPR_ACTION:
            reason = openflow.OFPR_ACTION
        else:
            print 'packet_in reason type %u unknown...just passing along' % event.reason
            reason = event.reason

        if event.buffer_id == UINT32_MAX:
            buffer_id = None
        else:
            buffer_id = event.buffer_id

        try:
            packet = ethernet(array.array('B', event.buf))
        except IncompletePacket, e:
            log.err('Incomplete Ethernet header',system='pyapi')
        
        ret = handler(event.datapath_id, event.in_port, reason,
                      event.total_len, buffer_id, packet)
        if ret == None:
            return CONTINUE
        return ret
    return f
github GlobalNOC / OESS / nox / src / nox / netapps / discovery / discovery.py View on Github external
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
github GlobalNOC / OESS / nox / src / nox / netapps / discovery / discovery.py View on Github external
def lldp_input_handler(self, dp_id, inport, ofp_reason, total_frame_len, buffer_id, packet):
        
        if(packet.type == ethernet.VLAN_TYPE):
            packet = packet.next
            assert (packet.eth_type == ethernet.LLDP_TYPE)
        elif(packet.type == ethernet.LLDP_TYPE):
            assert (packet.type == ethernet.LLDP_TYPE)
        else:
            #we should not get here!
            lg.error("lldp_input_handler did not get a proper packet")
            return

        if not packet.next:
            lg.error("lldp_input_handler lldp packet could not be parsed")
            return
    
        assert (isinstance(packet.next, lldp))
    
        lldph = packet.next
github GlobalNOC / OESS / nox / src / nox / netapps / nddi / nddi_dbus.py View on Github external
def fv_packet_in_callback(sg,dp,inport,reason,len,bid,packet):
    if(packet.type == ethernet.VLAN_TYPE):
        packet = packet.next

    string = packet.next
    logger.info(string.encode('hex'))
    (src_dpid,src_port,dst_dpid,dst_port,timestamp) = struct.unpack('QHQHq',string[:40])
    
    #verify the packet came in from expected node/port
    if(dst_dpid != dp):
        logger.warn("Packet was sent to dpid: " + str(dst_dpid) + " but came from: " + str(dp))
        return
    if(dst_port != inport):
        logger.warn("Packet was sent to port: " + str(dst_port) + " but came from: " + str(inport))
        return

    sg.fv_packet_in(src_dpid,src_port,dst_dpid,dst_port,timestamp)