def run_simulation(network_dir, condition, test_sub_name, disconnection_rate=0.0, drop_rate=0.0, threshold=sys.maxint): """ Network directory should contain network and sample files """ test_name = os.path.basename(network_dir) print "%s - %s - %s disconnect(%4.2f) drop(%4.2f) threshold(%d)" % (network_dir, test_name, test_sub_name, disconnection_rate, drop_rate, threshold) network_file_path = os.path.join(network_dir, test_name + ".txt") assert os.path.exists(network_file_path), "No network file %s exists " % network_file_path sample_file_path = os.path.join(network_dir, test_name + ".sample.txt") assert os.path.exists(sample_file_path), "No network file %s exists " % sample_file_path network = Network(network_file_path) host_ids = network.get_host_ids() # [h0, h1, h2] hosts = [] neighbors = network.get_network() # {0:[1], 1:[0,2], 2:[1]} for h in host_ids: # neighbor should be set in this experiment hosts.append(Host(id=h, neighbors=neighbors[h])) test_directory, sample = make_ready_for_test(network_dir=network_dir, test_name=test_name, condition=condition, test_sub_name=test_sub_name) if test_sub_name.startswith("single"): propagation_mode = ContextAggregator.SINGLE_ONLY_MODE else: propagation_mode = ContextAggregator.AGGREGATION_MODE config = {"network":network, "hosts":hosts, "neighbors":neighbors, "test_directory":test_directory, "sample":sample, "disconnection_rate":disconnection_rate, "drop_rate":drop_rate, ContextAggregator.PM:propagation_mode, "threshold":threshold} s = AggregationAsyncSimulator() simulation = s.run(config=config) return simulation
def get_average_network_link(network): n = Network(network) ids = n.get_host_ids() result = [] for id in ids: result.append(n.get_neighbors(id)) sizes = map(len, result) return 1.0*sum(sizes)/len(sizes)
def get_hosts(self): """ >>> d = get_simple_test_dir() + os.sep + "test_network1" >>> r = ReadReports(d).get_hosts() >>> r == ['host1', 'host2', 'host3', 'host4', 'host5', 'host6', 'host7', 'host8'] True """ network_dir = self.network_dir network_name = os.path.basename(network_dir) network_file_path = os.path.join(network_dir, network_name + ".txt") assert os.path.exists(network_file_path), "No %s network file exists" % network_file_path n = Network(network_file_path) ids = n.get_host_ids() return ["host%d" % i for i in sorted(ids)]