Changes between Version 5 and Version 6 of Old/NodeHandler/Commands/defTopology


Ignore:
Timestamp:
Aug 29, 2007, 12:46:16 AM (13 years ago)
Author:
thierry
Comment:

Legend:

Unmodified
Added
Removed
Modified
  • Old/NodeHandler/Commands/defTopology

    v5 v6  
    2929The optional 'block' allows the experimenter to further configure the topology. The following commands are defined inside the block:
    3030
    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.
    3232
    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.
    3434
    35   * '''size()'''  -- to be completed soon...
     35  * '''size()'''  Return the number of nodes in this topology.
    3636
    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.
    3838
    39   * '''getFirstNode()'''  ...
     39  * '''getFirstNode()'''  Return the node at the 1st position in this topology.
    4040
    41   * '''getLastNode()''' ...
     41  * '''getLastNode()''' Return the node at the last position in this topoly.
    4242   
    43   * '''getRandomNode()''' ...
     43  * '''getRandomNode()''' Return a random node from this topology. Subsequent calls to this method may return the same node.
    4444
    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.
    4646
    47   * '''eachNode(&block)'''
     47  * '''eachNode(&block)''' Execute the commands in ''block'' on each node within this topology.
    4848
    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.
    5050 
    51   * '''unsetStrict()'''
     51  * '''unsetStrict()''' Unset the "strict" flag. By default, the ''strict'' flag is NOT set for a topology.
    5252
    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.
    5454
    5555
     
    6262
    6363{{{
    64 # topology contains 1 node
    65 defTopology('test:topo:origin', [1, 1])
     64# Define a topology that contains 4 specific nodes
     65#
     66defTopology('test:topo:origin', [[1, 1],[2,5],[10,4],[15,1]])
    6667
    67 # nodes arranged in a circle
     68# Define a topology where nodes on the testbed are arranged
     69# in a circle
     70#
    6871defTopology('test:topo:circle') { |t|
    6972  # use simple 4-way algorithm
     
    8386  }
    8487}
     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#
     94defTopology('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}
    85115}}}
    86116