a8119cd9845f2cf921e558650cec25d3415817fc
[nepi.git] / examples / dce / wrapped_local_p2p_ccnpeek.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 version 2 as
8 #    published by the Free Software Foundation;
9 #
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.
14 #
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/>.
17 #
18 # Author: Alina Quereilhac <alina.quereilhac@inria.fr>
19
20 from nepi.execution.ec import ExperimentController 
21
22 def add_ns3_node(ec, simu):
23     node = ec.register_resource("ns3::Node")
24     ec.register_connection(node, simu)
25
26     ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
27     ec.register_connection(node, ipv4)
28
29     arp = ec.register_resource("ns3::ArpL3Protocol")
30     ec.register_connection(node, arp)
31     
32     icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
33     ec.register_connection(node, icmp)
34
35     udp = ec.register_resource("ns3::UdpL4Protocol")
36     ec.register_connection(node, udp)
37
38     tcp = ec.register_resource("ns3::TcpL4Protocol")
39     ec.register_connection(node, tcp)
40
41     return node
42
43 ec = ExperimentController(exp_id = "dce-local-ccnpeek")
44
45 node = ec.register_resource("linux::Node")
46 ec.set(node, "hostname", "localhost")
47 ec.set(node, "cleanProcesses", True)
48
49 simu = ec.register_resource("linux::ns3::Simulation")
50 ec.register_connection(simu, node)
51
52 nsnode = add_ns3_node(ec, simu)
53
54 ### create applications
55 ccnd = ec.register_resource("linux::ns3::dce::CCND")
56 ec.set (ccnd, "stackSize", 1<<20)
57 ec.set (ccnd, "StartTime", "1s")
58 ec.register_connection(ccnd, nsnode)
59
60 ccnpoke = ec.register_resource("linux::ns3::dce::CCNPoke")
61 ec.set (ccnpoke, "contentName", "ccnx:/chunk0")
62 ec.set (ccnpoke, "content", "DATA")
63 ec.set (ccnpoke, "stackSize", 1<<20)
64 ec.set (ccnpoke, "StartTime", "2s")
65 ec.register_connection(ccnpoke, nsnode)
66
67 ccnpeek = ec.register_resource("linux::ns3::dce::CCNPeek")
68 ec.set (ccnpeek, "contentName", "ccnx:/chunk0")
69 ec.set (ccnpeek, "stackSize", 1<<20)
70 ec.set (ccnpeek, "StartTime", "4s")
71 ec.set (ccnpeek, "StopTime", "20s")
72 ec.register_connection(ccnpeek, nsnode)
73
74 ec.deploy()
75
76 ec.wait_finished([ccnpeek])
77
78 stdout = ec.trace(ccnpeek, "stdout")
79
80 ec.shutdown()
81
82 print "PEEK received", stdout
83