1

I am trying to label, change shape, and change label-color of nodes in NS2 2.35/nam 1.15. I am able to add the label and change the color of the nodes correctly (although color requires 2 lines). However, I would like to make that node a square AND change the label color (the label color is lime green and difficult to read). Seems simple... via the manual/internet/sources out there, I have generated the following code to accomplish this:

set stime 0.0

#color works... but requires BOTH these lines 
$ns at $stime "$BS color darkgreen"
$BS color darkgreen

#shape does NOT work. Shape stays a circle
$ns at $stime "$BS shape square"
$BS shape square

#Label works 
$ns at $stime "$BS label \"BASE STATION\""

#label color does NOT. Moves the node to position 0,0
$ns at $stime "$BS label-color black"
$BS label-color black;


#base station position
set bsx [expr $val(x)/2]
set bsy [expr $val(y)/2]
$BS set X_ $bsx
$BS set Y_ $bsy
$BS set Z_ 0.0;

When I run the code, the node color changes and the label is added. However, the shape does not ever change - I have not been able to get it to change either (via changing stime, commenting out stuff, adding, trying different shapes, etc). In addition, when I leave in the label color, it SHIFTS the entire node position from (35, 35) to (0, 0). How would label color shift node position??? Why does my shape never change? What am I doing wrong with label color? Is this an initialization problem within the event scheduler?

As a final note, every node in my whole simulation before 'Play' in nam is pressed starts as a green circle. The colors and labels change AFTER play is hit.

Sam Dean
  • 379
  • 9
  • 19

1 Answers1

2

The default node color is black. And when using energyModel it's green. The color setting is done in tcl/ns-lib.tcl line 1344 : For energyModel. The shape (circle) is set in line 1352 and 1357. My example: red, square ...

  1343      if [info exists energyModel_] { 
  1344          set nodeColor "red"
  1345      } else {
  1346          set nodeColor "black"
  1347      }
  .
  1352  -z $size -v square -c $nodeColor"
  1353      } else { 
  1354          # Flat addressing
  1355          $self puts-nam-config "n -t * -s [$nodep id] \
  1356  -x [$nodep set X_] -y [$nodep set Y_] -Z [$nodep set Z_] -z $size \
  1357  -v square -c $nodeColor"

Build a new ns-allinone-2.35/, and save 'ns' to /usr/local/bin/ns-red-square. Patch: nam_red-square-node.patch (858B, 26 lines) https://drive.google.com/file/d/1PcCwp7bM_Z4208LIFquX3cbt4HNdOcX9/view?usp=sharing (Easy to edit to your preferred color.)

Note : You can have as many ns-allinone-2.xx as you want, installed at the same time https://drive.google.com/file/d/1FCjn-9fkR7tKeqClUpHsleaEdnoKRZzq/view?usp=sharing

My simulation / animation example: $ ns-red-square aodv-Soumia.tcl

enter image description here

P.S.: darkgreen works nice too !


Simulation examples with added square https://drive.google.com/file/d/17nYE9UIVQ7Ir7QUcsdbwSwF240nt0k-w/view?usp=sharing

Simulation example with color settings and square: D-Sq-kartiksd.tcl

$ grep -ni green D-Sq-kartiksd.tcl
$ grep -ni square D-Sq-kartiksd.tcl

Link https://www.dropbox.com/s/s7dvjg1wflz3xsj/D-Sq-kartiksd.tcl?dl=0

Knud Larsen
  • 5,753
  • 2
  • 14
  • 19