def run_general(scheme, trace, nflows, nruns, nlandmarks, scale_list, percentage, num_max_cache): assert (trace in VALID_TRACES) assert (scheme in VALID_SCHEMES) # initialize topology and transactions from the dataset G_ori, trans = get_topology_and_transactions(trace) # find the right threshold for the requested "percentage" threshold = get_threshold(trace, trans, percentage) # run simulation ("nruns" times) for every possible "scale_factor" value and record # and average over success ratio, success volume, transaction fees, # number of probing messages, and cache hit probability (Flash only) 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 = [] print('Start run simulation for trace', trace, '- scheme', scheme, '- scale factor', scale_factor) # payments to send for seed in range(nruns): random.seed(seed) payments = generate_payments(trace, 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) # record stats for the current run 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) # average over runs and store averages 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) # log results to file with open(f'{trace}-{scheme}-{nflows}.txt', 'w') as filehandle: filehandle.write(' '.join([str(e) for e in res_volume]) + '\n') filehandle.write(' '.join([str(e) for e in res_ratio]) + '\n') filehandle.write(' '.join([str(e) for e in res_msg]) + '\n') if scheme == 'flash': filehandle.write(' '.join([str(e) for e in res_hit]) + '\n')
def run_flash_cache(trace, nflows, nruns, scale_factor, percentage, cache_list): assert (trace in VALID_TRACES) # initialize topology and transactions from the dataset G_ori, trans = get_topology_and_transactions(trace) # run Flash simulation ("nruns" times) for every possible "num_max_cache" value and record # and average over success ratio, success volume, and number of probing messages flash_micro_volume = [] flash_micro_msg = [] flash_ratio = [] flash_hit = [] flash_table = [] for num_max_cache in cache_list: G = scale_topo_cap(G_ori, scale_factor) threshold = get_threshold(trace, trans, percentage) micro_volume_list = [] micro_msg_list = [] ratio_list = [] hit_list = [] table_list = [] # payments to send for seed in range(nruns): print('Start run simulation. Run', seed) payments = generate_payments(trace, seed, nflows, trans, G) # todo: lightning trace??? (remark: seems that "flash_micro_msg" remains empty for "lightning"? at least that is the case in "sim/result/rawdata/lightning-cache.txt") 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) # record stats for the current run micro_volume_list.append(1.0 * micro_volume) micro_msg_list.append(micro_msg) ratio_list.append(1.0 * num_delivered / nflows) hit_list.append(hit_ratio) table_list.append(table_size) # average over runs and store averages flash_micro_volume.append(sum(micro_volume_list) / nruns) flash_micro_msg.append(sum(micro_msg_list) / nruns) flash_ratio.append(sum(ratio_list) / nruns) flash_hit.append(sum(hit_list) / nruns) flash_table.append(sum(table_list) / nruns) # log results to file with open(f'{trace}-cache.txt', 'w') as filehandle: filehandle.write(' '.join([str(e) for e in flash_micro_volume]) + '\n') filehandle.write(' '.join([str(e) for e in flash_ratio]) + '\n') filehandle.write(' '.join([str(e) for e in flash_hit]) + '\n') filehandle.write(' '.join([str(e) for e in flash_table]) + '\n') filehandle.write(' '.join([str(e) for e in flash_micro_msg]) + '\n')
def run_flash_cache(trace, nflows, nruns, scale_factor, percentage, cache_list): G_ori = nx.DiGraph() trans = [] if (trace == 'ripple'): G_ori, trans = ripple_proc.setup() if (trace == 'lightning'): G_ori, trans = lightning_proc.setup() flash_micro_volume = [] flash_micro_msg = [] flash_ratio = [] flash_hit = [] flash_table = [] for num_max_cache in cache_list: G = scale_topo_cap(G_ori, scale_factor) threshold = get_threshold(trace, trans, percentage) micro_volume_list = [] micro_msg_list = [] ratio_list = [] hit_list = [] table_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) micro_volume_list.append(1.0*micro_volume) micro_msg_list.append(micro_msg) ratio_list.append(1.0*num_delivered/nflows) hit_list.append(hit_ratio) table_list.append(table_size) flash_micro_volume.append(sum(micro_volume_list)/nruns) flash_micro_msg.append(sum(micro_msg_list)/nruns) flash_ratio.append(sum(ratio_list)/nruns) flash_hit.append(sum(hit_list)/nruns) flash_table.append(sum(table_list)/nruns) with open(trace+'-'+'cache.txt', 'w') as filehandle: for element in flash_micro_volume: filehandle.write('%s ' % element) filehandle.write('\n') for element in flash_ratio: filehandle.write('%s ' % element) filehandle.write('\n') for element in flash_hit: filehandle.write('%s ' % element) filehandle.write('\n') for element in flash_table: filehandle.write('%s ' % element) for element in flash_micro_msg: filehandle.write('%s ' % element)
def run_flash_thresh(trace, nflows, nruns, scale_factor, percentage_list, num_max_cache): assert (trace in VALID_TRACES) # initialize topology and transactions from the dataset G_ori, trans = get_topology_and_transactions(trace) # run Flash simulation ("nruns" times) for every possible "percentage" value and record # and average over success ratio, success volume, and number of probing messages 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 = [] # simulate multiple runs of payments for seed in range(nruns): print('Start run simulation. Run', seed) payments = generate_payments(trace, 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) # record stats for the current run volume_list.append(1.0 * volume) ratio_list.append(1.0 * num_delivered / nflows) msg_list.append(1.0 * total_probing_messages) # average over runs and store averages flash_volume.append(sum(volume_list) / nruns) flash_ratio.append(sum(ratio_list) / nruns) flash_msg.append(sum(msg_list) / nruns) # log results to file with open(f'{trace}-threshold.txt', 'w') as filehandle: filehandle.write(' '.join([str(e) for e in flash_volume]) + '\n') filehandle.write(' '.join([str(e) for e in flash_ratio]) + '\n') filehandle.write(' '.join([str(e) for e in flash_msg]) + '\n')
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)