Tutorial: tut_topo_2.rb¶
Click here to return to the tutorial.
Given below is the code for the tut_topo_2.rb script:
1 #
2 # This is a script example, which illustrates the use of multi-hop topologies
3 #
4 # The scenario of this experiment involves several groups of nodes: a 'sender' and
5 # multiple 'receiver' groups. The 'sender' group will generate some broadcast traffic,
6 # which will be received by the 'receiver' groups.
7 #
8 # Each group contains nodes that are not explicitly defined within this script, but
9 # rather randomly drawn from the set of active nodes on the tested where this script is
10 # running. In other words, this script example does not specifically name which node belongs to
11 # which group.
12 #
13 # The multi-hop connectivity map for this scenario is as follows
14 #
15 # myNode_1 -> myNode_2 -> myNode_3 -> myNode4
16 #
17 # where "A -> B" means that node A has an asymmetric link to node B
18 #
19 # More information on the available commands to define a topology are available on the
20 # following page:
21 # http://www.orbit-lab.org/wiki/Documentation/NodeHandler/Commands/defTopology
22 #
23 # In this example we:
24 #
25 # 1) Define a 1st Topology, which will be used to build the multi-hop connectivity map
26 # 2) Define a 1st sub-topology, which will be used to build the 'sender' group of nodes
27 # 3) Define the 'sender' group of nodes
28 # 4) Define other sub-topologies, which will be used to build the different 'receiver' groups of nodes
29 # 5) Define the multiple 'receiver' groups of nodes
30 # 6) Configure the wireless interfaces on all the nodes and enforce the multi-hop topology
31 # 7) Finally run the experiment
32 #
33
34 # 1)
35 # Define the Main Topology for this experiment
36 #
37 # This topology will hold all the nodes involved in this experiment and it will also
38 # define the links between them in our multi-hop scenario
39 #
40 # A topology is a set of logical nodes (vertices) with a mapping to
41 # real nodes of a testbed. Optionally, a set of logical links (edges)
42 # can also be added to a topology to connect different nodes, thus
43 # "emulating" a multi-hop configuration.
44 #
45 # This topology will have nodes and links which will be as follows:
46 # myNode_1 -> myNode_2 -> myNode_3 -> myNode4
47 #
48 defTopology('mainTopology') { |t|
49
50 # 1.1 - Load a "base" topology with all the currently active nodes
51 # The use of 'system:topo:active' is only possible when an "imageNodes4"
52 # process has been performed previously from the same path as the one
53 # where this script is currently ran.
54 baseTopo = Topology['system:topo:all']
55 puts "Number of Active nodes on this testbed: #{baseTopo.size}"
56
57 # 1.2 - Select a set of nodes from the base topology
58 # A given ':number' of nodes with the required ':features' are selected
59 # using the given ':method'. These nodes are given the node-name ':name'
60 # where %i% will be repaced my an incremental count from 0..'number'
61 #
62 # ':features' is a hash which holds the required characteristics for these nodes
63 #
64 # NOTE: So far (Nov.07) no 'features' selection is currently implemented, thus
65 # the following 'features' are just here as placeholders / illustrations.
66 someNodes = baseTopo.select( :method => :random,
67 :number => 4,
68 :name => "myNode_%i%",
69 :features => {:wifi => "atheros" , :bt => "false" , :mem => "512" , :channel => "all"})
70
71 # 1.3 - Add the selected nodes to this topology
72 t.addNodes(someNodes)
73 # 1.3 bis - Nodes can also be explicitly added using the following methods, which
74 # can replace or be combined with the above steps 2 and 3:
75 # t.addNode(x, y) -> add node [x,y], and give it the node-name "[x,y]"
76 # t.addNode("myNode", [x,y]) -> add node [x,y], and give it the node-name "myNode"
77
78 # 1.4 - Define a set of edges between these nodes
79 # (This step is optional if you don't need a multi-hop scenario)
80 # When present, this step allows the emulation of multi-hop experiment.
81 # When absent, the nodes connectivity will follow their "normal" radio coverage
82 #
83 # addLink(A,B,spec) -> add a link between nodes A and B, and configure that link
84 # with the characteristics given in the 'spec' hash
85 # e.g. spec = [ rate=54 , per=0.10 , etc... ]
86 # So far (Nov.07) no 'spec' selection other than 'asymmetric' is currently implemented,
87 # thus the other 'specs' are just here as placeholders / illustrations.
88 t.addLink("myNode_1","myNode_2",{ :rate =>54, :per =>0.1, :asymmetric => true })
89 t.addLink("myNode_2","myNode_3",{ :rate =>12, :per =>0.2, :asymmetric => true })
90 t.addLink("myNode_3","myNode_4",{ :rate =>6, :per =>0.4, :asymmetric => true })
91
92 # 1.5 - Optional
93 # Save the defined connectivity graph of this topology to a file, which
94 # can be viewed with graphviz
95 # The filename is: 'ID-Graph.dot' where 'ID' is this experiment ID
96 # It will be located in the current directory
97 t.saveGraphToFile()
98 }
99
100 # 2)
101 # Define a sub-Topology, which will hold a subset of "mainTopology"
102 # Typically, this would be used to put a selection of nodes from the
103 # main topology into a group of node running a same type of application.
104 # Thus, there are no connectivity states/constraints defined here.
105 #
106 defTopology('senderSubTopology') { |t|
107
108 # load the main topology defined above
109 mainT = Topology['mainTopology']
110
111 # Add nodes myNode_1..3 from the "mainTopology" into this sub-topology
112 for i in 1..3
113 node = mainT.getNodeByLabel("myNode_#{i}")
114 t.addNode(node)
115 end
116 }
117
118 # 3)
119 # Define a group of node "senderGroup"
120 # The nodes within this group will all run a broadcast traffic generator
121 #
122 defGroup('senderGroup', 'senderSubTopology') {|node|
123 node.prototype("test:proto:udp_sender", {
124 'destinationHost' => '192.168.255.255',
125 'localHost' => '0.0.0.0',
126 'localPort' => 4000,
127 'broadcast' => 1,
128 'packetSize' => 512,
129 'rate' => 400
130 })
131 }
132
133 # 4) and 5)
134 # Define 3 other sub-Topologies 'receiverSubTopology_2..4'
135 # Define 3 other group of node 'receiverGroup_2..4'
136 # The single node within each of this group runs a traffic sink
137 #
138 for i in 2..4
139
140 # 4) define 3 other sub-topologies for the receivers
141 defTopology("receiverSubTopology_#{i}") { |t|
142 # Get a given node from the main topology defined above
143 node = Topology['mainTopology'].getNodeByLabel("myNode_#{i}")
144 t.addNode(node)
145 }
146
147 # 5) define 3 receiver groups
148 defGroup("receiverGroup_#{i}", "receiverSubTopology_#{i}") {|node|
149 node.prototype("test:proto:udp_receiver", {'localHost' => '0.0.0.0'} )
150 }
151
152 end
153
154 # 6)
155 #
156 # 6.1 Configures the wireless interfaces of all the nodes in this experiment
157 #
158 allGroups.net.w0 { |w|
159 w.mode = "ad-hoc"
160 w.type = "g"
161 w.channel = "6"
162 w.essid = "exp1234"
163 w.ip = "%192.168.%x.%y"
164 }
165
166 # 6.2
167 # Implement/deploy the topology "mainTopology" on all the experiment nodes.
168 # It is at this point that the MAC filtering tables on each node will be set
169 # according to the connectivity graph associated with "mainTopology".
170 # The interfaces that will be added to the filtering tables on the nodes will be
171 # the ones corresponding to "w0" (which currently maps to "ath0").
172 # (NOTE to developers: this mapping w0->ath0 is temporary, ideally as suggested
173 # on the dev-list, we should NOT use software-specific name such as "ath0". But
174 # the current INVENTORY database does not support that. This will be changed in
175 # the near future)
176 #
177 # Here we use the iptable tool to set up the MAC filtering tables on each node.
178 # Other options are "ebtable" and "mackill"
179 #
180 allGroups.net.w0.enforce_link = {:topology => 'mainTopology', :method => 'iptable'}
181 #allGroups.net.w0.enforce_link = {:topology => 'mainTopology', :method => 'ebtable'}
182 #allGroups.net.w0.enforce_link = {:topology => 'mainTopology', :method => 'mackill'}
183
184 # 7)
185 # Everything is ready, start the applications on the nodes...
186 #
187 whenAllInstalled() {|node|
188 wait 10
189 allGroups.startApplications
190 wait 60
191 Experiment.done
192 }
193
Click here to return to the tutorial.