In NS2 ..in TCL file, how can I calculate number of Hops in one path to reach the destination in wireless Network?
I need your help.
In NS2 ..in TCL file, how can I calculate number of Hops in one path to reach the destination in wireless Network?
I need your help.
You must do that in the protocol's codes...
First of all i don't know which protocol you want to use, but fortunately the protocols in ns2 are very similar to each other... So i will c guide you to how to do it.
I will use AODV protocol as a sample...
In theory :
We'll say when a RREQ packet has arrived, increment the packet hop count for current rout...
This is the simplest way :
Now open
aodv.cc
For example/ns-allinone-2.35/ns-2.35/aodv/aodv.cc
and in the lines that says :Click Enter after
if (rq->rq_dst == index) {
and write :This Code will print the hop count for each packet that arrived to the destination.
In terminal
cd
into your ns2 directory and typemake
and click Enter. For example :This is the hardest way :
In code :
Open
aodv_packet.h
from your ns2 directory... For example/ns-allinone-2.35/ns-2.35/aodv/aodv_packet.h
Find
struct hdr_aodv_request {
and create an interget variable in it calledhop_count_
...Like :
struct hdr_aodv_request { int hop_count_;
Now open
aodv.cc
from/ns-allinone-2.35/ns-2.35/aodv/aodv.cc
and find the definition ofsendRequest(Packet *p)
function that might look likevoid AODV::sendRequest(nsaddr_t dst) {
...Now in this function you must see some codes like :
And where it says
rq->rq_timestamp = CURRENT_TIME;
just click Enter and write the blow code :Now you need to find the definition of
recvRequest(Packet *p)
that might look likevoid AODV::recvRequest(Packet *p) {
...In this function find the lines that says :
After
else {
click Enter and write :In terminal
cd
into your ns2 directory and typemake
and click Enter. For example :Now for printing you can use the first solution that i wrote above.