Skip to main content

How to color nodes in NS2

You can color the nodes in NS2. It is bit tricky to color them in a wireless network. We can do this by following code.

set node0 [$ns node]
$node0 color "blue"
$ns at 0.0 "$node0 color blue"



  1. thanku for useful information

  2. How many types of colors are possible ?
    And also can we mention the color in hexadecimal values like for blue can we write #0000FF ??

  3. thanks for the information.... !!! is it possible to fill a node inside with color..?? please help me..

  4. thx dude, u r the best.

  5. Can you help me change color of the node using C++ in AODV.CC files..??

  6. thats really very very helpful... (y)

  7. thnku its really helpful

  8. Thx, finally I found a solution that it really worked in wireless! thumbs up :)


Post a Comment

Popular posts from this blog

Runtime packet loss calculation in NS2

Hello friend, here I am going to present a method to calculate the runtime packet loss. I am going to show this using ns2 2.34 and AODV.
      Sometime we require packet loss to calculate trust value (in case of Trust Based protocols where it is done by no. of packets sent - no. of packets received).
       I am going to show the calculation for a particular pair of nodes.
Steps involved:-

A) We will have to add a node as a malicious node which will drop the packets
     intentionally. You can add a malicious node using this link.

B) Second, we'll set the AODV in promiscuous mode, where every node will
     listen to its neighbors.

1) We need to modify in total 3 files to set AODV in promiscuous mode, so it's
    good to take a backup of it.
    Files are:
ns-allinone-2.34/ns-2.34/aodv/aodv.ccns-allinone-2.34/ns-2.34/aodv/aodv.hns-allinone-2.34/ns-2.34/tcl/lib/ns-mobilenode.tcl 2) Open the file ns-allinone-2.34/ns-2.34/aodv/aodv.h in your favorite editor
    and make the cha…

How to add trust table in NS2.

I am assuming AODV protocol. In add below code

   //Initialize as per your need.
//Deconstruct as per your need.

trust_entry* trust_store::trust_lookup(
nsaddr_t node_id)
     trust_entry *rp = trusthead.lh_first;
     for (; rp; rp = rp->trust_link.le_next) {
             if (rp->node_id == node_id)
    return rp;
void trust_store::trust_delete(
nsaddr_t node_id)
    trust_entry *rp = trust_lookup(node_id);

    if (rp)
        LIST_REMOVE(rp, trust_link);
        delete rp;


nsaddr_t node_id, nsaddr_t prev_node,nsaddr_t next_node,int32_t trust_value)
    trust_entry *rp;
    //assert(tr_lookup(dst_seq_no) == 0);
    rp = new trust_entry;
    rp->node_id = node_id;
    rp->prev_node = prev_node;
    rp->next_node = next_node;
    rp->trust_value = trust_value;
    LIST_INSERT_HEAD(&trusthead, rp, trust_link);