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
22 from nepi.execution.ec import ExperimentController
24 ec = ExperimentController(exp_id = "ns3-local-wifi-ping")
26 # Simulation will executed in the local machine
27 node = ec.register_resource("linux::Node")
28 ec.set(node, "hostname", "localhost")
30 # Add a simulation resource
31 simu = ec.register_resource("linux::ns3::Simulation")
32 ec.set(simu, "verbose", True)
33 ec.register_connection(simu, node)
35 ## Add a ns-3 node with its protocol stack
36 nsnode1 = ec.register_resource("ns3::Node")
37 ec.register_connection(nsnode1, simu)
39 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
40 ec.register_connection(nsnode1, ipv4)
41 arp = ec.register_resource("ns3::ArpL3Protocol")
42 ec.register_connection(nsnode1, arp)
43 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
44 ec.register_connection(nsnode1, icmp)
46 # Adding constant mobility to the ns-3 node
47 mobility1 = ec.register_resource("ns3::ConstantPositionMobilityModel")
48 position1 = "%d:%d:%d" % (0, 0, 0)
49 ec.set(mobility1, "Position", position1)
50 ec.register_connection(nsnode1, mobility1)
52 # Add a wifi access point net device to the node
53 dev1 = ec.register_resource("ns3::WifiNetDevice")
54 ec.set(dev1, "ip", "10.0.0.1")
55 ec.set(dev1, "prefix", "30")
56 ec.register_connection(nsnode1, dev1)
58 phy1 = ec.register_resource("ns3::YansWifiPhy")
59 ec.set(phy1, "Standard", "WIFI_PHY_STANDARD_80211a")
60 ec.register_connection(dev1, phy1)
62 error1 = ec.register_resource("ns3::NistErrorRateModel")
63 ec.register_connection(phy1, error1)
65 manager1 = ec.register_resource("ns3::ArfWifiManager")
66 ec.register_connection(dev1, manager1)
68 # Mark the node as a wireless access point
69 mac1 = ec.register_resource("ns3::ApWifiMac")
70 ec.set(mac1, "Standard", "WIFI_PHY_STANDARD_80211a")
71 ec.register_connection(dev1, mac1)
73 ## Add another ns-3 node with its protocol stack
74 nsnode2 = ec.register_resource("ns3::Node")
75 ec.register_connection(nsnode2, simu)
77 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
78 ec.register_connection(nsnode2, ipv4)
79 arp = ec.register_resource("ns3::ArpL3Protocol")
80 ec.register_connection(nsnode2, arp)
81 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
82 ec.register_connection(nsnode2, icmp)
84 # Adding constant mobility to the ns-3 node
85 mobility2 = ec.register_resource("ns3::ConstantPositionMobilityModel")
86 position2 = "%d:%d:%d" % (50, 50, 0)
87 ec.set(mobility2, "Position", position2)
88 ec.register_connection(nsnode2, mobility2)
90 # Add a wifi station net device to the node
91 dev2 = ec.register_resource("ns3::WifiNetDevice")
92 ec.set(dev2, "ip", "10.0.0.2")
93 ec.set(dev2, "prefix", "30")
94 ec.register_connection(nsnode2, dev2)
96 phy2 = ec.register_resource("ns3::YansWifiPhy")
97 ec.set(phy2, "Standard", "WIFI_PHY_STANDARD_80211a")
98 ec.register_connection(dev2, phy2)
100 error2 = ec.register_resource("ns3::NistErrorRateModel")
101 ec.register_connection(phy2, error2)
103 manager2 = ec.register_resource("ns3::ArfWifiManager")
104 ec.register_connection(dev2, manager2)
106 # Mark the node as a wireless station
107 mac2 = ec.register_resource("ns3::StaWifiMac")
108 ec.set(mac2, "Standard", "WIFI_PHY_STANDARD_80211a")
109 ec.register_connection(dev2, mac2)
112 chan = ec.register_resource("ns3::YansWifiChannel")
113 delay = ec.register_resource("ns3::ConstantSpeedPropagationDelayModel")
114 ec.register_connection(chan, delay)
115 loss = ec.register_resource("ns3::LogDistancePropagationLossModel")
116 ec.register_connection(chan, loss)
117 ec.register_connection(chan, phy1)
118 ec.register_connection(chan, phy2)
121 ping = ec.register_resource("ns3::V4Ping")
122 ec.set (ping, "Remote", "10.0.0.2")
123 ec.set (ping, "Interval", "1s")
124 ec.set (ping, "Verbose", True)
125 ec.set (ping, "StartTime", "0s")
126 ec.set (ping, "StopTime", "20s")
127 ec.register_connection(ping, nsnode1)
131 ec.wait_finished([ping])
133 stdout = ec.trace(simu, "stdout")
137 print("PING OUTPUT", stdout)