From: Alina Quereilhac <alina.quereilhac@inria.fr>
Date: Fri, 27 May 2011 13:46:33 +0000 (+0200)
Subject: bug fixing: addresses and routes
X-Git-Tag: nepi_v2~1
X-Git-Url: http://git.onelab.eu/?a=commitdiff_plain;h=88b563bf316fa151152c477cb5ee3e9a809a60d2;p=nepi.git

bug fixing: addresses and routes
---

diff --git a/setup.py b/setup.py
index 69109239..36a10810 100755
--- a/setup.py
+++ b/setup.py
@@ -4,9 +4,9 @@ from distutils.core import setup, Extension, Command
 
 setup(
         name        = "nepi",
-        version     = "0.1",
+        version     = "0.2",
         description = "High-level abstraction for running network experiments",
-        author      = "Alina Quereilhac, Martín Ferrari and Claudio Freire",
+        author      = "Mathieu Lacage, Alina Quereilhac, Martín Ferrari and Claudio Freire",
         url         = "http://yans.pl.sophia.inria.fr/code/hgwebdir.cgi/nepi/",
         license     = "GPLv2",
         platforms   = "Linux",
diff --git a/src/nepi/core/attributes.py b/src/nepi/core/attributes.py
index 321e5c9d..151cab06 100644
--- a/src/nepi/core/attributes.py
+++ b/src/nepi/core/attributes.py
@@ -117,7 +117,7 @@ class Attribute(object):
             self._value = value
             self._modified = True
         else:
-            raise RuntimeError("Invalid value %s for attribute %s" %
+            raise ValueError("Invalid value %s for attribute %s" %
                     (str(value), self.name))
 
     value = property(get_value, set_value)
diff --git a/src/nepi/core/design.py b/src/nepi/core/design.py
index c8993449..c4aa80d7 100644
--- a/src/nepi/core/design.py
+++ b/src/nepi/core/design.py
@@ -256,14 +256,6 @@ class Box(AttributesMap):
     def tags(self):
         return self._tags
 
-    @property
-    def addresses(self):
-        return []
-
-    @property
-    def routes(self):
-        return []
-
     def trace_help(self, trace_id):
         return self._traces[trace_id].help
 
diff --git a/src/nepi/core/execute.py b/src/nepi/core/execute.py
index b6470d54..7f0d3ed8 100644
--- a/src/nepi/core/execute.py
+++ b/src/nepi/core/execute.py
@@ -608,8 +608,14 @@ class ExperimentController(object):
         raise RuntimeError("No element exists with guid %d" % guid)    
 
     def shutdown(self):
+        exceptions = list()
         for testbed in self._testbeds.values():
-            testbed.shutdown()
+            try:
+                testbed.shutdown()
+            except:
+                exceptions.append(sys.exc_info())
+        for exc_info in exceptions:
+            raise exc_info[0], exc_info[1], exc_info[2]
 
     def _testbed_for_guid(self, guid):
         for testbed_guid in self._testbeds.keys():
diff --git a/src/nepi/testbeds/ns3/execute.py b/src/nepi/testbeds/ns3/execute.py
index b975b7fa..15a8c262 100644
--- a/src/nepi/testbeds/ns3/execute.py
+++ b/src/nepi/testbeds/ns3/execute.py
@@ -55,8 +55,16 @@ class TestbedController(testbed_impl.TestbedController):
         self._condition = threading.Condition()
         self._simulator_thread = threading.Thread(target = self._simulator_run,
                 args = [self._condition])
+        self._simulator_thread.isDaemon()
         self._simulator_thread.start()
 
+    def stop(self, time = TIME_NOW):
+        super(TestbedController, self).stop(time)
+        # BUG!!!!
+        # TODO!! This is not working!!!
+        self.ns3.Simulator.Stop()
+        #self._stop_simulation(time)
+
     def set(self, guid, name, value, time = TIME_NOW):
         super(TestbedController, self).set(guid, name, value, time)
         # TODO: take on account schedule time for the task
@@ -120,11 +128,22 @@ class TestbedController(testbed_impl.TestbedController):
         self._traces[guid][trace_id] = filename
 
     def shutdown(self):
-        for element in self._elements.values():
+        for element in self._elements.itervalues():
             if isinstance(element, self.LOCAL_TYPES):
                 # graceful shutdown of locally-implemented objects
                 element.Cleanup()
-            element = None
+        self._elements.clear()
+        if self.ns3:
+            self.ns3.Simulator.Stop()
+            # BUG!!!!
+            # TODO!! This is not working!!! NEVER STOPS THE SIMULATION!!!
+            #self._stop_simulation("0s")
+            #if self._simulator_thread:
+            #    print "Joining thread"
+            #    self._simulator_thread.join()
+            #print "destroying"
+            self.ns3.Simulator.Destroy()
+        self._ns3 = None
         sys.stdout.flush()
         sys.stderr.flush()
 
@@ -188,6 +207,22 @@ class TestbedController(testbed_impl.TestbedController):
     def _get_ns3_attribute(self, name, ns3_value, element):
         element.GetAttribute(name, ns3_value)
 
+    def _stop_simulation(self, time):
+        if self.status() == TESTBED_STATUS_STARTED:
+            # schedule the event in the Simulator
+            self._schedule_event(self._condition, self._stop_ns3_simulation, 
+                    time)
+        else:
+            self._stop_ns3_simulation(time)
+
+    def _stop_simulation(self, time = TIME_NOW):
+        if not self.ns3:
+            return
+        if time == TIME_NOW:
+            self.ns3.Simulator.Stop()
+        else:
+            self.ns3.Simulator.Stop(self.ns3.Time(time))
+
     def _to_ns3_value(self, guid, name, value):
         factory_id = self._create[guid]
         TypeId = self.ns3.TypeId()
diff --git a/src/nepi/util/parser/base.py b/src/nepi/util/parser/base.py
index fcc8efca..89d88deb 100644
--- a/src/nepi/util/parser/base.py
+++ b/src/nepi/util/parser/base.py
@@ -207,8 +207,10 @@ class ExperimentParser(object):
                 self.attributes_to_data(data, box.guid, box.attributes)
                 self.traces_to_data(data, box.guid, box.traces)
                 self.connections_to_data(data, box.guid, box.connectors)
-                self.addresses_to_data(data, box.guid, box.addresses)
-                self.routes_to_data(data, box.guid, box.routes)
+                if hasattr(box, "addresses"):
+                    self.addresses_to_data(data, box.guid, box.addresses)
+                if hasattr(box, "routes"):
+                    self.routes_to_data(data, box.guid, box.routes)
         return data
 
     def graphical_info_to_data(self, data, guid, g_info):