22 #include "ns3/assert.h"
23 #include "ns3/fatal-error.h"
44 for (iterator i = begin (); i != end (); i++)
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;
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;
483 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
485 if (available >= n &&
494 buffer += typeUidSize;
500 buffer += fragStartSize;
502 buffer += fragEndSize;
516 while (current != 0xffff && current !=
m_tail)
520 ReadItems (current, &tmpItem, &tmpExtraItem);
522 &tmpItem, &tmpExtraItem);
524 current = tmpItem.
next;
527 uint16_t written = h.
AddBig (0xffff, h.
m_tail, item, extraItem);
549 item->
next = buffer[0];
550 item->
next |= (buffer[1]) << 8;
551 item->
prev = buffer[2];
552 item->
prev |= (buffer[3]) << 8;
560 bool isExtra = (item->
typeUid & 0x1) == 0x1;
578 return buffer - &m_data->m_data[
current];
633 uint32_t size =
sizeof (
struct Data);
639 uint8_t *buf =
new uint8_t [size];
650 uint8_t *buf = (uint8_t *)data;
691 uint16_t written =
AddSmall (&item);
708 if ((item.
typeUid & 0xfffffffe) != uid ||
717 else if (item.
typeUid != uid &&
760 uint16_t written =
AddSmall (&item);
778 if ((item.
typeUid & 0xfffffffe) != uid ||
787 else if (item.
typeUid != uid &&
848 if (extraItem.packetUid == tailExtraItem.packetUid &&
852 extraItem.fragmentStart == tailExtraItem.fragmentEnd)
859 tailExtraItem.fragmentEnd = extraItem.fragmentEnd;
877 while (current != 0xffff)
879 o.
ReadItems (current, &item, &extraItem);
880 uint16_t written =
AddBig (0xffff,
m_tail, &item, &extraItem);
911 uint32_t leftToRemove =
start;
913 while (current != 0xffff && leftToRemove > 0)
918 uint32_t itemRealSize = extraItem.fragmentEnd - extraItem.fragmentStart;
919 if (itemRealSize <= leftToRemove)
931 leftToRemove -= itemRealSize;
937 extraItem.fragmentStart += leftToRemove;
939 uint16_t written = fragment.
AddBig (0xffff, fragment.
m_tail,
942 while (current != 0xffff && current !=
m_tail)
952 NS_ASSERT (item.
size >= extraItem.fragmentEnd - extraItem.fragmentStart &&
953 extraItem.fragmentStart <= extraItem.fragmentEnd);
975 uint32_t leftToRemove = end;
977 while (current != 0xffff && leftToRemove > 0)
982 uint32_t itemRealSize = extraItem.fragmentEnd - extraItem.fragmentStart;
983 if (itemRealSize <= leftToRemove)
995 leftToRemove -= itemRealSize;
1001 NS_ASSERT (extraItem.fragmentEnd > leftToRemove);
1002 extraItem.fragmentEnd -= leftToRemove;
1004 uint16_t written = fragment.
AddBig (fragment.
m_head, 0xffff,
1007 while (current != 0xffff && current !=
m_head)
1009 current = item.
prev;
1017 NS_ASSERT (item.
size >= extraItem.fragmentEnd - extraItem.fragmentStart &&
1018 extraItem.fragmentStart <= extraItem.fragmentEnd);
1023 current = item.
prev;
1032 uint32_t totalSize = 0;
1035 while (current != 0xffff)
1040 totalSize += extraItem.fragmentEnd - extraItem.fragmentStart;
1041 if (current == tail)
1046 current = item.
next;
1064 : m_metadata (metadata),
1066 m_current (metadata->
m_head),
1068 m_hasReadTail (false)
1076 if (m_current == 0xffff)
1093 m_metadata->ReadItems (m_current, &smallItem, &extraItem);
1094 if (m_current == m_metadata->m_tail)
1096 m_hasReadTail =
true;
1098 m_current = smallItem.
next;
1099 uint32_t uid = (smallItem.
typeUid & 0xfffffffe) >> 1;
1152 uint32_t totalSize = 0;
1168 while (current != 0xffff)
1171 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1180 totalSize += 4 + tid.
GetName ().size ();
1182 totalSize += 1 + 4 + 2 + 4 + 4 + 8;
1188 current = item.
next;
1197 uint8_t*
start = buffer;
1208 while (current != 0xffff)
1211 NS_LOG_LOGIC (
"bytesWritten=" << static_cast<uint32_t> (buffer - start) <<
", typeUid="<<
1213 ", fragmentStart="<<extraItem.
fragmentStart<<
", fragmentEnd="<<
1216 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1221 std::string uidString = tid.
GetName ();
1222 uint32_t uidStringSize = uidString.size ();
1223 buffer =
AddToRawU32 (uidStringSize, start, buffer, maxSize);
1228 buffer =
AddToRaw (reinterpret_cast<const uint8_t *> (uidString.c_str ()),
1229 uidStringSize, start, buffer, maxSize);
1244 uint8_t isBig = item.
typeUid & 0x1;
1245 buffer =
AddToRawU8 (isBig, start, buffer, maxSize);
1287 current = item.
next;
1290 NS_ASSERT (static_cast<uint32_t> (buffer - start) == maxSize);
1298 const uint8_t*
start = buffer;
1299 uint32_t desSize = size - 4;
1308 uint32_t uidStringSize = 0;
1312 if (uidStringSize == 0)
1319 std::string uidString;
1320 for (uint32_t j = 0; j < uidStringSize; j++)
1324 uidString.push_back (ch);
1333 item.
typeUid = (uid << 1) | isBig;
1346 ", fragmentStart="<<extraItem.
fragmentStart<<
", fragmentEnd="<<
1348 uint32_t tmp =
AddBig (0xffff,
m_tail, &item, &extraItem);
1352 return (desSize !=0) ? 0 : 1;
1361 NS_LOG_FUNCTION (static_cast<uint32_t> (data) << &start << ¤t << maxSize);
1363 if (static_cast<uint32_t> ((current +
sizeof (uint8_t) - start)) > maxSize)
1367 memcpy (current, &data,
sizeof (uint8_t));
1368 return current +
sizeof (uint8_t);
1379 if (static_cast<uint32_t> ((current +
sizeof (uint16_t) - start)) > maxSize)
1383 memcpy (current, &data,
sizeof (uint16_t));
1384 return current +
sizeof (uint16_t);
1395 if (static_cast<uint32_t> ((current +
sizeof (uint32_t) - start)) > maxSize)
1399 memcpy (current, &data,
sizeof (uint32_t));
1400 return current +
sizeof (uint32_t);
1411 if (static_cast<uint32_t> ((current +
sizeof (uint64_t) - start)) > maxSize)
1415 memcpy (current, &data,
sizeof (uint64_t));
1416 return current +
sizeof (uint64_t);
1428 if (static_cast<uint32_t> ((current + dataSize - start)) > maxSize)
1432 memcpy (current, data, dataSize);
1433 return current + dataSize;
1438 const uint8_t*
start,
1442 NS_LOG_FUNCTION (static_cast<uint32_t> (data) << &start << ¤t << maxSize);
1444 if (static_cast<uint32_t> ((current +
sizeof (uint8_t) - start)) > maxSize)
1448 memcpy (&data, current,
sizeof (uint8_t));
1449 return const_cast<uint8_t *
> (
current) +
sizeof (uint8_t);
1454 const uint8_t*
start,
1460 if (static_cast<uint32_t> ((current +
sizeof (uint16_t) - start)) > maxSize)
1464 memcpy (&data, current,
sizeof (uint16_t));
1465 return const_cast<uint8_t *
> (
current) +
sizeof (uint16_t);
1470 const uint8_t*
start,
1476 if (static_cast<uint32_t> ((current +
sizeof (uint32_t) - start)) > maxSize)
1480 memcpy (&data, current,
sizeof (uint32_t));
1481 return const_cast<uint8_t *
> (
current) +
sizeof (uint32_t);
1486 const uint8_t*
start,
1492 if ((uint32_t)((current +
sizeof (uint64_t) - start)) > maxSize)
1496 memcpy (&data, current,
sizeof (uint64_t));
1497 return const_cast<uint8_t *
> (
current) +
sizeof (uint64_t);
#define NS_LOG_FUNCTION(parameters)
void RemoveAtEnd(uint32_t end)
void RemoveAtStart(uint32_t start)
automatically resized byte buffer
#define NS_ASSERT(condition)
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
static TypeId GetTypeId(void)
#define NS_FATAL_ERROR(msg)
fatal error handling
Buffer::Iterator End(void) const
#define NS_LOG_LOGIC(msg)
Buffer::Iterator Begin(void) const
Protocol trailer serialization and deserialization.
void SetUid(uint16_t tid)
std::string GetName(void) const
uint16_t GetUid(void) const
uint32_t GetSize(void) const
#define NS_ASSERT_MSG(condition, message)
virtual TypeId GetInstanceTypeId(void) const =0
bool IsChildOf(TypeId other) const
a unique identifier for an interface.
static TypeId LookupByName(std::string name)