2 # -*- coding: utf-8 -*-
5 from nepi.core.design import ExperimentDescription, FactoriesProvider
6 from nepi.core.execute import ExperimentController
7 from nepi.util import proxy
8 from nepi.util.constants import DeploymentConfiguration as DC, ATTR_NEPI_TESTBED_ENVIRONMENT_SETUP
17 class PlanetLabMultiIntegrationTestCase(unittest.TestCase):
18 testbed_id = "planetlab"
19 testbed_version = "01"
21 slicename1 = "inria_nepi"
22 plchost1 = "nepiplc.pl.sophia.inria.fr"
24 slicename2 = "inria_nepi12"
25 plchost2 = "www.planet-lab.eu"
27 host1pl1 = "nepi1.pl.sophia.inria.fr"
28 host2pl1 = "nepi2.pl.sophia.inria.fr"
30 host1pl2 = "onelab11.pl.sophia.inria.fr"
31 host2pl2 = "onelab10.pl.sophia.inria.fr"
34 self.root_dir = tempfile.mkdtemp()
38 shutil.rmtree(self.root_dir)
42 shutil.rmtree(self.root_dir)
44 def make_experiment_desc(self):
45 testbed_id = self.testbed_id
46 testbed_version = self.testbed_version
48 slicename1 = self.slicename1
49 plchost1 = self.plchost1
51 slicename2 = self.slicename2
52 plchost2 = self.plchost2
54 pl_ssh_key = os.environ.get(
56 "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'],) )
57 pl_user, pl_pwd = test_util.pl_auth()
59 exp_desc = ExperimentDescription()
60 pl_provider = FactoriesProvider(testbed_id, testbed_version)
61 pl_desc = exp_desc.add_testbed_description(pl_provider)
62 pl_desc.set_attribute_value("homeDirectory", self.root_dir)
63 pl_desc.set_attribute_value("slice", slicename1)
64 pl_desc.set_attribute_value("sliceSSHKey", pl_ssh_key)
65 pl_desc.set_attribute_value("authUser", pl_user)
66 pl_desc.set_attribute_value("authPass", pl_pwd)
67 pl_desc.set_attribute_value("plcHost", plchost1)
69 pl_desc2 = exp_desc.add_testbed_description(pl_provider)
70 pl_desc2.set_attribute_value("homeDirectory", self.root_dir+"v2")
71 pl_desc2.set_attribute_value("slice", slicename2)
72 pl_desc2.set_attribute_value("sliceSSHKey", pl_ssh_key)
73 pl_desc2.set_attribute_value("authUser", pl_user)
74 pl_desc2.set_attribute_value("authPass", pl_pwd)
75 pl_desc2.set_attribute_value("plcHost", plchost2)
77 return pl_desc, pl_desc2, exp_desc
79 def make_pl_tapnode(self, pl, tapip, hostname, label_prefix):
80 node1 = pl.create("Node")
81 node1.set_attribute_value("hostname", hostname)
82 node1.set_attribute_value("label", label_prefix)
83 node1.set_attribute_value("emulation", True) # require emulation
84 iface1 = pl.create("NodeInterface")
85 iface1.set_attribute_value("label", label_prefix+"iface")
86 tap1 = pl.create("TapInterface")
87 tap1.enable_trace("packets") # for error output
88 tap1.set_attribute_value("label", label_prefix+"tap")
89 inet = pl.create("Internet")
90 node1.connector("devs").connect(iface1.connector("node"))
91 node1.connector("devs").connect(tap1.connector("node"))
92 iface1.connector("inet").connect(inet.connector("devs"))
94 tap1ip = tap1.add_address()
95 tap1ip.set_attribute_value("Address", tapip)
96 tap1ip.set_attribute_value("NetPrefix", 24)
97 tap1ip.set_attribute_value("Broadcast", False)
99 return node1, iface1, tap1, tap1ip, inet
101 def _test_plpl_crossconnect(self, proto):
102 pl, pl2, exp = self.make_experiment_desc()
104 # Create PL node, ifaces, assign addresses
105 node1, iface1, tap1, tap1ip, inet1 = self.make_pl_tapnode(pl,
106 "192.168.2.2", self.host1pl1, "node1")
107 node2, iface2, tap2, tap2ip, inet2 = self.make_pl_tapnode(pl2,
108 "192.168.2.3", self.host1pl2, "node2")
111 tap1.connector(proto).connect(tap2.connector(proto))
113 # Create PlanetLab ping application, pinging the from one PL to another
114 ping = pl.create("Application")
115 ping.set_attribute_value("command", "ping -qc10 {#[node2tap].addr[0].[Address]#}")
116 ping.enable_trace("stdout")
117 ping.enable_trace("stderr")
118 ping.connector("node").connect(node1.connector("apps"))
120 comp_result = r"""PING .* \(.*\) \d*\(\d*\) bytes of data.
122 --- .* ping statistics ---
123 10 packets transmitted, 10 received, 0% packet loss, time \d*ms.*
128 controller = ExperimentController(xml, self.root_dir)
131 while not controller.is_finished(ping.guid):
134 ping_result = controller.trace(ping.guid, "stdout")
135 tap_trace = controller.trace(tap1.guid, "packets")
136 tap2_trace = controller.trace(tap2.guid, "packets")
139 controller.shutdown()
141 # asserts at the end, to make sure there's proper cleanup
142 self.assertTrue(re.match(comp_result, ping_result, re.MULTILINE),
143 "Unexpected trace:\n%s\nTap trace at origin:\n%s\nTap trace at destination:\n%s\n" % (
148 @test_util.skipUnless(test_util.pl_auth() is not None,
149 "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
150 @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
151 "Test is expensive, requires NEPI_FULL_TESTS=yes")
152 def test_plpl_crossconnect_udp(self):
153 self._test_plpl_crossconnect("udp")
155 @test_util.skipUnless(test_util.pl_auth() is not None,
156 "Test requires PlanetLab authentication info (PL_USER and PL_PASS environment variables)")
157 @test_util.skipUnless(os.environ.get('NEPI_FULL_TESTS','').lower() in ('1','yes','true','on'),
158 "Test is expensive, requires NEPI_FULL_TESTS=yes")
159 def test_plpl_crossconnect_tcp(self):
160 self._test_plpl_crossconnect("tcp")
163 if __name__ == '__main__':