DCE traces working
[nepi.git] / src / nepi / resources / ns3 / ns3node.py
index b0e5dcf..b6188e3 100644 (file)
@@ -17,6 +17,7 @@
 #
 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
 
+from nepi.execution.attribute import Attribute, Flags, Types
 from nepi.execution.resource import clsinit_copy
 from nepi.resources.ns3.ns3base import NS3Base
 
@@ -24,6 +25,16 @@ from nepi.resources.ns3.ns3base import NS3Base
 class NS3BaseNode(NS3Base):
     _rtype = "abstract::ns3::Node"
 
+    @classmethod
+    def _register_attributes(cls):
+        enable_dce = Attribute("enableDCE", 
+                "This node will run in DCE emulation mode ",
+                default = False,
+                type = Types.Bool,
+                flags = Flags.Design)
+
+        cls._register_attribute(enable_dce)
+
     @property
     def simulation(self):
         from nepi.resources.ns3.ns3simulation import NS3Simulation
@@ -50,6 +61,18 @@ class NS3BaseNode(NS3Base):
         if mobility: return mobility[0]
         return None
 
+    @property
+    def devices(self):
+        from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
+        devices = self.get_connected(NS3BaseNetDevice.get_rtype())
+
+        if not devices: 
+            msg = "Node not connected to devices"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return devices
+
     @property
     def _rms_to_wait(self):
         rms = set()
@@ -70,6 +93,9 @@ class NS3BaseNode(NS3Base):
         uuid_packet_socket_factory = self.simulation.create("PacketSocketFactory")
         self.simulation.invoke(self.uuid, "AggregateObject", uuid_packet_socket_factory)
 
+        if self.get("enableDCE") == True:
+            self._add_dce()
+
     def _connect_object(self):
         ipv4 = self.ipv4
         if ipv4:
@@ -79,4 +105,10 @@ class NS3BaseNode(NS3Base):
         if mobility:
             self.simulation.invoke(self.uuid, "AggregateObject", mobility.uuid)
 
+    def _add_dce(self):
+        container_uuid = self.simulation.create("NodeContainer")
+        self.simulation.invoke(container_uuid, "Add", self.uuid)
+        with self.simulation.dce_manager_lock:
+            self.simulation.invoke(self.simulation.dce_manager_helper_uuid, 
+                    "Install", container_uuid)