#!/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 __future__ import print_function from nepi.execution.ec import ExperimentController from test_utils import skipIfAnyNotAliveWithIdentity import os import time import unittest class LinuxUdpTunnelTestCase(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']) @skipIfAnyNotAliveWithIdentity def t_tap_udp_tunnel(self, user, host, identity): ec = ExperimentController(exp_id="test-tap-udp-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", "192.168.3.1") ec.set(tap1, "prefix", "30") 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", "192.168.3.2") ec.set(tap2, "prefix", "30") ec.register_connection(tap2, node2) udptun = ec.register_resource("linux::UdpTunnel") ec.register_connection(tap1, udptun) ec.register_connection(tap2, udptun) app = ec.register_resource("linux::Application") cmd = "ping -c3 192.168.3.2" ec.set(app, "command", cmd) ec.register_connection(app, node1) ec.deploy() ec.wait_finished(app) ping = ec.trace(app, "stdout") print(ping) expected = """3 packets transmitted, 3 received, 0% packet loss""" self.assertTrue(ping.find(expected) > -1) vif_name = ec.get(tap1, "deviceName") self.assertTrue(vif_name.startswith("tap")) vif_name = ec.get(tap2, "deviceName") self.assertTrue(vif_name.startswith("tap")) ec.shutdown() @skipIfAnyNotAliveWithIdentity def t_tun_udp_tunnel(self, user, host, identity): ec = ExperimentController(exp_id="test-tun-udp-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", "192.168.3.1") ec.set(tun1, "prefix", "30") 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", "192.168.3.2") ec.set(tun2, "prefix", "30") ec.register_connection(tun2, node2) udptun = ec.register_resource("linux::UdpTunnel") ec.register_connection(tun1, udptun) ec.register_connection(tun2, udptun) app = ec.register_resource("linux::Application") cmd = "ping -c3 192.168.3.2" ec.set(app, "command", cmd) ec.register_connection(app, node1) ec.deploy() ec.wait_finished(app) ping = ec.trace(app, "stdout") print(ping) expected = """3 packets transmitted, 3 received, 0% packet loss""" self.assertTrue(ping.find(expected) > -1) vif_name = ec.get(tun1, "deviceName") self.assertTrue(vif_name.startswith("tun")) vif_name = ec.get(tun2, "deviceName") self.assertTrue(vif_name.startswith("tun")) ec.shutdown() def test_tap_udp_tunnel(self): self.t_tap_udp_tunnel(self.user, self.host, self.identity) def ztest_tun_udp_tunnel(self): self.t_tun_udp_tunnel(self.user, self.host, self.identity) if __name__ == '__main__': unittest.main()