added tags to boxes. For now only one tag: MOBILE
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 23 May 2011 21:01:50 +0000 (23:01 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Mon, 23 May 2011 21:01:50 +0000 (23:01 +0200)
src/nepi/core/design.py
src/nepi/core/execute.py
src/nepi/core/metadata.py
src/nepi/core/testbed_impl.py
src/nepi/testbeds/ns3/factories_metadata_v3_9_RC3.py
src/nepi/util/proxy.py
test/core/design.py
test/core/execute.py
test/core/integration.py
test/lib/mock/metadata_v01.py

index 50e00c1..c942d10 100644 (file)
@@ -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):
index 67e5ebc..3b1463a 100644 (file)
@@ -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()
index 4ae57a1..c8015cd 100644 (file)
@@ -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:
index 288b234..b34b8fe 100644 (file)
@@ -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()
index febb5c4..4e695dd 100644 (file)
@@ -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": "",
index 059ccff..3a64ecd 100644 (file)
@@ -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
index 2481d19..8401533 100755 (executable)
@@ -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)
index e5c609f..2f39379 100755 (executable)
@@ -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()
 
index f099c08..ea12585 100755 (executable)
@@ -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
         
index 5478c7e..2b7d37c 100644 (file)
@@ -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",