How Do I Obtain the RSSI Value of a STA or AP in NS3?

316 views
Skip to first unread message

susu ya

unread,
Feb 23, 2024, 8:57:34 AM2/23/24
to ns-3-users
The following method was originally from Mr.Adil Alsuhaim and his video: https://www.youtube.com/watch?v=TuETIX7M2cY .
-------------------------------------
To get the RSSI, you need to connect to a TraceSource called "MonitorSnifferRx" belonging to the ns3::WifiPhy class, and this depends on whether you are using a WifiNetDevice or WaveNetDevice. The documentation of ns3::WifiPhy states that it can be accessed as follows

For WifiNetDevice: "/NodeList/[i]/DeviceList/[i]/$ns3::WifiNetDevice/Phy"
For WaveNetDevice: "/NodeList/[i]/DeviceList/[i]/$ns3::WaveNetDevice/PhyEntities/[i]"
What you can do to access the TraceSource is use the string, and create a callback function with the proper signature, let's say the function is called PromiscHandler. You can use Config::Connect after you have created the nodes & configured their devices as follows:

//If using WifiNetDevice
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/MonitorSnifferRx", MakeCallback (&PromiscHandler));

//if using WaveNetDevice (for WAVE/DSRC)
Config::Connect ("/NodeList/*/DeviceList/*/$ns3::WaveNetDevice/PhyEntities/*/MonitorSnifferRx", MakeCallback (&PromiscHandler));

and then create PromiscHandler as follows

void PromiscHandler (std::string context, Ptr<const Packet> packet, uint16_t channelFreq, WifiTxVector tx, MpduInfo mpdu, SignalNoiseDbm sn)
{
    std::cout << "Context : " << context << std::endl;
    std::cout << " Signal: " << sn.signal << " Noise: " << sn.noise << std::endl;
}
The context string matches the source of the event. You can use string manipulation functions to get the node id.

Keep in mind that in older versions of ns-3, if the string you used in Config::Connect didn't find a match, then nothing happens. I believe starting from ns-3.31, the call will fail if no matches were found, and a new function called Config::ConnectFailSafe is added which returns true if a match was found, and false otherwise. 
---------------------------------

But the signal strength and noise intensity are (probably?) different from the RSSI, and I don't think they can be treated as the same type.

I accidentally saw some structs containing RSSI in src/wifi/model/phy-entity.h in my leisure, does this mean that NS3 can directly help us get RSSI values? Or is this a breakthrough point to solve the problem?

Here's the code I found
/// RxSignalInfo structure containing info on the received signal
struct RxSignalInfo
{
double snr; ///< SNR in linear scale
double rssi; ///< RSSI in dBm
};

I hope I don't disturb with dumb questions!
Thank you!

Tommaso Pecorella

unread,
Feb 23, 2024, 4:45:01 PM2/23/24
to ns-3-users
Hi, it isn't a dumb question at all !

Actually the two are the same - sort of. If you read the code, you'll find this:
    RxSignalInfo rxSignalInfo;
    rxSignalInfo.snr = rxInfo.second.signal / rxInfo.second.noise;
    rxSignalInfo.rssi = rxInfo.second.signal;

so, basically, the rssi is the "signal" in the above structure, and the noise... well, it's the noise. The RxSignalInfo is not passed by the trace probably because it's very easy to calculate.
Internally, however, the code later on uses the snr and rssi to do its math, so it makes sense to pre-compute them.

Note that, as usual, a high rssi might not be enough, as you might have an excellent rssi, a huge noise figure, and your packets will be lost anyway. The rssi only tells you half the story.

susu ya

unread,
Feb 24, 2024, 4:41:43 AM2/24/24
to ns-3-users
I get it, this will allow my experiments to continue, thank you Tommaso
Reply all
Reply to author
Forward
0 new messages