Exemplo n.º 1
0
def pkt_retransmits(request, src_node, dst_node):
    #print 'Pkt retransmits'
    try:
        d = request.session.get(request.session.session_key)
        if d is None:            
            raise Exception, INVALID_SESSION_MSG
        if NS_TRACEFILE_KEY in d:
            #print 'Trace file key found'
            if NS_TRACEFILE_MODE in d:
                #print 'Trace file format found (', d[NS_TRACEFILE_MODE], ')'
                # Create a TraceAnalyzer object
                ta = TraceAnalyzer(d[NS_TRACEFILE_KEY], d[NS_TRACEFILE_MODE])
                retransmits = ta.get_packet_retransmissions(src_node, dst_node)
                label = 'Packet retransmission count between %s-%s' % (src_node, dst_node,)
                retransmits = {
                    'data': retransmits,
                    'label': label,
                }
                #print retransmits
                return HttpResponse(json.dumps(retransmits))
            else:
                raise KeyError, 'Trace file mode not set!'
        else:
            raise KeyError, 'Wrong key!!!'
    except KeyError, ke:
        #print str(ke)
        mesg = str(ke)
        error = {'error' : mesg}
        return HttpResponse(json.dumps(error))
Exemplo n.º 2
0
def analyze_trace_file(trace_file_name, session_key, timestamp, metrics):

    metrics_dir_path       = '/'.join( [globals.NS2_SCRIPT_STORAGE_PATH, 'batch', session_key, timestamp, 'metrics',] )
    
    try:
        os.makedirs( metrics_dir_path )
        #print 'Created dir', metrics_dir_path
        
        try:
            tr_file = open(trace_file_name, 'r')
            #print 'Analyzing trace file', trace_file_name

            metrics = json.loads( metrics )
            #print metrics
            for a_metric in metrics:
                a_metric = json.loads( a_metric )
                
                if a_metric['name'] == "bytes-rcvd":

                    # Sample: {"name":"bytes-rcvd","parameters":[66,"MAC|RTR|"],"mode":"Wired"}
                    ta = TraceAnalyzer( trace_file_name, a_metric['mode'] )
                    layers = a_metric['parameters'][1].strip()
                    if len(layers) > 0:
                        layers = [ l.strip() for l in a_metric['parameters'][1].split('|') if l.strip() != '' ]
                    else:
                        layers = None
                    #print layers
                    bytes_rcvd = ta.get_cumulative_bytes_received_for_node_at_layers(a_metric['parameters'][0], layers)
                    #print 'bytes_rcvd', len(bytes_rcvd)
                    xvals = []
                    yvals = []
                    for entry in bytes_rcvd:
                        xvals.append(entry[0])
                        yvals.append(entry[1])

                    image_file_name = '-'.join( [ 'bytes_rcvd', str(a_metric['parameters'][0]), a_metric['parameters'][1].replace('|', '_') ] )
                    image_file_name += '.png'

                    image_title = 'Bytes received by node %d (%s)' % ( a_metric['parameters'][0], a_metric['parameters'][1], )
                                        
                    plot_graph(xvals, yvals, 'Time (in seconds)', 'Kbits received', image_title, metrics_dir_path+'/'+image_file_name)
                    
                elif a_metric['name'] == "e2e-delay":

                    # Sample: {"name":"e2e-delay","parameters":[66,67,1],"mode":"Wired"}
                    ta = TraceAnalyzer( trace_file_name, a_metric['mode'] )
                    delay = ta.get_end2end_delay( a_metric['parameters'][0], a_metric['parameters'][1] )

                    xvals = []
                    yvals = []
                    for entry in delay:
                        xvals.append(entry[0])
                        yvals.append(entry[1])

                    image_file_name = '-'.join( [ 'e2e_delay', str(a_metric['parameters'][0]), str(a_metric['parameters'][1]), str(a_metric['parameters'][2]) ] )
                    image_file_name += '.png'

                    image_title = 'End-to-end delay between nodes %d and %d (scaling = %d)' % (a_metric['parameters'][0], a_metric['parameters'][1], a_metric['parameters'][2])
                                        
                    plot_graph(xvals, yvals, 'Packet sequence #', 'Delay', image_title, metrics_dir_path+'/'+image_file_name)

                elif a_metric['name'] == "pkt-retransmission":

                    # Sample: {"name":"pkt-retransmission","parameters":[66,67],"mode":"Wired"}
                    ta = TraceAnalyzer( trace_file_name, a_metric['mode'] )
                    count = ta.get_packet_retransmissions( a_metric['parameters'][0], a_metric['parameters'][1] )

                    xvals = []
                    yvals = []
                    for entry in count:
                        xvals.append(entry[0])
                        yvals.append(entry[1])

                    image_file_name = '-'.join( [ 'pkt-retransmission', str(a_metric['parameters'][0]), str(a_metric['parameters'][1]), ] )
                    image_file_name += '.png'

                    image_title = 'Packet retransmissions between nodes %d and %d' % ( a_metric['parameters'][0], a_metric['parameters'][1], )

                    plot_graph(xvals, yvals, 'Packet sequence #', 'Retransmission count', image_title, metrics_dir_path+'/'+image_file_name)
                                                            
                elif a_metric['name'] == "hop-count":

                    # Sample: {"name":"hop-count","parameters":[66,0,67,0],"mode":"Wired"}
                    ta = TraceAnalyzer( trace_file_name, a_metric['mode'] )
                    count = ta.get_hop_count_pkt_seq_num( a_metric['parameters'][0], a_metric['parameters'][1], a_metric['parameters'][2], a_metric['parameters'][3] )

                    xvals = []
                    yvals = []
                    for entry in count:
                        xvals.append(entry[0])
                        yvals.append(entry[1])

                    image_file_name = '-'.join( [ 'pkt-retransmission', str(a_metric['parameters'][0]), str(a_metric['parameters'][1]), ] )
                    image_file_name += '.png'

                    image_title = 'Hop count between nodes %d:%d and %d:%d' % ( a_metric['parameters'][0], a_metric['parameters'][1], a_metric['parameters'][2], a_metric['parameters'][2], )
                    
                    plot_graph(xvals, yvals, 'Packet sequence #', 'Hop count', image_title, metrics_dir_path+'/'+image_file_name)
                    
            
        except IOError, ioe:
            output['error'] = str(ioe)
        finally:
            if tr_file:
                tr_file.close()