satish ajur
satish ajur

Reputation: 11

dyanamic cluster formation in ns-2 simulator using tcl scripting & AWk language

I want to create clusters dynamically with any number of nodes (the number read from command line input). I have deployed nodes using set dest command with x and y values, but I want to implement dynamic cluster formation each time. As shown, I have x and y coordinates hard-coded, but I would like to create them at runtime.

   $ns_ at $tn "$node_(0) setdest 730.061 715.205 750"    
   $ns_ at $tn "$node_(1) setdest 1032.95 867.473 750"    
   $ns_ at $tn "$node_(2) setdest 941.11 1031.13 750"    
   $ns_ at $tn "$node_(3) setdest 1112.75 993.609 750"    
   $ns_ at $tn "$node_(4) setdest 1085.21 1176.37 750"    
   $ns_ at $tn "$node_(5) setdest 1232.55 821.43 750"    
   $ns_ at $tn "$node_(6) setdest 1277.3 1040.56 750"    
   $ns_ at $tn "$node_(7) setdest 883.426 466.448 750"    
   $ns_ at $tn "$node_(8) setdest 1001.59 290.138 750"    
   $ns_ at $tn "$node_(9) setdest 774.005 337.611 750"    
   $ns_ at $tn "$node_(10) setdest 636.72 245.85 750"    
   $ns_ at $tn "$node_(11) setdest 888.613 195.457 750"    

Upvotes: 1

Views: 2124

Answers (1)

Donal Fellows
Donal Fellows

Reputation: 137567

Here's how to place twelve nodes with random locations.

for {set i 0} {$i < 12} {incr i} {
    # I've no idea how you *want* to do this, but this works for example
    set xLocation [expr {int(1500 * rand())}]
    set yLocation [expr {int(1500 * rand())}]

    # Place the node (is that what the right name is?)
    $ns_ at $tn [list $node_($i) setdest $xLocation $yLocation 750]
}

The list command is ideal for generating callbacks; it does precisely the quoting that you need.

Upvotes: 1

Related Questions