X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=src%2Fnepi%2Fresources%2Flinux%2Fns3%2Fns3simulation.py;h=deca9748c4353e6975f3f11e9a459ade9e8f8105;hb=a30a625a864a459755199598beb977dfd6064698;hp=e026bb8109973a9ec7cc82fd96ea2747a762a2dd;hpb=a7e76f2c5b9646f44e5cbf6c558ed08b5b73ce28;p=nepi.git diff --git a/src/nepi/resources/linux/ns3/ns3simulation.py b/src/nepi/resources/linux/ns3/ns3simulation.py index e026bb81..deca9748 100644 --- a/src/nepi/resources/linux/ns3/ns3simulation.py +++ b/src/nepi/resources/linux/ns3/ns3simulation.py @@ -89,14 +89,9 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): default = "ns-3-dev", flags = Flags.Design) - enable_dce = Attribute("enableDCE", - "Install DCE source code", - default = False, - type = Types.Bool, - flags = Flags.Design) - pybindgen_version = Attribute("pybindgenVersion", "Version of pybindgen to install from bazar repo", + #default = "864", default = "868", flags = Flags.Design) @@ -115,7 +110,6 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): cls._register_attribute(ns3_version) cls._register_attribute(pybindgen_version) cls._register_attribute(populate_routing_tables) - cls._register_attribute(enable_dce) def __init__(self, ec, guid): LinuxApplication.__init__(self, ec, guid) @@ -126,11 +120,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): self._socket_name = "ns3-%s.sock" % os.urandom(4).encode('hex') self._dce_manager_helper_uuid = None self._dce_application_helper_uuid = None - - # Lock used to synchronize usage of DceManagerHelper - self.dce_manager_lock = threading.Lock() - # Lock used to synchronize usage of DceApplicationHelper - self.dce_application_lock = threading.Lock() + self._enable_dce = False @property def socket_name(self): @@ -140,14 +130,6 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): def remote_socket(self): return os.path.join(self.run_home, self.socket_name) - @property - def dce_manager_helper_uuid(self): - return self._dce_manager_helper_uuid - - @property - def dce_application_helper_uuid(self): - return self._dce_application_helper_uuid - @property def ns3_build_home(self): return os.path.join(self.node.bin_dir, "ns-3", self.get("ns3Version"), @@ -233,10 +215,6 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): stype = self.create("StringValue", sched_type) self.invoke(GLOBAL_VALUE_UUID, "Bind", "SchedulerType", btrue) - if self.get("enableDCE"): - self._dce_manager_helper_uuid = self.create("DceManagerHelper") - self._dce_application_helper_uuid = self.create("DceApplicationHelper") - def do_deploy(self): if not self.node or self.node.state < ResourceState.READY: self.debug("---- RESCHEDULING DEPLOY ---- node state %s " % self.node.state ) @@ -291,7 +269,22 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): if self.get("populateRoutingTables") == True: self.invoke(IPV4_GLOBAL_ROUTING_HELPER_UUID, "PopulateRoutingTables") - self._client.start() + self._client.start() + + # Wait until the Simulation is actually started... + is_running = False + for i in xrange(1000): + is_running = self.invoke(SIMULATOR_UUID, "isRunning") + + if is_running: + break + else: + time.sleep(1) + else: + if not is_running: + msg = " Simulation did not start" + self.error(msg) + raise RuntimeError self.set_started() else: @@ -320,6 +313,21 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): super(LinuxApplication, self).do_release() + @property + def enable_dce(self): + if self._enable_dce is None: + from nepi.resources.ns3.ns3dceapplication import NS3BaseDceApplication + rclass = ResourceFactory.get_resource_type(NS3BaseDceApplication) + + self._enable_dce = False + for guid in self.ec.resources: + rm = self.ec.get_resource(guid) + if isinstance(rm, rclass): + self._enable_dce = True + break + + return self._enable_dce + @property def _start_command(self): command = [] @@ -357,8 +365,8 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): @property def dce_repo(self): - #return "http://code.nsnam.org/ns-3-dce" - return "http://code.nsnam.org/epmancini/ns-3-dce" + return "http://code.nsnam.org/ns-3-dce" + #eturn "http://code.nsnam.org/epmancini/ns-3-dce" @property def _build(self): @@ -404,7 +412,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): } clone_dce_cmd = " echo 'DCE will not be built' " - if self.get("enableDCE"): + if self.enable_dce: clone_dce_cmd = ( # DCE installation # Test if dce is alredy installed @@ -424,7 +432,6 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): 'dce_repo': self.dce_repo } - return ( # NS3 installation "( " @@ -491,7 +498,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): @property def _install(self): install_dce_cmd = " echo 'DCE will not be installed' " - if self.get("enableDCE"): + if self.enable_dce: install_dce_cmd = ( " ( " " ((test -d %(ns3_build_home)s/bin_dce ) && " @@ -501,6 +508,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): " ( " # If not, copy ns-3 build to bin " cd ${SRC}/dce/ns-3-dce && " + " rm -rf ${SRC}/dce/ns-3-dce/build && " " ./waf configure %(enable_opt)s --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s " " --prefix=%(ns3_build_home)s --with-ns3=%(ns3_build_home)s && " " ./waf build && " @@ -528,6 +536,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): # If not, copy ns-3 build to bin " mkdir -p %(ns3_build_home)s && " " cd ${SRC}/ns-3/%(ns3_version)s && " + " rm -rf ${SRC}/ns-3/%(ns3_version)s/build && " " ./waf configure -d %(build_mode)s --with-pybindgen=${SRC}/pybindgen/%(pybindgen_version)s " " --prefix=%(ns3_build_home)s && " " ./waf build && " @@ -581,7 +590,7 @@ class LinuxNS3Simulation(LinuxApplication, NS3Simulation): .replace("${HOME}", self.node.home_dir) # If NS3LIBRARIES is defined and not empty, use that value, # if not use ns3_build_home/lib/ - .replace("${BIN_DCE}", "${NS3LIBRARIES-%s/lib/}../bin_dce" % \ + .replace("${BIN_DCE}", "${NS3LIBRARIES-%s/lib}/../bin_dce" % \ self.ns3_build_home) )