2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
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.
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.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.attribute import Attribute, Flags, Types
21 from nepi.execution.resource import clsinit_copy
22 from nepi.resources.ns3.ns3base import NS3Base
25 class NS3BaseNode(NS3Base):
26 _rtype = "abstract::ns3::Node"
29 def _register_attributes(cls):
30 enablestack = Attribute("enableStack",
31 "Install network stack in Node, including: ARP, "
32 "IP4, ICMP, UDP and TCP ",
37 cls._register_attribute(enablestack)
41 from nepi.resources.ns3.ns3simulation import NS3Simulation
42 for guid in self.connections:
43 rm = self.ec.get_resource(guid)
44 if isinstance(rm, NS3Simulation):
47 msg = "Node not connected to simulation"
49 raise RuntimeError, msg
53 from nepi.resources.ns3.ns3ipv4l3protocol import NS3BaseIpv4L3Protocol
54 ipv4s = self.get_connected(NS3BaseIpv4L3Protocol.get_rtype())
55 if ipv4s: return ipv4s[0]
60 from nepi.resources.ns3.ns3arpl3protocol import NS3BaseArpL3Protocol
61 arps = self.get_connected(NS3BaseArpL3Protocol.get_rtype())
62 if arps: return arps[0]
67 from nepi.resources.ns3.ns3mobilitymodel import NS3BaseMobilityModel
68 mobility = self.get_connected(NS3BaseMobilityModel.get_rtype())
69 if mobility: return mobility[0]
74 from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
75 devices = self.get_connected(NS3BaseNetDevice.get_rtype())
78 msg = "Node not connected to devices"
80 raise RuntimeError, msg
85 def dceapplications(self):
86 from nepi.resources.ns3.ns3dceapplication import NS3BaseDceApplication
87 dceapplications = self.get_connected(NS3BaseDceApplication.get_rtype())
89 return dceapplications
92 def _rms_to_wait(self):
94 rms.add(self.simulation)
104 mobility = self.mobility
110 def _configure_object(self):
111 if self.get("enableStack"):
112 uuid_stack_helper = self.simulation.create("InternetStackHelper")
113 self.simulation.invoke(uuid_stack_helper, "Install", self.uuid)
115 ### node.AggregateObject(PacketSocketFactory())
116 uuid_packet_socket_factory = self.simulation.create("PacketSocketFactory")
117 self.simulation.invoke(self.uuid, "AggregateObject", uuid_packet_socket_factory)
119 dceapplications = self.dceapplications
121 self._add_dce(dceapplications)
123 def _connect_object(self):
126 self.simulation.invoke(self.uuid, "AggregateObject", ipv4.uuid)
127 self._connected.add(ipv4.uuid)
128 ipv4._connected.add(self.uuid)
132 self.simulation.invoke(self.uuid, "AggregateObject", arp.uuid)
133 self._connected.add(arp.uuid)
134 arp._connected.add(self.uuid)
136 mobility = self.mobility
138 self.simulation.invoke(self.uuid, "AggregateObject", mobility.uuid)
139 self._connected.add(mobility.uuid)
140 mobility._connected.add(self.uuid)
142 def _add_dce(self, dceapplications):
143 dceapp = dceapplications[0]
145 container_uuid = self.simulation.create("NodeContainer")
146 self.simulation.invoke(container_uuid, "Add", self.uuid)
147 with dceapp.dce_manager_lock:
148 self.simulation.invoke(dceapp.dce_manager_helper_uuid,
149 "Install", container_uuid)