A Discrete-Event Network Simulator
API
fifo-queue-disc.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2017 Universita' degli Studi di Napoli Federico II
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Authors: Stefano Avallone <stavallo@unina.it>
18  */
19 
20 #include "fifo-queue-disc.h"
21 
22 #include "ns3/drop-tail-queue.h"
23 #include "ns3/log.h"
24 #include "ns3/object-factory.h"
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE("FifoQueueDisc");
30 
31 NS_OBJECT_ENSURE_REGISTERED(FifoQueueDisc);
32 
33 TypeId
35 {
36  static TypeId tid =
37  TypeId("ns3::FifoQueueDisc")
39  .SetGroupName("TrafficControl")
40  .AddConstructor<FifoQueueDisc>()
41  .AddAttribute("MaxSize",
42  "The max queue size",
43  QueueSizeValue(QueueSize("1000p")),
44  MakeQueueSizeAccessor(&QueueDisc::SetMaxSize, &QueueDisc::GetMaxSize),
45  MakeQueueSizeChecker());
46  return tid;
47 }
48 
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 (GetCurrentSize() + item > GetMaxSize())
66  {
67  NS_LOG_LOGIC("Queue full -- dropping pkt");
69  return false;
70  }
71 
72  bool retval = GetInternalQueue(0)->Enqueue(item);
73 
74  // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the
75  // internal queue because QueueDisc::AddInternalQueue sets the trace callback
76 
77  NS_LOG_LOGIC("Number packets " << GetInternalQueue(0)->GetNPackets());
78  NS_LOG_LOGIC("Number bytes " << GetInternalQueue(0)->GetNBytes());
79 
80  return retval;
81 }
82 
85 {
86  NS_LOG_FUNCTION(this);
87 
88  Ptr<QueueDiscItem> item = GetInternalQueue(0)->Dequeue();
89 
90  if (!item)
91  {
92  NS_LOG_LOGIC("Queue empty");
93  return nullptr;
94  }
95 
96  return item;
97 }
98 
101 {
102  NS_LOG_FUNCTION(this);
103 
104  Ptr<const QueueDiscItem> item = GetInternalQueue(0)->Peek();
105 
106  if (!item)
107  {
108  NS_LOG_LOGIC("Queue empty");
109  return nullptr;
110  }
111 
112  return item;
113 }
114 
115 bool
117 {
118  NS_LOG_FUNCTION(this);
119  if (GetNQueueDiscClasses() > 0)
120  {
121  NS_LOG_ERROR("FifoQueueDisc cannot have classes");
122  return false;
123  }
124 
125  if (GetNPacketFilters() > 0)
126  {
127  NS_LOG_ERROR("FifoQueueDisc needs no packet filter");
128  return false;
129  }
130 
131  if (GetNInternalQueues() == 0)
132  {
133  // add a DropTail queue
136  QueueSizeValue(GetMaxSize())));
137  }
138 
139  if (GetNInternalQueues() != 1)
140  {
141  NS_LOG_ERROR("FifoQueueDisc needs 1 internal queue");
142  return false;
143  }
144 
145  return true;
146 }
147 
148 void
150 {
151  NS_LOG_FUNCTION(this);
152 }
153 
154 } // namespace ns3
A FIFO packet queue that drops tail-end packets on overflow.
Simple queue disc implementing the FIFO (First-In First-Out) policy.
FifoQueueDisc()
FifoQueueDisc constructor.
Ptr< const QueueDiscItem > DoPeek() override
Return a copy of the next packet the queue disc will extract.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
bool CheckConfig() override
Check whether the current configuration is correct.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
static constexpr const char * LIMIT_EXCEEDED_DROP
Packet dropped due to queue disc limit exceeded.
static TypeId GetTypeId()
Get the type ID.
~FifoQueueDisc() override
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
uint32_t GetNBytes() const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:439
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
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
Class for representing queue sizes.
Definition: queue-size.h:96
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 ",...
Ptr< T > CreateObjectWithAttributes(Args... args)
Allocate an Object on the heap and initialize with a set of attributes.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:46
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:107
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
Definition: queue-disc.h:108
Every class exported by the ns3 library is enclosed in the ns3 namespace.