Tutorial/HowToApplication: tut_app_1.rb

File tut_app_1.rb, 2.7 KB (added by thierry, 16 years ago)
Line 
1#
2# This is a script example, which shows how to run an application on a set of nodes
3#
4# The scenario of this experiment involves one set of nodes: 'worker'. We will execute
5# the appliation command 'tcpdump -A -i ath0 -w /tmp/dump.txt' on all the nodes within
6# that set. The output of this command for each node will be stored into a text file on
7# node itself.
8# Note: to retrieve these outputs, you will need to either use the OML Collection
9# Framework (see other tutorials), or directly copy the required text file from the
10# corresponding node.
11#
12# In this example we:
13# 1) Define a new Application, which will be a wrapper around the tcpdump application
14# 2) Define a set of nodes which contains 1 node: [1,1] that will run the application
15# 3) Run the application
16#
17
18# 1)
19# Define a new application
20# The following declaration defines a new application which as a URI 'tcpdumpWrapper'
21# and the name 'dumpApp'
22#
23# To use this Application definition in multiple experiment scripts, place it
24# into a separate stand-alone file with the name 'tcpdumpWrapper.rb' in the same
25# directory as the experiment scripts that would use it. These experiment scripts
26# will then NOT require this step 1) declaration.
27#
28# NOTE: tcpdump output its user message on STDERR and not STDOUT, thus when
29# running this tutorial script, please ignore false error messages such as:
30# "ERROR NodeApp: tcpdump: listening on ath0, link-type EN10MB (Ethernet), capture size 96 bytes"
31#
32defApplication('tcpdumpWrapper', 'dumpApp') {|app|
33 app.shortDescription = "This is a simple wrapper application around tcpdump"
34 app.path="/usr/sbin/tcpdump -A -i ath0 -w /tmp/dump.txt"
35}
36
37# 2)
38# Define a set of node that would use the above application
39#
40defGroup('worker', [1,1]) {|node|
41
42 # Configure the wireless interface on the node(s) in this set
43 node.net.w0.mode = "Master"
44 node.net.w0.type = "g"
45 node.net.w0.essid = "tutorial"
46 node.net.w0.ip = "192.168.0.1"
47
48 # Add the 'tcpdumpWrapper' application to the node(s) in this set
49 node.addApplication('tcpdumpWrapper', 'dumpApp', nil, nil)
50
51 # Note: the signature of addApplication() is
52 #
53 # addApplication(app, vName, bindings, env)
54 #
55 # 'app' - The application URI or instance
56 # 'vName' - Virtual name given to this app
57 # 'paramBindings' - Parameter bindings for this application
58 # 'env' - Environment to set before starting application
59}
60
61# 3)
62# When all the nodes are UP, execute the application on them
63#
64whenAllUp() {|node|
65
66 # Wait 10 sec to make sure that the wireless interfaces are all
67 # configured
68 wait 10
69
70 # Start all the applications
71 allGroups.startApplications
72
73 # Wait 10 sec that will be the application duration time
74 wait 10
75
76 # Stop the experiment
77 Experiment.done
78}