for testbed_description in self.testbed_descriptions:
testbed_description.destroy()
-# TODO: When the experiment xml is passed to the controller to execute it
-# NetReferences in the xml need to be solved
-#
-#targets = re.findall(r"%target:(.*?)%", command)
-#for target in targets:
-# try:
-# (family, address, port) = resolve_netref(target, AF_INET,
-# self.server.experiment )
-# command = command.replace("%%target:%s%%" % target, address.address)
-# except:
-# continue
def experiment_xml(self):
return self._experiment_xml
+ @property
+ def guids(self):
+ guids = list()
+ for testbed_guid in self._testbeds.keys():
+ _guids = self._guids_in_testbed(testbed_guid)
+ if _guids:
+ guids.extend(_guids)
+ return guids
+
def persist_experiment_xml(self):
xml_path = os.path.join(self._root_dir, "experiment.xml")
f = open(xml_path, "w")
f.write(self._experiment_xml)
f.close()
- def trace(self, testbed_guid, guid, trace_id, attribute='value'):
- return self._testbeds[testbed_guid].trace(guid, trace_id, attribute)
+ def trace(self, guid, trace_id, attribute='value'):
+ testbed = self._testbed_for_guid(guid)
+ if testbed != None:
+ return testbed.trace(guid, trace_id, attribute)
+ raise RuntimeError("No element exists with guid %d" % guid)
@staticmethod
def _parallel(callables):
# 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()
+
# start experiment (parallel start on all testbeds)
self._parallel([testbed.start
for testbed in self._testbeds.itervalues()])
self._init_testbed_controllers(recover = True)
def is_finished(self, guid):
- for testbed in self._testbeds.values():
- if guid in testbed.guids:
- return testbed.status(guid) == STATUS_FINISHED
+ testbed = self._testbed_for_guid(guid)
+ if testbed != None:
+ return testbed.status(guid) == STATUS_FINISHED
raise RuntimeError("No element exists with guid %d" % guid)
- def set(self, testbed_guid, guid, name, value, time = TIME_NOW):
- testbed = self._testbeds[testbed_guid]
- testbed.set(guid, name, value, time)
+ def set(self, guid, name, value, time = TIME_NOW):
+ testbed = self._testbed_for_guid(guid)
+ if testbed != None:
+ testbed.set(guid, name, value, time)
+ raise RuntimeError("No element exists with guid %d" % guid)
- def get(self, testbed_guid, guid, name, time = TIME_NOW):
- testbed = self._testbeds[testbed_guid]
- return testbed.get(guid, name, time)
+ def get(self, guid, name, time = TIME_NOW):
+ testbed = self._testbed_for_guid(guid)
+ if testbed != None:
+ return testbed.get(guid, name, time)
+ raise RuntimeError("No element exists with guid %d" % guid)
- def get_tags(self, testbed_guid, guid):
- testbed = self._testbeds[testbed_guid]
- return testbed.get_tags(guid)
+ def get_tags(self, guid):
+ testbed = self._testbed_for_guid(guid)
+ if testbed != None:
+ return testbed.get_tags(guid)
+ raise RuntimeError("No element exists with guid %d" % guid)
def shutdown(self):
for testbed in self._testbeds.values():
testbed.shutdown()
-
+
+ def _testbed_for_guid(self, guid):
+ for testbed_guid in self._testbeds.keys():
+ if guid in self._guids_in_testbed(testbed_guid):
+ return self._testbeds[testbed_guid]
+ return None
+
def _guids_in_testbed(self, testbed_guid):
if testbed_guid not in self._testbeds:
return set()
self._controller = ExperimentController(self._experiment_xml,
root_dir = self._root_dir)
+ @Marshalling.handles(GUIDS)
+ @Marshalling.args()
+ @Marshalling.retval( Marshalling.pickled_data )
+ def guids(self):
+ return self._controller.guids
+
@Marshalling.handles(XML)
@Marshalling.args()
@Marshalling.retval()
return self._controller.experiment_xml
@Marshalling.handles(TRACE)
- @Marshalling.args(int, int, str, Marshalling.base64_data)
+ @Marshalling.args(int, str, Marshalling.base64_data)
@Marshalling.retval()
- def trace(self, testbed_guid, guid, trace_id, attribute):
- return str(self._controller.trace(testbed_guid, guid, trace_id, attribute))
+ def trace(self, guid, trace_id, attribute):
+ return str(self._controller.trace(guid, trace_id, attribute))
@Marshalling.handles(FINISHED)
@Marshalling.args(int)
return self._controller.is_finished(guid)
@Marshalling.handles(EXPERIMENT_GET)
- @Marshalling.args(int, int, Marshalling.base64_data, str)
+ @Marshalling.args(int, Marshalling.base64_data, str)
@Marshalling.retval( Marshalling.pickled_data )
- def get(self, testbed_guid, guid, name, time):
- return self._controller.get(testbed_guid, guid, name, time)
+ def get(self, guid, name, time):
+ return self._controller.get(guid, name, time)
@Marshalling.handles(EXPERIMENT_SET)
- @Marshalling.args(int, int, Marshalling.base64_data, Marshalling.pickled_data, str)
+ @Marshalling.args(int, Marshalling.base64_data, Marshalling.pickled_data, str)
@Marshalling.retvoid
- def set(self, testbed_guid, guid, name, value, time):
- self._controller.set(testbed_guid, guid, name, value, time)
+ def set(self, guid, name, value, time):
+ self._controller.set(guid, name, value, time)
@Marshalling.handles(GET_TAGS)
- @Marshalling.args(int, int)
+ @Marshalling.args(int)
@Marshalling.retval( Marshalling.pickled_data )
- def get_tags(self, testbed_guid, guid):
- return self._controller.get_tags(testbed_guid, guid)
+ def get_tags(self, guid):
+ return self._controller.get_tags(guid)
@Marshalling.handles(START)
@Marshalling.args()
--- /dev/null
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+
+MOBILE = 0
+
controller = proxy.create_controller(xml, access_config)
controller.start()
- cross1 = controller.get(desc1.guid, iface12.guid, "cross")
- cross2 = controller.get(desc2.guid, iface21.guid, "cross")
+ cross1 = controller.get(iface12.guid, "cross")
+ cross2 = controller.get(iface21.guid, "cross")
self.assertTrue(cross1 == cross2 == True)
controller.stop()
controller.shutdown()
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
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])
+ self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
controller.stop()
controller.shutdown()
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
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])
+ self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
controller.stop()
controller.shutdown()
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
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])
+ self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
controller.stop()
controller.shutdown()
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
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])
+ self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
controller.stop()
controller.shutdown()
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
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])
+ self.assertEquals(controller.get_tags(node1.guid), [tags.MOBILE])
# controller dies
del controller
# test recovery
self.assertTrue(controller.is_finished(app.guid))
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
self.assertTrue(fake_result.startswith(comp_result))
controller.stop()
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- fake_result = controller.trace(desc.guid, app.guid, "fake")
+ fake_result = controller.trace(app.guid, "fake")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- ping_result = controller.trace(netns_desc.guid, app.guid, "stdout")
+ ping_result = controller.trace(app.guid, "stdout")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- ping_result = controller.trace(netns_desc.guid, app.guid, "stdout")
+ ping_result = controller.trace(app.guid, "stdout")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- ping_result = controller.trace(netns_desc.guid, app.guid, "stdout")
+ ping_result = controller.trace(app.guid, "stdout")
comp_result = """PING 10.0.0.2 (10.0.0.2) 56(84) bytes of data.
--- 10.0.0.2 ping statistics ---
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- ping_result = controller.trace(ns3_desc.guid, iface2.guid, "P2PAsciiTrace")
+ ping_result = controller.trace(iface2.guid, "P2PAsciiTrace")
comp_result = "- 19.021 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 19 protocol 1 offset 0 flags [none] length: 84 10.0.0.2 > 10.0.0.1) ns3::Icmpv4Header (type=0, code=0) ns3::Icmpv4Echo (identifier=0, sequence=19)"
if ping_result.find(comp_result) == -1:
self.fail("Unexpected trace: %s" % (ping_result,))
while not controller.is_finished(app.guid):
time.sleep(0.5)
- ping_result = controller.trace(ns3_desc.guid, iface2.guid, "P2PAsciiTrace")
+ ping_result = controller.trace(iface2.guid, "P2PAsciiTrace")
comp_result = "- 19.021 /NodeList/1/DeviceList/0/$ns3::PointToPointNetDevice/TxQueue/Dequeue ns3::PppHeader (Point-to-Point Protocol: IP (0x0021)) ns3::Ipv4Header (tos 0x0 ttl 64 id 19 protocol 1 offset 0 flags [none] length: 84 10.0.0.2 > 10.0.0.1) ns3::Icmpv4Header (type=0, code=0) ns3::Icmpv4Echo (identifier=0, sequence=19)"
if ping_result.find(comp_result) == -1:
self.fail("Unexpected trace: %s" % (ping_result,))
controller.start()
while not controller.is_finished(app.guid):
time.sleep(0.5)
- ping_result = controller.trace(pl.guid, app.guid, "stdout")
+ ping_result = controller.trace(app.guid, "stdout")
comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
--- .* ping statistics ---