A Discrete-Event Network Simulator
API
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 
23 namespace ns3
24 {
25 
31 template <typename Item>
32 class DropTailQueue : public Queue<Item>
33 {
34  public:
39  static TypeId GetTypeId();
45  DropTailQueue();
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:
59  using Queue<Item>::DoPeek;
60 
62 };
63 
68 template <typename Item>
69 TypeId
71 {
72  static TypeId tid =
75  .SetGroupName("Network")
76  .template AddConstructor<DropTailQueue<Item>>()
77  .AddAttribute("MaxSize",
78  "The max queue size",
79  QueueSizeValue(QueueSize("100p")),
80  MakeQueueSizeAccessor(&QueueBase::SetMaxSize, &QueueBase::GetMaxSize),
81  MakeQueueSizeChecker());
82  return tid;
83 }
84 
85 template <typename Item>
87  : Queue<Item>(),
88  NS_LOG_TEMPLATE_DEFINE("DropTailQueue")
89 {
90  NS_LOG_FUNCTION(this);
91 }
92 
93 template <typename Item>
95 {
96  NS_LOG_FUNCTION(this);
97 }
98 
99 template <typename Item>
100 bool
102 {
103  NS_LOG_FUNCTION(this << item);
104 
105  return DoEnqueue(GetContainer().end(), item);
106 }
107 
108 template <typename Item>
109 Ptr<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 
121 template <typename Item>
122 Ptr<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 
134 template <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
150 extern template class DropTailQueue<Packet>;
151 extern 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
Class for representing queue sizes.
Definition: queue-size.h:96
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:931
#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