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 version 2 as
8 # published by the Free Software Foundation;
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program. If not, see <http://www.gnu.org/licenses/>.
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
21 # This example must be executed as root:
22 # $ sudo PYTHONPATH=$PYTHONPATH:src python examples/netns/local_switch_ping.py
24 from nepi.execution.ec import ExperimentController
26 ec = ExperimentController(exp_id = "netns-local-p2p-ping")
28 # Simulation will executed in the local machine
29 node = ec.register_resource("linux::Node")
30 ec.set(node, "hostname", "localhost")
32 # Add an emulation resource
33 emu = ec.register_resource("linux::netns::Emulation")
34 ec.set(emu, "verbose", True)
35 ec.register_connection(emu, node)
37 # Add two emulated nodes
38 netnsnode1 = ec.register_resource("netns::Node")
39 ec.register_connection(netnsnode1, emu)
41 iface1 = ec.register_resource("netns::NodeInterface")
42 ec.register_connection(iface1, netnsnode1)
44 ip1 = ec.register_resource("netns::IPv4Address")
45 ec.set(ip1, "ip", "10.0.0.1")
46 ec.set(ip1, "prefix", "30")
47 ec.register_connection(ip1, iface1)
49 netnsnode2 = ec.register_resource("netns::Node")
50 ec.register_connection(netnsnode2, emu)
52 iface2 = ec.register_resource("netns::NodeInterface")
53 ec.register_connection(iface2, netnsnode2)
55 ip2 = ec.register_resource("netns::IPv4Address")
56 ec.set(ip2, "ip", "10.0.0.2")
57 ec.set(ip2, "prefix", "30")
58 ec.register_connection(ip2, iface2)
60 switch = ec.register_resource("netns::Switch")
61 ec.register_connection(iface1, switch)
62 ec.register_connection(iface2, switch)
64 ping = ec.register_resource("netns::Application")
65 ec.set(ping, "command", "ping -c20 10.0.0.2")
66 ec.register_connection(ping, netnsnode1)
70 ec.wait_finished([ping])
72 stdout = ec.trace(ping, "stdout")
76 print "PING OUTPUT", stdout