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>
21 from nepi.execution.ec import ExperimentController
23 from test_utils import skipIfNotAlive
29 def add_ns3_node(ec, simu):
30 node = ec.register_resource("ns3::Node")
31 ec.register_connection(node, simu)
33 ipv4 = ec.register_resource("ns3::Ipv4L3Protocol")
34 ec.register_connection(node, ipv4)
36 arp = ec.register_resource("ns3::ArpL3Protocol")
37 ec.register_connection(node, arp)
39 icmp = ec.register_resource("ns3::Icmpv4L4Protocol")
40 ec.register_connection(node, icmp)
42 udp = ec.register_resource("ns3::UdpL4Protocol")
43 ec.register_connection(node, udp)
45 tcp = ec.register_resource("ns3::TcpL4Protocol")
46 ec.register_connection(node, tcp)
50 class LinuxNS3CCNPeekDceApplicationTest(unittest.TestCase):
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'])
57 def t_dce_ccnpeek(self, host, user = None, identity = None):
58 ec = ExperimentController(exp_id = "test-dce-ccnpeek")
60 node = ec.register_resource("linux::Node")
61 if host == "localhost":
62 ec.set(node, "hostname", host)
64 ec.set(node, "hostname", host)
65 ec.set(node, "username", user)
66 ec.set(node, "identity", identity)
68 ec.set(node, "cleanProcesses", True)
69 #ec.set(node, "cleanHome", True)
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)
76 nsnode = add_ns3_node(ec, simu)
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)
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)
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)
100 ec.wait_finished([ccnpeek])
102 expected = "ccnpeek ccnx:/chunk0"
103 cmdline = ec.trace(ccnpeek, "cmdline")
104 self.assertTrue(cmdline.find(expected) > -1, cmdline)
106 expected = "Start Time: NS3 Time: 4s ("
107 status = ec.trace(ccnpeek, "status")
108 self.assertTrue(status.find(expected) > -1, status)
111 stdout = ec.trace(ccnpeek, "stdout")
112 self.assertTrue(stdout.find(expected) > -1, stdout)
117 def t_dce_ccnpeek_with_stack(self, host, user = None, identity = None):
118 ec = ExperimentController(exp_id = "test-dce-peek-lostack")
120 node = ec.register_resource("linux::Node")
121 if host == "localhost":
122 ec.set(node, "hostname", host)
124 ec.set(node, "hostname", host)
125 ec.set(node, "username", user)
126 ec.set(node, "identity", identity)
128 ec.set(node, "cleanProcesses", True)
129 #ec.set(node, "cleanHome", True)
131 simu = ec.register_resource("linux::ns3::Simulation")
132 ec.set(simu, "verbose", True)
133 ec.register_connection(simu, node)
135 nsnode = ec.register_resource("ns3::Node")
136 ec.set(nsnode, "enableStack", True)
137 ec.register_connection(nsnode, simu)
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)
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)
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)
161 ec.wait_finished([ccnpeek])
163 expected = "ccnpeek ccnx:/chunk0"
164 cmdline = ec.trace(ccnpeek, "cmdline")
165 self.assertTrue(cmdline.find(expected) > -1, cmdline)
167 expected = "Start Time: NS3 Time: 4s ("
168 status = ec.trace(ccnpeek, "status")
169 self.assertTrue(status.find(expected) > -1, status)
172 stdout = ec.trace(ccnpeek, "stdout")
173 self.assertTrue(stdout.find(expected) > -1, stdout)
177 def test_dce_ccnpeek_fedora(self):
178 self.t_dce_ccnpeek(self.fedora_host, self.fedora_user, self.fedora_identity)
180 def test_dce_ccnpeek_local(self):
181 self.t_dce_ccnpeek("localhost")
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)
187 def test_dce_ccnpeek_with_stack_local(self):
188 self.t_dce_ccnpeek_with_stack("localhost")
191 if __name__ == '__main__':