Beispiel #1
0
def calc_stats(filename,controller,port):
    pending = {}

    ip = inet_pton(AF_INET,controller)
    ip = struct.unpack("I",ip)[0]

    oft = oftrace.oftrace_open(filename)
    m = oftrace.oftrace_next_msg(oft,ip,port)

    while(m != None):
        if(m.type == oftrace.OFPT_PACKET_IN):
            eth = oftrace.uint_to_oft_ethhdr(m.ptr.packet_in.data)
            etype = ntohs(eth.ether_type)

            # don't capture LLDP packets
            if(etype != 0x88cc):
                # don't store the whole message. python seems to trouble with
                # shallow and deep copies of swig objects...
                msg = {}
                msg["src_ip"] = inet_ntop(AF_INET,struct.pack("I",m.ip.saddr))
                msg["tcp_src"] = m.tcp.source
                msg["dst_ip"] = inet_ntop(AF_INET,struct.pack("I",m.ip.daddr))
                msg["tcp_dst"] = m.tcp.dest
                msg["sec"] = m.phdr.ts_sec
                msg["usec"] = m.phdr.ts_usec
                msg["type"] = m.type

                # enqueue packet in pending-response queue
                buf_id = m.ptr.packet_in.buffer_id
                pending[buf_id] = msg

        elif(m.type == oftrace.OFPT_PACKET_OUT or m.type == oftrace.OFPT_FLOW_MOD):
            if (m.type == oftrace.OFPT_PACKET_OUT):
                buf_id = m.ptr.packet_out.buffer_id
            else:
                buf_id = m.ptr.flow_mod.buffer_id
            if pending.has_key(buf_id):
                src_ip = inet_ntop(AF_INET,struct.pack("I",m.ip.saddr))
                dst_ip = inet_ntop(AF_INET,struct.pack("I",m.ip.daddr))

                diff_time = timesub(m,pending[buf_id])

                print ("%ld.%.6ld secs_to_resp %ld.%.6ld buf_id:%x from %s:%u -> %s:%u (%d packets queued)") % \
                      (diff_time["sec"],
                       diff_time["usec"],
		       pending[buf_id]['sec'],
                       pending[buf_id]['usec'],
                       buf_id,
                       src_ip,
                       ntohs(m.tcp.source),
                       dst_ip,
                       ntohs(m.tcp.dest),
                       len(pending))
                # ok, now we can remove initial request (packet-in) from queue
                del pending[buf_id]
            elif(buf_id != 0xffffffff):
                sys.stderr.write("weird, bufid %x not found \n" % (buf_id) )

        m = oftrace.oftrace_next_msg(oft,ip,port)
Beispiel #2
0
def do_analyze(filename, controller, port):
    msg_count = 0
    start_time = {}
    # a bit ugly...
    ip = inet_pton(AF_INET, controller)
    ip = struct.unpack("I", ip)[0]

    oft = oftrace.oftrace_open(filename)
    m = oftrace.oftrace_next_msg(oft, ip, port)

    # save this for timestamp reference
    if (m != None):
        start_time["sec"] = m.phdr.ts_sec
        start_time["usec"] = m.phdr.ts_usec
    # dump all packets
    while (m != None):
        msg_count = msg_count + 1
        dump_msg(msg_count, m, start_time)
        m = oftrace.oftrace_next_msg(oft, ip, port)
Beispiel #3
0
def do_analyze(filename, controller, port):
    msg_count = 0
    start_time = {}
    # a bit ugly...
    ip = inet_pton(AF_INET, controller)
    ip = struct.unpack("I", ip)[0]

    oft = oftrace.oftrace_open(filename)
    m = oftrace.oftrace_next_msg(oft, ip, port)

    # save this for timestamp reference
    if m != None:
        start_time["sec"] = m.phdr.ts_sec
        start_time["usec"] = m.phdr.ts_usec
    # dump all packets
    while m != None:
        msg_count = msg_count + 1
        dump_msg(msg_count, m, start_time)
        m = oftrace.oftrace_next_msg(oft, ip, port)
Beispiel #4
0
def calc_stats(filename, controller, port):
    pending = {}

    ip = inet_pton(AF_INET, controller)
    ip = struct.unpack("I", ip)[0]

    oft = oftrace.oftrace_open(filename)
    m = oftrace.oftrace_next_msg(oft, ip, port)
    last_progress = -1.0
    while (m != None):
        progress = oftrace.oftrace_progress(oft)
        if (progress > (last_progress + MinProgress)):
            sys.stderr.write("--------- %f done ----\n" % (progress))
            last_progress = progress
        if m.type == oftrace.OFPT_PACKET_OUT:
            if m.ptr.packet_out.buffer_id != 4294967295L:  # skip if this packet_out
                m = oftrace.oftrace_next_msg(oft, ip, port)
                continue  # is releasing a packet in a buffer
            eth = m.embedded_packet
            etype = ntohs(eth.ether_type)
            # capture only LLDP packets
            if (etype == 0x88cc):
                # don't store the whole message. python seems to trouble with
                # shallow and deep copies of swig objects...
                msg = {}
                msg["src_ip"] = inet_ntop(AF_INET,
                                          struct.pack("I", m.ip.saddr))
                msg["tcp_src"] = m.tcp.source
                msg["dst_ip"] = inet_ntop(AF_INET,
                                          struct.pack("I", m.ip.daddr))
                msg["tcp_dst"] = m.tcp.dest
                msg["sec"] = m.phdr.ts_sec
                msg["usec"] = m.phdr.ts_usec
                msg["type"] = m.type

                # enqueue packet in pending-response queue
                srcdst = srcdst2str(eth.ether_dhost, eth.ether_shost)
                if pending.has_key(srcdst):
                    print_dropped(pending, srcdst)
                pending[srcdst] = msg
        elif (m.type == oftrace.OFPT_PACKET_IN):
            eth = m.embedded_packet
            etype = ntohs(eth.ether_type)
            # capture only LLDP packets
            if (etype == 0x88cc):
                srcdst = srcdst2str(eth.ether_dhost, eth.ether_shost)
                #		pdb.set_trace()
                if pending.has_key(srcdst):
                    src_ip = inet_ntop(AF_INET, struct.pack("I", m.ip.saddr))
                    dst_ip = inet_ntop(AF_INET, struct.pack("I", m.ip.daddr))
                    diff_time = timesub(m, pending[srcdst])
                    print ("%ld.%.6ld secs_to_resp %ld.%.6ld %s from %s:%u -> %s:%u (%d packets queued)") % \
                     (diff_time["sec"],
                      diff_time["usec"],
                      pending[srcdst]['sec'],
                      pending[srcdst]['usec'],
                      srcdst,
                      src_ip,
                      ntohs(m.tcp.source),
                      dst_ip,
                      ntohs(m.tcp.dest),
                      len(pending))
                    del pending[srcdst]
        # grab next message at bottom of loop b/c Python is brain dead
        # 	and doesn't allow this inside the conditional
        #print "----------- Grabbing next packet ----------"
        m = oftrace.oftrace_next_msg(oft, ip, port)
Beispiel #5
0
def calc_stats(filename, controller, port):
    pending = {}

    ip = inet_pton(AF_INET, controller)
    ip = struct.unpack("I", ip)[0]

    oft = oftrace.oftrace_open(filename)
    m = oftrace.oftrace_next_msg(oft, ip, port)

    while (m != None):
        if (m.type == oftrace.OFPT_PACKET_IN):
            eth = oftrace.uint_to_oft_ethhdr(m.ptr.packet_in.data)
            etype = ntohs(eth.ether_type)

            # don't capture LLDP packets
            if (etype != 0x88cc):
                # don't store the whole message. python seems to trouble with
                # shallow and deep copies of swig objects...
                msg = {}
                msg["src_ip"] = inet_ntop(AF_INET,
                                          struct.pack("I", m.ip.saddr))
                msg["tcp_src"] = m.tcp.source
                msg["dst_ip"] = inet_ntop(AF_INET,
                                          struct.pack("I", m.ip.daddr))
                msg["tcp_dst"] = m.tcp.dest
                msg["sec"] = m.phdr.ts_sec
                msg["usec"] = m.phdr.ts_usec
                msg["type"] = m.type

                # enqueue packet in pending-response queue
                buf_id = m.ptr.packet_in.buffer_id
                pending[buf_id] = msg

        elif (m.type == oftrace.OFPT_PACKET_OUT
              or m.type == oftrace.OFPT_FLOW_MOD):
            if (m.type == oftrace.OFPT_PACKET_OUT):
                buf_id = m.ptr.packet_out.buffer_id
            else:
                buf_id = m.ptr.flow_mod.buffer_id
            if pending.has_key(buf_id):
                src_ip = inet_ntop(AF_INET, struct.pack("I", m.ip.saddr))
                dst_ip = inet_ntop(AF_INET, struct.pack("I", m.ip.daddr))

                diff_time = timesub(m, pending[buf_id])

                print ("%ld.%.6ld secs_to_resp %ld.%.6ld buf_id:%x from %s:%u -> %s:%u (%d packets queued)") % \
                      (diff_time["sec"],
                       diff_time["usec"],
                pending[buf_id]['sec'],
                       pending[buf_id]['usec'],
                       buf_id,
                       src_ip,
                       ntohs(m.tcp.source),
                       dst_ip,
                       ntohs(m.tcp.dest),
                       len(pending))
                # ok, now we can remove initial request (packet-in) from queue
                del pending[buf_id]
            elif (buf_id != 0xffffffff):
                sys.stderr.write("weird, bufid %x not found \n" % (buf_id))

        m = oftrace.oftrace_next_msg(oft, ip, port)
Beispiel #6
0
def calc_stats(filename,controller,port):
	pending = {}

	ip = inet_pton(AF_INET,controller)
	ip = struct.unpack("I",ip)[0]

	oft = oftrace.oftrace_open(filename)
	m = oftrace.oftrace_next_msg(oft,ip,port)
	last_progress=-1.0
	while(m != None):
		progress = oftrace.oftrace_progress(oft)
		if ( progress > ( last_progress + MinProgress)) :
			sys.stderr.write( "--------- %f done ----\n" % (progress))
			last_progress=progress
		if m.type == oftrace.OFPT_PACKET_OUT:
			if m.ptr.packet_out.buffer_id != 4294967295L:	# skip if this packet_out 
				m = oftrace.oftrace_next_msg(oft,ip,port)
				continue				# is releasing a packet in a buffer
			eth = m.embedded_packet
			etype = ntohs(eth.ether_type)
			# capture only LLDP packets
			if(etype == 0x88cc):
				# don't store the whole message. python seems to trouble with
				# shallow and deep copies of swig objects...
				msg = {}
				msg["src_ip"] = inet_ntop(AF_INET,struct.pack("I",m.ip.saddr))
				msg["tcp_src"] = m.tcp.source
				msg["dst_ip"] = inet_ntop(AF_INET,struct.pack("I",m.ip.daddr))
				msg["tcp_dst"] = m.tcp.dest
				msg["sec"] = m.phdr.ts_sec
				msg["usec"] = m.phdr.ts_usec
				msg["type"] = m.type

				# enqueue packet in pending-response queue
				srcdst = srcdst2str(eth.ether_dhost , eth.ether_shost);
				if pending.has_key(srcdst):
					print_dropped(pending,srcdst)
				pending[srcdst] = msg
		elif(m.type == oftrace.OFPT_PACKET_IN):
			eth = m.embedded_packet
			etype = ntohs(eth.ether_type)
			# capture only LLDP packets
			if(etype == 0x88cc):
				srcdst = srcdst2str(eth.ether_dhost , eth.ether_shost);
		#		pdb.set_trace()
				if pending.has_key(srcdst):
					src_ip = inet_ntop(AF_INET,struct.pack("I",m.ip.saddr))
					dst_ip = inet_ntop(AF_INET,struct.pack("I",m.ip.daddr))
					diff_time = timesub(m,pending[srcdst])
					print ("%ld.%.6ld secs_to_resp %ld.%.6ld %s from %s:%u -> %s:%u (%d packets queued)") % \
						(diff_time["sec"],
						 diff_time["usec"],
						 pending[srcdst]['sec'],
						 pending[srcdst]['usec'],
						 srcdst,
						 src_ip,
						 ntohs(m.tcp.source),
						 dst_ip,
						 ntohs(m.tcp.dest),
						 len(pending))
					del pending[srcdst]
		# grab next message at bottom of loop b/c Python is brain dead
		# 	and doesn't allow this inside the conditional
		#print "----------- Grabbing next packet ----------"
		m = oftrace.oftrace_next_msg(oft,ip,port)