How to get current node in network simulator 2

‘index’ is one of the important variables in NS2. It is the id of node on which current event is occurring. To understand it, let us use it somewhere in a source code. A part of code from aodv.cc is shown here. let us print the value of index here. since it is the node id, it must be an integer. Bold line has been inserted by me to print.

#########################################################

void
AODV::sendRequest(nsaddr_t dst) {
// Allocate a RREQ packet
Packet *p = Packet::alloc();
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
struct hdr_aodv_request *rq = HDR_AODV_REQUEST(p);
aodv_rt_entry *rt = rtable.rt_lookup(dst);

assert(rt);

printf(“current node is %d \n”, index);

/*
* Rate limit sending of Route Requests. We are very conservative
* about sending out route requests.
*/

if (rt->rt_flags == RTF_UP) {
assert(rt->rt_hops != INFINITY2);
Packet::free((Packet *)p);
return;
}

#########################################################

You are advised to add this line too and follow the following blog to reflect these changes and run a Tcl file in which aodv routing protocol is used. You will see some lines printing in the terminal showing the current node.

Raghavendra Pal

I have completed B.tech in Electronics and communication Engineering from Tezpur University, Assam in 2014. M.Tech in Communication systems from Motilal Nehru National Institute of Technology Allahabad in 2016. Currently pursuing Ph.D. in the domain of Wireless communication.

This Post Has One Comment

  1. It is magic. I was always worried about how to get which node is transmitting or receiving. It helped me a lot. thanks.

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Close Menu
×

Cart

Close Panel
Skip to toolbar