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 from optparse import OptionParser
24 usage = ("usage: %prog -H <hostanme> -u <username> -i <ssh-key>")
26 parser = OptionParser(usage = usage)
27 parser.add_option("-H", "--hostname", dest="hostname",
28 help="Remote host name or IP address", type="str")
29 parser.add_option("-u", "--username", dest="username",
30 help="Username to SSH to remote host", type="str")
31 parser.add_option("-i", "--ssh-key", dest="ssh_key",
32 help="Path to private SSH key to be used for connection",
34 (options, args) = parser.parse_args()
36 hostname = options.hostname
37 username = options.username
38 identity = options.ssh_key
40 ec = ExperimentController(exp_id = "ns3-remote-p2p-ping")
42 # Simulation will run in a remote machine
43 node = ec.register_resource("linux::Node")
44 ec.set(node, "hostname", hostname)
45 ec.set(node, "username", username)
46 ec.set(node, "identity", identity)
47 ec.set(node, "cleanProcesses", True)
48 ec.set(node, "cleanExperiment", True)
50 # Add a simulation resource
51 simu = ec.register_resource("linux::ns3::Simulation")
52 ec.set(simu, "verbose", True)
53 ec.register_connection(simu, node)
55 ## Add a ns-3 node with its protocol stack
56 nsnode1 = ec.register_resource("ns3::Node")
57 ec.register_connection(nsnode1, simu)
59 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
60 ec.register_connection(nsnode1, ipv4)
61 arp = ec.register_resource("ns3::ArpL3Protocol")
62 ec.register_connection(nsnode1, arp)
63 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
64 ec.register_connection(nsnode1, icmp)
66 # Add a point to point net device to the node
67 dev1 = ec.register_resource("ns3::PointToPointNetDevice")
68 ec.set(dev1, "ip", "10.0.0.1")
69 ec.set(dev1, "prefix", "30")
70 ec.register_connection(nsnode1, dev1)
71 queue1 = ec.register_resource("ns3::DropTailQueue")
72 ec.register_connection(dev1, queue1)
74 ## Add another ns-3 node with its protocol stack
75 nsnode2 = ec.register_resource("ns3::Node")
76 ec.register_connection(nsnode2, simu)
78 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
79 ec.register_connection(nsnode2, ipv4)
80 arp = ec.register_resource("ns3::ArpL3Protocol")
81 ec.register_connection(nsnode2, arp)
82 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
83 ec.register_connection(nsnode2, icmp)
85 # Add a point to point net device to the node
86 dev2 = ec.register_resource("ns3::PointToPointNetDevice")
87 ec.set(dev2, "ip", "10.0.0.2")
88 ec.set(dev2, "prefix", "30")
89 ec.register_connection(nsnode2, dev2)
90 queue2 = ec.register_resource("ns3::DropTailQueue")
91 ec.register_connection(dev2, queue2)
93 # Add a point to point channel
94 chan = ec.register_resource("ns3::PointToPointChannel")
95 ec.set(chan, "Delay", "0s")
96 ec.register_connection(chan, dev1)
97 ec.register_connection(chan, dev2)
100 ping = ec.register_resource("ns3::V4Ping")
101 ec.set (ping, "Remote", "10.0.0.2")
102 ec.set (ping, "Interval", "1s")
103 ec.set (ping, "Verbose", True)
104 ec.set (ping, "StartTime", "0s")
105 ec.set (ping, "StopTime", "20s")
106 ec.register_connection(ping, nsnode1)
110 ec.wait_finished([ping])
112 stdout = ec.trace(simu, "stdout")
116 print "PING OUTPUT", stdout