Added PlanetlabTAP & PlanetlabTUN
[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 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 from nepi.resources.planetlab.node import PlanetlabNode
23 from nepi.resources.planetlab.tun import PlanetlabTun
24 from nepi.resources.linux.application import LinuxApplication
25
26 from test_utils import skipIfNotAlive, skipInteractive
27
28 import os
29 import time
30 import unittest
31
32 class PlanetlabTunTestCase(unittest.TestCase):
33     def setUp(self):
34         self.host = "nepi2.pl.sophia.inria.fr"
35         self.user = "inria_nepi"
36
37     @skipIfNotAlive
38     def t_tun_create(self, host, user):
39         from nepi.execution.resource import ResourceFactory
40         
41         ResourceFactory.register_type(PlanetlabNode)
42         ResourceFactory.register_type(PlanetlabTun)
43         ResourceFactory.register_type(LinuxApplication)
44
45         ec = ExperimentController(exp_id = "test-un-create")
46         
47         node = ec.register_resource("PlanetlabNode")
48         ec.set(node, "hostname", host)
49         ec.set(node, "username", user)
50         ec.set(node, "cleanHome", True)
51         ec.set(node, "cleanProcesses", True)
52
53         tun = ec.register_resource("PlanetlabTun")
54         ec.set(tun, "ip4", "192.168.1.1")
55         ec.set(tun, "prefix4", "24")
56         ec.register_connection(tun, node)
57
58         app = ec.register_resource("LinuxApplication")
59         cmd = "ping -c3 192.168.1.1" 
60         ec.set(app, "command", cmd)
61         ec.register_connection(app, node)
62
63         ec.deploy()
64
65         ec.wait_finished(app)
66
67         ping = ec.trace(app, 'stdout')
68         expected = """3 packets transmitted, 3 received, 0% packet loss"""
69         self.assertTrue(ping.find(expected) > -1)
70         
71         if_name = ec.get(tun, "deviceName")
72         self.assertTrue(if_name.startswith("tun"))
73
74         ec.shutdown()
75
76     def test_tun_create(self):
77         self.t_tun_create(self.host, self.user)
78
79 if __name__ == '__main__':
80     unittest.main()
81