2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import testbed_impl
8 class TestbedController(testbed_impl.TestbedController):
9 def __init__(self, testbed_version):
10 super(TestbedController, self).__init__(TESTBED_ID, testbed_version)
11 self._home_directory = None
15 import node, interfaces
17 self._interfaces = interfaces
20 def home_directory(self):
21 return self._home_directory
24 self._home_directory = self._attributes.\
25 get_attribute_value("homeDirectory")
26 self.slicename = self._attributes.\
27 get_attribute_value("slice")
30 # Create node elements per XML data
31 super(TestbedController, self).do_create()
33 # Perform resource discovery if we don't have
34 # specific resources assigned yet
35 self.do_resource_discovery()
37 # Create PlanetLab slivers
38 self.do_provisioning()
40 # Wait for all nodes to be ready
43 def set(self, time, guid, name, value):
44 super(TestbedController, self).set(time, guid, name, value)
45 # TODO: take on account schedule time for the task
46 element = self._elements[guid]
48 setattr(element, name, value)
50 def get(self, time, guid, name):
51 # TODO: take on account schedule time for the task
52 element = self._elements.get(guid)
55 if hasattr(element, name):
57 return getattr(element, name)
59 # Try design-time attributes
60 return self.box_get(time, guid, name)
61 except KeyError, AttributeError:
64 def get_route(self, guid, index, attribute):
65 # TODO: fetch real data from planetlab
67 return self.box_get_route(guid, int(index), attribute)
68 except KeyError, AttributeError:
71 def get_address(self, guid, index, attribute='Address'):
72 # TODO: fetch real data from planetlab
74 return self.box_get_address(guid, int(index), attribute)
75 except KeyError, AttributeError:
79 def action(self, time, guid, action):
80 raise NotImplementedError
83 for trace in self._traces.values():
85 for element in self._elements.values():
88 def trace_filename(self, guid, trace_id):
89 # TODO: Need to be defined inside a home!!!! with and experiment id_code
90 return os.path.join(self.home_directory, "%d_%s" % (guid, trace_id))
92 def follow_trace(self, trace_id, trace):
93 self._traces[trace_id] = trace
95 def _make_node(self, parameters):
96 node = self._node.Node()
98 # Note: there is 1-to-1 correspondence between attribute names
99 # If that changes, this has to change as well
100 for attr in parameters.get_attribute_names():
101 setattr(node, attr, parameters.get_attribute_value(attr))
105 def _make_node_iface(self, parameters):
106 iface = self._interfaces.NodeIface()
108 # Note: there is 1-to-1 correspondence between attribute names
109 # If that changes, this has to change as well
110 for attr in parameters.get_attribute_names():
111 setattr(iface, attr, parameters.get_attribute_value(attr))
115 def _make_tun_iface(self, parameters):
116 iface = self._interfaces.TunIface()
118 # Note: there is 1-to-1 correspondence between attribute names
119 # If that changes, this has to change as well
120 for attr in parameters.get_attribute_names():
121 setattr(iface, attr, parameters.get_attribute_value(attr))
125 def _make_internet(self, parameters):
126 return self._node.Internet()
128 def _make_application(self, parameters):
129 app = self._app.Application()
131 # Note: there is 1-to-1 correspondence between attribute names
132 # If that changes, this has to change as well
133 for attr in parameters.get_attribute_names():
134 setattr(app, attr, parameters.get_attribute_value(attr))