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
22 from test_utils import skipIfNotAlive
28 class PlanetlabTunTestCase(unittest.TestCase):
30 self.host = "planetlab2.upc.es"
31 self.user = "inria_nepi"
32 self.identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
33 self.netblock = "192.168.3"
34 #self.host = "nepi2.pl.sophia.inria.fr"
35 #self.user = "inria_nepi"
37 #self.netblock = "192.168.1"
40 def t_tun_create(self, host, user, identity):
42 ec = ExperimentController(exp_id="test-un-create")
44 node = ec.register_resource("planetlab::Node")
45 ec.set(node, "hostname", host)
46 ec.set(node, "username", user)
47 ec.set(node, "identity", identity)
48 ec.set(node, "cleanExperiment", True)
49 ec.set(node, "cleanProcesses", True)
51 tun = ec.register_resource("planetlab::Tun")
52 ec.set(tun, "ip", "%s.1" % self.netblock)
53 ec.set(tun, "prefix", "24")
54 ec.register_connection(tun, node)
56 app = ec.register_resource("linux::Application")
57 cmd = "ping -c3 %s.1" % self.netblock
58 ec.set(app, "command", cmd)
59 ec.register_connection(app, node)
65 ping = ec.trace(app, "stdout")
66 expected = """3 packets transmitted, 3 received, 0% packet loss"""
67 self.assertTrue(ping.find(expected) > -1)
69 if_name = ec.get(tun, "deviceName")
70 self.assertTrue(if_name.startswith("tun"))
74 def test_tun_create(self):
75 self.t_tun_create(self.host, self.user, self.identity)
77 if __name__ == '__main__':