12#include "ns3/assert.h"
33 std::copy(buffer, buffer + len,
m_data.begin());
42 "No address with the given kind and length is registered.");
44 if (
m_type != search->second)
47 "You can only change the type of a type-0 address."
95 "Type-0 addresses are reserved. Please use SetType before using CopyFrom.");
96 std::copy(buffer, buffer + len,
m_data.begin());
110 std::copy(buffer + 2, buffer + 2 +
m_len,
m_data.begin());
135 "An address of the same kind and length is already registered.");
136 lastRegisteredType++;
138 return lastRegisteredType;
145 return 1 + 1 +
m_len;
172 if (address.m_type == 0)
177 std::ios_base::fmtflags ff = os.flags();
178 auto fill = os.fill(
'0');
179 os.setf(std::ios::hex, std::ios::basefield);
180 os << std::setw(2) << (
uint32_t)address.m_type <<
"-" << std::setw(2) << (
uint32_t)address.m_len
182 for (uint8_t i = 0; i < (address.m_len - 1); ++i)
184 os << std::setw(2) << (
uint32_t)address.m_data[i] <<
":";
187 os << std::setw(2) << (
uint32_t)address.m_data[address.m_len - 1];
198 std::string::size_type firstDash;
199 std::string::size_type secondDash;
200 firstDash =
v.find(
'-');
201 secondDash =
v.find(
'-', firstDash + 1);
202 std::string type =
v.substr(0, firstDash);
203 std::string len =
v.substr(firstDash + 1, secondDash - (firstDash + 1));
205 address.m_type = std::stoul(type,
nullptr, 16);
206 address.m_len = std::stoul(len,
nullptr, 16);
209 std::string::size_type col = secondDash + 1;
210 for (uint8_t i = 0; i < address.m_len; ++i)
213 std::string::size_type next;
214 next =
v.find(
':', col);
215 if (next == std::string::npos)
217 tmp =
v.substr(col,
v.size() - col);
218 address.m_data[i] = std::stoul(tmp,
nullptr, 16);
223 tmp =
v.substr(col, next - col);
224 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.
void SetType(const std::string &kind, uint8_t length)
Set the address type.
std::array< uint8_t, MAX_SIZE > m_data
The address value.
uint8_t m_type
Type of the address.
std::unordered_map< KindType, uint8_t, Address::KeyHash > KindTypeRegistry
Type of the address registry.
static KindTypeRegistry m_typeRegistry
Container of allocated address types.
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
bool CheckCompatible(uint8_t type, uint8_t len) const
Address()=default
Create an invalid address.
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.
std::ostream & operator<<(std::ostream &os, const Angles &a)
std::istream & operator>>(std::istream &is, Angles &a)