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