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 def add_ns3_node(ec, simu):
24 node = ec.register_resource("ns3::Node")
25 ec.register_connection(node, simu)
27 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
28 ec.register_connection(node, ipv4)
30 arp = ec.register_resource("ns3::ArpL3Protocol")
31 ec.register_connection(node, arp)
33 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
34 ec.register_connection(node, icmp)
36 udp = ec.register_resource("ns3::UdpL4Protocol")
37 ec.register_connection(node, udp)
39 tcp = ec.register_resource("ns3::TcpL4Protocol")
40 ec.register_connection(node, tcp)
44 def add_device(ec, node, ip, prefix, access_point = False):
45 dev = ec.register_resource("ns3::WifiNetDevice")
47 ec.set(dev, "prefix", prefix)
48 ec.register_connection(node, dev)
50 phy = ec.register_resource("ns3::YansWifiPhy")
51 ec.set(phy, "Standard", "WIFI_PHY_STANDARD_80211a")
52 ec.register_connection(dev, phy)
54 error = ec.register_resource("ns3::NistErrorRateModel")
55 ec.register_connection(phy, error)
57 manager = ec.register_resource("ns3::ArfWifiManager")
58 ec.register_connection(dev, manager)
61 mac = ec.register_resource("ns3::ApWifiMac")
63 mac = ec.register_resource("ns3::StaWifiMac")
65 ec.set(mac, "Standard", "WIFI_PHY_STANDARD_80211a")
66 ec.register_connection(dev, mac)
70 def add_constant_mobility(ec, node, x, y, z):
71 mobility = ec.register_resource("ns3::ConstantPositionMobilityModel")
72 position = "%d:%d:%d" % (x, y, z)
73 ec.set(mobility, "Position", position)
74 ec.register_connection(node, mobility)
77 def add_wifi_channel(ec):
78 channel = ec.register_resource("ns3::YansWifiChannel")
79 delay = ec.register_resource("ns3::ConstantSpeedPropagationDelayModel")
80 ec.register_connection(channel, delay)
82 loss = ec.register_resource("ns3::LogDistancePropagationLossModel")
83 ec.register_connection(channel, loss)
87 ec = ExperimentController(exp_id = "dce-custom-wifi-ping")
89 node = ec.register_resource("LinuxNode")
90 ec.set(node, "hostname", "localhost")
91 ec.set(node, "cleanProcesses", True)
93 simu = ec.register_resource("LinuxNS3Simulation")
94 ec.set(simu, "verbose", True)
95 ec.register_connection(simu, node)
97 nsnode1 = add_ns3_node(ec, simu)
98 add_constant_mobility(ec, nsnode1, 0, 0, 0)
99 dev1, phy1 = add_device(ec, nsnode1, "10.0.0.1", "30")
101 nsnode2 = add_ns3_node(ec, simu)
102 add_constant_mobility(ec, nsnode2, 50, 50, 0)
103 dev2, phy2 = add_device(ec, nsnode2, "10.0.0.2", "30", access_point = True)
106 chan = add_wifi_channel(ec)
107 ec.register_connection(chan, phy1)
108 ec.register_connection(chan, phy2)
110 ### create applications
111 ping = ec.register_resource("ns3::LinuxDceApplication")
112 ec.set (ping, "sources", "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2")
113 ec.set (ping, "build", "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && "
114 "cd iputils-s20101006/ && "
115 "sed -i 's/CFLAGS=/CFLAGS+=/g' Makefile && "
116 "make CFLAGS=-fPIC LDFLAGS='-pie -rdynamic' ping && "
117 "cp ping ${BIN_DCE} && cd - ")
118 ec.set (ping, "binary", "ping")
119 ec.set (ping, "stackSize", 1<<20)
120 ec.set (ping, "arguments", "-c 10;-s 1000;10.0.0.2")
121 ec.set (ping, "StartTime", "1s")
122 ec.set (ping, "StopTime", "20s")
123 ec.register_connection(ping, nsnode1)
127 ec.wait_finished([ping])
129 stdout = ec.trace(ping, "stdout")
133 print "PING OUTPUT", stdout