Tutorial/HowToTopology2: tut_topo_2.rb

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