bug fixing: addresses and routes
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 27 May 2011 13:46:33 +0000 (15:46 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Fri, 27 May 2011 13:46:33 +0000 (15:46 +0200)
setup.py
src/nepi/core/attributes.py
src/nepi/core/design.py
src/nepi/core/execute.py
src/nepi/testbeds/ns3/execute.py
src/nepi/util/parser/base.py

index 6910923..36a1081 100755 (executable)
--- 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",
index 321e5c9..151cab0 100644 (file)
@@ -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)
index c899344..c4aa80d 100644 (file)
@@ -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
 
index b6470d5..7f0d3ed 100644 (file)
@@ -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():
index b975b7f..15a8c26 100644 (file)
@@ -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()
index fcc8efc..89d88de 100644 (file)
@@ -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):