Skip to main content

Posts

Showing posts from June, 2013

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 aodv.cc withing rt_resolve() method, rt_print(0); 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] = "";     sprintf(tmp,"%d",node_id);     strcat(tmpFileName,tmp);        tmpFile = fopen(tmpFileName, "w");     aodv_rt_entry *rt;        for (rt = rtable.head(); rt; rt = rt->rt_link.le_next)     {         fprintf(             tmpFile,             "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);     }     fclose(tmpFile); } All the Best!

How to add trust table in NS2.

I am assuming AODV protocol. In rtable.cc add below code trust_entry::trust_entry() {    //Initialize as per your need. } trust_entry::~trust_entry() {   //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)                  break;      }     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;     } } trust_entry* trust_store::trust_insert( 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;     assert(rp);     rp->node_id = node_id;     rp->prev_node = prev_node;     rp->next_node = next_node;     rp->trust_value = trust_value;     LIS