A Discrete-Event Network Simulator
API
drop-tail-queue.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007 University of Washington
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 
19 #include "ns3/log.h"
20 #include "ns3/enum.h"
21 #include "ns3/uinteger.h"
22 #include "drop-tail-queue.h"
23 
24 namespace ns3 {
25 
26 NS_LOG_COMPONENT_DEFINE ("DropTailQueue");
27 
28 NS_OBJECT_ENSURE_REGISTERED (DropTailQueue);
29 
31 {
32  static TypeId tid = TypeId ("ns3::DropTailQueue")
33  .SetParent<Queue> ()
34  .SetGroupName("Network")
35  .AddConstructor<DropTailQueue> ()
36  .AddAttribute ("Mode",
37  "Whether to use bytes (see MaxBytes) or packets (see MaxPackets) as the maximum queue size metric.",
41  MakeEnumChecker (QUEUE_MODE_BYTES, "QUEUE_MODE_BYTES",
42  QUEUE_MODE_PACKETS, "QUEUE_MODE_PACKETS"))
43  .AddAttribute ("MaxPackets",
44  "The maximum number of packets accepted by this DropTailQueue.",
45  UintegerValue (100),
47  MakeUintegerChecker<uint32_t> ())
48  .AddAttribute ("MaxBytes",
49  "The maximum number of bytes accepted by this DropTailQueue.",
50  UintegerValue (100 * 65535),
52  MakeUintegerChecker<uint32_t> ())
53  ;
54 
55  return tid;
56 }
57 
59  Queue (),
60  m_packets (),
61  m_bytesInQueue (0)
62 {
63  NS_LOG_FUNCTION (this);
64 }
65 
67 {
68  NS_LOG_FUNCTION (this);
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION (this << mode);
75  m_mode = mode;
76 }
77 
80 {
81  NS_LOG_FUNCTION (this);
82  return m_mode;
83 }
84 
85 bool
87 {
88  NS_LOG_FUNCTION (this << p);
89 
90  if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () >= m_maxPackets))
91  {
92  NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt");
93  Drop (p);
94  return false;
95  }
96 
98  {
99  NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt");
100  Drop (p);
101  return false;
102  }
103 
104  m_bytesInQueue += p->GetSize ();
105  m_packets.push (p);
106 
107  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
108  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
109 
110  return true;
111 }
112 
115 {
116  NS_LOG_FUNCTION (this);
117 
118  if (m_packets.empty ())
119  {
120  NS_LOG_LOGIC ("Queue empty");
121  return 0;
122  }
123 
124  Ptr<Packet> p = m_packets.front ();
125  m_packets.pop ();
126  m_bytesInQueue -= p->GetSize ();
127 
128  NS_LOG_LOGIC ("Popped " << p);
129 
130  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
131  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
132 
133  return p;
134 }
135 
138 {
139  NS_LOG_FUNCTION (this);
140 
141  if (m_packets.empty ())
142  {
143  NS_LOG_LOGIC ("Queue empty");
144  return 0;
145  }
146 
147  Ptr<Packet> p = m_packets.front ();
148 
149  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
150  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
151 
152  return p;
153 }
154 
155 } // namespace ns3
156 
DropTailQueue::QueueMode GetMode(void) const
Get the encapsulation mode of this device.
virtual Ptr< const Packet > DoPeek(void) const
Peek the front packet in the queue.
static TypeId GetTypeId(void)
Get the type ID.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
Use number of bytes for maximum queue size.
Definition: queue.h:129
void SetMode(DropTailQueue::QueueMode mode)
Set the operating mode of this device.
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method...
Definition: enum.h:209
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
virtual bool DoEnqueue(Ptr< Packet > p)
Push a packet in the queue.
uint32_t m_maxBytes
max bytes in the queue
Abstract base class for packet Queues.
Definition: queue.h:45
uint32_t m_maxPackets
max packets in the queue
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:126
Hold variables of type enum.
Definition: enum.h:54
Hold an unsigned integer type.
Definition: uinteger.h:44
virtual Ptr< Packet > DoDequeue(void)
Pull a packet from the queue.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
Definition: log.h:252
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::queue< Ptr< Packet > > m_packets
the packets in the queue
Ptr< const AttributeChecker > MakeEnumChecker(int v1, std::string n1, int v2, std::string n2, int v3, std::string n3, int v4, std::string n4, int v5, std::string n5, int v6, std::string n6, int v7, std::string n7, int v8, std::string n8, int v9, std::string n9, int v10, std::string n10, int v11, std::string n11, int v12, std::string n12, int v13, std::string n13, int v14, std::string n14, int v15, std::string n15, int v16, std::string n16, int v17, std::string n17, int v18, std::string n18, int v19, std::string n19, int v20, std::string n20, int v21, std::string n21, int v22, std::string n22)
Make an EnumChecker pre-configured with a set of allowed values by name.
Definition: enum.cc:184
QueueMode m_mode
queue mode (packets or bytes limited)
uint32_t m_bytesInQueue
actual bytes in the queue
Use number of packets for maximum queue size.
Definition: queue.h:128
DropTailQueue()
DropTailQueue Constructor.
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
A FIFO packet queue that drops tail-end packets on overflow.
void Drop(Ptr< Packet > packet)
Drop a packet.
Definition: queue.cc:195