4259cd5a02dbeefb156ce11873f2062fba68dc10
[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         exp_desc = ExperimentDescription()
10         testbed_version = "01"
11         testbed_id = "planetlab"
12         provider = FactoriesProvider(testbed_id, testbed_version)
13         tstbd_desc = exp_desc.add_testbed_description(provider)
14         tstbd_desc.set_attribute_value("slice", "inria_nepi")
15         node1 = tstbd_desc.create("Node")
16         node2 = tstbd_desc.create("Node")
17         iface1 = tstbd_desc.create("NodeInterface")
18         node1.connector("devs").connect(iface1.connector("node"))
19         iface2 = tstbd_desc.create("NodeInterface")
20         node2.connector("devs").connect(iface2.connector("node"))
21         switch = tstbd_desc.create("Internet")
22         iface1.connector("inet").connect(switch.connector("devs"))
23         iface2.connector("inet").connect(switch.connector("devs"))
24         app = tstbd_desc.create("Application")
25         app.set_attribute_value("command", "ping -qc10 10.0.0.2")
26         app.connector("node").connect(node1.connector("apps"))
27         
28         return exp_desc, tstbd_desc, node1, node2, iface1, iface2, app
29         
30     def test_design_simple(self):
31         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
32
33         xml = exp_desc.to_xml()
34         exp_desc2 = ExperimentDescription()
35         exp_desc2.from_xml(xml)
36         xml2 = exp_desc2.to_xml()
37         self.assertTrue(xml == xml2)
38
39     def test_design_constrained(self):
40         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
41         
42         node1.set_attribute_value("hostname", "onelab*.inria.fr")
43         node2.set_attribute_value("hostname", "onelab*.inria.fr")
44
45         xml = exp_desc.to_xml()
46         exp_desc2 = ExperimentDescription()
47         exp_desc2.from_xml(xml)
48         xml2 = exp_desc2.to_xml()
49         self.assertTrue(xml == xml2)
50
51     def test_design_constrained2(self):
52         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
53         
54         node1.set_attribute_value("minReliability", 90.0)
55         node1.set_attribute_value("operatingSystem", "f12")
56         node2.set_attribute_value("minReliability", 50.0)
57         node2.set_attribute_value("architecture", "x86_64")
58
59         xml = exp_desc.to_xml()
60         exp_desc2 = ExperimentDescription()
61         exp_desc2.from_xml(xml)
62         xml2 = exp_desc2.to_xml()
63         self.assertTrue(xml == xml2)
64         
65     def test_design_emulation(self):
66         exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
67         
68         node1.set_attribute_value("emulation",True)
69         
70         netpipe1 = tstbd_desc.create("NetPipe")
71         netpipe1.set_attribute_value("mode","CLIENT")
72         netpipe1.set_attribute_value("portList","80,443")
73         netpipe1.set_attribute_value("bwIn",1.0)
74         netpipe1.set_attribute_value("bwOut",128.0/1024.0)
75         netpipe1.set_attribute_value("delayIn",12)
76         netpipe1.set_attribute_value("delayOut",92)
77         netpipe1.set_attribute_value("plrIn",0.05)
78         netpipe1.set_attribute_value("plrOut",0.15)
79         node1.connector("pipes").connect(netpipe1.connector("node"))
80
81         xml = exp_desc.to_xml()
82         exp_desc2 = ExperimentDescription()
83         exp_desc2.from_xml(xml)
84         xml2 = exp_desc2.to_xml()
85         self.assertTrue(xml == xml2)
86
87 if __name__ == '__main__':
88     unittest.main()