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