X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=test%2Fresources%2Flinux%2Fnetns%2Fnetnsemulation.py;fp=test%2Fresources%2Flinux%2Fnetns%2Fnetnsemulation.py;h=d6d0b449188d490f03c03928867441f0a221f7f5;hb=741b99fe027fe6b54846a0703d26510d9b40a135;hp=0000000000000000000000000000000000000000;hpb=c6e14a2d8c1b0aab27d0a0dde1d123153bbf0cbf;p=nepi.git diff --git a/test/resources/linux/netns/netnsemulation.py b/test/resources/linux/netns/netnsemulation.py new file mode 100644 index 00000000..d6d0b449 --- /dev/null +++ b/test/resources/linux/netns/netnsemulation.py @@ -0,0 +1,103 @@ +#!/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 . +# +# Author: Alina Quereilhac + +from nepi.execution.ec import ExperimentController +from nepi.execution.trace import TraceAttr + +from test_utils import skipIfNotAlive + +import os +import time +import unittest + +def add_node(ec, emu, addr, prefix): + node = ec.register_resource("netns::Node") + ec.register_connection(node, emu) + + iface = ec.register_resource("netns::NodeInterface") + ec.register_connection(iface, node) + + ip = ec.register_resource("netns::IPv4Address") + ec.set(ip, "ip", addr) + ec.set(ip, "prefix", prefix) + ec.register_connection(ip, iface) + + print ec.get(ip, "ip"), addr + print ec.get(ip, "prefix"), prefix + + return node, iface + +class LinuxNetNSEmulationTest(unittest.TestCase): + def setUp(self): + self.fedora_host = "mimas.inria.fr" + self.fedora_user = "aquereil" + self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME']) + + @skipIfNotAlive + def t_ping(self, host, user = None, identity = None): + ec = ExperimentController(exp_id = "test-netns-p2p-ping") + + node = ec.register_resource("LinuxNode") + if host == "localhost": + ec.set(node, "hostname", "localhost") + else: + ec.set(node, "hostname", host) + ec.set(node, "username", user) + ec.set(node, "identity", identity) + + ec.set(node, "cleanProcesses", True) + #ec.set(node, "cleanHome", True) + + emu = ec.register_resource("LinuxNetNSEmulation") + ec.set(emu, "verbose", True) + ec.register_connection(emu, node) + + netnode1, iface1 = add_node(ec, emu, "10.0.0.1", "24") + netnode2, iface2 = add_node(ec, emu, "10.0.0.2", "24") + + switch = ec.register_resource("netns::Switch") + ec.register_connection(iface1, switch) + ec.register_connection(iface2, switch) + + ping = ec.register_resource("netns::Application") + ec.set(ping, "command", "10.0.0.2") + ec.register_connection(ping, netnode1) + + ec.deploy() + + ec.wait_finished([ping]) + + stdout = ec.trace(ping, "stdout") + + expected = "20 packets transmitted, 20 received, 0% packet loss" + self.assertTrue(stdout.find(expected) > -1) + + ec.shutdown() + + def ztest_ping_fedora(self): + self.t_ping(self.fedora_host, self.fedora_user, self.fedora_identity) + + def test_ping_local(self): + self.t_ping("localhost") + + +if __name__ == '__main__': + unittest.main() +