2 # -*- coding: utf-8 -*-
4 from nepi.core.design import ExperimentDescription, FactoriesProvider
7 class PlanetlabDesignTestCase(unittest.TestCase):
8 def make_test_design(self):
9 exp_desc = ExperimentDescription()
10 testbed_id = "planetlab"
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"))
27 return exp_desc, tstbd_desc, node1, node2, iface1, iface2, app
29 def test_design_simple(self):
30 exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
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)
38 def test_design_constrained(self):
39 exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
41 node1.set_attribute_value("hostname", "onelab*.inria.fr")
42 node2.set_attribute_value("hostname", "onelab*.inria.fr")
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)
50 def test_design_constrained2(self):
51 exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
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")
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)
64 def test_design_emulation(self):
65 exp_desc, tstbd_desc, node1, node2, iface1, iface2, app = self.make_test_design()
67 node1.set_attribute_value("emulation",True)
69 netpipe1 = tstbd_desc.create("NetPipe")
70 netpipe1.set_attribute_value("mode","CLIENT")
71 netpipe1.set_attribute_value("portList","80,443")
72 netpipe1.set_attribute_value("bwIn",1.0)
73 netpipe1.set_attribute_value("bwOut",128.0/1024.0)
74 netpipe1.set_attribute_value("delayIn",12)
75 netpipe1.set_attribute_value("delayOut",92)
76 netpipe1.set_attribute_value("plrIn",0.05)
77 netpipe1.set_attribute_value("plrOut",0.15)
78 node1.connector("pipes").connect(netpipe1.connector("node"))
80 xml = exp_desc.to_xml()
81 exp_desc2 = ExperimentDescription()
82 exp_desc2.from_xml(xml)
83 xml2 = exp_desc2.to_xml()
84 self.assertTrue(xml == xml2)
86 if __name__ == '__main__':