author | Mathieu Lacage <mathieu.lacage@sophia.inria.fr> |
Mon, 23 Mar 2009 15:20:15 +0100 | |
changeset 4911 | 3eb902892538 |
parent 4909 | c5f36fcf52ad |
child 5050 | 5c2002bda934 |
permissions | -rw-r--r-- |
4907 | 1 |
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ |
2 |
/* |
|
3 |
* Copyright (c) 2006 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 |
*/ |
|
4908
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
20 |
#ifndef PACKET_TAG_LIST_H |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
21 |
#define PACKET_TAG_LIST_H |
4907 | 22 |
|
23 |
#include <stdint.h> |
|
24 |
#include <ostream> |
|
25 |
#include "ns3/type-id.h" |
|
26 |
||
27 |
namespace ns3 { |
|
28 |
||
29 |
class Tag; |
|
30 |
||
31 |
/** |
|
32 |
* \ingroup constants |
|
33 |
* \brief Tag maximum size |
|
34 |
* The maximum size (in bytes) of a Tag is stored |
|
35 |
* in this constant. |
|
36 |
*/ |
|
4911
3eb902892538
increase packet tag size for Address objects and decrease the size of Address objects for packet tags :)
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4909
diff
changeset
|
37 |
#define PACKET_TAG_MAX_SIZE 20 |
4907 | 38 |
|
4908
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
39 |
class PacketTagList |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
40 |
{ |
4907 | 41 |
public: |
4908
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
42 |
struct TagData { |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
43 |
uint8_t data[PACKET_TAG_MAX_SIZE]; |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
44 |
struct TagData *next; |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
45 |
TypeId tid; |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
46 |
uint32_t count; |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
47 |
}; |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
48 |
|
4907 | 49 |
inline PacketTagList (); |
50 |
inline PacketTagList (PacketTagList const &o); |
|
51 |
inline PacketTagList &operator = (PacketTagList const &o); |
|
52 |
inline ~PacketTagList (); |
|
53 |
||
54 |
void Add (Tag const&tag) const; |
|
55 |
bool Remove (Tag &tag); |
|
56 |
bool Peek (Tag &tag) const; |
|
57 |
inline void RemoveAll (void); |
|
58 |
||
4908
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
59 |
const struct PacketTagList::TagData *Head (void) const; |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
60 |
|
4907 | 61 |
private: |
62 |
||
63 |
bool Remove (TypeId tid); |
|
64 |
struct PacketTagList::TagData *AllocData (void) const; |
|
65 |
void FreeData (struct TagData *data) const; |
|
66 |
||
67 |
static struct PacketTagList::TagData *g_free; |
|
68 |
static uint32_t g_nfree; |
|
69 |
||
70 |
struct TagData *m_next; |
|
71 |
}; |
|
72 |
||
73 |
} // namespace ns3 |
|
74 |
||
4908
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
75 |
/**************************************************** |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
76 |
* Implementation of inline methods for performance |
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
77 |
****************************************************/ |
4907 | 78 |
|
79 |
namespace ns3 { |
|
80 |
||
81 |
PacketTagList::PacketTagList () |
|
82 |
: m_next () |
|
83 |
{} |
|
84 |
||
85 |
PacketTagList::PacketTagList (PacketTagList const &o) |
|
86 |
: m_next (o.m_next) |
|
87 |
{ |
|
88 |
if (m_next != 0) |
|
89 |
{ |
|
90 |
m_next->count++; |
|
91 |
} |
|
92 |
} |
|
93 |
||
94 |
PacketTagList & |
|
95 |
PacketTagList::operator = (PacketTagList const &o) |
|
96 |
{ |
|
97 |
// self assignment |
|
98 |
if (m_next == o.m_next) |
|
99 |
{ |
|
100 |
return *this; |
|
101 |
} |
|
102 |
RemoveAll (); |
|
103 |
m_next = o.m_next; |
|
104 |
if (m_next != 0) |
|
105 |
{ |
|
106 |
m_next->count++; |
|
107 |
} |
|
108 |
return *this; |
|
109 |
} |
|
110 |
||
111 |
PacketTagList::~PacketTagList () |
|
112 |
{ |
|
113 |
RemoveAll (); |
|
114 |
} |
|
115 |
||
116 |
void |
|
117 |
PacketTagList::RemoveAll (void) |
|
118 |
{ |
|
119 |
struct TagData *prev = 0; |
|
120 |
for (struct TagData *cur = m_next; cur != 0; cur = cur->next) |
|
121 |
{ |
|
122 |
cur->count--; |
|
123 |
if (cur->count > 0) |
|
124 |
{ |
|
125 |
break; |
|
126 |
} |
|
127 |
if (prev != 0) |
|
128 |
{ |
|
129 |
FreeData (prev); |
|
130 |
} |
|
131 |
prev = cur; |
|
132 |
} |
|
133 |
if (prev != 0) |
|
134 |
{ |
|
135 |
FreeData (prev); |
|
136 |
} |
|
137 |
m_next = 0; |
|
138 |
} |
|
139 |
||
140 |
} // namespace ns3 |
|
141 |
||
4908
cfdbb4a44f29
add packet tag iterator
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents:
4907
diff
changeset
|
142 |
#endif /* PACKET_TAG_LIST_H */ |