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