21 #include "ns3/address.h"
22 #include "ns3/assert.h"
24 #include "ns3/simulator.h"
42 NS_ASSERT_MSG(strlen(str) <= 17,
"Mac48Address: illegal string (too long) " << str);
44 unsigned int bytes[6];
48 "%02x:%02x:%02x:%02x:%02x:%02x%n",
56 NS_ASSERT_MSG(i == 6 && !str[charsRead],
"Mac48Address: illegal string " << str);
58 std::copy(std::begin(bytes), std::end(bytes), std::begin(
m_address));
188 uint8_t etherBuffer[6];
189 etherAddr.
CopyTo(etherBuffer);
203 etherBuffer[3] |= ipBuffer[1] & 0x7f;
204 etherBuffer[4] = ipBuffer[2];
205 etherBuffer[5] = ipBuffer[3];
221 uint8_t etherBuffer[6];
222 uint8_t ipBuffer[16];
226 etherAddr.
CopyTo(etherBuffer);
229 etherBuffer[2] = ipBuffer[12];
230 etherBuffer[3] = ipBuffer[13];
231 etherBuffer[4] = ipBuffer[14];
232 etherBuffer[5] = ipBuffer[15];
245 os.setf(std::ios::hex, std::ios::basefield);
247 for (uint8_t i = 0; i < 5; i++)
249 os << std::setw(2) << (uint32_t)ad[i] <<
":";
252 os << std::setw(2) << (uint32_t)ad[5];
253 os.setf(std::ios::dec, std::ios::basefield);
264 std::string::size_type col = 0;
265 for (uint8_t i = 0; i < 6; ++i)
268 std::string::size_type next;
269 next = v.find(
':', col);
270 if (next == std::string::npos)
272 tmp = v.substr(col, v.size() - col);
273 address.m_address[i] = std::stoul(tmp,
nullptr, 16);
278 tmp = v.substr(col, next - col);
279 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 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)