Ejemplo n.º 1
0
def cal_bw_delay(entries_range, idx, path, link_cap, tc_result):
    '''
	This function calculates bw and delay for requested entries:
	      |<---requested entries range--->|
	------|-------------------------------|---->t
	    start                            idx
	And then it return a list of integrated available bandwidth and delay along the path
	for example,
	[1,0.0501,5,50] means [idx = 1, delta_t = 0.0501s, Available bandwidth=5Mbps(bottleneck), total delay = 50ms]
	total delay includes propagation delay as well as queueing delay.

	'''
    j2k_stats = []
    #print "index"
    #print idx
    #print "index-range"
    #print idx-entries_range

    for i in xrange(idx - entries_range + 1, idx, 1):
        #list of one entry
        l = []
        #link counter which indicates the current link index in link_cap
        link_ct = 0
        if (i - 1) in tc_result and i in tc_result:
            l.append(i)
            j = path[0]
            l.append(rnd(float(tc_result[i][j]['delta_t']), 3))
            l.append(len(path) - 1)  #the last switch is used for delay
            for j in path[0:2]:  #ignore the last entry
                l.append(int(tc_result[i][j]['BackB']))
                l.append(
                    int(tc_result[i][j]['SentB']) -
                    int(tc_result[i - 1][j]['SentB']))
                if 'MinRate' in tc_result[i][j]:
                    l.append(rnd(float(tc_result[i][j]['MinRate']), 3))
                else:
                    l.append(float(link_cap[link_ct]))

                # for key, value in tc_result[i].iteritems() :
                # 					print key, value
                if j == path[0] and 'P_Delay' in tc_result[i][path[2]]:
                    l.append(rnd(float(tc_result[i][path[2]]['P_Delay']), 3))
                else:
                    l.append(rnd(float(0), 3))
                link_ct += 1
            j2k_stats.append(l)
        else:
            pass
    #print j2k_stats
    #print entries_range
    return j2k_stats
Ejemplo n.º 2
0
def cal_bw_delay(entries_range, idx, path, link_cap, tc_result):
    '''
	This function calculates bw and delay for requested entries:
	      |<---requested entries range--->|
	------|-------------------------------|---->t
	    start                            idx
	And then it return a list of integrated available bandwidth and delay along the path
	for example,
	[1,0.0501,5,50] means [idx = 1, delta_t = 0.0501s, Available bandwidth=5Mbps(bottleneck), total delay = 50ms]
	total delay includes propagation delay as well as queueing delay.

	'''
    j2k_stats = []
    #print "index"
    #print idx
    #print "index-range"
    #print idx-entries_range

    for i in xrange(idx, idx - entries_range, -1):
        #list of one entry
        l = []
        #link counter which indicates the current link index in link_cap
        link_ct = 0
        if (i - 1) in tc_result:
            l.append(i)
            j = path[0]
            l.append(rnd(float(tc_result[i][j]['delta_t']), 3))
            l.append(len(path))
            for j in path:
                lc = float(link_cap[link_ct])
                delta_sentB = int(tc_result[i][j]['SentB']) - int(
                    tc_result[i - 1][j]['SentB'])
                used_bw = float(delta_sentB) * 8 / 1000000
                util = used_bw / float(tc_result[i][j]['delta_t']) / lc
                l.append(int(tc_result[i][j]['BackP']))
                l.append(rnd(util, 3))
                l.append(lc)
                if 'P_Delay' in tc_result[i][j]:
                    l.append(rnd(float(tc_result[i][j]['P_Delay']), 3))
                else:
                    l.append(rnd(float(0), 3))
                link_ct += 1
            j2k_stats.append(l)
        else:
            pass
    #print j2k_stats
    #print entries_range+1, ' '
    return j2k_stats
Ejemplo n.º 3
0
def cal_bw_delay(entries_range,idx,path,link_cap,tc_result):
	'''
	This function calculates bw and delay for requested entries:
	      |<---requested entries range--->|
	------|-------------------------------|---->t
	    start                            idx
	And then it return a list of integrated available bandwidth and delay along the path
	for example,
	[1,0.0501,5,50] means [idx = 1, delta_t = 0.0501s, Available bandwidth=5Mbps(bottleneck), total delay = 50ms]
	total delay includes propagation delay as well as queueing delay.

	'''
	j2k_stats = []
	#print "index"
	#print idx
	#print "index-range"
	#print idx-entries_range

	for i in xrange(idx-entries_range+1,idx,1):
		#list of one entry
		l=[]
		#link counter which indicates the current link index in link_cap
		link_ct = 0
		if (i-1) in tc_result:
			l.append(i)
			j = path[0]
			l.append(rnd(float(tc_result[i][j]['delta_t']),3))
			l.append(len(path) - 1) #the last switch is used for delay
			for j in path[0:2]: #ignore the last entry
				l.append(int(tc_result[i][j]['BackB']))
				l.append(int(tc_result[i][j]['SentB']) - int(tc_result[i-1][j]['SentB']))
				l.append(float(link_cap[link_ct]))
				if j == path[0] and 'P_Delay' in tc_result[i][path[2]]:
					l.append(rnd(float(tc_result[i][path[2]]['P_Delay']), 3))
				else:
					l.append(rnd(float(0), 3))
				link_ct+=1
			j2k_stats.append(l)
		else:
			pass
	#print j2k_stats
        #print entries_range 
	return j2k_stats
Ejemplo n.º 4
0
def cal_stats(devs, timestamp):
    """
    This function calculates bw and delay for requested entries:
          |<---requested entries range--->|
    ------|-------------------------------|---->t
        start                            idx
    And then it return a list of integrated available bandwidth and delay along the path
    for example,
    [1,0.0501,5,50] means [idx = 1, delta_t = 0.0501s, Available bandwidth=5Mbps(bottleneck), total delay = 50ms]
    total delay includes propagation delay as well as queueing delay.

    """
    # print "index"
    # print idx
    # print "index-range"
    # print idx-entries_range
    # start = time.time()
    # list of one entry
    l = []
    tcshow()
    # print tc_dict
    for dev in devs:

        # print tc_dict[dev]
        l.append(dev)
        l.append(rnd(float(tc_dict[dev]["delta_t"]), 3))
        l.append(int(tc_dict[dev]["BackB"]))
        l.append(int(tc_dict[dev]["SentB"]))

        if "P_Delay" in tc_dict[dev]:
            l.append(rnd(float(tc_dict[dev]["P_Delay"]), 3))
        else:
            l.append(rnd(float(0), 3))

    # link counter which indicates the current link index in link_cap

    # print j2k_stats
    # print entries_range
    # end = time.time()
    # print(end - start)
    return l
Ejemplo n.º 5
0
def cal_bw_delay(entries_range, idx, path, link_cap, tc_result):
    '''
	This function calculates bw and delay for requested entries:
	      |<---requested entries range--->|
	------|-------------------------------|---->t
	    start                            idx
	And then it return a list of integrated available bandwidth and delay along the path
	for example,
	[1,0.0501,5,50] means [idx = 1, delta_t = 0.0501s, Available bandwidth=5Mbps(bottleneck), total delay = 50ms]
	total delay includes propagation delay as well as queueing delay.

	'''
    j2k_stats = []
    #print "index"
    #print idx
    #print "index-range"
    #print idx-entries_range

    for i in xrange(idx, idx - entries_range, -1):
        #list of one entry
        l = []
        #list of available bandwidth at each interface
        b = []
        #total delay along the path
        delay_sum = 0
        #link counter which indicates the current link index in link_cap
        link_ct = 0
        if (i - 1) in tc_result:
            for j in path:
                if j not in tc_result[i]:
                    #no such an interface, return
                    return j2k_stats
                else:
                    #calculate being used bw. bw = delta sent out bytes/delta time between two samplings
                    delta_sentB = int(tc_result[i][j]['SentB']) - int(
                        tc_result[i - 1][j]['SentB'])
                    delta_sentP = int(tc_result[i][j]['SentP']) - int(
                        tc_result[i - 1][j]['SentP'])
                    delta_t = float(tc_result[i][j]['delta_t'])
                    bw = delta_sentB * 8 / (delta_t * 1000000
                                            )  #B/S ->Mbps *8/1000000
                    #available bandwidth = link capacity - being used bandwidth
                    avail_bw = float(link_cap[link_ct]) - bw
                    if avail_bw < 0:
                        b.append(0.0)
                    else:
                        b.append(avail_bw)
                    #calculate the delay at each snapshot.delay = backlogged bytes/link capacity
                    SentP = float(tc_result[i][j]['SentP'])
                    if SentP != 0:
                        Psize = float(tc_result[i][j]['SentB']) / float(
                            tc_result[i][j]['SentP'])
                        #Psize = float(delta_sentB) / float(delta_sentP)
                    else:
                        Psize = 1000
                    delay = int(tc_result[i][j]['BackP']) * Psize * 8 / (
                        float(link_cap[link_ct]) * 1000)  #ms
                    #if Psize>1512:
                    #print Psize, delta_sentB, delta_sentP
                    #Psize = 1512
                    #sum up all the delays along the path
                    delay_sum += delay
                    if 'P_Delay' in tc_result[i][j]:
                        delay_sum += float(tc_result[i][j]['P_Delay'])
                    link_ct += 1
                    #print '-'*10
                    #print delay_sum
                    #print '*'*10
            l.append(i)
            l.append(rnd(delta_t, 3))
            #print "index:%d"%i
            #print b
            l.append(rnd(min(b), 3))
            l.append(rnd(delay_sum, 3))
            j2k_stats.append(l)
        else:
            pass

    return j2k_stats