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;
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;
269 if (value < 0x10000000)
271 uint8_t
byte = value & (~0x80);
272 buffer[0] = 0x80 |
byte;
274 byte = value & (~0x80);
275 buffer[1] = 0x80 |
byte;
277 byte = value & (~0x80);
278 buffer[2] = 0x80 |
byte;
284 uint8_t
byte = value & (~0x80);
285 buffer[0] = 0x80 |
byte;
287 byte = value & (~0x80);
288 buffer[1] = 0x80 |
byte;
290 byte = value & (~0x80);
291 buffer[2] = 0x80 |
byte;
293 byte = value & (~0x80);
294 buffer[3] = 0x80 |
byte;
311 uint8_t
byte = value & (~0x80);
312 buffer[0] = 0x80 |
byte;
381 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2;
395 buffer += typeUidSize;
418 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
435 buffer += typeUidSize;
441 buffer += fragStartSize;
443 buffer += fragEndSize;
476 uint32_t n = 2 + 2 + typeUidSize + sizeSize + 2 + fragStartSize + fragEndSize + 4;
478 if (available >= n &&
487 buffer += typeUidSize;
493 buffer += fragStartSize;
495 buffer += fragEndSize;
508 uint16_t current =
m_head;
509 while (current != 0xffff && current !=
m_tail)
513 ReadItems (current, &tmpItem, &tmpExtraItem);
515 &tmpItem, &tmpExtraItem);
517 current = tmpItem.
next;
520 uint16_t written = h.
AddBig (0xffff, h.
m_tail, item, extraItem);
537 item->
next = buffer[0];
538 item->
next |= (buffer[1]) << 8;
539 item->
prev = buffer[2];
540 item->
prev |= (buffer[3]) << 8;
548 bool isExtra = (item->
typeUid & 0x1) == 0x1;
582 if (
data->m_size >= size)
621 uint32_t size =
sizeof (
struct Data);
627 uint8_t *buf =
new uint8_t [size];
631 data->m_dirtyEnd = 0;
638 uint8_t *buf = (uint8_t *)
data;
679 uint16_t written =
AddSmall (&item);
696 if ((item.
typeUid & 0xfffffffe) != uid ||
705 else if (item.
typeUid != uid &&
748 uint16_t written =
AddSmall (&item);
766 if ((item.
typeUid & 0xfffffffe) != uid ||
775 else if (item.
typeUid != uid &&
836 if (extraItem.packetUid == tailExtraItem.packetUid &&
840 extraItem.fragmentStart == tailExtraItem.fragmentEnd)
847 tailExtraItem.fragmentEnd = extraItem.fragmentEnd;
865 while (current != 0xffff)
867 o.
ReadItems (current, &item, &extraItem);
868 uint16_t written =
AddBig (0xffff,
m_tail, &item, &extraItem);
899 uint32_t leftToRemove =
start;
900 uint16_t current =
m_head;
901 while (current != 0xffff && leftToRemove > 0)
906 uint32_t itemRealSize = extraItem.fragmentEnd - extraItem.fragmentStart;
907 if (itemRealSize <= leftToRemove)
919 leftToRemove -= itemRealSize;
925 extraItem.fragmentStart += leftToRemove;
927 uint16_t written = fragment.
AddBig (0xffff, fragment.
m_tail,
930 while (current != 0xffff && current !=
m_tail)
940 NS_ASSERT (item.
size >= extraItem.fragmentEnd - extraItem.fragmentStart &&
941 extraItem.fragmentStart <= extraItem.fragmentEnd);
963 uint32_t leftToRemove = end;
964 uint16_t current =
m_tail;
965 while (current != 0xffff && leftToRemove > 0)
970 uint32_t itemRealSize = extraItem.fragmentEnd - extraItem.fragmentStart;
971 if (itemRealSize <= leftToRemove)
983 leftToRemove -= itemRealSize;
989 NS_ASSERT (extraItem.fragmentEnd > leftToRemove);
990 extraItem.fragmentEnd -= leftToRemove;
992 uint16_t written = fragment.
AddBig (fragment.
m_head, 0xffff,
995 while (current != 0xffff && current !=
m_head)
1005 NS_ASSERT (item.
size >= extraItem.fragmentEnd - extraItem.fragmentStart &&
1006 extraItem.fragmentStart <= extraItem.fragmentEnd);
1011 current = item.
prev;
1020 uint32_t totalSize = 0;
1021 uint16_t current =
m_head;
1023 while (current != 0xffff)
1028 totalSize += extraItem.fragmentEnd - extraItem.fragmentStart;
1029 if (current == tail)
1034 current = item.
next;
1052 : m_metadata (metadata),
1054 m_current (metadata->
m_head),
1056 m_hasReadTail (false)
1064 if (m_current == 0xffff)
1081 m_metadata->ReadItems (m_current, &smallItem, &extraItem);
1082 if (m_current == m_metadata->m_tail)
1084 m_hasReadTail =
true;
1086 m_current = smallItem.
next;
1087 uint32_t uid = (smallItem.
typeUid & 0xfffffffe) >> 1;
1111 item.
current = m_buffer.Begin ();
1120 item.
current = m_buffer.End ();
1121 item.
current.
Prev (m_buffer.GetSize () - (m_offset + smallItem.
size));
1136 uint32_t totalSize = 0;
1151 uint32_t current =
m_head;
1152 while (current != 0xffff)
1155 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1164 totalSize += 4 + tid.
GetName ().size ();
1166 totalSize += 1 + 4 + 2 + 4 + 4 + 8;
1172 current = item.
next;
1181 uint8_t*
start = buffer;
1191 uint32_t current =
m_head;
1192 while (current != 0xffff)
1195 NS_LOG_LOGIC (
"bytesWritten=" <<
static_cast<uint32_t
> (buffer -
start) <<
", typeUid="<<
1197 ", fragmentStart="<<extraItem.
fragmentStart<<
", fragmentEnd="<<
1200 uint32_t uid = (item.
typeUid & 0xfffffffe) >> 1;
1205 std::string uidString = tid.
GetName ();
1206 uint32_t uidStringSize = uidString.size ();
1212 buffer =
AddToRaw (
reinterpret_cast<const uint8_t *
> (uidString.c_str ()),
1213 uidStringSize,
start, buffer, maxSize);
1228 uint8_t isBig = item.
typeUid & 0x1;
1271 current = item.
next;
1282 const uint8_t*
start = buffer;
1283 uint32_t desSize = size - 4;
1292 uint32_t uidStringSize = 0;
1296 if (uidStringSize == 0)
1303 std::string uidString;
1304 for (uint32_t j = 0; j < uidStringSize; j++)
1308 uidString.push_back (ch);
1317 item.
typeUid = (uid << 1) | isBig;
1330 ", fragmentStart="<<extraItem.
fragmentStart<<
", fragmentEnd="<<
1332 uint32_t tmp =
AddBig (0xffff,
m_tail, &item, &extraItem);
1336 return (desSize !=0) ? 0 : 1;
1347 if (
static_cast<uint32_t
> ((current +
sizeof (uint8_t) -
start)) > maxSize)
1351 memcpy (current, &
data,
sizeof (uint8_t));
1352 return current +
sizeof (uint8_t);
1363 if (
static_cast<uint32_t
> ((current +
sizeof (uint16_t) -
start)) > maxSize)
1367 memcpy (current, &
data,
sizeof (uint16_t));
1368 return current +
sizeof (uint16_t);
1379 if (
static_cast<uint32_t
> ((current +
sizeof (uint32_t) -
start)) > maxSize)
1383 memcpy (current, &
data,
sizeof (uint32_t));
1384 return current +
sizeof (uint32_t);
1395 if (
static_cast<uint32_t
> ((current +
sizeof (uint64_t) -
start)) > maxSize)
1399 memcpy (current, &
data,
sizeof (uint64_t));
1400 return current +
sizeof (uint64_t);
1412 if (
static_cast<uint32_t
> ((current + dataSize -
start)) > maxSize)
1416 memcpy (current,
data, dataSize);
1417 return current + dataSize;
1422 const uint8_t*
start,
1423 const uint8_t* current,
1428 if (
static_cast<uint32_t
> ((current +
sizeof (uint8_t) -
start)) > maxSize)
1432 memcpy (&
data, current,
sizeof (uint8_t));
1433 return const_cast<uint8_t *
> (current) +
sizeof (uint8_t);
1438 const uint8_t*
start,
1439 const uint8_t* current,
1444 if (
static_cast<uint32_t
> ((current +
sizeof (uint16_t) -
start)) > maxSize)
1448 memcpy (&
data, current,
sizeof (uint16_t));
1449 return const_cast<uint8_t *
> (current) +
sizeof (uint16_t);
1454 const uint8_t*
start,
1455 const uint8_t* current,
1460 if (
static_cast<uint32_t
> ((current +
sizeof (uint32_t) -
start)) > maxSize)
1464 memcpy (&
data, current,
sizeof (uint32_t));
1465 return const_cast<uint8_t *
> (current) +
sizeof (uint32_t);
1470 const uint8_t*
start,
1471 const uint8_t* current,
1476 if ((uint32_t)((current +
sizeof (uint64_t) -
start)) > maxSize)
1480 memcpy (&
data, current,
sizeof (uint64_t));
1481 return const_cast<uint8_t *
> (current) +
sizeof (uint64_t);
void Next(void)
go forward by one byte
void Prev(void)
go backward by one byte
automatically resized byte buffer
virtual TypeId GetInstanceTypeId(void) const =0
Get the most derived TypeId for this Object.
Protocol trailer serialization and deserialization.
static TypeId GetTypeId(void)
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.
uint16_t GetUid(void) const
Get the internal id of this TypeId.
void SetUid(uint16_t uid)
Set the internal id of this TypeId.
std::string GetName(void) 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.