A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
ns3::DataRate Class Reference

Class for representing data rates. More...

#include <data-rate.h>

Public Member Functions

 DataRate ()
 Macro to make help make data-rate an ns-3 attribute. More...
 
 DataRate (uint64_t bps)
 Integer constructor. More...
 
 DataRate (std::string rate)
 String constructor. More...
 
double CalculateTxTime (uint32_t bytes) const
 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 uint64_t Parse (const std::string)
 

Private Attributes

uint64_t m_bps
 

Detailed Description

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.

Constructor & Destructor Documentation

ns3::DataRate::DataRate ( )

Macro to make help make data-rate an ns-3 attribute.

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.

Parameters
bpsbit/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

Parameters
ratestring representing the desired rate

Definition at line 241 of file data-rate.cc.

References DoParse(), m_bps, NS_FATAL_ERROR, and NS_LOG_FUNCTION.

+ Here is the call graph for this function:

Member Function Documentation

double ns3::DataRate::CalculateTxTime ( uint32_t  bytes) const

Calculate transmission time.

Calculates the transmission time at this data rate

Parameters
bytesThe number of bytes (not bits) for which to calculate
Returns
The transmission time in seconds for the number of bytes specified

Definition at line 229 of file data-rate.cc.

References m_bps, and NS_LOG_FUNCTION.

Referenced by ns3::CsmaNetDevice::Attach(), ns3::HalfDuplexIdealPhy::StartTx(), ns3::PointToPointNetDevice::TransmitStart(), and ns3::CsmaNetDevice::TransmitStart().

+ Here is the caller graph for this function:

uint64_t ns3::DataRate::GetBitRate ( ) const

Get the underlying bitrate.

Returns
The underlying bitrate in bits per second

Definition at line 235 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(), and SimpleSource::ScheduleTx().

+ Here is the caller graph for this function:

bool ns3::DataRate::operator!= ( const DataRate rhs) const
Returns
true if this rate is not equal to rhs
Parameters
rhsthe 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
Returns
true if this rate is less than rhs
Parameters
rhsthe 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
Returns
true if this rate is less than or equal to rhs
Parameters
rhsthe 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
Returns
true if this rate is equal to rhs
Parameters
rhsthe 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
Returns
true if this rate is greater than rhs
Parameters
rhsthe 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
Returns
true if this rate is greather than or equal to rhs
Parameters
rhsthe datarate to compare to this datarate

Definition at line 214 of file data-rate.cc.

References m_bps.

static uint64_t ns3::DataRate::Parse ( const std::string  )
staticprivate

Member Data Documentation

uint64_t ns3::DataRate::m_bps
private

The documentation for this class was generated from the following files: