Fixing static lock messup with Ns3 DCE Manager
[nepi.git] / src / nepi / resources / linux / ns3 / ns3simulation.py
1 #
2 #    NEPI, a framework to manage network experiments
3 #    Copyright (C) 2014 INRIA
4 #
5 #    This program is free software: you can redistribute it and/or modify
6 #    it under the terms of the GNU General Public License as published by
7 #    the Free Software Foundation, either version 3 of the License, or
8 #    (at your option) any later version.
9 #
10 #    This program is distributed in the hope that it will be useful,
11 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
12 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 #    GNU General Public License for more details.
14 #
15 #    You should have received a copy of the GNU General Public License
16 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.trace import Trace, TraceAttr
22 from nepi.execution.resource import ResourceManager, clsinit_copy, \
23         ResourceState, ResourceFactory
24 from nepi.resources.linux.application import LinuxApplication
25 from nepi.util.timefuncs import tnow, tdiffsec
26 from nepi.resources.ns3.ns3simulation import NS3Simulation
27 from nepi.resources.ns3.ns3wrapper import SIMULATOR_UUID, GLOBAL_VALUE_UUID, \
28         IPV4_GLOBAL_ROUTING_HELPER_UUID
29 from nepi.resources.linux.ns3.ns3client import LinuxNS3Client
30
31 import os
32 import time
33 import threading
34
35 @clsinit_copy
36 class LinuxNS3Simulation(LinuxApplication, NS3Simulation):
37     _rtype = "linux::ns3::Simulation"
38
39     @classmethod
40     def _register_attributes(cls):
41         impl_type = Attribute("simulatorImplementationType",
42                 "The object class to use as the simulator implementation",
43             allowed = ["ns3::DefaultSimulatorImpl", "ns3::RealtimeSimulatorImpl"],
44             default = "ns3::DefaultSimulatorImpl",
45             type = Types.Enumerate,
46             flags = Flags.Design)
47
48         sched_type = Attribute("schedulerType",
49                 "The object class to use as the scheduler implementation",
50                 allowed = ["ns3::MapScheduler",
51                             "ns3::ListScheduler",
52                             "ns3::HeapScheduler",
53                             "ns3::MapScheduler",
54                             "ns3::CalendarScheduler"
55                     ],
56             default = "ns3::MapScheduler",
57             type = Types.Enumerate,
58             flags = Flags.Design)
59
60         check_sum = Attribute("checksumEnabled",
61                 "A global switch to enable all checksums for all protocols",
62             default = False,
63             type = Types.Bool,
64             flags = Flags.Design)
65
66         ns_log = Attribute("nsLog",
67             "NS_LOG environment variable. " \
68                     " Will only generate output if ns-3 is compiled in DEBUG mode. ",
69             flags = Flags.Design)
70
71         verbose = Attribute("verbose",
72             "True to output debugging info from the ns3 client-server communication",
73             type = Types.Bool,
74             flags = Flags.Design)
75
76         enable_dump = Attribute("enableDump",
77             "Enable dumping the remote executed ns-3 commands to a script "
78             "in order to later reproduce and debug the experiment",
79             type = Types.Bool,
80             default = False,
81             flags = Flags.Design)
82
83         build_mode = Attribute("buildMode",
84             "Mode used to build ns-3 with waf. One if: debug, release, oprimized ",
85             default = "optimized", 
86             allowed = ["debug", "release", "optimized"],
87             type = Types.Enumerate,
88             flags = Flags.Design)
89
90         ns3_version = Attribute("ns3Version",
91             "Version of ns-3 to install from nsam repo",
92             default = "ns-3.20", 
93             #default = "ns-3-dev", 
94             flags = Flags.Design)
95
96         pybindgen_version = Attribute("pybindgenVersion",
97             "Version of pybindgen to install from bazar repo",
98             default = "868", 
99             #default = "876", 
100             flags = Flags.Design)
101
102         dce_version = Attribute("dceVersion",
103             "Version of dce to install from nsam repo (tag branch for repo)",
104             #default = "dce-1.3", 
105             default = "dce-dev", 
106             flags = Flags.Design)
107
108         populate_routing_tables = Attribute("populateRoutingTables",
109             "Invokes  Ipv4GlobalRoutingHelper.PopulateRoutingTables() ",
110             default = False,
111             type = Types.Bool,
112             flags = Flags.Design)
113
114         stoptime = Attribute("StopTime",
115             "Time at which the simulation will stop",
116             flags = Flags.Design)
117
118         cls._register_attribute(impl_type)
119         cls._register_attribute(sched_type)
120         cls._register_attribute(check_sum)
121         cls._register_attribute(ns_log)
122         cls._register_attribute(enable_dump)
123         cls._register_attribute(verbose)
124         cls._register_attribute(build_mode)
125         cls._register_attribute(ns3_version)
126         cls._register_attribute(pybindgen_version)
127         cls._register_attribute(dce_version)
128         cls._register_attribute(populate_routing_tables)
129         cls._register_attribute(stoptime)
130
131     def __init__(self, ec, guid):
132         LinuxApplication.__init__(self, ec, guid)
133         NS3Simulation.__init__(self)
134
135         self._client = None
136         self._home = "ns3-simu-%s" % self.guid
137         self._socket_name = "ns3-%s.sock" % os.urandom(4).encode('hex')
138         self._enable_dce = None
139         self._dce_helper = None
140
141     @property
142     def socket_name(self):
143         return self._socket_name
144
145     @property
146     def remote_socket(self):
147         return os.path.join(self.run_home, self.socket_name)
148
149     def trace(self, name, attr = TraceAttr.ALL, block = 512, offset = 0):
150         # stout needs to get flushed on the ns-3 server side, else we will 
151         # get an empty stream. We try twice to retrieve the stream
152         # if we get empty stdout since the stream might not be
153         # flushed immediately.
154         if name.endswith("stdout"):
155             self._client.flush() 
156             result = LinuxApplication.trace(self, name, attr, block, offset)
157             if result:
158                 return result
159             # Let the stream be flushed
160             time.sleep(1)
161
162         return LinuxApplication.trace(self, name, attr, block, offset)
163
164     def upload_sources(self):
165         self.node.mkdir(os.path.join(self.node.src_dir, "ns3wrapper"))
166
167         # upload ns3 wrapper python script
168         ns3_wrapper = os.path.join(os.path.dirname(__file__), "..", "..", "ns3", 
169                 "ns3wrapper.py")
170
171         self.node.upload(ns3_wrapper,
172                 os.path.join(self.node.src_dir, "ns3wrapper", "ns3wrapper.py"),
173                 overwrite = False)
174
175         # upload ns3 wrapper debug python script
176         ns3_wrapper_debug = os.path.join(os.path.dirname(__file__), "..", "..", "ns3", 
177                 "ns3wrapper_debug.py")
178
179         self.node.upload(ns3_wrapper_debug,
180                 os.path.join(self.node.src_dir, "ns3wrapper", "ns3wrapper_debug.py"),
181                 overwrite = False)
182
183         # upload ns3_server python script
184         ns3_server = os.path.join(os.path.dirname(__file__), "..", "..", "ns3",
185                 "ns3server.py")
186
187         self.node.upload(ns3_server,
188                 os.path.join(self.node.src_dir, "ns3wrapper", "ns3server.py"),
189                 overwrite = False)
190
191         if self.node.use_rpm:
192             # upload pygccxml sources
193             pygccxml_tar = os.path.join(os.path.dirname(__file__), "dependencies",
194                     "%s.tar.gz" % self.pygccxml_version)
195
196             self.node.upload(pygccxml_tar,
197                     os.path.join(self.node.src_dir, "%s.tar.gz" % self.pygccxml_version),
198                     overwrite = False)
199
200         # Upload user defined ns-3 sources
201         self.node.mkdir(os.path.join(self.node.src_dir, "ns-3"))
202         src_dir = os.path.join(self.node.src_dir, "ns-3")
203
204         super(LinuxNS3Simulation, self).upload_sources(src_dir = src_dir)
205     
206     def upload_extra_sources(self, sources = None, src_dir = None):
207         return super(LinuxNS3Simulation, self).upload_sources(
208                 sources = sources, 
209                 src_dir = src_dir)
210
211     def upload_start_command(self):
212         command = self.get("command")
213         env = self.get("env")
214
215         # We want to make sure the ccnd is running
216         # before the experiment starts.
217         # Run the command as a bash script in background,
218         # in the host ( but wait until the command has
219         # finished to continue )
220         env = self.replace_paths(env)
221         command = self.replace_paths(command)
222
223         shfile = os.path.join(self.app_home, "start.sh")
224         self.node.upload_command(command, 
225                     shfile = shfile,
226                     env = env,
227                     overwrite = True)
228
229         # Run the ns3wrapper 
230         self._run_in_background()
231
232         # Wait until the remote socket is created
233         self.wait_remote_socket()
234
235     def configure(self):
236         if self.has_changed("simulatorImplementationType"):
237             simu_type = self.get("simulatorImplementationType")
238             stype = self.create("StringValue", simu_type)
239             self.invoke(GLOBAL_VALUE_UUID, "Bind", "SimulatorImplementationType", stype)
240
241         if self.has_changed("checksumEnabled"):
242             check_sum = self.get("checksumEnabled")
243             btrue = self.create("BooleanValue", check_sum)    
244             self.invoke(GLOBAL_VALUE_UUID, "Bind", "ChecksumEnabled", btrue)
245         
246         if self.has_changed("schedulerType"):
247             sched_type = self.get("schedulerType")
248             stype = self.create("StringValue", sched_type)
249             self.invoke(GLOBAL_VALUE_UUID, "Bind", "SchedulerType", btrue)
250         
251     def do_deploy(self):
252         if not self.node or self.node.state < ResourceState.READY:
253             self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state )
254             
255             # ccnd needs to wait until node is deployed and running
256             self.ec.schedule(self.reschedule_delay, self.deploy)
257         else:
258             if not self.get("command"):
259                 self.set("command", self._start_command)
260             
261             if not self.get("depends"):
262                 self.set("depends", self._dependencies)
263
264             if self.get("sources"):
265                 sources = self.get("sources")
266                 source = sources.split(" ")[0]
267                 basename = os.path.basename(source)
268                 version = ( basename.strip().replace(".tar.gz", "")
269                     .replace(".tar","")
270                     .replace(".gz","")
271                     .replace(".zip","") )
272
273                 self.set("ns3Version", version)
274                 self.set("sources", source)
275
276             if not self.get("build"):
277                 self.set("build", self._build)
278
279             if not self.get("install"):
280                 self.set("install", self._install)
281
282             if not self.get("env"):
283                 self.set("env", self._environment)
284
285             self.do_discover()
286             self.do_provision()
287
288             # Create client
289             self._client = LinuxNS3Client(self)
290
291             self.configure()
292             
293             self.set_ready()
294
295     def do_start(self):
296         """ Starts simulation execution
297
298         """
299         self.info("Starting")
300
301         if self.state == ResourceState.READY:
302             if self.get("populateRoutingTables") == True:
303                 self.invoke(IPV4_GLOBAL_ROUTING_HELPER_UUID, "PopulateRoutingTables")
304
305             time = self.get("StopTime")
306             if time:
307                 self._client.stop(time=time) 
308
309             self._client.start()
310
311             self.set_started()
312         else:
313             msg = " Failed to execute command '%s'" % command
314             self.error(msg, out, err)
315             raise RuntimeError, msg
316
317     def do_stop(self):
318         """ Stops simulation execution
319
320         """
321         if self.state == ResourceState.STARTED:
322             if not self.get("StopTime"):
323                 self._client.stop() 
324             self.set_stopped()
325
326     def do_release(self):
327         self.info("Releasing resource")
328
329         tear_down = self.get("tearDown")
330         if tear_down:
331             self.node.execute(tear_down)
332
333         self.do_stop()
334         self._client.shutdown()
335         LinuxApplication.do_stop(self)
336         
337         super(LinuxApplication, self).do_release()
338
339     @property
340     def enable_dce(self):
341         if self._enable_dce is None:
342             from nepi.resources.ns3.ns3dceapplication import NS3BaseDceApplication
343             rclass = ResourceFactory.get_resource_type(
344                     NS3BaseDceApplication.get_rtype())
345             
346             self._enable_dce = False
347             for guid in self.ec.resources:
348                 rm = self.ec.get_resource(guid)
349                 if isinstance(rm, rclass):
350                     self._enable_dce = True
351
352                     from nepi.resources.ns3.ns3dcehelper import NS3DceHelper
353                     self._dce_helper = NS3DceHelper(self)
354                     break
355
356         return self._enable_dce
357
358     @property
359     def dce_helper(self):
360         return self._dce_helper
361         
362     @property
363     def _start_command(self):
364         command = [] 
365
366         command.append("PYTHONPATH=$PYTHONPATH:${SRC}/ns3wrapper/")
367         
368         command.append("python ${SRC}/ns3wrapper/ns3server.py -S %s" % \
369                 os.path.basename(self.remote_socket) )
370
371         ns_log = self.get("nsLog")
372         if ns_log:
373             command.append("-L '%s'" % ns_log)
374
375         if self.get("enableDump"):
376             command.append("-D")
377
378         if self.get("verbose"):
379             command.append("-v")
380
381         command = " ".join(command)
382         return command
383
384     @property
385     def _dependencies(self):
386         if self.node.use_rpm:
387             return ( " gcc gcc-c++ python python-devel mercurial bzr tcpdump socat gccxml unzip")
388         elif self.node.use_deb:
389             return ( " gcc g++ python python-dev mercurial bzr tcpdump socat gccxml python-pygccxml unzip")
390         return ""
391
392     @property
393     def ns3_repo(self):
394         return "http://code.nsnam.org"
395
396     @property
397     def pygccxml_version(self):
398         return "pygccxml-1.0.0"
399
400     @property
401     def dce_repo(self):
402         return "http://code.nsnam.org/ns-3-dce"
403         #eturn "http://code.nsnam.org/epmancini/ns-3-dce"
404
405     @property
406     def dce_version(self):
407         dce_version = self.get("dceVersion")
408         return dce_version or "dce-dev"
409
410     @property
411     def ns3_build_location(self):
412         location = "${BIN}/ns-3/%(ns3_version)s%(dce_version)s/%(build_mode)s/build" \
413                     % {
414                         "ns3_version": self.get("ns3Version"),
415                         "dce_version": "-%s" % self.get("dceVersion") \
416                                 if self.enable_dce else "", 
417                         "build_mode": self.get("buildMode"),
418                       }
419
420         return location
421  
422
423     @property
424     def ns3_src_location(self):
425         location = "${SRC}/ns-3/%(ns3_version)s" \
426                     % {
427                         "ns3_version": self.get("ns3Version"),
428                       }
429
430         return location
431  
432     @property
433     def dce_src_location(self):
434         location = "${SRC}/ns-3-dce/%(dce_version)s" \
435                    % {
436                         "dce_version": self.get("dceVersion"),
437                      }
438
439         return location
440
441     @property
442     def _clone_ns3_command(self):
443         source = self.get("sources")
444         
445         if not source:
446             clone_ns3_cmd = "hg clone %(ns3_repo)s/%(ns3_version)s %(ns3_src)s" \
447                     % {
448                         "ns3_version": self.get("ns3Version"),
449                         "ns3_repo": self.ns3_repo,  
450                         "ns3_src": self.ns3_src_location,
451                       }
452         else:
453             if source.find(".tar.gz") > -1:
454                 clone_ns3_cmd = ( 
455                             "tar xzf ${SRC}/ns-3/%(basename)s " 
456                             " --strip-components=1 -C %(ns3_src)s"
457                             ) % {
458                                 "basename": os.path.basename(source),
459                                 "ns3_src": self.ns3_src_location,
460                                 }
461             elif source.find(".tar") > -1:
462                 clone_ns3_cmd = ( 
463                             "tar xf ${SRC}/ns-3/%(basename)s " 
464                             " --strip-components=1 -C %(ns3_src)s"
465                             ) % {
466                                 "basename": os.path.basename(source),
467                                 "ns3_src": self.ns3_src_location,
468                                 }
469             elif source.find(".zip") > -1:
470                 basename = os.path.basename(source)
471                 bare_basename = basename.replace(".zip", "") 
472
473                 clone_ns3_cmd = ( 
474                             "unzip ${SRC}/ns-3/%(basename)s && "
475                             "mv ${SRC}/ns-3/%(bare_basename)s %(ns3_src)s"
476                             ) % {
477                                 "bare_basename": basename_name,
478                                 "basename": basename,
479                                 "ns3_src": self.ns3_src_location,
480                                 }
481
482         return clone_ns3_cmd
483
484     @property
485     def _clone_dce_command(self):
486         clone_dce_cmd = " echo 'DCE will not be built' "
487
488         if self.enable_dce:
489             dce_version = self.dce_version
490             dce_tag = ""
491             if dce_version != "dce-dev":
492                 dce_tag = "-r %s" % dce_version
493
494             clone_dce_cmd = (
495                         # DCE installation
496                         # Test if dce is alredy cloned
497                         " ( "
498                         "  ( "
499                         "    ( test -d %(dce_src)s ) "
500                         "   && echo 'dce binaries found, nothing to do'"
501                         "  ) "
502                         " ) "
503                         "  || " 
504                         # Get dce source code
505                         " ( "
506                         "   mkdir -p %(dce_src)s && "
507                         "   hg clone %(dce_repo)s %(dce_tag)s %(dce_src)s"
508                         " ) "
509                      ) % {
510                             "dce_repo": self.dce_repo,
511                             "dce_tag": dce_tag,
512                             "dce_src": self.dce_src_location,
513                          }
514
515         return clone_dce_cmd
516
517     @property
518     def _build(self):
519         # If the user defined local sources for ns-3, we uncompress the sources
520         # on the remote sources directory. Else we clone ns-3 from the official repo.
521         clone_ns3_cmd = self._clone_ns3_command
522         clone_dce_cmd = self._clone_dce_command
523
524         ns3_build_cmd = (
525                 # NS3 installation
526                 "( "
527                 " ( "
528                 # Test if ns-3 is alredy cloned
529                 "  ((( test -d %(ns3_src)s ) || "
530                 "    ( test -d ${NS3BINDINGS:='None'} && test -d ${NS3LIBRARIES:='None'})) "
531                 "  && echo 'ns-3 binaries found, nothing to do' )"
532                 " ) "
533                 "  || " 
534                 # If not, install ns-3 and its dependencies
535                 " (   "
536                 # Install pygccxml
537                 "   (   "
538                 "     ( "
539                 "       python -c 'import pygccxml' && "
540                 "       echo 'pygccxml not found' "
541                 "     ) "
542                 "      || "
543                 "     ( "
544                 "       tar xf ${SRC}/%(pygccxml_version)s.tar.gz -C ${SRC} && "
545                 "       cd ${SRC}/%(pygccxml_version)s && "
546                 "       python setup.py build && "
547                 "       sudo -S python setup.py install "
548                 "     ) "
549                 "   ) " 
550                 # Install pybindgen
551                 "  && "
552                 "   (   "
553                 "     ( "
554                 "       test -d ${SRC}/pybindgen/%(pybindgen_version)s && "
555                 "       echo 'binaries found, nothing to do' "
556                 "     ) "
557                 "      || "
558                 # If not, clone and build
559                 "      ( cd ${SRC} && "
560                 "        mkdir -p ${SRC}/pybindgen && "
561                 "        bzr checkout lp:pybindgen -r %(pybindgen_version)s ${SRC}/pybindgen/%(pybindgen_version)s && "
562                 "        cd ${SRC}/pybindgen/%(pybindgen_version)s && "
563                 "        ./waf configure && "
564                 "        ./waf "
565                 "      ) "
566                 "   ) " 
567                 " && "
568                 # Get ns-3 source code
569                 "  ( "
570                 "     mkdir -p %(ns3_src)s && "
571                 "     %(clone_ns3_cmd)s "
572                 "  ) "
573                 " ) "
574                 ") "
575                 " && "
576                 "( "
577                 "   %(clone_dce_cmd)s "
578                 ") "
579              ) % { 
580                     "ns3_src": self.ns3_src_location,
581                     "pybindgen_version": self.get("pybindgenVersion"),
582                     "pygccxml_version": self.pygccxml_version,
583                     "clone_ns3_cmd": clone_ns3_cmd,
584                     "clone_dce_cmd": clone_dce_cmd,
585                  }
586
587         return ns3_build_cmd
588
589     @property
590     def _install_dce_command(self):
591         install_dce_cmd = " echo 'DCE will not be installed'"
592
593         if self.enable_dce:
594             install_dce_cmd = (
595                         " ( "
596                         "   ((test -d %(ns3_build)s/bin_dce ) && "
597                         "    echo 'dce binaries found, nothing to do' )"
598                         " ) "
599                         " ||" 
600                         " (   "
601                          # If not, copy build to dce
602                         "  cd %(dce_src)s && "
603                         "  rm -rf %(dce_src)s/build && "
604                         "  ./waf configure %(enable_opt)s --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s "
605                         "  --prefix=%(ns3_build)s --with-ns3=%(ns3_build)s && "
606                         "  ./waf build && "
607                         "  ./waf install && "
608                         "  [ ! -e %(ns3_build)s/lib/python/site-packages/ns/dce.so ] && "
609                         "   mv %(ns3_build)s/lib*/python*/site-packages/ns/dce.so %(ns3_build)s/lib/python/site-packages/ns/ "
610                         " )"
611                 ) % { 
612                     "pybindgen_version": self.get("pybindgenVersion"),
613                     "enable_opt": "--enable-opt" if  self.get("buildMode") == "optimized" else "",
614                     "ns3_build": self.ns3_build_location,
615                     "dce_src": self.dce_src_location,
616                      }
617
618         return install_dce_cmd
619
620     @property
621     def _install(self):
622         install_dce_cmd = self._install_dce_command
623
624         install_ns3_cmd = (
625                  # Test if ns-3 is alredy installed
626                 "("
627                 " ( "
628                 "  ( ( (test -d %(ns3_build)s/lib ) || "
629                 "    (test -d ${NS3BINDINGS:='None'} && test -d ${NS3LIBRARIES:='None'}) ) && "
630                 "    echo 'binaries found, nothing to do' )"
631                 " ) "
632                 " ||" 
633                 " (   "
634                  # If not, copy ns-3 build to bin
635                 "  mkdir -p %(ns3_build)s && "
636                 "  cd %(ns3_src)s && "
637                 "  rm -rf %(ns3_src)s/build && "
638                 "  ./waf configure -d %(build_mode)s --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s "
639                 "  --prefix=%(ns3_build)s && "
640                 "  ./waf build && "
641                 "  ./waf install && "
642                 "  mv %(ns3_build)s/lib*/python* %(ns3_build)s/lib/python "
643                 " )"
644                 ") "
645                 " && "
646                 "( "
647                 "   %(install_dce_cmd)s "
648                 ") "
649               ) % { 
650                     "pybindgen_version": self.get("pybindgenVersion"),
651                     "build_mode": self.get("buildMode"),
652                     "install_dce_cmd": install_dce_cmd,
653                     "ns3_build": self.ns3_build_location,
654                     "ns3_src": self.ns3_src_location,
655                  }
656
657         return install_ns3_cmd
658
659     @property
660     def _environment(self):
661         env = []
662         env.append("PYTHONPATH=$PYTHONPATH:${NS3BINDINGS:=%(ns3_build)s/lib/python/site-packages}" % { 
663                     "ns3_build": self.ns3_build_location
664                  })
665         # If NS3LIBRARIES is defined and not empty, assign its value, 
666         # if not assign ns3_build_home/lib/ to NS3LIBRARIES and LD_LIBARY_PATH
667         env.append("LD_LIBRARY_PATH=${NS3LIBRARIES:=%(ns3_build)s/lib}" % { 
668                     "ns3_build": self.ns3_build_location
669                  })
670         env.append("DCE_PATH=$NS3LIBRARIES/../bin_dce")
671         env.append("DCE_ROOT=$NS3LIBRARIES/..")
672
673         return " ".join(env) 
674
675     def replace_paths(self, command):
676         """
677         Replace all special path tags with shell-escaped actual paths.
678         """
679         return ( command
680             .replace("${USR}", self.node.usr_dir)
681             .replace("${LIB}", self.node.lib_dir)
682             .replace("${BIN}", self.node.bin_dir)
683             .replace("${SRC}", self.node.src_dir)
684             .replace("${SHARE}", self.node.share_dir)
685             .replace("${EXP}", self.node.exp_dir)
686             .replace("${EXP_HOME}", self.node.exp_home)
687             .replace("${APP_HOME}", self.app_home)
688             .replace("${RUN_HOME}", self.run_home)
689             .replace("${NODE_HOME}", self.node.node_home)
690             .replace("${HOME}", self.node.home_dir)
691             # If NS3LIBRARIES is defined and not empty, use that value, 
692             # if not use ns3_build_home/lib/
693             .replace("${BIN_DCE}", "${NS3LIBRARIES-%s/lib}/../bin_dce" % \
694                     self.ns3_build_location)
695             )
696
697     def valid_connection(self, guid):
698         # TODO: Validate!
699         return True
700
701     def wait_remote_socket(self):
702         """ Waits until the remote socket is created
703         """
704         command = " [ -e %s ] && echo 'DONE' " % self.remote_socket
705
706         for i in xrange(200):
707             (out, err), proc = self.node.execute(command, retry = 1, 
708                     with_lock = True)
709
710             if out.find("DONE") > -1:
711                 break
712         else:
713             raise RuntimeError("Remote socket not found at %s" % \
714                     self.remote_socket)
715     
716