How to Calculate Network Received Signal Strength in NS2
To calculate the Received Signal Strength (RSS) in NS2, we require mimicking a wireless network scenario in which nodes are transferring the packets, and the signal strength is estimated according to the propagation model and other wireless parameters. The received signal strength (RSS) is usually assess in dBm (decibels relative to one milliwatt) and is influenced by factors such as distance, transmission power, and the wireless environment.
NS2 delivers numerous propagation models such as TwoRayGround, FreeSpace, Shadowing that control the received signal strength according the distance among the transmitter and the receiver.
The following are the detailed procedures to calculate the Received Signal Strength in ns2:
Key Components to Calculate Received Signal Strength:
- Propagation Model: Describes how the signal decays as it propagates across space (e.g., FreeSpace, TwoRayGround).
- Transmission Power: Power at which the signal is routed (TxPower).
- Distance between Nodes: The further the nodes are from each other, the lower the signal strength.
Steps to Calculate Received Signal Strength (RSS) in NS2:
- Set up Wireless Network and Propagation Model: Utilize a wireless channel and set a propagation model that estimate signal strength in terms node distances and other factors.
- Define Transmission Power: The transmission power of each node is a key factor in defining the RSS. This is definite in the node’s wireless metrics.
- Run the Simulation and Generate the Trace File: The trace file will contains the data about the packets being sent and received, and the RSS can be resulting from the propagation model.
- Calculate RSS: NS2 computes RSS internally using the propagation model; however we can also access and estimate it directly by adapting the NS2 source code or by parsing the output.
Example Tcl Script to set up a Wireless Network in NS2:
Here’s a sample script that configure a simple wireless network in which nodes communicate, and the propagation model is used to compute the received signal strength.
# Create a new simulator instance
set ns [new Simulator]
# Set wireless network parameters
set val(chan) Channel/WirelessChannel
set val(prop) Propagation/TwoRayGround ;# Propagation model (can also use FreeSpace)
set val(netif) Phy/WirelessPhy
set val(mac) Mac/802_11
set val(ifq) Queue/DropTail/PriQueue
set val(ll) LL
set val(ant) Antenna/OmniAntenna
set val(ifqlen) 50
set val(x) 500 ;# X dimension of the topography
set val(y) 500 ;# Y dimension of the topography
# Define transmission power and receive sensitivity
set val(txPower) 0.2818 ;# Transmission power (in watts)
set val(rxPower) 0.0001 ;# Reception power (in watts)
# Set up two nodes
set node0 [$ns node]
set node1 [$ns node]
# Set the initial positions for the nodes
$node0 set X_ 50.0
$node0 set Y_ 50.0
$node0 set Z_ 0.0
$node1 set X_ 100.0
$node1 set Y_ 100.0
$node1 set Z_ 0.0
# Define the wireless link and the propagation model
set chan_1 [new $val(chan)]
# Attach an application to generate traffic (CBR)
set udp0 [new Agent/UDP]
set null0 [new Agent/Null]
$ns attach-agent $node0 $udp0
$ns attach-agent $node1 $null0
$ns connect $udp0 $null0
# Create a CBR traffic source
set cbr0 [new Application/Traffic/CBR]
$cbr0 attach-agent $udp0
$cbr0 set packetSize_ 512
$cbr0 set rate_ 1Mb
# Schedule traffic start and stop times
$ns at 1.0 “$cbr0 start”
$ns at 5.0 “$cbr0 stop”
# Open trace file to record events
set tracefile [open trace.tr w]
$ns trace-all $tracefile
# Define the finish procedure to close trace file and stop the simulation
proc finish {} {
global ns tracefile
$ns flush-trace
close $tracefile
exit 0
}
# Schedule end of simulation
$ns at 6.0 “finish”
# Run the simulation
$ns run
- Trace File Analysis for RSS:
Since NS2 doesn’t log RSS values straight in the default trace file, we can calculate it based on the propagation model and node positions.
- Modifying the NS2 Source Code to Log RSS:
To natively log the received signal strength, we adapt the Phy/WirelessPhy class in NS2. In particular we can adapt the recv function in the wireless-phy.cc file to print the RSS when packets are received.
- Open the file ~/ns-allinone-2.xx/ns-2.xx/phy/wireless-phy.cc.
- In the WirelessPhy::recv(Packet *p, Handler *h) function, enlarge code to log the received power.
For instance, add the following lines to print the received power (RSS):
void WirelessPhy::recv(Packet *p, Handler *h) {
hdr_cmn* hdr = HDR_CMN(p);
double Pr = p->txinfo_.getTxPr(); // Received power
printf(“Time: %g, Node: %d, Received Power: %g W\n”, NOW, index_, Pr);
// Existing code follows
…
}
This will print the received power for each packet when it is received.
- Calculate RSS Using the Propagation Model:
On the other hand, we can utilize the formulas for RSS according to the propagation model being used. Below are two commonly used propagation designs in NS2:
FreeSpace Model:
The FreeSpace propagation model estimates the RSS using the formula:
Pr=Pt⋅Gt⋅Gr⋅λ2(4πd)2⋅LP_r = \frac{P_t \cdot G_t \cdot G_r \cdot \lambda^2}{(4 \pi d)^2 \cdot L}Pr=(4πd)2⋅LPt⋅Gt⋅Gr⋅λ2
Where:
- PrP_rPr = received power.
- PtP_tPt = transmitted power.
- GtG_tGt and GrG_rGr = gains of the transmitting and receiving antennas.
- λ\lambdaλ = wavelength of the signal.
- ddd = distance among the transmitter and receiver.
- LLL = system loss.
TwoRayGround Model:
The TwoRayGround model is more accurate for longer distances and estimates the RSS as:
Pr=Pt⋅Gt⋅Gr⋅ht2⋅hr2d4P_r = \frac{P_t \cdot G_t \cdot G_r \cdot h_t^2 \cdot h_r^2}{d^4}Pr=d4Pt⋅Gt⋅Gr⋅ht2⋅hr2
Where:
- PrP_rPr = received power.
- PtP_tPt = transmitted power.
- GtG_tGt and GrG_rGr = antenna gains.
- hth_tht and hrh_rhr = heights of the transmitting and receiving antennas.
- ddd = distance among the transmitter and receiver.
We can compute the RSS for each packet using these formulas according to the nodes’ positions and the transmission power.
- Parsing the Output to Calculate RSS:
Once we will altered NS2 to log the RSS or are using a propagation model formula, we can parse the output and estimate the RSS for each packet.
For instance, if we utilize a formula such as the TwoRayGround model, we can compute the RSS using:
# Extract node distances and calculate RSS for each received packet
awk ‘{
Pr = $8; # Replace with your received power calculation logic
print “Received Signal Strength: ” Pr ” W”;
}’ trace.tr
Summary:
- Set up the simulation with a propagation model such as TwoRayGround, FreeSpace to define how signals disseminate.
- Run the simulation to create a trace file.
- Modify the NS2 source code if required to log the received signal strength (RSS).
- Calculate RSS using the output from the trace file or the propagation model formulas (TwoRayGround, FreeSpace).
In the structured manual, we validate the comprehensive procedures to computed and evaluate the Received Signal Strength that has key components, implementation procedures and snippets were given to measure in ns2 tool. Additional specific details regarding the Received Signal Strength will be provided.
We assist you in calculating the Network Received Signal Strength using the NS2 tool, tailored to your project ideas and topics that we provide. Engage with our experts to complete your tasks efficiently. Our team specializes in propagation models and various wireless parameters for your projects. Please share all relevant project details with us, and we will offer our support.