use print() - import print_function - should be fine for both py2 and py3
[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 __future__ import print_function
21
22 from nepi.execution.ec import ExperimentController 
23
24 def add_ns3_node(ec, simu):
25     node = ec.register_resource("ns3::Node")
26     ec.register_connection(node, simu)
27
28     ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
29     ec.register_connection(node, ipv4)
30
31     arp = ec.register_resource("ns3::ArpL3Protocol")
32     ec.register_connection(node, arp)
33     
34     icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
35     ec.register_connection(node, icmp)
36
37     udp = ec.register_resource("ns3::UdpL4Protocol")
38     ec.register_connection(node, udp)
39
40     tcp = ec.register_resource("ns3::TcpL4Protocol")
41     ec.register_connection(node, tcp)
42
43     return node
44
45 ec = ExperimentController(exp_id = "dce-local-ccnpeek")
46
47 node = ec.register_resource("linux::Node")
48 ec.set(node, "hostname", "localhost")
49 ec.set(node, "cleanProcesses", True)
50
51 simu = ec.register_resource("linux::ns3::Simulation")
52 ec.register_connection(simu, node)
53
54 nsnode = add_ns3_node(ec, simu)
55
56 ### create applications
57 ccnd = ec.register_resource("linux::ns3::dce::CCND")
58 ec.set (ccnd, "stackSize", 1<<20)
59 ec.set (ccnd, "StartTime", "1s")
60 ec.register_connection(ccnd, nsnode)
61
62 ccnpoke = ec.register_resource("linux::ns3::dce::CCNPoke")
63 ec.set (ccnpoke, "contentName", "ccnx:/chunk0")
64 ec.set (ccnpoke, "content", "DATA")
65 ec.set (ccnpoke, "stackSize", 1<<20)
66 ec.set (ccnpoke, "StartTime", "2s")
67 ec.register_connection(ccnpoke, nsnode)
68
69 ccnpeek = ec.register_resource("linux::ns3::dce::CCNPeek")
70 ec.set (ccnpeek, "contentName", "ccnx:/chunk0")
71 ec.set (ccnpeek, "stackSize", 1<<20)
72 ec.set (ccnpeek, "StartTime", "4s")
73 ec.set (ccnpeek, "StopTime", "20s")
74 ec.register_connection(ccnpeek, nsnode)
75
76 ec.deploy()
77
78 ec.wait_finished([ccnpeek])
79
80 stdout = ec.trace(ccnpeek, "stdout")
81
82 ec.shutdown()
83
84 print("PEEK received", stdout)
85