Changes between Version 5 and Version 6 of Old/NodeHandler/Commands/defTopology
- Timestamp:
- Aug 29, 2007, 12:46:16 AM (17 years ago)
Legend:
- Unmodified
- Added
- Removed
- Modified
-
Old/NodeHandler/Commands/defTopology
v5 v6 29 29 The optional 'block' allows the experimenter to further configure the topology. The following commands are defined inside the block: 30 30 31 * '''addNode(x,y)''' Add node at location x@y to the topology 31 * '''addNode(x,y)''' Add node at location x@y to the topology. 32 32 33 * '''removeNode(x,y)''' Remove node at location x@y from the topology 33 * '''removeNode(x,y)''' Remove node at location x@y from the topology. 34 34 35 * '''size()''' -- to be completed soon...35 * '''size()''' Return the number of nodes in this topology. 36 36 37 * '''getNode(index)''' -- to be completed soon...37 * '''getNode(index)''' Return the node at the position ''index'' in this topology. Return ''nil'' if ''index'' is greater than the number of nodes in the topology. 38 38 39 * '''getFirstNode()''' ...39 * '''getFirstNode()''' Return the node at the 1st position in this topology. 40 40 41 * '''getLastNode()''' ...41 * '''getLastNode()''' Return the node at the last position in this topoly. 42 42 43 * '''getRandomNode()''' ...43 * '''getRandomNode()''' Return a random node from this topology. Subsequent calls to this method may return the same node. 44 44 45 * '''getUniqueRandomNode()''' ...45 * '''getUniqueRandomNode()''' Return a unique random node from this topology. Subsequent calls to this method will never return the same node, i.e. once a node is randomly selected it is "removed from the bag of nodes" of this topology. When all the available nodes in this topology have been drawn, this method will return ''nil'' and output a warning message to the console. 46 46 47 * '''eachNode(&block)''' 47 * '''eachNode(&block)''' Execute the commands in ''block'' on each node within this topology. 48 48 49 * '''setStrict()''' 49 * '''setStrict()''' Set the ''strict'' flag for this topology. When the ''strict'' flag is set, adding or removing a node from this topology is not permitted, and will result in an error message on the console and the termination of the experiment. Typically a user sets this flag when s/he wants an experiment to proceed only if all the required nodes are present in this topology. By default, the ''strict'' flag is NOT set for a topology. 50 50 51 * '''unsetStrict()''' 51 * '''unsetStrict()''' Unset the "strict" flag. By default, the ''strict'' flag is NOT set for a topology. 52 52 53 * '''hasNode(x, y)''' 53 * '''hasNode(x, y)''' Return ''true'' if the node at location x@y is part of this topology, return ''false'' otherwise. 54 54 55 55 … … 62 62 63 63 {{{ 64 # topology contains 1 node 65 defTopology('test:topo:origin', [1, 1]) 64 # Define a topology that contains 4 specific nodes 65 # 66 defTopology('test:topo:origin', [[1, 1],[2,5],[10,4],[15,1]]) 66 67 67 # nodes arranged in a circle 68 # Define a topology where nodes on the testbed are arranged 69 # in a circle 70 # 68 71 defTopology('test:topo:circle') { |t| 69 72 # use simple 4-way algorithm … … 83 86 } 84 87 } 88 89 90 # Define a topology that will have 8 nodes randomly selected from 91 # a previously defined topology (''topo_grid_active'' which includes all the 92 # currently active node on the grid testbed) 93 # 94 defTopology('myTopo8Nodes') { |t| 95 96 # Load the 'topo_grid_active' 97 baseTopo = Topology['topo_grid_active'] 98 # Print the size of the base topology 99 puts "Size of the Base Topology: #{baseTopo.size}" 100 101 # Repeat the following 8 times 102 for count in 1..8 103 # Draw a random node from the base topology 104 aNode = baseTopo.getUniqueRandomNode 105 # Add this random node to this 'myTopo8Nodes' topology 106 t.addNode(aNode.x, aNode.y) 107 end 108 109 # Print the nodes that belongs to this topology 110 puts "Size of the 'myTopo8Nodes' Topology: #{t.size}" 111 t.eachNode { |n| 112 puts " - Node: #{n}" 113 } 114 } 85 115 }}} 86 116