A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
packet-metadata.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2006,2007 INRIA
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef PACKET_METADATA_H
9#define PACKET_METADATA_H
10
11#include "buffer.h"
12
13#include "ns3/assert.h"
14#include "ns3/callback.h"
15#include "ns3/type-id.h"
16
17#include <limits>
18#include <stdint.h>
19#include <vector>
20
21namespace ns3
22{
23
24class Chunk;
25class Buffer;
26class Header;
27class Trailer;
28
29/**
30 * @ingroup packet
31 * @brief Handle packet metadata about packet headers and trailers
32 *
33 * This class is used by the Packet class to record every operation
34 * performed on the packet's buffer. This class also provides
35 * an implementation of the Packet::Print methods which uses
36 * the metadata to analyse the content of the packet's buffer.
37 *
38 * To achieve this, this class maintains a linked list of so-called
39 * "items", each of which represents a header or a trailer, or
40 * payload, or a fragment of any of these. Each item contains a "next"
41 * and a "prev" field which point to the next and previous entries
42 * in the linked list. The PacketMetadata class maintains a pair
43 * of pointers to the head and the tail of the linked list.
44 *
45 * Each entry in the list also maintains:
46 * - its native size (the size it had when it was first added
47 * to the packet)
48 * - its type: identifies what kind of header, what kind of trailer,
49 * if it is payload or not
50 * - the uid of the packet to which it was first added
51 * - the start and end of the area represented by a fragment
52 * if it is one.
53 *
54 * This linked list is flattened in a byte buffer stored in
55 * struct PacketMetadata::Data. Each entry of the linked list is
56 * identified by an offset which identifies the first byte of the
57 * entry from the start of the data buffer. The size of this data
58 * buffer is 2^16-1 bytes maximum which somewhat limits the number
59 * of entries which can be stored in this linked list but it is
60 * quite unlikely to hit this limit in practice.
61 *
62 * Each item of the linked list is a variable-sized byte buffer
63 * made of a number of fields. Some of these fields are stored
64 * as fixed-size 32 bit integers, others as fixed-size 16 bit
65 * integers, and some others as variable-size 32-bit integers.
66 * The variable-size 32 bit integers are stored using the uleb128
67 * encoding.
68 */
70{
71 public:
72 /**
73 * @brief structure describing a packet metadata item
74 */
75 struct Item
76 {
77 /// Type of data in the packet
79 {
80 PAYLOAD, //!< Payload
81 HEADER, //!< Header
82 TRAILER //!< Trailer
83 };
84
85 /**
86 * metadata type
87 */
89
90 /**
91 * true: this is a fragmented header, trailer, or, payload.
92 * false: this is a whole header, trailer, or, payload.
93 */
95 /**
96 * TypeId of Header or Trailer. Valid only if type is
97 * header or trailer.
98 */
100 /**
101 * size of item. If fragment, size of fragment. Otherwise,
102 * size of original item.
103 */
105 /**
106 * how many bytes were trimmed from the start of a fragment.
107 * if isFragment is true, this field is zero.
108 */
110 /**
111 * how many bytes were trimmed from the end of a fragment.
112 * if isFragment is true, this field is zero.
113 */
115 /**
116 * an iterator which can be fed to Deserialize. Valid only
117 * if isFragment and isPayload are false.
118 */
120 };
121
122 /**
123 * @brief Iterator class for metadata items.
124 */
126 {
127 public:
128 /**
129 * @brief Constructor
130 * @param metadata a pointer to the metadata
131 * @param buffer the buffer the metadata refers to
132 */
133 ItemIterator(const PacketMetadata* metadata, Buffer buffer);
134 /**
135 * @brief Checks if there is another metadata item
136 * @returns true if there is another item
137 */
138 bool HasNext() const;
139 /**
140 * @brief Retrieve the next metadata item
141 * @returns the next metadata item
142 */
143 Item Next();
144
145 private:
146 const PacketMetadata* m_metadata; //!< pointer to the metadata
147 Buffer m_buffer; //!< buffer the metadata refers to
148 uint16_t m_current; //!< current position
149 uint32_t m_offset; //!< offset
150 bool m_hasReadTail; //!< true if the metadata tail has been read
151 };
152
153 /**
154 * @brief Enable the packet metadata
155 */
156 static void Enable();
157 /**
158 * @brief Enable the packet metadata checking
159 */
160 static void EnableChecking();
161
162 /**
163 * @brief Constructor
164 * @param uid packet uid
165 * @param size size of the header
166 */
167 inline PacketMetadata(uint64_t uid, uint32_t size);
168 /**
169 * @brief Copy constructor
170 * @param o the object to copy
171 */
172 inline PacketMetadata(const PacketMetadata& o);
173 /**
174 * @brief Basic assignment
175 * @param o the object to copy
176 * @return a copied object
177 */
178 inline PacketMetadata& operator=(const PacketMetadata& o);
179 inline ~PacketMetadata();
180
181 // Delete default constructor to avoid misuse
182 PacketMetadata() = delete;
183
184 /**
185 * @brief Add an header
186 * @param header header to add
187 * @param size header serialized size
188 */
189 void AddHeader(const Header& header, uint32_t size);
190 /**
191 * @brief Remove an header
192 * @param header header to remove
193 * @param size header serialized size
194 */
195 void RemoveHeader(const Header& header, uint32_t size);
196
197 /**
198 * Add a trailer
199 * @param trailer trailer to add
200 * @param size trailer serialized size
201 */
202 void AddTrailer(const Trailer& trailer, uint32_t size);
203 /**
204 * Remove a trailer
205 * @param trailer trailer to remove
206 * @param size trailer serialized size
207 */
208 void RemoveTrailer(const Trailer& trailer, uint32_t size);
209
210 /**
211 * @brief Creates a fragment.
212 *
213 * @param start the amount of stuff to remove from the start
214 * @param end the amount of stuff to remove from the end
215 * @return the fragment's metadata
216 *
217 * Calling this method is equivalent to calling RemoveAtStart (start)
218 * and then, RemoveAtEnd (end).
219 */
221
222 /**
223 * @brief Add a metadata at the metadata start
224 * @param o the metadata to add
225 */
226 void AddAtEnd(const PacketMetadata& o);
227 /**
228 * @brief Add some padding at the end
229 * @param end size of padding
230 */
231 void AddPaddingAtEnd(uint32_t end);
232 /**
233 * @brief Remove a chunk of metadata at the metadata start
234 * @param start the size of metadata to remove
235 */
236 void RemoveAtStart(uint32_t start);
237 /**
238 * @brief Remove a chunk of metadata at the metadata end
239 * @param end the size of metadata to remove
240 */
241 void RemoveAtEnd(uint32_t end);
242
243 /**
244 * @brief Get the packet Uid
245 * @return the packet Uid
246 */
247 uint64_t GetUid() const;
248
249 /**
250 * @brief Get the metadata serialized size
251 * @return the serialized size
252 */
254
255 /**
256 * @brief Initialize the item iterator to the buffer begin
257 * @param buffer buffer to initialize.
258 * @return the buffer iterator.
259 */
260 ItemIterator BeginItem(Buffer buffer) const;
261
262 /**
263 * @brief Serialization to raw uint8_t*
264 * @param buffer the buffer to serialize to
265 * @param maxSize the maximum serialization size
266 * @return 1 on success, 0 on failure
267 */
268 uint32_t Serialize(uint8_t* buffer, uint32_t maxSize) const;
269 /**
270 * @brief Deserialization from raw uint8_t*
271 * @param buffer the buffer to deserialize from
272 * @param size the size
273 * @return 1 on success, 0 on failure
274 */
275 uint32_t Deserialize(const uint8_t* buffer, uint32_t size);
276
277 private:
278 /**
279 * @brief Helper for the raw serialization.
280 *
281 * @param data the buffer to write to
282 * @param start start index
283 * @param current current index
284 * @param maxSize maximum size
285 * @return updated current index
286 */
287 static uint8_t* AddToRawU8(const uint8_t& data,
288 uint8_t* start,
289 uint8_t* current,
290 uint32_t maxSize);
291
292 /**
293 * @brief Helper for the raw serialization.
294 *
295 * @param data the buffer to write to
296 * @param start start index
297 * @param current current index
298 * @param maxSize maximum size
299 * @return updated current index
300 */
301 static uint8_t* AddToRawU16(const uint16_t& data,
302 uint8_t* start,
303 uint8_t* current,
304 uint32_t maxSize);
305
306 /**
307 * @brief Helper for the raw serialization.
308 *
309 * @param data the buffer to write to
310 * @param start start index
311 * @param current current index
312 * @param maxSize maximum size
313 * @return updated current index
314 */
315 static uint8_t* AddToRawU32(const uint32_t& data,
316 uint8_t* start,
317 uint8_t* current,
318 uint32_t maxSize);
319
320 /**
321 * @brief Helper for the raw serialization.
322 *
323 * @param data the buffer to write to
324 * @param start start index
325 * @param current current index
326 * @param maxSize maximum size
327 * @return updated current index
328 */
329 static uint8_t* AddToRawU64(const uint64_t& data,
330 uint8_t* start,
331 uint8_t* current,
332 uint32_t maxSize);
333
334 /**
335 * @brief Helper for the raw serialization.
336 *
337 * @param data the buffer to write to
338 * @param dataSize the data size to write to
339 * @param start start index
340 * @param current current index
341 * @param maxSize maximum size
342 * @return updated current index
343 */
344 static uint8_t* AddToRaw(const uint8_t* data,
345 uint32_t dataSize,
346 uint8_t* start,
347 uint8_t* current,
348 uint32_t maxSize);
349
350 /**
351 * @brief Helper for the raw deserialization.
352 *
353 * @param data the buffer to read from
354 * @param start start index
355 * @param current current index
356 * @param maxSize maximum size
357 * @return updated current index
358 */
359 static uint8_t* ReadFromRawU8(uint8_t& data,
360 const uint8_t* start,
361 const uint8_t* current,
362 uint32_t maxSize);
363
364 /**
365 * @brief Helper for the raw deserialization.
366 *
367 * @param data the buffer to read from
368 * @param start start index
369 * @param current current index
370 * @param maxSize maximum size
371 * @return updated current index
372 */
373 static uint8_t* ReadFromRawU16(uint16_t& data,
374 const uint8_t* start,
375 const uint8_t* current,
376 uint32_t maxSize);
377
378 /**
379 * @brief Helper for the raw deserialization.
380 *
381 * @param data the buffer to read from
382 * @param start start index
383 * @param current current index
384 * @param maxSize maximum size
385 * @return updated current index
386 */
387 static uint8_t* ReadFromRawU32(uint32_t& data,
388 const uint8_t* start,
389 const uint8_t* current,
390 uint32_t maxSize);
391
392 /**
393 * @brief Helper for the raw deserialization.
394 *
395 * @param data the buffer to read from
396 * @param start start index
397 * @param current current index
398 * @param maxSize maximum size
399 * @return updated current index
400 */
401 static uint8_t* ReadFromRawU64(uint64_t& data,
402 const uint8_t* start,
403 const uint8_t* current,
404 uint32_t maxSize);
405
406 /**
407 * the size of PacketMetadata::Data::m_data such that the total size
408 * of PacketMetadata::Data is 16 bytes
409 */
410#define PACKET_METADATA_DATA_M_DATA_SIZE 8
411
412 /**
413 * Data structure
414 */
415 struct Data
416 {
417 /** number of references to this struct Data instance. */
419 /** size (in bytes) of m_data buffer below */
421 /** max of the m_used field over all objects which reference this struct Data instance */
422 uint16_t m_dirtyEnd;
423 /** variable-sized buffer of bytes */
425 };
426
427 /* Note that since the next and prev fields are 16 bit integers
428 and since the value 0xffff is reserved to identify the
429 fact that the end or the start of the list is reached,
430 only a limited number of elements can be stored in
431 a m_data byte buffer.
432 */
433 /**
434 * @brief SmallItem structure
435 */
437 {
438 /** offset (in bytes) from start of m_data buffer
439 to next element in linked list. value is 0xffff
440 if next element does not exist.
441 stored as a fixed-size 16 bit integer.
442 */
443 uint16_t next;
444 /** offset (in bytes) from start of m_data buffer
445 to previous element in linked list. value is 0xffff
446 if previous element does not exist.
447 stored as a fixed-size 16 bit integer.
448 */
449 uint16_t prev;
450 /** the high 31 bits of this field identify the
451 type of the header or trailer represented by
452 this item: the value zero represents payload.
453 If the low bit of this uid is one, an ExtraItem
454 structure follows this SmallItem structure.
455 stored as a variable-size 32 bit integer.
456 */
458 /** the size (in bytes) of the header or trailer represented
459 by this element.
460 stored as a variable-size 32 bit integer.
461 */
463 /** this field tries to uniquely identify each header or
464 trailer _instance_ while the typeUid field uniquely
465 identifies each header or trailer _type_. This field
466 is used to test whether two items are equal in the sense
467 that they represent the same header or trailer instance.
468 That equality test is based on the typeUid and chunkUid
469 fields so, the likelihood that two header instances
470 share the same chunkUid _and_ typeUid is very small
471 unless they are really representations of the same header
472 instance.
473 stored as a fixed-size 16 bit integer.
474 */
475 uint16_t chunkUid;
476 };
477
478 /**
479 * @brief ExtraItem structure
480 */
482 {
483 /** offset (in bytes) from start of original header to
484 the start of the fragment still present.
485 stored as a variable-size 32 bit integer.
486 */
488 /** offset (in bytes) from start of original header to
489 the end of the fragment still present.
490 stored as a variable-size 32 bit integer.
491 */
493 /** the packetUid of the packet in which this header or trailer
494 was first added. It could be different from the m_packetUid
495 field if the user has aggregated multiple packets into one.
496 stored as a fixed-size 64 bit integer.
497 */
498 uint64_t packetUid;
499 };
500
501 /**
502 * @brief Class to hold all the metadata
503 */
504 class DataFreeList : public std::vector<Data*>
505 {
506 public:
508 };
509
511 /// Friend class
512 friend class ItemIterator;
513
514 /**
515 * @brief Add a SmallItem
516 * @param item the SmallItem to add
517 * @return added size
518 */
519 inline uint16_t AddSmall(const PacketMetadata::SmallItem* item);
520 /**
521 * @brief Add a "Big" Item (a SmallItem plus an ExtraItem)
522 * @param head the head
523 * @param tail the tail
524 * @param item the SmallItem to add
525 * @param extraItem the ExtraItem to add
526 * @return added size
527 */
528 uint16_t AddBig(uint32_t head,
529 uint32_t tail,
530 const PacketMetadata::SmallItem* item,
531 const PacketMetadata::ExtraItem* extraItem);
532 /**
533 * @brief Replace the tail
534 * @param item the item data to write
535 * @param extraItem the extra item data to write
536 * @param available the number of bytes which can
537 * be written without having to rewrite the buffer entirely.
538 */
540 PacketMetadata::ExtraItem* extraItem,
541 uint32_t available);
542 /**
543 * @brief Update the head
544 * @param written the used bytes
545 */
546 inline void UpdateHead(uint16_t written);
547 /**
548 * @brief Update the tail
549 * @param written the used bytes
550 */
551 inline void UpdateTail(uint16_t written);
552
553 /**
554 * @brief Get the ULEB128 (Unsigned Little Endian Base 128) size
555 * @param value the value
556 * @returns the value's ULEB128 size
557 */
558 inline uint32_t GetUleb128Size(uint32_t value) const;
559 /**
560 * @brief Read a ULEB128 (Unsigned Little Endian Base 128) coded number
561 * @param pBuffer the buffer to read from
562 * @returns the value
563 */
564 uint32_t ReadUleb128(const uint8_t** pBuffer) const;
565 /**
566 * @brief Append a 16-bit value to the buffer
567 * @param value the value to add
568 * @param buffer the buffer to write to
569 */
570 inline void Append16(uint16_t value, uint8_t* buffer);
571 /**
572 * @brief Append a 32-bit value to the buffer
573 * @param value the value to add
574 * @param buffer the buffer to write to
575 */
576 inline void Append32(uint32_t value, uint8_t* buffer);
577 /**
578 * @brief Append a value to the buffer
579 * @param value the value to add
580 * @param buffer the buffer to write to
581 */
582 inline void AppendValue(uint32_t value, uint8_t* buffer);
583 /**
584 * @brief Append a value to the buffer - extra
585 *
586 * This function is called by AppendValue
587 *
588 * @param value the value to add
589 * @param buffer the buffer to write to
590 */
591 void AppendValueExtra(uint32_t value, uint8_t* buffer);
592
593 /**
594 * @brief Reserve space
595 * @param n space to reserve
596 */
597 inline void Reserve(uint32_t n);
598 /**
599 * @brief Reserve space and make a metadata copy
600 * @param n space to reserve
601 */
602 void ReserveCopy(uint32_t n);
603
604 /**
605 * @brief Get the total size used by the metadata
606 * @return the metadata used size
607 */
608 uint32_t GetTotalSize() const;
609
610 /**
611 * @brief Read items
612 * @param current the offset we should start reading the data from
613 * @param item pointer to where we should store the data to return to the caller
614 * @param extraItem pointer to where we should store the data to return to the caller
615 * @returns the number of bytes read.
616 */
617 uint32_t ReadItems(uint16_t current,
619 PacketMetadata::ExtraItem* extraItem) const;
620 /**
621 * @brief Add an header
622 * @param uid header's uid to add
623 * @param size header serialized size
624 */
625 void DoAddHeader(uint32_t uid, uint32_t size);
626 /**
627 * @brief Check if the metadata state is ok
628 * @returns true if the internal state is ok
629 */
630 bool IsStateOk() const;
631 /**
632 * @brief Check if the position is valid
633 * @param pointer the position to check
634 * @returns true if the position is valid
635 */
636 bool IsPointerOk(uint16_t pointer) const;
637 /**
638 * @brief Check if the position is valid
639 * @param pointer the position to check
640 * @returns true if the position is valid
641 */
642 bool IsSharedPointerOk(uint16_t pointer) const;
643
644 /**
645 * @brief Recycle the buffer memory
646 * @param data the buffer data storage
647 */
648 static void Recycle(PacketMetadata::Data* data);
649 /**
650 * @brief Create a buffer data storage
651 * @param size the storage size to create
652 * @returns a pointer to the created buffer storage
653 */
655 /**
656 * @brief Allocate a buffer data storage
657 * @param n the storage size to create
658 * @returns a pointer to the allocated buffer storage
659 */
661 /**
662 * @brief Deallocate the buffer memory
663 * @param data the buffer data storage
664 */
666
667 static DataFreeList m_freeList; //!< the metadata data storage
668 static bool m_enable; //!< Enable the packet metadata
669 static bool m_enableChecking; //!< Enable the packet metadata checking
670
671 /**
672 * Set to true when adding metadata to a packet is skipped because
673 * m_enable is false; used to detect enabling of metadata in the
674 * middle of a simulation, which isn't allowed.
675 */
676 static bool m_metadataSkipped;
677
678 static uint32_t m_maxSize; //!< maximum metadata size
679 static uint16_t m_chunkUid; //!< Chunk Uid
680
681 Data* m_data; //!< Metadata storage
682 /*
683 head -(next)-> tail
684 ^ |
685 \---(prev)---|
686 */
687 uint16_t m_head; //!< list head
688 uint16_t m_tail; //!< list tail
689 uint32_t m_used; //!< used portion
690 uint64_t m_packetUid; //!< packet Uid
691};
692
693} // namespace ns3
694
695namespace ns3
696{
697
699 : m_data(PacketMetadata::Create(10)),
700 m_head(0xffff),
701 m_tail(0xffff),
702 m_used(0),
703 m_packetUid(uid)
704{
705 memset(m_data->m_data, 0xff, 4);
706 if (size > 0)
707 {
708 DoAddHeader(0, size);
709 }
710}
711
713 : m_data(o.m_data),
714 m_head(o.m_head),
715 m_tail(o.m_tail),
716 m_used(o.m_used),
717 m_packetUid(o.m_packetUid)
718{
719 NS_ASSERT(m_data != nullptr);
720 NS_ASSERT(m_data->m_count < std::numeric_limits<uint32_t>::max());
721 m_data->m_count++;
722}
723
726{
727 if (m_data != o.m_data)
728 {
729 // not self assignment
730 NS_ASSERT(m_data != nullptr);
731 m_data->m_count--;
732 if (m_data->m_count == 0)
733 {
735 }
736 m_data = o.m_data;
737 NS_ASSERT(m_data != nullptr);
738 m_data->m_count++;
739 }
740 m_head = o.m_head;
741 m_tail = o.m_tail;
742 m_used = o.m_used;
744 return *this;
745}
746
748{
749 NS_ASSERT(m_data != nullptr);
750 m_data->m_count--;
751 if (m_data->m_count == 0)
752 {
754 }
755}
756
757} // namespace ns3
758
759#endif /* PACKET_METADATA_H */
iterator in a Buffer instance
Definition buffer.h:89
automatically resized byte buffer
Definition buffer.h:83
Protocol header serialization and deserialization.
Definition header.h:33
Class to hold all the metadata.
Iterator class for metadata items.
uint16_t m_current
current position
Buffer m_buffer
buffer the metadata refers to
const PacketMetadata * m_metadata
pointer to the metadata
bool m_hasReadTail
true if the metadata tail has been read
bool HasNext() const
Checks if there is another metadata item.
Item Next()
Retrieve the next metadata item.
Handle packet metadata about packet headers and trailers.
uint32_t m_used
used portion
static uint8_t * ReadFromRawU64(uint64_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
Helper for the raw deserialization.
uint32_t GetSerializedSize() const
Get the metadata serialized size.
void ReplaceTail(PacketMetadata::SmallItem *item, PacketMetadata::ExtraItem *extraItem, uint32_t available)
Replace the tail.
PacketMetadata CreateFragment(uint32_t start, uint32_t end) const
Creates a fragment.
Data * m_data
Metadata storage.
PacketMetadata & operator=(const PacketMetadata &o)
Basic assignment.
void ReserveCopy(uint32_t n)
Reserve space and make a metadata copy.
void AddHeader(const Header &header, uint32_t size)
Add an header.
uint32_t ReadItems(uint16_t current, PacketMetadata::SmallItem *item, PacketMetadata::ExtraItem *extraItem) const
Read items.
static void Deallocate(PacketMetadata::Data *data)
Deallocate the buffer memory.
void AppendValueExtra(uint32_t value, uint8_t *buffer)
Append a value to the buffer - extra.
static PacketMetadata::Data * Create(uint32_t size)
Create a buffer data storage.
void Append32(uint32_t value, uint8_t *buffer)
Append a 32-bit value to the buffer.
friend class ItemIterator
Friend class.
static uint32_t m_maxSize
maximum metadata size
static bool m_enableChecking
Enable the packet metadata checking.
void UpdateHead(uint16_t written)
Update the head.
uint64_t GetUid() const
Get the packet Uid.
uint16_t m_head
list head
void AppendValue(uint32_t value, uint8_t *buffer)
Append a value to the buffer.
static void Recycle(PacketMetadata::Data *data)
Recycle the buffer memory.
static uint8_t * ReadFromRawU32(uint32_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
Helper for the raw deserialization.
static uint8_t * AddToRawU32(const uint32_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
Helper for the raw serialization.
static bool m_enable
Enable the packet metadata.
void AddAtEnd(const PacketMetadata &o)
Add a metadata at the metadata start.
void Reserve(uint32_t n)
Reserve space.
uint32_t ReadUleb128(const uint8_t **pBuffer) const
Read a ULEB128 (Unsigned Little Endian Base 128) coded number.
ItemIterator BeginItem(Buffer buffer) const
Initialize the item iterator to the buffer begin.
static void EnableChecking()
Enable the packet metadata checking.
void RemoveAtEnd(uint32_t end)
Remove a chunk of metadata at the metadata end.
void RemoveHeader(const Header &header, uint32_t size)
Remove an header.
uint32_t Deserialize(const uint8_t *buffer, uint32_t size)
Deserialization from raw uint8_t*.
void AddPaddingAtEnd(uint32_t end)
Add some padding at the end.
static uint8_t * ReadFromRawU16(uint16_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
Helper for the raw deserialization.
static uint16_t m_chunkUid
Chunk Uid.
static PacketMetadata::Data * Allocate(uint32_t n)
Allocate a buffer data storage.
void RemoveAtStart(uint32_t start)
Remove a chunk of metadata at the metadata start.
uint16_t AddSmall(const PacketMetadata::SmallItem *item)
Add a SmallItem.
static DataFreeList m_freeList
the metadata data storage
uint32_t GetUleb128Size(uint32_t value) const
Get the ULEB128 (Unsigned Little Endian Base 128) size.
uint32_t GetTotalSize() const
Get the total size used by the metadata.
void Append16(uint16_t value, uint8_t *buffer)
Append a 16-bit value to the buffer.
void RemoveTrailer(const Trailer &trailer, uint32_t size)
Remove a trailer.
static bool m_metadataSkipped
Set to true when adding metadata to a packet is skipped because m_enable is false; used to detect ena...
bool IsPointerOk(uint16_t pointer) const
Check if the position is valid.
bool IsStateOk() const
Check if the metadata state is ok.
uint32_t Serialize(uint8_t *buffer, uint32_t maxSize) const
Serialization to raw uint8_t*.
bool IsSharedPointerOk(uint16_t pointer) const
Check if the position is valid.
static uint8_t * AddToRawU8(const uint8_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
Helper for the raw serialization.
uint16_t m_tail
list tail
void UpdateTail(uint16_t written)
Update the tail.
uint64_t m_packetUid
packet Uid
static uint8_t * AddToRaw(const uint8_t *data, uint32_t dataSize, uint8_t *start, uint8_t *current, uint32_t maxSize)
Helper for the raw serialization.
void DoAddHeader(uint32_t uid, uint32_t size)
Add an header.
uint16_t AddBig(uint32_t head, uint32_t tail, const PacketMetadata::SmallItem *item, const PacketMetadata::ExtraItem *extraItem)
Add a "Big" Item (a SmallItem plus an ExtraItem)
static uint8_t * ReadFromRawU8(uint8_t &data, const uint8_t *start, const uint8_t *current, uint32_t maxSize)
Helper for the raw deserialization.
void AddTrailer(const Trailer &trailer, uint32_t size)
Add a trailer.
static uint8_t * AddToRawU16(const uint16_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
Helper for the raw serialization.
static uint8_t * AddToRawU64(const uint64_t &data, uint8_t *start, uint8_t *current, uint32_t maxSize)
Helper for the raw serialization.
static void Enable()
Enable the packet metadata.
Protocol trailer serialization and deserialization.
Definition trailer.h:30
a unique identifier for an interface.
Definition type-id.h:48
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
Ptr< T > Create(Ts &&... args)
Create class instances by constructors with varying numbers of arguments and return them by Ptr.
Definition ptr.h:436
Every class exported by the ns3 library is enclosed in the ns3 namespace.
#define PACKET_METADATA_DATA_M_DATA_SIZE
the size of PacketMetadata::Data::m_data such that the total size of PacketMetadata::Data is 16 bytes
uint8_t data[writeSize]
uint32_t m_size
size (in bytes) of m_data buffer below
uint8_t m_data[PACKET_METADATA_DATA_M_DATA_SIZE]
variable-sized buffer of bytes
uint32_t m_count
number of references to this struct Data instance.
uint16_t m_dirtyEnd
max of the m_used field over all objects which reference this struct Data instance
uint32_t fragmentEnd
offset (in bytes) from start of original header to the end of the fragment still present.
uint64_t packetUid
the packetUid of the packet in which this header or trailer was first added.
uint32_t fragmentStart
offset (in bytes) from start of original header to the start of the fragment still present.
structure describing a packet metadata item
ItemType type
metadata type
TypeId tid
TypeId of Header or Trailer.
bool isFragment
true: this is a fragmented header, trailer, or, payload.
uint32_t currentTrimmedFromEnd
how many bytes were trimmed from the end of a fragment.
Buffer::Iterator current
an iterator which can be fed to Deserialize.
ItemType
Type of data in the packet.
uint32_t currentTrimmedFromStart
how many bytes were trimmed from the start of a fragment.
uint32_t currentSize
size of item.
uint16_t next
offset (in bytes) from start of m_data buffer to next element in linked list.
uint16_t chunkUid
this field tries to uniquely identify each header or trailer instance while the typeUid field uniquel...
uint32_t typeUid
the high 31 bits of this field identify the type of the header or trailer represented by this item: t...
uint32_t size
the size (in bytes) of the header or trailer represented by this element.
uint16_t prev
offset (in bytes) from start of m_data buffer to previous element in linked list.