Added LinuxGRETunnel test (to validate)
authorAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 29 Jul 2014 21:19:07 +0000 (23:19 +0200)
committerAlina Quereilhac <alina.quereilhac@inria.fr>
Tue, 29 Jul 2014 21:19:07 +0000 (23:19 +0200)
src/nepi/resources/linux/gretunnel.py
src/nepi/resources/linux/tap.py
test/resources/linux/gretunnel.py [new file with mode: 0755]

index 174829d..d69ac30 100644 (file)
@@ -56,8 +56,9 @@ class LinuxGRETunnel(LinuxTunnel):
         # other endpoint
         connection_run_home = self.run_home(endpoint)
         connection_app_home = self.app_home(endpoint)
-        data = endpoint.gre_connect(remote_endpoint, connection_run_home, 
-                connection_app_home)
+        data = endpoint.gre_connect(remote_endpoint, 
+                connection_app_home,
+                connection_run_home) 
         return data
 
     def establish_connection(self, endpoint, remote_endpoint, data):
index 24efdff..ee977ef 100644 (file)
@@ -218,7 +218,7 @@ class LinuxTap(LinuxApplication):
 
         # upload command to connect.sh script
         shfile = os.path.join(connection_app_home, "gre-connect.sh")
-        endpoint.node.upload(gre_connect_command,
+        self.node.upload(gre_connect_command,
                 shfile,
                 text = True, 
                 overwrite = False)
@@ -297,12 +297,12 @@ class LinuxTap(LinuxApplication):
                 socket.gethostbyname(self.node.get("hostname")),
                 self.get("greKey")
             ))
-        command.append("sudo -S addr add dev %s %s/%d peer %s/%d" % (
-                self.get("deviceName"),
+        command.append("sudo -S ip addr add %s/%d peer %s/%d dev %s" % (
                 self.get("ip4"),
                 self.get("prefix4"),
                 self.get("pointopoint"),
                 self.get("prefix4"),
+                self.get("deviceName"),
                 ))
         command.append("sudo -S ip link set %s up " % self.get("deviceName"))
 
diff --git a/test/resources/linux/gretunnel.py b/test/resources/linux/gretunnel.py
new file mode 100755 (executable)
index 0000000..174b344
--- /dev/null
@@ -0,0 +1,158 @@
+#!/usr/bin/env python
+#
+#    NEPI, a framework to manage network experiments
+#    Copyright (C) 2013 INRIA
+#
+#    This program is free software: you can redistribute it and/or modify
+#    it under the terms of the GNU General Public License as published by
+#    the Free Software Foundation, either version 3 of the License, or
+#    (at your option) any later version.
+#
+#    This program is distributed in the hope that it will be useful,
+#    but WITHOUT ANY WARRANTY; without even the implied warranty of
+#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+#    GNU General Public License for more details.
+#
+#    You should have received a copy of the GNU General Public License
+#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
+#
+# Author: Alina Quereilhac <alina.quereilhac@inria.fr>
+
+from nepi.execution.ec import ExperimentController 
+
+from test_utils import skipIfAnyNotAliveWithIdentity
+
+import os
+import time
+import unittest
+
+class LinuxGRETunnelTestCase(unittest.TestCase):
+    def setUp(self):
+        self.host1 = "roseval.pl.sophia.inria.fr"
+        self.host2 = "truckers.pl.sophia.inria.fr"
+        self.user1 = "inria_nepi"
+        self.user2 = "aquereil"
+        self.identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
+        self.netblock = "192.168.1"
+
+    @skipIfAnyNotAliveWithIdentity
+    def t_tap_gre_tunnel(self, user1, host1, identity1, user2, host2, 
+            identity2):
+
+        ec = ExperimentController(exp_id = "test-tap-gre-tunnel")
+        
+        node1 = ec.register_resource("LinuxNode")
+        ec.set(node1, "hostname", host1)
+        ec.set(node1, "username", user1)
+        ec.set(node1, "identity", identity1)
+        ec.set(node1, "cleanHome", True)
+        ec.set(node1, "cleanProcesses", True)
+
+        tap1 = ec.register_resource("LinuxTap")
+        ec.set(tap1, "ip4", "%s.1" % self.netblock)
+        ec.set(tap1, "prefix4", 24)
+        ec.register_connection(tap1, node1)
+
+        node2 = ec.register_resource("LinuxNode")
+        ec.set(node2, "hostname", host2)
+        ec.set(node2, "username", user2)
+        ec.set(node2, "identity", identity2)
+        ec.set(node2, "cleanHome", True)
+        ec.set(node2, "cleanProcesses", True)
+
+        tap2 = ec.register_resource("LinuxTap")
+        ec.set(tap2, "ip4", "%s.2" % self.netblock)
+        ec.set(tap2, "prefix4", 24)
+        ec.register_connection(tap2, node2)
+
+        gretun = ec.register_resource("LinuxGRETunnel")
+        ec.register_connection(tap1, gretun)
+        ec.register_connection(tap2, gretun)
+
+        app = ec.register_resource("LinuxApplication")
+        cmd = "ping -c3 %s.2" % self.netblock
+        ec.set(app, "command", cmd)
+        ec.register_connection(app, node1)
+
+        ec.deploy()
+
+        ec.wait_finished(app)
+
+        ping = ec.trace(app, 'stdout')
+        expected = """3 packets transmitted, 3 received, 0% packet loss"""
+        self.assertTrue(ping.find(expected) > -1)
+        
+        if_name = ec.get(tap1, "deviceName")
+        self.assertTrue(if_name.startswith("tap"))
+        
+        if_name = ec.get(tap2, "deviceName")
+        self.assertTrue(if_name.startswith("tap"))
+
+        ec.shutdown()
+
+    @skipIfAnyNotAliveWithIdentity
+    def t_tun_gre_tunnel(self, user1, host1, identity1, user2, host2, 
+            identity2):
+
+        ec = ExperimentController(exp_id = "test-tun-gre-tunnel")
+        
+        node1 = ec.register_resource("LinuxNode")
+        ec.set(node1, "hostname", host1)
+        ec.set(node1, "username", user1)
+        ec.set(node1, "identity", identity1)
+        ec.set(node1, "cleanHome", True)
+        ec.set(node1, "cleanProcesses", True)
+
+        tun1 = ec.register_resource("LinuxTun")
+        ec.set(tun1, "ip4", "%s.1" % self.netblock)
+        ec.set(tun1, "prefix4", 24)
+        ec.register_connection(tun1, node1)
+
+        node2 = ec.register_resource("LinuxNode")
+        ec.set(node2, "hostname", host2)
+        ec.set(node2, "username", user2)
+        ec.set(node2, "identity", identity2)
+        ec.set(node2, "cleanHome", True)
+        ec.set(node2, "cleanProcesses", True)
+
+        tun2 = ec.register_resource("LinuxTun")
+        ec.set(tun2, "ip4", "%s.2" % self.netblock)
+        ec.set(tun2, "prefix4", 24)
+        ec.register_connection(tun2, node2)
+
+        udptun = ec.register_resource("LinuxGRETunnel")
+        ec.register_connection(tun1, udptun)
+        ec.register_connection(tun2, udptun)
+
+        app = ec.register_resource("LinuxApplication")
+        cmd = "ping -c3 %s.2" % self.netblock
+        ec.set(app, "command", cmd)
+        ec.register_connection(app, node1)
+
+        ec.deploy()
+
+        ec.wait_finished(app)
+
+        ping = ec.trace(app, 'stdout')
+        expected = """3 packets transmitted, 3 received, 0% packet loss"""
+        self.assertTrue(ping.find(expected) > -1)
+        
+        if_name = ec.get(tun1, "deviceName")
+        self.assertTrue(if_name.startswith("tun"))
+        
+        if_name = ec.get(tun2, "deviceName")
+        self.assertTrue(if_name.startswith("tun"))
+
+        ec.shutdown()
+
+    def test_tap_gre_tunnel(self):
+        self.t_tap_gre_tunnel(self.user1, self.host1, self.identity,
+                self.user2, self.host2, self.identity)
+
+    def ztest_tun_gre_tunnel(self):
+        self.t_tun_gre_tunnel(self.user1, self.host1, self.identity,
+                self.user2, self.host2, self.identity)
+
+if __name__ == '__main__':
+    unittest.main()
+