author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Thu, 07 Jun 2007 12:51:57 +0200 | |
changeset 883 | 4d2da35c09b0 |
parent 882 | 777fcfabc1c8 |
child 887 | acd1bbdf4f2f |
permissions | -rw-r--r-- |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
2 |
/* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
3 |
* Copyright (c) 2005,2006 INRIA |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
4 |
* All rights reserved. |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
5 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
6 |
* This program is free software; you can redistribute it and/or modify |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
7 |
* it under the terms of the GNU General Public License version 2 as |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
8 |
* published by the Free Software Foundation; |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
9 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
10 |
* This program is distributed in the hope that it will be useful, |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
13 |
* GNU General Public License for more details. |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
14 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
15 |
* You should have received a copy of the GNU General Public License |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
16 |
* along with this program; if not, write to the Free Software |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
17 |
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
18 |
* |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
19 |
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
20 |
*/ |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
21 |
#ifndef PACKET_H |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
22 |
#define PACKET_H |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
23 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
24 |
#include <stdint.h> |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
25 |
#include "buffer.h" |
104 | 26 |
#include "header.h" |
107
2cbaa2a1b116
add trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
106
diff
changeset
|
27 |
#include "trailer.h" |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
28 |
#include "tags.h" |
882
777fcfabc1c8
rename packet-history.h to packet-metadata.h
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
880
diff
changeset
|
29 |
#include "packet-metadata.h" |
14
6dd7d31c6fc3
replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
9
diff
changeset
|
30 |
#include "ns3/callback.h" |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
31 |
#include "ns3/assert.h" |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
32 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
33 |
namespace ns3 { |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
|
806
0190f1b49dc8
re-implement PacketHistory to use the PacketPrinter and work on ItemList::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
789
diff
changeset
|
35 |
class PacketPrinter; |
0190f1b49dc8
re-implement PacketHistory to use the PacketPrinter and work on ItemList::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
789
diff
changeset
|
36 |
|
79
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
37 |
/** |
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
38 |
* \brief network packets |
80
3706b1172ab9
start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
79
diff
changeset
|
39 |
* |
3706b1172ab9
start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
79
diff
changeset
|
40 |
* Each network packet contains a byte buffer and a list of tags. |
106
9b7cf31baf8c
remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
104
diff
changeset
|
41 |
* - The byte buffer stores the serialized content of the headers and trailers |
9b7cf31baf8c
remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
104
diff
changeset
|
42 |
* added to a packet. The serialized representation of these headers is expected |
80
3706b1172ab9
start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
79
diff
changeset
|
43 |
* to match that of real network packets bit for bit (although nothing |
3706b1172ab9
start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
79
diff
changeset
|
44 |
* forces you to do this) which means that the content of a packet buffer |
3706b1172ab9
start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
79
diff
changeset
|
45 |
* is expected to be that of a real packet. |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
46 |
* - The list of tags stores an arbitrarily large set of arbitrary |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
47 |
* user-provided data structures in the packet: only one instance of |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
48 |
* each type of data structure is allowed in a list of tags. |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
49 |
* These tags typically contain per-packet cross-layer information or |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
50 |
* flow identifiers. Each tag stored in the tag list can be at most |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
51 |
* 16 bytes big. Trying to attach bigger data structures will trigger |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
52 |
* crashes at runtime. |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
53 |
* |
106
9b7cf31baf8c
remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
104
diff
changeset
|
54 |
* Implementing a new type of Header for a new protocol is pretty easy |
9b7cf31baf8c
remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
104
diff
changeset
|
55 |
* and is a matter of creating a subclass of the ns3::Header base class, |
629
1b4dd2d99313
remove references to Chunk and replace them with references to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
624
diff
changeset
|
56 |
* and implementing the 4 pure virtual methods defined in ns3::Header. |
106
9b7cf31baf8c
remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
104
diff
changeset
|
57 |
* Sample code which shows how to create such a new Header, how to use |
84
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
58 |
* it, and how to manipulate tags is shown below: |
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
59 |
* \include samples/main-packet.cc |
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
60 |
* |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
61 |
* The current implementation of the byte buffers and tag list is based |
84
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
62 |
* on COW (Copy On Write. An introduction to COW can be found in Scott |
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
63 |
* Meyer's "More Effective C++", items 17 and 29). What this means is that |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
64 |
* copying packets without modifying them is very cheap (in terms of cpu |
84
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
65 |
* and memory usage) and modifying them can be also very cheap. What is |
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
66 |
* key for proper COW implementations is being |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
67 |
* able to detect when a given modification of the state of a packet triggers |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
68 |
* a full copy of the data prior to the modification: COW systems need |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
69 |
* to detect when an operation is "dirty". |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
70 |
* |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
71 |
* Dirty operations: |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
72 |
* - ns3::Packet::RemoveTag |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
73 |
* - ns3::Packet::Add |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
74 |
* - both versions of ns3::Packet::AddAtEnd |
84
63b3ed9ce4e4
integrate sample code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
82
diff
changeset
|
75 |
* |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
76 |
* Non-dirty operations: |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
77 |
* - ns3::Packet::AddTag |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
78 |
* - ns3::Packet::RemoveAllTags |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
79 |
* - ns3::Packet::PeekTag |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
80 |
* - ns3::Packet::Peek |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
81 |
* - ns3::Packet::Remove |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
82 |
* - ns3::Packet::CreateFragment |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
83 |
* - ns3::Packet::RemoveAtStart |
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
84 |
* - ns3::Packet::RemoveAtEnd |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
85 |
* |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
86 |
* Dirty operations will always be slower than non-dirty operations, |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
87 |
* sometimes by several orders of magnitude. However, even the |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
88 |
* dirty operations have been optimized for common use-cases which |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
89 |
* means that most of the time, these operations will not trigger |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
90 |
* data copies and will thus be still very fast. |
79
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
91 |
*/ |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
92 |
class Packet { |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
93 |
public: |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
94 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
95 |
* Create an empty packet with a new uid (as returned |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
96 |
* by getUid). |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
97 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
98 |
Packet (); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
99 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
100 |
* Create a packet with a zero-filled payload. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
101 |
* The memory necessary for the payload is not allocated: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
102 |
* it will be allocated at any later point if you attempt |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
103 |
* to fragment this packet or to access the zero-filled |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
104 |
* bytes. The packet is allocated with a new uid (as |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
105 |
* returned by getUid). |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
106 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
107 |
* \param size the size of the zero-filled payload |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
108 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
109 |
Packet (uint32_t size); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
110 |
/** |
239
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
111 |
* Create a packet with payload filled with the content |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
112 |
* of this buffer. The input data is copied: the input |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
113 |
* buffer is untouched. |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
114 |
* |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
115 |
* \param buffer the data to store in the packet. |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
116 |
* \param size the size of the input buffer. |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
117 |
*/ |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
118 |
Packet (uint8_t const*buffer, uint32_t size); |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
119 |
/** |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
120 |
* Create a new packet which contains a fragment of the original |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
121 |
* packet. The returned packet shares the same uid as this packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
122 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
123 |
* \param start offset from start of packet to start of fragment to create |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
124 |
* \param length length of fragment to create |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
125 |
* \returns a fragment of the original packet |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
126 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
127 |
Packet CreateFragment (uint32_t start, uint32_t length) const; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
128 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
129 |
* \returns the size in bytes of the packet (including the zero-filled |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
130 |
* initial payload) |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
131 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
132 |
uint32_t GetSize (void) const; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
133 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
134 |
* Add header to this packet. This method invokes the |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
135 |
* ns3::Chunk::GetSerializedSize and ns3::Chunk::SerializeTo |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
136 |
* methods to reserve space in the buffer and request the |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
137 |
* header to serialize itself in the packet buffer. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
138 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
139 |
* \param header a reference to the header to add to this packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
140 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
141 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
142 |
void AddHeader (T const &header); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
143 |
/** |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
144 |
* Deserialize and remove the header from the internal buffer. |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
145 |
* This method invokes ns3::Chunk::DeserializeFrom. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
146 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
147 |
* \param header a reference to the header to remove from the internal buffer. |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
148 |
* \returns the number of bytes removed from the packet. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
149 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
150 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
151 |
uint32_t RemoveHeader (T &header); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
152 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
153 |
* Add trailer to this packet. This method invokes the |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
154 |
* ns3::Chunk::GetSerializedSize and ns3::Trailer::serializeTo |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
155 |
* methods to reserve space in the buffer and request the trailer |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
156 |
* to serialize itself in the packet buffer. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
157 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
158 |
* \param trailer a reference to the trailer to add to this packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
159 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
160 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
161 |
void AddTrailer (T const &trailer); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
162 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
163 |
* Remove a deserialized trailer from the internal buffer. |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
164 |
* This method invokes the ns3::Chunk::DeserializeFrom method. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
165 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
166 |
* \param trailer a reference to the trailer to remove from the internal buffer. |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
167 |
* \returns the number of bytes removed from the end of the packet. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
168 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
169 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
170 |
uint32_t RemoveTrailer (T &trailer); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
171 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
172 |
* Attach a tag to this packet. The tag is fully copied |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
173 |
* in a packet-specific internal buffer. This operation |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
174 |
* is expected to be really fast. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
175 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
176 |
* \param tag a pointer to the tag to attach to this packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
177 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
178 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
179 |
void AddTag (T const &tag); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
180 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
181 |
* Remove a tag from this packet. The data stored internally |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
182 |
* for this tag is copied in the input tag if an instance |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
183 |
* of this tag type is present in the internal buffer. If this |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
184 |
* tag type is not present, the input tag is not modified. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
185 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
186 |
* This operation can be potentially slow and might trigger |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
187 |
* unexpectedly large memory allocations. It is thus |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
188 |
* usually a better idea to create a copy of this packet, |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
189 |
* and invoke removeAllTags on the copy to remove all |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
190 |
* tags rather than remove the tags one by one from a packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
191 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
192 |
* \param tag a pointer to the tag to remove from this packet |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
193 |
* \returns true if an instance of this tag type is stored |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
194 |
* in this packet, false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
195 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
196 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
197 |
bool RemoveTag (T &tag); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
198 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
199 |
* Copy a tag stored internally to the input tag. If no instance |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
200 |
* of this tag is present internally, the input tag is not modified. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
201 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
202 |
* \param tag a pointer to the tag to read from this packet |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
203 |
* \returns true if an instance of this tag type is stored |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
204 |
* in this packet, false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
205 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
206 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
207 |
bool PeekTag (T &tag) const; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
208 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
209 |
* Remove all the tags stored in this packet. This operation is |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
210 |
* much much faster than invoking removeTag n times. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
211 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
212 |
void RemoveAllTags (void); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
213 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
214 |
* Concatenate the input packet at the end of the current |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
215 |
* packet. This does not alter the uid of either packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
216 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
217 |
* \param packet packet to concatenate |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
218 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
219 |
void AddAtEnd (Packet packet); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
220 |
/** |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
221 |
* \param size number of padding bytes to add. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
222 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
223 |
void AddPaddingAtEnd (uint32_t size); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
224 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
225 |
* Remove size bytes from the end of the current packet |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
226 |
* It is safe to remove more bytes that what is present in |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
227 |
* the packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
228 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
229 |
* \param size number of bytes from remove |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
230 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
231 |
void RemoveAtEnd (uint32_t size); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
232 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
233 |
* Remove size bytes from the start of the current packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
234 |
* It is safe to remove more bytes that what is present in |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
235 |
* the packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
236 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
237 |
* \param size number of bytes from remove |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
238 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
239 |
void RemoveAtStart (uint32_t size); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
240 |
|
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
241 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
242 |
* If you try to change the content of the buffer |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
243 |
* returned by this method, you will die. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
244 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
245 |
* \returns a pointer to the internal buffer of the packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
246 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
247 |
uint8_t const *PeekData (void) const; |
91
8066ef8d9274
add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
90
diff
changeset
|
248 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
249 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
250 |
* A packet is allocated a new uid when it is created |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
251 |
* empty or with zero-filled payload. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
252 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
253 |
* \returns an integer identifier which uniquely |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
254 |
* identifies this packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
255 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
256 |
uint32_t GetUid (void) const; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
257 |
|
880 | 258 |
/** |
259 |
* \param os output stream in which the data should be printed. |
|
260 |
* |
|
261 |
* Iterate over the headers and trailers present in this packet, |
|
262 |
* from the first header to the last trailer and invoke, for |
|
263 |
* each of them, the user-provided method Header::DoPrint or |
|
264 |
* Trailer::DoPrint methods. |
|
265 |
*/ |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
266 |
void Print (std::ostream &os) const; |
880 | 267 |
/** |
268 |
* \param os output stream in which the data should be printed. |
|
269 |
* \param printer the output formatter to use to print |
|
270 |
* the content of this packet. |
|
271 |
* |
|
272 |
* Iterate over the headers and trailers present in this packet, |
|
273 |
* either in the "forward" (first header to last trailer) or in |
|
274 |
* the "backward" (last trailer to first header) direction, as |
|
275 |
* specified by the PacketPrinter::PrintForward or the |
|
276 |
* PacketPrinter::PrintBackward methods. For each header, trailer, |
|
277 |
* or fragment of a header or a trailer, invoke the user-specified |
|
278 |
* print callback stored in the specified PacketPrinter. |
|
279 |
*/ |
|
806
0190f1b49dc8
re-implement PacketHistory to use the PacketPrinter and work on ItemList::Print
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
789
diff
changeset
|
280 |
void Print (std::ostream &os, const PacketPrinter &printer) const; |
875
4ebee6ceebb5
rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
815
diff
changeset
|
281 |
|
880 | 282 |
/** |
283 |
* By default, packets do not keep around enough metadata to |
|
284 |
* perform the operations requested by the Print methods. If you |
|
285 |
* want to be able to invoke any of the two ::Print methods, |
|
286 |
* you need to invoke this method at least once during the |
|
287 |
* simulation setup and before any packet is created. |
|
288 |
* |
|
289 |
* The packet metadata is also used to perform extensive |
|
290 |
* sanity checks at runtime when performing operations on a |
|
291 |
* Packet. For example, this metadata is used to verify that |
|
292 |
* when you remove a header from a packet, this same header |
|
293 |
* was actually present at the front of the packet. These |
|
294 |
* errors will be detected and will abort the program. |
|
295 |
*/ |
|
875
4ebee6ceebb5
rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
815
diff
changeset
|
296 |
static void EnableMetadata (void); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
297 |
private: |
883
4d2da35c09b0
PacketHistory -> PacketMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
882
diff
changeset
|
298 |
Packet (Buffer buffer, Tags tags, PacketMetadata history, uint32_t uid); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
299 |
Buffer m_buffer; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
300 |
Tags m_tags; |
883
4d2da35c09b0
PacketHistory -> PacketMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
882
diff
changeset
|
301 |
PacketMetadata m_history; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
302 |
uint32_t m_uid; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
303 |
static uint32_t m_globalUid; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
304 |
}; |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
305 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
306 |
}; // namespace ns3 |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
307 |
|
77
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
308 |
|
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
309 |
/************************************************** |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
310 |
Start of implementation of templates defined |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
311 |
above |
77
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
312 |
*************************************************/ |
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
313 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
314 |
namespace ns3 { |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
315 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
316 |
template <typename T> |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
317 |
void |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
318 |
Packet::AddHeader (T const &header) |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
319 |
{ |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
320 |
NS_ASSERT_MSG (dynamic_cast<Header const *> (&header) != 0, |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
321 |
"Must pass Header subclass to Packet::AddHeader"); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
322 |
uint32_t size = header.GetSize (); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
323 |
m_buffer.AddAtStart (size); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
324 |
header.Serialize (m_buffer.Begin ()); |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
325 |
m_history.AddHeader (header, size); |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
326 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
327 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
328 |
uint32_t |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
329 |
Packet::RemoveHeader (T &header) |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
330 |
{ |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
331 |
NS_ASSERT_MSG (dynamic_cast<Header const *> (&header) != 0, |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
332 |
"Must pass Header subclass to Packet::RemoveHeader"); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
333 |
uint32_t deserialized = header.Deserialize (m_buffer.Begin ()); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
334 |
m_buffer.RemoveAtStart (deserialized); |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
335 |
m_history.RemoveHeader (header, deserialized); |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
336 |
return deserialized; |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
337 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
338 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
339 |
void |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
340 |
Packet::AddTrailer (T const &trailer) |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
341 |
{ |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
342 |
NS_ASSERT_MSG (dynamic_cast<Trailer const *> (&trailer) != 0, |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
343 |
"Must pass Trailer subclass to Packet::AddTrailer"); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
344 |
uint32_t size = trailer.GetSize (); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
345 |
m_buffer.AddAtEnd (size); |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
346 |
Buffer::Iterator start = m_buffer.End (); |
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
347 |
trailer.Serialize (start); |
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
348 |
m_history.AddTrailer (trailer, size); |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
349 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
350 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
351 |
uint32_t |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
352 |
Packet::RemoveTrailer (T &trailer) |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
353 |
{ |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
354 |
NS_ASSERT_MSG (dynamic_cast<Trailer const *> (&trailer) != 0, |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
355 |
"Must pass Trailer subclass to Packet::RemoveTrailer"); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
356 |
uint32_t deserialized = trailer.Deserialize (m_buffer.End ()); |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
357 |
m_buffer.RemoveAtEnd (deserialized); |
789
1e19322e9012
merge unfinished packet history code
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
629
diff
changeset
|
358 |
m_history.RemoveTrailer (trailer, deserialized); |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
359 |
return deserialized; |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
360 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
361 |
|
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
362 |
|
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
363 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
364 |
void Packet::AddTag (T const& tag) |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
365 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
366 |
m_tags.Add (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
367 |
} |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
368 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
369 |
bool Packet::RemoveTag (T & tag) |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
370 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
371 |
return m_tags.Remove (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
372 |
} |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
373 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
374 |
bool Packet::PeekTag (T & tag) const |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
375 |
{ |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
376 |
return m_tags.Peek (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
377 |
} |
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
378 |
}; // namespace ns3 |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
379 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
380 |
#endif /* PACKET_H */ |