author | Tom Henderson <tomh@tomh.org> |
Thu, 10 Jan 2008 07:31:40 -0800 | |
changeset 2217 | 0b4567d545de |
parent 2183 | ad0b316969f5 |
child 2370 | 5f7ad186b798 |
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" |
1865
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
33 |
#include "ns3/ptr.h" |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
34 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
35 |
namespace ns3 { |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
36 |
|
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
|
37 |
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
|
38 |
|
79
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
39 |
/** |
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
40 |
* \brief network packets |
80
3706b1172ab9
start of rationale for packets
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
79
diff
changeset
|
41 |
* |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
42 |
* 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
|
43 |
* metadata. |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
44 |
* |
106
9b7cf31baf8c
remove chunk
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
104
diff
changeset
|
45 |
* - 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
|
46 |
* 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
|
47 |
* 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
|
48 |
* 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
|
49 |
* is expected to be that of a real packet. |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
50 |
* |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
51 |
* - 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
|
52 |
* 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
|
53 |
* 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
|
54 |
* 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
|
55 |
* 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
|
56 |
* 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
|
57 |
* crashes at runtime. |
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
58 |
* |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
59 |
* - 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
|
60 |
* 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
|
61 |
* 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
|
62 |
* 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
|
63 |
* output from Packet::Print and Packet::Print. |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
64 |
* |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
65 |
* 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
|
66 |
* pretty easy and is a matter of creating a subclass of the ns3::Header |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
67 |
* or of the ns3::Trailer base class, and implementing the methods |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
68 |
* described in their respective API documentation. |
1131
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
69 |
* |
7d0c498c311a
improve dox
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
897
diff
changeset
|
70 |
* Implementing a new type of Tag requires roughly the same amount of |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
71 |
* work and this work is described in the ns3::Tag API documentation. |
81
80856bb1e1e8
add high-level intro to Packet API and implementation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
80
diff
changeset
|
72 |
* |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
73 |
* 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
|
74 |
* \ref packetperf |
79
84f791c00aa5
improve documentation and remove updateTag method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
77
diff
changeset
|
75 |
*/ |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
76 |
class Packet { |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
77 |
public: |
1865
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
78 |
void Ref (void) const; |
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
79 |
void Unref (void) const; |
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
80 |
|
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
81 |
Ptr<Packet> Copy (void) const; |
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
82 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
83 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
84 |
* 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
|
85 |
* by getUid). |
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 |
Packet (); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
88 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
89 |
* Create a packet with a zero-filled payload. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
90 |
* The memory necessary for the payload is not allocated: |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
91 |
* 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
|
92 |
* 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
|
93 |
* 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
|
94 |
* returned by getUid). |
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 |
* \param size the size of the zero-filled payload |
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 (uint32_t size); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
99 |
/** |
239
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
100 |
* 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
|
101 |
* 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
|
102 |
* buffer is untouched. |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
103 |
* |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
104 |
* \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
|
105 |
* \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
|
106 |
*/ |
e194d619534b
add packet constructor which accepts payload buffer.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
150
diff
changeset
|
107 |
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
|
108 |
/** |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
109 |
* 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
|
110 |
* 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
|
111 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
112 |
* \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
|
113 |
* \param length length of fragment to create |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
114 |
* \returns a fragment of the original packet |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
115 |
*/ |
1865
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
116 |
Ptr<Packet> CreateFragment (uint32_t start, uint32_t length) const; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
117 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
118 |
* \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
|
119 |
* initial payload) |
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 |
uint32_t GetSize (void) const; |
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 |
* Add header to this packet. This method invokes the |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
124 |
* GetSerializedSize and Serialize |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
125 |
* 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
|
126 |
* header to serialize itself in the packet buffer. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
127 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
128 |
* \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
|
129 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
130 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
131 |
void AddHeader (T const &header); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
132 |
/** |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
133 |
* Deserialize and remove the header from the internal buffer. |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
134 |
* This method invokes Deserialize. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
135 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
136 |
* \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
|
137 |
* \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
|
138 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
139 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
140 |
uint32_t RemoveHeader (T &header); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
141 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
142 |
* Add trailer to this packet. This method invokes the |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
143 |
* GetSerializedSize and Serialize |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
144 |
* 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
|
145 |
* to serialize itself in the packet buffer. |
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 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
|
148 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
149 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
150 |
void AddTrailer (T const &trailer); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
151 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
152 |
* Remove a deserialized trailer from the internal buffer. |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
153 |
* This method invokes the Deserialize method. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
154 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
155 |
* \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
|
156 |
* \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
|
157 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
158 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
159 |
uint32_t RemoveTrailer (T &trailer); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
160 |
/** |
2183
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
161 |
* \param tag a pointer to the tag to attach to this packet. |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
162 |
* |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
163 |
* 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
|
164 |
* in a packet-specific internal buffer. This operation |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
165 |
* is expected to be really fast. The copy constructor of the |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
166 |
* tag is invoked to copy it into the tag buffer. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
167 |
* |
2183
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
168 |
* Note that adding a tag is a const operation which is pretty |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
169 |
* un-intuitive. The rationale is that the content and behavior of |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
170 |
* a packet is _not_ changed when a tag is added to a packet: any |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
171 |
* code which was not aware of the new tag is going to work just |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
172 |
* the same if the new tag is added. The real reason why adding a |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
173 |
* tag was made a const operation is to allow a trace sink which gets |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
174 |
* a packet to tag the packet, even if the packet is const (and most |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
175 |
* trace sources should use const packets because it would be |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
176 |
* totally evil to allow a trace sink to modify the content of a |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
177 |
* packet). |
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
178 |
* |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
179 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
180 |
template <typename T> |
2183
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
181 |
void AddTag (T const &tag) const; |
150
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 |
* 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
|
184 |
* 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
|
185 |
* 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
|
186 |
* 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
|
187 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
188 |
* This operation can be potentially slow and might trigger |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
189 |
* unexpectedly large memory allocations. It is thus |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
190 |
* 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
|
191 |
* and invoke removeAllTags on the copy to remove all |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
192 |
* 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
|
193 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
194 |
* \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
|
195 |
* \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
|
196 |
* in this packet, false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
197 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
198 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
199 |
bool RemoveTag (T &tag); |
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 |
* 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
|
202 |
* of this tag is present internally, the input tag is not modified. |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
203 |
* The copy constructor of the tag is invoked to copy it into the |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
204 |
* input tag variable. |
150
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 |
* \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
|
207 |
* \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
|
208 |
* in this packet, false otherwise. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
209 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
210 |
template <typename T> |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
211 |
bool PeekTag (T &tag) const; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
212 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
213 |
* 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
|
214 |
* much much faster than invoking removeTag n times. |
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 |
void RemoveAllTags (void); |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
217 |
/** |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
218 |
* \param os output stream in which the data should be printed. |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
219 |
* |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
220 |
* Iterate over the tags present in this packet, and |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
221 |
* invoke the Print method of each tag stored in the packet. |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
222 |
*/ |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
223 |
void PrintTags (std::ostream &os) const; |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
224 |
|
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
225 |
/** |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
226 |
* 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
|
227 |
* 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
|
228 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
229 |
* \param packet packet to concatenate |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
230 |
*/ |
1865
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
231 |
void AddAtEnd (Ptr<const Packet> packet); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
232 |
/** |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
233 |
* \param size number of padding bytes to add. |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
234 |
*/ |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
235 |
void AddPaddingAtEnd (uint32_t size); |
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 |
* 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
|
238 |
* 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
|
239 |
* the packet. |
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 |
* \param size number of bytes from remove |
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 |
void RemoveAtEnd (uint32_t size); |
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 |
* 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
|
246 |
* 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
|
247 |
* the packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
248 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
249 |
* \param size number of bytes from remove |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
250 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
251 |
void RemoveAtStart (uint32_t size); |
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 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
254 |
* 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
|
255 |
* returned by this method, you will die. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
256 |
* |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
257 |
* \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
|
258 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
259 |
uint8_t const *PeekData (void) const; |
91
8066ef8d9274
add packet uid
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
90
diff
changeset
|
260 |
|
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
261 |
/** |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
262 |
* 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
|
263 |
* empty or with zero-filled payload. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
264 |
* |
1782
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
265 |
* Note: This uid is an internal uid and cannot be counted on to |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
266 |
* provide an accurate counter of how many "simulated packets" of a |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
267 |
* particular protocol are in the system. It is not trivial to make |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
268 |
* this uid into such a counter, because of questions such as what |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
269 |
* should the uid be when the packet is sent over broadcast media, or |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
270 |
* when fragmentation occurs. If a user wants to trace actual packet |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
271 |
* counts, he or she should look at e.g. the IP ID field or transport |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
272 |
* sequence numbers, or other packet or frame counters at other |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
273 |
* protocol layers. |
444ef6129d2e
Clarify pkt-uid field in doxygen
Tom Henderson <tomh@tomh.org>
parents:
1781
diff
changeset
|
274 |
* |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
275 |
* \returns an integer identifier which uniquely |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
276 |
* identifies this packet. |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
277 |
*/ |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
278 |
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
|
279 |
|
880 | 280 |
/** |
281 |
* \param os output stream in which the data should be printed. |
|
282 |
* |
|
283 |
* Iterate over the headers and trailers present in this packet, |
|
284 |
* from the first header to the last trailer and invoke, for |
|
285 |
* each of them, the user-provided method Header::DoPrint or |
|
286 |
* Trailer::DoPrint methods. |
|
287 |
*/ |
|
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
288 |
void Print (std::ostream &os) const; |
880 | 289 |
/** |
290 |
* \param os output stream in which the data should be printed. |
|
291 |
* \param printer the output formatter to use to print |
|
292 |
* the content of this packet. |
|
293 |
* |
|
294 |
* Iterate over the headers and trailers present in this packet, |
|
295 |
* either in the "forward" (first header to last trailer) or in |
|
296 |
* the "backward" (last trailer to first header) direction, as |
|
297 |
* specified by the PacketPrinter::PrintForward or the |
|
298 |
* PacketPrinter::PrintBackward methods. For each header, trailer, |
|
299 |
* or fragment of a header or a trailer, invoke the user-specified |
|
300 |
* print callback stored in the specified PacketPrinter. |
|
301 |
*/ |
|
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
|
302 |
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
|
303 |
|
880 | 304 |
/** |
305 |
* By default, packets do not keep around enough metadata to |
|
306 |
* perform the operations requested by the Print methods. If you |
|
307 |
* want to be able to invoke any of the two ::Print methods, |
|
308 |
* you need to invoke this method at least once during the |
|
309 |
* simulation setup and before any packet is created. |
|
310 |
* |
|
311 |
* The packet metadata is also used to perform extensive |
|
312 |
* sanity checks at runtime when performing operations on a |
|
313 |
* Packet. For example, this metadata is used to verify that |
|
314 |
* when you remove a header from a packet, this same header |
|
315 |
* was actually present at the front of the packet. These |
|
316 |
* errors will be detected and will abort the program. |
|
317 |
*/ |
|
875
4ebee6ceebb5
rename History::Enable to Packet::EnableMetadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
815
diff
changeset
|
318 |
static void EnableMetadata (void); |
1138
27245d50e5e0
use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1136
diff
changeset
|
319 |
|
1142
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
320 |
/** |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
321 |
* \returns a byte buffer |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
322 |
* |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
323 |
* 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
|
324 |
* 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
|
325 |
* 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
|
326 |
* 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
|
327 |
* |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
328 |
* This method will trigger calls to the Serialize and GetSerializedSize |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
329 |
* methods of each tag stored in this packet. |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
330 |
* |
1142
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
331 |
* 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
|
332 |
* 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
|
333 |
* a different CPU. |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
334 |
*/ |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
335 |
Buffer Serialize (void) const; |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
336 |
/** |
1249
94a1eddc8196
fix dox warning
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1246
diff
changeset
|
337 |
* \param buffer a byte buffer |
1142
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
338 |
* |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
339 |
* This method reads a byte buffer as created by Packet::Serialize |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
340 |
* and restores the state of the Packet to what it was prior to |
1142
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
341 |
* calling Serialize. |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
342 |
* |
1246
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
343 |
* This method will trigger calls to the Deserialize method |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
344 |
* of each tag stored in this packet. |
b9a73908ce00
beautify packet API doxygen
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1241
diff
changeset
|
345 |
* |
1142
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
346 |
* 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
|
347 |
* 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
|
348 |
* a different CPU. |
ff8f4a2efc6b
add doxygen documentation, constify
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1138
diff
changeset
|
349 |
*/ |
1138
27245d50e5e0
use CreateFullCopy and implement Serialize/Deserialize
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1136
diff
changeset
|
350 |
void Deserialize (Buffer buffer); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
351 |
private: |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
352 |
Packet (Buffer buffer, Tags tags, PacketMetadata metadata); |
1865
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
353 |
Packet (const Packet &o); |
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
354 |
Packet &operator = (const Packet &o); |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
355 |
Buffer m_buffer; |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
356 |
Tags m_tags; |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
357 |
PacketMetadata m_metadata; |
1865
829dc1815014
add Packet::Ref/Unref methods
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1360
diff
changeset
|
358 |
mutable uint32_t m_refCount; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
359 |
static uint32_t m_globalUid; |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
360 |
}; |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
361 |
|
1360
7686e996bd1d
add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1249
diff
changeset
|
362 |
std::ostream& operator<< (std::ostream& os, const Packet &packet); |
7686e996bd1d
add operator << for Packet and TraceContext
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1249
diff
changeset
|
363 |
|
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
364 |
/** |
2217 | 365 |
* \ingroup common |
1136
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
366 |
* \defgroup packetperf Packet Performance |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
367 |
* 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
|
368 |
* 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
|
369 |
* 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
|
370 |
* 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
|
371 |
* 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
|
372 |
* key for proper COW implementations is being |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
373 |
* 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
|
374 |
* 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
|
375 |
* to detect when an operation is "dirty". |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
376 |
* |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
377 |
* Dirty operations: |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
378 |
* - ns3::Packet::RemoveTag |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
379 |
* - ns3::Packet::AddHeader |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
380 |
* - ns3::Packet::AddTrailer |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
381 |
* - both versions of ns3::Packet::AddAtEnd |
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 |
* Non-dirty operations: |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
384 |
* - ns3::Packet::AddTag |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
385 |
* - ns3::Packet::RemoveAllTags |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
386 |
* - ns3::Packet::PeekTag |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
387 |
* - ns3::Packet::RemoveHeader |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
388 |
* - ns3::Packet::RemoveTrailer |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
389 |
* - ns3::Packet::CreateFragment |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
390 |
* - ns3::Packet::RemoveAtStart |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
391 |
* - ns3::Packet::RemoveAtEnd |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
392 |
* |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
393 |
* 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
|
394 |
* sometimes by several orders of magnitude. However, even the |
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
395 |
* 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
|
396 |
* 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
|
397 |
* data copies and will thus be still very fast. |
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 |
|
d5fe8364bcdf
add Tag documentation
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1132
diff
changeset
|
400 |
} // namespace ns3 |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
401 |
|
77
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
402 |
|
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
403 |
/************************************************** |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
404 |
Start of implementation of templates defined |
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
405 |
above |
77
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
406 |
*************************************************/ |
926e17b61dfb
add comment on implementation location
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
54
diff
changeset
|
407 |
|
16
99e833adbb46
change yans namespace to ns3
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
14
diff
changeset
|
408 |
namespace ns3 { |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
409 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
410 |
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
|
411 |
void |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
412 |
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
|
413 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
414 |
const Header *testHeader; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
415 |
// 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
|
416 |
// 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
|
417 |
testHeader = &header; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
418 |
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
|
419 |
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
|
420 |
header.Serialize (m_buffer.Begin ()); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
421 |
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
|
422 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
423 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
424 |
uint32_t |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
425 |
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
|
426 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
427 |
Header *testHeader; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
428 |
// 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
|
429 |
// 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
|
430 |
testHeader = &header; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
431 |
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
|
432 |
m_buffer.RemoveAtStart (deserialized); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
433 |
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
|
434 |
return deserialized; |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
435 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
436 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
437 |
void |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
438 |
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
|
439 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
440 |
const Trailer *testTrailer; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
441 |
// 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
|
442 |
// 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
|
443 |
testTrailer = &trailer; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
444 |
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
|
445 |
m_buffer.AddAtEnd (size); |
897
3d0c89af9c50
fix small variable name typo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
888
diff
changeset
|
446 |
Buffer::Iterator end = m_buffer.End (); |
3d0c89af9c50
fix small variable name typo
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
888
diff
changeset
|
447 |
trailer.Serialize (end); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
448 |
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
|
449 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
450 |
template <typename T> |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
451 |
uint32_t |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
452 |
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
|
453 |
{ |
1232
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
454 |
Trailer *testTrailer; |
2e8c3f8bb77f
remove Chunk base class
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1155
diff
changeset
|
455 |
// 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
|
456 |
// 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
|
457 |
testTrailer = &trailer; |
463
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
458 |
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
|
459 |
m_buffer.RemoveAtEnd (deserialized); |
888
f882ee7eaccf
history -> metadata
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
887
diff
changeset
|
460 |
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
|
461 |
return deserialized; |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
462 |
} |
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
463 |
|
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
464 |
|
c2082308e01a
merge Packet API changes needed for Packet pretty printing.
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
239
diff
changeset
|
465 |
template <typename T> |
2183
ad0b316969f5
make Packet::AddTag a const method
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1867
diff
changeset
|
466 |
void Packet::AddTag (T const& tag) const |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
467 |
{ |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
468 |
const Tag *parent; |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
469 |
// 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
|
470 |
// 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
|
471 |
parent = &tag; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
472 |
m_tags.Add (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
473 |
} |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
474 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
475 |
bool Packet::RemoveTag (T & tag) |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
476 |
{ |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
477 |
Tag *parent; |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
478 |
// 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
|
479 |
// 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
|
480 |
parent = &tag; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
481 |
return m_tags.Remove (tag); |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
482 |
} |
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
483 |
template <typename T> |
122
6b8f1eda5c57
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
111
diff
changeset
|
484 |
bool Packet::PeekTag (T & tag) const |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
485 |
{ |
1233
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
486 |
Tag *parent; |
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
487 |
// 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
|
488 |
// 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
|
489 |
parent = &tag; |
150
663120712cd9
fix coding style
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
131
diff
changeset
|
490 |
return m_tags.Peek (tag); |
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 |
|
dade465d569d
introduce Tag base class similar to Header and Trailer
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
1232
diff
changeset
|
493 |
} // namespace ns3 |
9
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
494 |
|
2c31ae7c94db
import from yans
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
diff
changeset
|
495 |
#endif /* PACKET_H */ |