How to get current data rate on Wi-Fi IPv4 Interface?

322 views
Skip to first unread message

Hassam Mughal

unread,
Nov 11, 2019, 12:57:20 AM11/11/19
to ns-3-users
Greetings everyone!
I have searched extensively in the Doxygen, but I am unable to identify from where can I get current data rate and available bandwidth on a Wi-Fi Interface. Please, can anyone help me in this regard?
Thanks

Hassam Mughal

unread,
Nov 11, 2019, 7:44:37 AM11/11/19
to ns-3-users
Is there anyone who can help me in this regard, please?

Jared Dulmage

unread,
Nov 11, 2019, 1:27:22 PM11/11/19
to ns-3-users
This question is somewhat ambiguous since there is no "set" data rate in wifi.  Each packet can be sent at its own data rate which is contained in a WifiTxVector.  Perhaps what you're looking for is WifiRemoteStationManager::GetDefaultMode which returns a WifiMode which can be used to get the data rate with said WifiTxVector.which may be had via WifiRemoteStationManager::GetDataTxVector. You'll see that this depends on a number of parameters of the packet and wifiheader being transmitted.  

Hope this helps,
Jared.

Hassam Mughal

unread,
Nov 12, 2019, 12:05:32 AM11/12/19
to ns-3-users
Dear Jared,

Thanks a lot. I will look into it. But can you just clear two more queries?
Is there any difference between the data rate set for an application and the data mode set through the WifiRemoteStationManager?
And is there any possibility that if we use ConstantRateWifiManager, we can still observe some change in data rates when we increase network traffic or the number of mobile ad hoc nodes in the network? 
Or due to mobility if the distance is increasing then the data rate is changed due to signal strength between two mobile ad hoc nodes?
Thanks

Jared Dulmage

unread,
Nov 12, 2019, 9:47:36 AM11/12/19
to ns-3-users
Answer to the first ? is yes, the (set) application data rate is independent of the wifi (over-the-air) rate.  Since you have a packet error model, it would be expected that even at a single over-the-air data rate you would experience various levels of packet errors, depending on distance.  This would result in different application layer data rates.  The way I usually look at these dynamic metrics is to output pcap traces and then use wireshark to analyze the time-varying throughput.  Wireshark will even graph it for you.

Jared.

Hassam Mughal

unread,
Nov 13, 2019, 8:05:40 AM11/13/19
to ns-3-users
Dear Jared,
A bundle of thanks for the explanation. Through pcap traces it is easy to analyze but the problem occurs when I need to get those values periodically during simulation in order to perform task scheduling.
Anyways, I will start working on it and will get back to you soon.
Thanks again.

Hassam Mughal

unread,
Nov 18, 2019, 4:12:00 AM11/18/19
to ns-3-users
Dear Jared, 
I have gone through these, and I have found the following methods and a member variable that can get the data rate;

uint64_t ns3::WifiMode::GetDataRate(WifiTxVector txVector) const;
uint64_t ns3::WifiMode::GetDataRate(uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const;
uint64_t ns3::WifiMode::GetDataRate(uint16_t channelWidth) const;

ns3::WifiMode::GetCodeRate (void) const;

uint64_t ns3::WifiMode::GetPhyRate (uint16_t channelWidth, uint16_t guardInterval, uint8_t nss) const;
uint64_t ns3::WifiMode::GetPhyRate(WifiTxVector txVector) const;
uint64_t ns3::WifiMode::GetPhyRate(uint16_t channelWidth) const;

The values of GetPhyRate(WifiTxVector txVector) and GetDataRate(WifiTxVector txVector) do change whenever a packet is sent or received but the values of GetCodeRate or m_cbrRate.GetBitRate() remain same always. Which one should I use in order to calculate data transfer time among mobile devices?

On Tuesday, November 12, 2019 at 11:47:36 PM UTC+9, Jared Dulmage wrote:

Jared Dulmage

unread,
Nov 18, 2019, 11:59:42 AM11/18/19
to ns-3-users
You can investigate how the wifiphy does it.

Jared.

Hassam Mughal

unread,
Nov 25, 2019, 11:19:17 AM11/25/19
to ns-3-users
Dear Jared,

I hope you are doing good. I investigated on this but the problem is, how can I get WifiTxVector in my manet-routing-compare.cc class which is an application layer class? In order to create an object of WifiTxVector I need to have different parameters. Because in WifiPhy, WifiTxVector is passed as an argument in every method. Hence, I am unable to find any solution to getting the value of GetDataRate in manet-routing-compare.cc class. Moreover, I tried to use this method: uint64_t ns3::WifiMode::GetDataRate(uint16_t channelWidth) const; but even after passing 22 or 11 or any int number as a parameter it says invalid arguments.

Hassam Mughal

unread,
Nov 26, 2019, 5:05:06 AM11/26/19
to ns-3-users
Dear Jared,

I have attached the file. I have included the dataRate trace source as well for MinstrelHtWifiManager. But this trace source is not being called in the simulation. Even if I am calling this: before Simulator::Run(); 
Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$ns3::MinstrelHtWifiManager", MakeCallback (&dataRate));

Any suggestions or guidelines in this regard will be highly appreciated.
Thanks
Regards,
Hassam
manet-routing-compare.cc

Jared Dulmage

unread,
Dec 1, 2019, 8:40:03 PM12/1/19
to ns-3-users
The first thing that comes to mind is that you hook up the trace by using the trace name:


Config::ConnectWithoutContext("/NodeList/*/DeviceList/*/$ns3::WifiNetDevice/RemoteStationManager/$ns3::MinstrelHtWifiManager/Rate", MakeCallback (&dataRate));


Let me know if that works.

Jared.

Hassam Mughal

unread,
Dec 2, 2019, 6:03:39 AM12/2/19
to ns-3-users
Dear Jared,

A bundle of thanks for pointing out the silly mistake I did. It's working now. However, is it possible to call it every time the data rate changes? Because as in this log output, the data rate is changing at the physical layer in YansWifiPhy but the trace is not fired.

Captured.PNG

Ahmad Hasan

unread,
Dec 2, 2019, 6:20:55 AM12/2/19
to ns-3-...@googlegroups.com
Hi Sir!

I hope this message finds you in good health. Sir I am working on Simulation of Sybil Attack in NS3. Actually I have worked upon Blackhole, Greyhole, and Wormhole Attack in NS3. But in this attack I do not know How to assign Fake IDs to Malicious Node to attack at Network. Please Guide me how to do this or any helping material or code if you have.

I'll be grateful. Stay blessed.

--
Posting to this group should follow these guidelines https://www.nsnam.org/wiki/Ns-3-users-guidelines-for-posting
---
You received this message because you are subscribed to the Google Groups "ns-3-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/d8fc1316-886a-4b77-bec6-3b8fc7911d31%40googlegroups.com.

Jared Dulmage

unread,
Dec 2, 2019, 10:26:20 AM12/2/19
to ns-3-users
Hassam,

I don't see where most of those debug messages come from, they're not in the current YansWifiPhy::StartTx.  Did you add them?  Without context, that message you highlight could be coming from anywhere.  I'd suggest tracking it down (perhaps adding a prefix_all to your log string) and seeing if it's relevant.  I imagine the trace is being called whenever it's hit.  If that's not the only place that the rate is changed, then you may need multiple traces pointing to your callback.

Good luck,
Jared.

Hassam Mughal

unread,
Dec 2, 2019, 10:37:16 AM12/2/19
to ns-3-users
Jared,

Yes, I have added those logs in YansWifiPhy.cc.

NS_LOG_DEBUG ("Code Rate: " << txVector.GetMode().GetCodeRate());
NS_LOG_DEBUG ("Data Rate: " << txVector.GetMode().GetDataRate(txVector));
NS_LOG_DEBUG ("Data Phy Rate: " << txVector.GetMode().GetPhyRate(txVector));

I am printing these values from the above-mentioned methods. So I think the values are getting changed based on MAC layer as well. Is it so? Anyways, I am getting the physical layer value through packet tags and using the trace as well and getting the value in manet-routing-compare.cc class.

Hasan H

unread,
Jan 8, 2020, 4:35:07 AM1/8/20
to ns-3-users
Hi Ahmad,
Could you please advice how did you simulate Blackhole, Greyhole, and Wormhole Attack in NS3?

Thank you in advance
To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-...@googlegroups.com.

NINJA INFO

unread,
Jan 9, 2020, 10:11:40 AM1/9/20
to ns-3-...@googlegroups.com
Hi,

Please check this link. This page have some NS3 source code. It may helpful for you.


To unsubscribe from this group and stop receiving emails from it, send an email to ns-3-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/ns-3-users/29305e82-6b55-4b8a-9281-8d8f6206f3a3%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages