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 class LinuxUdpTunnelTestCase(unittest.TestCase):
31 self.host = "roseval.pl.sophia.inria.fr"
32 self.user = "inria_nepi"
33 self.identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
35 @skipIfAnyNotAliveWithIdentity
36 def t_tap_udp_tunnel(self, user, host, identity):
38 ec = ExperimentController(exp_id="test-tap-udp-tunnel")
40 node1 = ec.register_resource("linux::Node")
41 ec.set(node1, "hostname", "localhost")
42 ec.set(node1, "cleanExperiment", True)
43 ec.set(node1, "cleanProcesses", True)
45 tap1 = ec.register_resource("linux::Tap")
46 ec.set(tap1, "ip", "192.168.3.1")
47 ec.set(tap1, "prefix", "30")
48 ec.register_connection(tap1, node1)
50 node2 = ec.register_resource("linux::Node")
51 ec.set(node2, "hostname", host)
52 ec.set(node2, "username", user)
53 ec.set(node2, "identity", identity)
54 ec.set(node2, "cleanExperiment", True)
55 ec.set(node2, "cleanProcesses", True)
57 tap2 = ec.register_resource("linux::Tap")
58 ec.set(tap2, "ip", "192.168.3.2")
59 ec.set(tap2, "prefix", "30")
60 ec.register_connection(tap2, node2)
62 udptun = ec.register_resource("linux::UdpTunnel")
63 ec.register_connection(tap1, udptun)
64 ec.register_connection(tap2, udptun)
66 app = ec.register_resource("linux::Application")
67 cmd = "ping -c3 192.168.3.2"
68 ec.set(app, "command", cmd)
69 ec.register_connection(app, node1)
75 ping = ec.trace(app, "stdout")
77 expected = """3 packets transmitted, 3 received, 0% packet loss"""
78 self.assertTrue(ping.find(expected) > -1)
80 vif_name = ec.get(tap1, "deviceName")
81 self.assertTrue(vif_name.startswith("tap"))
83 vif_name = ec.get(tap2, "deviceName")
84 self.assertTrue(vif_name.startswith("tap"))
88 @skipIfAnyNotAliveWithIdentity
89 def t_tun_udp_tunnel(self, user, host, identity):
91 ec = ExperimentController(exp_id="test-tun-udp-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", "192.168.3.1")
100 ec.set(tun1, "prefix", "30")
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", "192.168.3.2")
112 ec.set(tun2, "prefix", "30")
113 ec.register_connection(tun2, node2)
115 udptun = ec.register_resource("linux::UdpTunnel")
116 ec.register_connection(tun1, udptun)
117 ec.register_connection(tun2, udptun)
119 app = ec.register_resource("linux::Application")
120 cmd = "ping -c3 192.168.3.2"
121 ec.set(app, "command", cmd)
122 ec.register_connection(app, node1)
126 ec.wait_finished(app)
128 ping = ec.trace(app, "stdout")
131 expected = """3 packets transmitted, 3 received, 0% packet loss"""
132 self.assertTrue(ping.find(expected) > -1)
134 vif_name = ec.get(tun1, "deviceName")
135 self.assertTrue(vif_name.startswith("tun"))
137 vif_name = ec.get(tun2, "deviceName")
138 self.assertTrue(vif_name.startswith("tun"))
142 def test_tap_udp_tunnel(self):
143 self.t_tap_udp_tunnel(self.user, self.host, self.identity)
145 def ztest_tun_udp_tunnel(self):
146 self.t_tun_udp_tunnel(self.user, self.host, self.identity)
148 if __name__ == '__main__':