3 # NEPI, a framework to manage network experiments
4 # Copyright (C) 2013 INRIA
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.
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.
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/>.
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21 from nepi.execution.ec import ExperimentController
23 from test_utils import skipIfAnyNotAliveWithIdentity
29 ## TODO: VALIDATE THIS TEST!
31 class LinuxGRETunnelTestCase(unittest.TestCase):
33 self.host = "roseval.pl.sophia.inria.fr"
34 self.user = "inria_nepi"
35 self.identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
36 self.netblock = "192.168.1"
38 @skipIfAnyNotAliveWithIdentity
39 def t_tap_gre_tunnel(self, user, host, identity):
40 ec = ExperimentController(exp_id = "test-tap-gre-tunnel")
42 node1 = ec.register_resource("linux::Node")
43 ec.set(node1, "hostname", "localhost")
44 ec.set(node1, "cleanExperiment", True)
45 ec.set(node1, "cleanProcesses", True)
47 tap1 = ec.register_resource("linux::Tap")
48 ec.set(tap1, "ip", "%s.1" % self.netblock)
49 ec.set(tap1, "prefix", "32")
50 ec.register_connection(tap1, node1)
52 node2 = ec.register_resource("linux::Node")
53 ec.set(node2, "hostname", host)
54 ec.set(node2, "username", user)
55 ec.set(node2, "identity", identity)
56 ec.set(node2, "cleanExperiment", True)
57 ec.set(node2, "cleanProcesses", True)
59 tap2 = ec.register_resource("linux::Tap")
60 ec.set(tap2, "ip", "%s.2" % self.netblock)
61 ec.set(tap2, "prefix", "32")
62 ec.register_connection(tap2, node2)
64 gretun = ec.register_resource("linux::GRETunnel")
65 ec.register_connection(tap1, gretun)
66 ec.register_connection(tap2, gretun)
68 app = ec.register_resource("linux::Application")
69 cmd = "ping -c3 %s.2" % self.netblock
70 ec.set(app, "command", cmd)
71 ec.register_connection(app, node1)
77 ping = ec.trace(app, 'stdout')
78 expected = """3 packets transmitted, 3 received, 0% packet loss"""
79 self.assertTrue(ping.find(expected) > -1)
81 if_name = ec.get(tap1, "deviceName")
82 self.assertTrue(if_name.startswith("tap"))
84 if_name = ec.get(tap2, "deviceName")
85 self.assertTrue(if_name.startswith("tap"))
89 @skipIfAnyNotAliveWithIdentity
90 def t_tun_gre_tunnel(self, user, host, identity):
91 ec = ExperimentController(exp_id = "test-tun-gre-tunnel")
93 node1 = ec.register_resource("linux::Node")
94 ec.set(node1, "hostname", "localhost")
95 ec.set(node1, "cleanExperiment", True)
96 ec.set(node1, "cleanProcesses", True)
98 tun1 = ec.register_resource("linux::Tun")
99 ec.set(tun1, "ip", "%s.1" % self.netblock)
100 ec.set(tun1, "prefix", "32")
101 ec.register_connection(tun1, node1)
103 node2 = ec.register_resource("linux::Node")
104 ec.set(node2, "hostname", host)
105 ec.set(node2, "username", user)
106 ec.set(node2, "identity", identity)
107 ec.set(node2, "cleanExperiment", True)
108 ec.set(node2, "cleanProcesses", True)
110 tun2 = ec.register_resource("linux::Tun")
111 ec.set(tun2, "ip", "%s.2" % self.netblock)
112 ec.set(tun2, "prefix", "32")
113 ec.register_connection(tun2, node2)
115 udptun = ec.register_resource("linux::GRETunnel")
116 ec.register_connection(tun1, udptun)
117 ec.register_connection(tun2, udptun)
119 app = ec.register_resource("linux::Application")
120 cmd = "ping -c3 %s.2" % self.netblock
121 ec.set(app, "command", cmd)
122 ec.register_connection(app, node1)
126 ec.wait_finished(app)
128 ping = ec.trace(app, 'stdout')
129 expected = """3 packets transmitted, 3 received, 0% packet loss"""
130 self.assertTrue(ping.find(expected) > -1)
132 if_name = ec.get(tun1, "deviceName")
133 self.assertTrue(if_name.startswith("tun"))
135 if_name = ec.get(tun2, "deviceName")
136 self.assertTrue(if_name.startswith("tun"))
140 def test_tap_gre_tunnel(self):
141 self.t_tap_gre_tunnel(self.user, self.host, self.identity)
143 def ztest_tun_gre_tunnel(self):
144 self.t_tun_gre_tunnel(self.user, self.host, self.identity)
146 if __name__ == '__main__':