Frr_Config_Topo

Configure a network topology to function as a set of FRR routers.

Generate IP addresses, interface names, and FRR configurations for a topology and mark up the topology graph with the information.

Currently assumes all nodes run OSPF in one area.

annotate_graph(graph)

Annotate a topology with IP address for each node and IP address and interface names for each edge.

Source code in emulation/frr_config_topo.py
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
def annotate_graph(graph: networkx.Graph):
    '''
    Annotate a topology with IP address for each node and IP address and interface names
    for each edge.
    '''
    count = 1
    for node in graph.nodes.values():
        # Configure node with an ip address
        node["inf_count"] = 0
        node["number"] = count
        ip = 0x0A010000 + count
        count += 2
        node["ip"] = ipaddress.IPv4Interface((ip, 31))

    count = 1
    for edge in graph.edges.values():
        # Configure edge with a subnet
        edge["number"] = count
        ip = 0x0A0F0000 + count * 4
        count += 1
        edge["ip"] = ipaddress.IPv4Network((ip, 30))

    for n1, n2 in graph.edges:
        # Set ip addresses for each end of an edge
        edge = graph.edges[n1, n2]
        ips = list(edge["ip"].hosts())
        graph.adj[n1][n2]["ip"] = {}
        graph.adj[n1][n2]["ip"][n1] = ipaddress.IPv4Interface((ips[0].packed, 30))
        graph.adj[n2][n1]["ip"][n2] = ipaddress.IPv4Interface((ips[1].packed, 30))

        # Set interface names for each end of an edge
        c = graph.nodes[n1]["inf_count"] + 1
        graph.nodes[n1]["inf_count"] = c
        intf1 = f"{n1}-eth{c}"

        c = graph.nodes[n2]["inf_count"] + 1
        graph.nodes[n2]["inf_count"] = c
        intf2 = f"{n2}-eth{c}"

        graph.adj[n1][n2]["intf"] = {}
        graph.adj[n1][n2]["intf"][n1] = intf1
        graph.adj[n2][n1]["intf"][n2] = intf2

    # Generate config information for the satellites
    for name in torus_topo.satellites(graph):
        node = graph.nodes[name]
        node["ospf"] = create_ospf_config(graph, name)
        node["vtysh"] = create_vtysh_config(name)
        node["daemons"] = create_daemons_config()

    # Generate ip link pool information for the ground stations
    for name in torus_topo.ground_stations(graph):
        node = graph.nodes[name]
        uplinks = []
        for i in range(4):
            ip = 0x0A0F0000 + count * 4
            count += 1
            nw_link = ipaddress.IPv4Network((ip, 30))
            ips = list(nw_link.hosts())
            uplink = {"nw": nw_link,
                      "ip1": ipaddress.IPv4Interface((ips[0].packed, 30)),
                      "ip2": ipaddress.IPv4Interface((ips[1].packed, 30))}
            uplinks.append(uplink)
        node["uplinks"] = uplinks