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>
22 # This example must be executed as root:
23 # $ sudo PYTHONPATH=$PYTHONPATH:src python examples/netns/local_switch_ping.py
25 from nepi.execution.ec import ExperimentController
27 ec = ExperimentController(exp_id = "netns-local-p2p-ping")
29 # Simulation will executed in the local machine
30 node = ec.register_resource("linux::Node")
31 ec.set(node, "hostname", "localhost")
33 # Add an emulation resource
34 emu = ec.register_resource("linux::netns::Emulation")
35 ec.set(emu, "verbose", True)
36 ec.register_connection(emu, node)
38 # Add two emulated nodes
39 netnsnode1 = ec.register_resource("netns::Node")
40 ec.register_connection(netnsnode1, emu)
42 iface1 = ec.register_resource("netns::NodeInterface")
43 ec.register_connection(iface1, netnsnode1)
45 ip1 = ec.register_resource("netns::IPv4Address")
46 ec.set(ip1, "ip", "10.0.0.1")
47 ec.set(ip1, "prefix", "30")
48 ec.register_connection(ip1, iface1)
50 netnsnode2 = ec.register_resource("netns::Node")
51 ec.register_connection(netnsnode2, emu)
53 iface2 = ec.register_resource("netns::NodeInterface")
54 ec.register_connection(iface2, netnsnode2)
56 ip2 = ec.register_resource("netns::IPv4Address")
57 ec.set(ip2, "ip", "10.0.0.2")
58 ec.set(ip2, "prefix", "30")
59 ec.register_connection(ip2, iface2)
61 switch = ec.register_resource("netns::Switch")
62 ec.register_connection(iface1, switch)
63 ec.register_connection(iface2, switch)
65 ping = ec.register_resource("netns::Application")
66 ec.set(ping, "command", "ping -c20 10.0.0.2")
67 ec.register_connection(ping, netnsnode1)
71 ec.wait_finished([ping])
73 stdout = ec.trace(ping, "stdout")
77 print "PING OUTPUT", stdout