Class for representing data rates. More...
#include <data-rate.h>
Public Member Functions | |
| DataRate () | |
| DataRate (uint64_t bps) | |
| Integer constructor. More... | |
| DataRate (std::string rate) | |
| String constructor. More... | |
| Time | CalculateBitsTxTime (uint32_t bits) const |
| Calculate transmission time. More... | |
| Time | CalculateBytesTxTime (uint32_t bytes) const |
| Calculate transmission time. More... | |
| double | CalculateTxTime (uint32_t bytes) const NS_DEPRECATED |
| Calculate transmission time. More... | |
| uint64_t | GetBitRate () const |
| Get the underlying bitrate. More... | |
| bool | operator!= (const DataRate &rhs) const |
| bool | operator< (const DataRate &rhs) const |
| bool | operator<= (const DataRate &rhs) const |
| bool | operator== (const DataRate &rhs) const |
| bool | operator> (const DataRate &rhs) const |
| bool | operator>= (const DataRate &rhs) const |
Static Private Member Functions | |
| static bool | DoParse (const std::string s, uint64_t *v) |
| Parse a string representing a DataRate into an uint64_t. More... | |
Private Attributes | |
| uint64_t | m_bps |
| data rate [bps] More... | |
Friends | |
| std::istream & | operator>> (std::istream &is, DataRate &rate) |
| Stream extraction operator. More... | |
Class for representing data rates.
Allows for natural and familiar use of data rates. Allows construction from strings, natural multiplication e.g.:
This class also supports the regular comparison operators <, >, <=, >=, ==, and !=
Data rate specifiers consist of
Whitespace is allowed but not required between the numeric value and multipler or unit.
Supported multiplier prefixes:
| Prefix | Value |
|---|---|
| "k", "K" | 1000 |
| "Ki" | 1024 |
| "M" | 1000000 |
| "Mi" | 1024 Ki |
| "G" | 10^9 |
| "Gi " | 1024 Mi |
Supported unit strings:
| Symbol | Meaning |
|---|---|
| "b" | bits |
| "B" | 8-bit bytes |
| "s", "/s" | per second |
Examples:
Definition at line 88 of file data-rate.h.
| ns3::DataRate::DataRate | ( | ) |
Definition at line 187 of file data-rate.cc.
References NS_LOG_FUNCTION.
| ns3::DataRate::DataRate | ( | uint64_t | bps | ) |
Integer constructor.
Construct a data rate from an integer. This class only supports positive integer data rates in units of bits/s, meaning 1bit/s is the smallest non-trivial bitrate available.
| bps | bit/s value |
Definition at line 193 of file data-rate.cc.
References NS_LOG_FUNCTION.
| ns3::DataRate::DataRate | ( | std::string | rate | ) |
String constructor.
Construct a data rate from a string. Many different unit strings are supported Supported unit strings: bps, b/s, Bps, B/s
kbps, kb/s, Kbps, Kb/s, kBps, kB/s, KBps, KB/s, Kib/s, KiB/s
Mbps, Mb/s, MBps, MB/s, Mib/s, MiB/s
Gbps, Gb/s, GBps, GB/s, Gib/s, GiB/s
Examples: "56kbps" = 56,000 bits/s
"128 kb/s" = 128,000 bits/s
"8Kib/s" = 1 KiB/s = 8192 bits/s
"1kB/s" = 8000 bits/s
| rate | string representing the desired rate |
Definition at line 255 of file data-rate.cc.
References DoParse(), m_bps, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
Here is the call graph for this function:| Time ns3::DataRate::CalculateBitsTxTime | ( | uint32_t | bits | ) | const |
Calculate transmission time.
Calculates the transmission time at this data rate
| bits | The number of bits (not bytes) for which to calculate |
Definition at line 242 of file data-rate.cc.
References m_bps, NS_LOG_FUNCTION, and ns3::Seconds().
Here is the call graph for this function:| Time ns3::DataRate::CalculateBytesTxTime | ( | uint32_t | bytes | ) | const |
Calculate transmission time.
Calculates the transmission time at this data rate
| bytes | The number of bytes (not bits) for which to calculate |
Definition at line 235 of file data-rate.cc.
References m_bps, NS_LOG_FUNCTION, and ns3::Seconds().
Referenced by ns3::CsmaNetDevice::Attach(), ns3::SimpleNetDevice::SendFrom(), ns3::HalfDuplexIdealPhy::StartTx(), ns3::SimpleNetDevice::TransmitComplete(), ns3::PointToPointNetDevice::TransmitStart(), and ns3::CsmaNetDevice::TransmitStart().
Here is the call graph for this function:
Here is the caller graph for this function:| double ns3::DataRate::CalculateTxTime | ( | uint32_t | bytes | ) | const |
Calculate transmission time.
Calculates the transmission time at this data rate
| bytes | The number of bytes (not bits) for which to calculate |
Definition at line 229 of file data-rate.cc.
References m_bps, and NS_LOG_FUNCTION.
|
staticprivate |
Parse a string representing a DataRate into an uint64_t.
Allowed unit representations include all combinations of
| [in] | s | The string representation, including unit |
| [in,out] | v | The location to put the value, in bits/sec. |
Definition at line 34 of file data-rate.cc.
References NS_LOG_FUNCTION.
Referenced by DataRate(), and ns3::operator>>().
Here is the caller graph for this function:| uint64_t ns3::DataRate::GetBitRate | ( | ) | const |
Get the underlying bitrate.
Definition at line 249 of file data-rate.cc.
References m_bps, and NS_LOG_FUNCTION.
Referenced by ns3::OnOffApplication::CancelEvents(), ns3::RedQueue::InitializeParams(), ns3::operator*(), ns3::operator<<(), ns3::OnOffApplication::ScheduleNextTx(), MyApp::ScheduleTx(), SimpleSource::ScheduleTx(), and Ipv4DynamicGlobalRoutingTestCase::SendData().
Here is the caller graph for this function:| bool ns3::DataRate::operator!= | ( | const DataRate & | rhs | ) | const |
| rhs | the datarate to compare to this datarate |
Definition at line 224 of file data-rate.cc.
References m_bps.
| bool ns3::DataRate::operator< | ( | const DataRate & | rhs | ) | const |
| rhs | the datarate to compare to this datarate |
Definition at line 199 of file data-rate.cc.
References m_bps.
| bool ns3::DataRate::operator<= | ( | const DataRate & | rhs | ) | const |
| rhs | the datarate to compare to this datarate |
Definition at line 204 of file data-rate.cc.
References m_bps.
| bool ns3::DataRate::operator== | ( | const DataRate & | rhs | ) | const |
| rhs | the datarate to compare to this datarate |
Definition at line 219 of file data-rate.cc.
References m_bps.
| bool ns3::DataRate::operator> | ( | const DataRate & | rhs | ) | const |
| rhs | the datarate to compare to this datarate |
Definition at line 209 of file data-rate.cc.
References m_bps.
| bool ns3::DataRate::operator>= | ( | const DataRate & | rhs | ) | const |
| rhs | the datarate to compare to this datarate |
Definition at line 214 of file data-rate.cc.
References m_bps.
|
friend |
Stream extraction operator.
| is | the stream |
| rate | the data rate |
Definition at line 272 of file data-rate.cc.
|
private |
data rate [bps]
Definition at line 217 of file data-rate.h.
Referenced by CalculateBitsTxTime(), CalculateBytesTxTime(), CalculateTxTime(), DataRate(), GetBitRate(), operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().