Fixing static lock messup with Ns3 DCE Manager
[nepi.git] / test / resources / omf / omf6_vlc_traces.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: Julien Tribino <julien.tribino@inria.fr>
20
21
22 from nepi.execution.resource import ResourceFactory, ResourceManager, ResourceAction, ResourceState
23 from nepi.execution.ec import ExperimentController
24
25 from nepi.resources.omf.node import OMFNode
26 from nepi.resources.omf.application import OMFApplication
27 from nepi.resources.omf.interface import OMFWifiInterface
28 from nepi.resources.omf.channel import OMFChannel
29 from nepi.resources.omf.omf_api_factory import OMFAPIFactory
30
31 from nepi.util.timefuncs import *
32
33 import os
34 import time
35 import unittest
36
37 class OMFPingNormalCase(unittest.TestCase):
38     def test_deploy(self):
39         ec = ExperimentController(exp_id = "5421" )
40
41         self.node1 = ec.register_resource("omf::Node")
42         ec.set(self.node1, 'hostname', 'wlab12')
43         ec.set(self.node1, 'xmppUser', "nepi")
44         ec.set(self.node1, 'xmppServer', "xmpp-plexus.onelab.eu")
45         ec.set(self.node1, 'xmppPort', "5222")
46         ec.set(self.node1, 'xmppPassword', "1234")
47         
48         self.iface1 = ec.register_resource("omf::WifiInterface")
49         ec.set(self.iface1, 'name', "wlan0")
50         ec.set(self.iface1, 'mode', "adhoc")
51         ec.set(self.iface1, 'hw_mode', "g")
52         ec.set(self.iface1, 'essid', "vlcexp")
53         ec.set(self.iface1, 'ip', "10.0.0.17/24")
54         
55         self.channel = ec.register_resource("omf::Channel")
56         ec.set(self.channel, 'channel', "6")
57         ec.set(self.channel, 'xmppUser', "nepi")
58         ec.set(self.channel, 'xmppServer', "xmpp-plexus.onelab.eu")
59         ec.set(self.channel, 'xmppPort', "5222")
60         ec.set(self.channel, 'xmppPassword', "1234")
61         
62         self.app1 = ec.register_resource("omf::Application")
63         ec.set(self.app1, 'appid', 'Vlc#1')
64         ec.set(self.app1, 'command', "ping -c5 10.0.0.17")
65
66         ec.register_connection(self.app1, self.node1)
67         ec.register_connection(self.node1, self.iface1)
68         ec.register_connection(self.iface1, self.channel)
69
70         ec.register_condition(self.app1, ResourceAction.STOP, self.app1, ResourceState.STARTED , "10s")
71
72         ec.deploy()
73
74         ec.wait_finished(self.app1)
75
76         stdout_1 = ec.trace(self.app1, "stdout")
77         stderr_1 = ec.trace(self.app1, "stderr")
78
79         if stdout_1:
80             f = open("app1_out.txt", "w")
81             f.write(stdout_1)
82             f.close()
83
84         if stderr_1:
85             f = open("app1_err.txt", "w")
86             f.write(stderr_1)
87             f.close()
88
89         self.assertEquals(ec.get_resource(self.node1).state, ResourceState.STARTED)
90         self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.STARTED)
91         self.assertEquals(ec.get_resource(self.channel).state, ResourceState.STARTED)
92         self.assertEquals(ec.get_resource(self.app1).state, ResourceState.STOPPED)
93
94         ec.shutdown()
95
96         self.assertEquals(ec.get_resource(self.node1).state, ResourceState.RELEASED)
97         self.assertEquals(ec.get_resource(self.iface1).state, ResourceState.RELEASED)
98         self.assertEquals(ec.get_resource(self.channel).state, ResourceState.RELEASED)
99         self.assertEquals(ec.get_resource(self.app1).state, ResourceState.RELEASED)
100
101         t = open("app1_out.txt", "r")
102         l = t.readlines()
103         self.assertEquals(l[0], "PING 10.0.0.17 (10.0.0.17) 56(84) bytes of data.\n")
104         self.assertIn("5 packets transmitted, 5 received, 0% packet loss, time", l[-2])
105         self.assertIn("rtt min/avg/max/mdev = ", l[-1])
106         
107         t.close()
108         os.remove("app1_out.txt")
109         
110
111
112 if __name__ == '__main__':
113     unittest.main()
114
115
116