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