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)
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()
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)
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)
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)
def main(): scenario = Scenario() net = Network("10.0.0.0", "255.255.255.0") node1 = DockerNode('pong', docker_build_dir='./docker/pong') node2 = SwitchNode('bridge-1') node3 = SSHNode('ping', '10.243.42.11') net.connect(node1, node2, delay='200ms') net.connect(node2, node3, 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)