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));
68 return address.CheckCompatible(
GetType(), 6);
177 uint8_t etherBuffer[6];
178 etherAddr.
CopyTo(etherBuffer);
192 etherBuffer[3] |= ipBuffer[1] & 0x7f;
193 etherBuffer[4] = ipBuffer[2];
194 etherBuffer[5] = ipBuffer[3];
210 uint8_t etherBuffer[6];
211 uint8_t ipBuffer[16];
215 etherAddr.
CopyTo(etherBuffer);
218 etherBuffer[2] = ipBuffer[12];
219 etherBuffer[3] = ipBuffer[13];
220 etherBuffer[4] = ipBuffer[14];
221 etherBuffer[5] = ipBuffer[15];
234 os.setf(std::ios::hex, std::ios::basefield);
236 for (uint8_t i = 0; i < 5; i++)
238 os << std::setw(2) << (
uint32_t)ad[i] <<
":";
241 os << std::setw(2) << (
uint32_t)ad[5];
242 os.setf(std::ios::dec, std::ios::basefield);
253 std::string::size_type col = 0;
254 for (uint8_t i = 0; i < 6; ++i)
257 std::string::size_type next;
258 next = v.find(
':', col);
259 if (next == std::string::npos)
261 tmp = v.substr(col, v.size() - col);
262 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
267 tmp = v.substr(col, next - col);
268 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.
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.
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)
uint8_t m_address[6]
Address value.
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)