From f3f4764e770bd29cf09bf47978fd6ddc47e2daf6 Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Sun, 1 May 2011 12:31:31 +0200 Subject: [PATCH] added TestbedController status flag --- src/nepi/core/testbed_impl.py | 28 +++++++++++++++---- .../ns3/attributes_metadata_v3_9_RC3.py | 3 +- src/nepi/testbeds/ns3/execute.py | 10 +++++-- .../ns3/factories_metadata_v3_9_RC3.py | 2 +- src/nepi/util/constants.py | 9 ++++++ 5 files changed, 42 insertions(+), 10 deletions(-) diff --git a/src/nepi/core/testbed_impl.py b/src/nepi/core/testbed_impl.py index d408eb45..05c7c96a 100644 --- a/src/nepi/core/testbed_impl.py +++ b/src/nepi/core/testbed_impl.py @@ -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: diff --git a/src/nepi/testbeds/ns3/attributes_metadata_v3_9_RC3.py b/src/nepi/testbeds/ns3/attributes_metadata_v3_9_RC3.py index b469236c..04472612 100644 --- a/src/nepi/testbeds/ns3/attributes_metadata_v3_9_RC3.py +++ b/src/nepi/testbeds/ns3/attributes_metadata_v3_9_RC3.py @@ -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" diff --git a/src/nepi/testbeds/ns3/execute.py b/src/nepi/testbeds/ns3/execute.py index 12ea28bc..a89a6b70 100644 --- a/src/nepi/testbeds/ns3/execute.py +++ b/src/nepi/testbeds/ns3/execute.py @@ -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 diff --git a/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py b/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py index 1f4f34f1..fc740db1 100644 --- a/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py +++ b/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py @@ -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) diff --git a/src/nepi/util/constants.py b/src/nepi/util/constants.py index 8998d615..cb94c2e9 100644 --- a/src/nepi/util/constants.py +++ b/src/nepi/util/constants.py @@ -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" -- 2.47.0