Merge with tip
authorClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 26 Jul 2011 16:24:29 +0000 (18:24 +0200)
committerClaudio-Daniel Freire <claudio-daniel.freire@inria.fr>
Tue, 26 Jul 2011 16:24:29 +0000 (18:24 +0200)
src/nepi/testbeds/ns3/attributes_metadata.py
src/nepi/testbeds/ns3/constants.py
src/nepi/testbeds/ns3/execute.py
src/nepi/testbeds/ns3/factories_metadata.py
src/nepi/testbeds/ns3/ns3_bindings_import.py [new file with mode: 0644]
src/nepi/util/tags.py
test/lib/test_util.py
test/testbeds/ns3/execute.py

index b544e7a..9033998 100644 (file)
@@ -11,9 +11,28 @@ testbed_attributes = dict({
     "simu_impl_type": dict({
             "name": "SimulatorImplementationType",
             "help": "The object class to use as the simulator implementation",
-            "type": Attribute.STRING,
+            "value": "ns3::DefaultSimulatorImpl",
+            "type": Attribute.ENUM,
             "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
-            "validation_function": validation.is_string
+            "allowed": [
+                "ns3::DefaultSimulatorImpl",
+                "ns3::RealtimeSimulatorImpl",
+            ],
+            "validation_function": validation.is_enum
+        }),
+    "sched_impl_type": dict({
+            "name": "SchedulerType",
+            "help": "The object class to use as the scheduler implementation. Make sure to pick a thread-safe variant.",
+            "value": "ns3::ThreadsafeMapScheduler",
+            "type": Attribute.ENUM,
+            "flags": Attribute.ExecReadOnly | Attribute.ExecImmutable,
+            "allowed": [
+                "ns3::ThreadsafeMapScheduler",
+                "ns3::ThreadsafeHeapScheduler",
+                "ns3::ThreadsafeListScheduler",
+                "ns3::ThreadsafeCalendarScheduler",
+            ],
+            "validation_function": validation.is_enum
         }),
     "checksum": dict({
             "name": "ChecksumEnabled",
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..1a76576 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,19 +280,24 @@ 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")
+        sched_impl_type = self._attributes.get_attribute_value(
+                "SchedulerType")
         checksum = self._attributes.get_attribute_value("ChecksumEnabled")
         stop_time = self._attributes.get_attribute_value("StopTime")
 
-        init()
+        load_ns3_module()
 
         import ns3 as mod
  
         if simu_impl_type:
             value = mod.StringValue(simu_impl_type)
             mod.GlobalValue.Bind ("SimulatorImplementationType", value)
+        if sched_impl_type:
+            value = mod.StringValue(sched_impl_type)
+            mod.GlobalValue.Bind ("SchedulerType", value)
         if checksum:
             value = mod.BooleanValue(checksum)
             mod.GlobalValue.Bind ("ChecksumEnabled", value)
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)
diff --git a/src/nepi/testbeds/ns3/ns3_bindings_import.py b/src/nepi/testbeds/ns3/ns3_bindings_import.py
new file mode 100644 (file)
index 0000000..ae9e700
--- /dev/null
@@ -0,0 +1,33 @@
+from ns.core import *
+from ns.network import *
+from ns.config_store import *
+from ns.internet import *
+from ns.propagation import *
+from ns.point_to_point import *
+from ns.csma import *
+from ns.emu import *
+from ns.bridge import *
+from ns.tap_bridge import *
+from ns.applications import *
+from ns.nix_vector_routing import *
+from ns.olsr import *
+from ns.aodv import *
+from ns.dsdv import *
+from ns.click import *
+from ns.mobility import *
+from ns.wifi import *
+from ns.netanim import *
+from ns.stats import *
+from ns.uan import *
+from ns.spectrum import *
+from ns.mesh import *
+from ns.flow_monitor import *
+from ns.wimax import *
+from ns.lte import *
+from ns.mpi import *
+from ns.topology_read import *
+from ns.energy import *
+from ns.tools import *
+from ns.visualizer import *
+from ns.point_to_point_layout import *
+from ns.fd_net_device import *
index e3fbdf2..5e72440 100644 (file)
@@ -7,7 +7,6 @@ INTERFACE = "interface"
 WIRELESS = "wireless"
 APPLICATION = "application"
 NAT = "nat"
-ROUTER = "router" 
 SWITCH = "switch"
 PPP = "point-to-point"
 PROTOCOL = "protocol"
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()