Almost working local example for linux ns-3 simulator
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 4 Feb 2014 14:01:24 +0000 (15:01 +0100)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 4 Feb 2014 14:01:24 +0000 (15:01 +0100)
28 files changed:
src/nepi/execution/ec.py
src/nepi/execution/resource.py
src/nepi/resources/linux/ccn/ccnapplication.py
src/nepi/resources/linux/ccn/ccncontent.py
src/nepi/resources/linux/ccn/ccnd.py
src/nepi/resources/linux/ccn/ccnr.py
src/nepi/resources/linux/ccn/fibentry.py
src/nepi/resources/linux/ns3/ns3simulator.py
src/nepi/resources/linux/udptunnel.py
src/nepi/resources/ns3/ns3application.py
src/nepi/resources/ns3/ns3arpl3protocol.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3base.py
src/nepi/resources/ns3/ns3channel.py
src/nepi/resources/ns3/ns3errormodel.py
src/nepi/resources/ns3/ns3errorratemodel.py
src/nepi/resources/ns3/ns3icmpv4l4protocol.py [new file with mode: 0644]
src/nepi/resources/ns3/ns3ipv4l3protocol.py
src/nepi/resources/ns3/ns3netdevice.py
src/nepi/resources/ns3/ns3node.py
src/nepi/resources/ns3/ns3propagationdelaymodel.py
src/nepi/resources/ns3/ns3propagationlossmodel.py
src/nepi/resources/ns3/ns3queue.py
src/nepi/resources/ns3/ns3wifimac.py
src/nepi/resources/ns3/ns3wifiphy.py
src/nepi/resources/ns3/ns3wifiremotestationmanager.py
src/nepi/resources/ns3/resource_manager_generator.py
src/nepi/resources/planetlab/tap.py
test/resources/linux/ns3/ns3simulator.py

index 47110a4..571b3d5 100644 (file)
@@ -747,7 +747,6 @@ class ExperimentController(object):
                     break
 
             if reschedule:
-
                 callback = functools.partial(wait_all_and_start, group)
                 self.schedule("1s", callback)
             else:
index f0fad39..15375c8 100644 (file)
@@ -512,7 +512,6 @@ class ResourceManager(Logger):
         with self._release_lock:
             if self._state != ResourceState.RELEASED:
                 self.do_deploy()
-                self.debug("----- READY ---- ")
 
     def release(self):
         """ Perform actions to free resources used by the RM.
@@ -533,7 +532,6 @@ class ResourceManager(Logger):
                 self.error(err)
 
             self.set_released()
-            self.debug("----- RELEASED ---- ")
 
     def fail(self):
         """ Sets the RM to state FAILED.
@@ -955,30 +953,37 @@ class ResourceManager(Logger):
     def set_started(self):
         """ Mark ResourceManager as STARTED """
         self.set_state(ResourceState.STARTED, "_start_time")
+        self.debug("----- STARTED ---- ")
         
     def set_stopped(self):
         """ Mark ResourceManager as STOPPED """
         self.set_state(ResourceState.STOPPED, "_stop_time")
+        self.debug("----- STOPPED ---- ")
 
     def set_ready(self):
         """ Mark ResourceManager as READY """
         self.set_state(ResourceState.READY, "_ready_time")
+        self.debug("----- READY ---- ")
 
     def set_released(self):
         """ Mark ResourceManager as REALEASED """
         self.set_state(ResourceState.RELEASED, "_release_time")
+        self.debug("----- RELEASED ---- ")
 
     def set_failed(self):
         """ Mark ResourceManager as FAILED """
         self.set_state(ResourceState.FAILED, "_failed_time")
+        self.debug("----- FAILED ---- ")
 
     def set_discovered(self):
         """ Mark ResourceManager as DISCOVERED """
         self.set_state(ResourceState.DISCOVERED, "_discover_time")
+        self.debug("----- DISCOVERED ---- ")
 
     def set_provisioned(self):
         """ Mark ResourceManager as PROVISIONED """
         self.set_state(ResourceState.PROVISIONED, "_provision_time")
+        self.debug("----- PROVISIONED ---- ")
 
     def set_state(self, state, state_time_attr):
         """ Set the state of the RM while keeping a trace of the time """
index 89c949c..f79c7cf 100644 (file)
@@ -59,7 +59,6 @@ class LinuxCCNApplication(LinuxApplication):
             self.do_discover()
             self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     @property
index d23ca37..c7ce3bf 100644 (file)
@@ -96,7 +96,6 @@ class LinuxCCNContent(LinuxApplication):
             self.do_discover()
             self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def upload_start_command(self):
index b32937a..070e2cf 100644 (file)
@@ -176,7 +176,6 @@ class LinuxCCND(LinuxApplication):
             self.do_discover()
             self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def upload_start_command(self):
index 6b0aa6f..69a8437 100644 (file)
@@ -220,7 +220,6 @@ class LinuxCCNR(LinuxApplication):
             self.do_discover()
             self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def upload_start_command(self):
index 31272f3..dca91c2 100644 (file)
@@ -134,7 +134,6 @@ class LinuxFIBEntry(LinuxApplication):
             self.do_provision()
             self.configure()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def upload_start_command(self):
index 90edbc5..e468005 100644 (file)
@@ -54,7 +54,6 @@ class LinuxNS3Simulator(LinuxApplication, NS3Simulator):
             # ccnd needs to wait until node is deployed and running
             self.ec.schedule(reschedule_delay, self.deploy)
         else:
-            
             # TODO: Create socket!!
             socket_name = self.get("socketName")
             self._client = LinuxNS3Client(socket_name)
@@ -62,6 +61,15 @@ class LinuxNS3Simulator(LinuxApplication, NS3Simulator):
             #self.do_discover()
             #self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
+    def do_start(self):
+        command = self.get("command")
+
+        self.info("Starting ns-3 simulation")
+        
+        self._client.start()
+
+        self.set_started()
+
+    # TODO! DESTROY SOCKET AND SHUTDOWN CLIENT
index 44edad6..ba96788 100644 (file)
@@ -198,7 +198,6 @@ class UdpTunnel(LinuxApplication):
             self.do_discover()
             self.do_provision()
  
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def do_start(self):
index 6f8ad6b..b00b47f 100644 (file)
@@ -24,12 +24,31 @@ from nepi.resources.ns3.ns3base import NS3Base
 class NS3BaseApplication(NS3Base):
     _rtype = "abstract::ns3::Application"
 
+    @property
+    def node(self):
+        from nepi.resources.ns3.ns3node import NS3BaseNode
+        nodes = self.get_connected(NS3BaseNode.get_rtype())
+
+        if not nodes: 
+            msg = "Application not connected to node"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return nodes[0]
+
+    @property
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.node)
+        return rms
+
     def _connect_object(self):
         node = self.node
-        if node and node.uuid not in self.connected:
+        if node.uuid not in self.connected:
             self.simulator.invoke(node.uuid, "AddApplication", self.uuid)
             self._connected.add(node.uuid)
 
+    """
     def do_start(self):
         if self.state == ResourceState.READY:
             self.info("Starting")
@@ -50,4 +69,5 @@ class NS3BaseApplication(NS3Base):
             self.info("Stopping command '%s'" % command)
             self.simulator.invoke(self.uuid, "Stop")
             self.set_stopped()
+    """
 
diff --git a/src/nepi/resources/ns3/ns3arpl3protocol.py b/src/nepi/resources/ns3/ns3arpl3protocol.py
new file mode 100644 (file)
index 0000000..b40c581
--- /dev/null
@@ -0,0 +1,44 @@
+#
+#    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 NS3BaseArpL3Protocol(NS3Base):
+    _rtype = "abstract::ns3::ArpL3Protocol"
+
+    @property
+    def node(self):
+        from nepi.resources.ns3.ns3node import NS3BaseNode
+        nodes = self.get_connected(NS3BaseNode.get_rtype())
+
+        if not nodes: 
+            msg = "ArpL3Protocol not connected to node"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return nodes[0]
+
+    @property
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.node)
+        return rms
+
index ba03596..7cc077a 100644 (file)
@@ -42,11 +42,8 @@ class NS3Base(ResourceManager):
 
     @property
     def simulator(self):
-        # Ns3 RMs should be connected to the simulator through a ns3 node 
-        node = self.node
-        if node: return node.simulator
-        return None
-         
+        return self.node.simulator 
+
     @property
     def node(self):
         from nepi.resources.ns3.ns3node import NS3BaseNode
@@ -55,11 +52,18 @@ class NS3Base(ResourceManager):
         return None
 
     @property
-    def others_to_wait(self):
-        others = set()
+    def _rms_to_wait(self):
+        """ Returns the collection of ns-3 RMs that this RM needs to
+        wait for before start
+
+        This method should be overriden to wait for other ns-3
+        objects to be deployed before proceeding with the deployment
+
+        """
+        rms = set()
         node = self.node
-        if node: others.add(node)
-        return others
+        if node: rms.add(node)
+        return rms
 
     def _instantiate_object(self):
         if self.uuid:
@@ -83,21 +87,16 @@ class NS3Base(ResourceManager):
             self.simulator.invoke(node.uuid, "AggregateObject", self.uuid)
             self._connected.add(node.uuid)
 
-    def _wait_others(self):
-        """ Returns the collection of ns-3 RMs that this RM needs to
-        wait for before start
-
-        This method should be overriden to wait for other ns-3
-        objects to be deployed before proceeding with the deployment
-
-        """
-        for other in self.others_to_wait:
-            if other and other.state < ResourceState.READY:
+    def _wait_rms(self):
+        """ Returns True if dependent RMs are not yer READY, False otherwise"""
+        for rm in self._rms_to_wait:
+            if rm and rm.state < ResourceState.READY:
+                rm.debug("Not yet READY")
                 return True
         return False
 
     def do_provision(self):
-        # create run dir for ns3 object
+        # TODO: create run dir for ns3 object !!!!
         # self.simulator.node.mkdir(self.run_home)
 
         self._instantiate_object()
@@ -109,18 +108,14 @@ class NS3Base(ResourceManager):
         super(NS3Base, self).do_provision()
 
     def do_deploy(self):
-        if not self.simulator or self.simulator.state < ResourceState.READY or \
-                self._wait_others():
+        if self._wait_rms():
             self.debug("---- RESCHEDULING DEPLOY ----" )
-            
-            # ccnd needs to wait until node is deployed and running
             self.ec.schedule(reschedule_delay, self.deploy)
         else:
-            # TODO: CREATE AND CONFIGURE NS-3 C++ OBJECT
+            self.info("Entering deploy")
             self.do_discover()
             self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def do_start(self):
index 7386346..92dc892 100644 (file)
@@ -24,14 +24,25 @@ from nepi.resources.ns3.ns3base import NS3Base
 class NS3BaseChannel(NS3Base):
     _rtype = "abstract::ns3::Channel"
 
+    @property
+    def simulator(self):
+        return self.devices[0].node.simulator
+
     @property
     def devices(self):
         from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
-        return self.get_connected(NS3BaseNetDevice.get_rtype())
+        devices = self.get_connected(NS3BaseNetDevice.get_rtype())
+
+        if not devices: 
+            msg = "Channel not connected to devices"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return devices
 
     @property
-    def simulator(self):
-        devices = self.devices
-        if devices: return devices[0].node.simulator
-        return None
-    
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.simulator)
+        return rms
+
index 656b580..fa0779d 100644 (file)
@@ -28,19 +28,23 @@ class NS3BaseErrorModel(NS3Base):
     def device(self):
         from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
         devices = self.get_connected(NS3BaseNetDevice.get_rtype())
-        if devices: return devices[0]
-        return None
+
+        if not devices: 
+            msg = "ErrorModel not connected to device"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return devices[0]
 
     @property
-    def others_to_wait(self):
-        others = set()
-        device = self.device
-        if device: others.add(device)
-        return others
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.device)
+        return rms
 
     def _connect_object(self):
         device = self.device
-        if device and device.uuid not in self.connected:
+        if device.uuid not in self.connected:
             self.simulator.invoke(device.uuid, "SetReceiveErrorModel", self.uuid)
             self._connected.add(device.uuid)
 
index 3de9568..f1b283a 100644 (file)
@@ -19,7 +19,6 @@
 
 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):
@@ -27,20 +26,25 @@ class NS3BaseErrorRateModel(NS3Base):
 
     @property
     def phy(self):
+        from nepi.resources.ns3.ns3wifiphy import NS3BaseWifiPhy
         phys = self.get_connected(NS3BaseWifiPhy.get_rtype())
-        if phys: return phys[0]
-        return None
+
+        if not phys: 
+            msg = "ErrorRateModel not connected to phy"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return phys[0]
 
     @property
-    def others_to_wait(self):
-        others = set()
-        phy = self.phy
-        if phy: others.add(phy)
-        return others
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.phy)
+        return rms
 
     def _connect_object(self):
         phy = self.phy
-        if phy and phy.uuid not in self.connected:
+        if phy.uuid not in self.connected:
             self.simulator.invoke(phy.uuid, "SetErrorRateModel", self.uuid)
             self._connected.add(phy.uuid)
 
diff --git a/src/nepi/resources/ns3/ns3icmpv4l4protocol.py b/src/nepi/resources/ns3/ns3icmpv4l4protocol.py
new file mode 100644 (file)
index 0000000..94f8128
--- /dev/null
@@ -0,0 +1,44 @@
+#
+#    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 NS3BaseIcmpv4L4Protocol(NS3Base):
+    _rtype = "abstract::ns3::Icmpv4L4Protocol"
+
+    @property
+    def node(self):
+        from nepi.resources.ns3.ns3node import NS3BaseNode
+        nodes = self.get_connected(NS3BaseNode.get_rtype())
+
+        if not nodes: 
+            msg = "Icmp4L4Protocol not connected to node"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return nodes[0]
+
+    @property
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.node)
+        return rms
+
index 67fe21d..f8f3670 100644 (file)
@@ -24,6 +24,24 @@ from nepi.resources.ns3.ns3base import NS3Base
 class NS3BaseIpv4L3Protocol(NS3Base):
     _rtype = "abstract::ns3::Ipv4L3Protocol"
 
+    @property
+    def node(self):
+        from nepi.resources.ns3.ns3node import NS3BaseNode
+        nodes = self.get_connected(NS3BaseNode.get_rtype())
+
+        if not nodes: 
+            msg = "Ipv4L3Protocol not connected to node"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return nodes[0]
+
+    @property
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.node)
+        return rms
+
     def _configure_object(self):
         simulator = self.simulator
 
index 009d14c..66366cb 100644 (file)
@@ -42,21 +42,42 @@ class NS3BaseNetDevice(NS3Base):
         cls._register_attribute(ip)
         cls._register_attribute(prefix)
 
+    @property
+    def node(self):
+        from nepi.resources.ns3.ns3node import NS3BaseNode
+        nodes = self.get_connected(NS3BaseNode.get_rtype())
+
+        if not nodes: 
+            msg = "Device not connected to node"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return nodes[0]
+
     @property
     def channel(self):
         from nepi.resources.ns3.ns3channel import NS3BaseChannel
         channels = self.get_connected(NS3BaseChannel.get_rtype())
-        if channels: return channels[0]
-        return None
+
+        if not channels: 
+            msg = "Device not connected to channel"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return channels[0]
 
     @property
-    def others_to_wait(self):
+    def _rms_to_wait(self):
         others = set()
-        node = self.node
-        if node: others.add(node)
         
-        channel = self.channel
-        if channel: others.add(channel)
+        node = self.node
+        others.add(node)
+
+        ipv4 = node.ipv4
+        if node.ipv4:
+            others.add(ipv4)
+
+        others.add(self.channel)
         return others
 
     def _configure_object(self):
index 0cecfa7..62d2a38 100644 (file)
@@ -32,8 +32,10 @@ class NS3BaseNode(NS3Base):
             if isinstance(rm, NS3Simulator):
                 return rm
 
-        return None
-
+        msg = "Node not connected to simulator"
+        self.error(msg)
+        raise RuntimeError, msg
     @property
     def ipv4(self):
         from nepi.resources.ns3.ns3ipv4l3protocol import NS3BaseIpv4L3Protocol
@@ -42,8 +44,10 @@ class NS3BaseNode(NS3Base):
         return None
 
     @property
-    def others_to_wait(self):
-        return set()
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.simulator)
+        return rms
 
     def _configure_object(self):
         ### node.AggregateObject(PacketSocketFactory())
index 58842b7..6c5ee86 100644 (file)
@@ -19,7 +19,6 @@
 
 from nepi.execution.resource import clsinit_copy
 from nepi.resources.ns3.ns3base import NS3Base
-from nepi.resources.ns3.ns3channel import NS3BaseChannel
 
 @clsinit_copy
 class NS3BasePropagationDelayModel(NS3Base):
@@ -27,26 +26,29 @@ class NS3BasePropagationDelayModel(NS3Base):
 
     @property
     def simulator(self):
-        channel = self.channel
-        if channel: return channel.simulator
-        return None
+        return self.channel.simulator
 
     @property
     def channel(self):
+        from nepi.resources.ns3.ns3channel import NS3BaseChannel
         channels = self.get_connected(NS3BaseChannel.get_rtype())
-        if channels: return channels[0]
-        return None
+
+        if not channels: 
+            msg = "PropagationDelayModel not connected to channel"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return channels[0]
 
     @property
-    def others_to_wait(self):
+    def _rms_to_wait(self):
         others = set()
-        channel = self.channel
-        if channel: others.add(channel)
+        others.add(self.channel)
         return others
 
     def _connect_object(self):
         channel = self.channel
-        if channel and channel.uuid not in self.connected:
+        if channel.uuid not in self.connected:
             self.simulator.invoke(channel.uuid, "SetPropagationDelayModel", self.uuid)
             self._connected.add(channel.uuid)
 
index 617f8cf..fdaef38 100644 (file)
@@ -19,7 +19,6 @@
 
 from nepi.execution.resource import clsinit_copy
 from nepi.resources.ns3.ns3base import NS3Base
-from nepi.resources.ns3.ns3channel import NS3BaseChannel
 
 @clsinit_copy
 class NS3BasePropagationLossModel(NS3Base):
@@ -27,26 +26,29 @@ class NS3BasePropagationLossModel(NS3Base):
 
     @property
     def simulator(self):
-        channel = self.channel
-        if channel: return channel.simulator
-        return None
+        return self.channel.simulator
 
     @property
     def channel(self):
+        from nepi.resources.ns3.ns3channel import NS3BaseChannel
         channels = self.get_connected(NS3BaseChannel.get_rtype())
-        if channels: return channels[0]
-        return None
+
+        if not channels: 
+            msg = "PropagationLossModel not connected to channel"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return channels[0]
 
     @property
-    def others_to_wait(self):
+    def _rms_to_wait(self):
         others = set()
-        channel = self.channel
-        if channel: others.add(channel)
+        others.add(self.channel)
         return others
 
     def _connect_object(self):
         channel = self.channel
-        if channel and channel.uuid not in self.connected:
+        if channel.uuid not in self.connected:
             self.simulator.invoke(channel.uuid, "SetPropagationLossModel", self.uuid)
             self._connected.add(channel.uuid)
 
index a02a96e..9fd8df9 100644 (file)
@@ -28,25 +28,27 @@ class NS3BaseQueue(NS3Base):
     def device(self):
         from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
         devices = self.get_connected(NS3BaseNetDevice.get_rtype())
-        if devices: return devices[0]
-        return None
+
+        if not devices: 
+            msg = "Queue not connected to device"
+            self.error(msg, out, err)
+            raise RuntimeError, msg
+
+        return devices[0]
 
     @property
     def node(self):
-        device = self.device
-        if device: return device.node
-        return None
+        return self.device.node
 
     @property
-    def others_to_wait(self):
-        others = set()
-        device = self.device
-        if device: others.add(device)
-        return others
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.device)
+        return rms
 
     def _connect_object(self):
         device = self.device
-        if device and device.uuid not in self.connected:
+        if device.uuid not in self.connected:
             self.simulator.invoke(device.uuid, "SetQueue", self.uuid)
             self._connected.add(device.uuid)
 
index 6cc4c16..7e1cf8f 100644 (file)
@@ -24,23 +24,31 @@ from nepi.resources.ns3.ns3base import NS3Base
 class NS3BaseWifiMac(NS3Base):
     _rtype = "abstract::ns3::WifiMac"
 
+    @property
+    def node(self):
+        return self.device.node
+
     @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
+
+        if not devices: 
+            msg = "WifiMac not connected to device"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return devices[0]
 
     @property
-    def others_to_wait(self):
-        others = set()
-        device = self.device
-        if device: others.add(device)
-        return others
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.device)
+        return rms
 
     def _connect_object(self):
         device = self.device
-        if device and device.uuid not in self.connected:
+        if device.uuid not in self.connected:
             self.simulator.invoke(device.uuid, "SetMac", self.uuid)
             self._connected.add(device.uuid)
 
index a1f01b7..936eddc 100644 (file)
@@ -24,28 +24,34 @@ from nepi.resources.ns3.ns3base import NS3Base
 class NS3BaseWifiPhy(NS3Base):
     _rtype = "abstract::ns3::WifiPhy"
 
+    @property
+    def node(self):
+        return self.device.node
+
     @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
+
+        if not devices: 
+            msg = "WifiPhy not connected to device"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return devices[0]
 
     @property
-    def others_to_wait(self):
-        others = set()
-        device = self.device
-        if device: others.add(device)
-        return others
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.device)
+        return rms
 
     def _connect_object(self):
         device = self.device
-        if device and device.uuid not in self.connected:
+        if 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)
 
-            node = device.node
-            if node:
-                self.simulator.invoke(self.uuid, "SetMobility", node.uuid)
+            self.simulator.invoke(self.uuid, "SetMobility", self.node.uuid)
 
index 480250d..a5f4548 100644 (file)
@@ -25,28 +25,31 @@ from nepi.resources.ns3.ns3netdevice import NS3BaseNetDevice
 class NS3BaseWifiRemoteStationManager(NS3Base):
     _rtype = "abstract::ns3::WifiRemoteStationManager"
 
+    @property
+    def node(self):
+        return self.device.node
+
     @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 node(self):
-        device = self.device
-        if device: return device.node
-        return None
+        if not devices: 
+            msg = "WifiRemoteStationManager not connected to device"
+            self.error(msg)
+            raise RuntimeError, msg
+
+        return devices[0]
 
     @property
-    def others_to_wait(self):
-        others = set()
-        device = self.device
-        if device: others.add(device)
-        return others
+    def _rms_to_wait(self):
+        rms = set()
+        rms.add(self.device)
+        return rms
 
     def _connect_object(self):
         device = self.device
-        if device and device.uuid not in self.connected:
+        if device.uuid not in self.connected:
             self.simulator.invoke(device.uuid, "SetRemoteStationManager", self.uuid)
             self._connected.add(device.uuid)
 
index 5cb7cc1..aa3f51b 100644 (file)
@@ -23,23 +23,32 @@ from nepi.resources.ns3.ns3wrapper import load_ns3_module
 import os
 import re
 
+base_types = ["ns3::Node",
+        "ns3::Application", 
+        "ns3::NetDevice",
+        "ns3::Channel",
+        "ns3::Queue",
+        "ns3::Icmpv4L4Protocol",
+        "ns3::ArpL3Protocol",
+        "ns3::Ipv4L3Protocol",
+        "ns3::PropagationLossModel",
+        "ns3::PropagationDelayModel",
+        "ns3::WifiRemoteStationManager",
+        "ns3::WifiPhy",
+        "ns3::WifiMac",
+        "ns3::ErrorModel",
+        "ns3::ErrorRateModel"]
+
 def discard(ns3, tid):
     rtype = tid.GetName()
-
-    words = ["variable", "object", "probe", "adaptor", "wrapper", 
-            "container", "derived", "simple"]
-    for word in words:
-        if rtype.lower().find(word) > -1:
-            return True
-    
-    bases = ["ns3::Scheduler", "ns3::SimulatorImpl"]
     type_id = ns3.TypeId()
-    for base in bases:
-        tid_base = type_id.LookupByName(base)
-        if tid.IsChildOf(tid_base):
-            return True
 
-    return False
+    for type_name in base_types:
+        tid_base = type_id.LookupByName(type_name)
+        if type_name == rtype or tid.IsChildOf(tid_base):
+            return False
+
+    return True
 
 def select_base_class(ns3, tid): 
     base_class_import = "from nepi.resources.ns3.ns3base import NS3Base"
@@ -47,34 +56,15 @@ def select_base_class(ns3, tid):
    
     rtype = tid.GetName()
 
-    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.ns3ipv4l3protocol import NS3BaseIpv4L3Protocol"
-       base_class = "NS3BaseIpv4L3Protocol"
-    else:
-        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.%s import %s " % (
-                        base_module, base_class)
+    type_id = ns3.TypeId()
+
+    for type_name in base_types:
+        tid_base = type_id.LookupByName(type_name)
+        if type_name == rtype or tid.IsChildOf(tid_base):
+            base_class = "NS3Base" + type_name.replace("ns3::", "")
+            base_module = "ns3" + type_name.replace("ns3::", "").lower()
+            base_class_import = "from nepi.resources.ns3.%s import %s " % (
+                    base_module, base_class)
 
     return (base_class_import, base_class)
 
index 6cc490a..ec724a2 100644 (file)
@@ -169,7 +169,6 @@ class PlanetlabTap(LinuxApplication):
             self.do_discover()
             self.do_provision()
 
-            self.debug("----- READY ---- ")
             self.set_ready()
 
     def do_start(self):
index 9f17072..a4a97e0 100644 (file)
@@ -83,7 +83,7 @@ class LinuxNS3ClientTest(unittest.TestCase):
         ec.set(p1, "prefix", "30")
         ec.register_connection(nsnode1, p1)
         q1 = ec.register_resource("ns3::DropTailQueue")
-        ec.register_connection(nsnode1, q1)
+        ec.register_connection(p1, q1)
 
         nsnode2 = ec.register_resource("ns3::Node")
         ec.register_connection(nsnode2, simu)
@@ -102,7 +102,7 @@ class LinuxNS3ClientTest(unittest.TestCase):
         ec.set(p2, "prefix", "30")
         ec.register_connection(nsnode2, p2)
         q2 = ec.register_resource("ns3::DropTailQueue")
-        ec.register_connection(nsnode2, q2)
+        ec.register_connection(p2, q2)
 
         # Create channel
         chan = ec.register_resource("ns3::PointToPointChannel")
@@ -121,7 +121,7 @@ class LinuxNS3ClientTest(unittest.TestCase):
 
         ec.deploy()
 
-        time.sleep(5)
+        time.sleep(30)
 
         ec.shutdown()