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 "pfifo-fast-queue-disc.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("PfifoFastQueueDisc");
32 
33 NS_OBJECT_ENSURE_REGISTERED (PfifoFastQueueDisc);
34 
36 {
37  static TypeId tid = TypeId ("ns3::PfifoFastQueueDisc")
38  .SetParent<QueueDisc> ()
39  .SetGroupName ("TrafficControl")
40  .AddConstructor<PfifoFastQueueDisc> ()
41  .AddAttribute ("Limit",
42  "The maximum number of packets accepted by this queue disc.",
43  UintegerValue (1000),
45  MakeUintegerChecker<uint32_t> ())
46  ;
47  return tid;
48 }
49 
51 {
52  NS_LOG_FUNCTION (this);
53 }
54 
56 {
57  NS_LOG_FUNCTION (this);
58 }
59 
60 bool
62 {
63  NS_LOG_FUNCTION (this << item);
64 
65  if (GetNPackets () > m_limit)
66  {
67  NS_LOG_LOGIC ("Queue disc limit exceeded -- dropping packet");
68  Drop (item);
69  return false;
70  }
71 
72  uint32_t band;
73  int32_t ret = Classify (item);
74 
75  if (ret == PacketFilter::PF_NO_MATCH)
76  {
77  band = 1;
78  NS_LOG_DEBUG ("The filter was unable to classify; using default band of " << band);
79  }
80  else if (ret < 0 || ret > 2)
81  {
82  band = 1;
83  NS_LOG_DEBUG ("The filter returned an invalid value; using default band of " << band);
84  }
85  else
86  {
87  band = ret;
88  }
89 
90  if (!GetInternalQueue(band)->Enqueue (item))
91  {
92  NS_LOG_LOGIC ("Enqueue failed -- dropping pkt");
93  Drop (item);
94  return false;
95  }
96  NS_LOG_LOGIC ("Number packets band " << band << ": " << GetInternalQueue(band)->GetNPackets ());
97 
98  return true;
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 = StaticCast<QueueDiscItem> (GetInternalQueue (i)->Dequeue ())) != 0)
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  item = StaticCast<const QueueDiscItem> (GetInternalQueue (i)->Peek ());
132  NS_LOG_LOGIC ("Peeked from band " << i << ": " << item);
133  NS_LOG_LOGIC ("Number packets band " << i << ": " << GetInternalQueue (i)->GetNPackets ());
134  return item;
135  }
136 
137  NS_LOG_LOGIC ("Queue empty");
138  return item;
139 }
140 
141 bool
143 {
144  NS_LOG_FUNCTION (this);
145  if (GetNQueueDiscClasses () > 0)
146  {
147  NS_LOG_ERROR ("PfifoFastQueueDisc cannot have classes");
148  return false;
149  }
150 
151  if (GetNPacketFilters () == 0)
152  {
153  NS_LOG_ERROR ("PfifoFastQueueDisc needs at least a packet filter");
154  return false;
155  }
156 
157  if (GetNInternalQueues () == 0)
158  {
159  // create 3 DropTail queues with m_limit packets each
160  ObjectFactory factory;
161  factory.SetTypeId ("ns3::DropTailQueue");
162  factory.Set ("Mode", EnumValue (Queue::QUEUE_MODE_PACKETS));
163  factory.Set ("MaxPackets", UintegerValue (m_limit));
164  AddInternalQueue (factory.Create<Queue> ());
165  AddInternalQueue (factory.Create<Queue> ());
166  AddInternalQueue (factory.Create<Queue> ());
167  }
168 
169  if (GetNInternalQueues () != 3)
170  {
171  NS_LOG_ERROR ("PfifoFastQueueDisc needs 3 internal queues");
172  return false;
173  }
174 
175  if (GetInternalQueue (0)-> GetMode () != Queue::QUEUE_MODE_PACKETS ||
176  GetInternalQueue (1)-> GetMode () != Queue::QUEUE_MODE_PACKETS ||
177  GetInternalQueue (2)-> GetMode () != Queue::QUEUE_MODE_PACKETS)
178  {
179  NS_LOG_ERROR ("PfifoFastQueueDisc needs 3 internal queues operating in packet mode");
180  return false;
181  }
182 
183  for (uint8_t i = 0; i < 2; i++)
184  {
185  if (GetInternalQueue (i)->GetMaxPackets () < m_limit)
186  {
187  NS_LOG_ERROR ("The capacity of some internal queue(s) is less than the queue disc capacity");
188  return false;
189  }
190  }
191 
192  return true;
193 }
194 
195 void
197 {
198  NS_LOG_FUNCTION (this);
199 }
200 
201 } // namespace ns3
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:367
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 "...
static const int PF_NO_MATCH
Definition: packet-filter.h:45
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:411
#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:319
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:326
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:312
int32_t Classify(Ptr< QueueDiscItem > item)
Classify a packet by calling the packet filters, one at a time, until either a filter able to classif...
Definition: queue-disc.cc:373
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:346
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:427
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.
void Drop(Ptr< QueueDiscItem > item)
Drop a packet.
Definition: queue-disc.cc:393
Instantiate subclasses of ns3::Object.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:236
#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:127
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:826
PfifoFastQueueDisc()
PfifoFastQueueDisc constructor.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:228