Fixing wrong license
[nepi.git] / examples / omf / testing / nepi_omf5_iminds_stdin.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: Julien Tribino <julien.tribino@inria.fr>
19
20 """
21
22     Example :
23       - Testbed : iMinds
24       - Explanation :
25
26        Test the STDIN Message
27                    
28      Node Zotack
29      node0.nepi-robot.nepi.wilab2.ilabt.iminds.be
30      0 
31      |
32      |
33      0
34      Application RobotCTRLComm.rb
35    
36       - Experiment:
37         - t0 : Deployment
38         - t1 : After the application started, send the message START_DRIVE
39         - t2 (t1 + 83s) : Open Left eye of robot 1
40         - t3 (t2 + 2s) : Open Left eye of robot 2
41
42 """
43
44 from nepi.execution.resource import ResourceFactory, ResourceAction, ResourceState
45 from nepi.execution.ec import ExperimentController
46
47 import time
48
49 # Create the EC
50 ec = ExperimentController()
51
52 # Create and Configure the Node
53 node1 = ec.register_resource("omf::Node")
54     # If the hostname is not declared, Nepi will take SFA to provision one.
55 ec.set(node1, 'hostname', 'node0.nepi-robot.nepi.wilab2.ilabt.iminds.be')
56     # XMPP credentials
57 ec.set(node1, 'xmppServer', "default_slice_iminds")
58 ec.set(node1, 'xmppUser', "am.wilab2.ilabt.iminds.be")
59 ec.set(node1, 'xmppPort', "5222")
60 ec.set(node1, 'xmppPassword', "1234")
61 ec.set(node1, 'version', "5")
62
63 # Create and Configure the Application
64 app1 = ec.register_resource("omf::RobotApplication")
65 ec.set(app1, 'appid', "robot")
66 ec.set(app1, 'version', "5")
67 ec.set(app1, 'command', "/users/jtribino/RobotCTRLComm.rb /users/jtribino/coordinate.csv") 
68                     # /users/username/RobotCTRLComm.rb /users/username/coordinate.csv
69 ec.set(app1, 'env', " ")
70 ec.set(app1, 'sources', "/home/wlab18/Desktop/coordinate.csv")  # local path
71 ec.set(app1, 'sshUser', "jtribino")  # username
72
73 # Connection
74 ec.register_connection(app1, node1)
75
76 # The Application should run during 350sec
77 ec.register_condition(app1, ResourceAction.STOP, app1, ResourceState.STARTED , "350s")
78
79 # Deploy
80 ec.deploy()
81
82 ec.wait_started([app1])
83
84 ec.set(app1, 'stdin', "START_DRIVE")
85
86 time.sleep(83)
87 ec.set(app1, 'stdin', "1;openlefteye")
88
89 time.sleep(2)
90 ec.set(app1, 'stdin', "2;openlefteye")
91
92 ec.wait_finished([app1])
93
94 # Stop Experiment
95 ec.shutdown()