#!/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 version 2 as # published by the Free Software Foundation; # # 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 . # # Author: Alina Quereilhac from nepi.execution.ec import ExperimentController from test_utils import skipIfAnyNotAliveWithIdentity import os import time import unittest ## TODO: VALIDATE THIS TEST! class LinuxGRETunnelTestCase(unittest.TestCase): def setUp(self): self.host = "roseval.pl.sophia.inria.fr" self.user = "inria_nepi" self.identity = "%s/.ssh/id_rsa" % (os.environ['HOME']) self.netblock = "192.168.1" @skipIfAnyNotAliveWithIdentity def t_tap_gre_tunnel(self, user, host, identity): ec = ExperimentController(exp_id = "test-tap-gre-tunnel") node1 = ec.register_resource("linux::Node") ec.set(node1, "hostname", "localhost") ec.set(node1, "cleanExperiment", True) ec.set(node1, "cleanProcesses", True) tap1 = ec.register_resource("linux::Tap") ec.set(tap1, "ip", "%s.1" % self.netblock) ec.set(tap1, "prefix", "32") ec.register_connection(tap1, node1) node2 = ec.register_resource("linux::Node") ec.set(node2, "hostname", host) ec.set(node2, "username", user) ec.set(node2, "identity", identity) ec.set(node2, "cleanExperiment", True) ec.set(node2, "cleanProcesses", True) tap2 = ec.register_resource("linux::Tap") ec.set(tap2, "ip", "%s.2" % self.netblock) ec.set(tap2, "prefix", "32") ec.register_connection(tap2, node2) gretun = ec.register_resource("linux::GRETunnel") ec.register_connection(tap1, gretun) ec.register_connection(tap2, gretun) app = ec.register_resource("linux::Application") 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, user, host, identity): ec = ExperimentController(exp_id = "test-tun-gre-tunnel") node1 = ec.register_resource("linux::Node") ec.set(node1, "hostname", "localhost") ec.set(node1, "cleanExperiment", True) ec.set(node1, "cleanProcesses", True) tun1 = ec.register_resource("linux::Tun") ec.set(tun1, "ip", "%s.1" % self.netblock) ec.set(tun1, "prefix", "32") ec.register_connection(tun1, node1) node2 = ec.register_resource("linux::Node") ec.set(node2, "hostname", host) ec.set(node2, "username", user) ec.set(node2, "identity", identity) ec.set(node2, "cleanExperiment", True) ec.set(node2, "cleanProcesses", True) tun2 = ec.register_resource("linux::Tun") ec.set(tun2, "ip", "%s.2" % self.netblock) ec.set(tun2, "prefix", "32") ec.register_connection(tun2, node2) udptun = ec.register_resource("linux::GRETunnel") ec.register_connection(tun1, udptun) ec.register_connection(tun2, udptun) app = ec.register_resource("linux::Application") 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.user, self.host, self.identity) def ztest_tun_gre_tunnel(self): self.t_tun_gre_tunnel(self.user, self.host, self.identity) if __name__ == '__main__': unittest.main()