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
23 ec = ExperimentController(exp_id = "ns3-local-ping")
25 # Simulation will executed in the local machine
26 node = ec.register_resource("LinuxNode")
27 ec.set(node, "hostname", "localhost")
29 # Add a simulation resource
30 simu = ec.register_resource("LinuxNS3Simulation")
31 ec.set(simu, "verbose", True)
32 ec.register_connection(simu, node)
34 ## Add a ns-3 node with its protocol stack
35 nsnode1 = ec.register_resource("ns3::Node")
36 ec.register_connection(nsnode1, simu)
38 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
39 ec.register_connection(nsnode1, ipv4)
40 arp = ec.register_resource("ns3::ArpL3Protocol")
41 ec.register_connection(nsnode1, arp)
42 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
43 ec.register_connection(nsnode1, icmp)
45 # Add a point to point net device to the node
46 dev1 = ec.register_resource("ns3::PointToPointNetDevice")
47 ec.set(dev1, "ip", "10.0.0.1")
48 ec.set(dev1, "prefix", "30")
49 ec.register_connection(nsnode1, dev1)
50 queue1 = ec.register_resource("ns3::DropTailQueue")
51 ec.register_connection(dev1, queue1)
53 ## Add another ns-3 node with its protocol stack
54 nsnode2 = ec.register_resource("ns3::Node")
55 ec.register_connection(nsnode2, simu)
57 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
58 ec.register_connection(nsnode2, ipv4)
59 arp = ec.register_resource("ns3::ArpL3Protocol")
60 ec.register_connection(nsnode2, arp)
61 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
62 ec.register_connection(nsnode2, icmp)
64 # Add a point to point net device to the node
65 dev2 = ec.register_resource("ns3::PointToPointNetDevice")
66 ec.set(dev2, "ip", "10.0.0.2")
67 ec.set(dev2, "prefix", "30")
68 ec.register_connection(nsnode2, dev2)
69 queue2 = ec.register_resource("ns3::DropTailQueue")
70 ec.register_connection(dev2, queue2)
72 # Add a point to point channel
73 chan = ec.register_resource("ns3::PointToPointChannel")
74 ec.set(chan, "Delay", "0s")
75 ec.register_connection(chan, dev1)
76 ec.register_connection(chan, dev2)
79 ping = ec.register_resource("ns3::V4Ping")
80 ec.set (ping, "Remote", "10.0.0.2")
81 ec.set (ping, "Interval", "1s")
82 ec.set (ping, "Verbose", True)
83 ec.set (ping, "StartTime", "0s")
84 ec.set (ping, "StopTime", "20s")
85 ec.register_connection(ping, nsnode1)
89 ec.wait_finished([ping])
91 stdout = ec.trace(simu, "stdout")
95 print "PING OUTPUT", stdout