DCE traces working
[nepi.git] / src / nepi / resources / linux / ns3 / ns3simulation.py
index 5745f54..25b9535 100644 (file)
@@ -30,6 +30,7 @@ from nepi.resources.linux.ns3.ns3client import LinuxNS3Client
 
 import os
 import time
+import threading
 
 @clsinit_copy
 class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
@@ -81,7 +82,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 +94,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,6 +121,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_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):
@@ -128,6 +137,14 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
     def remote_socket(self):
         return os.path.join(self.run_home, self.socket_name)
 
+    @property
+    def dce_manager_helper_uuid(self):
+        return self._dce_manager_helper_uuid
+
+    @property
+    def dce_application_helper_uuid(self):
+        return self._dce_application_helper_uuid
+
     @property
     def ns3_build_home(self):
         return os.path.join(self.node.bin_dir, "ns-3", self.get("ns3Version"), 
@@ -207,6 +224,10 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
             sched_type = self.get("schedulerType")
             stype = self.create("StringValue", sched_type)
             self.invoke(GLOBAL_VALUE_UUID, "Bind", "SchedulerType", btrue)
+        
+        if self.get("enableDCE"):
+            self._dce_manager_helper_uuid = self.create("DceManagerHelper")
+            self._dce_application_helper_uuid = self.create("DceApplicationHelper")
 
     def do_deploy(self):
         if not self.node or self.node.state < ResourceState.READY:
@@ -302,7 +323,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
 
         ns_log = self.get("nsLog")
         if ns_log:
-            command.append("-L %s" % ns_log)
+            command.append("-L '%s'" % ns_log)
 
         if self.get("verbose"):
             command.append("-v")
@@ -326,6 +347,11 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
     def pygccxml_version(self):
         return "pygccxml-1.0.0"
 
+    @property
+    def dce_repo(self):
+        #return "http://code.nsnam.org/ns-3-dce"
+        return "http://code.nsnam.org/epmancini/ns-3-dce"
+
     @property
     def _build(self):
         # If the user defined local sources for ns-3, we uncompress the sources
@@ -384,9 +410,12 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
                         # Get dce source code
                         " ( "
                         "   mkdir -p ${SRC}/dce && "
-                        "   hg clone http://code.nsnam.org/ns-3-dce ${SRC}/dce/ns-3-dce"
+                        "   hg clone %(dce_repo)s ${SRC}/dce/ns-3-dce"
                         " ) "
-                    )
+                     ) % {
+                            'dce_repo': self.dce_repo
+                         }
+
 
         return (
                 # NS3 installation
@@ -464,16 +493,18 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
                         " (   "
                          # If not, copy ns-3 build to bin
                         "  cd ${SRC}/dce/ns-3-dce && "
-                        "  ./waf configure --enable-opt --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s "
+                        "  ./waf configure %(enable_opt)s --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s "
                         "  --prefix=%(ns3_build_home)s --with-ns3=%(ns3_build_home)s && "
                         "  ./waf build && "
-                        "  ./waf install "
+                        "  ./waf install && "
+                        "  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"),
                     'pybindgen_version': self.get("pybindgenVersion"),
                     'ns3_build_home': self.ns3_build_home,
                     'build_mode': self.get("buildMode"),
+                    'enable_opt': "--enable-opt" if  self.get("buildMode") == "optimized" else ""
                     }
 
         return (
@@ -490,10 +521,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 "
                 " )"
                 ") "
                 " && "
@@ -517,6 +548,8 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
         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/..")
 
         return " ".join(env)