From 1bffba88cceccb456c29421e2eea4d995a96caed Mon Sep 17 00:00:00 2001 From: Alina Quereilhac Date: Mon, 23 May 2011 23:01:50 +0200 Subject: [PATCH] added tags to boxes. For now only one tag: MOBILE --- src/nepi/core/design.py | 16 ++++++++++++++++ src/nepi/core/execute.py | 15 +++++++++++++++ src/nepi/core/metadata.py | 8 ++++++++ src/nepi/core/testbed_impl.py | 4 ++++ .../testbeds/ns3/factories_metadata_v3_9_RC3.py | 16 ++++++++++++++++ src/nepi/util/proxy.py | 14 ++++++++++++++ test/core/design.py | 3 +++ test/core/execute.py | 3 +++ test/core/integration.py | 13 +++++++++++-- test/lib/mock/metadata_v01.py | 5 +++-- 10 files changed, 93 insertions(+), 4 deletions(-) diff --git a/src/nepi/core/design.py b/src/nepi/core/design.py index 50e00c16..c942d10e 100644 --- a/src/nepi/core/design.py +++ b/src/nepi/core/design.py @@ -184,6 +184,8 @@ class Box(AttributesMap): self._container = container # traces -- list of available traces for the box self._traces = dict() + # tags -- list of tags for the box + self._tags = list() # connectors -- list of available connectors for the box self._connectors = dict() # factory_attributes -- factory attributes for box construction @@ -197,6 +199,8 @@ class Box(AttributesMap): for trace in factory.traces: tr = Trace(trace.trace_id, trace.help, trace.enabled) self._traces[trace.trace_id] = tr + for tag_id in factory.tags: + self._tags.append(tag_id) for attr in factory.box_attributes.attributes: self.add_attribute(attr.name, attr.help, attr.type, attr.value, attr.range, attr.allowed, attr.flags, @@ -240,6 +244,10 @@ class Box(AttributesMap): def factory_attributes(self): return self._factory_attributes + @property + def tags(self): + return self._tags + @property def addresses(self): return [] @@ -374,6 +382,7 @@ class Factory(AttributesMap): self._category = category self._connector_types = list() self._traces = list() + self._tags = list() self._box_attributes = AttributesMap() if not self._has_addresses and not self._has_routes: @@ -441,6 +450,10 @@ class Factory(AttributesMap): def traces(self): return self._traces + @property + def tags(self): + return self._tags + @property def box_attributes(self): return self._box_attributes @@ -452,6 +465,9 @@ class Factory(AttributesMap): trace = Trace(trace_id, help, enabled) self._traces.append(trace) + def add_tag(self, tag_id): + self._tags.append(tag_id) + def add_box_attribute(self, name, help, type, value = None, range = None, allowed = None, flags = Attribute.NoFlags, validation_function = None, category = None): diff --git a/src/nepi/core/execute.py b/src/nepi/core/execute.py index 67e5ebca..3b1463a4 100644 --- a/src/nepi/core/execute.py +++ b/src/nepi/core/execute.py @@ -97,6 +97,7 @@ class Factory(AttributesMap): self._prestart_function = prestart_function self._connector_types = dict() self._traces = list() + self._tags = list() self._box_attributes = AttributesMap() @property @@ -155,6 +156,10 @@ class Factory(AttributesMap): def traces(self): return self._traces + @property + def tags(self): + return self._tags + def connector_type(self, name): return self._connector_types[name] @@ -164,6 +169,9 @@ class Factory(AttributesMap): def add_trace(self, trace_id): self._traces.append(trace_id) + def add_tag(self, tag_id): + self._tags.append(tag_id) + def add_box_attribute(self, name, help, type, value = None, range = None, allowed = None, flags = Attribute.NoFlags, validation_function = None, category = None): @@ -321,6 +329,9 @@ class TestbedController(object): def get_attribute_list(self, guid): raise NotImplementedError + def get_tags(self, guid): + raise NotImplementedError + def action(self, time, guid, action): raise NotImplementedError @@ -549,6 +560,10 @@ class ExperimentController(object): testbed = self._testbeds[testbed_guid] return testbed.get(guid, name, time) + def get_tags(self, testbed_guid, guid): + testbed = self._testbeds[testbed_guid] + return testbed.get_tags(guid) + def shutdown(self): for testbed in self._testbeds.values(): testbed.shutdown() diff --git a/src/nepi/core/metadata.py b/src/nepi/core/metadata.py index 4ae57a18..c8015cd2 100644 --- a/src/nepi/core/metadata.py +++ b/src/nepi/core/metadata.py @@ -134,6 +134,7 @@ class VersionedMetadataInfo(object): "factory_attributes": list of references to attribute_ids, "box_attributes": list of regerences to attribute_ids, "traces": list of references to trace_id + "tags": list of references to tag_id "connector_types": list of references to connector_types }) """ @@ -406,6 +407,7 @@ class Metadata(object): self._add_attributes(factory, info, "box_attributes", True) self._add_design_traces(factory, info) + self._add_tags(factory, info) self._add_design_connector_types(factory, info) factories.append(factory) return factories @@ -441,6 +443,7 @@ class Metadata(object): self._add_attributes(factory, info, "box_attributes", True) self._add_execute_traces(factory, info) + self._add_tags(factory, info) self._add_execute_connector_types(factory, info) factories.append(factory) return factories @@ -504,6 +507,11 @@ class Metadata(object): trace_id = trace_info["name"] factory.add_trace(trace_id) + def _add_tags(self, factory, info): + if "tags" in info: + for tag_id in info["tags"]: + factory.add_tag(tag_id) + def _add_design_connector_types(self, factory, info): from nepi.core.design import ConnectorType if "connector_types" in info: diff --git a/src/nepi/core/testbed_impl.py b/src/nepi/core/testbed_impl.py index 288b2346..b34b8fe1 100644 --- a/src/nepi/core/testbed_impl.py +++ b/src/nepi/core/testbed_impl.py @@ -392,6 +392,10 @@ class TestbedController(execute.TestbedController): return addresses[index][attribute_index] + def get_tags(self, guid): + factory = self._get_factory(guid) + return factory.tags + def get_attribute_list(self, guid): factory = self._get_factory(guid) attribute_list = list() 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 febb5c45..4e695ddd 100644 --- a/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py +++ b/src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from nepi.util import tags from nepi.util.constants import AF_INET, STATUS_NOT_STARTED, STATUS_RUNNING, \ STATUS_FINISHED, STATUS_UNDETERMINED from nepi.util.tunchannel_impl import \ @@ -716,6 +717,7 @@ factories_info = dict({ "Rho", "X", "Y"], + "tags": [tags.MOBILE], }), "ns3::Node": dict({ "category": "Topology", @@ -738,6 +740,7 @@ factories_info = dict({ "DeltaX", "DeltaY", "LayoutType"], + "tags": [tags.MOBILE], }), "ns3::TapBridge": dict({ "category": "Device", @@ -776,6 +779,7 @@ factories_info = dict({ "connector_types": ["node"], "box_attributes": ["Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::V4Ping": dict({ "category": "Application", @@ -912,6 +916,7 @@ factories_info = dict({ "connector_types": ["node"], "box_attributes": ["Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::GaussMarkovMobilityModel": dict({ "category": "Mobility", @@ -930,6 +935,7 @@ factories_info = dict({ "NormalPitch", "Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::dot11s::HwmpProtocol": dict({ "category": "Protocol", @@ -1021,6 +1027,7 @@ factories_info = dict({ "box_attributes": ["WaypointsLeft", "Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::FileDescriptorNetDevice": dict({ "category": "Device", @@ -1132,6 +1139,7 @@ factories_info = dict({ "box_attributes": ["rho", "X", "Y"], + "tags": [tags.MOBILE], }), "ns3::RandomBoxPositionAllocator": dict({ "category": "Mobility", @@ -1142,6 +1150,7 @@ factories_info = dict({ "box_attributes": ["X", "Y", "Z"], + "tags": [tags.MOBILE], }), "ns3::Ipv6ExtensionDestination": dict({ "category": "", @@ -1323,6 +1332,7 @@ factories_info = dict({ "connector_types": [], "box_attributes": ["X", "Y"], + "tags": [tags.MOBILE], }), "ns3::NqapWifiMac": dict({ "category": "Mac", @@ -1351,6 +1361,7 @@ factories_info = dict({ "connector_types": ["node"], "box_attributes": ["Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::ThreeLogDistancePropagationLossModel": dict({ "category": "Loss", @@ -1423,6 +1434,7 @@ factories_info = dict({ "MaxY", "Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::BaseStationNetDevice": dict({ "category": "Device", @@ -1528,6 +1540,7 @@ factories_info = dict({ "Pause", "Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::RangePropagationLossModel": dict({ "category": "Loss", @@ -1679,6 +1692,7 @@ factories_info = dict({ "connector_types": ["node"], "box_attributes": ["Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::FixedRssLossModel": dict({ "category": "Loss", @@ -1710,6 +1724,7 @@ factories_info = dict({ "Speed", "Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::ListPositionAllocator": dict({ "category": "", @@ -2206,6 +2221,7 @@ factories_info = dict({ "Pause", "Position", "Velocity"], + "tags": [tags.MOBILE], }), "ns3::UanMacAloha": dict({ "category": "", diff --git a/src/nepi/util/proxy.py b/src/nepi/util/proxy.py index 059ccfff..3a64ecd9 100644 --- a/src/nepi/util/proxy.py +++ b/src/nepi/util/proxy.py @@ -56,6 +56,7 @@ TESTBED_VERSION = 36 EXPERIMENT_SET = 37 EXPERIMENT_GET = 38 DO_PRESTART = 39 +GET_TAGS = 40 instruction_text = dict({ OK: "OK", @@ -96,6 +97,7 @@ instruction_text = dict({ TESTBED_VERSION: "TESTBED_VERSION", EXPERIMENT_SET: "EXPERIMENT_SET", EXPERIMENT_GET: "EXPERIMENT_GET", + GET_TAGS: "GET_TAGS", }) def log_msg(server, params): @@ -643,6 +645,12 @@ class TestbedControllerServer(BaseServer): def get_attribute_list(self, guid): return self._testbed.get_attribute_list(guid) + @Marshalling.handles(GET_TAGS) + @Marshalling.args(int) + @Marshalling.retval( Marshalling.pickled_data ) + def get_tags(self, guid): + return self._testbed.get_tags(guid) + class ExperimentControllerServer(BaseServer): def __init__(self, root_dir, log_level, experiment_xml): super(ExperimentControllerServer, self).__init__(root_dir, log_level) @@ -684,6 +692,12 @@ class ExperimentControllerServer(BaseServer): def set(self, testbed_guid, guid, name, value, time): self._controller.set(testbed_guid, guid, name, value, time) + @Marshalling.handles(GET_TAGS) + @Marshalling.args(int, int) + @Marshalling.retval( Marshalling.pickled_data ) + def get_tags(self, testbed_guid, guid): + return self._controller.get_tags(testbed_guid, guid) + @Marshalling.handles(START) @Marshalling.args() @Marshalling.retvoid diff --git a/test/core/design.py b/test/core/design.py index 2481d197..84015339 100755 --- a/test/core/design.py +++ b/test/core/design.py @@ -2,6 +2,7 @@ # -*- coding: utf-8 -*- from nepi.core.design import ExperimentDescription, FactoriesProvider +from nepi.util import tags import mock.metadata_v01 import sys import unittest @@ -30,6 +31,8 @@ class DesignTestCase(unittest.TestCase): app.connector("node").connect(node1.connector("apps")) app.enable_trace("fake") + self.assertEquals(node1.tags, [tags.MOBILE]) + xml = exp_desc.to_xml() exp_desc2 = ExperimentDescription() exp_desc2.from_xml(xml) diff --git a/test/core/execute.py b/test/core/execute.py index e5c609ff..2f393792 100755 --- a/test/core/execute.py +++ b/test/core/execute.py @@ -1,6 +1,7 @@ #!/usr/bin/env python # -*- coding: utf-8 -*- +from nepi.util import tags from nepi.util.constants import STATUS_FINISHED import mock import mock.metadata_v01 @@ -49,6 +50,8 @@ class ExecuteTestCase(unittest.TestCase): """ self.assertTrue(app_result.startswith(comp_result)) + self.assertEquals(instance.get_tags(4), [tags.MOBILE]) + instance.stop() instance.shutdown() diff --git a/test/core/integration.py b/test/core/integration.py index f099c08f..ea125859 100755 --- a/test/core/integration.py +++ b/test/core/integration.py @@ -2,8 +2,8 @@ # -*- coding: utf-8 -*- from nepi.core.design import ExperimentDescription, FactoriesProvider +from nepi.util import proxy, tags from nepi.util.constants import STATUS_FINISHED, DeploymentConfiguration as DC -from nepi.util import proxy import mock import mock.metadata_v01 import mock2 @@ -100,6 +100,8 @@ class ExecuteTestCase(unittest.TestCase): 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) + self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + controller.stop() controller.shutdown() @@ -121,6 +123,8 @@ class ExecuteTestCase(unittest.TestCase): 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) + self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + controller.stop() controller.shutdown() @@ -144,6 +148,8 @@ class ExecuteTestCase(unittest.TestCase): 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) + self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + controller.stop() controller.shutdown() @@ -172,6 +178,8 @@ class ExecuteTestCase(unittest.TestCase): 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) + self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + controller.stop() controller.shutdown() @@ -200,7 +208,8 @@ class ExecuteTestCase(unittest.TestCase): 1 packets transmitted, 1 received, 0% packet loss, time 0ms """ self.assertTrue(fake_result.startswith(comp_result)) - + self.assertEquals(controller.get_tags(desc.guid, node1.guid), [tags.MOBILE]) + # controller dies del controller diff --git a/test/lib/mock/metadata_v01.py b/test/lib/mock/metadata_v01.py index 5478c7e6..2b7d37cc 100644 --- a/test/lib/mock/metadata_v01.py +++ b/test/lib/mock/metadata_v01.py @@ -4,7 +4,7 @@ from constants import TESTBED_ID from nepi.core import metadata from nepi.core.attributes import Attribute -from nepi.util import validation +from nepi.util import validation, tags from nepi.util.constants import STATUS_FINISHED NODE = "Node" @@ -134,7 +134,8 @@ factories_info = dict({ "stop_function": None, "status_function": None, "box_attributes": ["fake","test"], - "connector_types": ["devs", "apps"] + "connector_types": ["devs", "apps"], + "tags": [tags.MOBILE] }), IFACE: dict({ "help": "Fake iface", -- 2.43.0