| 1 | = How to integrate your application with nodehandler = |
| 2 | |
| 3 | This tutorial is for users who want to use [wiki:nodeHandler nodeHandler] to launch their applications on the nodes. For example, we assume that you want to launch |
| 4 | {{{ |
| 5 | tcpdump -i eth1 |
| 6 | }}} |
| 7 | on all the nodes in the experiment. |
| 8 | |
| 9 | Three steps are needed |
| 10 | |
| 11 | == Create application definition file== |
| 12 | This definition tells the nodehandler about your new application that you want to launch. It mainly includes details such as what are the command line options it takes and what are the statistics it returns. Here is a sample application definition for our above application |
| 13 | |
| 14 | '''Think about this as a class definition for your application''' |
| 15 | |
| 16 | {{{ |
| 17 | # |
| 18 | # Create an application representation from scratch |
| 19 | # |
| 20 | require 'handler/appDefinition' |
| 21 | |
| 22 | a = AppDefinition.create('test:app:tcpdump') |
| 23 | a.name = "tcpdump" |
| 24 | a.version(0, 0, 1) |
| 25 | a.shortDescription = "Tcpdump application" |
| 26 | a.description = <<TEXT |
| 27 | TCPDump application |
| 28 | TEXT |
| 29 | |
| 30 | # addProperty(name, description, mnemonic, type, isDynamic = false, constraints = nil) |
| 31 | |
| 32 | #Here ?i means tcpdump will be launched with -i <interface> option |
| 33 | a.addProperty('interface', 'Interface to run on', ?i, String, false) |
| 34 | |
| 35 | a.path = "/usr/sbin/tcpdump" |
| 36 | |
| 37 | if $0 == __FILE__ |
| 38 | require 'stringio' |
| 39 | require 'rexml/document' |
| 40 | include REXML |
| 41 | |
| 42 | sio = StringIO.new() |
| 43 | a.to_xml.write(sio, 2) |
| 44 | sio.rewind |
| 45 | puts sio.read |
| 46 | |
| 47 | sio.rewind |
| 48 | doc = Document.new(sio) |
| 49 | t = AppDefinition.from_xml(doc.root) |
| 50 | |
| 51 | puts |
| 52 | puts "-------------------------" |
| 53 | puts |
| 54 | t.to_xml.write($stdout, 2) |
| 55 | |
| 56 | end |
| 57 | |
| 58 | }}} |
| 59 | |
| 60 | |
| 61 | == Step 2: Prototype definition == |
| 62 | After informing nodeHandler about our new application, we then need to create a prototype using our application definition. |
| 63 | |
| 64 | '''Think about this as an instance of your above class''' |
| 65 | |
| 66 | {{{ |
| 67 | # |
| 68 | # Define a prototype |
| 69 | # |
| 70 | |
| 71 | require 'handler/prototype' |
| 72 | require 'handler/filter' |
| 73 | require 'handler/appDefinition' |
| 74 | |
| 75 | p = Prototype.create("test:proto:tcpdumper") |
| 76 | p.name = "TCPdump proto" |
| 77 | p.description = "TCPdump" |
| 78 | p.defProperty('interface', 'Interface to listen on') |
| 79 | |
| 80 | |
| 81 | tcpd = p.addApplication('aodvd', "test:app:tcpdump") |
| 82 | tcpd.bindProperty('interface') |
| 83 | |
| 84 | |
| 85 | |
| 86 | if $0 == __FILE__ |
| 87 | p.to_xml.write($stdout, 2) |
| 88 | puts |
| 89 | end |
| 90 | |
| 91 | }}} |
| 92 | |
| 93 | == Step 3: Using this prototype in an actual script == |
| 94 | |
| 95 | The following example script uses our newly defined application definition. |
| 96 | {{{ |
| 97 | ################################################## |
| 98 | # TCPDump using nodeHandler |
| 99 | ################################################## |
| 100 | |
| 101 | Experiment.name = "tutorial-tcpdump" |
| 102 | Experiment.project = "orbit:tutorial" |
| 103 | |
| 104 | # |
| 105 | # Define nodes used in experiment |
| 106 | # |
| 107 | defNodes('nodes', [[1,1],[1,2]]) {|node| |
| 108 | node.image = nil # assume the right image to be on disk |
| 109 | |
| 110 | node.prototype("test:proto:tcpdumper", { |
| 111 | 'interface' => 'eth1' #This is where we assign the interface for this specific instance |
| 112 | }) |
| 113 | node.net.w0.mode = "master" |
| 114 | } |
| 115 | |
| 116 | |
| 117 | allNodes.net.w0 { |w| |
| 118 | w.type = 'b' |
| 119 | w.essid = "helloworld" |
| 120 | w.ip = "%192.168.%x.%y" |
| 121 | } |
| 122 | |
| 123 | # |
| 124 | # Now, start the application |
| 125 | # |
| 126 | whenAllInstalled() {|node| |
| 127 | # Launch TCPdump on all nodes |
| 128 | |
| 129 | #startApplications will launch all the applications defined for the group "nodes" |
| 130 | NodeSet['nodes'].startApplications |
| 131 | |
| 132 | |
| 133 | |
| 134 | wait 180 |
| 135 | |
| 136 | Experiment.done |
| 137 | } |
| 138 | |
| 139 | }}} |