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