21 #include "ns3/address.h"
22 #include "ns3/assert.h"
24 #include "ns3/simulator.h"
42 NS_ASSERT_MSG(strlen(str) <= 23,
"Mac64Address: illegal string (too long) " << str);
44 unsigned int bytes[8];
48 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x%n",
58 NS_ASSERT_MSG(i == 8 && !str[charsRead],
"Mac64Address: illegal string " << str);
60 std::copy(std::begin(bytes), std::end(bytes), std::begin(
m_address));
122 uint64_t shift = 0xFF;
123 uint64_t addr =
static_cast<uint64_t
>(
m_address[7]) & (shift);
124 addr |= (
static_cast<uint64_t
>(
m_address[6]) << 8) & (shift << 8);
125 addr |= (
static_cast<uint64_t
>(
m_address[5]) << 16) & (shift << 16);
126 addr |= (
static_cast<uint64_t
>(
m_address[4]) << 24) & (shift << 24);
128 addr |= (
static_cast<uint64_t
>(
m_address[3]) << 32) & (shift << 32);
129 addr |= (
static_cast<uint64_t
>(
m_address[2]) << 40) & (shift << 40);
130 addr |= (
static_cast<uint64_t
>(
m_address[1]) << 48) & (shift << 48);
131 addr |= (
static_cast<uint64_t
>(
m_address[0]) << 56) & (shift << 56);
180 os.setf(std::ios::hex, std::ios::basefield);
182 for (uint8_t i = 0; i < 7; i++)
184 os << std::setw(2) << (uint32_t)ad[i] <<
":";
187 os << std::setw(2) << (uint32_t)ad[7];
188 os.setf(std::ios::dec, std::ios::basefield);
199 std::string::size_type col = 0;
200 for (uint8_t i = 0; i < 8; ++i)
203 std::string::size_type next;
204 next = v.find(
':', col);
205 if (next == std::string::npos)
207 tmp = v.substr(col, v.size() - col);
208 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
213 tmp = v.substr(col, next - col);
214 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
a polymophic address class
static uint8_t Register()
Allocate a new type id for a new type of address.
uint8_t m_address[8]
Address value.
Address ConvertTo() const
uint64_t ConvertToInt() const
static bool IsMatchingType(const Address &address)
static Mac64Address Allocate()
Allocate a new Mac64Address.
void CopyFrom(const uint8_t buffer[8])
void CopyTo(uint8_t buffer[8]) const
static Mac64Address ConvertFrom(const Address &address)
static void ResetAllocationIndex()
Reset the Mac64Address allocation index.
static uint8_t GetType()
Return the Type of address.
static uint64_t m_allocationIndex
Address allocation index.
static EventId ScheduleDestroy(FUNC f, Ts &&... args)
Schedule an event to run at the end of the simulation, when Simulator::Destroy() is called.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ATTRIBUTE_HELPER_CPP(ValueClassTest)
std::istream & operator>>(std::istream &is, Angles &a)
std::ostream & operator<<(std::ostream &os, const Angles &a)