A Discrete-Event Network Simulator
API
fifo-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) 2017 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 */
20
21#include "ns3/log.h"
22#include "fifo-queue-disc.h"
23#include "ns3/object-factory.h"
24#include "ns3/drop-tail-queue.h"
25
26namespace ns3 {
27
28NS_LOG_COMPONENT_DEFINE ("FifoQueueDisc");
29
30NS_OBJECT_ENSURE_REGISTERED (FifoQueueDisc);
31
33{
34 static TypeId tid = TypeId ("ns3::FifoQueueDisc")
36 .SetGroupName ("TrafficControl")
37 .AddConstructor<FifoQueueDisc> ()
38 .AddAttribute ("MaxSize",
39 "The max queue size",
40 QueueSizeValue (QueueSize ("1000p")),
41 MakeQueueSizeAccessor (&QueueDisc::SetMaxSize,
43 MakeQueueSizeChecker ())
44 ;
45 return tid;
46}
47
50{
51 NS_LOG_FUNCTION (this);
52}
53
55{
56 NS_LOG_FUNCTION (this);
57}
58
59bool
61{
62 NS_LOG_FUNCTION (this << item);
63
64 if (GetCurrentSize () + item > GetMaxSize ())
65 {
66 NS_LOG_LOGIC ("Queue full -- dropping pkt");
68 return false;
69 }
70
71 bool retval = GetInternalQueue (0)->Enqueue (item);
72
73 // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the
74 // internal queue because QueueDisc::AddInternalQueue sets the trace callback
75
76 NS_LOG_LOGIC ("Number packets " << GetInternalQueue (0)->GetNPackets ());
77 NS_LOG_LOGIC ("Number bytes " << GetInternalQueue (0)->GetNBytes ());
78
79 return retval;
80}
81
84{
85 NS_LOG_FUNCTION (this);
86
87 Ptr<QueueDiscItem> item = GetInternalQueue (0)->Dequeue ();
88
89 if (!item)
90 {
91 NS_LOG_LOGIC ("Queue empty");
92 return 0;
93 }
94
95 return item;
96}
97
100{
101 NS_LOG_FUNCTION (this);
102
103 Ptr<const QueueDiscItem> item = GetInternalQueue (0)->Peek ();
104
105 if (!item)
106 {
107 NS_LOG_LOGIC ("Queue empty");
108 return 0;
109 }
110
111 return item;
112}
113
114bool
116{
117 NS_LOG_FUNCTION (this);
118 if (GetNQueueDiscClasses () > 0)
119 {
120 NS_LOG_ERROR ("FifoQueueDisc cannot have classes");
121 return false;
122 }
123
124 if (GetNPacketFilters () > 0)
125 {
126 NS_LOG_ERROR ("FifoQueueDisc needs no packet filter");
127 return false;
128 }
129
130 if (GetNInternalQueues () == 0)
131 {
132 // add a DropTail queue
134 ("MaxSize", QueueSizeValue (GetMaxSize ())));
135 }
136
137 if (GetNInternalQueues () != 1)
138 {
139 NS_LOG_ERROR ("FifoQueueDisc needs 1 internal queue");
140 return false;
141 }
142
143 return true;
144}
145
146void
148{
149 NS_LOG_FUNCTION (this);
150}
151
152} // namespace ns3
Introspection did not find any typical Config paths.
Simple queue disc implementing the FIFO (First-In First-Out) policy.
FifoQueueDisc()
FifoQueueDisc constructor.
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
This function actually enqueues a packet into the queue disc.
virtual void InitializeParams(void)
Initialize parameters (if any) before the first packet is enqueued.
static constexpr const char * LIMIT_EXCEEDED_DROP
Packet dropped due to queue disc limit exceeded.
static TypeId GetTypeId(void)
Get the type ID.
virtual Ptr< const QueueDiscItem > DoPeek(void)
Return a copy of the next packet the queue disc will extract.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:181
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:579
QueueSize GetCurrentSize(void)
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
Definition: queue-disc.cc:521
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:445
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:452
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:599
std::size_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:626
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:438
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:667
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:480
std::size_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:606
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:727
Class for representing queue sizes.
Definition: queue-size.h:95
AttributeValue implementation for QueueSize.
a unique identifier for an interface.
Definition: type-id.h:59
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:922
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:257
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:289
#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:45
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:104
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
Definition: queue-disc.h:105
Every class exported by the ns3 library is enclosed in the ns3 namespace.