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 * SPDX-License-Identifier: GPL-2.0-only
5 */
6
7#ifndef DROPTAIL_H
8#define DROPTAIL_H
9
10#include "queue.h"
11
12namespace ns3
13{
14
15/**
16 * \ingroup queue
17 *
18 * \brief A FIFO packet queue that drops tail-end packets on overflow
19 */
20template <typename Item>
21class DropTailQueue : public Queue<Item>
22{
23 public:
24 /**
25 * \brief Get the type ID.
26 * \return the object TypeId
27 */
28 static TypeId GetTypeId();
29 /**
30 * \brief DropTailQueue Constructor
31 *
32 * Creates a droptail queue with a maximum size of 100 packets by default
33 */
35
36 ~DropTailQueue() override;
37
38 bool Enqueue(Ptr<Item> item) override;
39 Ptr<Item> Dequeue() override;
40 Ptr<Item> Remove() override;
41 Ptr<const Item> Peek() const override;
42
43 private:
44 using Queue<Item>::GetContainer;
45 using Queue<Item>::DoEnqueue;
46 using Queue<Item>::DoDequeue;
47 using Queue<Item>::DoRemove;
48 using Queue<Item>::DoPeek;
49
50 NS_LOG_TEMPLATE_DECLARE; //!< redefinition of the log component
51};
52
53/**
54 * Implementation of the templates declared above.
55 */
56
57template <typename Item>
60{
61 static TypeId tid =
64 .SetGroupName("Network")
65 .template AddConstructor<DropTailQueue<Item>>()
66 .AddAttribute("MaxSize",
67 "The max queue size",
71 return tid;
72}
73
74template <typename Item>
76 : Queue<Item>(),
77 NS_LOG_TEMPLATE_DEFINE("DropTailQueue")
78{
79 NS_LOG_FUNCTION(this);
80}
81
82template <typename Item>
87
88template <typename Item>
89bool
91{
92 NS_LOG_FUNCTION(this << item);
93
94 return DoEnqueue(GetContainer().end(), item);
95}
96
97template <typename Item>
100{
101 NS_LOG_FUNCTION(this);
102
103 Ptr<Item> item = DoDequeue(GetContainer().begin());
104
105 NS_LOG_LOGIC("Popped " << item);
106
107 return item;
108}
109
110template <typename Item>
113{
114 NS_LOG_FUNCTION(this);
115
116 Ptr<Item> item = DoRemove(GetContainer().begin());
117
118 NS_LOG_LOGIC("Removed " << item);
119
120 return item;
121}
122
123template <typename Item>
126{
127 NS_LOG_FUNCTION(this);
128
129 return DoPeek(GetContainer().begin());
130}
131
132// The following explicit template instantiation declarations prevent all the
133// translation units including this header file to implicitly instantiate the
134// DropTailQueue<Packet> class and the DropTailQueue<QueueDiscItem> class. The
135// unique instances of these classes are explicitly created through the macros
136// NS_OBJECT_TEMPLATE_CLASS_DEFINE (DropTailQueue,Packet) and
137// NS_OBJECT_TEMPLATE_CLASS_DEFINE (DropTailQueue,QueueDiscItem), which are included
138// in drop-tail-queue.cc
139extern template class DropTailQueue<Packet>;
140extern template class DropTailQueue<QueueDiscItem>;
141
142} // namespace ns3
143
144#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.
QueueSize GetMaxSize() const
Definition queue.cc:206
void SetMaxSize(QueueSize size)
Set the maximum size of this queue.
Definition queue.cc:189
Template class for packet Queues.
Definition queue.h:257
Ptr< Item > DoRemove(ConstIterator pos)
Definition queue.h:565
Ptr< Item > DoDequeue(ConstIterator pos)
Definition queue.h:536
bool DoEnqueue(ConstIterator pos, Ptr< Item > item)
Definition queue.h:500
Ptr< const Item > DoPeek(ConstIterator pos) const
Definition queue.h:617
const Container & GetContainer() const
Definition queue.h:493
Class for representing queue sizes.
Definition queue-size.h:85
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition log.h:225
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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.
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition queue-size.h:210
std::string GetTemplateClassName()
Helper function to get the name (as a string) of the type of a template class.
Ptr< const AttributeChecker > MakeQueueSizeChecker()
Definition queue-size.cc:18