Ejemplo n.º 1
0
def main():
    parser = ArgumentParser()
    parser.add_argument("lab_path", type=str, help='path to the lab directory')
    args = parser.parse_args()

    main_net = Network('15.0.0.0/8')

    size = 3

    core = main_net.generate_nodes('core_', size)
    nodes = main_net.generate_nodes('n', size * 2, image='kademlia')

    main_net.create_subnet('core_net', core)

    for i in range(len(core)):
        main_net.create_subnet('radial_' + str(i),
                               (core[i], nodes[2 * i], nodes[2 * i + 1]))

    main_net.create_overlay(Overlay.RIP, 'RIP_1', core)

    main_net.configure(verbose=True)

    for node in nodes[1:]:
        node.add_options(environment={'KADEMLIA_ARGS': nodes[0].get_ip()})

    main_net.render(args.lab_path, verbose=True)
Ejemplo n.º 2
0
def main():
    net = Network('15.0.0.0/8')

    # create network nodes that will represent client and server
    server = net.create_node('server',
                             image='madt/docker_compose',
                             enable_internet=True,
                             privileged=True)
    clients = net.generate_nodes('client',
                                 6,
                                 image='madt/pyget',
                                 environment={"SERVER": 'whoami.local'})

    with open('docker-compose.yml') as docker_compose_yml_file:
        server.add_dir('.', '/app')

    # create a local network that will connect all those nodes
    routers = net.generate_nodes('router', 3)
    net.create_subnet('subnet1', (routers[0], *clients[:3]))
    net.create_subnet('subnet2', (routers[1], *clients[3:]))
    net.create_subnet('subnet3', routers)
    net.create_subnet('subnet4', (routers[2], server))

    net.create_overlay(Overlay.RIP, 'RIP', routers)

    # distribute IP addresses
    net.configure(verbose=True)
    # pass server IP to the clients
    for client in clients:
        client.add_options(extra_hosts={'whoami.local': server.get_ip()})
    # save lab
    net.render('../../labs/compose', verbose=True)
Ejemplo n.º 3
0
def main():
    parser = ArgumentParser()
    parser.add_argument("lab_path", type=str, help='path to the lab directory')
    args = parser.parse_args()

    global subnets

    # Define network
    net = Network('15.0.0.0/8')

    # Create initial outer nodes and a subnet
    outer_nodes = [
        *net.generate_nodes('core_', children),
    ]
    net.create_subnet('core', outer_nodes)

    # Iteratively create other nodes
    for i in range(iterations):
        new_outer_nodes = []

        for node in outer_nodes:
            idx = outer_nodes.index(node) + 1

            new_nodes = net.generate_nodes('L{0}_N{1}_'.format(i, idx),
                                           children)
            net.create_subnet('L{0}_D{1}'.format(i, idx), (node, *new_nodes))
            subnets += 1

            new_outer_nodes.extend(new_nodes)

        central_nodes.extend(outer_nodes)
        outer_nodes = new_outer_nodes

    # OSPF - Open Shortest Path First
    net.create_overlay(Overlay.OSPF, 'OSPF', central_nodes)

    # Setup the node docker image
    for node in outer_nodes:
        node.image = 'kademlia'

    net.configure(verbose=True)

    for node in outer_nodes[1:]:
        node.add_options(
            environment={'KADEMLIA_ARGS': outer_nodes[0].get_ip()})

    net.render(args.lab_path, verbose=True)

    print('NET SIZE: ', len(central_nodes) + len(outer_nodes))
    print('SUBNETS: ', subnets)
Ejemplo n.º 4
0
def main():
    parser = ArgumentParser()
    parser.add_argument("lab_path", type=str, help='path to the lab directory')
    args = parser.parse_args()

    net = Network('15.0.0.0/8')

    routers = net.generate_nodes('r', 3)
    net.create_subnet('core', routers)

    for idx, router in enumerate(routers):
        n = net.create_node('n' + str(idx + 1))
        net.create_subnet('net' + str(idx + 1), (router, n))

        n.add_file('/me.txt', 'IM NODE #' + str(idx))

    net.create_overlay(Overlay.RIP, 'RIP', routers)
    net.render(args.lab_path, verbose=True)
Ejemplo n.º 5
0
def main():
    madt = Network('15.0.0.0/8')
    # create network nodes that will represent client and server
    server = madt.create_node('server', image='madt/nginx')
    clients = madt.generate_nodes('client', 1, image='madt/pyget')
    # create a local network that will connect all those nodes
    routers = madt.generate_nodes('ospfr', 2)
    madt.create_subnet('subnet1', (routers[0], clients[0]))
    #madt.create_subnet('subnet2', (routers[1], *clients[3:]))
    madt.create_subnet('subnet3', routers)
    madt.create_subnet('subnet4', (routers[1], server))

    madt.create_overlay(Overlay.OSPF, 'OSPF', routers)

    # distribute IP addresses
    madt.configure(verbose=True)
    # pass server IP to the clients
    for client in clients:
        client.add_options(environment={'SERVER': server.get_ip()})
    # save lab
    madt.render('../../labs/monitoring', verbose=True)
Ejemplo n.º 6
0
def main():
    madt = Network('15.0.0.0/8')

    server = madt.create_node('server', image='madt/nginx')
    clients = madt.generate_nodes(
        'client',
        6,
        image='inutano/wget',
        entrypoint=
        'sh -c "while true; do wget -O - -T 3 $SERVER; sleep 1; done"')

    routers = madt.generate_nodes('router', 3)
    madt.create_subnet('subnet1', (routers[0], *clients[:3]))
    madt.create_subnet('subnet2', (routers[1], *clients[3:]))
    madt.create_subnet('subnet3', routers)
    madt.create_subnet('subnet4', (routers[2], server))

    madt.create_overlay(Overlay.RIP, 'RIP', routers)

    madt.configure(verbose=True)
    for client in clients:
        client.add_options(environment={'SERVER': server.get_ip()})
    madt.render('../../labs/dynamic_routing', verbose=True)
Ejemplo n.º 7
0
def main():
    parser = ArgumentParser()
    parser.add_argument("lab_path", type=str, help='path to the lab directory')
    args = parser.parse_args()

    main_net = Network('15.0.0.0/8')

    core = main_net.generate_nodes('core_', 3)
    routers = main_net.generate_nodes('r', 2)
    ospf_routers = main_net.generate_nodes('ospfr', 2)
    nodes = main_net.generate_nodes('n', 11, image='kademlia')

    gateway = main_net.create_node('gateway')

    main_net.make_mesh(core)  # WAS IT DEPRECATED?
    # make subnets connecting each pair of nodes
    main_net.make_mesh((core[0], *routers))  # WAS IT DEPRECATED?

    main_net.create_subnet('ospf_1', (ospf_routers[0], core[2]))
    main_net.create_subnet('ospf_2', (ospf_routers[1], core[2]))

    main_net.create_subnet('lc1', (*nodes[:2], routers[0]))
    main_net.create_subnet('lc2', (*nodes[2:4], routers[1], gateway))
    main_net.create_subnet('lc3', (*nodes[4:7], core[1]))
    main_net.create_subnet('lc4', (*nodes[7:9], ospf_routers[0]))
    main_net.create_subnet('lc5', (*nodes[9:], ospf_routers[1]))

    main_net.create_overlay(Overlay.RIP, 'RIP_1', (core[0], *routers))

    main_net.create_overlay(Overlay.OSPF, 'OSPF_1', (core[2], *ospf_routers))

    main_net.create_overlay(
        Overlay.BGP, 'big_boi',
        [[*nodes[:4], *routers, gateway, core[0]], [*nodes[4:7], core[1]],
         [*nodes[7:], *ospf_routers, core[2]]])

    local_net = main_net.create_local_network(gateway)

    local_routers = local_net.generate_nodes('lan_router', 2)
    local_net.create_subnet('LAN0', (*local_routers, gateway))

    for idx, r in enumerate(local_routers):
        node = local_net.create_node('lan_node' + str(idx + 1),
                                     image='kademlia')
        local_net.create_subnet('LAN' + str(idx + 1), (node, r))
        nodes.append(node)

    local_net.create_overlay(Overlay.RIP, 'RIP_1', local_routers)

    main_net.configure(verbose=True)

    for node in nodes[1:]:
        node.add_options(environment={'KADEMLIA_ARGS': nodes[0].get_ip()})

    main_net.render(args.lab_path, verbose=True)
Ejemplo n.º 8
0
def main():
    parser = ArgumentParser()
    parser.add_argument("lab_path", type=str, help='path to the lab directory')
    args = parser.parse_args()

    net = Network('15.0.0.0/8')

    core = net.generate_nodes('core_', 3)
    routers = net.generate_nodes('r', 2)
    ospf_routers = net.generate_nodes('ospfr', 2)
    nodes = net.generate_nodes('n', 11, image='kademlia')

    net.make_mesh(core) # WAS IT DEPRECATED?

    # make subnets connecting each pair of nodes
    net.make_mesh((core[0], *routers)) # WAS IT DEPRECATED?

    net.create_subnet('ospf_1', (ospf_routers[0], core[2]))
    net.create_subnet('ospf_2', (ospf_routers[1], core[2]))

    net.create_subnet('lc1', (*nodes[:2], routers[0]))
    net.create_subnet('lc2', (*nodes[2:4], routers[1]))
    net.create_subnet('lc3', (*nodes[4:7], core[1]))
    net.create_subnet('lc4', (*nodes[7:9], ospf_routers[0]))
    net.create_subnet('lc5', (*nodes[9:], ospf_routers[1]))

    net.create_overlay(Overlay.RIP, 'RIP_1', (core[0], *routers))

    net.create_overlay(Overlay.OSPF, 'OSPF_1', (core[2], *ospf_routers))

    net.create_overlay(Overlay.BGP, 'big_boi', [
        [*nodes[:4], *routers, core[0]], [*nodes[4:7], core[1]], [*nodes[7:], *ospf_routers, core[2]]
    ])

    net.configure(verbose=True)

    for node in nodes[1:]:
        node.add_options(environment={'KADEMLIA_ARGS': nodes[0].get_ip()})

    net.render(args.lab_path, verbose=True)
Ejemplo n.º 9
0
from madt_lib.network import Network, Overlay
kt = Network('15.0.0.0/8')
# create network nodes that will represent client and server
server = kt.create_node('server', image='madt/nginx')
clients = kt.generate_nodes('client', 6, image='madt/pyget')
# create a local network that will connect all those nodes
routers = kt.generate_nodes('router', 3)
kt.create_subnet('subnet1', (routers[0], *clients[:3]))
kt.create_subnet('subnet2', (routers[1], *clients[3:]))
kt.create_subnet('subnet3', routers)
kt.create_subnet('subnet4', (routers[2], server))

kt.create_overlay(Overlay.RIP, 'RIP', routers)

# distribute IP addresses
kt.configure(verbose=True)
# pass server IP to the clients
for client in clients:
    client.add_options(environment={'SERVER': server.get_ip()})
# save lab
kt.render('/home/demo/labs/monitoring', verbose=True)
Ejemplo n.º 10
0
nodes = net.generate_nodes('n', 11, image='kademlia')

net.make_mesh(core)

# make subnets connecting each pair of nodes
net.make_mesh((core[0], *routers))

net.create_subnet('ospf_1', (ospf_routers[0], core[2]))
net.create_subnet('ospf_2', (ospf_routers[1], core[2]))

net.create_subnet('lc1', (*nodes[:2], routers[0]))
net.create_subnet('lc2', (*nodes[2:4], routers[1]))
net.create_subnet('lc3', (*nodes[4:7], core[1]))
net.create_subnet('lc4', (*nodes[7:9], ospf_routers[0]))
net.create_subnet('lc5', (*nodes[9:], ospf_routers[1]))

net.create_overlay(Overlay.RIP, 'RIP_1', (core[0], *routers))

net.create_overlay(Overlay.OSPF, 'OSPF_1', (core[2], *ospf_routers))

net.create_overlay(Overlay.BGP, 'big_boi',
                   [[*nodes[:4], *routers, core[0]], [*nodes[4:7], core[1]],
                    [*nodes[7:], *ospf_routers, core[2]]])

net.configure(verbose=True)

for n in nodes[1:]:
    n.add_options(environment={'KADEMLIA_ARGS': nodes[0].get_ip()})

net.render(sys.argv[1], verbose=True)