Addibg examples/linux/dce/custom_dce_ping.py
[nepi.git] / examples / linux / dce / custom_dce_ping.py
1 #!/usr/bin/env python
2 #
3 #    NEPI, a framework to manage network experiments
4 #    Copyright (C) 2013 INRIA
5 #
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.
10 #
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.
15 #
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/>.
18 #
19 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
20
21 from nepi.execution.ec import ExperimentController 
22
23 def add_ns3_node(ec, simu):
24     node = ec.register_resource("ns3::Node")
25     ec.register_connection(node, simu)
26
27     ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
28     ec.register_connection(node, ipv4)
29
30     arp = ec.register_resource("ns3::ArpL3Protocol")
31     ec.register_connection(node, arp)
32     
33     icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
34     ec.register_connection(node, icmp)
35
36     udp = ec.register_resource("ns3::UdpL4Protocol")
37     ec.register_connection(node, udp)
38
39     tcp = ec.register_resource("ns3::TcpL4Protocol")
40     ec.register_connection(node, tcp)
41
42     return node
43
44
45 def add_point2point_device(ec, node, ip,  prefix):
46     dev = ec.register_resource("ns3::PointToPointNetDevice")
47     ec.set(dev, "ip", ip)
48     ec.set(dev, "prefix", prefix)
49     ec.register_connection(node, dev)
50
51     queue = ec.register_resource("ns3::DropTailQueue")
52     ec.register_connection(dev, queue)
53
54     return dev
55
56 ec = ExperimentController(exp_id = "dce-custom-ping")
57
58 node = ec.register_resource("LinuxNode")
59 ec.set(node, "hostname", "localhost")
60 ec.set(node, "cleanProcesses", True)
61 #ec.set(node, "cleanHome", True)
62
63 simu = ec.register_resource("LinuxNS3Simulation")
64 ec.set(simu, "verbose", True)
65 ec.set(simu, "nsLog", "DceApplication")
66 ec.set(simu, "enableDump", True)
67 ec.register_connection(simu, node)
68
69 nsnode1 = add_ns3_node(ec, simu)
70 p2p1 = add_point2point_device(ec, nsnode1, "10.0.0.1", "30")
71 ec.set(p2p1, "DataRate", "5Mbps")
72
73 nsnode2 = add_ns3_node(ec, simu)
74 p2p2 = add_point2point_device(ec, nsnode2, "10.0.0.2", "30")
75 ec.set(p2p2, "DataRate", "5Mbps")
76
77 # Create channel
78 chan = ec.register_resource("ns3::PointToPointChannel")
79 ec.set(chan, "Delay", "2ms")
80
81 ec.register_connection(chan, p2p1)
82 ec.register_connection(chan, p2p2)
83
84 ### create applications
85 ping = ec.register_resource("ns3::LinuxDceApplication")
86 ec.set (ping, "sources", "http://www.skbuff.net/iputils/iputils-s20101006.tar.bz2")
87 ec.set (ping, "build", "tar xvjf ${SRC}/iputils-s20101006.tar.bz2 && "
88         "cd iputils-s20101006/ && "
89         "sed -i 's/CFLAGS=/CFLAGS+=/g' Makefile && "
90         "make CFLAGS=-fPIC LDFLAGS='-pie -rdynamic' ping && "
91         "cp ping ${BIN_DCE} && cd - ")
92 ec.set (ping, "binary", "ping")
93 ec.set (ping, "stackSize", 1<<20)
94 ec.set (ping, "arguments", "-c 10;-s 1000;10.0.0.2")
95 ec.set (ping, "StartTime", "1s")
96 ec.set (ping, "StopTime", "20s")
97 ec.register_connection(ping, nsnode1)
98
99 ec.deploy()
100
101 ec.wait_finished([ping])
102
103 stdout = ec.trace(ping, "stdout") 
104
105 ec.shutdown()
106
107 print "PING OUTPUT", stdout