-#!/usr/bin/env python
# -*- coding: utf-8 -*-
"""
from nepi.util.guid import GuidGenerator
from nepi.util.graphical_info import GraphicalInfo
from nepi.util.parser._xml import XmlExperimentParser
+from nepi.util.tags import Taggable
import sys
class Connector(object):
self._connections.append(connector)
connector._connections.append(self)
+ def get_connected_box(self, idx = 0):
+ if len(self._connections) == 0:
+ return None
+ return self._connections[idx].box
+
def disconnect(self, connector):
if connector not in self._connections or\
self not in connector._connections:
self.add_attribute(name = "Address",
help = "Address number",
type = Attribute.STRING,
- flags = Attribute.HasNoDefaultValue,
+ flags = Attribute.NoDefaultValue,
validation_function = validation.is_ip_address)
self.add_attribute(name = "NetPrefix",
help = "Network prefix for the address",
type = Attribute.INTEGER,
range = (0, 128),
value = 24,
- flags = Attribute.HasNoDefaultValue,
+ flags = Attribute.NoDefaultValue,
validation_function = validation.is_integer)
self.add_attribute(name = "Broadcast",
help = "Broadcast address",
type = Attribute.INTEGER,
range = (0, 128),
value = 24,
- flags = Attribute.HasNoDefaultValue,
+ flags = Attribute.NoDefaultValue,
validation_function = validation.is_integer)
self.add_attribute(name = "NextHop",
help = "Address for the next hop",
type = Attribute.STRING,
- flags = Attribute.HasNoDefaultValue,
+ flags = Attribute.NoDefaultValue,
validation_function = validation.is_ref_address)
self.add_attribute(name = "Metric",
help = "Routing metric",
type = Attribute.INTEGER,
value = 0,
- flags = Attribute.HasNoDefaultValue,
+ flags = Attribute.NoDefaultValue,
validation_function = validation.is_integer)
+ self.add_attribute(name = "Device",
+ help = "Device name",
+ type = Attribute.STRING,
+ value = None,
+ flags = Attribute.NoDefaultValue,
+ validation_function = validation.is_string)
-class Box(AttributesMap):
+class Box(AttributesMap, Taggable):
def __init__(self, guid, factory, testbed_guid, container = None):
super(Box, self).__init__()
# guid -- global unique identifier
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
trace = Trace(name, help, enabled)
self._traces[name] = trace
for tag_id in factory.tags:
- self._tags.append(tag_id)
+ self.add_tag(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,
attr.validation_function, attr.category)
for attr in factory.attributes:
- if attr.modified or attr.invisible:
+ if attr.modified or attr.is_metadata:
self._factory_attributes[attr.name] = attr.value
def __str__(self):
def factory_attributes(self):
return self._factory_attributes
- @property
- def tags(self):
- return self._tags
-
def trace_help(self, trace_id):
return self._traces[trace_id].help
self._connectors = self._traces = self._factory_attributes = None
class FactoriesProvider(object):
- def __init__(self, testbed_id, testbed_version):
+ def __init__(self, testbed_id):
super(FactoriesProvider, self).__init__()
self._testbed_id = testbed_id
- self._testbed_version = testbed_version
self._factories = dict()
- metadata = Metadata(testbed_id, testbed_version)
+ metadata = Metadata(testbed_id)
for factory in metadata.build_factories():
self.add_factory(factory)
+ self._testbed_version = metadata.testbed_version
+
@property
def testbed_id(self):
return self._testbed_id
self._boxes = dict()
self.graphical_info = GraphicalInfo()
- metadata = Metadata(provider.testbed_id, provider.testbed_version)
+ metadata = Metadata(provider.testbed_id)
for attr in metadata.testbed_attributes().attributes:
self.add_attribute(attr.name, attr.help, attr.type, attr.value,
attr.range, attr.allowed, attr.flags,
if box: return box
return None
+ def get_element_by_label(self, label):
+ for tbd_desc in self._testbed_descriptions.values():
+ l = tbd_desc.get_attribute_value("label")
+ if label == l:
+ return tbd_desc
+ for box in tbd_desc.boxes:
+ l = box.get_attribute_value("label")
+ if label == l:
+ return box
+ return None
+
def add_testbed_description(self, provider, guid = None):
testbed_description = TestbedDescription(self._guid_generator,
provider, guid)