'Naming nodes in NS2

I'm simulating a network in NS2, but i'm having a problem naming the nodes. I'm naming them from 1 to 10 but when i start it, it shows nodes from 0 to 9

set ns [new Simulator]

set nf [open out.nam w]

$ns namtrace-all $nf

set tf [open out.tr w]

$ns trace-all $nf

proc finish {} {

global ns nf tf

$ns flush-trace

close $nf

close $tf

exec nam out.nam &

exit 0

}

set n1 [$ns node]

set n2 [$ns node]

set n3 [$ns node]

set n4 [$ns node]

set n5 [$ns node]

set n6 [$ns node]

set n7 [$ns node]

set n8 [$ns node]

set n9 [$ns node]

set n10 [$ns node]

$ns duplex-link $n1 $n5 1Mb 10ms DropTail

$ns duplex-link-op $n1 $n5 orient right-down

$ns duplex-link $n2 $n5 1Mb 10ms DropTail

$ns duplex-link-op $n2 $n5 orient right

$ns duplex-link $n3 $n5 1Mb 10ms DropTail

$ns duplex-link-op $n3 $n5 orient right-up

$ns duplex-link $n4 $n5 1Mb 10ms DropTail

$ns duplex-link-op $n4 $n5 orient up

$ns duplex-link $n5 $n6 1Mb 10ms DropTail

$ns duplex-link-op $n5 $n6 orient right

$ns duplex-link $n6 $n7 1Mb 10ms DropTail

$ns duplex-link-op $n6 $n7 orient right-up

$ns duplex-link $n6 $n8 1Mb 10ms DropTail

$ns duplex-link-op $n6 $n8 orient right

$ns duplex-link $n6 $n9 1Mb 10ms DropTail

$ns duplex-link-op $n6 $n9 orient right-down

$ns duplex-link $n6 $n10 1Mb 10ms DropTail

$ns duplex-link-op $n6 $n10 orient down

$ns at 5.0 "finish"

$ns run



Solution 1:[1]


The first node is always 0 . So why change that ?


Solution 2:[2]

Counting of nodes in ns always start from zero by default

Solution 3:[3]

In ns-2, each node is defined with a set of attributes. Attributes specific to node are color, shape, label, label-color, position of label and adding/deleting mark on the node. Each node can have 3 shapes: circle (default), square, or hexagon. But once created, the shape of a node CANNOT be changed during the simulation. Different node may have different colors, and its color may be changed during animation. The following OTcl procedures are used to set node attributes, they are methods of the class Node:

$node color [color] ;# sets color of node
$node shape [shape] ;# sets shape of node
$node label [label] ;# sets label on node
$node label-color [lcolor] ;# sets color of label
$node label-at [ldirection] ;# sets position of label
$node add-mark [name] [color] [shape] ;# adds a mark to node
$node delete-mark [name] ;# deletes mark from node

Hope it answers your question. Good luck !

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Knud Larsen
Solution 2 Rohit
Solution 3 Rohit