A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Authors: Stefano Avallone <stavallo@unina.it>
7 */
8
9#include "fifo-queue-disc.h"
10
11#include "ns3/drop-tail-queue.h"
12#include "ns3/log.h"
13#include "ns3/object-factory.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("FifoQueueDisc");
19
20NS_OBJECT_ENSURE_REGISTERED(FifoQueueDisc);
21
22TypeId
24{
25 static TypeId tid =
26 TypeId("ns3::FifoQueueDisc")
28 .SetGroupName("TrafficControl")
29 .AddConstructor<FifoQueueDisc>()
30 .AddAttribute("MaxSize",
31 "The max queue size",
32 QueueSizeValue(QueueSize("1000p")),
35 return tid;
36}
37
43
48
49bool
51{
52 NS_LOG_FUNCTION(this << item);
53
54 if (GetCurrentSize() + item > GetMaxSize())
55 {
56 NS_LOG_LOGIC("Queue full -- dropping pkt");
58 return false;
59 }
60
61 bool retval = GetInternalQueue(0)->Enqueue(item);
62
63 // If Queue::Enqueue fails, QueueDisc::DropBeforeEnqueue is called by the
64 // internal queue because QueueDisc::AddInternalQueue sets the trace callback
65
66 NS_LOG_LOGIC("Number packets " << GetInternalQueue(0)->GetNPackets());
67 NS_LOG_LOGIC("Number bytes " << GetInternalQueue(0)->GetNBytes());
68
69 return retval;
70}
71
74{
75 NS_LOG_FUNCTION(this);
76
77 Ptr<QueueDiscItem> item = GetInternalQueue(0)->Dequeue();
78
79 if (!item)
80 {
81 NS_LOG_LOGIC("Queue empty");
82 return nullptr;
83 }
84
85 return item;
86}
87
90{
91 NS_LOG_FUNCTION(this);
92
94
95 if (!item)
96 {
97 NS_LOG_LOGIC("Queue empty");
98 return nullptr;
99 }
100
101 return item;
102}
103
104bool
106{
107 NS_LOG_FUNCTION(this);
108 if (GetNQueueDiscClasses() > 0)
109 {
110 NS_LOG_ERROR("FifoQueueDisc cannot have classes");
111 return false;
112 }
113
114 if (GetNPacketFilters() > 0)
115 {
116 NS_LOG_ERROR("FifoQueueDisc needs no packet filter");
117 return false;
118 }
119
120 if (GetNInternalQueues() == 0)
121 {
122 // add a DropTail queue
126 }
127
128 if (GetNInternalQueues() != 1)
129 {
130 NS_LOG_ERROR("FifoQueueDisc needs 1 internal queue");
131 return false;
132 }
133
134 return true;
135}
136
137void
142
143} // 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.
Smart pointer class similar to boost::intrusive_ptr.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition queue-disc.h:173
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
uint32_t GetNBytes() const
Get the amount of bytes stored by the queue disc.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
QueueSize GetCurrentSize() const
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
QueueSize GetMaxSize() const
Get the maximum size of the queue disc.
std::size_t GetNPacketFilters() const
Get the number of packet filters.
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
std::size_t GetNInternalQueues() const
Get the number of internal queues.
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.
Class for representing queue sizes.
Definition queue-size.h:85
a unique identifier for an interface.
Definition type-id.h:48
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition log.h:243
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition log.h:271
#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:35
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition queue-disc.h:96
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
Definition queue-disc.h:97
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition queue-size.h:210
Ptr< const AttributeChecker > MakeQueueSizeChecker()
Definition queue-size.cc:18