app.set_attribute_value("command", "ping -qc10 10.0.0.2")
app.connector("node").connect(node1.connector("apps"))
-from nepi.util.parser.base import ExperimentParser
-p = ExperimentParser()
-data = p.to_data(exp_desc)
-print data.data
+xml = exp_desc.to_xml()
exp_desc2 = ExperimentDescription()
-p.from_data(exp_desc2, data)
-data2 = p.to_data(exp_desc2)
-print data2.data
-print data.data == data2.data
-
-from nepi.util.parser._xml import XmlExperimentParser
-p = XmlExperimentParser()
-xml = p.to_xml(exp_desc)
-print xml
-exp_desc2 = ExperimentDescription()
-p.from_xml(exp_desc2, xml)
-xml2 = p.to_xml(exp_desc2)
-print xml2
-print xml == xml2
-
-#print experiment.xml_description
+exp_desc2.from_xml(xml)
+xml2 = exp_desc2.to_xml()
+assert xml == xml2
from nepi.core.attributes import AttributesMap, Attribute
from nepi.util import validation
from nepi.util.guid import GuidGenerator
+from nepi.util.graphical_info import GraphicalInfo
from nepi.util.parser._xml import XmlExperimentParser
import sys
# factory attributes for box construction
self._factory_attributes = list()
+ self.graphical_info = GraphicalInfo(str(self._guid))
+
for connector_type in factory.connector_types:
connector = Connector(self, connector_type)
self._connectors[connector_type.name] = connector
def testbed_version(self):
return self._testbed_version
+ @property
+ def factories(self):
+ return self._factories.values()
+
def factory(self, factory_id):
return self._factories[factory_id]
def remove_factory(self, factory_id):
del self._factories[factory_id]
- def list_factories(self):
- return self._factories.keys()
-
class TestbedDescription(AttributesMap):
def __init__(self, guid_generator, provider):
super(TestbedDescription, self).__init__()
self._guid = guid_generator.next()
self._provider = provider
self._boxes = dict()
+ self.graphical_info = GraphicalInfo(str(self._guid))
@property
def guid(self):
class ExperimentDescription(object):
def __init__(self, guid = 0):
self._guid_generator = GuidGenerator(guid)
- # testbed design instances
self._testbed_descriptions = dict()
@property
"Connector from P2PInterface to Node",
"node", 1, 1,
["netns_node_devs"]),
- ("netns_p2pinterface_p2p",
+ ("netns_p2piface_p2p",
"Connector to another P2PInterface",
"p2p", 1, 0,
["netns_p2piface_p2p"])
testbed_tag.setAttribute("testbed_id", str(testbed_id))
testbed_tag.setAttribute("testbed_version", str(testbed_version))
parent_tag.appendChild(testbed_tag)
+ self.graphical_info_data_to_xml(doc, testbed_tag, guid, data)
self.attributes_data_to_xml(doc, testbed_tag, guid, data)
elements_tag = doc.createElement("elements")
testbed_tag.appendChild(elements_tag)
parent_tag.appendChild(element_tag)
element_tag.setAttribute("factory_id", factory_id)
element_tag.setAttribute("guid", str(guid))
+ self.graphical_info_data_to_xml(doc, element_tag, guid, data)
self.factory_attributes_data_to_xml(doc, element_tag, guid, data)
self.attributes_data_to_xml(doc, element_tag, guid, data)
self.traces_data_to_xml(doc, element_tag, guid, data)
self.addresses_data_to_xml(doc, element_tag, guid, data)
self.routes_data_to_xml(doc, element_tag, guid, data)
self.connections_data_to_xml(doc, element_tag, guid, data)
-
+
+ def graphical_info_data_to_xml(self, doc, parent_tag, guid, data):
+ graphical_info_tag = doc.createElement("graphical_info")
+ parent_tag.appendChild(graphical_info_tag)
+ (x, y, width, height, label) = data.get_graphical_info_data(guid)
+ graphical_info_tag.setAttribute("x", str(x))
+ graphical_info_tag.setAttribute("y", str(y))
+ graphical_info_tag.setAttribute("width", str(width))
+ graphical_info_tag.setAttribute("height", str(height))
+ graphical_info_tag.setAttribute("label", str(label))
+
def factory_attributes_data_to_xml(self, doc, parent_tag, guid, data):
- factory_attributes_tag = doc.createElement("factory_attributes")
+ factory_attributes_tag = doc.createElement("factory_attributes")
parent_tag.appendChild(factory_attributes_tag)
for (name, value) in data.get_factory_attribute_data(guid):
factory_attribute_tag = doc.createElement("factory_attribute")
testbed_id = str(tag.getAttribute("testbed_id"))
testbed_version = str(tag.getAttribute("testbed_version"))
data.add_testbed_data(testbed_guid, testbed_id, testbed_version)
+ self.graphical_info_data_from_xml(tag, testbed_guid, data)
self.attributes_data_from_xml(tag, testbed_guid, data)
def box_data_from_xml(self, tag, testbed_guid, data):
guid = int(tag.getAttribute("guid"))
factory_id = str(tag.getAttribute("factory_id"))
data.add_box_data(guid, testbed_guid, factory_id)
+ self.graphical_info_data_from_xml(tag, guid, data)
self.factory_attributes_data_from_xml(tag, guid, data)
self.attributes_data_from_xml(tag, guid, data)
self.traces_data_from_xml(tag, guid, data)
self.addresses_data_from_xml(tag, guid, data)
self.routes_data_from_xml(tag, guid, data)
self.connections_data_from_xml(tag, guid, data)
-
+
+ def graphical_info_data_from_xml(self, tag, guid, data):
+ graphical_info_tag_list = tag.getElementsByTagName(
+ "graphical_info")
+ if len(graphical_info_tag_list) == 0:
+ return
+
+ graphical_info_tag = graphical_info_tag_list[0]
+ if graphical_info_tag.nodeType == tag.ELEMENT_NODE:
+ x = int(graphical_info_tag.getAttribute("x"))
+ y = int(graphical_info_tag.getAttribute("y"))
+ width = int(graphical_info_tag.getAttribute("width"))
+ height = int(graphical_info_tag.getAttribute("height"))
+ label = str(graphical_info_tag.getAttribute("label"))
+ data.add_graphical_info_data(guid, x, y, width, height, label)
+
def factory_attributes_data_from_xml(self, tag, guid, data):
factory_attributes_tag_list = tag.getElementsByTagName(
"factory_attributes")
box_data["factory_id"] = factory_id
self.data[guid] = box_data
+ def add_graphical_info_data(self, guid, x, y, width, height, label):
+ data = self.data[guid]
+ if not "graphical_info" in data:
+ data["graphical_info"] = dict()
+ graphical_info_data = data["graphical_info"]
+ graphical_info_data["x"] = x
+ graphical_info_data["y"] = y
+ graphical_info_data["width"] = width
+ graphical_info_data["height"] = height
+ graphical_info_data["label"] = label
+
def add_factory_attribute_data(self, guid, name, value):
data = self.data[guid]
if not "factory_attributes" in data:
box_data = self.data[guid]
return (box_data["testbed_guid"], box_data["factory_id"])
+ def get_graphical_info_data(self, guid):
+ data = self.data[guid]
+ if not "graphical_info" in data:
+ return (0, 0, 0, 0, "")
+ graphical_info_data = data["graphical_info"]
+ return (graphical_info_data["x"],
+ graphical_info_data["y"],
+ graphical_info_data["width"],
+ graphical_info_data["height"],
+ graphical_info_data["label"])
+
def get_factory_attribute_data(self, guid):
data = self.data[guid]
if not "factory_attributes" in data:
testbed_id = testbed_description.provider.testbed_id
testbed_version = testbed_description.provider.testbed_version
data.add_testbed_data(guid, testbed_id, testbed_version)
+ self.graphical_info_to_data(data, guid,
+ testbed_description.graphical_info)
self.attributes_to_data(data, guid, testbed_description.attributes)
for box in testbed_description.boxes:
data.add_box_data(box.guid, guid, box.factory_id)
+ self.graphical_info_to_data(data, box.guid, box.graphical_info)
self.factory_attributes_to_data(data, box.guid,
box.factory_attributes)
self.attributes_to_data(data, box.guid, box.attributes)
self.routes_to_data(data, box.guid, box.routes)
return data
+ def graphical_info_to_data(self, data, guid, g_info):
+ data.add_graphical_info_data(guid, g_info.x, g_info.y, g_info.width,
+ g_info.height, g_info.label)
+
def factory_attributes_to_data(self, data, guid, attributes):
for attribute in attributes:
if attribute.modified:
self.factory_attributes_from_data(testbed_description, factory_id,
guid, data)
box = testbed_description.create(factory_id)
+ self.graphical_info_from_data(box, data)
self.attributes_from_data(box, data)
self.traces_from_data(box, data)
self.addresses_from_data(box, data)
self.routes_from_data(box, data)
+ def graphical_info_from_data(self, element, data):
+ (x, y, width, height, label) = data.get_graphical_info_data(
+ element.guid)
+ element.graphical_info.x = x
+ element.graphical_info.y = y
+ element.graphical_info.width = width
+ element.graphical_info.height = height
+ element.graphical_info.label = label
+
def factory_attributes_from_data(self, testbed_description, factory_id,
guid, data):
factory = testbed_description.provider.factory(factory_id)