+SINGLETON = "singleton::"
+SIMULATOR_UUID = "singleton::Simulator"
+CONFIG_UUID = "singleton::Config"
+GLOBAL_VALUE_UUID = "singleton::GlobalValue"
+IPV4_GLOBAL_ROUTING_HELPER_UUID = "singleton::Ipv4GlobalRoutingHelper"
+
+def load_ns3_libraries():
+ import ctypes
+ import re
+
+ libdir = os.environ.get("NS3LIBRARIES")
+
+ # Load the ns-3 modules shared libraries
+ 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]
+
+ initial_size = len(libs)
+ # Try to load the libraries in the right order by trial and error.
+ # Loop until all libraries are loaded.
+ while len(libs) > 0:
+ for lib in libs:
+ libfile = os.path.join(libdir, lib)
+ try:
+ ctypes.CDLL(libfile, ctypes.RTLD_GLOBAL)
+ libs.remove(lib)
+ except:
+ #import traceback
+ #err = traceback.format_exc()
+ #print err
+ pass
+
+ # if did not load any libraries in the last iteration break
+ # to prevent infinit loop
+ if initial_size == len(libs):
+ raise RuntimeError("Imposible to load shared libraries %s" % str(libs))
+ initial_size = len(libs)
+
+def load_ns3_module():
+ load_ns3_libraries()
+
+ # import the python bindings for the ns-3 modules
+ bindings = os.environ.get("NS3BINDINGS")
+ if bindings:
+ sys.path.append(bindings)
+
+ import pkgutil
+ import imp
+ import ns
+
+ # create a Python module to add all ns3 classes
+ ns3mod = imp.new_module("ns3")
+ sys.modules["ns3"] = ns3mod
+
+ for importer, modname, ispkg in pkgutil.iter_modules(ns.__path__):
+ if modname in [ "visualizer" ]:
+ continue
+
+ fullmodname = "ns.%s" % modname
+ module = __import__(fullmodname, globals(), locals(), ['*'])
+
+ for sattr in dir(module):
+ if sattr.startswith("_"):
+ continue
+
+ attr = getattr(module, sattr)
+
+ # netanim.Config and lte.Config singleton overrides ns3::Config
+ if sattr == "Config" and modname in ['netanim', 'lte']:
+ sattr = "%s.%s" % (modname, sattr)
+
+ setattr(ns3mod, sattr, attr)
+
+ return ns3mod
+