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 __future__ import print_function
25 Initial positions. AP is fixed.
28 100m| (30,100) (60,100) (90,100)
33 60m| (30,60) (60,60) (90,60)
39 +----------------------------+
44 from nepi.execution.ec import ExperimentController
46 def add_node(ec, simu):
47 ## Add a ns-3 node with its protocol stack
48 nsnode = ec.register_resource("ns3::Node")
49 ec.register_connection(nsnode, simu)
51 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
52 ec.register_connection(nsnode, ipv4)
53 arp = ec.register_resource("ns3::ArpL3Protocol")
54 ec.register_connection(nsnode, arp)
55 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
56 ec.register_connection(nsnode, icmp)
59 def add_wifi_device(ec, node, ip, prefix, access_point = False):
60 dev = ec.register_resource("ns3::WifiNetDevice")
62 ec.set(dev, "prefix", prefix)
63 ec.register_connection(node, dev)
65 phy = ec.register_resource("ns3::YansWifiPhy")
66 ec.set(phy, "Standard", "WIFI_PHY_STANDARD_80211a")
67 ec.register_connection(dev, phy)
69 error = ec.register_resource("ns3::NistErrorRateModel")
70 ec.register_connection(phy, error)
72 manager = ec.register_resource("ns3::ArfWifiManager")
73 ec.register_connection(dev, manager)
76 mac = ec.register_resource("ns3::ApWifiMac")
78 mac = ec.register_resource("ns3::StaWifiMac")
80 ec.set(mac, "Standard", "WIFI_PHY_STANDARD_80211a")
81 ec.register_connection(dev, mac)
85 def add_random_mobility(ec, node, x, y, z, speed, bounds_width,
87 position = "%d:%d:%d" % (x, y, z)
88 bounds = "0|%d|0|%d" % (bounds_width, bounds_height)
89 speed = "ns3::UniformRandomVariable[Min=%d|Max=%s]" % (speed, speed)
90 pause = "ns3::ConstantRandomVariable[Constant=1.0]"
92 mobility = ec.register_resource("ns3::RandomDirection2dMobilityModel")
93 ec.set(mobility, "Position", position)
94 ec.set(mobility, "Bounds", bounds)
95 ec.set(mobility, "Speed", speed)
96 ec.set(mobility, "Pause", pause)
97 ec.register_connection(node, mobility)
100 def add_constant_mobility(ec, node, x, y, z):
101 mobility = ec.register_resource("ns3::ConstantPositionMobilityModel")
102 position = "%d:%d:%d" % (x, y, z)
103 ec.set(mobility, "Position", position)
104 ec.register_connection(node, mobility)
107 def add_wifi_channel(ec):
108 channel = ec.register_resource("ns3::YansWifiChannel")
109 delay = ec.register_resource("ns3::ConstantSpeedPropagationDelayModel")
110 ec.register_connection(channel, delay)
112 loss = ec.register_resource("ns3::LogDistancePropagationLossModel")
113 ec.register_connection(channel, loss)
117 bounds_width = bounds_height = 100
120 ec = ExperimentController(exp_id = "ns3-wifi-ping")
122 # Simulation will run in a remote machine
123 node = ec.register_resource("linux::Node")
124 ec.set(node, "hostname", "localhost")
126 # Add a simulation resource
127 simu = ec.register_resource("linux::ns3::Simulation")
128 ec.set(simu, "verbose", True)
129 ec.set(simu, "enableDump", True)
130 ec.set (simu, "StopTime", "22s")
131 ec.register_connection(simu, node)
135 nsnode1 = add_node(ec, simu)
136 dev1, phy1 = add_wifi_device(ec, nsnode1, "10.0.0.1", "24", access_point = False)
137 mobility1 = add_random_mobility(ec, nsnode1, x, y, 0, speed, bounds_width, bounds_height)
141 nsnode2 = add_node(ec, simu)
142 dev2, phy2 = add_wifi_device(ec, nsnode2, "10.0.0.2", "24", access_point = False)
143 mobility2 = add_random_mobility(ec, nsnode2, x, y, 0, speed, bounds_width, bounds_height)
147 nsnode3 = add_node(ec, simu)
148 dev3, phy3 = add_wifi_device(ec, nsnode3, "10.0.0.3", "24", access_point = False)
149 mobility3 = add_random_mobility(ec, nsnode3, x, y, 0, speed, bounds_width, bounds_height)
153 nsnode4 = add_node(ec, simu)
154 dev4, phy4 = add_wifi_device(ec, nsnode4, "10.0.0.4", "24", access_point = False)
155 mobility4 = add_random_mobility(ec, nsnode4, x, y, 0, speed, bounds_width, bounds_height)
159 nsnode5 = add_node(ec, simu)
160 dev5, phy5 = add_wifi_device(ec, nsnode5, "10.0.0.5", "24", access_point = False)
161 mobility5 = add_random_mobility(ec, nsnode5, x, y, 0, speed, bounds_width, bounds_height)
165 nsnode6 = add_node(ec, simu)
166 dev6, phy6 = add_wifi_device(ec, nsnode6, "10.0.0.6", "24", access_point = False)
167 mobility6 = add_random_mobility(ec, nsnode6, x, y, 0, speed, bounds_width, bounds_height)
171 nsnode7 = add_node(ec, simu)
172 dev7, phy7 = add_wifi_device(ec, nsnode7, "10.0.0.7", "24", access_point = True)
173 mobility7 = add_constant_mobility(ec, nsnode7, x, y, 0)
176 chan = add_wifi_channel(ec)
177 ec.register_connection(chan, phy1)
178 ec.register_connection(chan, phy2)
179 ec.register_connection(chan, phy3)
180 ec.register_connection(chan, phy4)
181 ec.register_connection(chan, phy5)
182 ec.register_connection(chan, phy6)
183 ec.register_connection(chan, phy7)
186 ping = ec.register_resource("ns3::V4Ping")
187 ec.set (ping, "Remote", "10.0.0.6")
188 ec.set (ping, "Interval", "1s")
189 ec.set (ping, "Verbose", True)
190 ec.set (ping, "StartTime", "1s")
191 ec.set (ping, "StopTime", "21s")
192 ec.register_connection(ping, nsnode1)
196 ec.wait_finished([ping])
198 stdout = ec.trace(simu, "stdout")
202 print("PING OUTPUT", stdout)