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 #include "ns3/net-device-queue-interface.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("FifoQueueDisc");
30 
31 NS_OBJECT_ENSURE_REGISTERED (FifoQueueDisc);
32 
34 {
35  static TypeId tid = TypeId ("ns3::FifoQueueDisc")
36  .SetParent<QueueDisc> ()
37  .SetGroupName ("TrafficControl")
38  .AddConstructor<FifoQueueDisc> ()
39  .AddAttribute ("MaxSize",
40  "The max queue size",
41  QueueSizeValue (QueueSize ("1000p")),
45  ;
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 0;
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 0;
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
135  ("MaxSize", QueueSizeValue (GetMaxSize ())));
136  }
137 
138  if (GetNInternalQueues () != 1)
139  {
140  NS_LOG_ERROR ("FifoQueueDisc needs 1 internal queue");
141  return false;
142  }
143 
144  return true;
145 }
146 
147 void
149 {
150  NS_LOG_FUNCTION (this);
151 }
152 
153 } // namespace ns3
Simple queue disc implementing the FIFO (First-In First-Out) policy.
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:440
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 "...
Class for representing queue sizes.
Definition: queue-size.h:94
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:712
virtual Ptr< const QueueDiscItem > DoPeek(void)
Return a copy of the next packet the queue disc will extract.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)
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.
virtual Ptr< QueueDiscItem > DoDequeue(void)
This function actually extracts a packet from the queue disc.
QueueSize GetCurrentSize(void)
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets, otherwise.
Definition: queue-disc.cc:523
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:202
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:447
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:182
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:567
Ptr< T > CreateObjectWithAttributes(std::string n1="", const AttributeValue &v1=EmptyAttributeValue(), std::string n2="", const AttributeValue &v2=EmptyAttributeValue(), std::string n3="", const AttributeValue &v3=EmptyAttributeValue(), std::string n4="", const AttributeValue &v4=EmptyAttributeValue(), std::string n5="", const AttributeValue &v5=EmptyAttributeValue(), std::string n6="", const AttributeValue &v6=EmptyAttributeValue(), std::string n7="", const AttributeValue &v7=EmptyAttributeValue(), std::string n8="", const AttributeValue &v8=EmptyAttributeValue(), std::string n9="", const AttributeValue &v9=EmptyAttributeValue())
Allocate an Object on the heap and initialize with a set of attributes.
static TypeId GetTypeId(void)
Get the type ID.
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:587
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Definition: queue-size.h:221
Introspection did not find any typical Config paths.
Ptr< const AttributeChecker > MakeQueueSizeChecker(void)
Definition: queue-size.cc:29
FifoQueueDisc()
FifoQueueDisc constructor.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:652
NS_LOG_LOGIC("Net device "<< nd<< " is not bridged")
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:454
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:104
Used by queue discs with single internal queue.
Definition: queue-disc.h:106
std::size_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:614
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:482
virtual bool CheckConfig(void)
Check whether the current configuration is correct.
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
Definition: log.h:254
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
std::size_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:594