#
# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
-from nepi.execution.resource import clsinit_copy
+from nepi.execution.resource import clsinit_copy, ResourceState
from nepi.resources.ns3.ns3base import NS3Base
@clsinit_copy
class NS3BaseApplication(NS3Base):
_rtype = "abstract::ns3::Application"
+ @property
+ def node(self):
+ from nepi.resources.ns3.ns3node import NS3BaseNode
+ nodes = self.get_connected(NS3BaseNode.get_rtype())
+
+ if not nodes:
+ msg = "Application not connected to node"
+ self.error(msg)
+ raise RuntimeError, msg
+
+ return nodes[0]
+
+ @property
+ def _rms_to_wait(self):
+ rms = set()
+ rms.add(self.node)
+ return rms
+
def _connect_object(self):
node = self.node
- if node and node.uuid not in self.connected:
- self.simulator.invoke(node.uuid, "AddApplication", self.uuid)
+ if node.uuid not in self.connected:
+ self.simulation.invoke(node.uuid, "AddApplication", self.uuid)
self._connected.add(node.uuid)
- def do_start(self):
- if self.state == ResourceState.READY:
- self.info("Starting")
-
- # BUG: without doing this explicit call it doesn't start!!!
- # Shouldn't be enough to set the StartTime?
- self.simulator.invoke(self.uuid, "Start")
-
- self.set_started()
- else:
- msg = " Failed "
- self.error(msg, out, err)
- raise RuntimeError, msg
-
def do_stop(self):
if self.state == ResourceState.STARTED:
- # No need to do anything, simulator.Destroy() will stop every object
+ # No need to do anything, simulation.Destroy() will stop every object
self.info("Stopping command '%s'" % command)
- self.simulator.invoke(self.uuid, "Stop")
+ self.simulation.invoke(self.uuid, "Stop")
self.set_stopped()
+ @property
+ def state(self):
+ if self._state == ResourceState.STARTED:
+ is_running = self.simulation.invoke(self.uuid, "isAppRunning")
+
+ if not is_running:
+ self.set_stopped()
+
+ return self._state
+