A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
pfifo-fast-queue-disc.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007, 2014 University of Washington
3 * 2015 Universita' degli Studi di Napoli Federico II
4 *
5 * SPDX-License-Identifier: GPL-2.0-only
6 *
7 * Authors: Stefano Avallone <stavallo@unina.it>
8 * Tom Henderson <tomhend@u.washington.edu>
9 */
10
12
13#include "ns3/log.h"
14#include "ns3/object-factory.h"
15#include "ns3/queue.h"
16#include "ns3/socket.h"
17
18namespace ns3
19{
20
21NS_LOG_COMPONENT_DEFINE("PfifoFastQueueDisc");
22
23NS_OBJECT_ENSURE_REGISTERED(PfifoFastQueueDisc);
24
25TypeId
27{
28 static TypeId tid =
29 TypeId("ns3::PfifoFastQueueDisc")
31 .SetGroupName("TrafficControl")
32 .AddConstructor<PfifoFastQueueDisc>()
33 .AddAttribute("MaxSize",
34 "The maximum number of packets accepted by this queue disc.",
35 QueueSizeValue(QueueSize("1000p")),
38 return tid;
39}
40
46
51
52const uint32_t PfifoFastQueueDisc::prio2band[16] = {1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
53
54bool
56{
57 NS_LOG_FUNCTION(this << item);
58
59 if (GetCurrentSize() >= GetMaxSize())
60 {
61 NS_LOG_LOGIC("Queue disc limit exceeded -- dropping packet");
63 return false;
64 }
65
66 uint8_t priority = 0;
67 SocketPriorityTag priorityTag;
68 if (item->GetPacket()->PeekPacketTag(priorityTag))
69 {
70 priority = priorityTag.GetPriority();
71 }
72
73 uint32_t band = prio2band[priority & 0x0f];
74
75 bool retval = GetInternalQueue(band)->Enqueue(item);
76
77 // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the
78 // internal queue because QueueDisc::AddInternalQueue sets the trace callback
79
80 if (!retval)
81 {
82 NS_LOG_WARN("Packet enqueue failed. Check the size of the internal queues");
83 }
84
85 NS_LOG_LOGIC("Number packets band " << band << ": " << GetInternalQueue(band)->GetNPackets());
86
87 return retval;
88}
89
92{
93 NS_LOG_FUNCTION(this);
94
96
97 for (uint32_t i = 0; i < GetNInternalQueues(); i++)
98 {
99 if ((item = GetInternalQueue(i)->Dequeue()))
100 {
101 NS_LOG_LOGIC("Popped from band " << i << ": " << item);
102 NS_LOG_LOGIC("Number packets band " << i << ": " << GetInternalQueue(i)->GetNPackets());
103 return item;
104 }
105 }
106
107 NS_LOG_LOGIC("Queue empty");
108 return item;
109}
110
113{
114 NS_LOG_FUNCTION(this);
115
117
118 for (uint32_t i = 0; i < GetNInternalQueues(); i++)
119 {
120 if ((item = GetInternalQueue(i)->Peek()))
121 {
122 NS_LOG_LOGIC("Peeked from band " << i << ": " << item);
123 NS_LOG_LOGIC("Number packets band " << i << ": " << GetInternalQueue(i)->GetNPackets());
124 return item;
125 }
126 }
127
128 NS_LOG_LOGIC("Queue empty");
129 return item;
130}
131
132bool
134{
135 NS_LOG_FUNCTION(this);
136 if (GetNQueueDiscClasses() > 0)
137 {
138 NS_LOG_ERROR("PfifoFastQueueDisc cannot have classes");
139 return false;
140 }
141
142 if (GetNPacketFilters() != 0)
143 {
144 NS_LOG_ERROR("PfifoFastQueueDisc needs no packet filter");
145 return false;
146 }
147
148 if (GetNInternalQueues() == 0)
149 {
150 // create 3 DropTail queues with GetLimit() packets each
151 ObjectFactory factory;
152 factory.SetTypeId("ns3::DropTailQueue<QueueDiscItem>");
153 factory.Set("MaxSize", QueueSizeValue(GetMaxSize()));
157 }
158
159 if (GetNInternalQueues() != 3)
160 {
161 NS_LOG_ERROR("PfifoFastQueueDisc needs 3 internal queues");
162 return false;
163 }
164
165 if (GetInternalQueue(0)->GetMaxSize().GetUnit() != QueueSizeUnit::PACKETS ||
168 {
169 NS_LOG_ERROR("PfifoFastQueueDisc needs 3 internal queues operating in packet mode");
170 return false;
171 }
172
173 for (uint8_t i = 0; i < 2; i++)
174 {
176 {
178 "The capacity of some internal queue(s) is less than the queue disc capacity");
179 return false;
180 }
181 }
182
183 return true;
184}
185
186void
191
192} // namespace ns3
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void Set(const std::string &name, const AttributeValue &value, Args &&... args)
Set an attribute to be set during construction.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Linux pfifo_fast is the default priority queue enabled on Linux systems.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
Ptr< const QueueDiscItem > DoPeek() override
Return a copy of the next packet the queue disc will extract.
static TypeId GetTypeId()
Get the type ID.
bool CheckConfig() override
Check whether the current configuration is correct.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
static constexpr const char * LIMIT_EXCEEDED_DROP
Packet dropped due to queue disc limit exceeded.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
static const uint32_t prio2band[16]
Priority to band map.
PfifoFastQueueDisc()
PfifoFastQueueDisc constructor.
Smart pointer class similar to boost::intrusive_ptr.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition queue-disc.h:173
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
QueueSize GetCurrentSize() const
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
QueueSize GetMaxSize() const
Get the maximum size of the queue disc.
std::size_t GetNPacketFilters() const
Get the number of packet filters.
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
std::size_t GetNInternalQueues() const
Get the number of internal queues.
Ptr< QueueDiscItem > Dequeue()
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
Ptr< const QueueDiscItem > Peek()
Get a copy of the next packet the queue discipline will extract.
void DropBeforeEnqueue(Ptr< const QueueDiscItem > item, const char *reason)
Perform the actions required when the queue disc is notified of a packet dropped before enqueue.
Template class for packet Queues.
Definition queue.h:257
Class for representing queue sizes.
Definition queue-size.h:85
indicates whether the socket has a priority set.
Definition socket.h:1307
uint8_t GetPriority() const
Get the tag's priority.
Definition socket.cc:849
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_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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 ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition log.h:250
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition queue-size.h:33
@ PACKETS
Use number of packets for queue size.
Definition queue-size.h:34
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition queue-disc.h:96
@ MULTIPLE_QUEUES
Used by queue discs with multiple internal queues/child queue discs.
Definition queue-disc.h:99
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition queue-size.h:210
Ptr< const AttributeChecker > MakeQueueSizeChecker()
Definition queue-size.cc:18