added TestbedController status flag
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 1 May 2011 10:31:31 +0000 (12:31 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Sun, 1 May 2011 10:31:31 +0000 (12:31 +0200)
src/nepi/core/testbed_impl.py
src/nepi/testbeds/ns3/attributes_metadata_v3_9_RC3.py
src/nepi/testbeds/ns3/execute.py
src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py
src/nepi/util/constants.py

index d408eb4..05c7c96 100644 (file)
@@ -4,12 +4,20 @@
 from nepi.core import execute
 from nepi.core.metadata import Metadata
 from nepi.util import validation
-from nepi.util.constants import AF_INET, AF_INET6, STATUS_UNDETERMINED, TIME_NOW
+from nepi.util.constants import STATUS_UNDETERMINED, TIME_NOW, \
+    TESTBED_STATUS_ZERO, \
+    TESTBED_STATUS_SETUP, \
+    TESTBED_STATUS_CREATED, \
+    TESTBED_STATUS_CONNECTED, \
+    TESTBED_STATUS_CROSS_CONNECTED, \
+    TESTBED_STATUS_CONFIGURED, \
+    TESTBED_STATUS_STARTED, \
+    TESTBED_STATUS_STOPPED
 
 class TestbedController(execute.TestbedController):
     def __init__(self, testbed_id, testbed_version):
         super(TestbedController, self).__init__(testbed_id, testbed_version)
-        self._started = False
+        self._status = TESTBED_STATUS_ZERO
         # testbed attributes for validation
         self._attributes = None
         # element factories for validation
@@ -175,7 +183,8 @@ class TestbedController(execute.TestbedController):
             self._add_route[guid] = list()
         self._add_route[guid].append((destination, netprefix, nexthop)) 
 
-    #do_setup(self): NotImplementedError
+    def do_setup(self):
+        self._status = TESTBED_STATUS_SETUP
 
     def do_create(self):
         guids = dict()
@@ -195,6 +204,7 @@ class TestbedController(execute.TestbedController):
                 parameters = self._get_parameters(guid)
                 for name, value in parameters.iteritems():
                     self.set(TIME_NOW, guid, name, value)
+        self._status = TESTBED_STATUS_CREATED
 
     def _do_connect(self, init = True):
         for guid1, connections in self._connect.iteritems():
@@ -225,6 +235,7 @@ class TestbedController(execute.TestbedController):
 
     def do_connect_compl(self):
         self._do_connect(init = False)
+        self._status = TESTBED_STATUS_CONNECTED
 
     def do_preconfigure(self):
         guids = dict()
@@ -261,6 +272,7 @@ class TestbedController(execute.TestbedController):
                 continue
             for guid in guids[factory_id]:
                 factory.configure_function(self, guid)
+        self._status = TESTBED_STATUS_CONFIGURED
 
     def _do_cross_connect(self, cross_data, init = True):
         for guid, cross_connections in self._cross_connect.iteritems():
@@ -289,6 +301,7 @@ class TestbedController(execute.TestbedController):
 
     def do_cross_connect_compl(self, cross_data):
         self._do_cross_connect(cross_data, init = False)
+        self._status = TESTBED_STATUS_CROSS_CONNECTED
 
     def set(self, time, guid, name, value):
         if not guid in self._create:
@@ -298,7 +311,8 @@ class TestbedController(execute.TestbedController):
         if not factory.box_attributes.has_attribute(name):
             raise AttributeError("Invalid attribute %s for element type %s" %
                     (name, factory_id))
-        if self._started and factory.is_attribute_design_only(name):
+        if self._status > TESTBED_STATUS_CREATED and \
+                factory.box_attributes.is_attribute_design_only(name):
             raise AttributeError("Attribute %s can only be modified during experiment design" % name)
         if not factory.box_attributes.is_attribute_value_valid(name, value):
             raise AttributeError("Invalid value %s for attribute %s" % \
@@ -322,7 +336,8 @@ class TestbedController(execute.TestbedController):
         factory = self._factories[factory_id]
         if not factory.box_attributes.has_attribute(name):
             raise AttributeError, "Invalid attribute %s for element type %s" % (name, factory_id)
-        if self._started and factory.is_attribute_design_only(name):
+        if self._status > TESTBED_STATUS_CREATED and \
+                factory.box_attributes.is_attribute_design_only(name):
             raise AttributeError, "Attribute %s can only be queried during experiment design" % name
         return factory.box_attributes.get_attribute_value(name)
 
@@ -396,7 +411,7 @@ class TestbedController(execute.TestbedController):
             start_function = factory.start_function
             if start_function:
                 start_function(self, guid)
-        self._started = True
+        self._status = TESTBED_STATUS_STARTED
 
     #action: NotImplementedError
 
@@ -406,6 +421,7 @@ class TestbedController(execute.TestbedController):
             stop_function = factory.stop_function
             if stop_function:
                 stop_function(self, guid)
+        self._status = TESTBED_STATUS_STOPPED
 
     def status(self, guid):
         if not guid in self._create:
index b469236..0447261 100644 (file)
@@ -2389,14 +2389,15 @@ attributes = dict({
         "name": "Standard",
         "validation_function": validation.is_string,
         "value": "WIFI_PHY_STANDARD_80211a",
+        "flags": Attribute.DesignOnly,
         "type": Attribute.ENUM,
         "allowed": wifi_standards.keys(),
         "help": "Wifi PHY standard"
     }),
     "LinuxSocketAddress": dict({
         "name": "LinuxSocketAddress",
-        "value": "",
         "validation_function": None,
+        "value": "",
         "flags": Attribute.Invisible,
         "type": Attribute.STRING,
         "help": "Socket address assigned to the Linux socket created to recive file descriptor"
index 12ea28b..a89a6b7 100644 (file)
@@ -4,6 +4,7 @@
 from constants import TESTBED_ID
 from nepi.core import testbed_impl
 from nepi.core.attributes import Attribute
+from nepi.util.constants import TESTBED_STATUS_CREATED
 import os
 import sys
 import threading
@@ -29,6 +30,7 @@ class TestbedController(testbed_impl.TestbedController):
         self._home_directory = self._attributes.\
             get_attribute_value("homeDirectory")
         self._ns3 = self._load_ns3_module()
+        super(TestbedController, self).do_setup()
 
     def start(self):
         super(TestbedController, self).start()
@@ -40,6 +42,9 @@ class TestbedController(testbed_impl.TestbedController):
     def set(self, time, guid, name, value):
         super(TestbedController, self).set(time, guid, name, value)
         # TODO: take on account schedule time for the task
+        if self._status < TESTBED_STATUS_CREATED or \
+                factory.box_attributes.is_attribute_design_only(name):
+            return
         element = self._elements[guid]
         ns3_value = self._to_ns3_value(guid, name, value) 
         element.SetAttribute(name, ns3_value)
@@ -197,8 +202,9 @@ class TestbedController(testbed_impl.TestbedController):
         typeid = TypeId.LookupByName(factory_id)
         for name, value in params.iteritems():
             info = self.ns3.TypeId.AttributeInfo()
-            typeid.LookupAttributeByName(name, info)
-            if info.flags & TypeId.ATTR_CONSTRUCT == TypeId.ATTR_CONSTRUCT:
+            found = typeid.LookupAttributeByName(name, info)
+            if found and \
+                (info.flags & TypeId.ATTR_CONSTRUCT == TypeId.ATTR_CONSTRUCT):
                 construct_params[name] = value
         return construct_params
 
index 1f4f34f..fc740db 100644 (file)
@@ -160,7 +160,7 @@ def create_wifi_standard_model(testbed_instance, guid):
     if "Standard" in parameters:
         standard = parameters["Standard"]
         if standard:
-            elements.ConfigureStandard(wifi_standards[standard])
+            element.ConfigureStandard(wifi_standards[standard])
 
 def create_ipv4protocol(testbed_instance, guid):
     create_element(testbed_instance, guid)
index 8998d61..cb94c2e 100644 (file)
@@ -9,5 +9,14 @@ STATUS_RUNNING = 1
 STATUS_FINISHED = 2
 STATUS_UNDETERMINED = 3
 
+TESTBED_STATUS_ZERO = 0
+TESTBED_STATUS_SETUP = 1
+TESTBED_STATUS_CREATED = 2
+TESTBED_STATUS_CONNECTED = 3
+TESTBED_STATUS_CROSS_CONNECTED = 4
+TESTBED_STATUS_CONFIGURED = 5
+TESTBED_STATUS_STARTED = 6
+TESTBED_STATUS_STOPPED = 7
+
 TIME_NOW = "0s"