import files that are relative to the source as nepi.full.path
[nepi.git] / src / nepi / resources / ns3 / ns3wrapper.py
index d8fa96f..a9a5e12 100644 (file)
@@ -3,9 +3,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
@@ -131,7 +130,7 @@ class NS3Wrapper(object):
         self._allowed_types = None
 
         # Object to dump instructions to reproduce and debug experiment
-        from ns3wrapper_debug import NS3WrapperDebuger
+        from nepi.resources.ns3.ns3wrapper_debug import NS3WrapperDebuger
         self._debuger = NS3WrapperDebuger(enabled = enable_dump)
 
     @property
@@ -155,7 +154,7 @@ class NS3Wrapper(object):
             tid_count = type_id.GetRegisteredN()
             base = type_id.LookupByName("ns3::Object")
 
-            for i in xrange(tid_count):
+            for i in range(tid_count):
                 tid = type_id.GetRegistered(i)
                 
                 if tid.MustHideFromDocumentation() or \
@@ -214,7 +213,7 @@ class NS3Wrapper(object):
         factory = self.ns3.ObjectFactory()
         factory.SetTypeId(type_name)
 
-        for name, value in kwargs.iteritems():
+        for name, value in kwargs.items():
             ns3_value = self._attr_from_string_to_ns3_value(type_name, name, value)
             factory.Set(name, ns3_value)
 
@@ -281,6 +280,9 @@ class NS3Wrapper(object):
         elif operation == "isAppRunning":
             result = self._is_app_running(uuid)
 
+        elif operation == "isAppStarted":
+            result = self._is_app_started(uuid)
+
         elif operation == "recvFD":
             ### passFD operation binds to a different random socket 
             ### en every execution, so the socket name that could be
@@ -573,11 +575,11 @@ class NS3Wrapper(object):
     def replace_kwargs(self, kwargs):
         realkwargs = dict([(k, self.get_object(v) \
                 if str(v).startswith("uuid") else v) \
-                for k,v in kwargs.iteritems()])
+                for k,v in kwargs.items()])
  
         realkwargs = dict([(k, self._singleton(v) \
                 if str(v).startswith(SINGLETON) else v )\
-                for k, v in realkwargs.iteritems()])
+                for k, v in realkwargs.items()])
 
         return realkwargs
 
@@ -598,10 +600,14 @@ class NS3Wrapper(object):
         app.GetAttribute("StartTime", start_time_value)
         start_time = start_time_value.Get()
         
-        if now.Compare(start_time) >= 0 and now.Compare(stop_time) < 0:
-            return True
+        if now.Compare(start_time) >= 0:
+            if stop_time.IsZero() or now.Compare(stop_time) < 0:
+                return True
 
         return False
+    
+    def _is_app_started(self, uuid):
+        return self._is_app_running(uuid) or self.is_finished
 
     def _add_static_route(self, ipv4_uuid, network, prefix, nexthop):
         ipv4 = self.get_object(ipv4_uuid)
@@ -639,10 +645,10 @@ class NS3Wrapper(object):
         # For all the interfaces registered with the ipv4 object, find
         # the one that matches the network of the nexthop
         nifaces = ipv4.GetNInterfaces()
-        for ifidx in xrange(nifaces):
+        for ifidx in range(nifaces):
             iface = ipv4.GetInterface(ifidx)
             naddress = iface.GetNAddresses()
-            for addridx in xrange(naddress):
+            for addridx in range(naddress):
                 ifaddr = iface.GetAddress(addridx)
                 ifmask = ifaddr.GetMask()
                 
@@ -662,7 +668,7 @@ class NS3Wrapper(object):
         newuuid = None
         if search:
             # search object
-            for ouuid, oobj in self._objects.iteritems():
+            for ouuid, oobj in self._objects.items():
                 if nobj == oobj:
                     newuuid = ouuid
                     break