Changed the endpoint_ip and endpoint_prefix attributes of TAP/TUN endpoints for ip...
[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 as published by
8 #    the Free Software Foundation, either version 3 of the License, or
9 #    (at your option) any later version.
10 #
11 #    This program is distributed in the hope that it will be useful,
12 #    but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #    GNU General Public License for more details.
15 #
16 #    You should have received a copy of the GNU General Public License
17 #    along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20
21 from nepi.execution.ec import ExperimentController 
22
23 from test_utils import skipIfNotAlive
24
25 import os
26 import time
27 import unittest
28
29 class LinuxTapTestCase(unittest.TestCase):
30     def setUp(self):
31         self.host = "roseval.pl.sophia.inria.fr"
32         self.user = "inria_nepi"
33         self.identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
34         self.netblock = "192.168.1"
35
36     @skipIfNotAlive
37     def t_tap_create(self, host, user=None, identity=None):
38
39         ec = ExperimentController(exp_id="test-tap-create")
40         
41         node = ec.register_resource("linux::Node")
42         ec.set(node, "hostname", host)
43
44         if host != "localhost":
45             ec.set(node, "username", user)
46             ec.set(node, "identity", identity)
47
48         ec.set(node, "cleanExperiment", True)
49         ec.set(node, "cleanProcesses", True)
50
51         tap = ec.register_resource("linux::Tap")
52         ec.set(tap, "ip", "%s.1" % self.netblock)
53         ec.set(tap, "prefix", "24")
54         ec.register_connection(tap, 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(tap, "deviceName")
70         self.assertTrue(if_name.startswith("tap"))
71
72         ec.shutdown()
73
74     def test_tap_create(self):
75         self.t_tap_create(self.host, self.user, self.identity)
76
77     def test_tap_create_local(self):
78         self.t_tap_create("localhost")
79
80
81 if __name__ == '__main__':
82     unittest.main()
83