Test Function From torus_topo.py

Create a torus network of the given size annotated with orbital information.

Source code in emulation/torus_topo.py
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
def create_network(num_rings: int =NUM_RINGS, num_ring_nodes: int =NUM_RING_NODES, ground_stations: bool = True) -> networkx.Graph:
    '''
    Create a torus network of the given size annotated with orbital information.
    '''
    graph: networkx.Graph = networkx.Graph()
    graph.graph["rings"] = num_rings
    graph.graph["ring_nodes"] = num_ring_nodes
    graph.graph["ring_list"] = []
    graph.graph["inclination"] = 53.9
    prev_ring_num = None
    for ring_num in range(num_rings):
        create_ring(graph, ring_num, num_ring_nodes)
        if prev_ring_num is not None:
            connect_rings(graph, prev_ring_num, ring_num, num_ring_nodes)
        prev_ring_num = ring_num
    if prev_ring_num is not None:
        connect_rings(graph, prev_ring_num, 0, num_ring_nodes)

    if ground_stations:
        add_ground_stations(graph)

    # Set all edges to up
    for edge_name, edge in graph.edges.items():
        edge["up"] = True
    return graph

Test Function From run_mn.py

Configure DNS for all nodes in the network by updating /etc/hosts in each node's namespace. Include interface IPs with descriptive names.

Source code in emulation/mnet/run_mn.py
 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
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
def configure_dns(net, graph):
    '''
    Configure DNS for all nodes in the network by updating /etc/hosts
    in each node's namespace. Include interface IPs with descriptive names.
    '''
    # First, collect all IP addresses and hostnames
    hosts_entries = []

    # Add satellite nodes loopback addresses
    for name in torus_topo.satellites(graph):
        node = graph.nodes[name]
        if "ip" in node:
            hosts_entries.append(f"{format(node['ip'].ip)}\t{name}")

        # Add interface IPs with descriptive names
        for neighbor in graph.adj[name]:
            edge = graph.adj[name][neighbor]
            local_ip = edge["ip"][name]
            remote_ip = edge["ip"][neighbor]
            local_intf = edge["intf"][name]
            remote_intf = edge["intf"][neighbor]

            # Add entries for both local and remote interfaces
            # Format: IP    devicename-intf devicename-TO-neighborname
            hosts_entries.append(f"{format(local_ip.ip)}\t{local_intf} {name}-TO-{neighbor}")
            hosts_entries.append(f"{format(remote_ip.ip)}\t{remote_intf} {neighbor}-TO-{name}")

    # Add ground stations
    for name in torus_topo.ground_stations(graph):
        node = graph.nodes[name]
        if "ip" in node:
            hosts_entries.append(f"{format(node['ip'].ip)}\t{name}")

    # Create hosts file content
    hosts_content = "\n".join([
        "127.0.0.1\tlocalhost",
        "::1\tlocalhost ip6-localhost ip6-loopback",
        "fe00::0\tip6-localnet",
        "ff00::0\tip6-mcastprefix",
        "ff02::1\tip6-allnodes",
        "ff02::2\tip6-allrouters",
        "\n# Network hosts",
        *hosts_entries
    ])

    # Update /etc/hosts in each node's namespace
    for node in net.hosts:
        # Create a temporary hosts file
        with open('/tmp/hosts.temp', 'w') as f:
            f.write(hosts_content)

        # Copy the file to the node's namespace
        node.cmd(f'mkdir -p /etc/netns/{node.name}')
        node.cmd(f'cp /tmp/hosts.temp /etc/netns/{node.name}/hosts')

        # Also update the current namespace's hosts file
        node.cmd('cp /tmp/hosts.temp /etc/hosts')

        # Clean up
        node.cmd('rm /tmp/hosts.temp')

        # Configure resolv.conf to use the hosts file
        resolv_content = "nameserver 127.0.0.1\nsearch mininet"
        node.cmd(f'echo "{resolv_content}" > /etc/netns/{node.name}/resolv.conf')
        node.cmd(f'echo "{resolv_content}" > /etc/resolv.conf')