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 version 2 as
8 # published by the Free Software Foundation;
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.ec import ExperimentController
21 from nepi.execution.resource import ResourceManager, ResourceState, \
22 clsinit_copy, ResourceAction, ResourceFactory
23 from nepi.util.plotter import PFormats
30 reschedule_delay = "0.5s"
34 class Link(ResourceManager):
35 _rtype = "dummy::Link"
37 time.sleep(deploy_time)
38 super(Link, self).do_deploy()
39 self.logger.debug(" -------- DEPLOYED ------- ")
41 class Interface(ResourceManager):
42 _rtype = "dummy::Interface"
45 node = self.get_connected(Node.get_rtype())[0]
46 link = self.get_connected(Link.get_rtype())[0]
48 if node.state < ResourceState.READY or \
49 link.state < ResourceState.READY:
50 self.ec.schedule(reschedule_delay, self.deploy)
51 self.logger.debug(" -------- RESCHEDULING ------- ")
53 time.sleep(deploy_time)
54 super(Interface, self).do_deploy()
55 self.logger.debug(" -------- DEPLOYED ------- ")
57 class Node(ResourceManager):
58 _rtype = "dummy::Node"
61 self.logger.debug(" -------- DO_DEPLOY ------- ")
62 time.sleep(deploy_time)
63 super(Node, self).do_deploy()
64 self.logger.debug(" -------- DEPLOYED ------- ")
66 class Application(ResourceManager):
67 _rtype = "dummy::Application"
70 node = self.get_connected(Node.get_rtype())[0]
72 if node.state < ResourceState.READY:
73 self.ec.schedule(reschedule_delay, self.deploy)
74 self.logger.debug(" -------- RESCHEDULING ------- ")
76 time.sleep(deploy_time)
77 super(Application, self).do_deploy()
78 self.logger.debug(" -------- DEPLOYED ------- ")
81 super(Application, self).do_start()
83 self.ec.schedule("0s", self.stop)
85 ResourceFactory.register_type(Application)
86 ResourceFactory.register_type(Node)
87 ResourceFactory.register_type(Interface)
88 ResourceFactory.register_type(Link)
90 class PlotterTestCase(unittest.TestCase):
91 def test_serialize(self):
95 ec = ExperimentController(exp_id = "plotter-test")
97 # Add simulated nodes and applications
102 for i in range(node_count):
103 node = ec.register_resource("dummy::Node")
106 iface = ec.register_resource("dummy::Interface")
107 ec.register_connection(node, iface)
110 for i in range(app_count):
111 app = ec.register_resource("dummy::Application")
112 ec.register_connection(node, app)
115 link = ec.register_resource("dummy::Link")
118 ec.register_connection(link, iface)
121 statinfo = os.stat(fpath)
122 size = statinfo.st_size
123 self.assertTrue(size > 0)
124 self.assertTrue(fpath.endswith(".png"))
128 fpath = ec.plot(format = PFormats.DOT)
129 statinfo = os.stat(fpath)
130 size = statinfo.st_size
131 self.assertTrue(size > 0)
132 self.assertTrue(fpath.endswith(".dot"))
136 if __name__ == '__main__':