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 ec = ExperimentController(exp_id = "ns3-local-wifi-ping")
25 # Simulation will executed in the local machine
26 node = ec.register_resource("linux::Node")
27 ec.set(node, "hostname", "localhost")
29 # Add a simulation resource
30 simu = ec.register_resource("linux::ns3::Simulation")
31 ec.set(simu, "verbose", True)
32 ec.register_connection(simu, node)
34 ## Add a ns-3 node with its protocol stack
35 nsnode1 = ec.register_resource("ns3::Node")
36 ec.register_connection(nsnode1, simu)
38 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
39 ec.register_connection(nsnode1, ipv4)
40 arp = ec.register_resource("ns3::ArpL3Protocol")
41 ec.register_connection(nsnode1, arp)
42 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
43 ec.register_connection(nsnode1, icmp)
45 # Adding constant mobility to the ns-3 node
46 mobility1 = ec.register_resource("ns3::ConstantPositionMobilityModel")
47 position1 = "%d:%d:%d" % (0, 0, 0)
48 ec.set(mobility1, "Position", position1)
49 ec.register_connection(nsnode1, mobility1)
51 # Add a wifi access point net device to the node
52 dev1 = ec.register_resource("ns3::WifiNetDevice")
53 ec.set(dev1, "ip", "10.0.0.1")
54 ec.set(dev1, "prefix", "30")
55 ec.register_connection(nsnode1, dev1)
57 phy1 = ec.register_resource("ns3::YansWifiPhy")
58 ec.set(phy1, "Standard", "WIFI_PHY_STANDARD_80211a")
59 ec.register_connection(dev1, phy1)
61 error1 = ec.register_resource("ns3::NistErrorRateModel")
62 ec.register_connection(phy1, error1)
64 manager1 = ec.register_resource("ns3::ArfWifiManager")
65 ec.register_connection(dev1, manager1)
67 # Mark the node as a wireless access point
68 mac1 = ec.register_resource("ns3::ApWifiMac")
69 ec.set(mac1, "Standard", "WIFI_PHY_STANDARD_80211a")
70 ec.register_connection(dev1, mac1)
72 ## Add another ns-3 node with its protocol stack
73 nsnode2 = ec.register_resource("ns3::Node")
74 ec.register_connection(nsnode2, simu)
76 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
77 ec.register_connection(nsnode2, ipv4)
78 arp = ec.register_resource("ns3::ArpL3Protocol")
79 ec.register_connection(nsnode2, arp)
80 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
81 ec.register_connection(nsnode2, icmp)
83 # Adding constant mobility to the ns-3 node
84 mobility2 = ec.register_resource("ns3::ConstantPositionMobilityModel")
85 position2 = "%d:%d:%d" % (50, 50, 0)
86 ec.set(mobility2, "Position", position2)
87 ec.register_connection(nsnode2, mobility2)
89 # Add a wifi station net device to the node
90 dev2 = ec.register_resource("ns3::WifiNetDevice")
91 ec.set(dev2, "ip", "10.0.0.2")
92 ec.set(dev2, "prefix", "30")
93 ec.register_connection(nsnode2, dev2)
95 phy2 = ec.register_resource("ns3::YansWifiPhy")
96 ec.set(phy2, "Standard", "WIFI_PHY_STANDARD_80211a")
97 ec.register_connection(dev2, phy2)
99 error2 = ec.register_resource("ns3::NistErrorRateModel")
100 ec.register_connection(phy2, error2)
102 manager2 = ec.register_resource("ns3::ArfWifiManager")
103 ec.register_connection(dev2, manager2)
105 # Mark the node as a wireless station
106 mac2 = ec.register_resource("ns3::StaWifiMac")
107 ec.set(mac2, "Standard", "WIFI_PHY_STANDARD_80211a")
108 ec.register_connection(dev2, mac2)
111 chan = ec.register_resource("ns3::YansWifiChannel")
112 delay = ec.register_resource("ns3::ConstantSpeedPropagationDelayModel")
113 ec.register_connection(chan, delay)
114 loss = ec.register_resource("ns3::LogDistancePropagationLossModel")
115 ec.register_connection(chan, loss)
116 ec.register_connection(chan, phy1)
117 ec.register_connection(chan, phy2)
120 ping = ec.register_resource("ns3::V4Ping")
121 ec.set (ping, "Remote", "10.0.0.2")
122 ec.set (ping, "Interval", "1s")
123 ec.set (ping, "Verbose", True)
124 ec.set (ping, "StartTime", "0s")
125 ec.set (ping, "StopTime", "20s")
126 ec.register_connection(ping, nsnode1)
130 ec.wait_finished([ping])
132 stdout = ec.trace(simu, "stdout")
136 print "PING OUTPUT", stdout