Fixes ns-3/DCE
[nepi.git] / src / nepi / resources / linux / ns3 / ns3simulation.py
index 69cdf18..e026bb8 100644 (file)
@@ -30,6 +30,10 @@ from nepi.resources.linux.ns3.ns3client import LinuxNS3Client
 
 import os
 import time
+import threading
+
+## TODO: Clean up DCE part. All that is DCE specific should go
+##       in the linux ns3dceapplication.py
 
 @clsinit_copy
 class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
@@ -81,7 +85,8 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
 
         ns3_version = Attribute("ns3Version",
             "Version of ns-3 to install from nsam repo",
-            default = "ns-3.19", 
+            #default = "ns-3.19", 
+            default = "ns-3-dev", 
             flags = Flags.Design)
 
         enable_dce = Attribute("enableDCE",
@@ -92,7 +97,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
 
         pybindgen_version = Attribute("pybindgenVersion",
             "Version of pybindgen to install from bazar repo",
-            default = "834", 
+            default = "868", 
             flags = Flags.Design)
 
         populate_routing_tables = Attribute("populateRoutingTables",
@@ -119,8 +124,13 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
         self._client = None
         self._home = "ns3-simu-%s" % self.guid
         self._socket_name = "ns3-%s.sock" % os.urandom(4).encode('hex')
-        self._dce_helper_uuid = None
+        self._dce_manager_helper_uuid = None
         self._dce_application_helper_uuid = None
+        
+        # Lock used to synchronize usage of DceManagerHelper 
+        self.dce_manager_lock = threading.Lock()
+        # Lock used to synchronize usage of DceApplicationHelper
+        self.dce_application_lock = threading.Lock()
 
     @property
     def socket_name(self):
@@ -131,8 +141,8 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
         return os.path.join(self.run_home, self.socket_name)
 
     @property
-    def dce_helper_uuid(self):
-        return self._dce_helper_uuid
+    def dce_manager_helper_uuid(self):
+        return self._dce_manager_helper_uuid
 
     @property
     def dce_application_helper_uuid(self):
@@ -180,6 +190,11 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
         src_dir = os.path.join(self.node.src_dir, "ns-3")
 
         super(LinuxNS3Simulation, self).upload_sources(src_dir = src_dir)
+    
+    def upload_extra_sources(self, sources = None, src_dir = None):
+        return super(LinuxNS3Simulation, self).upload_sources(
+                sources = sources, 
+                src_dir = src_dir)
 
     def upload_start_command(self):
         command = self.get("command")
@@ -219,7 +234,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
             self.invoke(GLOBAL_VALUE_UUID, "Bind", "SchedulerType", btrue)
         
         if self.get("enableDCE"):
-            self._dce_helper_uuid = self.create("DceManagerHelper")
+            self._dce_manager_helper_uuid = self.create("DceManagerHelper")
             self._dce_application_helper_uuid = self.create("DceApplicationHelper")
 
     def do_deploy(self):
@@ -490,7 +505,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
                         "  --prefix=%(ns3_build_home)s --with-ns3=%(ns3_build_home)s && "
                         "  ./waf build && "
                         "  ./waf install && "
-                        "  mv %(ns3_build_home)s/lib/python*/site-packages/ns/dce.so %(ns3_build_home)s/lib/python/site-packages/ns/ "
+                        "  mv %(ns3_build_home)s/lib*/python*/site-packages/ns/dce.so %(ns3_build_home)s/lib/python/site-packages/ns/ "
                         " )"
                 ) % { 
                     'ns3_version': self.get("ns3Version"),
@@ -514,10 +529,10 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
                 "  mkdir -p %(ns3_build_home)s && "
                 "  cd ${SRC}/ns-3/%(ns3_version)s && "
                 "  ./waf configure -d %(build_mode)s --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s "
-                "  --prefix=%(ns3_build_home)s --includedir=%(ns3_build_home)s && "
+                "  --prefix=%(ns3_build_home)s && "
                 "  ./waf build && "
                 "  ./waf install && "
-                "  mv %(ns3_build_home)s/lib/python* %(ns3_build_home)s/lib/python "
+                "  mv %(ns3_build_home)s/lib*/python* %(ns3_build_home)s/lib/python "
                 " )"
                 ") "
                 " && "
@@ -538,14 +553,38 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
         env.append("PYTHONPATH=$PYTHONPATH:${NS3BINDINGS:=%(ns3_build_home)s/lib/python/site-packages}" % { 
                     'ns3_build_home': self.ns3_build_home
                  })
-        env.append("LD_LIBRARY_PATH=${NS3LIBRARIES:=%(ns3_build_home)s/lib/}" % { 
+        # If NS3LIBRARIES is defined and not empty, assign its value, 
+        # if not assign ns3_build_home/lib/ to NS3LIBRARIES and LD_LIBARY_PATH
+        env.append("LD_LIBRARY_PATH=${NS3LIBRARIES:=%(ns3_build_home)s/lib}" % { 
                     'ns3_build_home': self.ns3_build_home
                  })
-        env.append("DCE_PATH=$PATH:$NS3LIBRARIES/../bin_dce")
-        env.append("DCE_ROOT=$PATH:$NS3LIBRARIES/..")
+        env.append("DCE_PATH=$NS3LIBRARIES/../bin_dce")
+        env.append("DCE_ROOT=$NS3LIBRARIES/..")
 
         return " ".join(env) 
 
+    def replace_paths(self, command):
+        """
+        Replace all special path tags with shell-escaped actual paths.
+        """
+        return ( command
+            .replace("${USR}", self.node.usr_dir)
+            .replace("${LIB}", self.node.lib_dir)
+            .replace("${BIN}", self.node.bin_dir)
+            .replace("${SRC}", self.node.src_dir)
+            .replace("${SHARE}", self.node.share_dir)
+            .replace("${EXP}", self.node.exp_dir)
+            .replace("${EXP_HOME}", self.node.exp_home)
+            .replace("${APP_HOME}", self.app_home)
+            .replace("${RUN_HOME}", self.run_home)
+            .replace("${NODE_HOME}", self.node.node_home)
+            .replace("${HOME}", self.node.home_dir)
+            # If NS3LIBRARIES is defined and not empty, use that value, 
+            # if not use ns3_build_home/lib/
+            .replace("${BIN_DCE}", "${NS3LIBRARIES-%s/lib/}../bin_dce" % \
+                    self.ns3_build_home)
+            )
+
     def valid_connection(self, guid):
         # TODO: Validate!
         return True