25 #include "ns3/assert.h"
26 #include "ns3/fatal-error.h"
47 for (
auto i = begin(); i != end(); i++)
59 "Error: attempting to enable the packet metadata "
60 "subsystem too late in the simulation, which is not allowed.\n"
61 "A common cause for this problem is to enable ASCII tracing "
62 "after sending any packets. One way to fix this problem is "
63 "to call ns3::PacketMetadata::Enable () near the beginning of"
64 " the program, before any packets are sent.");
123 bool ok = pointer == 0xffff || pointer <=
m_data->
m_size;
131 bool ok = pointer == 0xffff || pointer <=
m_used;
142 uint16_t current =
m_head;
143 while (ok && current != 0xffff)
179 if (value < 0x200000)
183 if (value < 0x10000000)
194 const uint8_t* buffer = *pBuffer;
199 result = (
byte & (~0x80));
202 *pBuffer = buffer + 1;
206 result |= (
byte & (~0x80)) << 7;
209 *pBuffer = buffer + 2;
213 result |= (
byte & (~0x80)) << 14;
216 *pBuffer = buffer + 3;
220 result |= (
byte & (~0x80)) << 21;
223 *pBuffer = buffer + 4;
227 result |= (
byte & (~0x80)) << 28;
230 *pBuffer = buffer + 5;
244 buffer[0] = value & 0xff;
253 buffer[0] = value & 0xff;
254 buffer[1] = (value >> 8) & 0xff;
255 buffer[2] = (value >> 16) & 0xff;
256 buffer[3] = (value >> 24) & 0xff;
263 if (value < 0x200000)
265 uint8_t
byte = value & (~0x80);
266 buffer[0] = 0x80 |
byte;
268 byte = value & (~0x80);
269 buffer[1] = 0x80 |
byte;
274 if (value < 0x10000000)
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;
289 uint8_t
byte = value & (~0x80);
290 buffer[0] = 0x80 |
byte;
292 byte = value & (~0x80);
293 buffer[1] = 0x80 |
byte;
295 byte = value & (~0x80);
296 buffer[2] = 0x80 |
byte;
298 byte = value & (~0x80);
299 buffer[3] = 0x80 |
byte;
316 uint8_t
byte = value & (~0x80);
317 buffer[0] = 0x80 |
byte;
386 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2;
398 buffer += typeUidSize;
422 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
437 buffer += typeUidSize;
443 buffer += fragStartSize;
445 buffer += fragEndSize;
476 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
486 buffer += typeUidSize;
492 buffer += fragStartSize;
494 buffer += fragEndSize;
507 uint16_t current =
m_head;
508 while (current != 0xffff && current !=
m_tail)
512 ReadItems(current, &tmpItem, &tmpExtraItem);
513 uint16_t written = h.
AddBig(0xffff, h.
m_tail, &tmpItem, &tmpExtraItem);
515 current = tmpItem.
next;
518 uint16_t written = h.
AddBig(0xffff, h.
m_tail, item, extraItem);
534 item->
next = buffer[0];
535 item->
next |= (buffer[1]) << 8;
536 item->
prev = buffer[2];
537 item->
prev |= (buffer[3]) << 8;
545 bool isExtra = (item->
typeUid & 0x1) == 0x1;
579 if (
data->m_size >= size)
617 uint32_t size =
sizeof(
Data);
623 auto buf =
new uint8_t[size];
627 data->m_dirtyEnd = 0;
635 auto buf = (uint8_t*)
data;
692 if ((item.
typeUid & 0xfffffffe) != uid || item.
size != size)
759 if ((item.
typeUid & 0xfffffffe) != uid || item.
size != size)
853 while (current != 0xffff)
856 uint16_t written =
AddBig(0xffff,
m_tail, &item, &extraItem);
888 uint32_t leftToRemove =
start;
889 uint16_t current =
m_head;
890 while (current != 0xffff && leftToRemove > 0)
896 if (itemRealSize <= leftToRemove)
908 leftToRemove -= itemRealSize;
916 uint16_t written = fragment.
AddBig(0xffff, fragment.
m_tail, &item, &extraItem);
918 while (current != 0xffff && current !=
m_tail)
922 written = fragment.
AddBig(0xffff, fragment.
m_tail, &item, &extraItem);
950 uint32_t leftToRemove = end;
951 uint16_t current =
m_tail;
952 while (current != 0xffff && leftToRemove > 0)
958 if (itemRealSize <= leftToRemove)
970 leftToRemove -= itemRealSize;
979 uint16_t written = fragment.
AddBig(fragment.
m_head, 0xffff, &item, &extraItem);
981 while (current != 0xffff && current !=
m_head)
985 written = fragment.
AddBig(fragment.
m_head, 0xffff, &item, &extraItem);
1006 uint32_t totalSize = 0;
1007 uint16_t current =
m_head;
1009 while (current != 0xffff)
1015 if (current == tail)
1020 current = item.
next;
1040 : m_metadata(metadata),
1042 m_current(metadata->
m_head),
1044 m_hasReadTail(false)
1053 if (m_current == 0xffff)
1071 m_metadata->ReadItems(m_current, &smallItem, &extraItem);
1072 if (m_current == m_metadata->m_tail)
1074 m_hasReadTail =
true;
1076 m_current = smallItem.
next;
1077 uint32_t uid = (smallItem.
typeUid & 0xfffffffe) >> 1;
1094 item.
current = m_buffer.Begin();
1103 item.
current = m_buffer.End();
1119 uint32_t totalSize = 0;
1134 uint32_t current =
m_head;
1135 while (current != 0xffff)
1138 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1147 totalSize += 4 + tid.
GetName().size();
1149 totalSize += 1 + 4 + 2 + 4 + 4 + 8;
1155 current = item.
next;
1164 uint8_t*
start = buffer;
1167 if (buffer ==
nullptr)
1174 uint32_t current =
m_head;
1175 while (current != 0xffff)
1179 <<
", typeUid=" << item.
typeUid <<
", size=" << item.
size
1183 <<
", packetUid=" << extraItem.
packetUid);
1185 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1190 std::string uidString = tid.
GetName();
1191 uint32_t uidStringSize = uidString.size();
1193 if (buffer ==
nullptr)
1197 buffer =
AddToRaw(
reinterpret_cast<const uint8_t*
>(uidString.c_str()),
1202 if (buffer ==
nullptr)
1210 if (buffer ==
nullptr)
1216 uint8_t isBig = item.
typeUid & 0x1;
1218 if (buffer ==
nullptr)
1224 if (buffer ==
nullptr)
1230 if (buffer ==
nullptr)
1236 if (buffer ==
nullptr)
1242 if (buffer ==
nullptr)
1248 if (buffer ==
nullptr)
1259 current = item.
next;
1270 const uint8_t*
start = buffer;
1271 uint32_t desSize = size - 4;
1280 uint32_t uidStringSize = 0;
1284 if (uidStringSize == 0)
1291 std::string uidString;
1292 for (uint32_t j = 0; j < uidStringSize; j++)
1296 uidString.push_back(ch);
1305 item.
typeUid = (uid << 1) | isBig;
1317 <<
", chunkUid=" << item.
chunkUid <<
", fragmentStart="
1319 <<
", packetUid=" << extraItem.
packetUid);
1320 uint32_t tmp =
AddBig(0xffff,
m_tail, &item, &extraItem);
1324 return (desSize != 0) ? 0 : 1;
1332 if (
static_cast<uint32_t
>(current +
sizeof(uint8_t) -
start) > maxSize)
1336 memcpy(current, &
data,
sizeof(uint8_t));
1337 return current +
sizeof(uint8_t);
1348 if (
static_cast<uint32_t
>(current +
sizeof(uint16_t) -
start) > maxSize)
1352 memcpy(current, &
data,
sizeof(uint16_t));
1353 return current +
sizeof(uint16_t);
1364 if (
static_cast<uint32_t
>(current +
sizeof(uint32_t) -
start) > maxSize)
1368 memcpy(current, &
data,
sizeof(uint32_t));
1369 return current +
sizeof(uint32_t);
1380 if (
static_cast<uint32_t
>(current +
sizeof(uint64_t) -
start) > maxSize)
1384 memcpy(current, &
data,
sizeof(uint64_t));
1385 return current +
sizeof(uint64_t);
1397 if (
static_cast<uint32_t
>(current + dataSize -
start) > maxSize)
1401 memcpy(current,
data, dataSize);
1402 return current + dataSize;
1407 const uint8_t*
start,
1408 const uint8_t* current,
1413 if (
static_cast<uint32_t
>(current +
sizeof(uint8_t) -
start) > maxSize)
1417 memcpy(&
data, current,
sizeof(uint8_t));
1418 return const_cast<uint8_t*
>(current) +
sizeof(uint8_t);
1423 const uint8_t*
start,
1424 const uint8_t* current,
1429 if (
static_cast<uint32_t
>(current +
sizeof(uint16_t) -
start) > maxSize)
1433 memcpy(&
data, current,
sizeof(uint16_t));
1434 return const_cast<uint8_t*
>(current) +
sizeof(uint16_t);
1439 const uint8_t*
start,
1440 const uint8_t* current,
1445 if (
static_cast<uint32_t
>(current +
sizeof(uint32_t) -
start) > maxSize)
1449 memcpy(&
data, current,
sizeof(uint32_t));
1450 return const_cast<uint8_t*
>(current) +
sizeof(uint32_t);
1455 const uint8_t*
start,
1456 const uint8_t* current,
1461 if ((uint32_t)(current +
sizeof(uint64_t) -
start) > maxSize)
1465 memcpy(&
data, current,
sizeof(uint64_t));
1466 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.