Fixing wrong license
[nepi.git] / test / resources / linux / tap.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 LinuxTapTestCase(unittest.TestCase):
29     def setUp(self):
30         self.host = "roseval.pl.sophia.inria.fr"
31         self.user = "inria_nepi"
32         self.identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
33         self.netblock = "192.168.1"
34
35     @skipIfNotAlive
36     def t_tap_create(self, host, user=None, identity=None):
37
38         ec = ExperimentController(exp_id="test-tap-create")
39         
40         node = ec.register_resource("linux::Node")
41         ec.set(node, "hostname", host)
42
43         if host != "localhost":
44             ec.set(node, "username", user)
45             ec.set(node, "identity", identity)
46
47         ec.set(node, "cleanExperiment", True)
48         ec.set(node, "cleanProcesses", True)
49
50         tap = ec.register_resource("linux::Tap")
51         ec.set(tap, "ip", "%s.1" % self.netblock)
52         ec.set(tap, "prefix", "24")
53         ec.register_connection(tap, node)
54
55         app = ec.register_resource("linux::Application")
56         cmd = "ping -c3 %s.1" % self.netblock
57         ec.set(app, "command", cmd)
58         ec.register_connection(app, node)
59
60         ec.deploy()
61
62         ec.wait_finished(app)
63
64         ping = ec.trace(app, "stdout")
65         expected = """3 packets transmitted, 3 received, 0% packet loss"""
66         self.assertTrue(ping.find(expected) > -1)
67         
68         if_name = ec.get(tap, "deviceName")
69         self.assertTrue(if_name.startswith("tap"))
70
71         ec.shutdown()
72
73     def test_tap_create(self):
74         self.t_tap_create(self.host, self.user, self.identity)
75
76     def test_tap_create_local(self):
77         self.t_tap_create("localhost")
78
79
80 if __name__ == '__main__':
81     unittest.main()
82