11#include "ns3/address.h"
12#include "ns3/assert.h"
14#include "ns3/simulator.h"
32 NS_ASSERT_MSG(strlen(str) <= 5,
"Mac16Address: illegal string (too long) " << str);
34 unsigned int bytes[2];
37 int i = sscanf(str,
"%02x:%02x%n", bytes, bytes + 1, &charsRead);
38 NS_ASSERT_MSG(i == 2 && !str[charsRead],
"Mac16Address: illegal string " << str);
40 std::copy(std::begin(bytes), std::end(bytes), std::begin(
m_address));
54 std::copy(buffer, buffer + 2,
m_address.begin());
68 return address.CheckCompatible(
GetType(), 2);
98 addr |= (
m_address[0] << 8) & (0xFF << 8);
150 uint8_t ipv6AddrBuf[16];
151 address.GetBytes(ipv6AddrBuf);
155 addrBuf[0] = 0x80 | (ipv6AddrBuf[14] & 0x1F);
156 addrBuf[1] = ipv6AddrBuf[15];
161 return multicastAddr;
183 std::ios_base::fmtflags ff = os.flags();
184 os.setf(std::ios::hex, std::ios::basefield);
185 auto fill = os.fill(
'0');
187 os << std::setw(2) << static_cast<uint32_t>(address.m_address[0]) <<
":";
188 os << std::setw(2) << static_cast<uint32_t>(address.m_address[1]);
202 std::string::size_type col = 0;
203 for (uint8_t i = 0; i < 2; ++i)
206 std::string::size_type next;
207 next =
v.find(
':', col);
208 if (next == std::string::npos)
210 tmp =
v.substr(col,
v.size() - col);
211 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
216 tmp =
v.substr(col, next - col);
217 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.
Describes an IPv6 address.
This class can contain 16 bit addresses.
static Mac16Address GetMulticast(Ipv6Address address)
Returns the multicast address associated with an IPv6 address according to RFC 4944 Section 9.
static bool IsMatchingType(const Address &address)
static uint64_t m_allocationIndex
Address allocation index.
static Mac16Address ConvertFrom(const Address &address)
uint16_t ConvertToInt() const
void CopyTo(uint8_t buffer[2]) const
static Mac16Address Allocate()
Allocate a new Mac16Address.
Address ConvertTo() const
void CopyFrom(const uint8_t buffer[2])
bool IsMulticast() const
Checks if the address is a multicast address according to RFC 4944 Section 9 (i.e....
std::array< uint8_t, 2 > m_address
Address value.
static void ResetAllocationIndex()
Reset the Mac16Address allocation index.
static Mac16Address GetBroadcast()
bool IsBroadcast() const
Checks if the address is a broadcast address according to 802.15.4 scheme (i.e., 0xFFFF).
static uint8_t GetType()
Return the Type of address.
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)