[wiki:Tutorial Back] [[TOC(heading=Tutorial TOC, Tutorial, Tutorial/HelloWorld, depth=2)]] = Basic Tutorial: Hello World Example = == 1. Developing a Script for an Experiment == As explained in the previous [wiki:Tutorial/Testbed overview] page, to run an experiment on the testbed a user needs to first describes this experiment in a ''script''. This ''script'' is then passed on to a '''Node Handler''', which will use it to run and control the experiment execution. This process is illustrated on the following fig 1. This script contains the experiment configuration and scenario. More precisely, it includes: * a description of the required resources (e.g. nodes on the testbed, applications to run), * their initializations and optional associations (e.g. nodeX is connected to NodeY, all nodes use channel 6 of 802.11g), * a description of their operation throughout the experiment duration (e.g. applicationX starts at T0 and run for 60sec, nodeY switch wireless configuration after 100sec). ORBIT experiment scripts are written using the Ruby scripting language. However, a user does '''not''' necessary need to be familiar with Ruby to be able to write and run simple experiments. The only prerequisite skills are some prior basic knowledge and practice of any other scripting and/or programming languages (e.g. python, perl, c, java,...). Of course, to be able to develop more complex experiment, a user will have to learn basics of Ruby and read about ORBIT-specific Ruby methods at some stage (more on these two issues at the end of this tutorial). [[Image(OMF-User-View.png)]] [[BR]]Figure 1. Execution of an Experiment from a User's point-of-view [[BR]] [[BR]] == 2. "Hello World" experiment == In this basic experiment, we define two groups of node: a ''sender'' and a ''receiver'' group. Although a group of node can contain several nodes, in this simple case each group contains only one node. We also associate a traffic generator application to the ''sender'' group, and a traffic sink application to the ''receiver'' group. We then define the configuration of the wireless interfaces on the nodes within these groups. Finally, we describe the successive actions to execute in order to perform the experiment. The script for this experiment is shown below. {{{ # # A) Define the 'sender' group, which has the unique node [1,1] # Nodes in this group will execute the application 'test:proto:sender' # defNodes('sender', [1,1]) {|node| node.prototype("test:proto:sender", { 'destinationHost' => '192.168.1.2', 'packetSize' => 1024, 'rate' => 300, 'protocol' => 'udp' }) node.net.w0.mode = "managed" } # # B) Define the 'receiver' group, which has the unique node [1,2] # Nodes in this group will execute the application 'test:proto:receiver' # defNodes('receiver', [1,2]) {|node| node.prototype("test:proto:receiver" , { 'protocol' => 'udp' }) node.net.w0.mode = "master" } # # C) Configure the wireless interfaces of All the Nodes involved in # this experiment # allNodes.net.w0 { |w| w.type = 'b' w.essid = "helloworld" w.ip = "%192.168.%x.%y" } # # D) When all the nodes are turned On and the all the applications # are installed and ready, we can start to perform the experiment # whenAllInstalled() {|node| wait 30 allNodes.startApplications wait 40 Experiment.done } }}} [[BR]] == 3. Understanding the "Hello World" script == As you noticed the "Hello World" script is almost ''human-readable'', and is quite understandable to any computer-literate reader. As already mentioned above, deep Ruby knowledge is '''not''' a prerequisite to running experiment on the ORBIT testbed. * The first part of this script uses the ORBIT method ''defNodes'' to define a group of nodes called ''sender'', which contains a unique node ''[1,1]''. Next, we perform some specific configurations on the node(s) within the group ''sender''. These specific configurations are described in a ''block'' (e.g. curly braces) that directly follows the ''defNodes'' call. Within this ''block'', we first assign a particular application to the ''sender'' node(s). This application is a traffic generator and is accessed via a ''prototype'' which is called ''test:proto:sender'' in this example. A prototype can be viewed as a wrapper around an existing application. It defines some set of properties (i.e. "parameters"), which allows us to customize the wrapped application for the specific need of an experiment. For example in this case, through the prototype we can set the address of the sender, and various parameters of the traffic generator itself, such as packet size, rate, and the protocol over which to send the traffic. Prototypes are normally defined in separate files, and the ORBIT platform has a set of predefined prototypes for some basic applications. For example, the prototype "test:proto:sender" is a wrapper around the application "otg" (orbit traffic generator). Other tutorials (see [wiki:Tutorial main page]) describes how to write your own prototypes for your own or existing applications. The last line on this 'sender' block configures the first wireless interface ''w0'' on the node(s) in this block into ''managed'' mode. {{{ # # A) Define the 'sender' group, which has the unique node [1,1] # defNodes('sender', [1,1]) {|node| # Assign the prototype "test:proto:sender" to the node(s) in this group node.prototype("test:proto:sender", { # Configure the properties for this prototype, i.e. the parameters for the wrapped application 'destinationHost' => '192.168.1.2', 'packetSize' => 1024, 'rate' => 300, 'protocol' => 'udp' }) # Configure the wireless interface "w0" of the node(s) in this group # Put the interface into "Managed" mode. node.net.w0.mode = "managed" } }}} * The second part of the script is very similar to the previous one. Here we define a 'receiver' group with a unique node, this time node [1,2]. Again we define some specific configuration for the 'receiver' nodes in a block following the ''defNodes'' call. In this case, we assign a traffic sink application to the node(s) via a prototype called "test:proto:receiver", we also set the 'protocol' property of this prototype. Finally, we configure the "w0" wireless interface of the node(s) into "master" mode. {{{ # # B) Define the 'receiver' group, which has the unique node [1,2] # defNodes('receiver', [1,2]) {|node| # Assign the prototype "test:proto:receiver" to the node(s) in this group node.prototype("test:proto:receiver" , { 'protocol' => 'udp' }) # Configure the wireless interface "w0" of the node(s) in this group node.net.w0.mode = "master" } }}} * The third part of the script presents an example on how to configure interfaces on all nodes in one place to ensure consistency. The command ''allNodes.net.w0'' describes the first wireless interface on all nodes in the experiment. The code inside the following ''block'' (e.g. curly braces) configures various parameters of these interfaces. In this specific example, we configure the interface as an 802.11b type, set the ''essid'' to a common string, and set it's IP address. We obviously do not want to set all the interfaces to the same IP address, thus any string beginning with a '%' is ''personalized'' for each node by replacing characters prefixed by a '%' with a local string. In this specific example, '%y' is replaced by the 'y' coordinate of the node. For this specific experiment setup, the IP address of node [1,1] will be 192.168.1.1, while node [1,2] will have 192.168.1.2 assigned. This part concludes the configuration phase of the experiment. {{{ # # C) Configure the wireless interfaces of All the Nodes in this experiment # allNodes.net.w0 { |w| w.type = 'b' w.essid = "helloworld" w.ip = "%192.168.%x.%y" } }}} * This final part of the script describes the operation to execute in order to perform the experiment. An ORBIT experiment script basically defines a state machine, or more precisely, what sequence of commands should be executed if the experiments enters a particular state. The only state we will use in this experiment is ''whenAllInstalled''. This state is reached when all the nodes are configures and all the requested applications are installed and ready to go. The sequence of commands to perform are given in a ''block'' following the ''whenAllInstalled'' call. The first command 'wait 30' will suspend the execution for 30 seconds to ensure that indeed everything has settled. The ''allNodes.startApplications'' will then send a command to all nodes to start the applications assigned to them (via the use of ''prototypes'') in the previous script parts. Thus in this example, this command will start a traffic generator on node [1,1] and a corresponding sink on node [1,2]. The different parameters for these applications are taken from the above definition as well. Finally, the next line 'wait 40' will suspend the control of the experiment for 40 seconds (during which the applications on the nodes '''will run''' and exchange traffic), before concluding the experiment with a call to ''Experiment.done''. {{{ # # D) When all the nodes are turned On and the all the applications # are installed and ready, we can start to perform the experiment # whenAllInstalled() {|node| # Wait 30sec wait 30 # Start all the Applications on all the nodes allNodes.startApplications # Wait for 40sec wait 40 # Stop the experiment execution Experiment.done } }}} [[BR]] == 4. Running the "Hello World" experiment == Before being able to run this experiment, you should: * [http://www.orbit-lab.org/wiki/Registration Register] for an account (if you have not done so yet) * [https://www.orbit-lab.org/schedule/ Make a reservation] on the Scheduler for a time slot on one of the sandbox testbed * Log into the console machine corresponding to this testbed. To control the Node Handler, your experiment, and the nodes on the testbed(s), you will use the generic '''orbit''' command and its options. {{{ # User Bob reserved a time slot on the sandbox1 testbed. # He then can access the sandbox1 console using the command: ssh bob@console.sb1.orbit-lab.org # To see a list of commands available through the orbit command: orbit help # which will give the following output Run a command on the testbed(s) Usage: orbit [COMMAND] [ARGUMENT]... Available COMMANDs: help Print this help message or a specif command usage exec Execute an experiment script load Load a disk image on a given set of nodes save Save a disk image from a given node into a file tell Switch a given set of nodes ON/OFF stat Returns the status of a given set of nodes To get more help on individual commands: 'omf help [COMMAND]' Examples: orbit help exec Return usage/help for the 'exec' command orbit help load Return usage/help for the 'load' command }}} * Install a disk image which includes ''nodeAgent4'' on the nodes of this testbed. For example, you can use the latest ''baseline.ndz'' disk image. This disk image installation is done using the ''orbit load'' command above, and detailed instructions on how to execute it on the nodes on a testbed can be found [wiki:Tutorial/HowToImage here]. Once the nodes have been imaged, you can run the "Hello World" experiment with the ''orbit exec'' command as follows: {{{ orbit exec --tutorial }}} Normally an experiment is described in a script file, e.g. "my_experiment.rb", which is run by using the command "orbit exec my_experiment". However in this particular case, the tutorial script is already stored in a repository known by the ''orbit exec'' application. Thus the "--tutorial" option instructs the ''orbit exec'' application to fetch that script and execute it. After running the above command, your console output should look like this: {{{ console.sb1:~# orbit exec --tutorial DEBUG Experiment: Domain: sb1 INFO init: NodeHandler Version 4.2.0 (1272) INFO init: Experiment ID: sb1_2007_11_19_19_15_19 INFO Experiment: load system:exp:stdlib INFO prop.resetDelay: resetDelay = 210:Fixnum INFO prop.resetTries: resetTries = 1:Fixnum INFO Experiment: load test:exp:tutorial-1a INFO stdlib: Waiting for nodes (Up/Down/Total): 0/2/2 - (still down: n_1_2,n_1_1) INFO stdlib: Waiting for nodes (Up/Down/Total): 0/2/2 - (still down: n_1_2,n_1_1) INFO stdlib: Waiting for nodes (Up/Down/Total): 0/2/2 - (still down: n_1_2,n_1_1) INFO stdlib: Waiting for nodes (Up/Down/Total): 0/2/2 - (still down: n_1_2,n_1_1) INFO stdlib: Waiting for nodes (Up/Down/Total): 0/2/2 - (still down: n_1_2,n_1_1) INFO stdlib: Waiting for nodes (Up/Down/Total): 0/2/2 - (still down: n_1_2,n_1_1) INFO n_1_1: Device 'net/w0' reported Not-Associated INFO stdlib: Waiting for nodes (Up/Down/Total): 1/1/2 - (still down: n_1_2) INFO whenAll: *: 'apps/app/status[@value='INSTALLED.OK']' fires INFO n_1_1: Device 'net/w0' reported 00:60:B3:25:BF:F5 INFO n_1_2: Device 'net/w0' reported 00:60:B3:25:BF:F5 INFO OML: Started: {"port"=>"7600", "iface"=>"eth2", "addr"=>"224.0.0.6"} INFO Experiment: DONE! INFO ExecApp: Application 'commServer' finished INFO run: Experiment sb1_2007_11_19_19_15_19 finished after 3:41 console.sb1:~# }}} '''Congratulation''' you just ran your first experiment script on the Orbit Testbed! You will find information on how to collect and interpret measurements and results from your experiment in the next parts of this basic tutorial, [wiki:Tutorial/CollectMeasurements here] and [wiki:Tutorial/AnalyzeResults here] [[BR]] == 5. Beyond the Basics == === 5.1. More on the Ruby Language and the ORBIT-specific Ruby methods === As mentioned previously, ORBIT experiment scripts are written in Ruby, an easily understood, extensible, dynamic, object-oriented scripting language. Ruby has been extended into the testbed user's domain with a number of methods. Besides its extensibility and object-orientation, Ruby is concise and consistent. An ORBIT script therefore is written in Ruby primarily using ORBIT-specific methods. Users are encouraged to take look at following resources: * [wiki:Tutorial/HowtoWriteScripts/RubyResources Ruby Resources] * [wiki:Tutorial/HowtoWriteScripts/OrbitRuby ORBIT Specific Ruby Methods] === 5.2. More Tutorials === Once you are done with the remaining parts of this basic tutorial (i.e. [wiki:Tutorial/CollectMeasurements collecting] and [wiki:Tutorial/AnalyzeResults interpreting] experiment measurements and results), you might want to have a look at the other tutorials on the [wiki:Tutorial main page] to further learn about the other ORBIT functions that can help you develop your own complex experiments. === 5.3. Definitions of the Prototypes and Application used in the "Hello World" script === * Orbit Traffic Generator (OTG) [[BR]] [wiki:Documentation/OTG/ScriptsRepository/ProtoDefSender sender.rb] is the file that contains the "test:proto:sender" prototype, which wraps around the [wiki:Documentation/OTG/ScriptsRepository/OtgAppDef otg.rb] application. * Orbit Traffic Receiver (OTR) [[BR]] [wiki:Documentation/OTG/ScriptsRepository/ProtoDefReceiver receiver.rb] is the file that contains the "test:proto:receiver" prototype, which wraps around the [wiki:Documentation/OTG/ScriptsRepository/OtrAppdef otr.rb] application.