enable automatic node stack
[nepi.git] / src / nepi / resources / ns3 / ns3node.py
index 0c0d876..8598979 100644 (file)
@@ -25,6 +25,17 @@ from nepi.resources.ns3.ns3base import NS3Base
 class NS3BaseNode(NS3Base):
     _rtype = "abstract::ns3::Node"
 
+    @classmethod
+    def _register_attributes(cls):
+        enablestack = Attribute("enableStack", 
+                "Install network stack in Node, including: ARP, "
+                "IP4, ICMP, UDP and TCP ",
+                type = Types.Bool,
+                default = False,
+                flags = Flags.Design)
+
+        cls._register_attribute(enablestack)
+
     @property
     def simulation(self):
         from nepi.resources.ns3.ns3simulation import NS3Simulation
@@ -86,9 +97,13 @@ class NS3BaseNode(NS3Base):
         return rms
 
     def _configure_object(self):
-        ### node.AggregateObject(PacketSocketFactory())
-        uuid_packet_socket_factory = self.simulation.create("PacketSocketFactory")
-        self.simulation.invoke(self.uuid, "AggregateObject", uuid_packet_socket_factory)
+        if self.get("enableStack"):
+            uuid_stack_helper = self.simulation.create("InternetStackHelper")
+            self.simulation.invoke(uuid_stack_helper, "Install", self.uuid)
+        else:
+            ### node.AggregateObject(PacketSocketFactory())
+            uuid_packet_socket_factory = self.simulation.create("PacketSocketFactory")
+            self.simulation.invoke(self.uuid, "AggregateObject", uuid_packet_socket_factory)
 
         dceapplications = self.dceapplications
         if dceapplications: