示例#1
0
    def test_use_env(self):
        for _ in range(0, 1000):
            links, symbolic_link_names, max_failures = SamplerTest.get_random_links(
            )
            netenv = NetworkEnvironment(links, k_failures=max_failures)

            sampler = Sampler(netenv)

            used_samples = set()
            for j in range(0, 10):
                sample = random.randint(0, netenv.num_concrete_envs - 1)
                concrete_env = netenv.get_concrete_env(sample)

                self.assertEqual(sampler.use_env(concrete_env), sample
                                 not in used_samples)
                used_samples.add(sample)
示例#2
0
    def get_query(sources):
        sources = [PolicySource(src_router) for src_router in sources]
        destinations = PolicyDestination("r12", "FastEthernet1/1", "11.0.12.0/24")
        num_paths = 3
        links = [Link("l{id}".format(id=i), edge, LinkState.UP) for i, edge in enumerate(ResponseTest.get_all_edges())]
        netenv = NetworkEnvironment(links)

        return Query(PolicyType.LoadBalancingSimple, sources, destinations, num_paths, netenv, negate=False)
示例#3
0
    def test_max_num_samples(self):
        for _ in range(0, 1000):
            links, symbolic_link_names, max_failures = SamplerTest.get_random_links(
            )
            netenv = NetworkEnvironment(links, k_failures=max_failures)

            max_num_samples = random.randint(0, 2 * netenv.num_concrete_envs)
            sampler = Sampler(netenv, max_num_samples=max_num_samples)
            correct_max_num_samples = min(max_num_samples,
                                          netenv.num_concrete_envs)

            self.assertEqual(sampler.max_num_samples, correct_max_num_samples)
示例#4
0
    def test_get_all_up(self):
        for _ in range(0, 1000):
            links, symbolic_link_names, max_failures = SamplerTest.get_random_links(
            )
            netenv = NetworkEnvironment(links, k_failures=max_failures)

            failed_links = [
                link.name for link in links if link.state == LinkState.DOWN
            ]
            all_up_env = ConcreteEnvironment.from_failed_links(
                links, failed_links)

            sampler = Sampler(netenv)

            self.assertEqual(sampler.get_all_up(), all_up_env)
示例#5
0
def build_network(backend, scenario_path, max_failures, waypoints_min, waypoints_fraction):
    topology_files = backend.get_topology()
    network = BackendTopologyBuilder.build_topology(topology_files, scenario_path)

    # get waypoints
    all_routers = network.nodes()
    num_waypoints = max(waypoints_min, int(len(all_routers) / waypoints_fraction))
    waypoints = random.sample(all_routers, num_waypoints)

    links = list()
    all_edges = network.get_undirected_edges()
    for i, edge in enumerate(all_edges):
        links.append(Link("l{id}".format(id=i), edge, LinkState.SYMBOLIC))

    # create the network environment
    netenv = NetworkEnvironment(links, k_failures=max_failures)

    return network, netenv, waypoints