# create vlc server
# DEBUG!! target = "{#[vlc_client].addr[0].[Address]#}"
target = "10.0.2.2"
- command = "vlc -I dummy -vvv %s --sout '#rtp{dst=%s,port=5004,mux=ts}' vlc:quit" \
+ command = "vlc -I dummy -vvv %s --sout '#rtp{dst=%s,port=5004,mux=ts}' vlc://quit" \
% (self.movie, target)
vlc_server = netns_desc1.create("Application")
vlc_server.set_attribute_value("command", command)
vlc_client.set_attribute_value("command", command)
vlc_client.set_attribute_value("user", self.user)
vlc_client.connector("node").connect(node4.connector("apps"))
- #vlc_trace = vlc_server.get_trace("StderrTrace")
- #vlc_trace.get_attribute("Filename").value = "vlc_server.err"
- #vlc_trace.enable()
#command = "xterm"
#xterm2 = netns_desc2.create("Application")
from nepi.util.graphical_info import GraphicalInfo
from nepi.util.parser._xml import XmlExperimentParser
import sys
-
-
class ConnectorType(ConnectorTypeBase):
def __init__(self, testbed_id, factory_id, name, help, max = -1, min = 0):
super(Trace, self).__init__()
self._trace_id = trace_id
self._help = help
- self.enabled = enabled
+ self._enabled = enabled
@property
def trace_id(self):
def help(self):
return self._help
+ @property
+ def enabled(self):
+ return self._enabled
+
+ def enable(self):
+ self._enabled = True
+
+ def disable(self):
+ self._enabled = False
+
class Address(AttributesMap):
def __init__(self):
super(Address, self).__init__()
# factory_attributes -- factory attributes for box construction
self._factory_attributes = dict()
# graphical_info -- GUI position information
- self.graphical_info = GraphicalInfo(str(self._guid))
+ self.graphical_info = GraphicalInfo()
for connector_type in factory.connector_types:
connector = Connector(self, connector_type)
return self._traces.values()
@property
- def traces_name(self):
+ def trace_names(self):
return self._traces.keys()
@property
return self._traces[trace_id].help
def enable_trace(self, trace_id):
- self._traces[trace_id].enabled = True
+ self._traces[trace_id].enable()
def disable_trace(self, trace_id):
- self._traces[trace_id].enabled = False
+ self._traces[trace_id].disable()
+
+ def is_trace_enabled(self, trace_id):
+ return self._traces[trace_id].enabled
def connector(self, name):
return self._connectors[name]
del self._factories[factory_id]
class TestbedDescription(AttributesMap):
- def __init__(self, guid_generator, provider):
+ def __init__(self, guid_generator, provider, guid = None):
super(TestbedDescription, self).__init__()
self._guid_generator = guid_generator
- self._guid = guid_generator.next()
+ self._guid = guid_generator.next(guid)
self._provider = provider
self._boxes = dict()
- self.graphical_info = GraphicalInfo(str(self._guid))
+ self.graphical_info = GraphicalInfo()
metadata = Metadata(provider.testbed_id, provider.testbed_version)
for attr in metadata.testbed_attributes().attributes:
def box(self, guid):
return self._boxes[guid] if guid in self._boxes else None
- def create(self, factory_id):
- guid = self._guid_generator.next()
+ def create(self, factory_id, guid = None):
+ guid = self._guid_generator.next(guid)
factory = self._provider.factory(factory_id)
box = factory.create(guid, self)
self._boxes[guid] = box
self._boxes = None
class ExperimentDescription(object):
- def __init__(self, guid = 0):
- self._guid_generator = GuidGenerator(guid)
+ def __init__(self):
+ self._guid_generator = GuidGenerator()
self._testbed_descriptions = dict()
@property
if box: return box
return None
- def add_testbed_description(self, provider):
+ def get_element(self, guid):
+ if guid in self._testbed_descriptions:
+ return self._testbed_descriptions[guid]
+ for testbed_description in self._testbed_descriptions.values():
+ box = testbed_description.box(guid)
+ if box: return box
+ return None
+
+ def add_testbed_description(self, provider, guid = None):
testbed_description = TestbedDescription(self._guid_generator,
- provider)
+ provider, guid)
guid = testbed_description.guid
self._testbed_descriptions[guid] = testbed_description
return testbed_description
- def remove_testbed_description(self, testbed_description):
- guid = testbed_description.guid
+ def remove_testbed_description(self, guid):
+ testbed_description = self._testbed_descriptions[guid]
del self._testbed_descriptions[guid]
+ testbed_description.destroy()
def destroy(self):
for testbed_description in self.testbed_descriptions:
def get_attribute_list(self, guid):
raise NotImplementedError
- def get_tags(self, guid):
+ def get_factory_id(self, guid):
raise NotImplementedError
def action(self, time, guid, action):
self._parallel([testbed.do_setup
for guid,testbed in self._testbeds.iteritems()
if guid in allowed_guids])
-
+
# perform create-connect in parallel, wait
# (internal connections only)
self._parallel([testbed.do_create
self._parallel([testbed.do_preconfigure
for guid,testbed in self._testbeds.iteritems()
if guid in allowed_guids])
-
+ self._clear_caches()
+
steps_to_configure(self, self._testbeds)
-
+
if self._netreffed_testbeds:
# initally resolve netrefs
self.do_netrefs(data, fail_if_undefined=False)
self._parallel([testbed.do_configure
for testbed in self._testbeds.itervalues()])
-
+ self._clear_caches()
+
#print >>sys.stderr, "DO IT"
#import time
#time.sleep(60)
cross_data = self._get_cross_data(guid)
testbed.do_cross_connect_compl(cross_data)
+ self._clear_caches()
+
# Last chance to configure (parallel on all testbeds)
self._parallel([testbed.do_prestart
for testbed in self._testbeds.itervalues()])
- # After this point no new elements will be craeted. Cleaning cache for safety.
- self._guids_in_testbed_cache = dict()
+ self._clear_caches()
# start experiment (parallel start on all testbeds)
self._parallel([testbed.start
for testbed in self._testbeds.itervalues()])
+ self._clear_caches()
+
+ def _clear_caches(self):
+ # Cleaning cache for safety.
+ self._guids_in_testbed_cache = dict()
+
def _persist_testbed_proxies(self):
TRANSIENT = ('Recover',)
testbed = self._testbed_for_guid(guid)
if testbed != None:
testbed.set(guid, name, value, time)
- raise RuntimeError("No element exists with guid %d" % guid)
+ else:
+ raise RuntimeError("No element exists with guid %d" % guid)
def get(self, guid, name, time = TIME_NOW):
testbed = self._testbed_for_guid(guid)
return testbed.get(guid, name, time)
raise RuntimeError("No element exists with guid %d" % guid)
- def get_tags(self, guid):
+ def get_factory_id(self, guid):
+ testbed = self._testbed_for_guid(guid)
+ if testbed != None:
+ return testbed.get_factory_id(guid)
+ raise RuntimeError("No element exists with guid %d" % guid)
+
+ def get_testbed_id(self, guid):
+ testbed = self._testbed_for_guid(guid)
+ if testbed != None:
+ return testbed.testbed_id
+ raise RuntimeError("No element exists with guid %d" % guid)
+
+ def get_testbed_version(self, guid):
testbed = self._testbed_for_guid(guid)
if testbed != None:
- return testbed.get_tags(guid)
+ return testbed.testbed_version
raise RuntimeError("No element exists with guid %d" % guid)
def shutdown(self):
value = "",
flags = Attribute.DesignOnly
)),
+ ("label", dict(
+ name = "label",
+ validation_function = validation.is_string,
+ type = Attribute.STRING,
+ flags = Attribute.DesignOnly,
+ help = "A unique identifier for referring to this testbed",
+ )),
)
DEPLOYMENT_ATTRIBUTES = (
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()
return factory.box_attributes.attributes_list
+ def get_factory_id(self, guid):
+ factory = self._get_factory(guid)
+ return factory.factory_id
+
def start(self, time = TIME_NOW):
self._do_in_factory_order(
'start_function',
#!/usr/bin/env python
# -*- coding: utf-8 -*-
-from constants import TESTBED_ID
from nepi.core import testbed_impl
from nepi.core.attributes import Attribute
-from nepi.util.constants import TIME_NOW
+from constants import TESTBED_ID
+from nepi.util.constants import TIME_NOW, \
+ TESTBED_STATUS_STARTED
import os
import sys
import threading
elif factory.box_attributes.is_attribute_invisible(name):
return
else:
- ns3_value = self._to_ns3_value(guid, name, value)
- element.SetAttribute(name, ns3_value)
+ ns3_value = self._to_ns3_value(guid, name, value)
+ self._set_attribute(name, ns3_value, element)
def get(self, guid, name, time = TIME_NOW):
value = super(TestbedController, self).get(guid, name, time)
(name, guid))
checker = info.checker
ns3_value = checker.Create()
- element.GetAttribute(name, ns3_value)
+ self._get_attribute(name, ns3_value, element)
value = ns3_value.SerializeToString(checker)
attr_type = factory.box_attributes.get_attribute_type(name)
if attr_type == Attribute.INTEGER:
"""Schedules event on running experiment"""
def execute_event(condition, has_event_occurred, func, *args):
# exec func
- func(*args)
- # flag event occured
- has_event_occurred[0] = True
- # notify condition indicating attribute was set
- condition.acquire()
- condition.notifyAll()
- condition.release()
+ try:
+ func(*args)
+ finally:
+ # flag event occured
+ has_event_occurred[0] = True
+ # notify condition indicating attribute was set
+ condition.acquire()
+ condition.notifyAll()
+ condition.release()
# contextId is defined as general context
contextId = long(0xffffffff)
while not has_event_occurred[0] and not self.ns3.Simulator.IsFinished():
condition.wait()
condition.release()
- if not has_event_occurred[0]:
- raise RuntimeError('Event could not be scheduled : %s %s ' \
- % (repr(func), repr(args)))
+
+ def _set_attribute(self, name, ns3_value, element):
+ if self.status() == TESTBED_STATUS_STARTED:
+ # schedule the event in the Simulator
+ self._schedule_event(self._condition, self._set_ns3_attribute,
+ name, ns3_value, element)
+ else:
+ self._set_ns3_attribute(name, ns3_value, element)
+
+ def _get_attribute(self, name, ns3_value, element):
+ if self.status() == TESTBED_STATUS_STARTED:
+ # schedule the event in the Simulator
+ self._schedule_event(self._condition, self._get_ns3_attribute,
+ name, ns3_value, element)
+ else:
+ self._get_ns3_attribute(name, ns3_value, element)
+
+ def _set_ns3_attribute(self, name, ns3_value, element):
+ element.SetAttribute(name, ns3_value)
+
+ def _get_ns3_attribute(self, name, ns3_value, element):
+ element.GetAttribute(name, ns3_value)
def _to_ns3_value(self, guid, name, value):
factory_id = self._create[guid]
class GraphicalInfo(object):
""" This class allows to describe the position and dimensions of a
2D object in a GUI canvas"""
- def __init__(self, label):
+ def __init__(self):
self.x = 0.0
self.y = 0.0
self.width = 0.0
self.height = 0.0
- self.label = label
# -*- coding: utf-8 -*-
class GuidGenerator(object):
- def __init__(self, guid = 0):
- self._last_guid = guid
+ def __init__(self):
+ self._guids = list()
- def next(self):
- self._last_guid += 1
- return self._last_guid
+ def next(self, guid = None):
+ if guid != None:
+ if guid in self._guids:
+ raise RuntimeError("guid %d is already assigned" % guid)
+ else:
+ last_guid = 0 if len(self._guids) == 0 else self._guids[-1]
+ guid = last_guid + 1
+ self._guids.append(guid)
+ self._guids.sort()
+ return guid
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)
+ (x, y, width, height) = 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")
y = float(graphical_info_tag.getAttribute("y"))
width = float(graphical_info_tag.getAttribute("width"))
height = float(graphical_info_tag.getAttribute("height"))
- label = str(graphical_info_tag.getAttribute("label"))
- data.add_graphical_info_data(guid, x, y, width, height, label)
+ data.add_graphical_info_data(guid, x, y, width, height)
def factory_attributes_data_from_xml(self, tag, guid, data):
factory_attributes_tag_list = tag.getElementsByTagName(
box_data["factory_id"] = factory_id
self.data[guid] = box_data
- def add_graphical_info_data(self, guid, x, y, width, height, label):
+ def add_graphical_info_data(self, guid, x, y, width, height):
data = self.data[guid]
if not "graphical_info" in data:
data["graphical_info"] = dict()
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]
return (graphical_info_data["x"],
graphical_info_data["y"],
graphical_info_data["width"],
- graphical_info_data["height"],
- graphical_info_data["label"])
+ graphical_info_data["height"])
def get_factory_attribute_data(self, guid):
data = self.data[guid]
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)
+ g_info.height)
def factory_attributes_to_data(self, data, guid, factory_attributes):
factory_attributes = factory_attributes or dict()
from nepi.core.design import FactoriesProvider
(testbed_id, testbed_version) = data.get_testbed_data(guid)
provider = FactoriesProvider(testbed_id, testbed_version)
- experiment_description.add_testbed_description(provider)
+ experiment_description.add_testbed_description(provider, guid)
testbed_description = experiment_description.testbed_description(guid)
self.graphical_info_from_data(testbed_description, data)
self.attributes_from_data(testbed_description, data)
testbed_guid)
self.factory_attributes_from_data(testbed_description, factory_id,
guid, data)
- box = testbed_description.create(factory_id)
+ box = testbed_description.create(factory_id, guid)
+
self.graphical_info_from_data(box, data)
self.attributes_from_data(box, data)
self.traces_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(
+ (x, y, width, height) = 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):
DO_CROSS_CONNECT_COMPL = 34
TESTBED_ID = 35
TESTBED_VERSION = 36
-EXPERIMENT_SET = 37
-EXPERIMENT_GET = 38
-DO_PRESTART = 39
-GET_TAGS = 40
+DO_PRESTART = 37
+GET_FACTORY_ID = 38
+GET_TESTBED_ID = 39
+GET_TESTBED_VERSION = 40
instruction_text = dict({
OK: "OK",
GET_ROUTE: "GET_ROUTE",
GET_ADDRESS: "GET_ADDRESS",
GET_ATTRIBUTE_LIST: "GET_ATTRIBUTE_LIST",
+ GET_FACTORY_ID: "GET_FACTORY_ID",
+ GET_TESTBED_ID: "GET_TESTBED_ID",
+ GET_TESTBED_VERSION: "GET_TESTBED_VERSION",
ACTION: "ACTION",
STATUS: "STATUS",
GUIDS: "GUIDS",
TESTBED_ID: "TESTBED_ID",
TESTBED_VERSION: "TESTBED_VERSION",
- EXPERIMENT_SET: "EXPERIMENT_SET",
- EXPERIMENT_GET: "EXPERIMENT_GET",
- GET_TAGS: "GET_TAGS",
})
def log_msg(server, params):
def get_attribute_list(self, guid):
return self._testbed.get_attribute_list(guid)
- @Marshalling.handles(GET_TAGS)
+ @Marshalling.handles(GET_FACTORY_ID)
@Marshalling.args(int)
- @Marshalling.retval( Marshalling.pickled_data )
- def get_tags(self, guid):
- return self._testbed.get_tags(guid)
+ @Marshalling.retval()
+ def get_factory_id(self, guid):
+ return self._testbed.get_factory_id(guid)
class ExperimentControllerServer(BaseServer):
def __init__(self, root_dir, log_level, experiment_xml):
def is_finished(self, guid):
return self._controller.is_finished(guid)
- @Marshalling.handles(EXPERIMENT_GET)
+ @Marshalling.handles(GET)
@Marshalling.args(int, Marshalling.base64_data, str)
@Marshalling.retval( Marshalling.pickled_data )
def get(self, guid, name, time):
return self._controller.get(guid, name, time)
- @Marshalling.handles(EXPERIMENT_SET)
+ @Marshalling.handles(SET)
@Marshalling.args(int, Marshalling.base64_data, Marshalling.pickled_data, str)
@Marshalling.retvoid
def set(self, guid, name, value, time):
self._controller.set(guid, name, value, time)
- @Marshalling.handles(GET_TAGS)
- @Marshalling.args(int)
- @Marshalling.retval( Marshalling.pickled_data )
- def get_tags(self, guid):
- return self._controller.get_tags(guid)
-
@Marshalling.handles(START)
@Marshalling.args()
@Marshalling.retvoid
def shutdown(self):
self._controller.shutdown()
+ @Marshalling.handles(GET_TESTBED_ID)
+ @Marshalling.args(int)
+ @Marshalling.retval()
+ def get_testbed_id(self, guid):
+ return self._controller.get_testbed_id(guid)
+
+ @Marshalling.handles(GET_FACTORY_ID)
+ @Marshalling.args(int)
+ @Marshalling.retval()
+ def get_factory_id(self, guid):
+ return self._controller.get_factory_id(guid)
+
+ @Marshalling.handles(GET_TESTBED_VERSION)
+ @Marshalling.args(int)
+ @Marshalling.retval()
+ def get_testbed_version(self, guid):
+ return self._controller.get_testbed_version(guid)
+
class BaseProxy(object):
_ServerClass = None
_ServerClassModule = "nepi.util.proxy"
"""
self.assertTrue(app_result.startswith(comp_result))
- self.assertEquals(instance.get_tags(4), [tags.MOBILE])
instance.stop()
instance.shutdown()
# -*- coding: utf-8 -*-
from nepi.core.design import ExperimentDescription, FactoriesProvider
-from nepi.util import proxy, tags
+from nepi.util import proxy
from nepi.util.constants import STATUS_FINISHED, DeploymentConfiguration as DC
import mock
import mock.metadata_v01
1 packets transmitted, 1 received, 0% packet loss, time 0ms
"""
self.assertTrue(fake_result.startswith(comp_result))
- self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+ self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+ self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+ self.assertEquals(controller.get_factory_id(node1.guid), "Node")
controller.stop()
controller.shutdown()
1 packets transmitted, 1 received, 0% packet loss, time 0ms
"""
self.assertTrue(fake_result.startswith(comp_result))
- self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+ self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+ self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+ self.assertEquals(controller.get_factory_id(node1.guid), "Node")
controller.stop()
controller.shutdown()
1 packets transmitted, 1 received, 0% packet loss, time 0ms
"""
self.assertTrue(fake_result.startswith(comp_result))
- self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+ self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+ self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+ self.assertEquals(controller.get_factory_id(node1.guid), "Node")
controller.stop()
controller.shutdown()
1 packets transmitted, 1 received, 0% packet loss, time 0ms
"""
self.assertTrue(fake_result.startswith(comp_result))
- self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+ self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+ self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+ self.assertEquals(controller.get_factory_id(node1.guid), "Node")
controller.stop()
controller.shutdown()
1 packets transmitted, 1 received, 0% packet loss, time 0ms
"""
self.assertTrue(fake_result.startswith(comp_result))
- self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
+
+ self.assertEquals(controller.get_testbed_id(node1.guid), "mock")
+ self.assertEquals(controller.get_testbed_version(node1.guid), "01")
+ self.assertEquals(controller.get_factory_id(node1.guid), "Node")
# controller dies
del controller