A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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 NS_LOG_COMPONENT_DEFINE ("DropTailQueue");
25 
26 namespace ns3 {
27 
28 NS_OBJECT_ENSURE_REGISTERED (DropTailQueue)
29  ;
30 
32 {
33  static TypeId tid = TypeId ("ns3::DropTailQueue")
34  .SetParent<Queue> ()
35  .AddConstructor<DropTailQueue> ()
36  .AddAttribute ("Mode",
37  "Whether to use bytes (see MaxBytes) or packets (see MaxPackets) as the maximum queue size metric.",
40  MakeEnumChecker (QUEUE_MODE_BYTES, "QUEUE_MODE_BYTES",
41  QUEUE_MODE_PACKETS, "QUEUE_MODE_PACKETS"))
42  .AddAttribute ("MaxPackets",
43  "The maximum number of packets accepted by this DropTailQueue.",
44  UintegerValue (100),
45  MakeUintegerAccessor (&DropTailQueue::m_maxPackets),
46  MakeUintegerChecker<uint32_t> ())
47  .AddAttribute ("MaxBytes",
48  "The maximum number of bytes accepted by this DropTailQueue.",
49  UintegerValue (100 * 65535),
50  MakeUintegerAccessor (&DropTailQueue::m_maxBytes),
51  MakeUintegerChecker<uint32_t> ())
52  ;
53 
54  return tid;
55 }
56 
58  Queue (),
59  m_packets (),
60  m_bytesInQueue (0)
61 {
62  NS_LOG_FUNCTION (this);
63 }
64 
66 {
67  NS_LOG_FUNCTION (this);
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION (this << mode);
74  m_mode = mode;
75 }
76 
79 {
80  NS_LOG_FUNCTION (this);
81  return m_mode;
82 }
83 
84 bool
86 {
87  NS_LOG_FUNCTION (this << p);
88 
89  if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () >= m_maxPackets))
90  {
91  NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt");
92  Drop (p);
93  return false;
94  }
95 
97  {
98  NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt");
99  Drop (p);
100  return false;
101  }
102 
103  m_bytesInQueue += p->GetSize ();
104  m_packets.push (p);
105 
106  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
107  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
108 
109  return true;
110 }
111 
114 {
115  NS_LOG_FUNCTION (this);
116 
117  if (m_packets.empty ())
118  {
119  NS_LOG_LOGIC ("Queue empty");
120  return 0;
121  }
122 
123  Ptr<Packet> p = m_packets.front ();
124  m_packets.pop ();
125  m_bytesInQueue -= p->GetSize ();
126 
127  NS_LOG_LOGIC ("Popped " << p);
128 
129  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
130  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
131 
132  return p;
133 }
134 
137 {
138  NS_LOG_FUNCTION (this);
139 
140  if (m_packets.empty ())
141  {
142  NS_LOG_LOGIC ("Queue empty");
143  return 0;
144  }
145 
146  Ptr<Packet> p = m_packets.front ();
147 
148  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
149  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
150 
151  return p;
152 }
153 
154 } // namespace ns3
155 
virtual Ptr< const Packet > DoPeek(void) const
static TypeId GetTypeId(void)
#define NS_LOG_FUNCTION(parameters)
Definition: log.h:345
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)
Definition: enum.cc:178
void SetMode(DropTailQueue::QueueMode mode)
Set the operating mode of this device.
NS_OBJECT_ENSURE_REGISTERED(NullMessageSimulatorImpl)
uint32_t GetSize(void) const
Definition: packet.h:650
virtual bool DoEnqueue(Ptr< Packet > p)
Abstract base class for packet Queues.
Definition: queue.h:45
hold variables of type 'enum'
Definition: enum.h:37
Hold an unsigned integer type.
Definition: uinteger.h:46
virtual Ptr< Packet > DoDequeue(void)
#define NS_LOG_LOGIC(msg)
Definition: log.h:368
Use number of bytes for maximum queue size.
Definition: queue.h:125
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:122
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:118
std::queue< Ptr< Packet > > m_packets
Use number of packets for maximum queue size.
Definition: queue.h:124
NS_LOG_COMPONENT_DEFINE("DropTailQueue")
DropTailQueue()
DropTailQueue Constructor.
DropTailQueue::QueueMode GetMode(void)
Get the encapsulation mode of this device.
a unique identifier for an interface.
Definition: type-id.h:49
TypeId SetParent(TypeId tid)
Definition: type-id.cc:611
void Drop(Ptr< Packet > packet)
Drop a packet.
Definition: queue.cc:192