Ignoring 'abstract' RMs upon ResourceFactory discover
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 2 Feb 2014 20:23:06 +0000 (21:23 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 2 Feb 2014 20:23:06 +0000 (21:23 +0100)
17 files changed:
src/nepi/execution/resource.py
src/nepi/resources/ns3/classes/__init__.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3application.py
src/nepi/resources/ns3/ns3base.py
src/nepi/resources/ns3/ns3channel.py
src/nepi/resources/ns3/ns3errormodel.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3errorratemodel.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3ipv4l3protocol.py [moved from src/nepi/resources/ns3/ns3ipv4protocol.py with 80% similarity]
src/nepi/resources/ns3/ns3netdevice.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3node.py
src/nepi/resources/ns3/ns3propagationdelaymodel.py [moved from src/nepi/resources/ns3/ns3delay.py with 97% similarity]
src/nepi/resources/ns3/ns3propagationlossmodel.py [moved from src/nepi/resources/ns3/ns3loss.py with 100% similarity]
src/nepi/resources/ns3/ns3queue.py
src/nepi/resources/ns3/ns3wifimac.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3wifiphy.py [moved from src/nepi/resources/ns3/ns3device.py with 58% similarity]
src/nepi/resources/ns3/ns3wifiremotestationmanager.py [moved from src/nepi/resources/ns3/ns3manager.py with 89% similarity]
src/nepi/resources/ns3/resource_manager_generator.py

index d0d9079..059a758 100644 (file)
@@ -1060,6 +1060,9 @@ def find_types():
                     continue
 
                 if issubclass(attr, ResourceManager):
+                    if find(attr.get_rtype().lower(), "abstract") > -1:
+                        continue 
+
                     types.append(attr)
 
                     if not modname in sys.modules:
diff --git a/src/nepi/resources/ns3/classes/__init__.py b/src/nepi/resources/ns3/classes/__init__.py
new file mode 100644 (file)
index 0000000..e69de29
index 736dd65..f53d505 100644 (file)
@@ -22,7 +22,7 @@ from nepi.resources.ns3.ns3base import NS3Base
 
 @clsinit_copy
 class NS3BaseApplication(NS3Base):
-    _rtype = "ns3::Application"
+    _rtype = "abstract::ns3::Application"
 
     def _connect_object(self):
         node = self.node
index f8d7d12..f36ffce 100644 (file)
 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__()
@@ -53,6 +53,7 @@ class NS3Base(ResourceManager):
          
     @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
@@ -104,8 +105,8 @@ class NS3Base(ResourceManager):
         # self.simulator.node.mkdir(self.run_home)
 
         self._instantiate_object()
-        self._configure_object()
         self._connect_object()
+        self._configure_object()
       
         self.info("Provisioning finished")
 
index fe628c8..063e31b 100644 (file)
 
 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
diff --git a/src/nepi/resources/ns3/ns3errormodel.py b/src/nepi/resources/ns3/ns3errormodel.py
new file mode 100644 (file)
index 0000000..656b580
--- /dev/null
@@ -0,0 +1,46 @@
+#
+#    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)
+
diff --git a/src/nepi/resources/ns3/ns3errorratemodel.py b/src/nepi/resources/ns3/ns3errorratemodel.py
new file mode 100644 (file)
index 0000000..3de9568
--- /dev/null
@@ -0,0 +1,46 @@
+#
+#    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)
+
similarity index 80%
rename from src/nepi/resources/ns3/ns3ipv4protocol.py
rename to src/nepi/resources/ns3/ns3ipv4l3protocol.py
index 81ce0ac..2155422 100644 (file)
@@ -21,20 +21,13 @@ from nepi.execution.resource import clsinit_copy
 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()
-
diff --git a/src/nepi/resources/ns3/ns3netdevice.py b/src/nepi/resources/ns3/ns3netdevice.py
new file mode 100644 (file)
index 0000000..4978c7e
--- /dev/null
@@ -0,0 +1,102 @@
+#
+#    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)
+
index 0e78bb0..7d0380c 100644 (file)
@@ -21,8 +21,15 @@ from nepi.execution.resource import clsinit_copy
 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):
similarity index 97%
rename from src/nepi/resources/ns3/ns3delay.py
rename to src/nepi/resources/ns3/ns3propagationdelaymodel.py
index e72c974..58842b7 100644 (file)
@@ -23,7 +23,7 @@ from nepi.resources.ns3.ns3channel import NS3BaseChannel
 
 @clsinit_copy
 class NS3BasePropagationDelayModel(NS3Base):
-    _rtype = "ns3::PropagationDelayModel"
+    _rtype = "abstract::ns3::PropagationDelayModel"
 
     @property
     def simulator(self):
index 4a2b66b..55ed57f 100644 (file)
 
 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
diff --git a/src/nepi/resources/ns3/ns3wifimac.py b/src/nepi/resources/ns3/ns3wifimac.py
new file mode 100644 (file)
index 0000000..6cc4c16
--- /dev/null
@@ -0,0 +1,46 @@
+#
+#    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)
+
similarity index 58%
rename from src/nepi/resources/ns3/ns3device.py
rename to src/nepi/resources/ns3/ns3wifiphy.py
index 98d7202..a1f01b7 100644 (file)
 
 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)
 
similarity index 89%
rename from src/nepi/resources/ns3/ns3manager.py
rename to src/nepi/resources/ns3/ns3wifiremotestationmanager.py
index f5c8c01..480250d 100644 (file)
 
 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
 
index 4042bf8..e8ff1a7 100644 (file)
@@ -24,48 +24,44 @@ import os
 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():
@@ -123,11 +119,11 @@ 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__))