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 as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
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.
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/>.
19 # Author: Julien Tribino <julien.tribino@inria.fr>
22 from nepi.execution.resource import ResourceFactory, ResourceManager, ResourceAction, ResourceState
23 from nepi.execution.ec import ExperimentController
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
31 from nepi.util.timefuncs import *
37 class OMFPingNormalCase(unittest.TestCase):
38 def test_deploy(self):
39 ec = ExperimentController(exp_id = "5421" )
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")
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")
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")
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")
66 ec.register_connection(self.app1, self.node1)
67 ec.register_connection(self.node1, self.iface1)
68 ec.register_connection(self.iface1, self.channel)
70 ec.register_condition(self.app1, ResourceAction.STOP, self.app1, ResourceState.STARTED , "10s")
74 ec.wait_finished(self.app1)
76 stdout_1 = ec.trace(self.app1, "stdout")
77 stderr_1 = ec.trace(self.app1, "stderr")
80 f = open("app1_out.txt", "w")
85 f = open("app1_err.txt", "w")
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)
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)
101 t = open("app1_out.txt", "r")
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])
108 os.remove("app1_out.txt")
112 if __name__ == '__main__':