3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21 from nepi.execution.ec import ExperimentController
22 from nepi.execution.resource import ResourceManager, ResourceState, \
23 clsinit_copy, ResourceAction, ResourceFactory
29 reschedule_delay = "0.5s"
33 class Link(ResourceManager):
34 _rtype = "dummy::Link"
36 time.sleep(deploy_time)
37 super(Link, self).do_deploy()
38 self.logger.debug(" -------- DEPLOYED ------- ")
40 class Interface(ResourceManager):
41 _rtype = "dummy::Interface"
44 node = self.get_connected(Node.get_rtype())[0]
45 link = self.get_connected(Link.get_rtype())[0]
47 if node.state < ResourceState.READY or \
48 link.state < ResourceState.READY:
49 self.ec.schedule(reschedule_delay, self.deploy)
50 self.logger.debug(" -------- RESCHEDULING ------- ")
52 time.sleep(deploy_time)
53 super(Interface, self).do_deploy()
54 self.logger.debug(" -------- DEPLOYED ------- ")
56 class Node(ResourceManager):
57 _rtype = "dummy::Node"
60 self.logger.debug(" -------- DO_DEPLOY ------- ")
61 time.sleep(deploy_time)
62 super(Node, self).do_deploy()
63 self.logger.debug(" -------- DEPLOYED ------- ")
65 class Application(ResourceManager):
66 _rtype = "dummy::Application"
69 node = self.get_connected(Node.get_rtype())[0]
71 if node.state < ResourceState.READY:
72 self.ec.schedule(reschedule_delay, self.deploy)
73 self.logger.debug(" -------- RESCHEDULING ------- ")
75 time.sleep(deploy_time)
76 super(Application, self).do_deploy()
77 self.logger.debug(" -------- DEPLOYED ------- ")
80 super(Application, self).do_start()
82 self.ec.schedule("0s", self.stop)
84 ResourceFactory.register_type(Application)
85 ResourceFactory.register_type(Node)
86 ResourceFactory.register_type(Interface)
87 ResourceFactory.register_type(Link)
89 class SerializeTestCase(unittest.TestCase):
90 def test_serialize(self):
94 dirpath = tempfile.mkdtemp()
96 ec = ExperimentController(exp_id = "serialize-test")
98 # Add simulated nodes and applications
103 for i in xrange(node_count):
104 node = ec.register_resource("dummy::Node")
107 iface = ec.register_resource("dummy::Interface")
108 ec.register_connection(node, iface)
111 for i in xrange(app_count):
112 app = ec.register_resource("dummy::Application")
113 ec.register_connection(node, app)
116 link = ec.register_resource("dummy::Link")
119 ec.register_connection(link, iface)
121 filepath = ec.save(dirpath)
126 # Wait until nodes and apps are deployed
127 ec.wait_finished(apps)
129 # Do the experiment controller shutdown
132 ec2 = ExperimentController.load(filepath)
133 apps = ec2.get_resources_by_type("dummy::Application")
135 ec2.wait_finished(apps)
138 self.assertEquals(len(ec.resources), len(ec2.resources))
141 if __name__ == '__main__':