A Discrete-Event Network Simulator
API
pfifo-fast-queue-disc.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007, 2014 University of Washington
4  * 2015 Universita' degli Studi di Napoli Federico II
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Authors: Stefano Avallone <stavallo@unina.it>
20  * Tom Henderson <tomhend@u.washington.edu>
21  */
22 
23 #include "ns3/log.h"
24 #include "ns3/object-factory.h"
25 #include "ns3/queue.h"
26 #include "ns3/net-device-queue-interface.h"
27 #include "ns3/socket.h"
28 #include "pfifo-fast-queue-disc.h"
29 
30 namespace ns3 {
31 
32 NS_LOG_COMPONENT_DEFINE ("PfifoFastQueueDisc");
33 
34 NS_OBJECT_ENSURE_REGISTERED (PfifoFastQueueDisc);
35 
37 {
38  static TypeId tid = TypeId ("ns3::PfifoFastQueueDisc")
39  .SetParent<QueueDisc> ()
40  .SetGroupName ("TrafficControl")
41  .AddConstructor<PfifoFastQueueDisc> ()
42  .AddAttribute ("Limit",
43  "The maximum number of packets accepted by this queue disc.",
44  UintegerValue (1000),
47  MakeUintegerChecker<uint32_t> (),
49  "Use the MaxSize attribute instead")
50  .AddAttribute ("MaxSize",
51  "The maximum number of packets accepted by this queue disc.",
52  QueueSizeValue (QueueSize ("0p")),
56  ;
57  return tid;
58 }
59 
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
67 {
68  NS_LOG_FUNCTION (this);
69 }
70 
71 const uint32_t PfifoFastQueueDisc::prio2band[16] = {1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
72 
73 bool
75 {
76  NS_LOG_FUNCTION (this << item);
77 
78  if (GetCurrentSize () >= GetMaxSize ())
79  {
80  NS_LOG_LOGIC ("Queue disc limit exceeded -- dropping packet");
82  return false;
83  }
84 
85  uint8_t priority = 0;
86  SocketPriorityTag priorityTag;
87  if (item->GetPacket ()->PeekPacketTag (priorityTag))
88  {
89  priority = priorityTag.GetPriority ();
90  }
91 
92  uint32_t band = prio2band[priority & 0x0f];
93 
94  bool retval = GetInternalQueue (band)->Enqueue (item);
95 
96  // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the
97  // internal queue because QueueDisc::AddInternalQueue sets the trace callback
98 
99  if (!retval)
100  {
101  NS_LOG_WARN ("Packet enqueue failed. Check the size of the internal queues");
102  }
103 
104  NS_LOG_LOGIC ("Number packets band " << band << ": " << GetInternalQueue (band)->GetNPackets ());
105 
106  return retval;
107 }
108 
111 {
112  NS_LOG_FUNCTION (this);
113 
114  Ptr<QueueDiscItem> item;
115 
116  for (uint32_t i = 0; i < GetNInternalQueues (); i++)
117  {
118  if ((item = GetInternalQueue (i)->Dequeue ()) != 0)
119  {
120  NS_LOG_LOGIC ("Popped from band " << i << ": " << item);
121  NS_LOG_LOGIC ("Number packets band " << i << ": " << GetInternalQueue (i)->GetNPackets ());
122  return item;
123  }
124  }
125 
126  NS_LOG_LOGIC ("Queue empty");
127  return item;
128 }
129 
132 {
133  NS_LOG_FUNCTION (this);
134 
136 
137  for (uint32_t i = 0; i < GetNInternalQueues (); i++)
138  {
139  if ((item = GetInternalQueue (i)->Peek ()) != 0)
140  {
141  NS_LOG_LOGIC ("Peeked from band " << i << ": " << item);
142  NS_LOG_LOGIC ("Number packets band " << i << ": " << GetInternalQueue (i)->GetNPackets ());
143  return item;
144  }
145  }
146 
147  NS_LOG_LOGIC ("Queue empty");
148  return item;
149 }
150 
151 void
153 {
154  NS_LOG_FUNCTION (this << limit);
156 }
157 
158 uint32_t
160 {
161  NS_LOG_FUNCTION (this);
162  return GetMaxSize ().GetValue ();
163 }
164 
165 bool
167 {
168  NS_LOG_FUNCTION (this);
169  if (GetNQueueDiscClasses () > 0)
170  {
171  NS_LOG_ERROR ("PfifoFastQueueDisc cannot have classes");
172  return false;
173  }
174 
175  if (GetNPacketFilters () != 0)
176  {
177  NS_LOG_ERROR ("PfifoFastQueueDisc needs no packet filter");
178  return false;
179  }
180 
181  if (GetNInternalQueues () == 0)
182  {
183  // create 3 DropTail queues with GetLimit() packets each
184  ObjectFactory factory;
185  factory.SetTypeId ("ns3::DropTailQueue<QueueDiscItem>");
186  factory.Set ("MaxSize", QueueSizeValue (GetMaxSize ()));
187  AddInternalQueue (factory.Create<InternalQueue> ());
188  AddInternalQueue (factory.Create<InternalQueue> ());
189  AddInternalQueue (factory.Create<InternalQueue> ());
190  }
191 
192  if (GetNInternalQueues () != 3)
193  {
194  NS_LOG_ERROR ("PfifoFastQueueDisc needs 3 internal queues");
195  return false;
196  }
197 
198  if (GetInternalQueue (0)-> GetMaxSize ().GetUnit () != QueueSizeUnit::PACKETS ||
199  GetInternalQueue (1)-> GetMaxSize ().GetUnit () != QueueSizeUnit::PACKETS ||
200  GetInternalQueue (2)-> GetMaxSize ().GetUnit () != QueueSizeUnit::PACKETS)
201  {
202  NS_LOG_ERROR ("PfifoFastQueueDisc needs 3 internal queues operating in packet mode");
203  return false;
204  }
205 
206  for (uint8_t i = 0; i < 2; i++)
207  {
208  if (GetInternalQueue (i)->GetMaxSize () < GetMaxSize ())
209  {
210  NS_LOG_ERROR ("The capacity of some internal queue(s) is less than the queue disc capacity");
211  return false;
212  }
213  }
214 
215  return true;
216 }
217 
218 void
220 {
221  NS_LOG_FUNCTION (this);
222 }
223 
224 } // namespace ns3
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract, without actually extracting the pack...
Definition: queue-disc.cc:873
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:652
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Class for representing queue sizes.
Definition: queue-size.h:94
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:704
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:42
QueueSize GetCurrentSize(void)
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets, otherwise.
Definition: queue-disc.cc:523
virtual void InitializeParams(void)
Initialize parameters (if any) before the first packet is enqueued.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:181
virtual Ptr< const QueueDiscItem > DoPeek(void)
This function returns a copy of the next packet the queue disc will extract.
uint32_t GetValue() const
Get the underlying value.
Definition: queue-size.cc:175
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
Ptr< InternalQueue > GetInternalQueue(uint32_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:587
static constexpr const char * LIMIT_EXCEEDED_DROP
Packet dropped due to queue disc limit exceeded.
void SetLimit(uint32_t limit)
Set the limit of this queue disc.
uint32_t GetLimit(void) const
Get the limit of this queue disc.
uint32_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:594
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:567
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Hold an unsigned integer type.
Definition: uinteger.h:44
Use number of packets for queue size.
Definition: queue-size.h:44
indicates whether the socket has a priority set.
Definition: socket.h:1303
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition: queue-size.h:221
Attribute or trace source is deprecated; user is warned.
Definition: type-id.h:72
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:614
Ptr< QueueDiscItem > Dequeue(void)
Request the queue discipline to extract a packet.
Definition: queue-disc.cc:860
Ptr< const AttributeChecker > MakeQueueSizeChecker(void)
Definition: queue-size.cc:29
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static TypeId GetTypeId(void)
Get the type ID.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
This function actually enqueues a packet into the queue disc.
void Set(std::string name, const AttributeValue &value)
Set an attribute to be set during construction.
uint8_t GetPriority(void) const
Get the tag's priority.
Definition: socket.cc:854
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:103
Instantiate subclasses of ns3::Object.
Used by queue discs with multiple internal queues/child queue discs.
Definition: queue-disc.h:107
Introspection did not find any typical Config paths.
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:261
static const uint32_t prio2band[16]
Priority to band map.
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:482
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:253
Linux pfifo_fast is the default priority queue enabled on Linux systems.
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: uinteger.h:45
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:914
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:454
PfifoFastQueueDisc()
PfifoFastQueueDisc constructor.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:440