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 version 2 as
8 # published by the Free Software Foundation;
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.
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/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20 from nepi.execution.ec import ExperimentController
22 from test_utils import skipIfAnyNotAliveWithIdentity
28 ## TODO: VALIDATE THIS TEST!
30 class LinuxGRETunnelTestCase(unittest.TestCase):
32 self.host = "roseval.pl.sophia.inria.fr"
33 self.user = "inria_nepi"
34 self.identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
35 self.netblock = "192.168.1"
37 @skipIfAnyNotAliveWithIdentity
38 def t_tap_gre_tunnel(self, user, host, identity):
39 ec = ExperimentController(exp_id = "test-tap-gre-tunnel")
41 node1 = ec.register_resource("linux::Node")
42 ec.set(node1, "hostname", "localhost")
43 ec.set(node1, "cleanExperiment", True)
44 ec.set(node1, "cleanProcesses", True)
46 tap1 = ec.register_resource("linux::Tap")
47 ec.set(tap1, "ip", "%s.1" % self.netblock)
48 ec.set(tap1, "prefix", "32")
49 ec.register_connection(tap1, node1)
51 node2 = ec.register_resource("linux::Node")
52 ec.set(node2, "hostname", host)
53 ec.set(node2, "username", user)
54 ec.set(node2, "identity", identity)
55 ec.set(node2, "cleanExperiment", True)
56 ec.set(node2, "cleanProcesses", True)
58 tap2 = ec.register_resource("linux::Tap")
59 ec.set(tap2, "ip", "%s.2" % self.netblock)
60 ec.set(tap2, "prefix", "32")
61 ec.register_connection(tap2, node2)
63 gretun = ec.register_resource("linux::GRETunnel")
64 ec.register_connection(tap1, gretun)
65 ec.register_connection(tap2, gretun)
67 app = ec.register_resource("linux::Application")
68 cmd = "ping -c3 %s.2" % self.netblock
69 ec.set(app, "command", cmd)
70 ec.register_connection(app, node1)
76 ping = ec.trace(app, 'stdout')
77 expected = """3 packets transmitted, 3 received, 0% packet loss"""
78 self.assertTrue(ping.find(expected) > -1)
80 if_name = ec.get(tap1, "deviceName")
81 self.assertTrue(if_name.startswith("tap"))
83 if_name = ec.get(tap2, "deviceName")
84 self.assertTrue(if_name.startswith("tap"))
88 @skipIfAnyNotAliveWithIdentity
89 def t_tun_gre_tunnel(self, user, host, identity):
90 ec = ExperimentController(exp_id = "test-tun-gre-tunnel")
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)
97 tun1 = ec.register_resource("linux::Tun")
98 ec.set(tun1, "ip", "%s.1" % self.netblock)
99 ec.set(tun1, "prefix", "32")
100 ec.register_connection(tun1, node1)
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)
109 tun2 = ec.register_resource("linux::Tun")
110 ec.set(tun2, "ip", "%s.2" % self.netblock)
111 ec.set(tun2, "prefix", "32")
112 ec.register_connection(tun2, node2)
114 udptun = ec.register_resource("linux::GRETunnel")
115 ec.register_connection(tun1, udptun)
116 ec.register_connection(tun2, udptun)
118 app = ec.register_resource("linux::Application")
119 cmd = "ping -c3 %s.2" % self.netblock
120 ec.set(app, "command", cmd)
121 ec.register_connection(app, node1)
125 ec.wait_finished(app)
127 ping = ec.trace(app, 'stdout')
128 expected = """3 packets transmitted, 3 received, 0% packet loss"""
129 self.assertTrue(ping.find(expected) > -1)
131 if_name = ec.get(tun1, "deviceName")
132 self.assertTrue(if_name.startswith("tun"))
134 if_name = ec.get(tun2, "deviceName")
135 self.assertTrue(if_name.startswith("tun"))
139 def test_tap_gre_tunnel(self):
140 self.t_tap_gre_tunnel(self.user, self.host, self.identity)
142 def ztest_tun_gre_tunnel(self):
143 self.t_tun_gre_tunnel(self.user, self.host, self.identity)
145 if __name__ == '__main__':