22 #include "ns3/nstime.h"
23 #include "ns3/fatal-error.h"
32 std::string::size_type n = s.find_first_not_of (
"0123456789.");
33 if (n != std::string::npos)
35 std::istringstream iss;
36 iss.str (s.substr (0, n));
39 std::string trailer = s.substr (n, std::string::npos);
45 else if (trailer ==
"b/s")
50 else if (trailer ==
"Bps")
53 *v = (uint64_t)(r * 8);
55 else if (trailer ==
"B/s")
58 *v = (uint64_t)(r * 8);
60 else if (trailer ==
"kbps")
63 *v = (uint64_t)(r * 1000);
65 else if (trailer ==
"kb/s")
68 *v = (uint64_t)(r * 1000);
70 else if (trailer ==
"Kbps")
73 *v = (uint64_t)(r * 1000);
75 else if (trailer ==
"Kb/s")
78 *v = (uint64_t)(r * 1000);
80 else if (trailer ==
"kBps")
83 *v = (uint64_t)(r * 8000);
85 else if (trailer ==
"kB/s")
88 *v = (uint64_t)(r * 8000);
90 else if (trailer ==
"KBps")
93 *v = (uint64_t)(r * 8000);
95 else if (trailer ==
"KB/s")
98 *v = (uint64_t)(r * 8000);
100 else if (trailer ==
"Kib/s")
103 *v = (uint64_t)(r * 1024);
105 else if (trailer ==
"KiB/s")
108 *v = (uint64_t)(r * 8192);
110 else if (trailer ==
"Mbps")
113 *v = (uint64_t)(r * 1000000);
115 else if (trailer ==
"Mb/s")
118 *v = (uint64_t)(r * 1000000);
120 else if (trailer ==
"MBps")
123 *v = (uint64_t)(r * 8000000);
125 else if (trailer ==
"MB/s")
128 *v = (uint64_t)(r * 8000000);
130 else if (trailer ==
"Mib/s")
133 *v = (uint64_t)(r * 1048576);
135 else if (trailer ==
"MiB/s")
138 *v = (uint64_t)(r * 1048576 * 8);
140 else if (trailer ==
"Gbps")
143 *v = (uint64_t)(r * 1000000000);
145 else if (trailer ==
"Gb/s")
148 *v = (uint64_t)(r * 1000000000);
150 else if (trailer ==
"GBps")
153 *v = (uint64_t)(r * 8*1000000000);
155 else if (trailer ==
"GB/s")
158 *v = (uint64_t)(r * 8*1000000000);
160 else if (trailer ==
"Gib/s")
163 *v = (uint64_t)(r * 1048576 * 1024);
165 else if (trailer ==
"GiB/s")
168 *v = (uint64_t)(r * 1048576 * 1024 * 8);
176 std::istringstream iss;
232 return static_cast<double>(bytes)*8/
m_bps;
266 is.setstate (std::ios_base::failbit);
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
keep track of time values and allow control of global simulation resolution
#define NS_LOG_FUNCTION(parameters)
bool operator<(const DataRate &rhs) const
TracedValue< T > operator*(const TracedValue< T > &lhs, const TracedValue< U > &rhs)
bool operator>(const DataRate &rhs) const
#define NS_FATAL_ERROR(msg)
fatal error handling
Class for representing data rates.
double GetSeconds(void) const
double CalculateTxTime(uint32_t bytes) const
Calculate transmission time.
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
uint64_t GetBitRate() const
Get the underlying bitrate.
DataRate()
Macro to make help make data-rate an ns-3 attribute.
bool operator<=(const DataRate &rhs) const
bool operator>=(const DataRate &rhs) const
static bool DoParse(const std::string s, uint64_t *v)
bool operator!=(const DataRate &rhs) const
bool operator==(const DataRate &rhs) const
ATTRIBUTE_HELPER_CPP(ObjectFactory)
NS_LOG_COMPONENT_DEFINE("DataRate")