コード例 #1
0
def run_flash_thresh(trace, nflows, nruns, scale_factor, percentage_list,
                     num_max_cache):
    G_ori = nx.DiGraph()
    trans = []

    if (trace == 'ripple'):
        G_ori, trans = ripple_proc.setup()
    if (trace == 'lightning'):
        G_ori, trans = lightning_proc.setup()

    flash_ratio = []
    flash_volume = []
    flash_msg = []

    for percentage in percentage_list:
        G = scale_topo_cap(G_ori, scale_factor)

        threshold = get_threshold(trace, trans, percentage)
        print 'threshold', threshold

        volume_list = []
        ratio_list = []
        msg_list = []

        # payments to send
        for seed in range(nruns):
            print 'Start run simulation. Run', seed
            payments = []
            if trace == 'ripple':
                payments = ripple_proc.generate_payments(
                    seed, nflows, trans, G)
            if trace == 'lightning':
                payments = lightning_proc.generate_payments(
                    seed, nflows, trans, G)

            volume, cost, num_delivered, total_probing_messages, total_max_path_length, hit_ratio, table_size, micro_volume, micro_msg = flash.routing(
                G.copy(), payments, threshold, num_max_cache)
            volume_list.append(1.0 * volume)
            ratio_list.append(1.0 * num_delivered / nflows)
            msg_list.append(1.0 * total_probing_messages)

        flash_volume.append(sum(volume_list) / nruns)
        flash_ratio.append(sum(ratio_list) / nruns)
        flash_msg.append(sum(msg_list) / nruns)

    with open(trace + '-' + 'threshold.txt', 'w') as filehandle:
        for element in flash_volume:
            filehandle.write('%s ' % element)
        filehandle.write('\n')
        for element in flash_ratio:
            filehandle.write('%s ' % element)
        filehandle.write('\n')
        for element in flash_msg:
            filehandle.write('%s ' % element)
コード例 #2
0
def get_topology_and_transactions(trace):
    assert (trace in VALID_TRACES)

    G_ori = nx.DiGraph()
    trans = []

    if trace == 'ripple':
        G_ori, trans = ripple_proc.setup()
    elif trace == 'lightning':
        G_ori, trans = lightning_proc.setup()

    return (G_ori, trans)
コード例 #3
0
def run_general(scheme, trace, nflows, nruns, nlandmarks, scale_list, percentage, num_max_cache):
	G_ori = nx.DiGraph()
	trans = []

	if (trace == 'ripple'):
		G_ori, trans = ripple_proc.setup()	
	if (trace == 'lightning'):
		G_ori, trans = lightning_proc.setup()

	threshold = get_threshold(trace, trans, percentage)

	res_ratio = []
	res_volume = []
	res_cost = []
	res_msg = []
	res_hit = []

	for scale_factor in scale_list:
		G = nx.DiGraph()
		G = scale_topo_cap(G_ori, scale_factor)

		volume_list = []
		ratio_list = []
		cost_list = []
		msg_list = []
		hit_list = []

		# payments to send
		for seed in range(nruns):
			random.seed(seed)
			print 'Start run simulation. Run', seed, ' trace ', trace, ' scheme ', scheme

			payments = []
			if trace == 'ripple': 
				payments = ripple_proc.generate_payments(seed, nflows, trans, G)
			if trace == 'lightning': 
				payments = lightning_proc.generate_payments(seed, nflows, trans, G)

			if scheme == 'sp':
				volume, cost, num_delivered, total_probing_messages, total_max_path_length = shortest_path.routing(G.copy(), payments)
			elif scheme == 'speedymurmurs': 
				volume, cost, num_delivered, total_probing_messages, total_max_path_length = speedymurmurs.routing(G.copy(), payments, nlandmarks)
			elif scheme == 'waterfilling':
				volume, cost, num_delivered, total_probing_messages, total_max_path_length = waterfilling.routing(G.copy(), payments)
			elif scheme == 'flash': 
				volume, cost, num_delivered, total_probing_messages, total_max_path_length, hit_ratio, table_size, micro_volume, micro_msg  = flash.routing(G.copy(), payments, threshold, num_max_cache)
			else: 
				print 'unknown routing'

			volume_list.append(1.0*volume)
			ratio_list.append(1.0*num_delivered/nflows)
			cost_list.append(cost)
			msg_list.append(1.0*total_probing_messages)
			if scheme == 'flash': 
				hit_list.append(hit_ratio)


		res_volume.append(sum(volume_list)/nruns)
		res_ratio.append(sum(ratio_list)/nruns)
		res_cost.append(sum(cost_list)/nruns)
		res_msg.append(sum(msg_list)/nruns)
		if scheme == 'flash': 
			res_hit.append(sum(hit_list)/nruns)

		print scheme, res_cost

	with open(trace+'-'+scheme+'-'+str(nflows)+'.txt', 'w') as filehandle: 
		for element in res_volume: 
			filehandle.write('%s ' % element)
		filehandle.write('\n')
		for element in res_ratio: 
			filehandle.write('%s ' % element)
		filehandle.write('\n')
		for element in res_msg: 
			filehandle.write('%s ' % element)
		if scheme == 'flash':
			filehandle.write('\n')
			for element in res_hit: 
				filehandle.write('%s ' % element)