コード例 #1
0
def main():
    scenario = Scenario()

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

    programm = "/root/libsrtp-2.3.0/test/rtpw"
    wordlist = "/root/libsrtp-2.3.0/test/words.txt"
    key = "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa"
    ip = "10.0.0.1"

    #srtp
    receiver_command = "{0} -e 128 -k {1} -r {2} 1111".format(programm,key,ip)
    sender_command = "{0} -e 128 -k {1} -w {2} -s {3} 1111".format(programm,key,wordlist,ip)

    #rtp
    #receiver_command = "{0} -r {1} 1111".format(programm,ip)
    #sender_command = "{0} -w {1} -s {2} 1111".format(programm,wordlist,ip)

    ports = dict()
    ports["1111"] = "1111/udp"
    print(receiver_command)
    print(sender_command)

    node1 = DockerNode('srtp-receiver', docker_build_dir='./docker/srtp', exposed_ports = ports, command=receiver_command)
    node2 = DockerNode('srtp-sender', docker_build_dir='./docker/srtp', command=sender_command)

    net.connect(node1, node2, delay='1000ms')

    scenario.add_network(net)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simulation_time parameter.
        sim.simulate(simulation_time=180)
コード例 #2
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,
                frequency=5860,
                channel_width=10,
                tx_power=18.0,
                standard=WiFiChannel.WiFiStandard.WIFI_802_11p,
                data_rate=WiFiChannel.WiFiDataRate.OFDM_RATE_BW_6Mbps)

    scenario.add_network(net)

    sumo = SUMOMobilityInput(name='Rail-To-X', sumo_port=8081)
    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 simulation_time parameter.
        sim.simulate(simulation_time=30)
コード例 #3
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 simulation_time parameter.
        sim.simulate(simulation_time=600)
コード例 #4
0
ファイル: wifi_example.py プロジェクト: Sofoca/marvis
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 simulation_time parameter.
        sim.simulate(simulation_time=180)
コード例 #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 simulation_time parameter.
        sim.simulate(simulation_time=60)
コード例 #6
0
def main():
    scenario = Scenario()

    net = Network('10.200.0.0', '255.255.255.0')

    ping = SSHNode('ping')
    pong = SSHNode('pong')
    net.connect(ping, pong, delay='150ms', speed='100Mbps')

    scenario.add_network(net)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simulation_time parameter.
        sim.simulate()
コード例 #7
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)
コード例 #8
0
ファイル: webserver_example.py プロジェクト: Sofoca/marvis
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 simulation_time parameter.
        sim.simulate(simulation_time=60)
コード例 #9
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0", base="0.0.0.2")
    net.block_ip_address("10.0.0.1")

    node1 = DockerNode('ping', docker_build_dir='./docker/ping')
    node2 = DockerNode('pong', docker_build_dir='./docker/pong')
    channel = net.create_channel(delay="10ms")
    channel.connect(node1, "10.0.0.17")
    channel.connect(node2)

    scenario.add_network(net)

    @scenario.workflow
    def increase_delay(workflow):
        workflow.sleep(60)
        net.set_delay("50ms")  # Inject a fault by increasing the delay to 50ms

    with scenario as sim:
        # To simulate forever, just do not specifiy the simulation_time parameter.
        sim.simulate(simulation_time=240)
コード例 #10
0
def main():

    scenario = Scenario()

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

    node1 = DockerNode('ping', docker_build_dir='./docker/ping')
    node1.color = (255, 0, 0)
    node1.position = (5, 5, 0)
    node2 = DockerNode('pong', docker_build_dir='./docker/pong')
    node2.color = (0, 255, 0)
    node2.position = (15, 5, 0)
    net.connect(node1, node2, delay='200ms')

    scenario.add_network(net)

    visualization = NetAnimVisualization()
    visualization.set_node_size(5.0)
    scenario.set_visualization(visualization)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simulation_time parameter.
        sim.simulate(simulation_time=60)
コード例 #11
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 simulation_time parameter.
        sim.simulate(simulation_time=60)
コード例 #12
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 simulation_time parameter.
        sim.simulate()