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>
24 Initial positions. AP is fixed.
27 100m| (30,100) (60,100) (90,100)
32 60m| (30,60) (60,60) (90,60)
38 +----------------------------+
43 from nepi.execution.ec import ExperimentController
45 def add_node(ec, simu):
46 ## Add a ns-3 node with its protocol stack
47 nsnode = ec.register_resource("ns3::Node")
48 ec.register_connection(nsnode, simu)
50 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
51 ec.register_connection(nsnode, ipv4)
52 arp = ec.register_resource("ns3::ArpL3Protocol")
53 ec.register_connection(nsnode, arp)
54 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
55 ec.register_connection(nsnode, icmp)
58 def add_wifi_device(ec, node, ip, prefix, access_point = False):
59 dev = ec.register_resource("ns3::WifiNetDevice")
61 ec.set(dev, "prefix", prefix)
62 ec.register_connection(node, dev)
64 phy = ec.register_resource("ns3::YansWifiPhy")
65 ec.set(phy, "Standard", "WIFI_PHY_STANDARD_80211a")
66 ec.register_connection(dev, phy)
68 error = ec.register_resource("ns3::NistErrorRateModel")
69 ec.register_connection(phy, error)
71 manager = ec.register_resource("ns3::ArfWifiManager")
72 ec.register_connection(dev, manager)
75 mac = ec.register_resource("ns3::ApWifiMac")
77 mac = ec.register_resource("ns3::StaWifiMac")
79 ec.set(mac, "Standard", "WIFI_PHY_STANDARD_80211a")
80 ec.register_connection(dev, mac)
84 def add_random_mobility(ec, node, x, y, z, speed, bounds_width,
86 position = "%d:%d:%d" % (x, y, z)
87 bounds = "0|%d|0|%d" % (bounds_width, bounds_height)
88 speed = "ns3::UniformRandomVariable[Min=%d|Max=%s]" % (speed, speed)
89 pause = "ns3::ConstantRandomVariable[Constant=1.0]"
91 mobility = ec.register_resource("ns3::RandomDirection2dMobilityModel")
92 ec.set(mobility, "Position", position)
93 ec.set(mobility, "Bounds", bounds)
94 ec.set(mobility, "Speed", speed)
95 ec.set(mobility, "Pause", pause)
96 ec.register_connection(node, mobility)
99 def add_constant_mobility(ec, node, x, y, z):
100 mobility = ec.register_resource("ns3::ConstantPositionMobilityModel")
101 position = "%d:%d:%d" % (x, y, z)
102 ec.set(mobility, "Position", position)
103 ec.register_connection(node, mobility)
106 def add_wifi_channel(ec):
107 channel = ec.register_resource("ns3::YansWifiChannel")
108 delay = ec.register_resource("ns3::ConstantSpeedPropagationDelayModel")
109 ec.register_connection(channel, delay)
111 loss = ec.register_resource("ns3::LogDistancePropagationLossModel")
112 ec.register_connection(channel, loss)
116 bounds_width = bounds_height = 100
119 ec = ExperimentController(exp_id = "ns3-wifi-ping")
121 # Simulation will run in a remote machine
122 node = ec.register_resource("LinuxNode")
123 ec.set(node, "hostname", "localhost")
125 # Add a simulation resource
126 simu = ec.register_resource("LinuxNS3Simulation")
127 ec.set(simu, "verbose", True)
128 ec.set(simu, "enableDump", True)
129 ec.set (simu, "StopTime", "22s")
130 ec.register_connection(simu, node)
134 nsnode1 = add_node(ec, simu)
135 dev1, phy1 = add_wifi_device(ec, nsnode1, "10.0.0.1", "24", access_point = False)
136 mobility1 = add_random_mobility(ec, nsnode1, x, y, 0, speed, bounds_width, bounds_height)
140 nsnode2 = add_node(ec, simu)
141 dev2, phy2 = add_wifi_device(ec, nsnode2, "10.0.0.2", "24", access_point = False)
142 mobility2 = add_random_mobility(ec, nsnode2, x, y, 0, speed, bounds_width, bounds_height)
146 nsnode3 = add_node(ec, simu)
147 dev3, phy3 = add_wifi_device(ec, nsnode3, "10.0.0.3", "24", access_point = False)
148 mobility3 = add_random_mobility(ec, nsnode3, x, y, 0, speed, bounds_width, bounds_height)
152 nsnode4 = add_node(ec, simu)
153 dev4, phy4 = add_wifi_device(ec, nsnode4, "10.0.0.4", "24", access_point = False)
154 mobility4 = add_random_mobility(ec, nsnode4, x, y, 0, speed, bounds_width, bounds_height)
158 nsnode5 = add_node(ec, simu)
159 dev5, phy5 = add_wifi_device(ec, nsnode5, "10.0.0.5", "24", access_point = False)
160 mobility5 = add_random_mobility(ec, nsnode5, x, y, 0, speed, bounds_width, bounds_height)
164 nsnode6 = add_node(ec, simu)
165 dev6, phy6 = add_wifi_device(ec, nsnode6, "10.0.0.6", "24", access_point = False)
166 mobility6 = add_random_mobility(ec, nsnode6, x, y, 0, speed, bounds_width, bounds_height)
170 nsnode7 = add_node(ec, simu)
171 dev7, phy7 = add_wifi_device(ec, nsnode7, "10.0.0.7", "24", access_point = True)
172 mobility7 = add_constant_mobility(ec, nsnode7, x, y, 0)
175 chan = add_wifi_channel(ec)
176 ec.register_connection(chan, phy1)
177 ec.register_connection(chan, phy2)
178 ec.register_connection(chan, phy3)
179 ec.register_connection(chan, phy4)
180 ec.register_connection(chan, phy5)
181 ec.register_connection(chan, phy6)
182 ec.register_connection(chan, phy7)
185 ping = ec.register_resource("ns3::V4Ping")
186 ec.set (ping, "Remote", "10.0.0.6")
187 ec.set (ping, "Interval", "1s")
188 ec.set (ping, "Verbose", True)
189 ec.set (ping, "StartTime", "1s")
190 ec.set (ping, "StopTime", "21s")
191 ec.register_connection(ping, nsnode1)
195 ec.wait_finished([ping])
197 stdout = ec.trace(simu, "stdout")
201 print "PING OUTPUT", stdout