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