2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import testbed_impl
6 from nepi.util.constants import TIME_NOW
9 class TestbedController(testbed_impl.TestbedController):
10 from nepi.util.tunchannel_impl import TunChannel
12 def __init__(self, testbed_version):
13 super(TestbedController, self).__init__(TESTBED_ID, testbed_version)
15 self._home_directory = None
19 def home_directory(self):
20 return self._home_directory
27 self._home_directory = self._attributes.\
28 get_attribute_value("homeDirectory")
29 self._netns = self._load_netns_module()
30 super(TestbedController, self).do_setup()
32 def set(self, guid, name, value, time = TIME_NOW):
33 super(TestbedController, self).set(guid, name, value, time)
34 # TODO: take on account schedule time for the task
35 factory_id = self._create[guid]
36 factory = self._factories[factory_id]
37 if factory.box_attributes.is_attribute_design_only(name):
39 element = self._elements.get(guid)
41 setattr(element, name, value)
43 def get(self, guid, name, time = TIME_NOW):
44 value = super(TestbedController, self).get(guid, name, time)
45 # TODO: take on account schedule time for the task
46 factory_id = self._create[guid]
47 factory = self._factories[factory_id]
48 if factory.box_attributes.is_attribute_design_only(name):
50 element = self._elements.get(guid)
52 return getattr(element, name)
53 except KeyError, AttributeError:
56 def action(self, time, guid, action):
57 raise NotImplementedError
60 for trace in self._traces.values():
62 for guid, element in self._elements.iteritems():
63 if isinstance(element, self.TunChannel):
66 factory_id = self._create[guid]
67 if factory_id == "Node":
69 self._elements.clear()
71 def trace_filename(self, guid, trace_id):
72 # TODO: Need to be defined inside a home!!!! with and experiment id_code
73 return os.path.join(self.home_directory, "%d_%s" % (guid, trace_id))
75 def follow_trace(self, trace_id, trace):
76 self._traces[trace_id] = trace
78 def _load_netns_module(self):
79 # TODO: Do something with the configuration!!!
82 netns_mod = sys.modules["netns"]
84 enable_debug = self._attributes.get_attribute_value("enableDebug")
86 netns_mod.environ.set_log_level(netns_mod.environ.LOG_DEBUG)