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 (double bits, Time span)
 Construct a data rate from an amount of bits transferred over a time span.
 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.
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)
auto operator<=> (const DataRate &rhs) const =default
 Spaceship comparison operator.

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);
cairo_uint64_t x
_cairo_uint_96by64_32x64_divrem:
Simulation virtual time values and global simulation resolution.
Definition nstime.h:95
Time Seconds(double value)
Construct a Time in the indicated unit.
Definition nstime.h:1313

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
attribute_DataRate

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

Constructor & Destructor Documentation

◆ DataRate() [1/4]

ns3::DataRate::DataRate ( )

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

References m_bps, and NS_LOG_FUNCTION.

Referenced by operator*(), operator*(), operator+(), operator+=(), operator-(), operator-=(), operator<=>(), and operator>>.

Here is the caller graph for this function:

◆ DataRate() [2/4]

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

References m_bps, and NS_LOG_FUNCTION.

◆ DataRate() [3/4]

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

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

Here is the call graph for this function:

◆ DataRate() [4/4]

ns3::DataRate::DataRate ( double bits,
Time span )

Construct a data rate from an amount of bits transferred over a time span.

The resulting rate is bits / span, expressed in bits/s. Since a DataRate can only hold an integral number of bits/s, the program is aborted if the division does not yield an integer.

Parameters
bitsthe number of bits transferred over span
spanthe duration over which bits were transferred (must be > 0)

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

References ns3::Time::As(), ns3::Time::GetTimeStep(), ns3::Time::IsStrictlyPositive(), m_bps, NS_ABORT_MSG_UNLESS, NS_ASSERT_MSG, NS_LOG_FUNCTION, ns3::Time::S, and ns3::Seconds().

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

References CalculateBitsTxTime(), and NS_LOG_FUNCTION.

Referenced by EmlsrUlTxopTest::CheckQosFrames(), ns3::AdvancedApEmlsrManager::GetDelayOnTxPsduNotForEmlsr(), ns3::PhyEntity::ScheduleEndOfMpdus(), and DataRateTestCase1::SingleTest().

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

References NS_LOG_FUNCTION, r, and v.

Referenced by DataRate(), and operator>>.

Here is the caller graph for this function:

◆ GetBitRate()

uint64_t ns3::DataRate::GetBitRate ( ) const

Get the underlying bitrate.

Returns
The underlying bitrate in bits per second

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

References m_bps, and NS_LOG_FUNCTION.

Referenced by FlentApplicationPing::DoRun(), FlentApplicationRrul::DoRun(), FlentApplicationTcpDownload::DoRun(), FlentApplicationTcpUpload::DoRun(), LteRadioLinkFailureTestCase::DoRun(), ns3::TcpBbr::InitPacingRate(), ns3::operator*(), ns3::operator*(), ns3::operator<<(), PacingRateTracer(), TraceQueueLength(), and TraceQueueLength().

Here is the caller graph for this function:

◆ 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 161 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 174 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 167 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 180 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 133 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 139 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) const
Returns
the DataRate representing the difference of this object with rhs
Parameters
rhsthe DataRate to subtract from this DataRate

Definition at line 146 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 153 of file data-rate.cc.

References DataRate(), m_bps, and NS_ASSERT_MSG.

Here is the call graph for this function:

◆ operator<=>()

auto ns3::DataRate::operator<=> ( const DataRate & rhs) const
default

Spaceship comparison operator.

All the other comparison operators are automatically generated from this one.

Parameters
rhsthe datarate to compare to this datarate
Returns
The result of the comparison.

References DataRate(), and v.

Here is the call graph for this function:

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

References DataRate(), DoParse(), and v.

Member Data Documentation

◆ m_bps

uint64_t ns3::DataRate::m_bps
private

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