Tutorial/HowToTopology: tut_topo_1_more.rb

File tut_topo_1_more.rb, 4.6 KB (added by thierry, 16 years ago)
Line 
1#
2# This is a script example, which illustrates the use of topologies in
3# an experiment scripts
4#
5# The scenario of this experiment involves two group of nodes: 'sender' and
6# 'receiver'. The 'sender' group will generate some broadcast traffic, which will
7# be received by the 'receiver' group.
8#
9# Each group contains nodes that are not explicitly defined within this script, but
10# rather randomly drawn from the set of active nodes on the tested where this script is
11# running. In other words, this script example does not specifically name which node belongs to
12# which group.
13#
14# More information on the available commands to define a topology are available on the
15# following page:
16# http://www.orbit-lab.org/wiki/Documentation/NodeHandler/Commands/defTopology
17#
18# In this example we:
19# 1) Define some experiment parameters
20# 2) Define a simple 1st Topology, which is NOT used later in the experiment
21# 3) Define a 2nd Topology, which will be used to build the 'sender' group of nodes
22# 4) Define a 3rd Topology, which will be used to build the 'receiver' group of nodes
23# 5) Define the 'sender' group of nodes
24# 6) Define the 'receiver' group of nodes
25# 7) Finally run the experiment
26#
27
28# 1)
29# Define some parameters to be use in this experiment
30#
31defProperty('minNodeNumber', 12, 'Minimum number of nodes required for this experiment')
32defProperty('receiverNumber', 8, 'Number of nodes in a receiver role')
33
34# 2)
35# Define a mock topology that we will use to verify the amount
36# of available active nodes on the testbed where this script is running
37# The list of active nodes is automatically created at the end of an 'imageNodes4' process.
38#
39# This step is optional and could also be integrated within the
40# definition of a topology that will be really used.
41# It is just here as an example.
42#
43defTopology('stubTopo') { |t|
44 # Load the topology which contains all the active nodes
45 baseTopo = Topology['system:topo:active']
46 # Check if there are enough nodes available in the 'baseTopo'
47 # if not then exit this experiment
48 if baseTopo.size < prop.minNodeNumber.value
49 puts "Not enough node available! (size: #{baseTopo.size})"
50 Experiment.done
51 end
52 puts "Number of active nodes on this testbed: #{baseTopo.size}"
53 # do nothing else with this stub topology...
54}
55
56# 3)
57# Define a topology that will hold the sender node(s) of this
58# experiment
59#
60defTopology('senderTopo') { |t|
61 baseTopo = Topology['system:topo:active']
62 # Draw a random node from the pool of active ones
63 aNode = baseTopo.getUniqueRandomNode
64 # Add this random node to this 'senderTopo' topology
65 t.addNode(aNode.x, aNode.y)
66 # Print the node that belongs to this topology
67 puts "Size of the my sender Topology: #{t.size}"
68 t.eachNode { |n|
69 puts " - Node: #{n}"
70 }
71}
72
73# 4)
74# Define a topology that will hold the receiver node(s) of this
75# experiment
76#
77defTopology('receiverTopo') { |t|
78 baseTopo = Topology['system:topo:active']
79 # Repeat the following 'receiverNumber' of time
80 for count in 1..prop.receiverNumber.value
81 # Draw a random node from the pool of active ones
82 aNode = baseTopo.getUniqueRandomNode
83 # Add this random node to this 'receiverTopo' topology
84 t.addNode(aNode.x, aNode.y)
85 end
86 # Print the nodes that belongs to this topology
87 puts "Size of the my receiver Topology: #{t.size}"
88 t.eachNode { |n|
89 puts " - Node: #{n}"
90 }
91}
92
93# 5)
94# Define the 'sender' group for this experiment
95# This group will include the node(s) from the 'senderTopo' topology
96# See "HelloWorld" tutorial pages for more info on the following commands
97#
98defGroup('sender', 'senderTopo') {|node|
99 node.prototype("test:proto:sender", {
100 'broadcast' => 'on',
101 'destinationHost' => '192.168.255.255',
102 'packetSize' => 1024,
103 'rate' => 200,
104 'protocol' => 'udp'
105 })
106 node.net.w0.mode = "Master"
107 node.net.w0.type = "g"
108 node.net.w0.essid = "npc123"
109 node.net.w0.ip = "192.168.0.1"
110 wait 30
111}
112
113# 6)
114# Define the 'receiver' group for this experiment
115# This group will include the node(s) from the 'receiverTopo' topology
116# See "HelloWorld" tutorial pages for more info on the following commands
117#
118defGroup('receivers', 'receiverTopo') {|node|
119 node.prototype("test:proto:receiver" , {
120 'protocol' => 'udp'
121 })
122 node.net.w0.mode = "Managed"
123 node.net.w0.type = "g"
124 node.net.w0.essid = "npc123"
125 node.net.w0.ip = "%192.168.%x.%y"
126 wait 30
127}
128
129# 7)
130# When all the applications are installed on the nodes in all the groups,
131# we can start running the applications used in this experiment
132# See "HelloWorld" tutorial pages for more info on the following commands
133#
134whenAllInstalled() {|node|
135 wait 15
136 allGroups.startApplications
137 wait 15
138 Experiment.done
139}
140