author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Wed, 08 Aug 2007 09:49:56 +0200 | |
changeset 1233 | dade465d569d |
parent 1232 | 2e8c3f8bb77f |
child 1241 | 66f126692f5e |
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" |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
30 |
#include "tag.h" |
14
6dd7d31c6fc3
replace yans include with ns3 include
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
9
diff
changeset
|
31 |
#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
|
32 |
#include "ns3/assert.h" |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
33 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
34 |
namespace ns3 { |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
35 |
|
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
|
36 |
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
|
37 |
|
79
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
38 |
/** |
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
39 |
* \brief network packets |
80
3706b1172ab9
start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
79
diff
changeset
|
40 |
* |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
41 |
* Each network packet contains a byte buffer, a list of tags, and |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
42 |
* metadata. |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
43 |
* |
106
9b7cf31baf8c
remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
104
diff
changeset
|
44 |
* - 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
|
45 |
* 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
|
46 |
* 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
|
47 |
* 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
|
48 |
* is expected to be that of a real packet. |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
49 |
* |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
50 |
* - 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
|
51 |
* 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
|
52 |
* 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
|
53 |
* 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
|
54 |
* 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
|
55 |
* 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
|
56 |
* crashes at runtime. |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
57 |
* |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
58 |
* - The metadata describes the type of the headers and trailers which |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
59 |
* were serialized in the byte buffer. The maintenance of metadata is |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
60 |
* optional and disabled by default. To enable it, you must call |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
61 |
* Packet::EnableMetadata and this will allow you to get non-empty |
1132
de8ccffc8485
doxygen improvements to Packet, Tags, and Headers/Trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1131
diff
changeset
|
62 |
* output from Packet::Print and Packet::Print. |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
63 |
* |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
64 |
* Implementing a new type of Header or Trailer for a new protocol is |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
65 |
* pretty easy and is a matter of creating a subclass of the ns3::Header |
1132
de8ccffc8485
doxygen improvements to Packet, Tags, and Headers/Trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1131
diff
changeset
|
66 |
* or of the ns3::Trailer base class, and implementing the 5 pure virtual |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
67 |
* methods defined in either of the two base classes. Users _must_ |
1132
de8ccffc8485
doxygen improvements to Packet, Tags, and Headers/Trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1131
diff
changeset
|
68 |
* also make sure that they class defines a public default constructor and |
de8ccffc8485
doxygen improvements to Packet, Tags, and Headers/Trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1131
diff
changeset
|
69 |
* a public method named GetUid, as documented in the ns3::Header and ns::Trailer |
de8ccffc8485
doxygen improvements to Packet, Tags, and Headers/Trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1131
diff
changeset
|
70 |
* API documentations. |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
71 |
* |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
72 |
* Implementing a new type of Tag requires roughly the same amount of |
1132
de8ccffc8485
doxygen improvements to Packet, Tags, and Headers/Trailers
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1131
diff
changeset
|
73 |
* work: users must implement a total of 6 methods which are described in |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
74 |
* \ref tags |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
75 |
* |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
76 |
* The performance aspects of the Packet API are discussed in |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
77 |
* \ref packetperf |
79
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
78 |
*/ |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
79 |
class Packet { |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
80 |
public: |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
81 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
82 |
* 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
|
83 |
* by getUid). |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
84 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
85 |
Packet (); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
86 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
87 |
* Create a packet with a zero-filled payload. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
88 |
* The memory necessary for the payload is not allocated: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
89 |
* 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
|
90 |
* 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
|
91 |
* 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
|
92 |
* returned by getUid). |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
93 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
94 |
* \param size the size of the zero-filled payload |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
95 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
96 |
Packet (uint32_t size); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
97 |
/** |
239
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
98 |
* 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
|
99 |
* 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
|
100 |
* buffer is untouched. |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
101 |
* |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
102 |
* \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
|
103 |
* \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
|
104 |
*/ |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
105 |
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
|
106 |
/** |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
107 |
* 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
|
108 |
* 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
|
109 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
110 |
* \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
|
111 |
* \param length length of fragment to create |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
112 |
* \returns a fragment of the original packet |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
113 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
114 |
Packet CreateFragment (uint32_t start, uint32_t length) const; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
115 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
116 |
* \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
|
117 |
* initial payload) |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
118 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
119 |
uint32_t GetSize (void) const; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
120 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
121 |
* Add header to this packet. This method invokes the |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
122 |
* ns3::Header::GetSerializedSize and ns3::Header::SerializeTo |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
123 |
* 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
|
124 |
* header to serialize itself in the packet buffer. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
125 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
126 |
* \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
|
127 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
128 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
129 |
void AddHeader (T const &header); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
130 |
/** |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
131 |
* Deserialize and remove the header from the internal buffer. |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
132 |
* This method invokes ns3::Header::DeserializeFrom. |
150
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 |
* \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
|
135 |
* \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
|
136 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
137 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
138 |
uint32_t RemoveHeader (T &header); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
139 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
140 |
* Add trailer to this packet. This method invokes the |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
141 |
* ns3::Trailer::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
|
142 |
* 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
|
143 |
* to serialize itself in the packet buffer. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
144 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
145 |
* \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
|
146 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
147 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
148 |
void AddTrailer (T const &trailer); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
149 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
150 |
* Remove a deserialized trailer from the internal buffer. |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
151 |
* This method invokes the ns3::Trailer::DeserializeFrom method. |
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 |
* \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
|
154 |
* \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
|
155 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
156 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
157 |
uint32_t RemoveTrailer (T &trailer); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
158 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
159 |
* 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
|
160 |
* in a packet-specific internal buffer. This operation |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
161 |
* is expected to be really fast. |
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 |
* \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
|
164 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
165 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
166 |
void AddTag (T const &tag); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
167 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
168 |
* 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
|
169 |
* 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
|
170 |
* 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
|
171 |
* 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
|
172 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
173 |
* This operation can be potentially slow and might trigger |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
174 |
* unexpectedly large memory allocations. It is thus |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
175 |
* 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
|
176 |
* and invoke removeAllTags on the copy to remove all |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
177 |
* 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
|
178 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
179 |
* \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
|
180 |
* \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
|
181 |
* in this packet, false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
182 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
183 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
184 |
bool RemoveTag (T &tag); |
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 |
* 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
|
187 |
* 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
|
188 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
189 |
* \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
|
190 |
* \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
|
191 |
* in this packet, false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
192 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
193 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
194 |
bool PeekTag (T &tag) const; |
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 |
* 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
|
197 |
* much much faster than invoking removeTag n times. |
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 |
void RemoveAllTags (void); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
200 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
201 |
* 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
|
202 |
* 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
|
203 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
204 |
* \param packet packet to concatenate |
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 |
void AddAtEnd (Packet packet); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
207 |
/** |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
208 |
* \param size number of padding bytes to add. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
209 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
210 |
void AddPaddingAtEnd (uint32_t size); |
150
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 |
* 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
|
213 |
* 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
|
214 |
* the packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
215 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
216 |
* \param size number of bytes from remove |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
217 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
218 |
void RemoveAtEnd (uint32_t size); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
219 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
220 |
* 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
|
221 |
* 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
|
222 |
* the packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
223 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
224 |
* \param size number of bytes from remove |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
225 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
226 |
void RemoveAtStart (uint32_t size); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
227 |
|
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 |
* 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
|
230 |
* returned by this method, you will die. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
231 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
232 |
* \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
|
233 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
234 |
uint8_t const *PeekData (void) const; |
91
8066ef8d9274
add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
90
diff
changeset
|
235 |
|
150
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 |
* 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
|
238 |
* empty or with zero-filled payload. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
239 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
240 |
* \returns an integer identifier which uniquely |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
241 |
* identifies this packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
242 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
243 |
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
|
244 |
|
880 | 245 |
/** |
246 |
* \param os output stream in which the data should be printed. |
|
247 |
* |
|
248 |
* Iterate over the headers and trailers present in this packet, |
|
249 |
* from the first header to the last trailer and invoke, for |
|
250 |
* each of them, the user-provided method Header::DoPrint or |
|
251 |
* Trailer::DoPrint methods. |
|
252 |
*/ |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
253 |
void Print (std::ostream &os) const; |
880 | 254 |
/** |
255 |
* \param os output stream in which the data should be printed. |
|
256 |
* \param printer the output formatter to use to print |
|
257 |
* the content of this packet. |
|
258 |
* |
|
259 |
* Iterate over the headers and trailers present in this packet, |
|
260 |
* either in the "forward" (first header to last trailer) or in |
|
261 |
* the "backward" (last trailer to first header) direction, as |
|
262 |
* specified by the PacketPrinter::PrintForward or the |
|
263 |
* PacketPrinter::PrintBackward methods. For each header, trailer, |
|
264 |
* or fragment of a header or a trailer, invoke the user-specified |
|
265 |
* print callback stored in the specified PacketPrinter. |
|
266 |
*/ |
|
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
|
267 |
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
|
268 |
|
880 | 269 |
/** |
270 |
* By default, packets do not keep around enough metadata to |
|
271 |
* perform the operations requested by the Print methods. If you |
|
272 |
* want to be able to invoke any of the two ::Print methods, |
|
273 |
* you need to invoke this method at least once during the |
|
274 |
* simulation setup and before any packet is created. |
|
275 |
* |
|
276 |
* The packet metadata is also used to perform extensive |
|
277 |
* sanity checks at runtime when performing operations on a |
|
278 |
* Packet. For example, this metadata is used to verify that |
|
279 |
* when you remove a header from a packet, this same header |
|
280 |
* was actually present at the front of the packet. These |
|
281 |
* errors will be detected and will abort the program. |
|
282 |
*/ |
|
875
4ebee6ceebb5
rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
815
diff
changeset
|
283 |
static void EnableMetadata (void); |
1138
27245d50e5e0
use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1136
diff
changeset
|
284 |
|
1142
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
285 |
/** |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
286 |
* \returns a byte buffer |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
287 |
* |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
288 |
* This method creates a serialized representation of a Packet object |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
289 |
* ready to be transmitted over a network to another system. This |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
290 |
* serialized representation contains a copy of the packet byte buffer, |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
291 |
* the tag list, and the packet metadata (if there is one). |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
292 |
* |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
293 |
* This method will typically be used by parallel simulations where |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
294 |
* the simulated system is partitioned and each partition runs on |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
295 |
* a different CPU. |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
296 |
*/ |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
297 |
Buffer Serialize (void) const; |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
298 |
/** |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
299 |
* \param a byte buffer |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
300 |
* |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
301 |
* This method reads a byte buffer as created by Packet::Serialize |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
302 |
* and restores the state of the Packet to what it was prio to |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
303 |
* calling Serialize. |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
304 |
* |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
305 |
* This method will typically be used by parallel simulations where |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
306 |
* the simulated system is partitioned and each partition runs on |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
307 |
* a different CPU. |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
308 |
*/ |
1138
27245d50e5e0
use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1136
diff
changeset
|
309 |
void Deserialize (Buffer buffer); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
310 |
private: |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
311 |
Packet (Buffer buffer, Tags tags, PacketMetadata metadata); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
312 |
Buffer m_buffer; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
313 |
Tags m_tags; |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
314 |
PacketMetadata m_metadata; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
315 |
static uint32_t m_globalUid; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
316 |
}; |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
317 |
|
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
318 |
/** |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
319 |
* \defgroup tags Packet Tags |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
320 |
* |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
321 |
* A tag is a class which must define: |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
322 |
* - a public default constructor |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
323 |
* - a public static method named GetUid |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
324 |
* - a public method named Print |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
325 |
* - a public method named GetSerializedSize |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
326 |
* - a public method named Serialize |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
327 |
* - a public method named Deserialize |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
328 |
* |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
329 |
* So, a tag class should look like this: |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
330 |
* \code |
1154
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
331 |
* // in header file |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
332 |
* // note how a tag class does not derive from any other class. |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
333 |
* class MyTag |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
334 |
* { |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
335 |
* public: |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
336 |
* // we need a public default constructor |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
337 |
* MyTag (); |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
338 |
* // we need a public static GetUid |
1154
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
339 |
* // GetUid must return a 32 bit integer which uniquely |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
340 |
* // identifies this tag type |
1154
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
341 |
* static uint32_t GetUid (void); |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
342 |
* // Print should record in the output stream |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
343 |
* // the content of the tag instance. |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
344 |
* void Print (std::ostream &os) const; |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
345 |
* // GetSerializedSize should return the number of bytes needed |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
346 |
* // to store the state of a tag instance |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
347 |
* uint32_t GetSerializedSize (void) const; |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
348 |
* // Serialize should store its state in the input |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
349 |
* // buffer with the help of the iterator. It should |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
350 |
* // write exactly size bytes. |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
351 |
* void Serialize (Buffer::Iterator i, uint32_t size) const; |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
352 |
* // Deserialize should restore the state of a Tag instance |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
353 |
* // from a byte buffer with the help of the iterator |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
354 |
* uint32_t Deserialize (Buffer::Iterator i); |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
355 |
* }; |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
356 |
* |
1154
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
357 |
* // in source file |
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
358 |
* |
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
359 |
* NS_TAG_ENSURE_REGISTERED (MyTag); |
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
360 |
* |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
361 |
* std::string MyTag::GetUid (void) |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
362 |
* { |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
363 |
* // we really want to make sure that this |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
364 |
* // string is unique in the universe. |
1155
1269189b9f41
update the Tag API to match the Header/Trailer API
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1154
diff
changeset
|
365 |
* static uint32_t uid = TagRegistry::Register<MyTag> ("MyTag.unique.prefix"); |
1154
3434ebc3c553
update dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1142
diff
changeset
|
366 |
* return uid; |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
367 |
* } |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
368 |
* \endcode |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
369 |
*/ |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
370 |
|
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
371 |
/** |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
372 |
* \defgroup packetperf Packet Performance |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
373 |
* The current implementation of the byte buffers and tag list is based |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
374 |
* on COW (Copy On Write. An introduction to COW can be found in Scott |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
375 |
* Meyer's "More Effective C++", items 17 and 29). What this means is that |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
376 |
* copying packets without modifying them is very cheap (in terms of cpu |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
377 |
* and memory usage) and modifying them can be also very cheap. What is |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
378 |
* key for proper COW implementations is being |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
379 |
* able to detect when a given modification of the state of a packet triggers |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
380 |
* a full copy of the data prior to the modification: COW systems need |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
381 |
* to detect when an operation is "dirty". |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
382 |
* |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
383 |
* Dirty operations: |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
384 |
* - ns3::Packet::RemoveTag |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
385 |
* - ns3::Packet::AddHeader |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
386 |
* - ns3::Packet::AddTrailer |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
387 |
* - both versions of ns3::Packet::AddAtEnd |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
388 |
* |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
389 |
* Non-dirty operations: |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
390 |
* - ns3::Packet::AddTag |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
391 |
* - ns3::Packet::RemoveAllTags |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
392 |
* - ns3::Packet::PeekTag |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
393 |
* - ns3::Packet::RemoveHeader |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
394 |
* - ns3::Packet::RemoveTrailer |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
395 |
* - ns3::Packet::CreateFragment |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
396 |
* - ns3::Packet::RemoveAtStart |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
397 |
* - ns3::Packet::RemoveAtEnd |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
398 |
* |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
399 |
* Dirty operations will always be slower than non-dirty operations, |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
400 |
* sometimes by several orders of magnitude. However, even the |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
401 |
* dirty operations have been optimized for common use-cases which |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
402 |
* means that most of the time, these operations will not trigger |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
403 |
* data copies and will thus be still very fast. |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
404 |
*/ |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
405 |
|
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
406 |
} // namespace ns3 |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
407 |
|
77
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
408 |
|
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
409 |
/************************************************** |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
410 |
Start of implementation of templates defined |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
411 |
above |
77
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
412 |
*************************************************/ |
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
413 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
414 |
namespace ns3 { |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
415 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
416 |
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
|
417 |
void |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
418 |
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
|
419 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
420 |
const Header *testHeader; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
421 |
// if the following assignment fails, it is because the |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
422 |
// input to this function is not a subclass of the Header class |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
423 |
testHeader = &header; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
424 |
uint32_t size = header.GetSerializedSize (); |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
425 |
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
|
426 |
header.Serialize (m_buffer.Begin ()); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
427 |
m_metadata.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
|
428 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
429 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
430 |
uint32_t |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
431 |
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
|
432 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
433 |
Header *testHeader; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
434 |
// if the following assignment fails, it is because the |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
435 |
// input to this function is not a subclass of the Header class |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
436 |
testHeader = &header; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
437 |
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
|
438 |
m_buffer.RemoveAtStart (deserialized); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
439 |
m_metadata.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
|
440 |
return deserialized; |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
441 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
442 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
443 |
void |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
444 |
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
|
445 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
446 |
const Trailer *testTrailer; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
447 |
// if the following assignment fails, it is because the |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
448 |
// input to this function is not a subclass of the Trailer class |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
449 |
testTrailer = &trailer; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
450 |
uint32_t size = trailer.GetSerializedSize (); |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
451 |
m_buffer.AddAtEnd (size); |
897
3d0c89af9c50
fix small variable name typo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
888
diff
changeset
|
452 |
Buffer::Iterator end = m_buffer.End (); |
3d0c89af9c50
fix small variable name typo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
888
diff
changeset
|
453 |
trailer.Serialize (end); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
454 |
m_metadata.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
|
455 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
456 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
457 |
uint32_t |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
458 |
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
|
459 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
460 |
Trailer *testTrailer; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
461 |
// if the following assignment fails, it is because the |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
462 |
// input to this function is not a subclass of the Trailer class |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
463 |
testTrailer = &trailer; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
464 |
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
|
465 |
m_buffer.RemoveAtEnd (deserialized); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
466 |
m_metadata.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
|
467 |
return deserialized; |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
468 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
469 |
|
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
470 |
|
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
471 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
472 |
void Packet::AddTag (T const& tag) |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
473 |
{ |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
474 |
const Tag *parent; |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
475 |
// if the following assignment fails, it is because the |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
476 |
// input to this function is not a subclass of the Tag class. |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
477 |
parent = &tag; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
478 |
m_tags.Add (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
479 |
} |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
480 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
481 |
bool Packet::RemoveTag (T & tag) |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
482 |
{ |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
483 |
Tag *parent; |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
484 |
// if the following assignment fails, it is because the |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
485 |
// input to this function is not a subclass of the Tag class. |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
486 |
parent = &tag; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
487 |
return m_tags.Remove (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
488 |
} |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
489 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
490 |
bool Packet::PeekTag (T & tag) const |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
491 |
{ |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
492 |
Tag *parent; |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
493 |
// if the following assignment fails, it is because the |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
494 |
// input to this function is not a subclass of the Tag class. |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
495 |
parent = &tag; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
496 |
return m_tags.Peek (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
497 |
} |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
498 |
|
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
499 |
} // namespace ns3 |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
500 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
501 |
#endif /* PACKET_H */ |