Fixing wrong license
[nepi.git] / test / resources / planetlab / tun.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
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;
9 #
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.
14 #
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/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.ec import ExperimentController 
21
22 from test_utils import skipIfNotAlive
23
24 import os
25 import time
26 import unittest
27
28 class PlanetlabTunTestCase(unittest.TestCase):
29     def setUp(self):
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"
36         #self.identity = None
37         #self.netblock = "192.168.1"
38
39     @skipIfNotAlive
40     def t_tun_create(self, host, user, identity):
41
42         ec = ExperimentController(exp_id="test-un-create")
43         
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)
50
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)
55
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)
60
61         ec.deploy()
62
63         ec.wait_finished(app)
64
65         ping = ec.trace(app, "stdout")
66         expected = """3 packets transmitted, 3 received, 0% packet loss"""
67         self.assertTrue(ping.find(expected) > -1)
68         
69         if_name = ec.get(tun, "deviceName")
70         self.assertTrue(if_name.startswith("tun"))
71
72         ec.shutdown()
73
74     def test_tun_create(self):
75         self.t_tun_create(self.host, self.user, self.identity)
76
77 if __name__ == '__main__':
78     unittest.main()
79