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 __future__ import print_function
26 from nepi.execution.ec import ExperimentController
28 ec = ExperimentController(exp_id = "netns-local-p2p-ping")
30 # Simulation will executed in the local machine
31 node = ec.register_resource("linux::Node")
32 ec.set(node, "hostname", "localhost")
34 # Add an emulation resource
35 emu = ec.register_resource("linux::netns::Emulation")
36 ec.set(emu, "verbose", True)
37 ec.register_connection(emu, node)
39 # Add two emulated nodes
40 netnsnode1 = ec.register_resource("netns::Node")
41 ec.register_connection(netnsnode1, emu)
43 iface1 = ec.register_resource("netns::NodeInterface")
44 ec.register_connection(iface1, netnsnode1)
46 ip1 = ec.register_resource("netns::IPv4Address")
47 ec.set(ip1, "ip", "10.0.0.1")
48 ec.set(ip1, "prefix", "30")
49 ec.register_connection(ip1, iface1)
51 netnsnode2 = ec.register_resource("netns::Node")
52 ec.register_connection(netnsnode2, emu)
54 iface2 = ec.register_resource("netns::NodeInterface")
55 ec.register_connection(iface2, netnsnode2)
57 ip2 = ec.register_resource("netns::IPv4Address")
58 ec.set(ip2, "ip", "10.0.0.2")
59 ec.set(ip2, "prefix", "30")
60 ec.register_connection(ip2, iface2)
62 switch = ec.register_resource("netns::Switch")
63 ec.register_connection(iface1, switch)
64 ec.register_connection(iface2, switch)
66 ping = ec.register_resource("netns::Application")
67 ec.set(ping, "command", "ping -c20 10.0.0.2")
68 ec.register_connection(ping, netnsnode1)
72 ec.wait_finished([ping])
74 stdout = ec.trace(ping, "stdout")
78 print("PING OUTPUT", stdout)