A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
drop-tail-queue.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 University of Washington
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 */
17
18#ifndef DROPTAIL_H
19#define DROPTAIL_H
20
21#include "queue.h"
22
23namespace ns3
24{
25
26/**
27 * \ingroup queue
28 *
29 * \brief A FIFO packet queue that drops tail-end packets on overflow
30 */
31template <typename Item>
32class DropTailQueue : public Queue<Item>
33{
34 public:
35 /**
36 * \brief Get the type ID.
37 * \return the object TypeId
38 */
39 static TypeId GetTypeId();
40 /**
41 * \brief DropTailQueue Constructor
42 *
43 * Creates a droptail queue with a maximum size of 100 packets by default
44 */
46
47 ~DropTailQueue() override;
48
49 bool Enqueue(Ptr<Item> item) override;
50 Ptr<Item> Dequeue() override;
51 Ptr<Item> Remove() override;
52 Ptr<const Item> Peek() const override;
53
54 private:
55 using Queue<Item>::GetContainer;
56 using Queue<Item>::DoEnqueue;
57 using Queue<Item>::DoDequeue;
58 using Queue<Item>::DoRemove;
59 using Queue<Item>::DoPeek;
60
61 NS_LOG_TEMPLATE_DECLARE; //!< redefinition of the log component
62};
63
64/**
65 * Implementation of the templates declared above.
66 */
67
68template <typename Item>
71{
72 static TypeId tid =
75 .SetGroupName("Network")
76 .template AddConstructor<DropTailQueue<Item>>()
77 .AddAttribute("MaxSize",
78 "The max queue size",
82 return tid;
83}
84
85template <typename Item>
87 : Queue<Item>(),
88 NS_LOG_TEMPLATE_DEFINE("DropTailQueue")
89{
90 NS_LOG_FUNCTION(this);
91}
92
93template <typename Item>
95{
96 NS_LOG_FUNCTION(this);
97}
98
99template <typename Item>
100bool
102{
103 NS_LOG_FUNCTION(this << item);
104
105 return DoEnqueue(GetContainer().end(), item);
106}
107
108template <typename Item>
111{
112 NS_LOG_FUNCTION(this);
113
114 Ptr<Item> item = DoDequeue(GetContainer().begin());
115
116 NS_LOG_LOGIC("Popped " << item);
117
118 return item;
119}
120
121template <typename Item>
124{
125 NS_LOG_FUNCTION(this);
126
127 Ptr<Item> item = DoRemove(GetContainer().begin());
128
129 NS_LOG_LOGIC("Removed " << item);
130
131 return item;
132}
133
134template <typename Item>
137{
138 NS_LOG_FUNCTION(this);
139
140 return DoPeek(GetContainer().begin());
141}
142
143// The following explicit template instantiation declarations prevent all the
144// translation units including this header file to implicitly instantiate the
145// DropTailQueue<Packet> class and the DropTailQueue<QueueDiscItem> class. The
146// unique instances of these classes are explicitly created through the macros
147// NS_OBJECT_TEMPLATE_CLASS_DEFINE (DropTailQueue,Packet) and
148// NS_OBJECT_TEMPLATE_CLASS_DEFINE (DropTailQueue,QueueDiscItem), which are included
149// in drop-tail-queue.cc
150extern template class DropTailQueue<Packet>;
151extern template class DropTailQueue<QueueDiscItem>;
152
153} // namespace ns3
154
155#endif /* DROPTAIL_H */
A FIFO packet queue that drops tail-end packets on overflow.
NS_LOG_TEMPLATE_DECLARE
redefinition of the log component
static TypeId GetTypeId()
Get the type ID.
Ptr< const Item > Peek() const override
Get a copy of an item in the queue (each subclass defines the position) without removing it.
DropTailQueue()
DropTailQueue Constructor.
bool Enqueue(Ptr< Item > item) override
Place an item into the Queue (each subclass defines the position)
Ptr< Item > Remove() override
Remove an item from the Queue (each subclass defines the position), counting it and tracing it as bot...
Ptr< Item > Dequeue() override
Remove an item from the Queue (each subclass defines the position), counting it and tracing it as deq...
~DropTailQueue() override
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
QueueSize GetMaxSize() const
Definition: queue.cc:217
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Definition: queue.cc:200
Template class for packet Queues.
Definition: queue.h:268
Ptr< Item > DoRemove(ConstIterator pos)
Pull the item to drop from the queue.
Definition: queue.h:576
Ptr< Item > DoDequeue(ConstIterator pos)
Pull the item to dequeue from the queue.
Definition: queue.h:547
bool DoEnqueue(ConstIterator pos, Ptr< Item > item)
Push an item in the queue.
Definition: queue.h:511
Ptr< const Item > DoPeek(ConstIterator pos) const
Peek the front item in the queue.
Definition: queue.h:628
const Container & GetContainer() const
Get a const reference to the container of queue items.
Definition: queue.h:504
Class for representing queue sizes.
Definition: queue-size.h:96
AttributeValue implementation for QueueSize.
Definition: queue-size.h:221
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:932
Ptr< const AttributeChecker > MakeQueueSizeChecker()
Definition: queue-size.cc:29
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition: queue-size.h:221
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition: log.h:236
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:282
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::string GetTemplateClassName()
Helper function to get the name (as a string) of the type of a template class.
Definition: object-base.h:155