21 #include "ns3/assert.h"
45 NS_LOG_FUNCTION (
this << static_cast<uint32_t> (type) << &buffer << static_cast<uint32_t> (len));
47 std::memcpy (m_data, buffer, m_len);
50 : m_type (address.m_type),
54 std::memcpy (m_data, address.m_data, m_len);
57 Address::operator = (
const Address &address)
60 m_type = address.m_type;
61 m_len = address.m_len;
63 std::memcpy (m_data, address.m_data, m_len);
71 return m_len == 0 && m_type == 0;
86 std::memcpy (buffer, m_data, m_len);
96 std::memcpy (buffer + 2, m_data, m_len);
105 std::memcpy (m_data, buffer, len);
118 std::memcpy (m_data, buffer + 2, m_len);
124 NS_LOG_FUNCTION (
this << static_cast<uint32_t> (type) << static_cast<uint32_t> (len));
127 return (m_len == len && m_type == type) || (m_len >= len && m_type == 0);
133 return m_type == type;
140 static uint8_t type = 1;
149 return 1 + 1 + m_len;
158 buffer.
Write (m_data, m_len);
165 m_type = buffer.
ReadU8 ();
168 buffer.
Read (m_data, m_len);
185 if (a.m_type != b.m_type &&
191 if (a.m_len != b.m_len)
195 return std::memcmp (a.m_data, b.m_data, a.m_len) == 0;
197 bool operator != (
const Address &a,
const Address &b)
201 bool operator < (
const Address &a,
const Address &b)
203 if (a.m_type < b.m_type)
207 else if (a.m_type > b.m_type)
211 if (a.m_len < b.m_len)
215 else if (a.m_len > b.m_len)
219 NS_ASSERT (a.GetLength () == b.GetLength ());
220 for (uint8_t i = 0; i < a.GetLength (); i++)
222 if (a.m_data[i] < b.m_data[i])
226 else if (a.m_data[i] > b.m_data[i])
234 std::ostream&
operator<< (std::ostream& os,
const Address & address)
236 os.setf (std::ios::hex, std::ios::basefield);
238 os << std::setw (2) << (uint32_t) address.m_type <<
"-" << std::setw (2) << (uint32_t) address.m_len <<
"-";
239 for (uint8_t i = 0; i < (address.m_len-1); ++i)
241 os << std::setw (2) << (uint32_t)address.m_data[i] <<
":";
244 os << std::setw (2) << (uint32_t) address.m_data[address.m_len-1];
245 os.setf (std::ios::dec, std::ios::basefield);
251 AsInt (std::string v)
254 std::istringstream iss;
257 iss >> std::hex >> retval >> std::dec;
261 std::istream&
operator>> (std::istream& is, Address & address)
265 std::string::size_type firstDash, secondDash;
266 firstDash = v.find (
"-");
267 secondDash = v.find (
"-", firstDash+1);
268 std::string type = v.substr (0, firstDash-0);
269 std::string len = v.substr (firstDash+1, secondDash-(firstDash+1));
271 address.m_type = AsInt (type);
272 address.m_len = AsInt (len);
273 NS_ASSERT (address.m_len <= Address::MAX_SIZE);
275 std::string::size_type col = secondDash + 1;
276 for (uint8_t i = 0; i < address.m_len; ++i)
279 std::string::size_type next;
280 next = v.find (
":", col);
281 if (next == std::string::npos)
283 tmp = v.substr (col, v.size ()-col);
284 address.m_data[i] = AsInt (tmp);
289 tmp = v.substr (col, next-col);
290 address.m_data[i] = AsInt (tmp);
297 Address& operator+ (Address & address,
int increment)
300 id = (uint64_t)address.m_data[0] << 40 |
301 (uint64_t)address.m_data[1] << 32 |
302 (uint64_t)address.m_data[2] << 24 |
303 (uint64_t)address.m_data[3] << 16 |
304 (uint64_t)address.m_data[4] << 8 |
305 (uint64_t)address.m_data[5];
308 uint8_t m_address[6];
309 std::memset (m_address, 0, 6);
311 m_address[0] = (
id >> 40) & 0xff;
312 m_address[1] = (
id >> 32) & 0xff;
313 m_address[2] = (
id >> 24) & 0xff;
314 m_address[3] = (
id >> 16) & 0xff;
315 m_address[4] = (
id >> 8) & 0xff;
316 m_address[5] = (
id >> 0) & 0xff;
317 address.CopyFrom(m_address, 6);
bool IsInvalid(void) const
std::istream & operator>>(std::istream &is, Angles &a)
void Write(const uint8_t *buffer, uint32_t size)
#define NS_LOG_FUNCTION(parameters)
bool IsMatchingType(uint8_t type) const
#define NS_ASSERT(condition)
#define NS_LOG_COMPONENT_DEFINE(name)
#define NS_LOG_FUNCTION_NOARGS()
TAG_BUFFER_INLINE uint8_t ReadU8(void)
a polymophic address class
bool CheckCompatible(uint8_t type, uint8_t len) const
uint32_t CopyAllTo(uint8_t *buffer, uint8_t len) const
uint8_t GetLength(void) const
uint32_t CopyAllFrom(const uint8_t *buffer, uint8_t len)
void Deserialize(TagBuffer buffer)
uint32_t GetSerializedSize(void) const
std::ostream & operator<<(std::ostream &os, const Angles &a)
uint32_t CopyFrom(const uint8_t *buffer, uint8_t len)
#define ATTRIBUTE_HELPER_CPP(type)
TAG_BUFFER_INLINE void WriteU8(uint8_t v)
uint32_t CopyTo(uint8_t buffer[MAX_SIZE]) const
void Serialize(TagBuffer buffer) const
void Read(uint8_t *buffer, uint32_t size)
static uint8_t Register(void)