networking - How to set position and orientation of nodes displayed in NAM using TCL code? -


using ns2 , nam, want display tree topology containing many nodes. how set position of nodes , orientation displayed in image. first image shows before editing , changing position of nodes in nam tool. second image displays after editing node position manually using nam tool. want see nodes position displayed in second image. not want edit manually. how write tcl code ?

nodes position , orientation before editing in nam tool

here tcl code

    #create simulator object     set ns [new simulator]     $ns color 1 green     $ns color 2 red     $ns color 3 blue     $ns color 4 magenta     #tell simulator use dynamic routing     $ns rtproto dv     set tracefile [open out.tr w]     $ns trace-all $tracefile     #open nam trace file     set nf [open out.nam w]     $ns namtrace-all $nf     #define 'finish' procedure     proc finish {} {             global ns tracefile nf             $ns flush-trace         #close trace file             close $nf          #execute nam on trace file             exec nam out.nam &             exit 0     }     #create thirty 6 nodes     {set 0} {$i < 21} {incr i} {             set n($i) [$ns node]     }     $ns duplex-link $n(0) $n(1) 1mb 10ms droptail      $ns duplex-link $n(0) $n(2) 1mb 10ms droptail      $ns duplex-link $n(0) $n(3) 1mb 10ms droptail      $ns duplex-link $n(0) $n(4) 1mb 10ms droptail      $ns duplex-link $n(1) $n(5) 1mb 10ms droptail      $ns duplex-link $n(1) $n(7) 1mb 10ms droptail      $ns duplex-link $n(1) $n(9) 1mb 10ms droptail      $ns duplex-link $n(1) $n(11) 1mb 10ms droptail     $ns duplex-link $n(2) $n(5) 1mb 10ms droptail      $ns duplex-link $n(2) $n(7) 1mb 10ms droptail      $ns duplex-link $n(2) $n(9) 1mb 10ms droptail      $ns duplex-link $n(2) $n(11) 1mb 10ms droptail     $ns duplex-link $n(3) $n(6) 1mb 10ms droptail      $ns duplex-link $n(3) $n(8) 1mb 10ms droptail      $ns duplex-link $n(3) $n(10) 1mb 10ms droptail     $ns duplex-link $n(3) $n(12) 1mb 10ms droptail     $ns duplex-link $n(4) $n(6) 1mb 10ms droptail      $ns duplex-link $n(4) $n(8) 1mb 10ms droptail      $ns duplex-link $n(4) $n(10) 1mb 10ms droptail     $ns duplex-link $n(4) $n(12) 1mb 10ms droptail     $ns duplex-link $n(5) $n(13) 1mb 10ms droptail     $ns duplex-link $n(5) $n(14) 1mb 10ms droptail     $ns duplex-link $n(6) $n(13) 1mb 10ms droptail     $ns duplex-link $n(6) $n(14) 1mb 10ms droptail     $ns duplex-link $n(7) $n(15) 1mb 10ms droptail     $ns duplex-link $n(7) $n(16) 1mb 10ms droptail     $ns duplex-link $n(8) $n(15) 1mb 10ms droptail     $ns duplex-link $n(8) $n(16) 1mb 10ms droptail     $ns duplex-link $n(9) $n(17) 1mb 10ms droptail     $ns duplex-link $n(9) $n(18) 1mb 10ms droptail     $ns duplex-link $n(10) $n(17) 1mb 10ms droptail     $ns duplex-link $n(10) $n(18) 1mb 10ms droptail     $ns duplex-link $n(11) $n(19) 1mb 10ms droptail     $ns duplex-link $n(11) $n(20) 1mb 10ms droptail     $ns duplex-link $n(12) $n(19) 1mb 10ms droptail     $ns duplex-link $n(12) $n(20) 1mb 10ms droptail     # provide initial location of mobilenodes     $n(0) set x_ 0.0     $n(0) set y_ 0.0     #create udp source node     set udp0 [new agent/udp]     $udp0 set class_ 1     $ns attach-agent $n(0) $udp0     #create udp1 source node     set udp1 [new agent/udp]     $udp1 set class_ 2     $ns attach-agent $n(0) $udp1      set cbr0 [new application/traffic/cbr]     $cbr0 set packetsize_ 250     $cbr0 set interval_ 0.010     $cbr0 attach-agent $udp0     set cbr1 [new application/traffic/cbr]     $cbr1 set packetsize_ 250     $cbr1 set interval_ 0.010     $cbr1 attach-agent $udp1     set null0 [new agent/null]     $ns attach-agent $n(13) $null0     set null1 [new agent/null]     $ns attach-agent $n(20) $null1     $ns connect $udp0 $null0     $ns connect $udp1 $null1     $ns @ 0.0 "$cbr0 start"     $ns @ 0.0 "$cbr1 start"     $ns @ 5.0 "finish"     #run simulation     $ns run 

after editing in nam tool

it's matter of spreading nodes. there's few ways it, key you've got rectangular space.

# describe indices of nodes , how approximately want arrange them. set indexlayout {     {0}     {1 2 3 4}     {5 6 7 8 9 10 11 12}     {13 14 15 16 17 18 19 20} }  # describe space we're going lay them out over; might need tune set originx 0 set originy 0 set width   100 set height  100  # layout set nrows [llength $indexlayout] set rowsize [expr {$height / $nrows}] set rowy [expr {$originy + $rowsize / 2}] foreach row $indexlayout {     set ncols [llength $row]     set colsize [expr {$width / $ncols}]     set rowx [expr {$originx + $colsize / 2}]     foreach index $row {         $n($index) set x_ $rowx         $n($index) set y_ $rowy         set rowx [expr {$rowx + $colsize}]     }     set rowy [expr {$rowy + $rowsize}] } 

i'm not sure if need explicitly set link orientations if lay nodes out, if do, should read stack overflow question: angle based orientation ns2 not working information syntax like. if need lay links out explicitly, need geometry (though can't see why make required default).


Comments

Popular posts from this blog

php - Permission denied. Laravel linux server -

google bigquery - Delta between query execution time and Java query call to finish -

python - Pandas two dataframes multiplication? -