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>
20 from nepi.execution.ec import ExperimentController
22 ec = ExperimentController(exp_id = "ns3-local-p2p-ping")
24 # Simulation will executed in the local machine
25 node = ec.register_resource("linux::Node")
26 ec.set(node, "hostname", "localhost")
28 # Add a simulation resource
29 simu = ec.register_resource("linux::ns3::Simulation")
30 ec.set(simu, "verbose", True)
31 ec.register_connection(simu, node)
33 ## Add a ns-3 node with its protocol stack
34 nsnode1 = ec.register_resource("ns3::Node")
35 ec.register_connection(nsnode1, simu)
37 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
38 ec.register_connection(nsnode1, ipv4)
39 arp = ec.register_resource("ns3::ArpL3Protocol")
40 ec.register_connection(nsnode1, arp)
41 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
42 ec.register_connection(nsnode1, icmp)
44 # Add a point to point net device to the node
45 dev1 = ec.register_resource("ns3::PointToPointNetDevice")
46 ec.set(dev1, "ip", "10.0.0.1")
47 ec.set(dev1, "prefix", "30")
48 ec.register_connection(nsnode1, dev1)
49 queue1 = ec.register_resource("ns3::DropTailQueue")
50 ec.register_connection(dev1, queue1)
52 ## Add another ns-3 node with its protocol stack
53 nsnode2 = ec.register_resource("ns3::Node")
54 ec.register_connection(nsnode2, simu)
56 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
57 ec.register_connection(nsnode2, ipv4)
58 arp = ec.register_resource("ns3::ArpL3Protocol")
59 ec.register_connection(nsnode2, arp)
60 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
61 ec.register_connection(nsnode2, icmp)
63 # Add a point to point net device to the node
64 dev2 = ec.register_resource("ns3::PointToPointNetDevice")
65 ec.set(dev2, "ip", "10.0.0.2")
66 ec.set(dev2, "prefix", "30")
67 ec.register_connection(nsnode2, dev2)
68 queue2 = ec.register_resource("ns3::DropTailQueue")
69 ec.register_connection(dev2, queue2)
71 # Add a point to point channel
72 chan = ec.register_resource("ns3::PointToPointChannel")
73 ec.set(chan, "Delay", "0s")
74 ec.register_connection(chan, dev1)
75 ec.register_connection(chan, dev2)
78 ping = ec.register_resource("ns3::V4Ping")
79 ec.set (ping, "Remote", "10.0.0.2")
80 ec.set (ping, "Interval", "1s")
81 ec.set (ping, "Verbose", True)
82 ec.set (ping, "StartTime", "0s")
83 ec.set (ping, "StopTime", "20s")
84 ec.register_connection(ping, nsnode1)
88 ec.wait_finished([ping])
90 stdout = ec.trace(simu, "stdout")
94 print "PING OUTPUT", stdout