1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
3
* Copyright (c) 2006 INRIA
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;
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.
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
18
* Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
20
#include "packet-tag-list.h"
21
#include "tag-buffer.h"
23
#include "ns3/fatal-error.h"
27
NS_LOG_COMPONENT_DEFINE ("PacketTagList");
33
struct PacketTagList::TagData *PacketTagList::g_free = 0;
34
uint32_t PacketTagList::g_nfree = 0;
36
struct PacketTagList::TagData *
37
PacketTagList::AllocData (void) const
39
NS_LOG_FUNCTION (g_nfree);
40
struct PacketTagList::TagData *retval;
44
g_free = g_free->m_next;
49
retval = new struct PacketTagList::TagData ();
55
PacketTagList::FreeData (struct TagData *data) const
57
NS_LOG_FUNCTION (g_nfree << data);
65
data->tid = TypeId ();
69
struct PacketTagList::TagData *
70
PacketTagList::AllocData (void) const
72
NS_LOG_FUNCTION_NOARGS ();
73
struct PacketTagList::TagData *retval;
74
retval = new struct PacketTagList::TagData ();
79
PacketTagList::FreeData (struct TagData *data) const
81
NS_LOG_FUNCTION (data);
87
PacketTagList::Remove (Tag &tag)
89
NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
90
TypeId tid = tag.GetInstanceTypeId ();
92
for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
97
tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
104
struct TagData *start = 0;
105
struct TagData **prevNext = &start;
106
for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
112
* Note: I believe that we could optimize this to
113
* avoid copying each TagData located after the target id
114
* and just link the already-copied list to the next tag.
118
struct TagData *copy = AllocData ();
119
copy->tid = cur->tid;
122
memcpy (copy->data, cur->data, PACKET_TAG_MAX_SIZE);
124
prevNext = ©->next;
133
PacketTagList::Add (const Tag &tag) const
135
NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
136
// ensure this id was not yet added
137
for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
139
NS_ASSERT (cur->tid != tag.GetInstanceTypeId ());
141
struct TagData *head = AllocData ();
144
head->tid = tag.GetInstanceTypeId ();
146
NS_ASSERT (tag.GetSerializedSize () <= PACKET_TAG_MAX_SIZE);
147
tag.Serialize (TagBuffer (head->data, head->data+tag.GetSerializedSize ()));
149
const_cast<PacketTagList *> (this)->m_next = head;
153
PacketTagList::Peek (Tag &tag) const
155
NS_LOG_FUNCTION (this << tag.GetInstanceTypeId ());
156
TypeId tid = tag.GetInstanceTypeId ();
157
for (struct TagData *cur = m_next; cur != 0; cur = cur->next)
162
tag.Deserialize (TagBuffer (cur->data, cur->data+PACKET_TAG_MAX_SIZE));
170
const struct PacketTagList::TagData *
171
PacketTagList::Head (void) const