57df1744597a5da39e6ef9765a5d22ae33b8de37
[nepi.git] / test / resources / linux / ns3 / ccn / ns3dceccnpeek.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
21 from nepi.execution.ec import ExperimentController 
22
23 from test_utils import skipIfNotAlive
24
25 import os
26 import time
27 import unittest
28
29 def add_ns3_node(ec, simu):
30     node = ec.register_resource("ns3::Node")
31     ec.register_connection(node, simu)
32
33     ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
34     ec.register_connection(node, ipv4)
35     
36     arp = ec.register_resource("ns3::ArpL3Protocol")
37     ec.register_connection(node, arp)
38     
39     icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
40     ec.register_connection(node, icmp)
41
42     udp = ec.register_resource("ns3::UdpL4Protocol")
43     ec.register_connection(node, udp)
44
45     tcp = ec.register_resource("ns3::TcpL4Protocol")
46     ec.register_connection(node, tcp)
47
48     return node
49
50 class LinuxNS3CCNPeekDceApplicationTest(unittest.TestCase):
51     def setUp(self):
52         self.fedora_host = "nepi2.pl.sophia.inria.fr"
53         self.fedora_user = "inria_nepi"
54         self.fedora_identity = "%s/.ssh/id_rsa_planetlab" % (os.environ['HOME'])
55
56     @skipIfNotAlive
57     def t_dce_ccnpeek(self, host, user = None, identity = None):
58         ec = ExperimentController(exp_id = "test-dce-ccnpeek")
59
60         node = ec.register_resource("linux::Node")
61         if host == "localhost":
62             ec.set(node, "hostname", host)
63         else:
64             ec.set(node, "hostname", host)
65             ec.set(node, "username", user)
66             ec.set(node, "identity", identity)
67         
68         ec.set(node, "cleanProcesses", True)
69         #ec.set(node, "cleanHome", True)
70
71         simu = ec.register_resource("linux::ns3::Simulation")
72         ec.set(simu, "verbose", True)
73         ec.set(simu, "nsLog", "DceApplication")
74         ec.register_connection(simu, node)
75
76         nsnode = add_ns3_node(ec, simu)
77
78         ### create applications
79         ccnd = ec.register_resource("linux::ns3::dce::CCND")
80         ec.set (ccnd, "stackSize", 1<<20)
81         ec.set (ccnd, "StartTime", "1s")
82         ec.register_connection(ccnd, nsnode)
83
84         ccnpoke = ec.register_resource("linux::ns3::dce::CCNPoke")
85         ec.set (ccnpoke, "contentName", "ccnx:/chunk0")
86         ec.set (ccnpoke, "content", "DATA")
87         ec.set (ccnpoke, "stackSize", 1<<20)
88         ec.set (ccnpoke, "StartTime", "2s")
89         ec.register_connection(ccnpoke, nsnode)
90
91         ccnpeek = ec.register_resource("linux::ns3::dce::CCNPeek")
92         ec.set (ccnpeek, "contentName", "ccnx:/chunk0")
93         ec.set (ccnpeek, "stackSize", 1<<20)
94         ec.set (ccnpeek, "StartTime", "4s")
95         ec.set (ccnpeek, "StopTime", "20s")
96         ec.register_connection(ccnpeek, nsnode)
97
98         ec.deploy()
99
100         ec.wait_finished([ccnpeek])
101
102         expected = "ccnpeek ccnx:/chunk0"
103         cmdline = ec.trace(ccnpeek, "cmdline")
104         self.assertTrue(cmdline.find(expected) > -1, cmdline)
105
106         expected = "Start Time: NS3 Time:          4s ("
107         status = ec.trace(ccnpeek, "status")
108         self.assertTrue(status.find(expected) > -1, status)
109
110         expected = "DATA"
111         stdout = ec.trace(ccnpeek, "stdout")
112         self.assertTrue(stdout.find(expected) > -1, stdout)
113
114         ec.shutdown()
115
116     @skipIfNotAlive
117     def t_dce_ccnpeek_with_stack(self, host, user = None, identity = None):
118         ec = ExperimentController(exp_id = "test-dce-peek-lostack")
119         
120         node = ec.register_resource("linux::Node")
121         if host == "localhost":
122             ec.set(node, "hostname", host)
123         else:
124             ec.set(node, "hostname", host)
125             ec.set(node, "username", user)
126             ec.set(node, "identity", identity)
127         
128         ec.set(node, "cleanProcesses", True)
129         #ec.set(node, "cleanHome", True)
130
131         simu = ec.register_resource("linux::ns3::Simulation")
132         ec.set(simu, "verbose", True)
133         ec.register_connection(simu, node)
134
135         nsnode = ec.register_resource("ns3::Node")
136         ec.set(nsnode, "enableStack", True)
137         ec.register_connection(nsnode, simu)
138
139         ### create applications
140         ccnd = ec.register_resource("linux::ns3::dce::CCND")
141         ec.set (ccnd, "stackSize", 1<<20)
142         ec.set (ccnd, "StartTime", "1s")
143         ec.register_connection(ccnd, nsnode)
144
145         ccnpoke = ec.register_resource("linux::ns3::dce::CCNPoke")
146         ec.set (ccnpoke, "contentName", "ccnx:/chunk0")
147         ec.set (ccnpoke, "content", "DATA")
148         ec.set (ccnpoke, "stackSize", 1<<20)
149         ec.set (ccnpoke, "StartTime", "2s")
150         ec.register_connection(ccnpoke, nsnode)
151
152         ccnpeek = ec.register_resource("linux::ns3::dce::CCNPeek")
153         ec.set (ccnpeek, "contentName", "ccnx:/chunk0")
154         ec.set (ccnpeek, "stackSize", 1<<20)
155         ec.set (ccnpeek, "StartTime", "4s")
156         ec.set (ccnpeek, "StopTime", "20s")
157         ec.register_connection(ccnpeek, nsnode)
158
159         ec.deploy()
160
161         ec.wait_finished([ccnpeek])
162
163         expected = "ccnpeek ccnx:/chunk0"
164         cmdline = ec.trace(ccnpeek, "cmdline")
165         self.assertTrue(cmdline.find(expected) > -1, cmdline)
166
167         expected = "Start Time: NS3 Time:          4s ("
168         status = ec.trace(ccnpeek, "status")
169         self.assertTrue(status.find(expected) > -1, status)
170
171         expected = "DATA"
172         stdout = ec.trace(ccnpeek, "stdout")
173         self.assertTrue(stdout.find(expected) > -1, stdout)
174
175         ec.shutdown()
176
177     def test_dce_ccnpeek_fedora(self):
178         self.t_dce_ccnpeek(self.fedora_host, self.fedora_user, self.fedora_identity)
179
180     def test_dce_ccnpeek_local(self):
181         self.t_dce_ccnpeek("localhost")
182
183     def test_dce_ccnpeek_with_stack_fedora(self):
184         self.t_dce_ccnpeek_with_stack(self.fedora_host, 
185                 self.fedora_user, self.fedora_identity)
186
187     def test_dce_ccnpeek_with_stack_local(self):
188         self.t_dce_ccnpeek_with_stack("localhost")
189
190
191 if __name__ == '__main__':
192     unittest.main()