2 # NEPI, a framework to manage network experiments
3 # Copyright (C) 2014 INRIA
5 # This program is free software: you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation, either version 3 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.resource import ResourceManager, clsinit_copy, \
21 ResourceState, reschedule_delay
22 from nepi.execution.attribute import Flags
23 from nepi.execution.trace import TraceAttr
26 class NetNSBase(ResourceManager):
27 _rtype = "abstract::netns::Object"
28 _backend_type = "netns"
30 def __init__(self, ec, guid):
31 super(NetNSBase, self).__init__(ec, guid)
33 self._connected = set()
34 self._trace_filename = dict()
38 return self._connected
44 def trace(self, name, attr = TraceAttr.ALL, block = 512, offset = 0):
45 filename = self._trace_filename.get(name)
47 self.error("Can not resolve trace %s. Did you enabled it?" % name)
50 return self.emulation.trace(filename, attr, block, offset)
53 def _rms_to_wait(self):
54 """ Returns the collection of RMs that this RM needs to
57 This method should be overriden to wait for other
58 objects to be deployed before proceeding with the deployment
61 raise RuntimeError, "No dependencies defined!"
63 def _instantiate_object(self):
68 for rm in self._rms_to_wait:
72 """ Returns True if dependent RMs are not yer READY, False otherwise"""
74 if rm.state < ResourceState.READY:
78 def do_provision(self):
79 self._instantiate_object()
81 self.info("Provisioning finished")
83 super(NetNSBase, self).do_provision()
87 self.debug("---- RESCHEDULING DEPLOY ----" )
88 self.ec.schedule(reschedule_delay, self.deploy)
96 if self.state == ResourceState.READY:
97 # No need to do anything, simulation.Run() will start every object
102 self.error(msg, out, err)
103 raise RuntimeError, msg
106 if self.state == ResourceState.STARTED:
107 # No need to do anything, simulation.Destroy() will stop every object
115 #flags = Flags.NoWrite | Flags.NoRead | Flags.Design
117 if self.state in [ResourceState.READY, ResourceState.STARTED] \
118 and not self.has_flag(name, flags):
119 return self.emulation.emu_get(self.uuid, name)
121 value = super(NetNSBase, self).get(name)
122 if name != "critical":
123 print name, value, "lalal"
126 def set(self, name, value):
127 #flags = Flags.NoWrite | Flags.NoRead | Flags.Design
129 if self.has_flag(name, flags):
131 msg = " Cannot change Design only attribue %s" % name
132 self.error(msg, out, err)
135 if self.state in [ResourceState.READY, ResourceState.STARTED]:
136 self.emulation.emu_set(self.uuid, name, value)
138 value = super(NetNSBase, self).set(name, value)
139 if name != "critical":
140 print name, value, "IEEEEEEEE:"