Changes between Initial Version and Version 1 of Old/NodeHandler/Tutorial/HelloWorld


Ignore:
Timestamp:
Sep 29, 2005, 5:20:47 PM (19 years ago)
Author:
zhibinwu
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Old/NodeHandler/Tutorial/HelloWorld

    v1 v1  
     1[wiki:WikiStart Orbit] > [wiki:NodeHandler NodeHandler] > [wiki:NodeHandler/Tutorial Tutorial] > HelloWorld Example
     2
     3The "Hello World" Experiment is simple.  It has one sender and one receiver as diagrammed in Figure 7 below.  The script for this experiment is shown in Figure 8.
     4
     5Figure 7.  "Hello World" Experiment.
     6
     7{{{
     8Experiment.name = "tutorial-1a"
     9Experiment.project = "orbit:tutorial"
     10
     11#
     12# Define nodes used in experiment
     13#
     14defNodes('sender', [1,2]) {|node|
     15  node.image = nil  # assume the right image to be on disk
     16
     17  node.prototype("test:proto:sender", {
     18    'destinationHost' => '192.168.1.4',
     19    'packetSize' => 1024,
     20    'rate' => 300,
     21    'protocol' => 'udp'   
     22  })
     23  node.net.w0.mode = "managed"
     24}
     25
     26defNodes('receiver', [1,4]) {|node|
     27  node.image = nil  # assume the right image to be on disk
     28  node.prototype("test:proto:receiver" , {
     29    'hostname' => '192.168.1.4',
     30    'protocol' => 'udp'
     31  })
     32  node.net.w0.mode = "master"
     33}
     34
     35allNodes.net.w0 { |w|
     36  w.type = 'b'
     37  w.essid = "helloworld"
     38  w.ip = "%192.168.%x.%y"
     39}
     40
     41#
     42# Now, start the application
     43#
     44whenAllInstalled() {|node|
     45  wait 30
     46
     47  allNodes.startApplications
     48  wait 40
     49
     50  Experiment.done
     51}
     52}}}
     53
     54Figure 8.  Script for "Hello World" Experiment
     55
     56The first line of the script in Figure 8 assigns a name to the experiment and the second line assigns the name of the associated project to the experiment.  Next, the sender node is defined, then the receiver node.  Each of these definitions uses the defNodes method which takes the name of the group of nodes (here a group of one) then a selector for addresses of the nodes in the group, then a block of Ruby code enclosed in braces.  These blocks of code are performed for each selected node using the selector (only one each here) to specify to the image to be loaded (defaulted here), prototype, and mode (managed and master).  The prototype statement contains a name and a hash list which associates values with the destinationHost, packetSize, rate and protocol properties, thus setting the parameters for a node.  Setting the mode helps configure the node.
     57
     58The script then uses the allNodes method that evaluates the block for all nodes in the array, here to load each of the nodes in the array, assign its type, specify its load id and assign its IP address.
     59
     60The last part of the script uses ''whenAllInstalled()'' to wait to execute the block of code enclosed in braces until each specified image is installed OK.  The block of code then waits 30 seconds, then starts each of the specified applications, waits 40 seconds, then concludes the experiment insuring all measurements are saved to the database.