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.");
111 bool ok = pointer == 0xffff || pointer <=
m_data->
m_size;
118 bool ok = pointer == 0xffff || pointer <=
m_used;
129 uint16_t current =
m_head;
130 while (ok && current != 0xffff)
166 if (value < 0x200000)
170 if (value < 0x10000000)
181 const uint8_t* buffer = *pBuffer;
186 result = (
byte & (~0x80));
189 *pBuffer = buffer + 1;
193 result |= (
byte & (~0x80)) << 7;
196 *pBuffer = buffer + 2;
200 result |= (
byte & (~0x80)) << 14;
203 *pBuffer = buffer + 3;
207 result |= (
byte & (~0x80)) << 21;
210 *pBuffer = buffer + 4;
214 result |= (
byte & (~0x80)) << 28;
217 *pBuffer = buffer + 5;
231 buffer[0] = value & 0xff;
240 buffer[0] = value & 0xff;
241 buffer[1] = (value >> 8) & 0xff;
242 buffer[2] = (value >> 16) & 0xff;
243 buffer[3] = (value >> 24) & 0xff;
250 if (value < 0x200000)
252 uint8_t
byte = value & (~0x80);
253 buffer[0] = 0x80 | byte;
255 byte = value & (~0x80);
256 buffer[1] = 0x80 | byte;
261 if (value < 0x10000000)
263 uint8_t
byte = value & (~0x80);
264 buffer[0] = 0x80 | byte;
266 byte = value & (~0x80);
267 buffer[1] = 0x80 | byte;
269 byte = value & (~0x80);
270 buffer[2] = 0x80 | byte;
276 uint8_t
byte = value & (~0x80);
277 buffer[0] = 0x80 | byte;
279 byte = value & (~0x80);
280 buffer[1] = 0x80 | byte;
282 byte = value & (~0x80);
283 buffer[2] = 0x80 | byte;
285 byte = value & (~0x80);
286 buffer[3] = 0x80 | byte;
303 uint8_t
byte = value & (~0x80);
304 buffer[0] = 0x80 | byte;
373 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2;
385 buffer += typeUidSize;
409 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
424 buffer += typeUidSize;
430 buffer += fragStartSize;
432 buffer += fragEndSize;
463 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
473 buffer += typeUidSize;
479 buffer += fragStartSize;
481 buffer += fragEndSize;
494 uint16_t current =
m_head;
495 while (current != 0xffff && current !=
m_tail)
499 ReadItems(current, &tmpItem, &tmpExtraItem);
500 uint16_t written = h.
AddBig(0xffff, h.
m_tail, &tmpItem, &tmpExtraItem);
502 current = tmpItem.
next;
505 uint16_t written = h.
AddBig(0xffff, h.
m_tail, item, extraItem);
521 item->
next = buffer[0];
522 item->
next |= (buffer[1]) << 8;
523 item->
prev = buffer[2];
524 item->
prev |= (buffer[3]) << 8;
532 bool isExtra = (item->
typeUid & 0x1) == 0x1;
566 if (
data->m_size >= size)
610 auto buf =
new uint8_t[size];
614 data->m_dirtyEnd = 0;
622 auto buf = (uint8_t*)
data;
679 if ((item.
typeUid & 0xfffffffe) != uid || item.
size != size)
746 if ((item.
typeUid & 0xfffffffe) != uid || item.
size != size)
840 while (current != 0xffff)
843 uint16_t written =
AddBig(0xffff,
m_tail, &item, &extraItem);
876 uint16_t current =
m_head;
877 while (current != 0xffff && leftToRemove > 0)
883 if (itemRealSize <= leftToRemove)
895 leftToRemove -= itemRealSize;
903 uint16_t written = fragment.
AddBig(0xffff, fragment.
m_tail, &item, &extraItem);
905 while (current != 0xffff && current !=
m_tail)
909 written = fragment.
AddBig(0xffff, fragment.
m_tail, &item, &extraItem);
938 uint16_t current =
m_tail;
939 while (current != 0xffff && leftToRemove > 0)
945 if (itemRealSize <= leftToRemove)
957 leftToRemove -= itemRealSize;
966 uint16_t written = fragment.
AddBig(fragment.
m_head, 0xffff, &item, &extraItem);
968 while (current != 0xffff && current !=
m_head)
972 written = fragment.
AddBig(fragment.
m_head, 0xffff, &item, &extraItem);
994 uint16_t current =
m_head;
996 while (current != 0xffff)
1002 if (current == tail)
1007 current = item.
next;
1027 : m_metadata(metadata),
1029 m_current(metadata->
m_head),
1031 m_hasReadTail(false)
1040 if (m_current == 0xffff)
1058 m_metadata->ReadItems(m_current, &smallItem, &extraItem);
1059 if (m_current == m_metadata->m_tail)
1061 m_hasReadTail =
true;
1063 m_current = smallItem.
next;
1081 item.
current = m_buffer.Begin();
1090 item.
current = m_buffer.End();
1122 while (current != 0xffff)
1134 totalSize += 4 + tid.
GetName().size();
1136 totalSize += 1 + 4 + 2 + 4 + 4 + 8;
1142 current = item.
next;
1151 uint8_t* start = buffer;
1154 if (buffer ==
nullptr)
1162 while (current != 0xffff)
1166 <<
", typeUid=" << item.
typeUid <<
", size=" << item.
size
1170 <<
", packetUid=" << extraItem.
packetUid);
1177 std::string uidString = tid.
GetName();
1178 uint32_t uidStringSize = uidString.size();
1179 buffer =
AddToRawU32(uidStringSize, start, buffer, maxSize);
1180 if (buffer ==
nullptr)
1184 buffer =
AddToRaw(
reinterpret_cast<const uint8_t*
>(uidString.c_str()),
1189 if (buffer ==
nullptr)
1197 if (buffer ==
nullptr)
1203 uint8_t isBig = item.
typeUid & 0x1;
1204 buffer =
AddToRawU8(isBig, start, buffer, maxSize);
1205 if (buffer ==
nullptr)
1211 if (buffer ==
nullptr)
1217 if (buffer ==
nullptr)
1223 if (buffer ==
nullptr)
1229 if (buffer ==
nullptr)
1235 if (buffer ==
nullptr)
1246 current = item.
next;
1257 const uint8_t* start = buffer;
1271 if (uidStringSize == 0)
1278 std::string uidString;
1279 for (
uint32_t j = 0; j < uidStringSize; j++)
1283 uidString.push_back(ch);
1292 item.
typeUid = (uid << 1) | isBig;
1304 <<
", chunkUid=" << item.
chunkUid <<
", fragmentStart="
1306 <<
", packetUid=" << extraItem.
packetUid);
1311 return (desSize != 0) ? 0 : 1;
1319 if (
static_cast<uint32_t>(current +
sizeof(uint8_t) - start) > maxSize)
1323 memcpy(current, &
data,
sizeof(uint8_t));
1324 return current +
sizeof(uint8_t);
1335 if (
static_cast<uint32_t>(current +
sizeof(uint16_t) - start) > maxSize)
1339 memcpy(current, &
data,
sizeof(uint16_t));
1340 return current +
sizeof(uint16_t);
1367 if (
static_cast<uint32_t>(current +
sizeof(uint64_t) - start) > maxSize)
1371 memcpy(current, &
data,
sizeof(uint64_t));
1372 return current +
sizeof(uint64_t);
1384 if (
static_cast<uint32_t>(current + dataSize - start) > maxSize)
1388 memcpy(current,
data, dataSize);
1389 return current + dataSize;
1394 const uint8_t* start,
1395 const uint8_t* current,
1400 if (
static_cast<uint32_t>(current +
sizeof(uint8_t) - start) > maxSize)
1404 memcpy(&
data, current,
sizeof(uint8_t));
1405 return const_cast<uint8_t*
>(current) +
sizeof(uint8_t);
1410 const uint8_t* start,
1411 const uint8_t* current,
1416 if (
static_cast<uint32_t>(current +
sizeof(uint16_t) - start) > maxSize)
1420 memcpy(&
data, current,
sizeof(uint16_t));
1421 return const_cast<uint8_t*
>(current) +
sizeof(uint16_t);
1426 const uint8_t* start,
1427 const uint8_t* current,
1437 return const_cast<uint8_t*
>(current) +
sizeof(
uint32_t);
1442 const uint8_t* start,
1443 const uint8_t* current,
1448 if ((
uint32_t)(current +
sizeof(uint64_t) - start) > maxSize)
1452 memcpy(&
data, current,
sizeof(uint64_t));
1453 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.