From: Alina Quereilhac Date: Mon, 10 Feb 2014 17:37:21 +0000 (+0100) Subject: Added attributes for ns-3 simulator. Realtime mode working X-Git-Tag: nepi-3.1.0~120^2~8 X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=7129b4c861ab0672df95b3106c80b00973d9918e;p=nepi.git Added attributes for ns-3 simulator. Realtime mode working --- diff --git a/src/nepi/resources/linux/ns3/ns3simulation.py b/src/nepi/resources/linux/ns3/ns3simulation.py index f820eabf..d4f37b0e 100644 --- a/src/nepi/resources/linux/ns3/ns3simulation.py +++ b/src/nepi/resources/linux/ns3/ns3simulation.py @@ -254,6 +254,19 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): super(LinuxApplication, self).do_release() + @property + def state(self): + """ Returns the state of the application + """ + state = super(LinuxApplication, self).state + if state == ResourceState.STARTED: + # Check simulator + is_finished = self.invoke(SIMULATOR_UUID, "IsFinished") + if is_finished: + self.do_stop() + + return self._state + @property def _start_command(self): command = [] diff --git a/test/resources/linux/ns3/ns3simulation.py b/test/resources/linux/ns3/ns3simulation.py index f0211969..93995634 100644 --- a/test/resources/linux/ns3/ns3simulation.py +++ b/test/resources/linux/ns3/ns3simulation.py @@ -119,14 +119,14 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() - def test_real_time(self): + def ztest_real_time(self): 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, "cleanProcesses", True) - #ec.set(node, "cleanHome", True) + ec.set(node, "cleanHome", True) simu = ec.register_resource("LinuxNS3Simulation") ec.set(simu, "verbose", True) @@ -206,6 +206,37 @@ class LinuxNS3ClientTest(unittest.TestCase): ec.shutdown() + def test_stop_time(self): + ec = ExperimentController(exp_id = "test-ns3-stop-time") + + node = ec.register_resource("LinuxNode") + ec.set(node, "hostname", self.fedora_host) + ec.set(node, "username", self.fedora_user) + ec.set(node, "cleanProcesses", True) + #ec.set(node, "cleanHome", True) + + simu = ec.register_resource("LinuxNS3Simulation") + ec.set(simu, "verbose", True) + ec.set(simu, "simulatorImplementationType", "ns3::RealtimeSimulatorImpl") + ec.set(simu, "checksumEnabled", True) + ec.set(simu, "stopTime", "20s") + ec.register_connection(simu, node) + + ec.deploy() + + ec.wait_finished([simu]) + + rm = ec.get_resource(simu) + start_time = rm.start_time + stop_time = rm.stop_time + delta = stop_time - start_time + + print delta.seconds + self.assertTrue(delta.seconds >= 20) + self.assertTrue(delta.seconds < 25) + + ec.shutdown() + if __name__ == '__main__': unittest.main()