continue
if issubclass(attr, ResourceManager):
+ if find(attr.get_rtype().lower(), "abstract") > -1:
+ continue
+
types.append(attr)
if not modname in sys.modules:
@clsinit_copy
class NS3BaseApplication(NS3Base):
- _rtype = "ns3::Application"
+ _rtype = "abstract::ns3::Application"
def _connect_object(self):
node = self.node
from nepi.execution.resource import ResourceManager, clsinit_copy, \
ResourceState, reschedule_delay
-from nepi.execute.attributes import Flags
+from nepi.execution.attribute import Flags
from nepi.resources.ns3.ns3simulator import NS3Simulator
-from nepi.resources.ns3.ns3node import NS3BaseNode
@clsinit_copy
class NS3Base(ResourceManager):
- _rtype = "ns3::Object"
+ _rtype = "abstract::ns3::Object"
+ _backend_type = "ns3"
def __init__(self):
super(NS3Base, self).__init__()
@property
def node(self):
+ from nepi.resources.ns3.ns3node import NS3BaseNode
nodes = self.get_connected(NS3BaseNode.get_rtype())
if nodes: return nodes[0]
return None
# self.simulator.node.mkdir(self.run_home)
self._instantiate_object()
- self._configure_object()
self._connect_object()
+ self._configure_object()
self.info("Provisioning finished")
from nepi.execution.resource import clsinit_copy
from nepi.resources.ns3.ns3base import NS3Base
-from nepi.resources.ns3.ns3device import NS3BaseNetDevice
@clsinit_copy
class NS3BaseChannel(NS3Base):
- _rtype = "ns3::Channel"
+ _rtype = "abstract::ns3::Channel"
@property
def devices(self):
+ from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
return self.get_connected(NS3BaseNetDevice.get_rtype())
@property
--- /dev/null
+#
+# NEPI, a framework to manage network experiments
+# Copyright (C) 2014 INRIA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.resource import clsinit_copy
+from nepi.resources.ns3.ns3base import NS3Base
+
+@clsinit_copy
+class NS3BaseErrorModel(NS3Base):
+ _rtype = "abstract::ns3::ErrorModel"
+
+ @property
+ def device(self):
+ from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
+ devices = self.get_connected(NS3BaseNetDevice.get_rtype())
+ if devices: return devices[0]
+ return None
+
+ @property
+ def others_to_wait(self):
+ others = set()
+ device = self.device
+ if device: others.add(device)
+ return others
+
+ def _connect_object(self):
+ device = self.device
+ if device and device.uuid not in self.connected:
+ self.simulator.invoke(device.uuid, "SetReceiveErrorModel", self.uuid)
+ self._connected.add(device.uuid)
+
--- /dev/null
+#
+# NEPI, a framework to manage network experiments
+# Copyright (C) 2014 INRIA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.resource import clsinit_copy
+from nepi.resources.ns3.ns3base import NS3Base
+from nepi.resources.ns3.ns3wifiphy import NS3BaseWifiPhy
+
+@clsinit_copy
+class NS3BaseErrorRateModel(NS3Base):
+ _rtype = "abstract::ns3::ErrorRateModel"
+
+ @property
+ def phy(self):
+ phys = self.get_connected(NS3BaseWifiPhy.get_rtype())
+ if phys: return phys[0]
+ return None
+
+ @property
+ def others_to_wait(self):
+ others = set()
+ phy = self.phy
+ if phy: others.add(phy)
+ return others
+
+ def _connect_object(self):
+ phy = self.phy
+ if phy and phy.uuid not in self.connected:
+ self.simulator.invoke(phy.uuid, "SetErrorRateModel", self.uuid)
+ self._connected.add(phy.uuid)
+
from nepi.resources.ns3.ns3base import NS3Base
@clsinit_copy
-class NS3BaseIpV4Protocol(Ns3Base):
- _rtype = "ns3::IpV4Protocol"
-
- def do_provision(self):
- # create run dir for ns3 object
- # self.simulator.node.mkdir(self.run_home)
-
- self._instantiate_object()
+class NS3BaseIpv4L3Protocol(NS3Base):
+ _rtype = "abstract::ns3::Ipv4L3Protocol"
+ def _configure_object(self):
uuid_list_routing = simulator.create("Ipv4ListRouting")
simulator.invoke(self.uuid, "SetRoutingProtocol", uuid_list_routing)
uuid_static_routing = simulator.create("Ipv4StaticRouting")
simulator.invoke(self.uuid, "SetRoutingProtocol", uuid_static_routing, 1)
- super(NS3BaseIpV4Protocol, self).do_provision()
-
--- /dev/null
+#
+# NEPI, a framework to manage network experiments
+# Copyright (C) 2014 INRIA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.attribute import Attribute, Flags
+from nepi.execution.resource import clsinit_copy
+from nepi.resources.ns3.ns3base import NS3Base
+
+@clsinit_copy
+class NS3BaseNetDevice(NS3Base):
+ _rtype = "abstract::ns3::NetDevice"
+
+ @classmethod
+ def _register_attributes(cls):
+ mac = Attribute("mac", "MAC address for device",
+ flags = Flags.ExecReadOnly)
+
+ ip = Attribute("ip", "IP address for device",
+ flags = Flags.ExecReadOnly)
+
+ prefix = Attribute("prefix", "Network prefix for device",
+ flags = Flags.ExecReadOnly)
+
+ cls._register_attribute(mac)
+ cls._register_attribute(ip)
+ cls._register_attribute(prefix)
+
+ @property
+ def channel(self):
+ from nepi.resources.ns3.ns3channel import NS3Channel
+ channels = self.get_connected(NS3BaseChannel.get_rtype())
+ if channels: return channels[0]
+ return None
+
+ @property
+ def others_to_wait(self):
+ others = set()
+ node = self.node
+ if node: others.add(node)
+
+ channel = self.channel
+ if channel: others.add(channel)
+ return others
+
+ def _configure_object(self):
+ # Set Mac
+ mac = self.get("mac")
+ if mac:
+ mac_uuid = self.simulator.create("Mac48Address", mac)
+ else:
+ mac_uuid = self.simulator.invoke("singleton::Mac48Address", "Allocate")
+ self.simulator.invoke(self.uuid, "SetAddress", mac_uuid)
+
+ # Set IP address
+ ip = self.get("ip")
+ prefix = self.get("prefix")
+
+ i = ipaddr.IPAddress(ip)
+ if i.version == 4:
+ # IPv4
+ ipv4 = self.node.ipv4
+ ifindex_uuid = self.simulator.invoke(ipv4.uuid, "AddInterface",
+ self.uuid)
+ ipv4_addr_uuid = self.simulator.create("Ipv4Address", ip)
+ ipv4_mask_uuid = self.simulator.create("Ipv4Mask", "/%s" % str(prefix))
+ inaddr_uuid = self.simulator.create("Ipv4InterfaceAddress",
+ ipv4_addr_uuid, ipv4_mask_uuid)
+ self.simulator.invoke(ipv4.uuid, "AddAddress", ifindex_uuid,
+ inaddr_uuid)
+ self.simulator.invoke(ipv4.uuid, "SetMetric", ifindex_uuid, 1)
+ self.simulator.invoke(ipv4.uuid, "SetUp", ifindex_uuid)
+ else:
+ # IPv6
+ # TODO!
+ pass
+
+ def _connect_object(self):
+ node = self.node
+ if node and node.uuid not in self.connected:
+ self.simulator.invoke(node.uuid, "AddDevice", self.uuid)
+ self._connected.add(node.uuid)
+
+ channel = self.channel
+ if channel and channel.uuid not in self.connected:
+ self.simulator.invoke(self.uuid, "Attach", channel.uuid)
+ self._connected.add(channel.uuid)
+
from nepi.resources.ns3.ns3base import NS3Base
@clsinit_copy
-class NS3BaseNode(Ns3Base):
- _rtype = "ns3::Node"
+class NS3BaseNode(NS3Base):
+ _rtype = "abstract::ns3::Node"
+
+ @property
+ def ipv4(self):
+ from nepi.resources.ns3.ns3ipv4l3protocol import NS3BaseIpv4L3Protocol
+ ipv4s = self.get_connected(NS3BaseIpv4L3Protocol.get_rtype())
+ if ipv4s: return ipv4s[0]
+ return None
@property
def others_to_wait(self):
@clsinit_copy
class NS3BasePropagationDelayModel(NS3Base):
- _rtype = "ns3::PropagationDelayModel"
+ _rtype = "abstract::ns3::PropagationDelayModel"
@property
def simulator(self):
from nepi.execution.resource import clsinit_copy
from nepi.resources.ns3.ns3base import NS3Base
-from nepi.resources.ns3.ns3device import NS3BaseNetDevice
@clsinit_copy
class NS3BaseQueue(NS3Base):
- _rtype = "ns3::Queue"
+ _rtype = "abstract::ns3::Queue"
@property
def device(self):
+ from nepi.resources.ns3.ns3device import NS3BaseNetDevice
devices = self.get_connected(NS3BaseNetDevice.get_rtype())
if devices: return devices[0]
return None
--- /dev/null
+#
+# NEPI, a framework to manage network experiments
+# Copyright (C) 2014 INRIA
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.resource import clsinit_copy
+from nepi.resources.ns3.ns3base import NS3Base
+
+@clsinit_copy
+class NS3BaseWifiMac(NS3Base):
+ _rtype = "abstract::ns3::WifiMac"
+
+ @property
+ def device(self):
+ from nepi.resources.ns3.ns3device import NS3BaseNetDevice
+ devices = self.get_connected(NS3BaseNetDevice.get_rtype())
+ if devices: return devices[0]
+ return None
+
+ @property
+ def others_to_wait(self):
+ others = set()
+ device = self.device
+ if device: others.add(device)
+ return others
+
+ def _connect_object(self):
+ device = self.device
+ if device and device.uuid not in self.connected:
+ self.simulator.invoke(device.uuid, "SetMac", self.uuid)
+ self._connected.add(device.uuid)
+
from nepi.execution.resource import clsinit_copy
from nepi.resources.ns3.ns3base import NS3Base
-from nepi.resources.ns3.ns3channel import NS3Channel
@clsinit_copy
-class NS3BaseNetDevice(NS3Base):
- _rtype = "ns3::NetDevice"
+class NS3BaseWifiPhy(NS3Base):
+ _rtype = "abstract::ns3::WifiPhy"
@property
- def channel(self):
- channels = self.get_connected(NS3BaseChannel.get_rtype())
- if channels: return channels[0]
+ def device(self):
+ from nepi.resources.ns3.ns3device import NS3BaseNetDevice
+ devices = self.get_connected(NS3BaseNetDevice.get_rtype())
+ if devices: return devices[0]
return None
@property
def others_to_wait(self):
others = set()
- node = self.node
- if node: others.add(node)
-
- channel = self.channel
- if channel: others.add(channel)
+ device = self.device
+ if device: others.add(device)
return others
def _connect_object(self):
- node = self.node
- if node and node.uuid not in self.connected:
- self.simulator.invoke(node.uuid, "AddDevice", self.uuid)
- self._connected.add(node.uuid)
+ device = self.device
+ if device and device.uuid not in self.connected:
+ self.simulator.invoke(device.uuid, "SetPhy", self.uuid)
+ self.simulator.invoke(self.uuid, "SetDevice", device.uuid)
+ self._connected.add(device.uuid)
- channel = self.channel
- if channel and channel.uuid not in self.connected:
- self.simulator.invoke(self.uuid, "Attach", channel.uuid)
- self._connected.add(channel.uuid)
+ node = device.node
+ if node:
+ self.simulator.invoke(self.uuid, "SetMobility", node.uuid)
from nepi.execution.resource import clsinit_copy
from nepi.resources.ns3.ns3base import NS3Base
-from nepi.resources.ns3.ns3device import NS3BaseDevice
+from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
@clsinit_copy
class NS3BaseWifiRemoteStationManager(NS3Base):
- _rtype = "ns3::WifiRemoteStationManager"
+ _rtype = "abstract::ns3::WifiRemoteStationManager"
@property
def device(self):
- devices = self.get_connected(NS3BaseDevice.get_rtype())
+ devices = self.get_connected(NS3BaseNetDevice.get_rtype())
if devices: return devices[0]
return None
import re
def select_base_class(ns3, tid):
+ base_class_import = base_class = None
+
rtype = tid.GetName()
- type_id = ns3.TypeId()
- appbase = type_id.LookupByName("ns3::Application")
- devicebase = type_id.LookupByName("ns3::NetDevice")
- channelbase = type_id.LookupByName("ns3::Channel")
- queuebase = type_id.LookupByName("ns3::Queue")
- lossbase = type_id.LookupByName("ns3::PropagationLossModel")
- delaybase = type_id.LookupByName("ns3::PropagationDelayModel")
- managerbase = type_id.LookupByName("ns3::WifiRemoteStationManager")
-
- if tid.IsChiledOf(appbase):
- base_class_import = "from nepi.resources.ns3.ns3application import NS3BaseApplication"
- base_class = "NS3BaseApplication"
- elif tid.IsChiledOf(devicebase):
- base_class_import = "from nepi.resources.ns3.ns3device import NS3BaseNetDevice"
- base_class = "NS3BaseNetDevice"
- elif tid.IsChiledOf(channelbase):
- base_class_import = "from nepi.resources.ns3.ns3channel import NS3BaseChannel"
- base_class = "NS3BaseChannel"
- elif tid.IsChiledOf(queuebase):
- base_class_import = "from nepi.resources.ns3.ns3queue import NS3BaseQueue"
- base_class = "NS3BaseQueue"
- elif tid.IsChiledOf(lossbase):
- base_class_import = "from nepi.resources.ns3.ns3loss import NS3BasePropagationLossModel"
- base_class = "NS3BasePropagationLossDelay"
- elif tid.IsChiledOf(delaybase):
- base_class_import = "from nepi.resources.ns3.ns3delay import NS3BasePropagationDelayModel"
- base_class = "NS3BasePropagationDelayModel"
- elif tid.IsChiledOf(managerbase):
- base_class_import = "from nepi.resources.ns3.ns3manager import NS3BaseWifiRemoteStationManager"
- base_class = "NS3BaseWifiRemoteStationManager"
- elif rtype == "ns3::Node":
+ if rtype == "ns3::Node":
base_class_import = "from nepi.resources.ns3.ns3node import NS3BaseNode"
base_class = "NS3BaseNode"
elif rtype == "ns3::Ipv4L3Protocol":
- base_class_import = "from nepi.resources.ns3.ns3ipv4protocol import NS3BaseIpV4Protocol"
- base_class = "NS3BaseIpV4Protocol"
+ base_class_import = "from nepi.resources.ns3.ns3ipv4protocol import NS3BaseIpv4L3Protocol"
+ base_class = "NS3BaseIpv4L3Protocol"
else:
base_class_import = "from nepi.resources.ns3.ns3base import NS3Base"
base_class = "NS3Base"
+
+ if not base_class:
+ type_id = ns3.TypeId()
+
+ bases = ["ns3::Application",
+ "ns3::NetDevice",
+ "ns3::Channel",
+ "ns3::Queue",
+ "ns3::PropagationLossModel",
+ "ns3::PropagationDelayModel",
+ "ns3::WifiRemoteStationManager",
+ "ns3::WifiPhy",
+ "ns3::WifiMac",
+ "ns3::ErrorModel",
+ "ns3::ErrorRateModel"]
+
+ for base in bases:
+ tid_base = type_id.LookupByName(base)
+ if tid.IsChildOf(tid_base):
+ base_class = "NS3Base" + base.replace("ns3::", "")
+ base_module = "ns3" + base.replace("ns3::", "").lower()
+ base_class_import = "from nepi.resources.ns3.ns3application import %s " % (
+ base_module, base_class)
+
return (base_class_import, base_class)
def create_ns3_rms():
replace('::', ''). \
replace("-","_").lower() + ".py"
- #f = open(os.path.join(d, "classes", fname), "w")
- #print os.path.join(d, fname)
- #print template
- #f.write(template)
- #f.close()
+ f = open(os.path.join(d, "classes", fname), "w")
+ print os.path.join(d, fname)
+ print template
+ f.write(template)
+ f.close()
def template_attributes(ns3, tid):
d = os.path.dirname(os.path.realpath(__file__))