Added attributes for ns-3 simulator. Realtime mode working
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 10 Feb 2014 17:37:21 +0000 (18:37 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 10 Feb 2014 17:37:21 +0000 (18:37 +0100)
src/nepi/resources/linux/ns3/ns3simulation.py
test/resources/linux/ns3/ns3simulation.py

index f820eab..d4f37b0 100644 (file)
@@ -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 = [] 
index f021196..9399563 100644 (file)
@@ -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()