11#include "ns3/assert.h"
56 m_len = address.m_len;
68 "No address with the given kind and length is registered.");
70 if (
m_type != search->second)
73 "You can only change the type of a type-0 address."
121 "Type-0 addresses are reserved. Please use SetType before using CopyFrom.");
122 std::memcpy(
m_data, buffer, len);
161 "An address of the same kind and length is already registered.");
162 lastRegisteredType++;
164 return lastRegisteredType;
171 return 1 + 1 +
m_len;
235 for (uint8_t i = 0; i < a.
GetLength(); i++)
252 if (address.m_len == 0)
256 std::ios_base::fmtflags ff = os.flags();
257 auto fill = os.fill(
'0');
258 os.setf(std::ios::hex, std::ios::basefield);
259 os << std::setw(2) << (
uint32_t)address.m_type <<
"-" << std::setw(2) << (
uint32_t)address.m_len
261 for (uint8_t i = 0; i < (address.m_len - 1); ++i)
263 os << std::setw(2) << (
uint32_t)address.m_data[i] <<
":";
266 os << std::setw(2) << (
uint32_t)address.m_data[address.m_len - 1];
277 std::string::size_type firstDash;
278 std::string::size_type secondDash;
279 firstDash =
v.find(
'-');
280 secondDash =
v.find(
'-', firstDash + 1);
281 std::string type =
v.substr(0, firstDash);
282 std::string len =
v.substr(firstDash + 1, secondDash - (firstDash + 1));
284 address.m_type = std::stoul(type,
nullptr, 16);
285 address.m_len = std::stoul(len,
nullptr, 16);
288 std::string::size_type col = secondDash + 1;
289 for (uint8_t i = 0; i < address.m_len; ++i)
292 std::string::size_type next;
293 next =
v.find(
':', col);
294 if (next == std::string::npos)
296 tmp =
v.substr(col,
v.size() - col);
297 address.m_data[i] = std::stoul(tmp,
nullptr, 16);
302 tmp =
v.substr(col, next - col);
303 address.m_data[i] = std::stoul(tmp,
nullptr, 16);
a polymophic address class
uint32_t GetSerializedSize() const
Get the number of bytes needed to serialize the underlying Address Typically, this is GetLength () + ...
void Serialize(TagBuffer buffer) const
Serialize this address in host byte order to a byte buffer.
static constexpr uint8_t UNASSIGNED_TYPE
Unassigned Address type is reserved. Defined for clarity.
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
static constexpr uint32_t MAX_SIZE
The maximum size of a byte buffer which can be stored in an Address instance.
uint8_t m_len
Length of the address.
uint8_t m_data[MAX_SIZE]
The address value.
void SetType(const std::string &kind, uint8_t length)
Set the address type.
uint8_t m_type
Type of the address.
Address & operator=(const Address &address)
Basic assignment operator.
std::unordered_map< KindType, uint8_t, Address::KeyHash > KindTypeRegistry
Type of the address registry.
static KindTypeRegistry m_typeRegistry
Container of allocated address types.
Address()
Create an invalid address.
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
bool CheckCompatible(uint8_t type, uint8_t len) const
uint8_t GetLength() const
Get the length of the underlying address.
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
Copy the address bytes into a buffer.
void Deserialize(TagBuffer buffer)
static uint8_t Register(const std::string &kind, uint8_t length)
Allocate a new type id for a new type of address.
bool IsMatchingType(uint8_t type) const
uint32_t CopyAllTo(uint8_t *buffer, uint8_t len) const
void Read(uint8_t *buffer, uint32_t size)
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
TAG_BUFFER_INLINE uint8_t ReadU8()
void Write(const uint8_t *buffer, uint32_t size)
#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(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.
bool operator!=(Callback< R, Args... > a, Callback< R, Args... > b)
Inequality test.
bool operator==(const EventId &a, const EventId &b)
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::istream & operator>>(std::istream &is, Angles &a)
bool operator<(const EventId &a, const EventId &b)