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 class LinuxUdpTunnelTestCase(unittest.TestCase):
30 self.host = "roseval.pl.sophia.inria.fr"
31 self.user = "inria_nepi"
32 self.identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
34 @skipIfAnyNotAliveWithIdentity
35 def t_tap_udp_tunnel(self, user, host, identity):
37 ec = ExperimentController(exp_id="test-tap-udp-tunnel")
39 node1 = ec.register_resource("linux::Node")
40 ec.set(node1, "hostname", "localhost")
41 ec.set(node1, "cleanExperiment", True)
42 ec.set(node1, "cleanProcesses", True)
44 tap1 = ec.register_resource("linux::Tap")
45 ec.set(tap1, "ip", "192.168.3.1")
46 ec.set(tap1, "prefix", "30")
47 ec.register_connection(tap1, node1)
49 node2 = ec.register_resource("linux::Node")
50 ec.set(node2, "hostname", host)
51 ec.set(node2, "username", user)
52 ec.set(node2, "identity", identity)
53 ec.set(node2, "cleanExperiment", True)
54 ec.set(node2, "cleanProcesses", True)
56 tap2 = ec.register_resource("linux::Tap")
57 ec.set(tap2, "ip", "192.168.3.2")
58 ec.set(tap2, "prefix", "30")
59 ec.register_connection(tap2, node2)
61 udptun = ec.register_resource("linux::UdpTunnel")
62 ec.register_connection(tap1, udptun)
63 ec.register_connection(tap2, udptun)
65 app = ec.register_resource("linux::Application")
66 cmd = "ping -c3 192.168.3.2"
67 ec.set(app, "command", cmd)
68 ec.register_connection(app, node1)
74 ping = ec.trace(app, "stdout")
76 expected = """3 packets transmitted, 3 received, 0% packet loss"""
77 self.assertTrue(ping.find(expected) > -1)
79 vif_name = ec.get(tap1, "deviceName")
80 self.assertTrue(vif_name.startswith("tap"))
82 vif_name = ec.get(tap2, "deviceName")
83 self.assertTrue(vif_name.startswith("tap"))
87 @skipIfAnyNotAliveWithIdentity
88 def t_tun_udp_tunnel(self, user, host, identity):
90 ec = ExperimentController(exp_id="test-tun-udp-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", "192.168.3.1")
99 ec.set(tun1, "prefix", "30")
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", "192.168.3.2")
111 ec.set(tun2, "prefix", "30")
112 ec.register_connection(tun2, node2)
114 udptun = ec.register_resource("linux::UdpTunnel")
115 ec.register_connection(tun1, udptun)
116 ec.register_connection(tun2, udptun)
118 app = ec.register_resource("linux::Application")
119 cmd = "ping -c3 192.168.3.2"
120 ec.set(app, "command", cmd)
121 ec.register_connection(app, node1)
125 ec.wait_finished(app)
127 ping = ec.trace(app, "stdout")
130 expected = """3 packets transmitted, 3 received, 0% packet loss"""
131 self.assertTrue(ping.find(expected) > -1)
133 vif_name = ec.get(tun1, "deviceName")
134 self.assertTrue(vif_name.startswith("tun"))
136 vif_name = ec.get(tun2, "deviceName")
137 self.assertTrue(vif_name.startswith("tun"))
141 def test_tap_udp_tunnel(self):
142 self.t_tap_udp_tunnel(self.user, self.host, self.identity)
144 def ztest_tun_udp_tunnel(self):
145 self.t_tun_udp_tunnel(self.user, self.host, self.identity)
147 if __name__ == '__main__':