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/pointer.h"
25 #include "ns3/object-factory.h"
26 #include "ns3/drop-tail-queue.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),
46  MakeUintegerChecker<uint32_t> ())
47  ;
48  return tid;
49 }
50 
52 {
53  NS_LOG_FUNCTION (this);
54 }
55 
57 {
58  NS_LOG_FUNCTION (this);
59 }
60 
61 const uint32_t PfifoFastQueueDisc::prio2band[16] = {1, 2, 2, 2, 1, 2, 0, 0, 1, 1, 1, 1, 1, 1, 1, 1};
62 
63 bool
65 {
66  NS_LOG_FUNCTION (this << item);
67 
68  if (GetNPackets () > m_limit)
69  {
70  NS_LOG_LOGIC ("Queue disc limit exceeded -- dropping packet");
71  Drop (item);
72  return false;
73  }
74 
75  uint8_t priority = 0;
76  SocketPriorityTag priorityTag;
77  if (item->GetPacket ()->PeekPacketTag (priorityTag))
78  {
79  priority = priorityTag.GetPriority ();
80  }
81 
82  uint32_t band = prio2band[priority & 0x0f];
83 
84  bool retval = GetInternalQueue (band)->Enqueue (item);
85 
86  // If Queue::Enqueue fails, QueueDisc::Drop is called by the internal queue
87  // because QueueDisc::AddInternalQueue sets the drop callback
88 
89  NS_LOG_LOGIC ("Number packets band " << band << ": " << GetInternalQueue (band)->GetNPackets ());
90 
91  return retval;
92 }
93 
96 {
97  NS_LOG_FUNCTION (this);
98 
99  Ptr<QueueDiscItem> item;
100 
101  for (uint32_t i = 0; i < GetNInternalQueues (); i++)
102  {
103  if ((item = StaticCast<QueueDiscItem> (GetInternalQueue (i)->Dequeue ())) != 0)
104  {
105  NS_LOG_LOGIC ("Popped from band " << i << ": " << item);
106  NS_LOG_LOGIC ("Number packets band " << i << ": " << GetInternalQueue (i)->GetNPackets ());
107  return item;
108  }
109  }
110 
111  NS_LOG_LOGIC ("Queue empty");
112  return item;
113 }
114 
117 {
118  NS_LOG_FUNCTION (this);
119 
121 
122  for (uint32_t i = 0; i < GetNInternalQueues (); i++)
123  {
124  item = StaticCast<const QueueDiscItem> (GetInternalQueue (i)->Peek ());
125  NS_LOG_LOGIC ("Peeked from band " << i << ": " << item);
126  NS_LOG_LOGIC ("Number packets band " << i << ": " << GetInternalQueue (i)->GetNPackets ());
127  return item;
128  }
129 
130  NS_LOG_LOGIC ("Queue empty");
131  return item;
132 }
133 
134 bool
136 {
137  NS_LOG_FUNCTION (this);
138  if (GetNQueueDiscClasses () > 0)
139  {
140  NS_LOG_ERROR ("PfifoFastQueueDisc cannot have classes");
141  return false;
142  }
143 
144  if (GetNPacketFilters () != 0)
145  {
146  NS_LOG_ERROR ("PfifoFastQueueDisc needs no packet filter");
147  return false;
148  }
149 
150  if (GetNInternalQueues () == 0)
151  {
152  // create 3 DropTail queues with m_limit packets each
153  ObjectFactory factory;
154  factory.SetTypeId ("ns3::DropTailQueue");
155  factory.Set ("Mode", EnumValue (Queue::QUEUE_MODE_PACKETS));
156  factory.Set ("MaxPackets", UintegerValue (m_limit));
157  AddInternalQueue (factory.Create<Queue> ());
158  AddInternalQueue (factory.Create<Queue> ());
159  AddInternalQueue (factory.Create<Queue> ());
160  }
161 
162  if (GetNInternalQueues () != 3)
163  {
164  NS_LOG_ERROR ("PfifoFastQueueDisc needs 3 internal queues");
165  return false;
166  }
167 
168  if (GetInternalQueue (0)-> GetMode () != Queue::QUEUE_MODE_PACKETS ||
169  GetInternalQueue (1)-> GetMode () != Queue::QUEUE_MODE_PACKETS ||
170  GetInternalQueue (2)-> GetMode () != Queue::QUEUE_MODE_PACKETS)
171  {
172  NS_LOG_ERROR ("PfifoFastQueueDisc needs 3 internal queues operating in packet mode");
173  return false;
174  }
175 
176  for (uint8_t i = 0; i < 2; i++)
177  {
178  if (GetInternalQueue (i)->GetMaxPackets () < m_limit)
179  {
180  NS_LOG_ERROR ("The capacity of some internal queue(s) is less than the queue disc capacity");
181  return false;
182  }
183  }
184 
185  return true;
186 }
187 
188 void
190 {
191  NS_LOG_FUNCTION (this);
192 }
193 
194 } // namespace ns3
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:379
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 "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Ptr< Queue > GetInternalQueue(uint32_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:324
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:205
Abstract base class for packet Queues.
Definition: queue.h:44
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
uint32_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:331
void Drop(Ptr< QueueItem > item)
Drop a packet.
Definition: queue-disc.cc:411
Hold variables of type enum.
Definition: enum.h:54
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Hold an unsigned integer type.
Definition: uinteger.h:44
void AddInternalQueue(Ptr< Queue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:314
indicates whether the socket has a priority set.
Definition: socket.h:1304
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:351
uint32_t m_limit
Maximum number of packets that can be stored.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
virtual Ptr< const QueueDiscItem > DoPeek(void) const
This function returns a copy of the next packet the queue disc will extract.
Ptr< QueueDiscItem > Dequeue(void)
Request the queue discipline to extract a packet.
Definition: queue-disc.cc:467
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
Instantiate subclasses of ns3::Object.
static const uint32_t prio2band[16]
Priority to band map.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:220
Linux pfifo_fast is the default priority queue enabled on Linux systems.
Use number of packets for maximum queue size.
Definition: queue.h:132
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:904
PfifoFastQueueDisc()
PfifoFastQueueDisc constructor.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:230