A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
byte-tag-list.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef BYTE_TAG_LIST_H
20#define BYTE_TAG_LIST_H
21
22#define __STDC_LIMIT_MACROS
23#include "tag-buffer.h"
24
25#include "ns3/type-id.h"
26
27#include <stdint.h>
28
29namespace ns3
30{
31
32struct ByteTagListData;
33
34/**
35 * \ingroup packet
36 *
37 * \brief keep track of the byte tags stored in a packet.
38 *
39 * This class is mostly private to the Packet implementation and users
40 * should never have to access it directly.
41 *
42 * \internal
43 * The implementation of this class is a bit tricky so, there are a couple
44 * of things to keep in mind here:
45 *
46 * - It stores all tags in a single byte buffer: each tag is stored
47 * as 4 32bit integers (TypeId, tag data size, start, end) followed
48 * by the tag data as generated by Tag::Serialize.
49 *
50 * - The struct ByteTagListData structure which contains the tag byte buffer
51 * is shared and, thus, reference-counted. This data structure is unshared
52 * as-needed to emulate COW semantics.
53 *
54 * - Each tag tags a unique set of bytes identified by the pair of offsets
55 * (start,end). These offsets are relative to the start of the packet
56 * Whenever the origin of the offset changes, the Packet adjusts all
57 * byte tags using ByteTagList::Adjust method.
58 *
59 * - When packet is reduced in size, byte tags that span outside the packet
60 * boundaries remain in ByteTagList. It is not a problem as iterator fixes
61 * the boundaries before returning item. However, when packet is extending,
62 * it calls ByteTagList::AddAtStart or ByteTagList::AddAtEnd to cut byte
63 * tags that will otherwise cover new bytes.
64 */
66{
67 public:
68 /**
69 * \brief An iterator for iterating through a byte tag list
70 *
71 * An iterator for iterating through a byte tag list
72 *
73 */
75 {
76 public:
77 /**
78 * \brief An item specifies an individual tag within a byte buffer
79 *
80 * An item specifies an individual tag within a byte buffer
81 *
82 */
83 struct Item
84 {
85 TypeId tid; //!< type of the tag
86 uint32_t size; //!< size of tag data
87 int32_t start; //!< offset to the start of the tag from the virtual byte buffer
88 int32_t end; //!< offset to the end of the tag from the virtual byte buffer
89 TagBuffer buf; //!< the data for the tag as generated by Tag::Serialize
90
91 /// Constructs an item with the given TagBuffer
92 /// \param buf The Tag Buffer
94
95 private:
96 /// Friend class
97 friend class ByteTagList;
98 /// Friend class
100 };
101
102 /**
103 * \brief Used to determine if the iterator is at the end of the byteTagList
104 *
105 * \returns true if there are more Items in the list
106 */
107 bool HasNext() const;
108
109 /**
110 * \brief Returns the next Item from the ByteTagList
111 *
112 * \returns the next Item in the ByteTagList
113 */
115
116 /**
117 * \brief Returns the offset from the start of the virtual byte buffer to the ByteTagList
118 *
119 * \returns offset to the start of this ByteTagList
120 */
121 uint32_t GetOffsetStart() const;
122
123 private:
124 /// Friend class
125 friend class ByteTagList;
126
127 /**
128 * \brief Constructor
129 * \param start Starting tag
130 * \param end End tag
131 * \param offsetStart offset to the start of the tag from the virtual byte buffer
132 * \param offsetEnd offset to the end of the tag from the virtual byte buffer
133 * \param adjustment adjustment to byte tag offsets
134 */
135 Iterator(uint8_t* start,
136 uint8_t* end,
137 int32_t offsetStart,
138 int32_t offsetEnd,
139 int32_t adjustment);
140
141 /**
142 * \brief Prepare the iterator for the next tag
143 */
144 void PrepareForNext();
145 uint8_t* m_current; //!< Current tag
146 uint8_t* m_end; //!< End tag
147 int32_t m_offsetStart; //!< Offset to the start of the tag from the virtual byte buffer
148 int32_t m_offsetEnd; //!< Offset to the end of the tag from the virtual byte buffer
149 int32_t m_adjustment; //!< Adjustment to byte tag offsets
150 uint32_t m_nextTid; //!< TypeId of the next tag
151 uint32_t m_nextSize; //!< Size of the next tag
152 int32_t m_nextStart; //!< Start of the next tag
153 int32_t m_nextEnd; //!< End of the next tag
154 };
155
156 ByteTagList();
157
158 /**
159 *
160 * Copy constructor, copies the data and increases reference count
161 *
162 * \param o The ByteTagList to copy
163 *
164 */
165 ByteTagList(const ByteTagList& o);
166
167 /**
168 *
169 * Assignment operator, deallocates current data and assigns
170 * value of passed in ByteTagList. Also increases reference count
171 *
172 * \param o reference to the ByteTagList to copy
173 * \returns reference to the assignee
174 *
175 */
177 ~ByteTagList();
178
179 /**
180 * \param tid the typeid of the tag added
181 * \param bufferSize the size of the tag when its serialization will
182 * be completed. Typically, the return value of Tag::GetSerializedSize
183 * \param start offset which uniquely identifies the first byte tagged by this tag.
184 * \param end offset which uniquely identifies the last byte tagged by this tag.
185 * \returns a buffer which can be used to write the tag data.
186 *
187 *
188 */
189 TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end);
190
191 /**
192 * \param o the other list of tags to aggregate.
193 *
194 * Aggregate the two lists of tags.
195 */
196 void Add(const ByteTagList& o);
197
198 /**
199 *
200 * Removes all of the tags from the ByteTagList
201 */
202 void RemoveAll();
203
204 /**
205 * \param offsetStart the offset which uniquely identifies the first data byte
206 * present in the byte buffer associated to this ByteTagList.
207 * \param offsetEnd the offset which uniquely identifies the last data byte
208 * present in the byte buffer associated to this ByteTagList.
209 * \returns an iterator
210 *
211 * The returned iterator will allow you to loop through the set of tags present
212 * in this list: the boundaries of each tag as reported by their start and
213 * end offsets will be included within the input offsetStart and offsetEnd.
214 */
215 ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const;
216
217 /**
218 * Adjust the offsets stored internally by the adjustment delta.
219 *
220 * \param adjustment value to change stored offsets by
221 */
222 inline void Adjust(int32_t adjustment);
223
224 /**
225 * Make sure that all offsets are smaller than appendOffset which represents
226 * the location where new bytes have been added to the byte buffer.
227 *
228 * \param appendOffset maximum offset value
229 *
230 */
231 void AddAtEnd(int32_t appendOffset);
232 /**
233 * Make sure that all offsets are bigger than prependOffset which represents
234 * the location where new bytes have been added to the byte buffer.
235 *
236 * \param prependOffset minimum offset value
237 *
238 */
239 void AddAtStart(int32_t prependOffset);
240 /**
241 * Returns number of bytes required for packet serialization.
242 *
243 * \returns number of bytes required for packet serialization
244 */
246 /**
247 * Serialize the tag list into a byte buffer.
248 *
249 * \param [in,out] buffer The byte buffer to which the tag list will be serialized
250 * \param [in] maxSize Max The max size of the buffer for bounds checking
251 *
252 * \returns zero if complete tag list is not serialized
253 */
254 uint32_t Serialize(uint32_t* buffer, uint32_t maxSize) const;
255 /**
256 * Deserialize tag list from the provided buffer.
257 *
258 * \param [in] buffer The buffer to read from.
259 * \param [in] size The number of bytes to deserialize.
260 *
261 * \returns zero if complete tag list is not deserialized
262 */
263 uint32_t Deserialize(const uint32_t* buffer, uint32_t size);
264
265 private:
266 /**
267 * \brief Returns an iterator pointing to the very first tag in this list.
268 *
269 * \returns an iterator
270 */
272
273 /**
274 * \brief Allocate the memory for the ByteTagListData
275 * \param size the memory to allocate
276 * \returns the ByteTagListData structure
277 */
279
280 /**
281 * \brief Deallocates a ByteTagListData
282 * \param data the ByteTagListData to deallocate
283 */
285
286 int32_t m_minStart; //!< minimal start offset
287 int32_t m_maxEnd; //!< maximal end offset
288 int32_t m_adjustment; //!< adjustment to byte tag offsets
289 uint32_t m_used; //!< the number of used bytes in the buffer
290 ByteTagListData* m_data; //!< the ByteTagListData structure
291};
292
293void
295{
296 m_adjustment += adjustment;
297}
298
299} // namespace ns3
300
301#endif /* BYTE_TAG_LIST_H */
An iterator for iterating through a byte tag list.
Definition: byte-tag-list.h:75
uint8_t * m_current
Current tag.
int32_t m_adjustment
Adjustment to byte tag offsets.
int32_t m_offsetEnd
Offset to the end of the tag from the virtual byte buffer.
ByteTagList::Iterator::Item Next()
Returns the next Item from the ByteTagList.
void PrepareForNext()
Prepare the iterator for the next tag.
int32_t m_nextEnd
End of the next tag.
uint32_t GetOffsetStart() const
Returns the offset from the start of the virtual byte buffer to the ByteTagList.
int32_t m_nextStart
Start of the next tag.
int32_t m_offsetStart
Offset to the start of the tag from the virtual byte buffer.
uint32_t m_nextSize
Size of the next tag.
bool HasNext() const
Used to determine if the iterator is at the end of the byteTagList.
uint32_t m_nextTid
TypeId of the next tag.
uint8_t * m_end
End tag.
keep track of the byte tags stored in a packet.
Definition: byte-tag-list.h:66
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
Deserialize tag list from the provided buffer.
void AddAtEnd(int32_t appendOffset)
Make sure that all offsets are smaller than appendOffset which represents the location where new byte...
void Deallocate(ByteTagListData *data)
Deallocates a ByteTagListData.
ByteTagList & operator=(const ByteTagList &o)
Assignment operator, deallocates current data and assigns value of passed in ByteTagList.
void Adjust(int32_t adjustment)
Adjust the offsets stored internally by the adjustment delta.
ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const
int32_t m_minStart
minimal start offset
uint32_t m_used
the number of used bytes in the buffer
ByteTagListData * Allocate(uint32_t size)
Allocate the memory for the ByteTagListData.
ByteTagList::Iterator BeginAll() const
Returns an iterator pointing to the very first tag in this list.
void RemoveAll()
Removes all of the tags from the ByteTagList.
int32_t m_adjustment
adjustment to byte tag offsets
TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
Serialize the tag list into a byte buffer.
void AddAtStart(int32_t prependOffset)
Make sure that all offsets are bigger than prependOffset which represents the location where new byte...
int32_t m_maxEnd
maximal end offset
ByteTagListData * m_data
the ByteTagListData structure
uint32_t GetSerializedSize() const
Returns number of bytes required for packet serialization.
read and write tag data
Definition: tag-buffer.h:52
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint8_t data[writeSize]
An item specifies an individual tag within a byte buffer.
Definition: byte-tag-list.h:84
TypeId tid
type of the tag
Definition: byte-tag-list.h:85
TagBuffer buf
the data for the tag as generated by Tag::Serialize
Definition: byte-tag-list.h:89
uint32_t size
size of tag data
Definition: byte-tag-list.h:86
int32_t end
offset to the end of the tag from the virtual byte buffer
Definition: byte-tag-list.h:88
int32_t start
offset to the start of the tag from the virtual byte buffer
Definition: byte-tag-list.h:87
Internal representation of the byte tags stored in a packet.