Changed the endpoint_ip and endpoint_prefix attributes of TAP/TUN endpoints for ip...
[nepi.git] / test / resources / linux / gretunnel.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 skipIfAnyNotAliveWithIdentity
24
25 import os
26 import time
27 import unittest
28
29 ## TODO: VALIDATE THIS TEST!
30
31 class LinuxGRETunnelTestCase(unittest.TestCase):
32     def setUp(self):
33         self.host1 = "roseval.pl.sophia.inria.fr"
34         self.host2 = "138.96.118.11"
35         self.user1 = "inria_nepi"
36         self.user2 = "omflab"
37         self.identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
38         self.netblock = "192.168.1"
39
40     @skipIfAnyNotAliveWithIdentity
41     def t_tap_gre_tunnel(self, user1, host1, identity1, user2, host2, 
42             identity2):
43
44         ec = ExperimentController(exp_id = "test-tap-gre-tunnel")
45         
46         node1 = ec.register_resource("linux::Node")
47         ec.set(node1, "hostname", host1)
48         ec.set(node1, "username", user1)
49         ec.set(node1, "identity", identity1)
50         ec.set(node1, "cleanExperiment", True)
51         ec.set(node1, "cleanProcesses", True)
52
53         tap1 = ec.register_resource("linux::Tap")
54         ec.set(tap1, "ip", "%s.1" % self.netblock)
55         ec.set(tap1, "prefix", "32")
56         ec.register_connection(tap1, node1)
57
58         node2 = ec.register_resource("linux::Node")
59         ec.set(node2, "hostname", host2)
60         ec.set(node2, "username", user2)
61         ec.set(node2, "identity", identity2)
62         ec.set(node2, "cleanExperiment", True)
63         ec.set(node2, "cleanProcesses", True)
64
65         tap2 = ec.register_resource("linux::Tap")
66         ec.set(tap2, "ip", "%s.2" % self.netblock)
67         ec.set(tap2, "prefix", "32")
68         ec.register_connection(tap2, node2)
69
70         gretun = ec.register_resource("linux::GRETunnel")
71         ec.register_connection(tap1, gretun)
72         ec.register_connection(tap2, gretun)
73
74         app = ec.register_resource("linux::Application")
75         cmd = "ping -c3 %s.2" % self.netblock
76         ec.set(app, "command", cmd)
77         ec.register_connection(app, node1)
78
79         ec.deploy()
80
81         ec.wait_finished(app)
82
83         ping = ec.trace(app, 'stdout')
84         expected = """3 packets transmitted, 3 received, 0% packet loss"""
85         self.assertTrue(ping.find(expected) > -1)
86         
87         if_name = ec.get(tap1, "deviceName")
88         self.assertTrue(if_name.startswith("tap"))
89         
90         if_name = ec.get(tap2, "deviceName")
91         self.assertTrue(if_name.startswith("tap"))
92
93         ec.shutdown()
94
95     @skipIfAnyNotAliveWithIdentity
96     def t_tun_gre_tunnel(self, user1, host1, identity1, user2, host2, 
97             identity2):
98
99         ec = ExperimentController(exp_id = "test-tun-gre-tunnel")
100         
101         node1 = ec.register_resource("linux::Node")
102         ec.set(node1, "hostname", host1)
103         ec.set(node1, "username", user1)
104         ec.set(node1, "identity", identity1)
105         ec.set(node1, "cleanExperiment", True)
106         ec.set(node1, "cleanProcesses", True)
107
108         tun1 = ec.register_resource("linux::Tun")
109         ec.set(tun1, "ip", "%s.1" % self.netblock)
110         ec.set(tun1, "prefix", "32")
111         ec.register_connection(tun1, node1)
112
113         node2 = ec.register_resource("linux::Node")
114         ec.set(node2, "hostname", host2)
115         ec.set(node2, "username", user2)
116         ec.set(node2, "identity", identity2)
117         ec.set(node2, "cleanExperiment", True)
118         ec.set(node2, "cleanProcesses", True)
119
120         tun2 = ec.register_resource("linux::Tun")
121         ec.set(tun2, "ip", "%s.2" % self.netblock)
122         ec.set(tun2, "prefix", "32")
123         ec.register_connection(tun2, node2)
124
125         udptun = ec.register_resource("linux::GRETunnel")
126         ec.register_connection(tun1, udptun)
127         ec.register_connection(tun2, udptun)
128
129         app = ec.register_resource("linux::Application")
130         cmd = "ping -c3 %s.2" % self.netblock
131         ec.set(app, "command", cmd)
132         ec.register_connection(app, node1)
133
134         ec.deploy()
135
136         ec.wait_finished(app)
137
138         ping = ec.trace(app, 'stdout')
139         expected = """3 packets transmitted, 3 received, 0% packet loss"""
140         self.assertTrue(ping.find(expected) > -1)
141         
142         if_name = ec.get(tun1, "deviceName")
143         self.assertTrue(if_name.startswith("tun"))
144         
145         if_name = ec.get(tun2, "deviceName")
146         self.assertTrue(if_name.startswith("tun"))
147
148         ec.shutdown()
149
150     def test_tap_gre_tunnel(self):
151         self.t_tap_gre_tunnel(self.user1, self.host1, self.identity,
152                 self.user2, self.host2, self.identity)
153
154     def test_tun_gre_tunnel(self):
155         self.t_tun_gre_tunnel(self.user1, self.host1, self.identity,
156                 self.user2, self.host2, self.identity)
157
158 if __name__ == '__main__':
159     unittest.main()
160