8d025cea485327dcd35a3d264a5cbecef99df319
[nepi.git] / test / resources / linux / udptunnel.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 skipIfAnyNotAliveWithIdentity
23
24 import os
25 import time
26 import unittest
27
28 class LinuxUdpTunnelTestCase(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" % (os.environ['HOME'])
33
34     @skipIfAnyNotAliveWithIdentity
35     def t_tap_udp_tunnel(self, user, host, identity):
36
37         ec = ExperimentController(exp_id="test-tap-udp-tunnel")
38         
39         node1 = ec.register_resource("linux::Node")
40         ec.set(node1, "hostname", "localhost")
41         ec.set(node1, "cleanExperiment", True)
42         ec.set(node1, "cleanProcesses", True)
43
44         tap1 = ec.register_resource("linux::Tap")
45         ec.set(tap1, "ip", "192.168.3.1")
46         ec.set(tap1, "prefix", "30")
47         ec.register_connection(tap1, node1)
48
49         node2 = ec.register_resource("linux::Node")
50         ec.set(node2, "hostname", host)
51         ec.set(node2, "username", user)
52         ec.set(node2, "identity", identity)
53         ec.set(node2, "cleanExperiment", True)
54         ec.set(node2, "cleanProcesses", True)
55
56         tap2 = ec.register_resource("linux::Tap")
57         ec.set(tap2, "ip", "192.168.3.2")
58         ec.set(tap2, "prefix", "30")
59         ec.register_connection(tap2, node2)
60
61         udptun = ec.register_resource("linux::UdpTunnel")
62         ec.register_connection(tap1, udptun)
63         ec.register_connection(tap2, udptun)
64
65         app = ec.register_resource("linux::Application")
66         cmd = "ping -c3 192.168.3.2"
67         ec.set(app, "command", cmd)
68         ec.register_connection(app, node1)
69
70         ec.deploy()
71
72         ec.wait_finished(app)
73
74         ping = ec.trace(app, "stdout")
75         print ping
76         expected = """3 packets transmitted, 3 received, 0% packet loss"""
77         self.assertTrue(ping.find(expected) > -1)
78         
79         vif_name = ec.get(tap1, "deviceName")
80         self.assertTrue(vif_name.startswith("tap"))
81         
82         vif_name = ec.get(tap2, "deviceName")
83         self.assertTrue(vif_name.startswith("tap"))
84
85         ec.shutdown()
86
87     @skipIfAnyNotAliveWithIdentity
88     def t_tun_udp_tunnel(self, user, host, identity):
89
90         ec = ExperimentController(exp_id="test-tun-udp-tunnel")
91         
92         node1 = ec.register_resource("linux::Node")
93         ec.set(node1, "hostname", "localhost")
94         ec.set(node1, "cleanExperiment", True)
95         ec.set(node1, "cleanProcesses", True)
96
97         tun1 = ec.register_resource("linux::Tun")
98         ec.set(tun1, "ip", "192.168.3.1")
99         ec.set(tun1, "prefix", "30")
100         ec.register_connection(tun1, node1)
101
102         node2 = ec.register_resource("linux::Node")
103         ec.set(node2, "hostname", host)
104         ec.set(node2, "username", user)
105         ec.set(node2, "identity", identity)
106         ec.set(node2, "cleanExperiment", True)
107         ec.set(node2, "cleanProcesses", True)
108
109         tun2 = ec.register_resource("linux::Tun")
110         ec.set(tun2, "ip", "192.168.3.2")
111         ec.set(tun2, "prefix", "30")
112         ec.register_connection(tun2, node2)
113
114         udptun = ec.register_resource("linux::UdpTunnel")
115         ec.register_connection(tun1, udptun)
116         ec.register_connection(tun2, udptun)
117
118         app = ec.register_resource("linux::Application")
119         cmd = "ping -c3 192.168.3.2"
120         ec.set(app, "command", cmd)
121         ec.register_connection(app, node1)
122
123         ec.deploy()
124
125         ec.wait_finished(app)
126
127         ping = ec.trace(app, "stdout")
128
129         print ping
130         expected = """3 packets transmitted, 3 received, 0% packet loss"""
131         self.assertTrue(ping.find(expected) > -1)
132         
133         vif_name = ec.get(tun1, "deviceName")
134         self.assertTrue(vif_name.startswith("tun"))
135         
136         vif_name = ec.get(tun2, "deviceName")
137         self.assertTrue(vif_name.startswith("tun"))
138
139         ec.shutdown()
140
141     def test_tap_udp_tunnel(self):
142         self.t_tap_udp_tunnel(self.user, self.host, self.identity)
143
144     def ztest_tun_udp_tunnel(self):
145         self.t_tun_udp_tunnel(self.user, self.host, self.identity)
146
147 if __name__ == '__main__':
148     unittest.main()
149