A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
ns3::DataRate Class Reference

Class for representing data rates. More...

#include "data-rate.h"

+ Collaboration diagram for ns3::DataRate:

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.
 
DataRateoperator*= (double rhs)
 Scales the DataRate.
 
DataRateoperator*= (uint64_t rhs)
 Scales the DataRate.
 
DataRate operator+ (DataRate rhs) const
 
DataRateoperator+= (DataRate rhs)
 
DataRate operator- (DataRate rhs) const
 
DataRateoperator-= (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.
 

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;
Time txtime = x.CalculateBytesTxTime (nBytes);
Class for representing data rates.
Definition data-rate.h:78
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1344

This class also supports the regular comparison operators <, >, <=, >=, ==, and !=

Data rate specifiers consist of

  • A numeric value,
  • An optional multiplier prefix and
  • A unit.

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:

  • "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
See also
DataRate Attribute

Definition at line 77 of file data-rate.h.

Constructor & Destructor Documentation

◆ DataRate() [1/3]

ns3::DataRate::DataRate ( )

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

References NS_LOG_FUNCTION.

Referenced by operator*(), operator*(), operator+(), and operator-().

+ Here is the caller graph for this function:

◆ DataRate() [2/3]

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 123 of file data-rate.cc.

References NS_LOG_FUNCTION.

◆ DataRate() [3/3]

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 240 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

◆ CalculateBitsTxTime()

Time ns3::DataRate::CalculateBitsTxTime ( uint32_t bits) const

Calculate transmission time.

Calculates the transmission time at this data rate

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

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

References m_bps, NS_LOG_FUNCTION, and ns3::Seconds().

Referenced by CalculateBytesTxTime(), and DataRateTestCase1::SingleTest().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ CalculateBytesTxTime()

Time ns3::DataRate::CalculateBytesTxTime ( 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 for the number of bytes specified

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

References CalculateBitsTxTime(), and NS_LOG_FUNCTION.

Referenced by ns3::CsmaNetDevice::Attach(), EmlsrUlTxopTest::CheckQosFrames(), 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().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ DoParse()

bool ns3::DataRate::DoParse ( const std::string s,
uint64_t * v )
staticprivate

Parse a string representing a DataRate into an uint64_t.

Allowed unit representations include all combinations of

  • An SI prefix: k, K, M, G
  • Decimal or kibibit (as in "Kibps", meaning 1024 bps)
  • Bits or bytes (8 bits)
  • "bps" or "/s"
Parameters
[in]sThe string representation, including unit
[in,out]vThe location to put the value, in bits/sec.
Returns
true if parsing was successful.

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

References NS_LOG_FUNCTION.

Referenced by DataRate().

+ Here is the caller graph for this function:

◆ GetBitRate()

uint64_t ns3::DataRate::GetBitRate ( ) const

◆ operator!=()

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 214 of file data-rate.cc.

References m_bps.

◆ operator*() [1/2]

DataRate ns3::DataRate::operator* ( double rhs) const

Scales the DataRate.

Multiplies with double and is re-casted to an int

Returns
DataRate object representing the product of this object with rhs
Parameters
rhsthe double to multiply to this datarate

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

References DataRate(), and m_bps.

+ Here is the call graph for this function:

◆ operator*() [2/2]

DataRate ns3::DataRate::operator* ( uint64_t rhs) const

Scales the DataRate.

Returns
DataRate object representing the product of this object with rhs
Parameters
rhsthe uint64_t to multiply to this datarate

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

References DataRate(), and m_bps.

+ Here is the call graph for this function:

◆ operator*=() [1/2]

DataRate & ns3::DataRate::operator*= ( double rhs)

Scales the DataRate.

Multiplies with double and is re-casted to an int

Returns
DataRate object representing the product of this object with rhs
Parameters
rhsthe double to multiply to this datarate

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

References m_bps.

◆ operator*=() [2/2]

DataRate & ns3::DataRate::operator*= ( uint64_t rhs)

Scales the DataRate.

Returns
DataRate object representing the product of this object with rhs
Parameters
rhsthe uint64_t to multiply to this datarate

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

References m_bps.

◆ operator+()

DataRate ns3::DataRate::operator+ ( DataRate rhs) const
Returns
the DataRate representing the sum of this object with rhs
Parameters
rhsthe DataRate to add to this DataRate

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

References DataRate(), and m_bps.

+ Here is the call graph for this function:

◆ operator+=()

DataRate & ns3::DataRate::operator+= ( DataRate rhs)
Returns
the DataRate representing the sum of this object with rhs
Parameters
rhsthe DataRate to add to this DataRate

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

References m_bps.

◆ operator-()

DataRate ns3::DataRate::operator- ( DataRate rhs) const
Returns
the DataRate representing the difference of this object with rhs
Parameters
rhsthe DataRate to subtract from this DataRate

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

References DataRate(), m_bps, and NS_ASSERT_MSG.

+ Here is the call graph for this function:

◆ operator-=()

DataRate & ns3::DataRate::operator-= ( DataRate rhs)
Returns
the DataRate representing the difference of this object with rhs
Parameters
rhsthe DataRate to subtract from this DataRate

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

References m_bps, and NS_ASSERT_MSG.

◆ operator<()

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 183 of file data-rate.cc.

References m_bps.

◆ operator<=()

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 189 of file data-rate.cc.

References m_bps.

◆ operator==()

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 208 of file data-rate.cc.

References m_bps.

◆ operator>()

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 196 of file data-rate.cc.

References m_bps.

◆ operator>=()

bool ns3::DataRate::operator>= ( const DataRate & rhs) const
Returns
true if this rate is greater than or equal to rhs
Parameters
rhsthe datarate to compare to this datarate

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

References m_bps.

Friends And Related Symbol Documentation

◆ operator>>

std::istream & operator>> ( std::istream & is,
DataRate & rate )
friend

Stream extraction operator.

Parameters
isthe stream
ratethe data rate
Returns
a reference to the stream

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

Member Data Documentation

◆ m_bps


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