ns-3.11
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 22 Jul 2011 08:52:10 +0000 (10:52 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 22 Jul 2011 08:52:10 +0000 (10:52 +0200)
src/nepi/testbeds/ns3/constants.py
src/nepi/testbeds/ns3/execute.py
src/nepi/testbeds/ns3/factories_metadata.py
test/lib/test_util.py
test/testbeds/ns3/execute.py

index aa5a3bd..7a1f4c5 100644 (file)
@@ -2,5 +2,5 @@
 # -*- coding: utf-8 -*-
 
 TESTBED_ID = "ns3"
-TESTBED_VERSION = "3.9"
+TESTBED_VERSION = "3.11"
 
index 6d246e9..5c3045b 100644 (file)
@@ -12,56 +12,47 @@ import random
 import socket
 import weakref
 
-def init():
+def load_ns3_module():
+    import sys
     if 'ns3' in sys.modules:
         return
 
     import ctypes
     import imp
+    import re
 
     bindings = os.environ["NEPI_NS3BINDINGS"] \
                if "NEPI_NS3BINDINGS" in os.environ else None
-    libfile = os.environ["NEPI_NS3LIBRARY"] \
+    libdir = os.environ["NEPI_NS3LIBRARY"] \
                if "NEPI_NS3LIBRARY" in os.environ else None
 
-    if libfile:
-        ctypes.CDLL(libfile, ctypes.RTLD_GLOBAL)
-        """
-        files = os.listdir(build_path)
+    if libdir:
+        files = os.listdir(libdir)
         regex = re.compile("(.*\.so)$")
         libs = [m.group(1) for filename in files for m in [regex.search(filename)] if m]
-        i = 0
-        while len(libs) > 0:
-            i += 1
-            lib = libs[ i % len(libs)]
-            libfile = os.path.join(build_path, lib)
-            try:
-                ctypes.CDLL(libfile, ctypes.RTLD_GLOBAL)
-                libs.remove(lib)
-            except:
-                pass
-        """
-
-       path = [ os.path.dirname(__file__) ] + sys.path
-       if bindings:
-           path = [ bindings ] + path
-
-       try:
-           module = imp.find_module ('ns3', path)
-           mod = imp.load_module ('ns3', *module)
-       except ImportError:
-           # In some environments, ns3 per-se does not exist,
-           # only the low-level _ns3
-           module = imp.find_module ('_ns3', path)
-           mod = imp.load_module ('_ns3', *module)
-           sys.modules["ns3"] = mod # install it as ns3 too
-           
-           # When using _ns3, we have to make sure we destroy
-           # the simulator when the process finishes
-           import atexit
-           atexit.register(mod.Simulator.Destroy)
 
+        libscp = list(libs)
+        while len(libs) > 0:
+            for lib in libscp:
+                libfile = os.path.join(libdir, lib)
+                try:
+                    ctypes.CDLL(libfile, ctypes.RTLD_GLOBAL)
+                    libs.remove(lib)
+                except:
+                    pass
+            # if did not load any libraries in the last iteration
+            if len(libscp) == len(libs):
+                raise RuntimeError("Imposible to load shared libraries %s" % str(libs))
+            libscp = list(libs)
+
+    if not bindings:
+        import ns3
+        sys.modules["ns3"] = ns3
+        return
+    
+    sys.path.append(bindings)
+    import ns3_bindings_import as mod
+    sys.modules["ns3"] = mod
 
 class TestbedController(testbed_impl.TestbedController):
     from nepi.util.tunchannel_impl import TunChannel
@@ -91,7 +82,7 @@ class TestbedController(testbed_impl.TestbedController):
     def do_setup(self):
         self._home_directory = self._attributes.\
             get_attribute_value("homeDirectory")
-        self._ns3 = self._load_ns3_module()
+        self._ns3 = self._configure_ns3_module()
         
         # create home...
         home = os.path.normpath(self.home_directory)
@@ -289,13 +280,13 @@ class TestbedController(testbed_impl.TestbedController):
         ns3_value.DeserializeFromString(str_value, checker)
         return ns3_value
 
-    def _load_ns3_module(self):
+    def _configure_ns3_module(self):
         simu_impl_type = self._attributes.get_attribute_value(
                 "SimulatorImplementationType")
         checksum = self._attributes.get_attribute_value("ChecksumEnabled")
         stop_time = self._attributes.get_attribute_value("StopTime")
 
-        init()
+        load_ns3_module()
 
         import ns3 as mod
  
index d2f3009..fe38f4a 100644 (file)
@@ -162,7 +162,7 @@ def wimaxpcap_trace(testbed_instance, guid, trace_id):
 
 def rtt_trace(testbed_instance, guid, trace_id):
     element = testbed_instance._elements[guid]
-    helper = testbed_instance.ns3.PlotHelper()
+    helper = testbed_instance.ns3.ScalarTraceHelper()
     prefix = "trace-app-%d" % (guid, )
     filename = helper.GetFilenameFromSource(prefix, element, trace_id)
     filepath = _follow_trace(testbed_instance, guid, trace_id, filename)
index 39fe983..3373b8e 100644 (file)
@@ -31,28 +31,14 @@ def ns3_library_path():
     return None
 
 def ns3_usable():
-    if ns3_library_path():
-        try:
-            ctypes.CDLL(ns3_library_path(), ctypes.RTLD_GLOBAL)
-        except:
-            return False
-
-    if ns3_bindings_path():
-        sys.path.insert(0, ns3_bindings_path())
-
     try:
-        found = imp.find_module('ns3')
-        module = imp.load_module('ns3', *found)
-    except ImportError:
-        try:
-            found = imp.find_module('_ns3')
-            module = imp.load_module('_ns3', *found)
-        except ImportError:
-            return False
-    finally:
-        if ns3_bindings_path():
-            del sys.path[0]
-
+        from nepi.testbeds.ns3 import execute
+        execute.load_ns3_module()
+    except:
+        import traceback
+        import sys
+        traceback.print_exc(file = sys.stderr)
+        return False
     return True
 
 def pl_auth():
index 07fedcc..5eec42b 100755 (executable)
@@ -75,18 +75,18 @@ class Ns3ExecuteTestCase(unittest.TestCase):
         ping_result = instance.trace(14, "P2PAsciiTrace")
         ping_rtt = instance.trace(17, "Rtt")
         comp_result = "- 9.021 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 9 protocol 1 offset 0 flags [none] length: 84 10.0.0.2 > 10.0.0.1) ns3::Icmpv4Header (type=0, code=0) ns3::Icmpv4Echo (identifier=0, sequence=9)"
-        comp_rtt_result = """41992186ns        41992186ns
-1041992186ns   41992186ns
-2041992186ns   41992186ns
-3041992186ns   41992186ns
-4041992186ns   41992186ns
-5041992186ns   41992186ns
-6041992186ns   41992186ns
-7041992186ns   41992186ns
-8041992186ns   41992186ns
-9041992186ns   41992186ns"""
+        comp_rtt_result = """+41992186.0ns\t+41992186.0ns
++1041992186.0ns\t+41992186.0ns
++2041992186.0ns\t+41992186.0ns
++3041992186.0ns\t+41992186.0ns
++4041992186.0ns\t+41992186.0ns
++5041992186.0ns\t+41992186.0ns
++6041992186.0ns\t+41992186.0ns
++7041992186.0ns\t+41992186.0ns
++8041992186.0ns\t+41992186.0ns
++9041992186.0ns\t+41992186.0ns"""
         self.assertNotEqual(ping_result.find(comp_result), -1)
-        self.assertEqual(ping_rtt.strip(), comp_rtt_result, -1)
+        self.assertEqual(ping_rtt.strip(), comp_rtt_result.strip())
         instance.stop()
         instance.shutdown()