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