Determine Traffic Load of node in NS-2

Traffic load of a node can be estimated by routing protocol using number of packets currently enqueued in Interface Queue 'ifqueue' using:


As number of packets increases, its length increases.

​A good approach is to estimate traffic load based on time interval between two received data packets.

Network Simulator NS-2 Tutorials

Determine Energy of node in NS-2

In NS-2, node's energy can be retrieved using mobilenode.h file functions/variables. For example in AODV routing protocol, first include mobilenode.h file in aodv.h file:


Similarly in aodv.h file, declare myNode pointer of type mobilenode in class AODV: public Agent in protected scope.

double myEnergy;
MobileNode *myNode;

In file , add following to aodv constructor:

MobileNode *myNode;myEnergy = 0.0;

Now node's current energy can be fetched as follow:

myNode = (MobileNode *)(Node::get_node_by_address(index));
myEnergy = myNode->energy_model()->energy();

In tcl file make sure to include energy model in node config parameters.In $ns_ node-config parameters add:

​-energyModel    EnergyModel    \
-initialenergy     100    \

For new learners of NS-2, the book "Introduction to Network Simulator NS2" by Teerawat Issariyakul & Ekram Hossain is a must read. Along with that, NS-2 Manual is also very handy and useful.

Determine Received Signal Strength in NS-2

In NS-2, Received Signal Strength (Power) of the packet received at routing layer can be accessed as:


where p is pointer of type packet i.e 
packet *p

​Assign this value to variable of double type. The value returned of received power will be in watts.

​For example in AODV routing protocol code, goto file and in function
void AODV::recvRequest(Packet *p)

double rec_power;rec_power = p->txinfo_.RxPr;

​Therefore when ever RREQ packet is received by a node, its received signal strength (Power) will be calculated and saved in variable rec_power. To convert received power from Watts to dBm, use expression:

​rec_power_dBm = 10log10[rec_power] + 30;

​SNR is calculated as:

SNR = rec_power_dBm - NPdBm

where NPdBm is Noise Power. The typical value of NPdBm is 90.

Copyright © 2019 Hasan Farooq. All rights reserved.

Setting Communication Range in NS-2

To set communication range in NS-2, find RXThresh_ value for desired communication range and use that value in your tcl file.

To get RXThresh_ value, first you have to compile file found at: 


using command: 

g++ -lm -o threshold

After compiling successfully, run this utility and specify options (such as Propagation model, Transmit Power, Frequency etc) and desired communication range and it will return RXThresh_value. Use this value in your tcl file as:

Phy/WirelessPhy set RXThresh_ xxxxxxxx

​where xxxxxxxx is the value returned from threshold utility

For specifying CSThresh_ value, commonly CSRange:TXRange ratio used is 2.2 . So If your TXRange is 250m, use threshold utility again to compute value for 2.2 * 250m =  550m and use the returned value for CSThresh_ in your tcl file as:

Phy/WirelessPhy set CSThresh_ xxxxxxxx

Hasan Farooq