14#include "ns3/assert.h"
15#include "ns3/fatal-error.h"
36 for (
auto i = begin(); i != end(); i++)
48 "Error: attempting to enable the packet metadata "
49 "subsystem too late in the simulation, which is not allowed.\n"
50 "A common cause for this problem is to enable ASCII tracing "
51 "after sending any packets. One way to fix this problem is "
52 "to call ns3::PacketMetadata::Enable () near the beginning of"
53 " the program, before any packets are sent.");
112 bool ok = pointer == 0xffff || pointer <=
m_data->
m_size;
120 bool ok = pointer == 0xffff || pointer <=
m_used;
131 uint16_t current =
m_head;
132 while (ok && current != 0xffff)
168 if (value < 0x200000)
172 if (value < 0x10000000)
183 const uint8_t* buffer = *pBuffer;
188 result = (
byte & (~0x80));
191 *pBuffer = buffer + 1;
195 result |= (
byte & (~0x80)) << 7;
198 *pBuffer = buffer + 2;
202 result |= (
byte & (~0x80)) << 14;
205 *pBuffer = buffer + 3;
209 result |= (
byte & (~0x80)) << 21;
212 *pBuffer = buffer + 4;
216 result |= (
byte & (~0x80)) << 28;
219 *pBuffer = buffer + 5;
233 buffer[0] = value & 0xff;
242 buffer[0] = value & 0xff;
243 buffer[1] = (value >> 8) & 0xff;
244 buffer[2] = (value >> 16) & 0xff;
245 buffer[3] = (value >> 24) & 0xff;
252 if (value < 0x200000)
254 uint8_t
byte = value & (~0x80);
255 buffer[0] = 0x80 | byte;
257 byte = value & (~0x80);
258 buffer[1] = 0x80 | byte;
263 if (value < 0x10000000)
265 uint8_t
byte = value & (~0x80);
266 buffer[0] = 0x80 | byte;
268 byte = value & (~0x80);
269 buffer[1] = 0x80 | byte;
271 byte = value & (~0x80);
272 buffer[2] = 0x80 | byte;
278 uint8_t
byte = value & (~0x80);
279 buffer[0] = 0x80 | byte;
281 byte = value & (~0x80);
282 buffer[1] = 0x80 | byte;
284 byte = value & (~0x80);
285 buffer[2] = 0x80 | byte;
287 byte = value & (~0x80);
288 buffer[3] = 0x80 | byte;
305 uint8_t
byte = value & (~0x80);
306 buffer[0] = 0x80 | byte;
375 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2;
387 buffer += typeUidSize;
411 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
426 buffer += typeUidSize;
432 buffer += fragStartSize;
434 buffer += fragEndSize;
465 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
475 buffer += typeUidSize;
481 buffer += fragStartSize;
483 buffer += fragEndSize;
496 uint16_t current =
m_head;
497 while (current != 0xffff && current !=
m_tail)
501 ReadItems(current, &tmpItem, &tmpExtraItem);
502 uint16_t written = h.
AddBig(0xffff, h.
m_tail, &tmpItem, &tmpExtraItem);
504 current = tmpItem.
next;
507 uint16_t written = h.
AddBig(0xffff, h.
m_tail, item, extraItem);
523 item->
next = buffer[0];
524 item->
next |= (buffer[1]) << 8;
525 item->
prev = buffer[2];
526 item->
prev |= (buffer[3]) << 8;
534 bool isExtra = (item->
typeUid & 0x1) == 0x1;
568 if (
data->m_size >= size)
612 auto buf =
new uint8_t[size];
616 data->m_dirtyEnd = 0;
624 auto buf = (uint8_t*)
data;
681 if ((item.
typeUid & 0xfffffffe) != uid || item.
size != size)
748 if ((item.
typeUid & 0xfffffffe) != uid || item.
size != size)
842 while (current != 0xffff)
845 uint16_t written =
AddBig(0xffff,
m_tail, &item, &extraItem);
878 uint16_t current =
m_head;
879 while (current != 0xffff && leftToRemove > 0)
885 if (itemRealSize <= leftToRemove)
897 leftToRemove -= itemRealSize;
905 uint16_t written = fragment.
AddBig(0xffff, fragment.
m_tail, &item, &extraItem);
907 while (current != 0xffff && current !=
m_tail)
911 written = fragment.
AddBig(0xffff, fragment.
m_tail, &item, &extraItem);
940 uint16_t current =
m_tail;
941 while (current != 0xffff && leftToRemove > 0)
947 if (itemRealSize <= leftToRemove)
959 leftToRemove -= itemRealSize;
968 uint16_t written = fragment.
AddBig(fragment.
m_head, 0xffff, &item, &extraItem);
970 while (current != 0xffff && current !=
m_head)
974 written = fragment.
AddBig(fragment.
m_head, 0xffff, &item, &extraItem);
996 uint16_t current =
m_head;
998 while (current != 0xffff)
1004 if (current == tail)
1009 current = item.
next;
1029 : m_metadata(metadata),
1031 m_current(metadata->
m_head),
1033 m_hasReadTail(false)
1042 if (m_current == 0xffff)
1060 m_metadata->ReadItems(m_current, &smallItem, &extraItem);
1061 if (m_current == m_metadata->m_tail)
1063 m_hasReadTail =
true;
1065 m_current = smallItem.
next;
1083 item.
current = m_buffer.Begin();
1092 item.
current = m_buffer.End();
1124 while (current != 0xffff)
1136 totalSize += 4 + tid.
GetName().size();
1138 totalSize += 1 + 4 + 2 + 4 + 4 + 8;
1144 current = item.
next;
1153 uint8_t* start = buffer;
1156 if (buffer ==
nullptr)
1164 while (current != 0xffff)
1168 <<
", typeUid=" << item.
typeUid <<
", size=" << item.
size
1172 <<
", packetUid=" << extraItem.
packetUid);
1179 std::string uidString = tid.
GetName();
1180 uint32_t uidStringSize = uidString.size();
1181 buffer =
AddToRawU32(uidStringSize, start, buffer, maxSize);
1182 if (buffer ==
nullptr)
1186 buffer =
AddToRaw(
reinterpret_cast<const uint8_t*
>(uidString.c_str()),
1191 if (buffer ==
nullptr)
1199 if (buffer ==
nullptr)
1205 uint8_t isBig = item.
typeUid & 0x1;
1206 buffer =
AddToRawU8(isBig, start, buffer, maxSize);
1207 if (buffer ==
nullptr)
1213 if (buffer ==
nullptr)
1219 if (buffer ==
nullptr)
1225 if (buffer ==
nullptr)
1231 if (buffer ==
nullptr)
1237 if (buffer ==
nullptr)
1248 current = item.
next;
1259 const uint8_t* start = buffer;
1273 if (uidStringSize == 0)
1280 std::string uidString;
1281 for (
uint32_t j = 0; j < uidStringSize; j++)
1285 uidString.push_back(ch);
1294 item.
typeUid = (uid << 1) | isBig;
1306 <<
", chunkUid=" << item.
chunkUid <<
", fragmentStart="
1308 <<
", packetUid=" << extraItem.
packetUid);
1313 return (desSize != 0) ? 0 : 1;
1321 if (
static_cast<uint32_t>(current +
sizeof(uint8_t) - start) > maxSize)
1325 memcpy(current, &
data,
sizeof(uint8_t));
1326 return current +
sizeof(uint8_t);
1337 if (
static_cast<uint32_t>(current +
sizeof(uint16_t) - start) > maxSize)
1341 memcpy(current, &
data,
sizeof(uint16_t));
1342 return current +
sizeof(uint16_t);
1369 if (
static_cast<uint32_t>(current +
sizeof(uint64_t) - start) > maxSize)
1373 memcpy(current, &
data,
sizeof(uint64_t));
1374 return current +
sizeof(uint64_t);
1386 if (
static_cast<uint32_t>(current + dataSize - start) > maxSize)
1390 memcpy(current,
data, dataSize);
1391 return current + dataSize;
1396 const uint8_t* start,
1397 const uint8_t* current,
1402 if (
static_cast<uint32_t>(current +
sizeof(uint8_t) - start) > maxSize)
1406 memcpy(&
data, current,
sizeof(uint8_t));
1407 return const_cast<uint8_t*
>(current) +
sizeof(uint8_t);
1412 const uint8_t* start,
1413 const uint8_t* current,
1418 if (
static_cast<uint32_t>(current +
sizeof(uint16_t) - start) > maxSize)
1422 memcpy(&
data, current,
sizeof(uint16_t));
1423 return const_cast<uint8_t*
>(current) +
sizeof(uint16_t);
1428 const uint8_t* start,
1429 const uint8_t* current,
1439 return const_cast<uint8_t*
>(current) +
sizeof(
uint32_t);
1444 const uint8_t* start,
1445 const uint8_t* current,
1450 if ((
uint32_t)(current +
sizeof(uint64_t) - start) > maxSize)
1454 memcpy(&
data, current,
sizeof(uint64_t));
1455 return const_cast<uint8_t*
>(current) +
sizeof(uint64_t);
void Prev()
go backward by one byte
void Next()
go forward by one byte
automatically resized byte buffer
virtual TypeId GetInstanceTypeId() const =0
Get the most derived TypeId for this Object.
Protocol trailer serialization and deserialization.
static TypeId GetTypeId()
Get the type ID.
a unique identifier for an interface.
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
static TypeId LookupByName(std::string name)
Get a TypeId by name.
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
uint16_t GetUid() const
Get the internal id of this TypeId.
std::string GetName() const
Get the name.
#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_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#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.