ns-3 simulator synchronizing start
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 2 Jun 2014 17:08:03 +0000 (19:08 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 2 Jun 2014 17:08:03 +0000 (19:08 +0200)
src/nepi/resources/linux/ns3/ns3simulation.py
src/nepi/resources/ns3/ns3server.py
src/nepi/resources/ns3/ns3wrapper.py
test/resources/linux/ns3/ccn/ns3dceccnpeek.py

index 0080846..94029a1 100644 (file)
@@ -275,7 +275,22 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
             if self.get("populateRoutingTables") == True:
                 self.invoke(IPV4_GLOBAL_ROUTING_HELPER_UUID, "PopulateRoutingTables")
 
-            self._client.start() 
+            self._client.start()
+
+            # Wait until the Simulation starts...
+            is_running = False
+            for i in xrange(100):
+                is_running = self.invoke(SIMULATOR_UUID, "isRunning")
+            
+                if is_running:
+                    break
+                else:
+                    time.sleep(1)
+            else:
+                if not is_running:
+                    msg = " Simulation did not start"
+                    self.error(msg)
+                    raise RuntimeError
 
             self.set_started()
         else:
@@ -408,7 +423,6 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
                             'dce_repo': self.dce_repo
                          }
 
-
         return (
                 # NS3 installation
                 "( "
index a9f4353..24b26b9 100644 (file)
@@ -65,51 +65,55 @@ def handle_message(ns3_wrapper, msg_type, args, kwargs):
     if msg_type == NS3WrapperMessage.CREATE:
         clazzname = args.pop(0)
         
-        ns3_wrapper.logger.debug("CREATE %s %s" % (clazzname, str(args)))
+        result = ns3_wrapper.create(clazzname, *args)
 
-        uuid = ns3_wrapper.create(clazzname, *args)
+        ns3_wrapper.logger.debug("%s CREATE %s %s" % (str(result), clazzname, 
+            str(args)))
         
-        #ns3_wrapper.logger.debug("%s = CREATE " % str(uuid))
-        return uuid
+        return result
 
     if msg_type == NS3WrapperMessage.FACTORY:
         type_name = args.pop(0)
 
-        ns3_wrapper.logger.debug("FACTORY %s %s" % (type_name, str(kwargs)))
-
-        uuid = ns3_wrapper.factory(type_name, **kwargs)
+        result = ns3_wrapper.factory(type_name, **kwargs)
+        
+        ns3_wrapper.logger.debug("%s FACTORY %s %s" % (str(result), type_name, 
+            str(kwargs)))
         
-        #ns3_wrapper.logger.debug("%s = FACTORY " % str(uuid))
-        return uuid
+        return result
 
     if msg_type == NS3WrapperMessage.INVOKE:
         uuid = args.pop(0)
         operation = args.pop(0)
-        
-        ns3_wrapper.logger.debug("INVOKE %s %s %s %s " % (uuid, operation, 
-            str(args), str(kwargs)))
-    
-        uuid = ns3_wrapper.invoke(uuid, operation, *args, **kwargs)
-        return uuid
+   
+        result = ns3_wrapper.invoke(uuid, operation, *args, **kwargs)
+
+        ns3_wrapper.logger.debug("%s INVOKE %s %s %s %s " % (str(result), uuid, 
+            operation, str(args), str(kwargs)))
+
+        return result
 
     if msg_type == NS3WrapperMessage.GET:
         uuid = args.pop(0)
         name = args.pop(0)
 
-        ns3_wrapper.logger.debug("GET %s %s" % (uuid, name))
+        result = ns3_wrapper.get(uuid, name)
+        
+        ns3_wrapper.logger.debug("%s GET %s %s" % (str(result), uuid, name))
 
-        value = ns3_wrapper.get(uuid, name)
-        return value
+        return result
 
     if msg_type == NS3WrapperMessage.SET:
         uuid = args.pop(0)
         name = args.pop(0)
         value = args.pop(0)
 
-        ns3_wrapper.logger.debug("SET %s %s %s" % (uuid, name, str(value)))
+        result = ns3_wrapper.set(uuid, name, value)
+
+        ns3_wrapper.logger.debug("%s SET %s %s %s" % (str(result), uuid, name, 
+            str(value)))
 
-        value = ns3_wrapper.set(uuid, name, value)
-        return value
+        return result
  
     if msg_type == NS3WrapperMessage.FLUSH:
         # Forces flushing output and error streams.
index b617f33..f6075b0 100644 (file)
@@ -212,6 +212,8 @@ class NS3Wrapper(object):
         return uuid
 
     def invoke(self, uuid, operation, *args, **kwargs):
+        if operation == "isRunning":
+            return self._is_running()
         if operation == "isAppRunning":
             return self._is_app_running(uuid)
         if operation == "addStaticRoute":
@@ -447,6 +449,16 @@ class NS3Wrapper(object):
 
         return realkwargs
 
+    def _is_running(self): 
+        if self.ns3.Simulator.IsFinished():
+            return False
+
+        now = self.ns3.Simulator.Now()
+        if now.IsZero():
+            return False
+        
+        return True
+
     def _is_app_running(self, uuid): 
         now = self.ns3.Simulator.Now()
         if now.IsZero():
index 1d9acca..ea296b3 100644 (file)
@@ -50,17 +50,20 @@ def add_ns3_node(ec, simu):
 class LinuxNS3CCNPeekDceApplicationTest(unittest.TestCase):
     def setUp(self):
         self.fedora_host = "nepi2.pl.sophia.inria.fr"
-        self.fedora_host = "planetlabpc1.upf.edu"
         self.fedora_user = "inria_nepi"
         self.fedora_identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
+        self.fedora_host = "mimas.inria.fr"
+        self.fedora_user = "aquereil"
+        self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
 
     def test_dce_ccnpeek(self):
-        ec = ExperimentController(exp_id = "test-dce-ccnpeek")
+        ec = ExperimentController(exp_id = "test-dce-ccnpeek2")
         
         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, "cleanExperiment", True)
         #ec.set(node, "cleanProcesses", True)
         #ec.set(node, "cleanHome", True)