From 95525009ed3a5d4b049c7fb1d3480e73605e9176 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Fri, 22 Jul 2011 10:52:10 +0200 Subject: [PATCH] ns-3.11 --- src/nepi/testbeds/ns3/constants.py | 2 +- src/nepi/testbeds/ns3/execute.py | 71 +++++++++------------ src/nepi/testbeds/ns3/factories_metadata.py | 2 +- test/lib/test_util.py | 28 ++------ test/testbeds/ns3/execute.py | 22 +++---- 5 files changed, 51 insertions(+), 74 deletions(-) diff --git a/src/nepi/testbeds/ns3/constants.py b/src/nepi/testbeds/ns3/constants.py index aa5a3bd2..7a1f4c52 100644 --- a/src/nepi/testbeds/ns3/constants.py +++ b/src/nepi/testbeds/ns3/constants.py @@ -2,5 +2,5 @@ # -*- coding: utf-8 -*- TESTBED_ID = "ns3" -TESTBED_VERSION = "3.9" +TESTBED_VERSION = "3.11" diff --git a/src/nepi/testbeds/ns3/execute.py b/src/nepi/testbeds/ns3/execute.py index 6d246e9f..5c3045b4 100644 --- a/src/nepi/testbeds/ns3/execute.py +++ b/src/nepi/testbeds/ns3/execute.py @@ -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 diff --git a/src/nepi/testbeds/ns3/factories_metadata.py b/src/nepi/testbeds/ns3/factories_metadata.py index d2f30090..fe38f4a1 100644 --- a/src/nepi/testbeds/ns3/factories_metadata.py +++ b/src/nepi/testbeds/ns3/factories_metadata.py @@ -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/test/lib/test_util.py b/test/lib/test_util.py index 39fe983a..3373b8ec 100644 --- a/test/lib/test_util.py +++ b/test/lib/test_util.py @@ -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(): diff --git a/test/testbeds/ns3/execute.py b/test/testbeds/ns3/execute.py index 07fedcc4..5eec42bb 100755 --- a/test/testbeds/ns3/execute.py +++ b/test/testbeds/ns3/execute.py @@ -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() -- 2.47.0