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.host1 = "roseval.pl.sophia.inria.fr"
34 self.host2 = "138.96.118.11"
35 self.user1 = "inria_nepi"
37 self.identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
38 self.netblock = "192.168.1"
40 @skipIfAnyNotAliveWithIdentity
41 def t_tap_gre_tunnel(self, user1, host1, identity1, user2, host2,
44 ec = ExperimentController(exp_id = "test-tap-gre-tunnel")
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)
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)
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)
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)
70 gretun = ec.register_resource("linux::GRETunnel")
71 ec.register_connection(tap1, gretun)
72 ec.register_connection(tap2, gretun)
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)
83 ping = ec.trace(app, 'stdout')
84 expected = """3 packets transmitted, 3 received, 0% packet loss"""
85 self.assertTrue(ping.find(expected) > -1)
87 if_name = ec.get(tap1, "deviceName")
88 self.assertTrue(if_name.startswith("tap"))
90 if_name = ec.get(tap2, "deviceName")
91 self.assertTrue(if_name.startswith("tap"))
95 @skipIfAnyNotAliveWithIdentity
96 def t_tun_gre_tunnel(self, user1, host1, identity1, user2, host2,
99 ec = ExperimentController(exp_id = "test-tun-gre-tunnel")
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)
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)
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)
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)
125 udptun = ec.register_resource("linux::GRETunnel")
126 ec.register_connection(tun1, udptun)
127 ec.register_connection(tun2, udptun)
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)
136 ec.wait_finished(app)
138 ping = ec.trace(app, 'stdout')
139 expected = """3 packets transmitted, 3 received, 0% packet loss"""
140 self.assertTrue(ping.find(expected) > -1)
142 if_name = ec.get(tun1, "deviceName")
143 self.assertTrue(if_name.startswith("tun"))
145 if_name = ec.get(tun2, "deviceName")
146 self.assertTrue(if_name.startswith("tun"))
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)
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)
158 if __name__ == '__main__':