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);
191
inline
PacketTagList
&
operator =
(
PacketTagList
const
&o);
197
inline
~PacketTagList
();
198
204
void
Add
(
Tag
const
&tag)
const
;
212
bool
Remove
(
Tag
&tag);
222
bool
Replace
(
Tag
&tag);
230
bool
Peek
(
Tag
&tag)
const
;
234
inline
void
RemoveAll
(
void
);
238
const
struct
PacketTagList::TagData
*
Head
(
void
)
const
;
239
240
private
:
252
typedef
bool (
PacketTagList
::*
COWWriter
)
253
(
Tag
& tag,
bool
preMerge,
254
struct
TagData
* cur,
struct
TagData
** prevNext);
262
bool
COWTraverse
(
Tag
& tag,
PacketTagList::COWWriter
Writer);
274
bool
RemoveWriter
(
Tag
& tag,
bool
preMerge,
275
struct
TagData
* cur,
struct
TagData
** prevNext);
287
bool
ReplaceWriter
(
Tag
& tag,
bool
preMerge,
struct
TagData
* cur,
struct
TagData
** prevNext);
288
292
struct
TagData
*
m_next
;
293
};
294
295
}
// namespace ns3
296
297
/****************************************************
298
* Implementation of inline methods for performance
299
****************************************************/
300
301
namespace
ns3 {
302
303
PacketTagList::PacketTagList
()
304
: m_next ()
305
{
306
}
307
308
PacketTagList::PacketTagList
(
PacketTagList
const
&o)
309
: m_next (o.m_next)
310
{
311
if
(
m_next
!= 0)
312
{
313
m_next
->
count
++;
314
}
315
}
316
317
PacketTagList
&
318
PacketTagList::operator =
(
PacketTagList
const
&o)
319
{
320
// self assignment
321
if
(
m_next
== o.
m_next
)
322
{
323
return
*
this
;
324
}
325
RemoveAll
();
326
m_next
= o.
m_next
;
327
if
(
m_next
!= 0)
328
{
329
m_next
->
count
++;
330
}
331
return
*
this
;
332
}
333
334
PacketTagList::~PacketTagList
()
335
{
336
RemoveAll
();
337
}
338
339
void
340
PacketTagList::RemoveAll
(
void
)
341
{
342
struct
TagData
*prev = 0;
343
for
(
struct
TagData
*cur =
m_next
; cur != 0; cur = cur->
next
)
344
{
345
cur->
count
--;
346
if
(cur->count > 0)
347
{
348
break
;
349
}
350
if
(prev != 0)
351
{
352
delete
prev;
353
}
354
prev = cur;
355
}
356
if
(prev != 0)
357
{
358
delete
prev;
359
}
360
m_next
= 0;
361
}
362
363
}
// namespace ns3
364
365
#endif
/* PACKET_TAG_LIST_H */
ns3::PacketTagList::~PacketTagList
~PacketTagList()
Destructor.
Definition:
packet-tag-list.h:334
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:159
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:283
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:265
ns3::PacketTagList::Add
void Add(Tag const &tag) const
Add a tag to the head of this branch.
Definition:
packet-tag-list.cc:245
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:210
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:198
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:166
ns3::PacketTagList::PacketTagList
PacketTagList()
Create a new PacketTagList.
Definition:
packet-tag-list.h:303
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:39
ns3::PacketTagList::m_next
struct TagData * m_next
Pointer to first TagData on the list.
Definition:
packet-tag-list.h:292
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:318
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:253
ns3::PacketTagList::RemoveAll
void RemoveAll(void)
Remove all tags from this list (up to the first merge).
Definition:
packet-tag-list.h:340
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 Sat Apr 19 2014 14:07:05 for ns-3 by
1.8.6