10#include "ns3/address.h"
11#include "ns3/assert.h"
13#include "ns3/simulator.h"
31 NS_ASSERT_MSG(strlen(str) <= 17,
"Mac48Address: illegal string (too long) " << str);
33 unsigned int bytes[6];
37 "%02x:%02x:%02x:%02x:%02x:%02x%n",
45 NS_ASSERT_MSG(i == 6 && !str[charsRead],
"Mac48Address: illegal string " << str);
47 std::copy(std::begin(bytes), std::end(bytes), std::begin(
m_address));
54 std::copy(buffer, buffer + 6,
m_address.begin());
68 return address.CheckCompatible(
GetType(), 6);
178 uint8_t etherBuffer[6];
179 etherAddr.
CopyTo(etherBuffer);
193 etherBuffer[3] |= ipBuffer[1] & 0x7f;
194 etherBuffer[4] = ipBuffer[2];
195 etherBuffer[5] = ipBuffer[3];
202 result.CopyFrom(etherBuffer);
211 uint8_t etherBuffer[6];
212 uint8_t ipBuffer[16];
216 etherAddr.
CopyTo(etherBuffer);
219 etherBuffer[2] = ipBuffer[12];
220 etherBuffer[3] = ipBuffer[13];
221 etherBuffer[4] = ipBuffer[14];
222 etherBuffer[5] = ipBuffer[15];
232 std::ios_base::fmtflags ff = os.flags();
233 os.setf(std::ios::hex, std::ios::basefield);
234 auto fill = os.fill(
'0');
236 os << std::setw(2) << static_cast<uint32_t>(address.m_address[0]) <<
":";
237 os << std::setw(2) << static_cast<uint32_t>(address.m_address[1]) <<
":";
238 os << std::setw(2) << static_cast<uint32_t>(address.m_address[2]) <<
":";
239 os << std::setw(2) << static_cast<uint32_t>(address.m_address[3]) <<
":";
240 os << std::setw(2) << static_cast<uint32_t>(address.m_address[4]) <<
":";
241 os << std::setw(2) << static_cast<uint32_t>(address.m_address[5]);
255 std::string::size_type col = 0;
256 for (uint8_t i = 0; i < 6; ++i)
259 std::string::size_type next;
260 next =
v.find(
':', col);
261 if (next == std::string::npos)
263 tmp =
v.substr(col,
v.size() - col);
264 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
269 tmp =
v.substr(col, next - col);
270 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
a polymophic address class
static uint8_t Register(const std::string &kind, uint8_t length)
Allocate a new type id for a new type of address.
Ipv4 addresses are stored in host order in this class.
void Serialize(uint8_t buf[4]) const
Serialize this address to a 4-byte buffer.
Describes an IPv6 address.
void Serialize(uint8_t buf[16]) const
Serialize this address to a 16-byte buffer.
std::array< uint8_t, 6 > m_address
Address value.
static Mac48Address GetMulticast(Ipv4Address address)
static void ResetAllocationIndex()
Reset the Mac48Address allocation index.
static bool IsMatchingType(const Address &address)
void CopyFrom(const uint8_t buffer[6])
static uint8_t GetType()
Return the Type of address.
static Mac48Address ConvertFrom(const Address &address)
static Mac48Address GetBroadcast()
static Mac48Address Allocate()
Allocate a new Mac48Address.
static Mac48Address GetMulticast6Prefix()
Get the multicast prefix for IPv6 (33:33:00:00:00:00).
void CopyTo(uint8_t buffer[6]) const
static Mac48Address GetMulticastPrefix()
static uint64_t m_allocationIndex
Address allocation index.
Address ConvertTo() const
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)