A Discrete-Event Network Simulator
API
byte-tag-list.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2008 INRIA
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 #ifndef BYTE_TAG_LIST_H
21 #define BYTE_TAG_LIST_H
22 
23 #define __STDC_LIMIT_MACROS
24 #include <stdint.h>
25 #include "ns3/type-id.h"
26 #include "tag-buffer.h"
27 
28 namespace ns3 {
29 
30 struct ByteTagListData;
31 
64 {
65 public:
72  class Iterator
73  {
74 public:
81  struct Item
82  {
84  uint32_t size;
85  int32_t start;
86  int32_t end;
88 
91  Item (TagBuffer buf);
92 private:
94  friend class ByteTagList;
96  friend class ByteTagList::Iterator;
97  };
98 
104  bool HasNext (void) const;
105 
111  struct ByteTagList::Iterator::Item Next (void);
112 
118  uint32_t GetOffsetStart (void) const;
119 private:
121  friend class ByteTagList;
122 
131  Iterator (uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd, int32_t adjustment);
132 
136  void PrepareForNext (void);
137  uint8_t *m_current;
138  uint8_t *m_end;
139  int32_t m_offsetStart;
140  int32_t m_offsetEnd;
141  int32_t m_adjustment;
142  uint32_t m_nextTid;
143  uint32_t m_nextSize;
144  int32_t m_nextStart;
145  int32_t m_nextEnd;
146  };
147 
148  ByteTagList ();
149 
158  ByteTagList (const ByteTagList &o);
159 
170  ~ByteTagList ();
171 
182  TagBuffer Add (TypeId tid, uint32_t bufferSize, int32_t start, int32_t end);
183 
189  void Add (const ByteTagList &o);
190 
195  void RemoveAll (void);
196 
208  ByteTagList::Iterator Begin (int32_t offsetStart, int32_t offsetEnd) const;
209 
215  inline void Adjust (int32_t adjustment);
216 
224  void AddAtEnd (int32_t appendOffset);
232  void AddAtStart (int32_t prependOffset);
238  uint32_t GetSerializedSize (void) const;
247  uint32_t Serialize (uint32_t* buffer, uint32_t maxSize) const;
256  uint32_t Deserialize (const uint32_t* buffer, uint32_t size);
257 
258 private:
264  ByteTagList::Iterator BeginAll (void) const;
265 
271  struct ByteTagListData *Allocate (uint32_t size);
272 
277  void Deallocate (struct ByteTagListData *data);
278 
279  int32_t m_minStart;
280  int32_t m_maxEnd;
281  int32_t m_adjustment;
282  uint32_t m_used;
284 };
285 
286 void
287 ByteTagList::Adjust (int32_t adjustment)
288 {
289  m_adjustment += adjustment;
290 }
291 
292 } // namespace ns3
293 
294 #endif /* BYTE_TAG_LIST_H */
uint32_t Deserialize(const uint32_t *buffer, uint32_t size)
Deserialize tag list from the provided buffer.
ByteTagList & operator=(const ByteTagList &o)
Assignment operator, deallocates current data and assigns value of passed in ByteTagList.
struct ByteTagListData * m_data
the ByteTagListData structure
def start()
Definition: core.py:1855
uint32_t GetSerializedSize(void) const
Returns number of bytes required for packet serialization.
keep track of the byte tags stored in a packet.
Definition: byte-tag-list.h:63
TagBuffer Add(TypeId tid, uint32_t bufferSize, int32_t start, int32_t end)
void Adjust(int32_t adjustment)
Adjust the offsets stored internally by the adjustment delta.
uint32_t m_nextTid
TypeId of the next tag.
void Deallocate(struct ByteTagListData *data)
Deallocates a ByteTagListData.
uint8_t * m_current
Current tag.
int32_t m_offsetEnd
Offset to the end of the tag from the virtual byte buffer.
void AddAtEnd(int32_t appendOffset)
Make sure that all offsets are smaller than appendOffset which represents the location where new byte...
void PrepareForNext(void)
Prepare the iterator for the next tag.
void RemoveAll(void)
Removes all of the tags from the ByteTagList.
ByteTagList::Iterator Begin(int32_t offsetStart, int32_t offsetEnd) const
Internal representation of the byte tags stored in a packet.
uint32_t m_nextSize
Size of the next tag.
uint8_t data[writeSize]
int32_t start
offset to the start of the tag from the virtual byte buffer
Definition: byte-tag-list.h:85
struct ByteTagList::Iterator::Item Next(void)
Returns the next Item from the ByteTagList.
struct ByteTagListData * Allocate(uint32_t size)
Allocate the memory for the ByteTagListData.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Iterator(uint8_t *start, uint8_t *end, int32_t offsetStart, int32_t offsetEnd, int32_t adjustment)
Constructor.
int32_t m_minStart
minimal start offset
int32_t m_nextStart
Start of the next tag.
int32_t end
offset to the end of the tag from the virtual byte buffer
Definition: byte-tag-list.h:86
ByteTagList::Iterator BeginAll(void) const
Returns an iterator pointing to the very first tag in this list.
uint32_t m_used
the number of used bytes in the buffer
int32_t m_offsetStart
Offset to the start of the tag from the virtual byte buffer.
TypeId tid
type of the tag
Definition: byte-tag-list.h:83
uint32_t size
size of tag data
Definition: byte-tag-list.h:84
int32_t m_adjustment
adjustment to byte tag offsets
TagBuffer buf
the data for the tag as generated by Tag::Serialize
Definition: byte-tag-list.h:87
An iterator for iterating through a byte tag list.
Definition: byte-tag-list.h:72
read and write tag data
Definition: tag-buffer.h:51
int32_t m_nextEnd
End of the next tag.
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
Item(TagBuffer buf)
Constructs an item with the given TagBuffer.
uint32_t GetOffsetStart(void) const
Returns the offset from the start of the virtual byte buffer to the ByteTagList.
uint32_t Serialize(uint32_t *buffer, uint32_t maxSize) const
Serialize the tag list into a byte buffer.
a unique identifier for an interface.
Definition: type-id.h:58
int32_t m_adjustment
Adjustment to byte tag offsets.
bool HasNext(void) const
Used to determine if the iterator is at the end of the byteTagList.
uint8_t * m_end
End tag.
An item specifies an individual tag within a byte buffer.
Definition: byte-tag-list.h:81