Simple ad-hoc example and RSSI

1,680 views
Skip to first unread message

Con con

unread,
Dec 12, 2016, 8:07:20 AM12/12/16
to ns-3-users
Hello all,
I am new to NS3. Actually I am trying to learn NS3 last weeks using the examples and the documentation found in the website. I am using the example wifi-simple-adhoc-grid in which I change some parameters and see the differencies.
What I am trying to achive now is to show the received RSSI in the receiving node. I can see this information in the logs but I didn't find a way to get this information using the C++ code. For example in the logs I can find the following info
bandwidth(MHz)=22, signal(W)= 4.32242e-09, noise(W)=4.41361e-13, interference(W)=0, snr(linear)=9793.39
If I convert the signal(W) into dBm the results seems to be correct. How can I get these information and the packet received delay using C++.
Thanks.!!

Tommaso Pecorella

unread,
Dec 14, 2016, 8:53:34 PM12/14/16
to ns-3-users
Hi,

the short answer is: traces and the data collection framework. The long answer is... have you read the tutorial ?

Cheers,

T.

Con con

unread,
Dec 18, 2016, 8:45:19 AM12/18/16
to ns-3-users
Hello Tommaso, 
I have read the tutorial but I did not find an example that measure the received RSSI at predefined node. I saved the trace files but there is no such information there. What is actually the data collection framework ? Which tutorial do you mean actually ? 
Thanks for your answer. I am trying to start from basics but I think the documentation is not so helpful.

Tommaso Pecorella

unread,
Dec 24, 2016, 6:29:17 PM12/24/16
to ns-3-users
Hi,

Data collection is described here: Data Collection.
About the trace, it is well documented:
    .AddTraceSource ("MonitorSnifferRx",
                     
"Trace source simulating a wifi device in monitor mode "
                     
"sniffing all received frames",
                     
MakeTraceSourceAccessor (&WifiPhy::m_phyMonitorSniffRxTrace),
                     
"ns3::WifiPhy::MonitorSnifferRxTracedCallback")


Note that the trace will fire for all the received packets, even the ones not directed at that specific node. You'll have to filter the wanted/unwanted packets manually.

Have fun,

T.

Tommaso Pecorella

unread,
Dec 24, 2016, 6:30:11 PM12/24/16
to ns-3-users
Forgot... that trace source is in the WifiPhy

Con con

unread,
Dec 29, 2016, 4:01:31 AM12/29/16
to ns-3-users
Hello Tommaso, 
thanks for help. I will try this today and let you know. 
By the way, what is the best way you suggest to start learnig NS3. Assuming that I am a researcher I would like to gain a costructed and deep knowledge. 
thanks again.

Tommaso Pecorella

unread,
Jan 2, 2017, 10:00:02 PM1/2/17
to ns-3-users
Hi,

the best way is to study the examples and, if you don't understand something, dig in the code.
Moreover, a good suggestion is: don't be shy, ask the maintainer if you don't understand something and if you find a missing feature... implement it. The first time will be hard, the second time will be less hard, and so on.

Cheers,

T.

Con con

unread,
Jan 30, 2017, 5:24:27 PM1/30/17
to ns-3-users
Hello Tommaso,
I have managed to get the RSSI value I wanted. using the following export 

export 'NS_LOG=YansWifiPhy=level_all|prefix_func|prefix_time'

after that I run the program and get something like that 1s YansWifiPhy:StartReceivePreambleAndHeader(): sync to signal (power=1.08061e-08W). Converting that to dBm I get the correct value.
the problem now is that : 
if I change from 
wifi.SetStandard (WIFI_PHY_STANDARD_80211b); 2.4Ghz
to 
wifi.SetStandard (WIFI_PHY_STANDARD_80211a); 5 Ghz
The RSSI i get is always correct according to 2.4GHz. If I change to 5Ghz nothing change. 
What's the problem ? 
I get the same RSSI, which is not correct. On the other hand if I change the distance I get different RSSI which is correct. 
Thanks for support.
Best regards!

Tommaso Pecorella

unread,
Feb 1, 2017, 7:00:49 PM2/1/17
to ns-3-users
Hi,

you didn't dig in the code enough.
The YansWifiPhy:StartReceivePreambleAndHeader receives the power loss from the propagationLoss Model, which is set by YansWifihelper.
If you don't change anything, it's set to LogDistancePropagationLossModel, which is independent from the actual bandwidth used (5 or 2.4 GHz).
For real, you should tune the LogDistancePropagationLossModel parameters, and in particular the ReferenceLoss. By default it is set to... well, see for yourself, and read the detailed description.

Cheers,

T.

Con con

unread,
Feb 4, 2017, 4:51:46 AM2/4/17
to ns-3-users
Hello Tommaso,
Thanks for help anyway.
Yes exactly that's why I have the following code added,
YansWifiChannelHelper wifiChannel;
wifiChannel.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel");
I use FriisPropagationLossModel because it's easier to calculate if it's correct or not.

I would like to make a comment according to ns3 and please correct me if I am wrong. The example I am trying to run is like hello world of ns3 but it is so difficult ( at least I found it difficult) to implement. The whole concept is to create an ad-hoc network and calculate the RxGain in the receiver, find the propagation loss and calculate the throughput as a beginning for my project which is more complex. Maybe I am missing something.  

Tommaso Pecorella

unread,
Feb 4, 2017, 8:59:57 AM2/4/17
to ns-3-users
Hi,

what i said applies to Friis as well:

TypeId 
FriisPropagationLossModel::GetTypeId (void)
{
 
static TypeId tid = TypeId ("ns3::FriisPropagationLossModel")
   
.SetParent<PropagationLossModel> ()
   
.SetGroupName ("Propagation")
   
.AddConstructor<FriisPropagationLossModel> ()
   
.AddAttribute ("Frequency",
                   
"The carrier frequency (in Hz) at which propagation occurs  (default is 5.15 GHz).",
                   
DoubleValue (5.150e9),
                   
MakeDoubleAccessor (&FriisPropagationLossModel::SetFrequency,
                                       
&FriisPropagationLossModel::GetFrequency),
                   
MakeDoubleChecker<double> ())

You need to set the Frequency, or it will be set to the same value, regardless of the Wi-Fi standard you use.

About the "hello world" comparison, I can safely say that you're already trying stuff for chapter 3 of the book. The "hello world" is the 1st script of the tutorial.
And yes, ns-3 isn't so easy, sorry.

On the bright side, you raised an interesting point, I'll forward it to the Wi-Fi module maintainer.


Cheers,

T.

Con con

unread,
Feb 5, 2017, 2:59:50 PM2/5/17
to ns-3-users
Hello Tommaso,
First of all I would like to thank you for the reply and the productive discussion we have. It is the only way to improve open source projects. Finally I made it to work by setting the frequency as you said. Yes it's not easy and it's my fault if I am complaining about that, because it's an open source project. 
On the other side I will be happy to participate on that as soon as I learn how to use it, then start developing and contribute to the project. I was contributing in GDAL project in C++ as a developer. 
Another thing that I noticed is the following : I set the std::string phyMode ("DsssRate11Mbps"); which is working only in 2.4Ghz in 802.11b/g but if I set the frequency to 5.230e9 
wifiChannel.AddPropagationLoss ("ns3::FriisPropagationLossModel","Frequency",DoubleValue(5.230e9)); is also working. I think that a validation layer that makes all these checks is mandatory. 
Please correct me if I am wrong.
Thanks again.

Tommaso Pecorella

unread,
Feb 8, 2017, 10:47:30 AM2/8/17
to ns-3-users
Hi,

you're right. We have an enhancement request open in our tracker about this.

Cheers,

T.

Con con

unread,
Mar 29, 2017, 6:34:32 PM3/29/17
to ns-3-users
Hello Tommaso,
I am coming back again according to RxPower. Since my last post, I was able to get the received rssi using export 'NS_LOG=YansWifiPhy=level_all|prefix_func|prefix_time' . Since then I was able to write and use more complex examples but still did not find any way to get the received power of a packet using code ! Currently I am working in example ht-wifi-network.cc . I was able to extend this example(add validation either using 5Ghz or 2.4Ghz ) and able to simulate 802.11 ac but still I am not able to get the received signal strength.! I will be able to do many things and comparisons if I get this information. I will be able to get throughput, distance channel widths and so more, and even more with received signal strength. Could you assist me achieve that ?
Thanks.
Best Regards!

Konstantinos

unread,
Mar 30, 2017, 3:43:50 AM3/30/17
to ns-3-users
Hi,

Instead of NS_LOG, you can use traces from YansWifiPhy that provide the RxPower.
Particularly the MonitorSnifferRx will be triggered by any device when it receives a packet. 

Regards,
K

Con con

unread,
Apr 1, 2017, 10:09:41 AM4/1/17
to ns-3-users
Hello Konstantinos,
Thanks for reply. I have already try to use YansWifiPhy with the following code : 

Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/Phy/MonitorSnifferRx", MakeCallback (&PhyTrace));

And then I create the callback function PhyTrace which never fires. I remind you that I am working on the example ht-wifi-network.cc.
Do you know if this is correct ? But why it is not firing up ?
Thanks.

Konstantinos

unread,
Apr 1, 2017, 11:29:55 AM4/1/17
to ns-3-users
Please provide the test scenario and the ns-3 release you are using.

Con con

unread,
Apr 1, 2017, 2:42:24 PM4/1/17
to ns-3-users
Hello Konstantinos,
I am using ns-3.26 the last stable release. As you can see in ht-wifi-network.cc the scope is to compute the throughput between an AP and a STA. Except from that I would like to be able to show in another column the received RSSI in order to compare some data rate adoption algorithms. As soon as I will be able to achieve the RSSI I will change the mobility model and do further simulations etc.. thanks.!

Konstantinos

unread,
Apr 1, 2017, 6:39:36 PM4/1/17
to ns-3-users
As requested, please provide the test scenario that you mentioned the trace does not work.

Con con

unread,
Apr 2, 2017, 2:42:38 AM4/2/17
to ns-3-users
I run this ./waf --run "ht-wifi  --frequency=2.4 --distance=10 --udp=0 --simulationTime=1" and this
./waf --run "ht-wifi  --frequency=2.4 --distance=10 --udp=1 --simulationTime=1" . To test udp and tcp also. And the callback function is the following : 
void PhyTrace(Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm){

        WifiMacHeader header; 
        Ptr<Packet> m_currentPacket;
        m_currentPacket = packet->Copy(); 
        m_currentPacket->RemoveHeader (header); 
        Mac48Address source = header.GetAddr2(); 
        Mac48Address dest = header.GetAddr1();

std::cout<<"Packet received from " << source << " to " << dest << " on Chan " << channelNumber << " with Signal " << signalDbm << " and noise " << noiseDbm<< std::endl;
}
And the callback never fired.!

Konstantinos

unread,
Apr 2, 2017, 4:44:05 AM4/2/17
to ns-3-users
Hi,

As I said, you haven't provided the complete source code that I could run, you only said what you modified.
So, I went and created mine which is working. 

Sample output:

Packet received from 00:00:00:17:00:00 to 88:02:3c:00:00:00 on Chan 2412 with Signal -52.0254 and noise -97.9557

Packet received from 00:00:00:17:00:00 to 88:02:3c:00:00:00 on Chan 2412 with Signal -52.0254 and noise -97.9557

Packet received from 00:00:00:17:00:00 to 88:02:3c:00:00:00 on Chan 2412 with Signal -52.0254 and noise -97.9557

Packet received from 00:00:00:00:00:17 to 00:00:00:00:00:18 on Chan 2412 with Signal -52.0254 and noise -97.9557


You said you are working on ns-3.26, but your callback signature is not correct.
Check the API for ns-3.26
typedef void(* ns3::WifiPhy::MonitorSnifferRxCallback) (Ptr< const Packet > packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, WifiPreamble preamble, WifiTxVector txVector, struct mpduInfo aMpdu, struct signalNoiseDbm signalNoise)

Your callback signature is different
void PhyTrace(Ptr<const Packet> packet, uint16_t channelFreqMhz, uint16_t channelNumber, uint32_t rate, bool isShortPreamble, double signalDbm, double noiseDbm){

And I would expect to get error message during compilation. Not that it does not fire at runtime...

Con con

unread,
Apr 2, 2017, 5:47:16 AM4/2/17
to ns-3-users
Hello Konstantinos,
I have attached you the source code file.! I have used your signature, and as you can see in the callback function I used only a simple std::cout to check if the callback is called, but I never got this called! Please take a look. Thanks for your contribution.
ht-wifi.cc

Konstantinos

unread,
Apr 2, 2017, 6:06:43 AM4/2/17
to ns-3-users
Hi,

Please move your config connect close to the Simulator::Run() (e.g. after the call to populate the routing table).
This is because the NetDevices have NOT been created when you call the connect.

Con con

unread,
Apr 2, 2017, 8:44:58 AM4/2/17
to ns-3-users
Hello Konstantinos, you are correct!! Now it's working fine!!. As soon as I finish I would like to contribute with an example according to RSSI,SNR  and simple example of ns3 is it possible ?

Con con

unread,
Apr 2, 2017, 11:56:39 AM4/2/17
to ns-3-users
Although I used it successful I have some doubt about the validity of the results.  Using this calcuator http://www.daycounter.com/Calculators/Friis-Calculator.phtml I have entered my options and the rx gain is computed -68.1 db(25 meters FriisPropagations Loss). Using ns3 and the source code above I get -70.5953 db. 
Is there something I have to take care about ?

Konstantinos

unread,
Apr 3, 2017, 3:14:44 AM4/3/17
to ns-3-users
Hi,

You are NOT using Friis in your scenario. 

I know you have this:

...
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
phy.SetChannel (channel.Create ());
channel
.SetPropagationDelay ("ns3::ConstantSpeedPropagationDelayModel");
channel
.AddPropagationLoss ("ns3::FriisPropagationLossModel", "Frequency",DoubleValue(2.412e9));
...

However, this is incorrectly configured. The channel has been already created and set (with default values) and then you go and set some attributes.
These are never used. Even if you put them before the phy.SetChannel() method, your calculations would be off, and that's because the default Channel configuration which adds L
LogDistance propagation. You would then add, on top of that Friis.

We have discussed this in the list, and it should also be in the documentation, how to properly setup wifi channel.

Regards,
K

Con con

unread,
Apr 18, 2017, 5:01:06 AM4/18/17
to ns-3-users
Hello Konstaninos,
Thanks for help. This is the one thing that cause the problem. The other thing is the following code. 
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();

I changed it to YansWifiChannelHelper channel;
So then I am able to set channel parameters whatever I want. 
The question I have now is the following. 
HtMcs is related to RSSI. Where is defined this relation (something like an index or a map in C++) ?
This could be used for example if we would like to simulate using real WiFi chip values.! I searched in file wifi-mode.cc or wifi-phy.cc but these files does not include rssi as a factor, but I am sure that ns3 do that !
Thanks.!
Reply all
Reply to author
Forward
0 new messages