示例#1
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')
    channel_server = net.create_channel(data_rate="1000Mbps")
    channel_server.connect(server)
    channel_server.connect(bridge)

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

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

    scenario.add_network(net)
    with scenario as sim:
        # To simulate forever, do not specify the simulation_time parameter.
        sim.simulate(simulation_time=60)
示例#2
0
def main():
    scenario = Scenario()

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

    node1 = DockerNode('ping', docker_build_dir='./docker/ping')
    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.
    channel = net.create_channel()
    channel.connect(node1)
    channel.connect(node2)

    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)
def main():

    logger = getLogger('scenario')

    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')
    channel = net.create_channel()

    server_a = DockerNode(
        'server_a',
        docker_build_dir='./docker/fault-tolerant-app/temperature-server')
    channel.connect(server_a)

    server_b = DockerNode(
        'server_b',
        docker_build_dir='./docker/fault-tolerant-app/temperature-server')
    channel.connect(server_b)

    voter = DockerNode(
        'voter',
        docker_build_dir='./docker/fault-tolerant-app/temperature-voter')
    channel.connect(voter)

    scenario.add_network(net)

    @scenario.workflow
    def on_and_off(workflow):

        # disconnect servers intermittently
        workflow.sleep(5)
        logger.info('disconnecting temperature server a')
        server_a.go_offline()
        workflow.sleep(5)
        logger.info('disconnecting temperature server b')
        server_b.go_offline()
        workflow.sleep(5)
        logger.info('reconnecting temperature servers')
        server_a.go_online()
        server_b.go_online()

        # introduce a network delay
        workflow.sleep(5)
        logger.info('setting network delay higher than check interval')
        channel.set_delay("1100ms")
        workflow.sleep(5)
        logger.info('removing network delay')
        channel.set_delay("0ms")

    with scenario as sim:
        sim.simulate(simulation_time=30)
示例#4
0
def main():
    scenario = Scenario()

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

    node1 = DockerNode('ping', docker_build_dir='./docker/ping')
    node2 = LXDNode('pong', image='alpine/3.10')
    channel = net.create_channel(delay="200ms")
    channel.connect(node1)
    channel.connect(node2)

    scenario.add_network(net)

    with scenario as sim:
        # To simulate forever, do not specify the simulation_time parameter.
        sim.simulate()
示例#5
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')
    channel_server = net.create_channel(data_rate="1000Mbps")
    channel_server.connect(server)
    channel_server.connect(bridge)

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

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

    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 = 6

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

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

    ping = SSHNode('ping')
    pong = SSHNode('pong')

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

    scenario.add_network(net)

    with scenario as sim:
        # To simulate forever, do not specify the simulation_time parameter.
        sim.simulate()
示例#7
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="200ms")
    channel.connect(node1, "10.0.0.17")
    channel.connect(node2)

    scenario.add_network(net)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simulation_time parameter.
        sim.simulate(simulation_time=60)
示例#8
0
def main():
    scenario = Scenario()

    net = Network("10.0.0.0", "255.255.255.0", delay="200ms")

    node1 = DockerNode('pong', docker_build_dir='./docker/pong')
    node2 = SwitchNode('bridge-1')
    node3 = SSHNode('ping', '10.243.42.11')

    channel1 = net.create_channel("channel1")
    channel1.connect(node1)
    channel1.connect(node2)
    channel2 = net.create_channel("channel2")
    channel2.connect(node2)
    channel2.connect(node3)

    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")

    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)
    channel = net.create_channel()
    channel.connect(node1, "10.0.0.17")
    channel.connect(node2)

    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)
示例#10
0
def main():
    scenario = Scenario()

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

    switch = DockerNode('switch',
                        docker_build_dir='./docker/sumo',
                        command="java FileServer")
    train = DockerNode('train',
                       docker_build_dir='./docker/sumo',
                       command="java FileClient")
    channel = net.create_channel(
        frequency=5860,
        channel_width=10,
        tx_power=18.0,
        standard=WiFiChannel.WiFiStandard.WIFI_802_11p,
        data_rate=WiFiChannel.WiFiDataRate.OFDM_RATE_BW_6Mbps)
    channel.connect(train)
    channel.connect(switch)

    scenario.add_network(net)

    sumo = SUMOMobilityInput(sumo_host='localhost', sumo_port=8813)
    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, do not specify the simulation_time parameter.
        sim.simulate(simulation_time=30)
示例#11
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, do not specify the simulation_time parameter.
        sim.simulate(simulation_time=240)
示例#12
0
def main():
    scenario = Scenario()

    simulation_time = 1 * 3600  # in seconds

    net = Network("10.0.0.0",
                  "255.255.255.0",
                  default_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)

    bridge = SwitchNode('br-1')

    n1 = DockerNode('n1',
                    docker_build_dir='./docker/wntr',
                    command='python3 test_code.py --node_name n1')
    n4 = DockerNode('n4',
                    docker_build_dir='./docker/wntr',
                    command='python3 test_code.py --node_name n4')
    server = DockerNode('server', docker_image='httpd:2.4')

    channel_sb = net.create_channel()
    channel_sb.connect(server)
    channel_sb.connect(bridge)

    channel_1b = net.create_channel()
    channel_1b.connect(n1)
    channel_1b.connect(bridge)

    channel_2b = net.create_channel()
    channel_2b.connect(n4)
    channel_2b.connect(bridge)

    scenario.add_network(net)

    pressure_sensors = [
        'n1', 'n4', 'n31', 'n54', 'n105', 'n114', 'n163', 'n188', 'n215',
        'n229', 'n288', 'n296', 'n332', 'n342', 'n410', 'n415', 'n429', 'n458',
        'n469', 'n495', 'n506', 'n516', 'n519', 'n549', 'n613', 'n636', 'n644',
        'n679', 'n722', 'n726', 'n740', 'n752', 'n769'
    ]

    # wn = WNTRMobilityInput(duration=simulation_time, inp_path='docker/wntr/scenario/L-TOWN.inp', step_length=60)
    wn = wntr.network.WaterNetworkModel('docker/wntr/scenario/L-TOWN.inp')
    sim = wntr.sim.EpanetSimulator(wn)
    results = sim.run_sim()
    for node in scenario.nodes():
        node_pressure = results.node['pressure'].loc[:, node.name]
        node_pressure.to_csv('docker/wntr/filetransfer/' + node.name + '.csv')

    # wntr.add_node_to_mapping(n1, 'n1', 'junction')
    # wntr.add_node_to_mapping(n2, 'n4', 'junction')

    # scenario.add_mobility_input(wntr)

    with scenario as sim:
        # To simulate forever, just do not specifiy the simulation_time parameter.
        sim.simulate(simulation_time=simulation_time)