Class for representing data rates. More...
#include <data-rate.h>
Public Member Functions | |
DataRate () | |
DataRate (uint64_t bps) | |
Integer constructor. | |
DataRate (std::string rate) | |
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 |
double | CalculateTxTime (uint32_t bytes) const |
Calculate transmission time. | |
uint64_t | GetBitRate () const |
Static Private Member Functions | |
static uint64_t | Parse (const std::string) |
Private Attributes | |
uint64_t | m_bps |
Class for representing data rates.
Allows for natural and familiar use of data rates. Allows construction from strings, natural multiplication e.g.:
DataRate x("56kbps"); double nBits = x*ns3::Seconds(19.2); uint32_t nBytes = 20; double txtime = x.CalclulateTxTime(nBytes);
This class also supports the regular comparison operators <, >, <=, >=, ==, and !=
Conventions used: "b" stands for bits, "B" for bytes (8 bits)
"k" stands for 1000, "K" also stands for 1000, "Ki" stands for 1024
"M" stand for 1000000, "Mib" stands for 1024 kibibits, or 1048576 bits
"G" stand for 10^9, "Gib" stands for 1024 mebibits
whitespace is allowed but not required between the numeric value and units
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
Definition at line 71 of file data-rate.h.
ns3::DataRate::DataRate | ( | ) |
Definition at line 184 of file data-rate.cc.
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 availiable.
Definition at line 188 of file data-rate.cc.
ns3::DataRate::DataRate | ( | std::string | rate | ) |
Definition at line 232 of file data-rate.cc.
References DoParse(), m_bps, and NS_FATAL_ERROR.
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 222 of file data-rate.cc.
References m_bps.
Referenced by ns3::CsmaNetDevice::Attach(), ns3::PointToPointNetDevice::TransmitStart(), and ns3::CsmaNetDevice::TransmitStart().
uint64_t ns3::DataRate::GetBitRate | ( | ) | const |
Get the underlying bitrate
Definition at line 227 of file data-rate.cc.
References m_bps.
Referenced by ns3::OnOffApplication::CancelEvents(), and ns3::OnOffApplication::ScheduleNextTx().
bool ns3::DataRate::operator!= | ( | const DataRate & | rhs | ) | const |
Definition at line 217 of file data-rate.cc.
References m_bps.
bool ns3::DataRate::operator< | ( | const DataRate & | rhs | ) | const |
Definition at line 192 of file data-rate.cc.
References m_bps.
bool ns3::DataRate::operator<= | ( | const DataRate & | rhs | ) | const |
Definition at line 197 of file data-rate.cc.
References m_bps.
bool ns3::DataRate::operator== | ( | const DataRate & | rhs | ) | const |
Definition at line 212 of file data-rate.cc.
References m_bps.
bool ns3::DataRate::operator> | ( | const DataRate & | rhs | ) | const |
Definition at line 202 of file data-rate.cc.
References m_bps.
bool ns3::DataRate::operator>= | ( | const DataRate & | rhs | ) | const |
Definition at line 207 of file data-rate.cc.
References m_bps.
static uint64_t ns3::DataRate::Parse | ( | const std::string | ) | [static, private] |
uint64_t ns3::DataRate::m_bps [private] |
Definition at line 108 of file data-rate.h.
Referenced by CalculateTxTime(), DataRate(), GetBitRate(), operator!=(), operator<(), operator<=(), operator==(), operator>(), and operator>=().