Class for representing data rates. More...
#include "data-rate.h"
Public Member Functions | |
DataRate () | |
DataRate (std::string rate) | |
String constructor. | |
DataRate (uint64_t bps) | |
Integer constructor. | |
Time | CalculateBitsTxTime (uint32_t bits) const |
Calculate transmission time. | |
Time | CalculateBytesTxTime (uint32_t bytes) const |
Calculate transmission time. | |
uint64_t | GetBitRate () const |
Get the underlying bitrate. | |
bool | operator!= (const DataRate &rhs) const |
DataRate | operator* (double rhs) const |
Scales the DataRate. | |
DataRate | operator* (uint64_t rhs) const |
Scales the DataRate. | |
DataRate & | operator*= (double rhs) |
Scales the DataRate. | |
DataRate & | operator*= (uint64_t rhs) |
Scales the DataRate. | |
DataRate | operator+ (DataRate rhs) const |
DataRate & | operator+= (DataRate rhs) |
DataRate | operator- (DataRate rhs) const |
DataRate & | operator-= (DataRate rhs) |
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. | |
Private Attributes | |
uint64_t | m_bps |
data rate [bps] | |
Friends | |
std::istream & | operator>> (std::istream &is, DataRate &rate) |
Stream extraction operator. | |
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 multiplier 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 77 of file data-rate.h.
ns3::DataRate::DataRate | ( | ) |
Definition at line 117 of file data-rate.cc.
References NS_LOG_FUNCTION.
Referenced by operator*(), operator*(), operator+(), and operator-().
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 123 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 240 of file data-rate.cc.
References DoParse(), m_bps, NS_FATAL_ERROR, and NS_LOG_FUNCTION.
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 227 of file data-rate.cc.
References m_bps, NS_LOG_FUNCTION, and ns3::Seconds().
Referenced by CalculateBytesTxTime(), and DataRateTestCase1::SingleTest().
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 220 of file data-rate.cc.
References CalculateBitsTxTime(), and NS_LOG_FUNCTION.
Referenced by ns3::CsmaNetDevice::Attach(), ns3::TbfQueueDisc::DoDequeue(), ns3::AdvancedEmlsrManager::DoGetDelayUntilAccessRequest(), ns3::AdvancedApEmlsrManager::GetDelayOnTxPsduNotForEmlsr(), ns3::PhyEntity::ScheduleEndOfMpdus(), DataRateTestCase1::SingleTest(), ns3::SimpleNetDevice::StartTransmission(), ns3::HalfDuplexIdealPhy::StartTx(), ns3::CsmaNetDevice::TransmitStart(), and ns3::PointToPointNetDevice::TransmitStart().
|
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 24 of file data-rate.cc.
References NS_LOG_FUNCTION.
Referenced by DataRate().
uint64_t ns3::DataRate::GetBitRate | ( | ) | const |
Get the underlying bitrate.
Definition at line 234 of file data-rate.cc.
References m_bps, and NS_LOG_FUNCTION.
Referenced by ns3::TcpBbr::AckAggregationCwnd(), ns3::OnOffApplication::CancelEvents(), ns3::TcpBbr::CheckFullPipe(), ns3::TbfQueueDisc::DoDequeue(), LteRadioLinkFailureTestCase::DoRun(), ns3::RedQueueDisc::InitializeParams(), ns3::TcpBbr::InitPacingRate(), ns3::operator*(), ns3::operator*(), ns3::operator<<(), PacingRateTracer(), ns3::OnOffApplication::ScheduleNextTx(), ns3::TutorialApp::ScheduleTx(), Ipv4DynamicGlobalRoutingTestCase::SendData(), ns3::TcpBbr::SetPacingRate(), TraceQueueLength(), TraceQueueLength(), and ns3::TcpBbr::UpdateAckAggregation().
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.
Scales the DataRate.
Multiplies with double and is re-casted to an int
rhs | the double to multiply to this datarate |
Definition at line 158 of file data-rate.cc.
References DataRate(), and m_bps.
DataRate ns3::DataRate::operator* | ( | uint64_t | rhs | ) | const |
Scales the DataRate.
rhs | the uint64_t to multiply to this datarate |
Definition at line 171 of file data-rate.cc.
References DataRate(), and m_bps.
Scales the DataRate.
Multiplies with double and is re-casted to an int
rhs | the double to multiply to this datarate |
Definition at line 164 of file data-rate.cc.
References m_bps.
DataRate & ns3::DataRate::operator*= | ( | uint64_t | rhs | ) |
Scales the DataRate.
rhs | the uint64_t to multiply to this datarate |
Definition at line 177 of file data-rate.cc.
References m_bps.
Definition at line 130 of file data-rate.cc.
References DataRate(), and m_bps.
Definition at line 143 of file data-rate.cc.
References DataRate(), m_bps, and NS_ASSERT_MSG.
Definition at line 150 of file data-rate.cc.
References m_bps, and NS_ASSERT_MSG.
bool ns3::DataRate::operator< | ( | const DataRate & | rhs | ) | const |
rhs | the datarate to compare to this datarate |
Definition at line 183 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 189 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 208 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 196 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 202 of file data-rate.cc.
References m_bps.
|
friend |
Stream extraction operator.
is | the stream |
rate | the data rate |
Definition at line 260 of file data-rate.cc.
|
private |
data rate [bps]
Definition at line 264 of file data-rate.h.
Referenced by DataRate(), CalculateBitsTxTime(), GetBitRate(), operator!=(), operator*(), operator*(), operator*=(), operator*=(), operator+(), operator+=(), operator-(), operator-=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().