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 as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21 from nepi.execution.ec import ExperimentController
22 from nepi.execution.trace import TraceAttr
24 from test_utils import skipIfNotAlive
30 def add_node(ec, emu, addr, prefix):
31 node = ec.register_resource("netns::Node")
32 ec.register_connection(node, emu)
34 iface = ec.register_resource("netns::NodeInterface")
35 ec.register_connection(iface, node)
37 ip = ec.register_resource("netns::IPv4Address")
38 ec.set(ip, "ip", addr)
39 ec.set(ip, "prefix", prefix)
40 ec.register_connection(ip, iface)
42 print ec.get(ip, "ip"), addr
43 print ec.get(ip, "prefix"), prefix
47 class LinuxNetNSEmulationTest(unittest.TestCase):
49 self.fedora_host = "mimas.inria.fr"
50 self.fedora_user = "aquereil"
51 self.fedora_identity = "%s/.ssh/id_rsa" % (os.environ['HOME'])
54 def t_ping(self, host, user = None, identity = None):
55 ec = ExperimentController(exp_id = "test-netns-p2p-ping")
57 node = ec.register_resource("LinuxNode")
58 if host == "localhost":
59 ec.set(node, "hostname", "localhost")
61 ec.set(node, "hostname", host)
62 ec.set(node, "username", user)
63 ec.set(node, "identity", identity)
65 ec.set(node, "cleanProcesses", True)
66 #ec.set(node, "cleanHome", True)
68 emu = ec.register_resource("LinuxNetNSEmulation")
69 ec.set(emu, "verbose", True)
70 ec.register_connection(emu, node)
72 netnode1, iface1 = add_node(ec, emu, "10.0.0.1", "24")
73 netnode2, iface2 = add_node(ec, emu, "10.0.0.2", "24")
75 switch = ec.register_resource("netns::Switch")
76 ec.register_connection(iface1, switch)
77 ec.register_connection(iface2, switch)
79 ping = ec.register_resource("netns::Application")
80 ec.set(ping, "command", "10.0.0.2")
81 ec.register_connection(ping, netnode1)
85 ec.wait_finished([ping])
87 stdout = ec.trace(ping, "stdout")
89 expected = "20 packets transmitted, 20 received, 0% packet loss"
90 self.assertTrue(stdout.find(expected) > -1)
94 def ztest_ping_fedora(self):
95 self.t_ping(self.fedora_host, self.fedora_user, self.fedora_identity)
97 def test_ping_local(self):
98 self.t_ping("localhost")
101 if __name__ == '__main__':