85 * means that most of the time, these operations will not trigger |
85 * means that most of the time, these operations will not trigger |
86 * data copies and will thus be still very fast. |
86 * data copies and will thus be still very fast. |
87 */ |
87 */ |
88 class Packet { |
88 class Packet { |
89 public: |
89 public: |
90 /** |
90 /** |
91 * Create an empty packet with a new uid (as returned |
91 * Create an empty packet with a new uid (as returned |
92 * by getUid). |
92 * by getUid). |
93 */ |
93 */ |
94 Packet (); |
94 Packet (); |
95 /** |
95 /** |
96 * Create a packet with a zero-filled payload. |
96 * Create a packet with a zero-filled payload. |
97 * The memory necessary for the payload is not allocated: |
97 * The memory necessary for the payload is not allocated: |
98 * it will be allocated at any later point if you attempt |
98 * it will be allocated at any later point if you attempt |
99 * to fragment this packet or to access the zero-filled |
99 * to fragment this packet or to access the zero-filled |
100 * bytes. The packet is allocated with a new uid (as |
100 * bytes. The packet is allocated with a new uid (as |
101 * returned by getUid). |
101 * returned by getUid). |
102 * |
102 * |
103 * \param size the size of the zero-filled payload |
103 * \param size the size of the zero-filled payload |
104 */ |
104 */ |
105 Packet (uint32_t size); |
105 Packet (uint32_t size); |
106 /** |
106 /** |
107 * Create a new packet which contains a fragment of the original |
107 * Create a new packet which contains a fragment of the original |
108 * packet. The returned packet shares the same uid as this packet. |
108 * packet. The returned packet shares the same uid as this packet. |
109 * |
109 * |
110 * \param start offset from start of packet to start of fragment to create |
110 * \param start offset from start of packet to start of fragment to create |
111 * \param length length of fragment to create |
111 * \param length length of fragment to create |
112 * \returns a fragment of the original packet |
112 * \returns a fragment of the original packet |
113 */ |
113 */ |
114 Packet createFragment (uint32_t start, uint32_t length) const; |
114 Packet createFragment (uint32_t start, uint32_t length) const; |
115 /** |
115 /** |
116 * \returns the size in bytes of the packet (including the zero-filled |
116 * \returns the size in bytes of the packet (including the zero-filled |
117 * initial payload) |
117 * initial payload) |
118 */ |
118 */ |
119 uint32_t getSize (void) const; |
119 uint32_t getSize (void) const; |
120 /** |
120 /** |
121 * Add header to this packet. This method invokes the |
121 * Add header to this packet. This method invokes the |
122 * ns3::Header::serializeTo method to request the header to serialize |
122 * ns3::Header::serializeTo method to request the header to serialize |
123 * itself in the packet buffer. |
123 * itself in the packet buffer. |
124 * |
124 * |
125 * \param header a reference to the header to add to this packet. |
125 * \param header a reference to the header to add to this packet. |
126 */ |
126 */ |
127 void add (Header const &header); |
127 void add (Header const &header); |
128 /** |
128 /** |
129 * Deserialize header from this packet. This method invokes the |
129 * Deserialize header from this packet. This method invokes the |
130 * ns3::Header::deserializeFrom method to request the header to deserialize |
130 * ns3::Header::deserializeFrom method to request the header to deserialize |
131 * itself from the packet buffer. This method does not remove |
131 * itself from the packet buffer. This method does not remove |
132 * the data from the buffer. It merely reads it. |
132 * the data from the buffer. It merely reads it. |
133 * |
133 * |
134 * \param header a reference to the header to deserialize from the buffer |
134 * \param header a reference to the header to deserialize from the buffer |
135 */ |
135 */ |
136 void peek (Header &header); |
136 void peek (Header &header); |
137 /** |
137 /** |
138 * Remove a deserialized header from the internal buffer. |
138 * Remove a deserialized header from the internal buffer. |
139 * This method removes the bytes read by Packet::peek from |
139 * This method removes the bytes read by Packet::peek from |
140 * the packet buffer. |
140 * the packet buffer. |
141 * |
141 * |
142 * \param header a reference to the header to remove from the internal buffer. |
142 * \param header a reference to the header to remove from the internal buffer. |
143 */ |
143 */ |
144 void remove (Header const &header); |
144 void remove (Header const &header); |
145 /** |
145 /** |
146 * Add trailer to this packet. This method invokes the |
146 * Add trailer to this packet. This method invokes the |
147 * ns3::Trailer::serializeTo method to request the trailer to serialize |
147 * ns3::Trailer::serializeTo method to request the trailer to serialize |
148 * itself in the packet buffer. |
148 * itself in the packet buffer. |
149 * |
149 * |
150 * \param trailer a reference to the trailer to add to this packet. |
150 * \param trailer a reference to the trailer to add to this packet. |
151 */ |
151 */ |
152 void add (Trailer const &trailer); |
152 void add (Trailer const &trailer); |
153 /** |
153 /** |
154 * Deserialize trailer from this packet. This method invokes the |
154 * Deserialize trailer from this packet. This method invokes the |
155 * ns3::Trailer::deserializeFrom method to request the trailer to deserialize |
155 * ns3::Trailer::deserializeFrom method to request the trailer to deserialize |
156 * itself from the packet buffer. This method does not remove |
156 * itself from the packet buffer. This method does not remove |
157 * the data from the buffer. It merely reads it. |
157 * the data from the buffer. It merely reads it. |
158 * |
158 * |
159 * \param trailer a reference to the trailer to deserialize from the buffer |
159 * \param trailer a reference to the trailer to deserialize from the buffer |
160 */ |
160 */ |
161 void peek (Trailer &trailer); |
161 void peek (Trailer &trailer); |
162 /** |
162 /** |
163 * Remove a deserialized trailer from the internal buffer. |
163 * Remove a deserialized trailer from the internal buffer. |
164 * This method removes the bytes read by Packet::peek from |
164 * This method removes the bytes read by Packet::peek from |
165 * the packet buffer. |
165 * the packet buffer. |
166 * |
166 * |
167 * \param trailer a reference to the trailer to remove from the internal buffer. |
167 * \param trailer a reference to the trailer to remove from the internal buffer. |
168 */ |
168 */ |
169 void remove (Trailer const &trailer); |
169 void remove (Trailer const &trailer); |
170 /** |
170 /** |
171 * Attach a tag to this packet. The tag is fully copied |
171 * Attach a tag to this packet. The tag is fully copied |
172 * in a packet-specific internal buffer. This operation |
172 * in a packet-specific internal buffer. This operation |
173 * is expected to be really fast. |
173 * is expected to be really fast. |
174 * |
174 * |
175 * \param tag a pointer to the tag to attach to this packet. |
175 * \param tag a pointer to the tag to attach to this packet. |
176 */ |
176 */ |
177 template <typename T> |
177 template <typename T> |
178 void addTag (T const &tag); |
178 void addTag (T const &tag); |
179 /** |
179 /** |
180 * Remove a tag from this packet. The data stored internally |
180 * Remove a tag from this packet. The data stored internally |
181 * for this tag is copied in the input tag if an instance |
181 * for this tag is copied in the input tag if an instance |
182 * of this tag type is present in the internal buffer. If this |
182 * of this tag type is present in the internal buffer. If this |
183 * tag type is not present, the input tag is not modified. |
183 * tag type is not present, the input tag is not modified. |
184 * |
184 * |
185 * This operation can be potentially slow and might trigger |
185 * This operation can be potentially slow and might trigger |
186 * unexpectedly large memory allocations. It is thus |
186 * unexpectedly large memory allocations. It is thus |
187 * usually a better idea to create a copy of this packet, |
187 * usually a better idea to create a copy of this packet, |
188 * and invoke removeAllTags on the copy to remove all |
188 * and invoke removeAllTags on the copy to remove all |
189 * tags rather than remove the tags one by one from a packet. |
189 * tags rather than remove the tags one by one from a packet. |
190 * |
190 * |
191 * \param tag a pointer to the tag to remove from this packet |
191 * \param tag a pointer to the tag to remove from this packet |
192 * \returns true if an instance of this tag type is stored |
192 * \returns true if an instance of this tag type is stored |
193 * in this packet, false otherwise. |
193 * in this packet, false otherwise. |
194 */ |
194 */ |
195 template <typename T> |
195 template <typename T> |
196 bool removeTag (T &tag); |
196 bool removeTag (T &tag); |
197 /** |
197 /** |
198 * Copy a tag stored internally to the input tag. If no instance |
198 * Copy a tag stored internally to the input tag. If no instance |
199 * of this tag is present internally, the input tag is not modified. |
199 * of this tag is present internally, the input tag is not modified. |
200 * |
200 * |
201 * \param tag a pointer to the tag to read from this packet |
201 * \param tag a pointer to the tag to read from this packet |
202 * \returns true if an instance of this tag type is stored |
202 * \returns true if an instance of this tag type is stored |
203 * in this packet, false otherwise. |
203 * in this packet, false otherwise. |
204 */ |
204 */ |
205 template <typename T> |
205 template <typename T> |
206 bool peekTag (T &tag) const; |
206 bool peekTag (T &tag) const; |
207 /** |
207 /** |
208 * Remove all the tags stored in this packet. This operation is |
208 * Remove all the tags stored in this packet. This operation is |
209 * much much faster than invoking removeTag n times. |
209 * much much faster than invoking removeTag n times. |
210 */ |
210 */ |
211 void removeAllTags (void); |
211 void removeAllTags (void); |
212 /** |
212 /** |
213 * Concatenate the input packet at the end of the current |
213 * Concatenate the input packet at the end of the current |
214 * packet. This does not alter the uid of either packet. |
214 * packet. This does not alter the uid of either packet. |
215 * |
215 * |
216 * \param packet packet to concatenate |
216 * \param packet packet to concatenate |
217 */ |
217 */ |
218 void addAtEnd (Packet packet); |
218 void addAtEnd (Packet packet); |
219 /** |
219 /** |
220 * Concatenate the fragment of the input packet identified |
220 * Concatenate the fragment of the input packet identified |
221 * by the offset and size parameters at the end of the current |
221 * by the offset and size parameters at the end of the current |
222 * packet. This does not alter the uid of either packet. |
222 * packet. This does not alter the uid of either packet. |
223 * |
223 * |
224 * \param packet to concatenate |
224 * \param packet to concatenate |
225 * \param offset offset of fragment to copy from the start of the input packet |
225 * \param offset offset of fragment to copy from the start of the input packet |
226 * \param size size of fragment of input packet to copy. |
226 * \param size size of fragment of input packet to copy. |
227 */ |
227 */ |
228 void addAtEnd (Packet packet, uint32_t offset, uint32_t size); |
228 void addAtEnd (Packet packet, uint32_t offset, uint32_t size); |
229 /** |
229 /** |
230 * Remove size bytes from the end of the current packet |
230 * Remove size bytes from the end of the current packet |
231 * It is safe to remove more bytes that what is present in |
231 * It is safe to remove more bytes that what is present in |
232 * the packet. |
232 * the packet. |
233 * |
233 * |
234 * \param size number of bytes from remove |
234 * \param size number of bytes from remove |
235 */ |
235 */ |
236 void removeAtEnd (uint32_t size); |
236 void removeAtEnd (uint32_t size); |
237 /** |
237 /** |
238 * Remove size bytes from the start of the current packet. |
238 * Remove size bytes from the start of the current packet. |
239 * It is safe to remove more bytes that what is present in |
239 * It is safe to remove more bytes that what is present in |
240 * the packet. |
240 * the packet. |
241 * |
241 * |
242 * \param size number of bytes from remove |
242 * \param size number of bytes from remove |
243 */ |
243 */ |
244 void removeAtStart (uint32_t size); |
244 void removeAtStart (uint32_t size); |
245 |
245 |
246 /** |
246 /** |
247 * If you try to change the content of the buffer |
247 * If you try to change the content of the buffer |
248 * returned by this method, you will die. |
248 * returned by this method, you will die. |
249 * |
249 * |
250 * \returns a pointer to the internal buffer of the packet. |
250 * \returns a pointer to the internal buffer of the packet. |
251 */ |
251 */ |
252 uint8_t const *peekData (void) const; |
252 uint8_t const *peekData (void) const; |
253 |
253 |
254 /** |
254 /** |
255 * A packet is allocated a new uid when it is created |
255 * A packet is allocated a new uid when it is created |
256 * empty or with zero-filled payload. |
256 * empty or with zero-filled payload. |
257 * |
257 * |
258 * \returns an integer identifier which uniquely |
258 * \returns an integer identifier which uniquely |
259 * identifies this packet. |
259 * identifies this packet. |
260 */ |
260 */ |
261 uint32_t getUid (void) const; |
261 uint32_t getUid (void) const; |
262 private: |
262 private: |
263 Packet (Buffer buffer, Tags tags, uint32_t uid); |
263 Packet (Buffer buffer, Tags tags, uint32_t uid); |
264 Buffer m_buffer; |
264 Buffer m_buffer; |
265 Tags m_tags; |
265 Tags m_tags; |
266 uint32_t m_uid; |
266 uint32_t m_uid; |
267 static uint32_t m_global_uid; |
267 static uint32_t m_global_uid; |
268 }; |
268 }; |
269 |
269 |
270 }; // namespace ns3 |
270 }; // namespace ns3 |
271 |
271 |
272 |
272 |