fixed shebangs in non executable .py files
[nepi.git] / test / testbeds / planetlab / design.py
1 #!/usr/bin/env python
2 # -*- coding: utf-8 -*-
3
4 from nepi.core.design import ExperimentDescription, FactoriesProvider
5 import unittest
6
7 class PlanetlabDesignTestCase(unittest.TestCase):
8     def make_test_design(self):
9         testbed_id = "planetlab"
10         exp_desc = ExperimentDescription()
11         provider = FactoriesProvider(testbed_id)
12         tstbd_desc = exp_desc.add_testbed_description(provider)
13         tstbd_desc.set_attribute_value("slice", "inria_nepi")
14         node1 = tstbd_desc.create("Node")
15         node2 = tstbd_desc.create("Node")
16         iface1 = tstbd_desc.create("NodeInterface")
17         node1.connector("devs").connect(iface1.connector("node"))
18         iface2 = tstbd_desc.create("NodeInterface")
19         node2.connector("devs").connect(iface2.connector("node"))
20         switch = tstbd_desc.create("Internet")
21         iface1.connector("inet").connect(switch.connector("devs"))
22         iface2.connector("inet").connect(switch.connector("devs"))
23         app = tstbd_desc.create("Application")
24         app.set_attribute_value("command", "ping -qc10 10.0.0.2")
25         app.connector("node").connect(node1.connector("apps"))
26         
27         return exp_desc, tstbd_desc, node1, node2, iface1, iface2, app
28         
29     def test_design_simple(self):
30         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
31
32         xml = exp_desc.to_xml()
33         exp_desc2 = ExperimentDescription()
34         exp_desc2.from_xml(xml)
35         xml2 = exp_desc2.to_xml()
36         self.assertTrue(xml == xml2)
37
38     def test_design_constrained(self):
39         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
40         
41         node1.set_attribute_value("hostname", "onelab*.inria.fr")
42         node2.set_attribute_value("hostname", "onelab*.inria.fr")
43
44         xml = exp_desc.to_xml()
45         exp_desc2 = ExperimentDescription()
46         exp_desc2.from_xml(xml)
47         xml2 = exp_desc2.to_xml()
48         self.assertTrue(xml == xml2)
49
50     def test_design_constrained2(self):
51         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
52         
53         node1.set_attribute_value("minReliability", 90.0)
54         node1.set_attribute_value("operatingSystem", "f12")
55         node2.set_attribute_value("minReliability", 50.0)
56         node2.set_attribute_value("architecture", "x86_64")
57
58         xml = exp_desc.to_xml()
59         exp_desc2 = ExperimentDescription()
60         exp_desc2.from_xml(xml)
61         xml2 = exp_desc2.to_xml()
62         self.assertTrue(xml == xml2)
63         
64     def test_design_emulation(self):
65         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
66         
67         netpipe1 = tstbd_desc.create("NetPipe")
68         netpipe1.set_attribute_value("mode","CLIENT")
69         netpipe1.set_attribute_value("portList","80,443")
70         netpipe1.set_attribute_value("bwIn",1.0)
71         netpipe1.set_attribute_value("bwOut",128.0/1024.0)
72         netpipe1.set_attribute_value("delayIn",12)
73         netpipe1.set_attribute_value("delayOut",92)
74         netpipe1.set_attribute_value("plrIn",0.05)
75         netpipe1.set_attribute_value("plrOut",0.15)
76         node1.connector("pipes").connect(netpipe1.connector("node"))
77
78         xml = exp_desc.to_xml()
79         exp_desc2 = ExperimentDescription()
80         exp_desc2.from_xml(xml)
81         xml2 = exp_desc2.to_xml()
82         self.assertTrue(xml == xml2)
83
84 if __name__ == '__main__':
85     unittest.main()