10#include "ns3/address.h"
11#include "ns3/assert.h"
13#include "ns3/simulator.h"
31 NS_ASSERT_MSG(strlen(str) <= 23,
"Mac64Address: illegal string (too long) " << str);
33 unsigned int bytes[8];
37 "%02x:%02x:%02x:%02x:%02x:%02x:%02x:%02x%n",
47 NS_ASSERT_MSG(i == 8 && !str[charsRead],
"Mac64Address: illegal string " << str);
49 std::copy(std::begin(bytes), std::end(bytes), std::begin(
m_address));
83 return address.CheckCompatible(
GetType(), 8);
111 uint64_t shift = 0xFF;
112 uint64_t addr =
static_cast<uint64_t
>(
m_address[7]) & (shift);
113 addr |= (
static_cast<uint64_t
>(
m_address[6]) << 8) & (shift << 8);
114 addr |= (
static_cast<uint64_t
>(
m_address[5]) << 16) & (shift << 16);
115 addr |= (
static_cast<uint64_t
>(
m_address[4]) << 24) & (shift << 24);
117 addr |= (
static_cast<uint64_t
>(
m_address[3]) << 32) & (shift << 32);
118 addr |= (
static_cast<uint64_t
>(
m_address[2]) << 40) & (shift << 40);
119 addr |= (
static_cast<uint64_t
>(
m_address[1]) << 48) & (shift << 48);
120 addr |= (
static_cast<uint64_t
>(
m_address[0]) << 56) & (shift << 56);
169 os.setf(std::ios::hex, std::ios::basefield);
171 for (uint8_t i = 0; i < 7; i++)
173 os << std::setw(2) << (
uint32_t)ad[i] <<
":";
176 os << std::setw(2) << (
uint32_t)ad[7];
177 os.setf(std::ios::dec, std::ios::basefield);
188 std::string::size_type col = 0;
189 for (uint8_t i = 0; i < 8; ++i)
192 std::string::size_type next;
193 next = v.find(
':', col);
194 if (next == std::string::npos)
196 tmp = v.substr(col, v.size() - col);
197 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
202 tmp = v.substr(col, next - col);
203 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 ATTRIBUTE_HELPER_CPP(type)
Define the attribute value, accessor and checkers for class type
#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.
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::istream & operator>>(std::istream &is, Angles &a)