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 def add_ns3_node(ec, simu):
25 node = ec.register_resource("ns3::Node")
26 ec.register_connection(node, simu)
28 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
29 ec.register_connection(node, ipv4)
31 arp = ec.register_resource("ns3::ArpL3Protocol")
32 ec.register_connection(node, arp)
34 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
35 ec.register_connection(node, icmp)
37 udp = ec.register_resource("ns3::UdpL4Protocol")
38 ec.register_connection(node, udp)
40 tcp = ec.register_resource("ns3::TcpL4Protocol")
41 ec.register_connection(node, tcp)
45 def add_device(ec, node, ip, prefix):
46 dev = ec.register_resource("ns3::PointToPointNetDevice")
48 ec.set(dev, "prefix", prefix)
49 ec.register_connection(node, dev)
51 queue = ec.register_resource("ns3::DropTailQueue")
52 ec.register_connection(dev, queue)
56 ec = ExperimentController(exp_id = "dce-custom-dlm-ping")
58 node = ec.register_resource("linux::Node")
59 ec.set(node, "hostname", "localhost")
60 ec.set(node, "cleanProcesses", True)
62 simu = ec.register_resource("linux::ns3:Simulation")
63 ec.set(simu, "verbose", True)
64 #ec.set(simu, "enableDump", True)
65 ec.register_connection(simu, node)
67 nsnode1 = add_ns3_node(ec, simu)
68 dev1 = add_device(ec, nsnode1, "10.0.0.1", "30")
69 ec.set(dev1, "DataRate", "5Mbps")
71 nsnode2 = add_ns3_node(ec, simu)
72 dev2 = add_device(ec, nsnode2, "10.0.0.2", "30")
73 ec.set(dev2, "DataRate", "5Mbps")
76 chan = ec.register_resource("ns3::PointToPointChannel")
77 ec.set(chan, "Delay", "2ms")
79 ec.register_connection(chan, dev1)
80 ec.register_connection(chan, dev2)
82 ### create applications
83 ping = ec.register_resource("linux::ns3::dce::Application")
84 ec.set (ping, "sources", "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2")
85 ec.set (ping, "build", "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && "
86 "cd iputils-s20101006/ && "
87 "sed -i 's/CFLAGS=/CFLAGS+=/g' Makefile && "
88 "make CFLAGS=-fPIC LDFLAGS='-pie -rdynamic' ping && "
89 "cp ping ${BIN_DCE} && cd - ")
90 ec.set (ping, "binary", "ping")
91 ec.set (ping, "stackSize", 1<<20)
92 ec.set (ping, "arguments", "-c 10;-s 1000;10.0.0.2")
93 #ec.set (ping, "useDlmLoader", True)
94 ec.set (ping, "StartTime", "1s")
95 ec.set (ping, "StopTime", "20s")
96 ec.register_connection(ping, nsnode1)
100 ec.wait_finished([ping])
102 stdout = ec.trace(ping, "stdout")
106 print("PING OUTPUT", stdout)