Skip to main content

How to print Routing table of each node in NS2

You need to pass node id as an argument to this method.
e.g. in withing rt_resolve() method,


This will print node 0's routing table at that time with file name as node_0.

void AODV::rt_print(nsaddr_t node_id)
    FILE * tmpFile;
    char tmpFileName[50] = "node_";
    char tmp[10] = "";
    tmpFile = fopen(tmpFileName, "w");

    aodv_rt_entry *rt;   

    for (rt = rtable.head(); rt; rt = rt->rt_link.le_next)

            "Node Id:%i Current time:%.4lf Destination:%i Next hop:%i No. of hops:%i Seq. No.:%i Route expire:%f Flags:%.4lf %d \n",
            node_id, CURRENT_TIME, rt->rt_dst, rt->rt_nexthop, rt->rt_hops,rt->rt_seqno, rt->rt_expire, rt->rt_flags);


All the Best!


  1. This comment has been removed by the author.

  2. Replies
    1. can you post a blog on detecting the malicious node in network using ns2.34 with code or please mail me the explanation or the code plz
      mail address :

  3. Can you please explain in detail .how 2 print routin table.Its ll really help me.Thanks in Advance

  4. hello Mr , how can i access to node_id and this variable is declared as protected in the file Node.h , is there any solution to do that ?

  5. where will the print statement in .cc file printed?

    1. you can use rt_print(index) in anywhere in as you like. For eg,u can use it in recvReply fun after update routing table or if (ih->daddr() == index) ... something like that.

  6. hi i am gaurav

    i want to print current node id in to comman/ file how can i

  7. Can u please mail me codes of aodv modified with watchdog in ns2
    So it'll be a great help from U...

  8. could u let us complete demo on ur above created routing table

  9. we are doing on same one,.............can we have brief xplanation on routing table

  10. Sir, I want to isolate the malicious node. Can you please tell me how can I do that?
    Please mail at

  11. Dear sir, I am using ns2-2.35 version. In TCL script when i define the energy model, all the nodes will be in green color. Can that be changed to any other color? (not dynamically in tcl). If so, pls explain me how.
    My mail id:

  12. can you please tell me how to give IDs to the nodes

  13. i m getting error in make command,,.. pls help me..

  14. i m getting error in make command,,.. pls help me..

  15. can you post a blog on detecting the malicious node in network using ns2.34 with code or please mail me the explanation or the code plz
    mail address :


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);