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