2 # -*- coding: utf-8 -*-
4 from constants import TESTBED_ID
5 from nepi.core import testbed_impl
8 class TestbedInstance(testbed_impl.TestbedInstance):
9 def __init__(self, testbed_version):
10 super(TestbedInstance, self).__init__(TESTBED_ID, testbed_version)
12 self._home_directory = None
16 def home_directory(self):
17 return self._home_directory
24 self._home_directory = self._attributes.\
25 get_attribute_value("homeDirectory")
26 self._netns = self._load_netns_module()
28 def do_configure(self):
30 # configure addressess
31 for guid, addresses in self._add_address.iteritems():
32 element = self._elements[guid]
33 for address in addresses:
34 (address, netprefix, broadcast) = address
35 # TODO: Decide if we should add a ipv4 or ipv6 address
36 element.add_v4_address(address, netprefix)
38 for guid, routes in self._add_route.iteritems():
39 element = self._elements[guid]
41 (destination, netprefix, nexthop) = route
42 element.add_route(prefix = destination, prefix_len = netprefix,
45 def set(self, time, guid, name, value):
46 super(TestbedInstance, self).set(time, guid, name, value)
47 # TODO: take on account schedule time for the task
48 element = self._elements[guid]
50 setattr(element, name, value)
52 def get(self, time, guid, name):
53 # TODO: take on account schedule time for the task
54 element = self._elements[guid]
55 return getattr(element, name)
57 def action(self, time, guid, action):
58 raise NotImplementedError
60 def trace(self, guid, trace_id):
61 fd = open("%s" % self.trace_filename(guid, trace_id), "r")
67 for trace in self._traces.values():
69 for element in self._elements.values():
72 def trace_filename(self, guid, trace_id):
73 # TODO: Need to be defined inside a home!!!! with and experiment id_code
74 return os.path.join(self.home_directory, "%d_%s" % (guid, trace_id))
76 def follow_trace(self, trace_id, trace):
77 self._traces[trace_id] = trace
79 def _load_netns_module(self):
80 # TODO: Do something with the configuration!!!
83 netns_mod = sys.modules["netns"]
85 enable_debug = self._attributes.get_attribute_value("enableDebug")
87 netns_mod.environ.set_log_level(netns_mod.environ.LOG_DEBUG)