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 nepi.execution.ec import ExperimentController
22 def add_ns3_node(ec, simu):
23 node = ec.register_resource("ns3::Node")
24 ec.register_connection(node, simu)
26 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
27 ec.register_connection(node, ipv4)
29 arp = ec.register_resource("ns3::ArpL3Protocol")
30 ec.register_connection(node, arp)
32 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
33 ec.register_connection(node, icmp)
35 udp = ec.register_resource("ns3::UdpL4Protocol")
36 ec.register_connection(node, udp)
38 tcp = ec.register_resource("ns3::TcpL4Protocol")
39 ec.register_connection(node, tcp)
43 def add_device(ec, node, ip, prefix):
44 dev = ec.register_resource("ns3::CsmaNetDevice")
46 ec.set(dev, "prefix", prefix)
47 ec.register_connection(node, dev)
49 queue = ec.register_resource("ns3::DropTailQueue")
50 ec.register_connection(dev, queue)
54 ec = ExperimentController(exp_id = "dce-custom-csma-ping")
56 node = ec.register_resource("linux::Node")
57 ec.set(node, "hostname", "localhost")
58 ec.set(node, "cleanProcesses", True)
60 simu = ec.register_resource("linux::ns3::Simulation")
61 ec.set(simu, "verbose", True)
62 ec.register_connection(simu, node)
64 nsnode1 = add_ns3_node(ec, simu)
65 dev1 = add_device(ec, nsnode1, "10.0.0.1", "30")
67 nsnode2 = add_ns3_node(ec, simu)
68 dev2 = add_device(ec, nsnode2, "10.0.0.2", "30")
71 chan = ec.register_resource("ns3::CsmaChannel")
72 ec.set(chan, "Delay", "2ms")
74 ec.register_connection(chan, dev1)
75 ec.register_connection(chan, dev2)
77 ### create applications
78 ping = ec.register_resource("linux::ns3::dce::Application")
79 ec.set (ping, "sources", "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2")
80 ec.set (ping, "build", "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && "
81 "cd iputils-s20101006/ && "
82 "sed -i 's/CFLAGS=/CFLAGS+=/g' Makefile && "
83 "make CFLAGS=-fPIC LDFLAGS='-pie -rdynamic' ping && "
84 "cp ping ${BIN_DCE} && cd - ")
85 ec.set (ping, "binary", "ping")
86 ec.set (ping, "stackSize", 1<<20)
87 ec.set (ping, "arguments", "-c 10;-s 1000;10.0.0.2")
88 ec.set (ping, "StartTime", "1s")
89 ec.set (ping, "StopTime", "20s")
90 ec.register_connection(ping, nsnode1)
94 ec.wait_finished([ping])
96 stdout = ec.trace(ping, "stdout")
100 print "PING OUTPUT", stdout