Changing ResourceManager naming for platform::ResourceName
[nepi.git] / test / resources / linux / tcpdump.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 from test_utils import skipIfNotAlive, skipInteractive
23
24 import os
25 import time
26 import tempfile
27 import unittest
28
29 class LinuxTcpdumpTestCase(unittest.TestCase):
30     def setUp(self):
31         self.fedora_host = "nepi2.pl.sophia.inria.fr"
32         self.fedora_user = "inria_nepi"
33
34         self.ubuntu_host = "roseval.pl.sophia.inria.fr"
35         self.ubuntu_user = "alina"
36         
37         self.target = "nepi5.pl.sophia.inria.fr"
38
39     @skipIfNotAlive
40     def t_tofile(self, host, user):
41         ec = ExperimentController(exp_id = "test-to-file")
42         
43         node = ec.register_resource("linux::Node")
44         ec.set(node, "hostname", host)
45         ec.set(node, "username", user)
46         ec.set(node, "cleanExperiment", True)
47         ec.set(node, "cleanProcesses", True)
48
49         pcap = ec.register_resource("linux::Tcpdump")
50         ec.set(pcap, "i", "eth0")
51         ec.set(pcap, "w", "custom_output")
52         ec.register_connection(pcap, node)
53
54         app = ec.register_resource("linux::Ping")
55         ec.set(app, "count", "20")
56         ec.set(app, "target", self.target)
57         ec.register_connection(app, node)
58
59         ec.deploy()
60
61         ec.wait_finished(app)
62
63         output = ec.trace(pcap, "custom_output")
64         self.assertTrue(len(output) > 0)
65
66         ec.shutdown()
67
68     def test_tofile_fedora(self):
69         self.t_tofile(self.fedora_host, self.fedora_user)
70
71     def test_tofile_ubuntu(self):
72         self.t_tofile(self.ubuntu_host, self.ubuntu_user)
73
74 if __name__ == '__main__':
75     unittest.main()
76