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>
23 Initial positions. AP is fixed.
26 100m| (30,100) (60,100) (90,100)
31 60m| (30,60) (60,60) (90,60)
37 +----------------------------+
42 from nepi.execution.ec import ExperimentController
44 def add_node(ec, simu):
45 ## Add a ns-3 node with its protocol stack
46 nsnode = ec.register_resource("ns3::Node")
47 ec.register_connection(nsnode, simu)
49 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
50 ec.register_connection(nsnode, ipv4)
51 arp = ec.register_resource("ns3::ArpL3Protocol")
52 ec.register_connection(nsnode, arp)
53 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
54 ec.register_connection(nsnode, icmp)
57 def add_wifi_device(ec, node, ip, prefix, access_point = False):
58 dev = ec.register_resource("ns3::WifiNetDevice")
60 ec.set(dev, "prefix", prefix)
61 ec.register_connection(node, dev)
63 phy = ec.register_resource("ns3::YansWifiPhy")
64 ec.set(phy, "Standard", "WIFI_PHY_STANDARD_80211a")
65 ec.register_connection(dev, phy)
67 error = ec.register_resource("ns3::NistErrorRateModel")
68 ec.register_connection(phy, error)
70 manager = ec.register_resource("ns3::ArfWifiManager")
71 ec.register_connection(dev, manager)
74 mac = ec.register_resource("ns3::ApWifiMac")
76 mac = ec.register_resource("ns3::StaWifiMac")
78 ec.set(mac, "Standard", "WIFI_PHY_STANDARD_80211a")
79 ec.register_connection(dev, mac)
83 def add_random_mobility(ec, node, x, y, z, speed, bounds_width,
85 position = "%d:%d:%d" % (x, y, z)
86 bounds = "0|%d|0|%d" % (bounds_width, bounds_height)
87 speed = "ns3::UniformRandomVariable[Min=%d|Max=%s]" % (speed, speed)
88 pause = "ns3::ConstantRandomVariable[Constant=1.0]"
90 mobility = ec.register_resource("ns3::RandomDirection2dMobilityModel")
91 ec.set(mobility, "Position", position)
92 ec.set(mobility, "Bounds", bounds)
93 ec.set(mobility, "Speed", speed)
94 ec.set(mobility, "Pause", pause)
95 ec.register_connection(node, mobility)
98 def add_constant_mobility(ec, node, x, y, z):
99 mobility = ec.register_resource("ns3::ConstantPositionMobilityModel")
100 position = "%d:%d:%d" % (x, y, z)
101 ec.set(mobility, "Position", position)
102 ec.register_connection(node, mobility)
105 def add_wifi_channel(ec):
106 channel = ec.register_resource("ns3::YansWifiChannel")
107 delay = ec.register_resource("ns3::ConstantSpeedPropagationDelayModel")
108 ec.register_connection(channel, delay)
110 loss = ec.register_resource("ns3::LogDistancePropagationLossModel")
111 ec.register_connection(channel, loss)
115 bounds_width = bounds_height = 100
118 ec = ExperimentController(exp_id = "ns3-wifi-ping")
120 # Simulation will run in a remote machine
121 node = ec.register_resource("linux::Node")
122 ec.set(node, "hostname", "localhost")
124 # Add a simulation resource
125 simu = ec.register_resource("linux::ns3::Simulation")
126 ec.set(simu, "verbose", True)
127 ec.set(simu, "enableDump", True)
128 ec.set (simu, "StopTime", "22s")
129 ec.register_connection(simu, node)
133 nsnode1 = add_node(ec, simu)
134 dev1, phy1 = add_wifi_device(ec, nsnode1, "10.0.0.1", "24", access_point = False)
135 mobility1 = add_random_mobility(ec, nsnode1, x, y, 0, speed, bounds_width, bounds_height)
139 nsnode2 = add_node(ec, simu)
140 dev2, phy2 = add_wifi_device(ec, nsnode2, "10.0.0.2", "24", access_point = False)
141 mobility2 = add_random_mobility(ec, nsnode2, x, y, 0, speed, bounds_width, bounds_height)
145 nsnode3 = add_node(ec, simu)
146 dev3, phy3 = add_wifi_device(ec, nsnode3, "10.0.0.3", "24", access_point = False)
147 mobility3 = add_random_mobility(ec, nsnode3, x, y, 0, speed, bounds_width, bounds_height)
151 nsnode4 = add_node(ec, simu)
152 dev4, phy4 = add_wifi_device(ec, nsnode4, "10.0.0.4", "24", access_point = False)
153 mobility4 = add_random_mobility(ec, nsnode4, x, y, 0, speed, bounds_width, bounds_height)
157 nsnode5 = add_node(ec, simu)
158 dev5, phy5 = add_wifi_device(ec, nsnode5, "10.0.0.5", "24", access_point = False)
159 mobility5 = add_random_mobility(ec, nsnode5, x, y, 0, speed, bounds_width, bounds_height)
163 nsnode6 = add_node(ec, simu)
164 dev6, phy6 = add_wifi_device(ec, nsnode6, "10.0.0.6", "24", access_point = False)
165 mobility6 = add_random_mobility(ec, nsnode6, x, y, 0, speed, bounds_width, bounds_height)
169 nsnode7 = add_node(ec, simu)
170 dev7, phy7 = add_wifi_device(ec, nsnode7, "10.0.0.7", "24", access_point = True)
171 mobility7 = add_constant_mobility(ec, nsnode7, x, y, 0)
174 chan = add_wifi_channel(ec)
175 ec.register_connection(chan, phy1)
176 ec.register_connection(chan, phy2)
177 ec.register_connection(chan, phy3)
178 ec.register_connection(chan, phy4)
179 ec.register_connection(chan, phy5)
180 ec.register_connection(chan, phy6)
181 ec.register_connection(chan, phy7)
184 ping = ec.register_resource("ns3::V4Ping")
185 ec.set (ping, "Remote", "10.0.0.6")
186 ec.set (ping, "Interval", "1s")
187 ec.set (ping, "Verbose", True)
188 ec.set (ping, "StartTime", "1s")
189 ec.set (ping, "StopTime", "21s")
190 ec.register_connection(ping, nsnode1)
194 ec.wait_finished([ping])
196 stdout = ec.trace(simu, "stdout")
200 print "PING OUTPUT", stdout