A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
packet-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) 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
*/
20
#ifndef PACKET_TAG_LIST_H
21
#define PACKET_TAG_LIST_H
22
28
#include <stdint.h>
29
#include <ostream>
30
#include "ns3/type-id.h"
31
32
namespace
ns3 {
33
34
class
Tag;
35
129
class
PacketTagList
130
{
131
public
:
140
struct
TagData
141
{
159
enum
TagData_e
160
{
161
MAX_SIZE
= 20
162
};
163
164
uint8_t
data
[
MAX_SIZE
];
165
struct
TagData
*
next
;
166
TypeId
tid
;
167
uint32_t
count
;
168
};
/* struct TagData */
169
173
inline
PacketTagList
();
182
inline
PacketTagList
(
PacketTagList
const
&o);
192
inline
PacketTagList
&
operator =
(
PacketTagList
const
&o);
198
inline
~PacketTagList
();
199
205
void
Add
(
Tag
const
&tag)
const
;
213
bool
Remove
(
Tag
&tag);
223
bool
Replace
(
Tag
&tag);
231
bool
Peek
(
Tag
&tag)
const
;
235
inline
void
RemoveAll
(
void
);
239
const
struct
PacketTagList::TagData
*
Head
(
void
)
const
;
240
241
private
:
253
typedef
bool (
PacketTagList
::*
COWWriter
)
254
(
Tag
& tag,
bool
preMerge,
255
struct
TagData
* cur,
struct
TagData
** prevNext);
263
bool
COWTraverse
(
Tag
& tag,
PacketTagList::COWWriter
Writer);
275
bool
RemoveWriter
(
Tag
& tag,
bool
preMerge,
276
struct
TagData
* cur,
struct
TagData
** prevNext);
288
bool
ReplaceWriter
(
Tag
& tag,
bool
preMerge,
struct
TagData
* cur,
struct
TagData
** prevNext);
289
293
struct
TagData
*
m_next
;
294
};
295
296
}
// namespace ns3
297
298
/****************************************************
299
* Implementation of inline methods for performance
300
****************************************************/
301
302
namespace
ns3 {
303
304
PacketTagList::PacketTagList
()
305
: m_next ()
306
{
307
}
308
309
PacketTagList::PacketTagList
(
PacketTagList
const
&o)
310
: m_next (o.m_next)
311
{
312
if
(
m_next
!= 0)
313
{
314
m_next
->
count
++;
315
}
316
}
317
318
PacketTagList
&
319
PacketTagList::operator =
(
PacketTagList
const
&o)
320
{
321
// self assignment
322
if
(
m_next
== o.
m_next
)
323
{
324
return
*
this
;
325
}
326
RemoveAll
();
327
m_next
= o.
m_next
;
328
if
(
m_next
!= 0)
329
{
330
m_next
->
count
++;
331
}
332
return
*
this
;
333
}
334
335
PacketTagList::~PacketTagList
()
336
{
337
RemoveAll
();
338
}
339
340
void
341
PacketTagList::RemoveAll
(
void
)
342
{
343
struct
TagData
*prev = 0;
344
for
(
struct
TagData
*cur =
m_next
; cur != 0; cur = cur->
next
)
345
{
346
cur->
count
--;
347
if
(cur->count > 0)
348
{
349
break
;
350
}
351
if
(prev != 0)
352
{
353
delete
prev;
354
}
355
prev = cur;
356
}
357
if
(prev != 0)
358
{
359
delete
prev;
360
}
361
m_next
= 0;
362
}
363
364
}
// namespace ns3
365
366
#endif
/* PACKET_TAG_LIST_H */
ns3::PacketTagList::~PacketTagList
~PacketTagList()
Destructor.
Definition:
packet-tag-list.h:335
ns3::PacketTagList::TagData::data
uint8_t data[MAX_SIZE]
Serialization buffer.
Definition:
packet-tag-list.h:164
ns3::PacketTagList::Remove
bool Remove(Tag &tag)
Remove (the first instance of) tag from the list.
Definition:
packet-tag-list.cc:158
ns3::PacketTagList::TagData::next
struct TagData * next
Pointer to next in list.
Definition:
packet-tag-list.h:165
ns3::PacketTagList::Head
const struct PacketTagList::TagData * Head(void) const
Definition:
packet-tag-list.cc:282
ns3::PacketTagList
List of the packet tags stored in a packet.
Definition:
packet-tag-list.h:129
ns3::PacketTagList::Peek
bool Peek(Tag &tag) const
Find a tag and return its value.
Definition:
packet-tag-list.cc:264
ns3::PacketTagList::Add
void Add(Tag const &tag) const
Add a tag to the head of this branch.
Definition:
packet-tag-list.cc:244
ns3::PacketTagList::ReplaceWriter
bool ReplaceWriter(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
Copy-on-write implementing Replace.
Definition:
packet-tag-list.cc:209
ns3::PacketTagList::TagData
Tree node for sharing serialized tags.
Definition:
packet-tag-list.h:140
ns3::PacketTagList::Replace
bool Replace(Tag &tag)
Replace the value of a tag.
Definition:
packet-tag-list.cc:197
ns3::PacketTagList::RemoveWriter
bool RemoveWriter(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
Copy-on-write implementing Remove.
Definition:
packet-tag-list.cc:165
ns3::PacketTagList::PacketTagList
PacketTagList()
Create a new PacketTagList.
Definition:
packet-tag-list.h:304
ns3::PacketTagList::TagData::TagData_e
TagData_e
Packet Tag maximum size.
Definition:
packet-tag-list.h:159
ns3::Tag
tag a set of bytes in a packet
Definition:
tag.h:36
ns3::PacketTagList::COWTraverse
bool COWTraverse(Tag &tag, PacketTagList::COWWriter Writer)
Traverse the list implementing copy-on-write, using Writer.
Definition:
packet-tag-list.cc:38
ns3::PacketTagList::m_next
struct TagData * m_next
Pointer to first TagData on the list.
Definition:
packet-tag-list.h:293
ns3::PacketTagList::TagData::MAX_SIZE
Size of serialization buffer data.
Definition:
packet-tag-list.h:161
ns3::PacketTagList::TagData::tid
TypeId tid
Type of the tag serialized into data.
Definition:
packet-tag-list.h:166
ns3::PacketTagList::operator=
PacketTagList & operator=(PacketTagList const &o)
Assignment.
Definition:
packet-tag-list.h:319
ns3::PacketTagList::COWWriter
bool(PacketTagList::* COWWriter)(Tag &tag, bool preMerge, struct TagData *cur, struct TagData **prevNext)
Typedef of method function pointer for copy-on-write operations.
Definition:
packet-tag-list.h:254
ns3::PacketTagList::RemoveAll
void RemoveAll(void)
Remove all tags from this list (up to the first merge).
Definition:
packet-tag-list.h:341
ns3::TypeId
a unique identifier for an interface.
Definition:
type-id.h:49
ns3::PacketTagList::TagData::count
uint32_t count
Number of incoming links.
Definition:
packet-tag-list.h:167
src
network
model
packet-tag-list.h
Generated on Fri Dec 5 2014 17:29:21 for ns-3 by
1.8.6