X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=test%2Fresources%2Flinux%2Fns3%2Fns3simulation.py;h=1b3b7cb20d656c250a72ec156e95e33bf3d712ae;hb=e55924b6886bd7382a28e1ae235c4810f852e163;hp=9817ce9450664d940cd049b86c383e3a887755ea;hpb=1e77723c376f90f713798fc03deef740b25737b4;p=nepi.git diff --git a/test/resources/linux/ns3/ns3simulation.py b/test/resources/linux/ns3/ns3simulation.py old mode 100644 new mode 100755 index 9817ce94..1b3b7cb2 --- a/test/resources/linux/ns3/ns3simulation.py +++ b/test/resources/linux/ns3/ns3simulation.py @@ -4,9 +4,8 @@ # Copyright (C) 2013 INRIA # # This program is free software: you can redistribute it and/or modify -# it under the terms of the GNU General Public License as published by -# the Free Software Foundation, either version 3 of the License, or -# (at your option) any later version. +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation; # # This program is distributed in the hope that it will be useful, # but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -18,20 +17,11 @@ # # Author: Alina Quereilhac - -# -# Network topology -# -# n0 n1 n2 n3 -# | | | | -# ----------------- -# -# node n0 sends IGMP traffic to node n3 - - from nepi.execution.ec import ExperimentController from nepi.execution.trace import TraceAttr +from test_utils import skipIfNotAlive + import os import time import unittest @@ -54,12 +44,10 @@ def add_ns3_node(ec, simu): return node -def add_point2point_device(ec, node, address = None, prefix = None): +def add_point2point_device(ec, node, ip, prefix): dev = ec.register_resource("ns3::PointToPointNetDevice") - if address: - ec.set(dev, "ip", address) - if prefix: - ec.set(dev, "prefix", prefix) + ec.set(dev, "ip", ip) + ec.set(dev, "prefix", prefix) ec.register_connection(node, dev) queue = ec.register_resource("ns3::DropTailQueue") @@ -67,12 +55,10 @@ def add_point2point_device(ec, node, address = None, prefix = None): return dev -def add_csma_device(ec, node, address = None, prefix = None): +def add_csma_device(ec, node, ip, prefix): dev = ec.register_resource("ns3::CsmaNetDevice") - if address: - ec.set(dev, "ip", address) - if prefix: - ec.set(dev, "prefix", prefix) + ec.set(dev, "ip", ip) + ec.set(dev, "prefix", prefix) ec.register_connection(node, dev) queue = ec.register_resource("ns3::DropTailQueue") @@ -80,13 +66,11 @@ def add_csma_device(ec, node, address = None, prefix = None): return dev -def add_wifi_device(ec, node, address = None, prefix = None, +def add_wifi_device(ec, node, ip, prefix, access_point = False): dev = ec.register_resource("ns3::WifiNetDevice") - if address: - ec.set(dev, "ip", address) - if prefix: - ec.set(dev, "prefix", prefix) + ec.set(dev, "ip", ip) + ec.set(dev, "prefix", prefix) ec.register_connection(node, dev) phy = ec.register_resource("ns3::YansWifiPhy") @@ -141,68 +125,28 @@ def add_wifi_channel(ec): return channel -class LinuxNS3ClientTest(unittest.TestCase): +class LinuxNS3SimulationTest(unittest.TestCase): def setUp(self): - #self.fedora_host = "nepi2.pl.sophia.inria.fr" - self.fedora_host = "planetlabpc1.upf.edu" - #self.fedora_host = "peeramide.irisa.fr" - #self.fedora_user = "inria_nepi" - self.fedora_user = "inria_alina" + self.fedora_host = "nepi2.pl.sophia.inria.fr" + self.fedora_user = "inria_nepi" self.fedora_identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME']) - def test_local_p2p_ping(self): - ec = ExperimentController(exp_id = "test-ns3-local-p2p") - - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", "localhost") - - simu = ec.register_resource("LinuxNS3Simulation") - ec.set(simu, "verbose", True) - ec.register_connection(simu, node) - - nsnode1 = add_ns3_node(ec, simu) - dev1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30") - - nsnode2 = add_ns3_node(ec, simu) - dev2 = add_point2point_device(ec, nsnode2, "10.0.0.2", "30") - - # Create channel - chan = ec.register_resource("ns3::PointToPointChannel") - ec.set(chan, "Delay", "0s") - ec.register_connection(chan, dev1) - ec.register_connection(chan, dev2) - - ### create pinger - ping = ec.register_resource("ns3::V4Ping") - ec.set (ping, "Remote", "10.0.0.2") - ec.set (ping, "Interval", "1s") - ec.set (ping, "Verbose", True) - ec.set (ping, "StartTime", "0s") - ec.set (ping, "StopTime", "20s") - ec.register_connection(ping, nsnode1) - - ec.deploy() - - ec.wait_finished([ping]) - - stdout = ec.trace(simu, "stdout") - - expected = "20 packets transmitted, 20 received, 0% packet loss" - self.assertTrue(stdout.find(expected) > -1) - - ec.shutdown() - - def test_simple_p2p_ping(self): + @skipIfNotAlive + def t_p2p_ping(self, host, user = None, identity = None): ec = ExperimentController(exp_id = "test-ns3-p2p-ping") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) ec.register_connection(simu, node) @@ -238,17 +182,22 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_simple_cmsa_ping(self): + @skipIfNotAlive + def t_csma_ping(self, host, user = None, identity = None): ec = ExperimentController(exp_id = "test-ns3-csma-ping") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) ec.register_connection(simu, node) @@ -284,21 +233,27 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_compile_local_source(self): - ec = ExperimentController(exp_id = "test-ns3-local-source") + @skipIfNotAlive + def t_user_sources(self, host, user = None, identity = None): + ec = ExperimentController(exp_id = "test-ns3-user-sources") + + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) sources = os.path.join(os.path.dirname(os.path.realpath(__file__)), "ns-3.18-user.tar.gz") ec.set(simu, "sources", sources) + ec.set(simu, "pybindgenVersion", "834") ec.register_connection(simu, node) nsnode1 = add_ns3_node(ec, simu) @@ -333,17 +288,22 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_compile_debug_mode(self): + @skipIfNotAlive + def t_compile_debug_mode(self, host, user = None, identity = None): ec = ExperimentController(exp_id = "test-ns3-debug-mode") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", host) + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) ec.set(simu, "nsLog", "V4Ping:Node") ec.set(simu, "buildMode", "debug") @@ -385,17 +345,22 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_real_time(self): + @skipIfNotAlive + def t_real_time(self, host, user = None, identity = None): ec = ExperimentController(exp_id = "test-ns3-real-time") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) - ec.set(node, "cleanProcesses", True) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) + #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "simulatorImplementationType", "ns3::RealtimeSimulatorImpl") ec.set(simu, "checksumEnabled", True) ec.set(simu, "verbose", True) @@ -441,17 +406,22 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_traces(self): + @skipIfNotAlive + def t_traces(self, host, user = None, identity = None): ec = ExperimentController(exp_id = "test-ns3-traces") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", self.fedora_host) + ec.set(node, "username", self.fedora_user) + ec.set(node, "identity", self.fedora_identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) ec.register_connection(simu, node) @@ -515,21 +485,26 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_simple_wifi_ping(self): + @skipIfNotAlive + def t_wifi_ping(self, host, user = None, identity = None): bounds_width = bounds_height = 200 x = y = 100 speed = 1 ec = ExperimentController(exp_id = "test-ns3-wifi-ping") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) ec.register_connection(simu, node) @@ -567,7 +542,8 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_routing(self): + @skipIfNotAlive + def t_routing(self, host, user = None, identity = None): """ network topology: n4 @@ -580,14 +556,18 @@ class LinuxNS3ClientTest(unittest.TestCase): """ ec = ExperimentController(exp_id = "test-ns3-routes") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", host) + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) ec.register_connection(simu, node) @@ -679,7 +659,8 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def ztest_automatic_routing(self): + @skipIfNotAlive + def t_automatic_routing(self, host, user = None, identity = None): """ network topology: n4 @@ -692,14 +673,18 @@ class LinuxNS3ClientTest(unittest.TestCase): """ ec = ExperimentController(exp_id = "test-ns3-routing") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) ec.set(simu, "populateRoutingTables", True) ec.register_connection(simu, node) @@ -766,30 +751,32 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_dce(self): + @skipIfNotAlive + def t_dce(self, host, user = None, identity = None): ec = ExperimentController(exp_id = "test-ns3-dce") - node = ec.register_resource("LinuxNode") - ec.set(node, "hostname", self.fedora_host) - ec.set(node, "username", self.fedora_user) - ec.set(node, "identity", self.fedora_identity) + node = ec.register_resource("linux::Node") + if host == "localhost": + ec.set(node, "hostname", host) + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + ec.set(node, "cleanProcesses", True) #ec.set(node, "cleanHome", True) - simu = ec.register_resource("LinuxNS3Simulation") + simu = ec.register_resource("linux::ns3::Simulation") ec.set(simu, "verbose", True) - ec.set(simu, "enableDCE", True) ec.set(simu, "buildMode", "debug") ec.set(simu, "nsLog", "DceApplication") ec.register_connection(simu, node) nsnode1 = add_ns3_node(ec, simu) - ec.set(nsnode1, "enableDCE", True) p2p1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30") ec.set(p2p1, "DataRate", "5Mbps") nsnode2 = add_ns3_node(ec, simu) - ec.set(nsnode2, "enableDCE", True) p2p2 = add_point2point_device(ec, nsnode2, "10.0.0.2", "30") ec.set(p2p2, "DataRate", "5Mbps") @@ -801,7 +788,7 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.register_connection(chan, p2p2) ### create applications - udp_perf = ec.register_resource("ns3::DceApplication") + udp_perf = ec.register_resource("linux::ns3::dce::Application") ec.set (udp_perf, "binary", "udp-perf") ec.set (udp_perf, "stackSize", 1<<20) ec.set (udp_perf, "arguments", "--duration=10;--nodes=2") @@ -809,7 +796,7 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.set (udp_perf, "StopTime", "20s") ec.register_connection(udp_perf, nsnode1) - udp_perf_client = ec.register_resource("ns3::DceApplication") + udp_perf_client = ec.register_resource("linux::ns3::dce::Application") ec.set (udp_perf_client, "binary", "udp-perf") ec.set (udp_perf_client, "stackSize", 1<<20) ec.set (udp_perf_client, "arguments", "--client;--nodes=2;--host=10.0.0.1;--duration=10") @@ -820,17 +807,78 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.deploy() ec.wait_finished([udp_perf_client]) - - stderr = ec.trace(simu, "stderr") - print " CMDLINE", ec.trace(udp_perf, "cmdline") - print " STATUS ", ec.trace(udp_perf, "status") - print " OUT ", ec.trace(udp_perf, "stdout") - print " ERROR ", ec.trace(udp_perf, "stderr") + expected = "udp-perf --duration=10 --nodes=2" + cmdline = ec.trace(udp_perf, "cmdline") + self.assertTrue(cmdline.find(expected) > -1, cmdline) + + expected = "Start Time: NS3 Time: 1s (" + status = ec.trace(udp_perf, "status") + self.assertTrue(status.find(expected) > -1, status) + + expected = "received=1500 bytes, 1 reads (@1500 bytes) 1500" + stdout = ec.trace(udp_perf, "stdout") + self.assertTrue(stdout.find(expected) > -1, stdout) + + stderr = ec.trace(simu, "stderr") expected = "DceApplication:StartApplication" - self.assertTrue(stderr.find(expected) > -1) + self.assertTrue(stderr.find(expected) > -1, stderr) ec.shutdown() + + def test_p2p_ping_fedora(self): + self.t_p2p_ping(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_p2p_ping_local(self): + self.t_p2p_ping("localhost") + + def test_csma_ping_fedora(self): + self.t_csma_ping(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_csma_ping_local(self): + self.t_csma_ping("localhost") + + def test_wifi_ping_fedora(self): + self.t_wifi_ping(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_wifi_ping_local(self): + self.t_wifi_ping("localhost") + + def test_user_sources_fedora(self): + self.t_user_sources(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_user_sources_local(self): + self.t_user_sources("localhost") + + def test_compile_debug_mode_fedora(self): + self.t_compile_debug_mode(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_compile_debug_mode_local(self): + self.t_compile_debug_mode("localhost") + + def test_real_time_fedora(self): + self.t_real_time(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_real_time_local(self): + self.t_real_time("localhost") + + def test_traces_fedora(self): + self.t_traces(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_traces_local(self): + self.t_traces("localhost") + + def test_routing_fedora(self): + self.t_routing(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_routing_local(self): + self.t_routing("localhost") + + def test_dce_fedora(self): + self.t_dce(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_dce_local(self): + self.t_dce("localhost") if __name__ == '__main__':