22 #include "ns3/assert.h"
23 #include "ns3/fatal-error.h"
44 for (iterator i = begin (); i != end (); i++)
48 PacketMetadata::m_enable =
false;
56 "Error: attempting to enable the packet metadata "
57 "subsystem too late in the simulation, which is not allowed.\n"
58 "A common cause for this problem is to enable ASCII tracing "
59 "after sending any packets. One way to fix this problem is "
60 "to call ns3::PacketMetadata::Enable () near the beginning of"
61 " the program, before any packets are sent.");
121 bool ok = pointer == 0xffff || pointer <=
m_data->
m_size;
128 bool ok = pointer == 0xffff || pointer <=
m_used;
139 uint16_t current =
m_head;
140 while (ok && current != 0xffff)
176 if (value < 0x200000)
180 if (value < 0x10000000)
190 const uint8_t *buffer = *pBuffer;
195 result = (byte & (~0x80));
198 *pBuffer = buffer + 1;
202 result |= (byte & (~0x80)) << 7;
205 *pBuffer = buffer + 2;
209 result |= (byte & (~0x80)) << 14;
212 *pBuffer = buffer + 3;
216 result |= (byte & (~0x80)) << 21;
219 *pBuffer = buffer + 4;
223 result |= (byte & (~0x80)) << 28;
226 *pBuffer = buffer + 5;
240 buffer[0] = value & 0xff;
248 buffer[0] = value & 0xff;
249 buffer[1] = (value >> 8) & 0xff;
250 buffer[2] = (value >> 16) & 0xff;
251 buffer[3] = (value >> 24) & 0xff;
258 if (value < 0x200000)
260 uint8_t byte = value & (~0x80);
261 buffer[0] = 0x80 | byte;
263 byte = value & (~0x80);
264 buffer[1] = 0x80 | byte;
266 byte = value & (~0x80);
270 if (value < 0x10000000)
272 uint8_t byte = value & (~0x80);
273 buffer[0] = 0x80 | byte;
275 byte = value & (~0x80);
276 buffer[1] = 0x80 | byte;
278 byte = value & (~0x80);
279 buffer[2] = 0x80 | byte;
285 uint8_t byte = value & (~0x80);
286 buffer[0] = 0x80 | byte;
288 byte = value & (~0x80);
289 buffer[1] = 0x80 | byte;
291 byte = value & (~0x80);
292 buffer[2] = 0x80 | byte;
294 byte = value & (~0x80);
295 buffer[3] = 0x80 | byte;
312 uint8_t byte = value & (~0x80);
313 buffer[0] = 0x80 | byte;
382 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2;
396 buffer += typeUidSize;
419 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
436 buffer += typeUidSize;
442 buffer += fragStartSize;
444 buffer += fragEndSize;
477 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
479 if (available >= n &&
488 buffer += typeUidSize;
494 buffer += fragStartSize;
496 buffer += fragEndSize;
509 uint16_t current =
m_head;
510 while (current != 0xffff && current !=
m_tail)
514 ReadItems (current, &tmpItem, &tmpExtraItem);
516 &tmpItem, &tmpExtraItem);
518 current = tmpItem.
next;
521 uint16_t written = h.
AddBig (0xffff, h.
m_tail, item, extraItem);
538 item->
next = buffer[0];
539 item->
next |= (buffer[1]) << 8;
540 item->
prev = buffer[2];
541 item->
prev |= (buffer[3]) << 8;
549 bool isExtra = (item->
typeUid & 0x1) == 0x1;
567 return buffer - &m_data->m_data[current];
622 uint32_t size =
sizeof (
struct Data);
628 uint8_t *buf =
new uint8_t [size];
639 uint8_t *buf = (uint8_t *)data;
680 uint16_t written =
AddSmall (&item);
697 if ((item.
typeUid & 0xfffffffe) != uid ||
706 else if (item.
typeUid != uid &&
749 uint16_t written =
AddSmall (&item);
767 if ((item.
typeUid & 0xfffffffe) != uid ||
776 else if (item.
typeUid != uid &&
837 if (extraItem.packetUid == tailExtraItem.packetUid &&
841 extraItem.fragmentStart == tailExtraItem.fragmentEnd)
848 tailExtraItem.fragmentEnd = extraItem.fragmentEnd;
866 while (current != 0xffff)
868 o.
ReadItems (current, &item, &extraItem);
869 uint16_t written =
AddBig (0xffff,
m_tail, &item, &extraItem);
900 uint32_t leftToRemove =
start;
901 uint16_t current =
m_head;
902 while (current != 0xffff && leftToRemove > 0)
907 uint32_t itemRealSize = extraItem.fragmentEnd - extraItem.fragmentStart;
908 if (itemRealSize <= leftToRemove)
920 leftToRemove -= itemRealSize;
926 extraItem.fragmentStart += leftToRemove;
928 uint16_t written = fragment.
AddBig (0xffff, fragment.
m_tail,
931 while (current != 0xffff && current !=
m_tail)
941 NS_ASSERT (item.
size >= extraItem.fragmentEnd - extraItem.fragmentStart &&
942 extraItem.fragmentStart <= extraItem.fragmentEnd);
964 uint32_t leftToRemove = end;
965 uint16_t current =
m_tail;
966 while (current != 0xffff && leftToRemove > 0)
971 uint32_t itemRealSize = extraItem.fragmentEnd - extraItem.fragmentStart;
972 if (itemRealSize <= leftToRemove)
984 leftToRemove -= itemRealSize;
990 NS_ASSERT (extraItem.fragmentEnd > leftToRemove);
991 extraItem.fragmentEnd -= leftToRemove;
993 uint16_t written = fragment.
AddBig (fragment.
m_head, 0xffff,
996 while (current != 0xffff && current !=
m_head)
1006 NS_ASSERT (item.
size >= extraItem.fragmentEnd - extraItem.fragmentStart &&
1007 extraItem.fragmentStart <= extraItem.fragmentEnd);
1012 current = item.
prev;
1021 uint32_t totalSize = 0;
1022 uint16_t current =
m_head;
1024 while (current != 0xffff)
1029 totalSize += extraItem.fragmentEnd - extraItem.fragmentStart;
1030 if (current == tail)
1035 current = item.
next;
1053 : m_metadata (metadata),
1055 m_current (metadata->
m_head),
1057 m_hasReadTail (false)
1065 if (m_current == 0xffff)
1082 m_metadata->ReadItems (m_current, &smallItem, &extraItem);
1083 if (m_current == m_metadata->m_tail)
1085 m_hasReadTail =
true;
1087 m_current = smallItem.
next;
1088 uint32_t uid = (smallItem.
typeUid & 0xfffffffe) >> 1;
1112 item.
current = m_buffer.Begin ();
1121 item.
current = m_buffer.End ();
1122 item.
current.
Prev (m_buffer.GetSize () - (m_offset + smallItem.
size));
1137 uint32_t totalSize = 0;
1152 uint32_t current =
m_head;
1153 while (current != 0xffff)
1156 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1165 totalSize += 4 + tid.
GetName ().size ();
1167 totalSize += 1 + 4 + 2 + 4 + 4 + 8;
1173 current = item.
next;
1182 uint8_t*
start = buffer;
1192 uint32_t current =
m_head;
1193 while (current != 0xffff)
1196 NS_LOG_LOGIC (
"bytesWritten=" << static_cast<uint32_t> (buffer - start) <<
", typeUid="<<
1198 ", fragmentStart="<<extraItem.
fragmentStart<<
", fragmentEnd="<<
1201 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1206 std::string uidString = tid.
GetName ();
1207 uint32_t uidStringSize = uidString.size ();
1208 buffer =
AddToRawU32 (uidStringSize, start, buffer, maxSize);
1213 buffer =
AddToRaw (reinterpret_cast<const uint8_t *> (uidString.c_str ()),
1214 uidStringSize, start, buffer, maxSize);
1229 uint8_t isBig = item.
typeUid & 0x1;
1230 buffer =
AddToRawU8 (isBig, start, buffer, maxSize);
1272 current = item.
next;
1275 NS_ASSERT (static_cast<uint32_t> (buffer - start) == maxSize);
1283 const uint8_t*
start = buffer;
1284 uint32_t desSize = size - 4;
1293 uint32_t uidStringSize = 0;
1297 if (uidStringSize == 0)
1304 std::string uidString;
1305 for (uint32_t j = 0; j < uidStringSize; j++)
1309 uidString.push_back (ch);
1318 item.
typeUid = (uid << 1) | isBig;
1331 ", fragmentStart="<<extraItem.
fragmentStart<<
", fragmentEnd="<<
1333 uint32_t tmp =
AddBig (0xffff,
m_tail, &item, &extraItem);
1337 return (desSize !=0) ? 0 : 1;
1346 NS_LOG_FUNCTION (static_cast<uint32_t> (data) << &start << ¤t << maxSize);
1348 if (static_cast<uint32_t> ((current +
sizeof (uint8_t) - start)) > maxSize)
1352 memcpy (current, &data,
sizeof (uint8_t));
1353 return current +
sizeof (uint8_t);
1364 if (static_cast<uint32_t> ((current +
sizeof (uint16_t) - start)) > maxSize)
1368 memcpy (current, &data,
sizeof (uint16_t));
1369 return current +
sizeof (uint16_t);
1380 if (static_cast<uint32_t> ((current +
sizeof (uint32_t) - start)) > maxSize)
1384 memcpy (current, &data,
sizeof (uint32_t));
1385 return current +
sizeof (uint32_t);
1396 if (static_cast<uint32_t> ((current +
sizeof (uint64_t) - start)) > maxSize)
1400 memcpy (current, &data,
sizeof (uint64_t));
1401 return current +
sizeof (uint64_t);
1413 if (static_cast<uint32_t> ((current + dataSize - start)) > maxSize)
1417 memcpy (current, data, dataSize);
1418 return current + dataSize;
1423 const uint8_t*
start,
1424 const uint8_t* current,
1427 NS_LOG_FUNCTION (static_cast<uint32_t> (data) << &start << ¤t << maxSize);
1429 if (static_cast<uint32_t> ((current +
sizeof (uint8_t) - start)) > maxSize)
1433 memcpy (&data, current,
sizeof (uint8_t));
1434 return const_cast<uint8_t *
> (current) +
sizeof (uint8_t);
1439 const uint8_t*
start,
1440 const uint8_t* current,
1445 if (static_cast<uint32_t> ((current +
sizeof (uint16_t) - start)) > maxSize)
1449 memcpy (&data, current,
sizeof (uint16_t));
1450 return const_cast<uint8_t *
> (current) +
sizeof (uint16_t);
1455 const uint8_t*
start,
1456 const uint8_t* current,
1461 if (static_cast<uint32_t> ((current +
sizeof (uint32_t) - start)) > maxSize)
1465 memcpy (&data, current,
sizeof (uint32_t));
1466 return const_cast<uint8_t *
> (current) +
sizeof (uint32_t);
1471 const uint8_t*
start,
1472 const uint8_t* current,
1477 if ((uint32_t)((current +
sizeof (uint64_t) - start)) > maxSize)
1481 memcpy (&data, current,
sizeof (uint64_t));
1482 return const_cast<uint8_t *
> (current) +
sizeof (uint64_t);
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
automatically resized byte buffer
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_FATAL_ERROR(msg)
Report a fatal error with a message and terminate.
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static TypeId GetTypeId(void)
Get the type ID.
void Prev(void)
go backward by one byte
void Next(void)
go forward by one byte
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Protocol trailer serialization and deserialization.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string GetName(void) const
Get the name.
uint16_t GetUid(void) const
Get the internal id of this TypeId.
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
virtual TypeId GetInstanceTypeId(void) const =0
Get the most derived TypeId for this Object.
bool IsChildOf(TypeId other) const
Check if this TypeId is a child of another.
a unique identifier for an interface.
static TypeId LookupByName(std::string name)
Get a TypeId by name.