예제 #1
0
def get_path_lengths(as_rel_file, target_asn):
    nx_graph = as_graph.parse_as_rel_file(as_rel_file)

    graph = ASGraph(nx_graph, policy=routing_policy.RPKIPolicy())
    print("Loaded graph")

    origin_id = int(target_asn)
    origin = graph.get_asys(origin_id)

    print(f"Determining reachability to AS {origin_id}")
    reachable_from = graph.determine_reachability_one(origin_id)
    total_asyss = len(graph.asyss)
    print(
        f"AS {origin_id} is reachable from {reachable_from} / {total_asyss} ASs"
    )

    print(f"Finding routes to AS {origin_id}")
    graph.find_routes_to(origin)

    path_lengths = {}
    for asys in graph.asyss.values():
        route = asys.get_route(origin.as_id)
        path_len = route.length if route else -1
        if path_len not in path_lengths:
            path_lengths[path_len] = 0
        path_lengths[path_len] += 1

    # Cross-check path routing results with reachability.
    assert path_lengths.get(-1, 0) + reachable_from == total_asyss

    for path_len, count in sorted(path_lengths.items()):
        print(f"path_length: {path_len}, count: {count}")
예제 #2
0
 def test_parse_as_rel_file(self):
     graph = as_graph.parse_as_rel_file(AS_REL_FILEPATH)
     for i in range(1, 14):
         assert i in graph.nodes
     assert graph.edges[(1, 2)]['customer'] == 2
     assert graph.edges[(2, 6)]['customer'] == 6
     assert graph.edges[(2, 3)]['customer'] is None
예제 #3
0
def generate(seed, trials, figure, as_rel_file, output_file):
    if seed is not None:
        random.seed(seed)

    nx_graph = as_graph.parse_as_rel_file(as_rel_file)
    print("Loaded graph")

    func = getattr(graphs, figure)
    func(output_file, nx_graph, trials)
예제 #4
0
    def test_check_for_customer_provider_cycles(self):
        nx_graph = as_graph.parse_as_rel_file(AS_REL_FILEPATH)
        graph = ASGraph(nx_graph)
        self.assertFalse(graph.any_customer_provider_cycles())

        # Create a customer-provider cycle
        nx_graph.add_edge(1, 6, customer=1)
        graph = ASGraph(nx_graph)
        self.assertTrue(graph.any_customer_provider_cycles())
예제 #5
0
    def test_learn_routes(self):
        graph = ASGraph(as_graph.parse_as_rel_file(AS_REL_FILEPATH))
        asys_8 = graph.get_asys(8)
        for asys in graph.asyss.values():
            graph.find_routes_to(asys_8)

        for asys in graph.asyss.values():
            assert 8 in asys.routing_table
            route = asys.routing_table[8]
            assert route.final == asys
예제 #6
0
def find_route(as_rel_file, origin_asn, final_asn):
    nx_graph = as_graph.parse_as_rel_file(as_rel_file)

    graph = ASGraph(nx_graph)
    print("Loaded graph")

    origin = graph.get_asys(origin_asn)
    final = graph.get_asys(final_asn)

    print(f"Finding routes to AS {origin_asn}")
    graph.find_routes_to(origin)

    print(final.routing_table.get(origin_asn, None))
예제 #7
0
def check_graph(as_rel_file):
    nx_graph = as_graph.parse_as_rel_file(as_rel_file)

    if not nx.is_connected(nx_graph):
        print("Graph is not fully connected!")
    else:
        print("Graph is fully connected")

    graph = ASGraph(nx_graph)
    print("Checking for customer-provider cycles")
    if graph.any_customer_provider_cycles():
        print("Graph has a customer-provider cycle!")
    else:
        print("Graph has no cycles")
예제 #8
0
 def test_ASGraph_constructor(self):
     graph = ASGraph(as_graph.parse_as_rel_file(AS_REL_FILEPATH))
     for i in range(1, 14):
         assert i in graph.asyss
     assert graph.get_asys(1).get_relation(
         graph.get_asys(2)) == Relation.CUSTOMER
     assert graph.get_asys(2).get_relation(
         graph.get_asys(1)) == Relation.PROVIDER
     assert graph.get_asys(2).get_relation(
         graph.get_asys(6)) == Relation.CUSTOMER
     assert graph.get_asys(6).get_relation(
         graph.get_asys(2)) == Relation.PROVIDER
     assert graph.get_asys(2).get_relation(
         graph.get_asys(3)) == Relation.PEER
     assert graph.get_asys(3).get_relation(
         graph.get_asys(2)) == Relation.PEER
예제 #9
0
def figure7b(filename: str, nx_graph: nx.Graph, n_trials: int):
    results = []
    attacks = get_attacks()

    for (label, filepath, as_rel_file) in attacks:
        nx_graph = as_graph.parse_as_rel_file(as_rel_file)
        print("Loaded graph for ", label)

        with open(filepath) as f:
            attackers = None
            targets = []
            # Expects 1 attacker, n victims, comments beginning with #
            for l in f:
                if l[0] == '#':
                    continue
                if attackers == None:
                    attackers = [int(l)]
                    continue
                targets.append(int(l))

        trials = list(itertools.product(targets, attackers))

        deployments = np.arange(0, 110, 10)

        attack_results = []
        for deployment in deployments:
            attack_results.append(
                fmean(experiments.figure7b(nx_graph, deployment, trials)))
        results.append(attack_results)
        print(label, attack_results)

    plt.figure(figsize=(10, 5))
    for i in range(len(results)):
        plt.plot(deployments, results[i], label=attacks[i][0])
    plt.legend()
    plt.xlabel("Deployment (top ISPs)")
    plt.ylabel("Attacker's Success Rate")
    plt.savefig(filename)