Exemplo n.º 1
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    node1 = DockerNode('ping',
                       docker_build_dir='./docker/ping',
                       command=["tail", "-f", "/dev/null"])
    node1.set_position(0, 50, 0)
    node2 = DockerNode('pong', docker_build_dir='./docker/pong')
    node2.set_position(5, 50, 0)
    # Also have a look at the WiFiChannel initializer. There are some more options you can configure.
    # E.g. the WiFi standard, transmit power and channel number can be set.
    net.connect(node1, node2, channel_type=WiFiChannel)

    scenario.add_network(net)

    @scenario.workflow
    def move_node(workflow):
        x = 10
        node2.go_offline()
        workflow.sleep(5)
        node2.go_online()
        while True:
            node2.set_position(x, 50, 0)
            x += 2
            workflow.sleep(2)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simluation_time parameter.
        sim.simulate(simluation_time=180)
Exemplo n.º 2
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    bridge = SwitchNode('br-1')

    server = DockerNode('server', docker_image='httpd:2.4')
    net.connect(server, bridge, delay='0', speed='1000Mbps')

    client1 = DockerNode('client-1',
                         docker_build_dir='./docker/curl-webserver',
                         cpus=0.5,
                         memory="128m")
    client2 = DockerNode('client-2',
                         docker_build_dir='./docker/curl-webserver',
                         cpus=0.5,
                         memory="128m")
    net.connect(client1, bridge, delay='50ms', speed='100Mbps')
    net.connect(client2, bridge, delay='20ms', speed='100Mbps')

    scenario.add_network(net)
    with scenario as sim:
        # To simulate forever, just do not specifiy the time parameter.
        sim.simulate(simluation_time=60)
Exemplo n.º 3
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    switch = DockerNode('switch',
                        docker_build_dir='./docker/sumo',
                        command="java FileServer")
    train = DockerNode('train',
                       docker_build_dir='./docker/sumo',
                       command="java FileClient")
    net.connect(train, switch, channel_type=WifiChannel, tx_power=30.0)

    scenario.add_network(net)

    sumo = SUMOMobilityInput(
        'sumo-gui',
        'docker/sumo/scenarios/scenario4/scenario.sumocfg',
        name='Rail-To-X')
    sumo.add_node_to_mapping(switch, 'n0', obj_type='junction')
    sumo.add_node_to_mapping(train, 'train')

    scenario.add_mobility_input(sumo)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simluation_time parameter.
        sim.simulate(simluation_time=30)
Exemplo n.º 4
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    bridge = SwitchNode('br-1')

    validator1 = DockerNode('validator1', docker_build_dir='./docker',
                            dockerfile='sawtooth-pbft/validator/Dockerfile',
                            exposed_ports={8008:8008}, volumes=volumes_for_validator(1),
                            command=['sawtooth-validator', '-v', '-E', 'tcp://validator1:8800'])
    net.connect(validator1, bridge, delay='5ms', speed='100Mbps')

    validator2 = DockerNode('validator2', docker_build_dir='./docker',
                            dockerfile='sawtooth-pbft/validator/Dockerfile',
                            volumes=volumes_for_validator(2),
                            command=['sawtooth-validator', '-v', '-E', 'tcp://validator2:8800'])
    net.connect(validator2, bridge, delay='5ms', speed='100Mbps')

    validator3 = DockerNode('validator3', docker_build_dir='./docker',
                            dockerfile='sawtooth-pbft/validator/Dockerfile',
                            volumes=volumes_for_validator(3),
                            command='sawtooth-validator -v -E tcp://validator3:8800')
    net.connect(validator3, bridge, delay='5ms', speed='100Mbps')

    validator4 = DockerNode('validator4', docker_build_dir='./docker',
                            dockerfile='sawtooth-pbft/validator/Dockerfile',
                            volumes=volumes_for_validator(4),
                            command='sawtooth-validator -v -E tcp://validator4:8800')
    net.connect(validator4, bridge, delay='5ms', speed='100Mbps')

    scenario.add_network(net)
    with scenario as sim:
        # To simulate forever, just do not specifiy the time parameter.
        sim.simulate(simluation_time=600)
Exemplo n.º 5
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    node1 = DockerNode('ping', docker_build_dir='./docker/ping')
    node2 = DockerNode('pong', docker_build_dir='./docker/pong')
    net.connect(node1, node2, delay='200ms')

    scenario.add_network(net)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simluation_time parameter.
        sim.simulate(simluation_time=60)
Exemplo n.º 6
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    node1 = DockerNode('ping', docker_build_dir='./docker/ping')
    node2 = SwitchNode('bridge-1')
    node3 = DockerNode('pong', docker_build_dir='./docker/pong')
    net.connect(node1, node2, delay='200ms')
    net.connect(node2, node3, delay='200ms')

    scenario.add_network(net)
    with scenario as sim:
        sim.simulate(simluation_time=60)
Exemplo n.º 7
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    bridge = SwitchNode('br-1')

    script_directory = os.path.dirname(os.path.realpath(__file__))
    htdocs_directory = os.path.join(script_directory,
                                    '../docker/curl-webserver/htdocs')
    # Always specify absolute paths. You can also set 'rw' as mode.
    # If you are lazy, you can also give `{htdocs_directory: '/usr/local/apache2/htdocs'}`, which
    # automatically mounts it as read-write.
    server_volumes = {
        htdocs_directory: {
            'bind': '/usr/local/apache2/htdocs',
            'mode': 'ro'
        }
    }

    # Using ports: The first value (key) is the internal port in the container.
    # You can also restrict the ip: {'80/tcp': ('127.0.0.1', 8080)}
    # or use multiple ports {'80/tcp': [8080, 80]}
    # Please check whether your container / server is configured correctly to accept
    # requests on all IPs because there are different IPs for NS-3 and the connection
    # to the host!
    ports = {80: 8080}

    server = DockerNode('server',
                        docker_image='httpd:2.4',
                        volumes=server_volumes,
                        exposed_ports=ports)
    net.connect(server, bridge, delay='0', speed='1000Mbps')

    client1 = DockerNode('client-1',
                         docker_build_dir='./docker/curl-webserver',
                         cpus=0.5,
                         memory="128m")
    client2 = DockerNode('client-2',
                         docker_build_dir='./docker/curl-webserver',
                         cpus=0.5,
                         memory="128m")
    net.connect(client1, bridge, delay='50ms', speed='100Mbps')
    net.connect(client2, bridge, delay='20ms', speed='100Mbps')

    scenario.add_network(net)
    with scenario as sim:
        # To simulate forever, just do not specifiy the time parameter.
        sim.simulate(simluation_time=60)
Exemplo n.º 8
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    bridge = SwitchNode('br-1')

    server = DockerNode('server', docker_image='httpd:2.4')
    net.connect(server, bridge, delay='0', speed='1000Mbps')

    client1 = DockerNode('client-1',
                         docker_build_dir='./docker/curl-webserver',
                         cpus=0.5,
                         memory="128m")
    client2 = DockerNode('client-2',
                         docker_build_dir='./docker/curl-webserver',
                         cpus=0.5,
                         memory="128m")
    net.connect(client1, bridge, delay='50ms', speed='100Mbps')
    net.connect(client2, bridge, delay='20ms', speed='100Mbps')

    example = Example()

    @scenario.workflow
    def test(workflow):
        workflow.wait_until(lambda: example.some_value, 6, globals(), locals())
        server.go_offline()
        workflow.sleep(10)
        server.go_online()

    @scenario.workflow
    def test2(workflow):
        workflow.sleep(10)
        client1.execute_command('curl server -v')
        example.some_value = 42

    scenario.add_network(net)
    with scenario as sim:
        # To simulate forever, just do not specifiy the time parameter.
        sim.simulate(simluation_time=60)
Exemplo n.º 9
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0")

    bridge = SwitchNode('br-1')

    validator = DockerNode('validator',
                           docker_build_dir='./docker/sawtooth',
                           dockerfile='validator.Dockerfile')
    net.connect(validator, bridge, delay='0', speed='1000Mbps')

    settings_tp = DockerNode('set-tp',
                             docker_build_dir='./docker/sawtooth',
                             dockerfile='settings-tp.Dockerfile')
    net.connect(settings_tp, bridge, delay='0', speed='1000Mbps')

    intkey_tp = DockerNode('intkey',
                           docker_build_dir='./docker/sawtooth',
                           dockerfile='intkey-tp.Dockerfile')
    net.connect(intkey_tp, bridge, delay='0', speed='1000Mbps')

    rest_api = DockerNode('rest-api',
                          docker_build_dir='./docker/sawtooth',
                          dockerfile='rest-api.Dockerfile')
    net.connect(rest_api, bridge, delay='0', speed='1000Mbps')

    shell = DockerNode('shell',
                       docker_build_dir='./docker/sawtooth',
                       dockerfile='shell.Dockerfile')
    net.connect(shell, bridge, delay='0', speed='1000Mbps')

    scenario.add_network(net)
    with scenario as sim:
        # To simulate forever, just do not specifiy the time parameter.
        sim.simulate()