A Discrete-Event Network Simulator
API
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  * 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;
8  *
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.
13  *
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
17  *
18  * Authors: Stefano Avallone <stavallo@unina.it>
19  * Tom Henderson <tomhend@u.washington.edu>
20  */
21 
22 #include "pfifo-fast-queue-disc.h"
23 
24 #include "ns3/log.h"
25 #include "ns3/object-factory.h"
26 #include "ns3/queue.h"
27 #include "ns3/socket.h"
28 
29 namespace ns3
30 {
31 
32 NS_LOG_COMPONENT_DEFINE("PfifoFastQueueDisc");
33 
34 NS_OBJECT_ENSURE_REGISTERED(PfifoFastQueueDisc);
35 
36 TypeId
38 {
39  static TypeId tid =
40  TypeId("ns3::PfifoFastQueueDisc")
42  .SetGroupName("TrafficControl")
43  .AddConstructor<PfifoFastQueueDisc>()
44  .AddAttribute("MaxSize",
45  "The maximum number of packets accepted by this queue disc.",
46  QueueSizeValue(QueueSize("1000p")),
47  MakeQueueSizeAccessor(&QueueDisc::SetMaxSize, &QueueDisc::GetMaxSize),
48  MakeQueueSizeChecker());
49  return tid;
50 }
51 
54 {
55  NS_LOG_FUNCTION(this);
56 }
57 
59 {
60  NS_LOG_FUNCTION(this);
61 }
62 
63 const uint32_t PfifoFastQueueDisc::prio2band[16] = {1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
64 
65 bool
67 {
68  NS_LOG_FUNCTION(this << item);
69 
70  if (GetCurrentSize() >= GetMaxSize())
71  {
72  NS_LOG_LOGIC("Queue disc limit exceeded -- dropping packet");
74  return false;
75  }
76 
77  uint8_t priority = 0;
78  SocketPriorityTag priorityTag;
79  if (item->GetPacket()->PeekPacketTag(priorityTag))
80  {
81  priority = priorityTag.GetPriority();
82  }
83 
84  uint32_t band = prio2band[priority & 0x0f];
85 
86  bool retval = GetInternalQueue(band)->Enqueue(item);
87 
88  // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the
89  // internal queue because QueueDisc::AddInternalQueue sets the trace callback
90 
91  if (!retval)
92  {
93  NS_LOG_WARN("Packet enqueue failed. Check the size of the internal queues");
94  }
95 
96  NS_LOG_LOGIC("Number packets band " << band << ": " << GetInternalQueue(band)->GetNPackets());
97 
98  return retval;
99 }
100 
103 {
104  NS_LOG_FUNCTION(this);
105 
106  Ptr<QueueDiscItem> item;
107 
108  for (uint32_t i = 0; i < GetNInternalQueues(); i++)
109  {
110  if ((item = GetInternalQueue(i)->Dequeue()))
111  {
112  NS_LOG_LOGIC("Popped from band " << i << ": " << item);
113  NS_LOG_LOGIC("Number packets band " << i << ": " << GetInternalQueue(i)->GetNPackets());
114  return item;
115  }
116  }
117 
118  NS_LOG_LOGIC("Queue empty");
119  return item;
120 }
121 
124 {
125  NS_LOG_FUNCTION(this);
126 
128 
129  for (uint32_t i = 0; i < GetNInternalQueues(); i++)
130  {
131  if ((item = GetInternalQueue(i)->Peek()))
132  {
133  NS_LOG_LOGIC("Peeked from band " << i << ": " << item);
134  NS_LOG_LOGIC("Number packets band " << i << ": " << GetInternalQueue(i)->GetNPackets());
135  return item;
136  }
137  }
138 
139  NS_LOG_LOGIC("Queue empty");
140  return item;
141 }
142 
143 bool
145 {
146  NS_LOG_FUNCTION(this);
147  if (GetNQueueDiscClasses() > 0)
148  {
149  NS_LOG_ERROR("PfifoFastQueueDisc cannot have classes");
150  return false;
151  }
152 
153  if (GetNPacketFilters() != 0)
154  {
155  NS_LOG_ERROR("PfifoFastQueueDisc needs no packet filter");
156  return false;
157  }
158 
159  if (GetNInternalQueues() == 0)
160  {
161  // create 3 DropTail queues with GetLimit() packets each
162  ObjectFactory factory;
163  factory.SetTypeId("ns3::DropTailQueue<QueueDiscItem>");
164  factory.Set("MaxSize", QueueSizeValue(GetMaxSize()));
168  }
169 
170  if (GetNInternalQueues() != 3)
171  {
172  NS_LOG_ERROR("PfifoFastQueueDisc needs 3 internal queues");
173  return false;
174  }
175 
176  if (GetInternalQueue(0)->GetMaxSize().GetUnit() != QueueSizeUnit::PACKETS ||
179  {
180  NS_LOG_ERROR("PfifoFastQueueDisc needs 3 internal queues operating in packet mode");
181  return false;
182  }
183 
184  for (uint8_t i = 0; i < 2; i++)
185  {
186  if (GetInternalQueue(i)->GetMaxSize() < GetMaxSize())
187  {
188  NS_LOG_ERROR(
189  "The capacity of some internal queue(s) is less than the queue disc capacity");
190  return false;
191  }
192  }
193 
194  return true;
195 }
196 
197 void
199 {
200  NS_LOG_FUNCTION(this);
201 }
202 
203 } // 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.
Definition: ptr.h:77
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:184
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:573
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:432
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:591
QueueSize GetCurrentSize() const
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
Definition: queue-disc.cc:515
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
Definition: queue-disc.cc:661
QueueSize GetMaxSize() const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:446
std::size_t GetNPacketFilters() const
Get the number of packet filters.
Definition: queue-disc.cc:618
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:474
std::size_t GetNInternalQueues() const
Get the number of internal queues.
Definition: queue-disc.cc:598
Ptr< QueueDiscItem > Dequeue()
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
Definition: queue-disc.cc:886
Ptr< const QueueDiscItem > Peek()
Get a copy of the next packet the queue discipline will extract.
Definition: queue-disc.cc:920
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.
Definition: queue-disc.cc:720
Template class for packet Queues.
Definition: queue.h:268
Class for representing queue sizes.
Definition: queue-size.h:96
indicates whether the socket has a priority set.
Definition: socket.h:1316
uint8_t GetPriority() const
Get the tag's priority.
Definition: socket.cc:860
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_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#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 ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:44
@ PACKETS
Use number of packets for queue size.
Definition: queue-size.h:45
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:107
@ MULTIPLE_QUEUES
Used by queue discs with multiple internal queues/child queue discs.
Definition: queue-disc.h:110
Every class exported by the ns3 library is enclosed in the ns3 namespace.