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 
31 {
32  static TypeId tid = TypeId ("ns3::DropTailQueue")
33  .SetParent<Queue> ()
34  .AddConstructor<DropTailQueue> ()
35  .AddAttribute ("Mode",
36  "Whether to use bytes (see MaxBytes) or packets (see MaxPackets) as the maximum queue size metric.",
39  MakeEnumChecker (QUEUE_MODE_BYTES, "QUEUE_MODE_BYTES",
40  QUEUE_MODE_PACKETS, "QUEUE_MODE_PACKETS"))
41  .AddAttribute ("MaxPackets",
42  "The maximum number of packets accepted by this DropTailQueue.",
43  UintegerValue (100),
44  MakeUintegerAccessor (&DropTailQueue::m_maxPackets),
45  MakeUintegerChecker<uint32_t> ())
46  .AddAttribute ("MaxBytes",
47  "The maximum number of bytes accepted by this DropTailQueue.",
48  UintegerValue (100 * 65535),
49  MakeUintegerAccessor (&DropTailQueue::m_maxBytes),
50  MakeUintegerChecker<uint32_t> ())
51  ;
52 
53  return tid;
54 }
55 
57  Queue (),
58  m_packets (),
59  m_bytesInQueue (0)
60 {
61  NS_LOG_FUNCTION (this);
62 }
63 
65 {
66  NS_LOG_FUNCTION (this);
67 }
68 
69 void
71 {
72  NS_LOG_FUNCTION (this << mode);
73  m_mode = mode;
74 }
75 
78 {
79  NS_LOG_FUNCTION (this);
80  return m_mode;
81 }
82 
83 bool
85 {
86  NS_LOG_FUNCTION (this << p);
87 
88  if (m_mode == QUEUE_MODE_PACKETS && (m_packets.size () >= m_maxPackets))
89  {
90  NS_LOG_LOGIC ("Queue full (at max packets) -- droppping pkt");
91  Drop (p);
92  return false;
93  }
94 
96  {
97  NS_LOG_LOGIC ("Queue full (packet would exceed max bytes) -- droppping pkt");
98  Drop (p);
99  return false;
100  }
101 
102  m_bytesInQueue += p->GetSize ();
103  m_packets.push (p);
104 
105  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
106  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
107 
108  return true;
109 }
110 
113 {
114  NS_LOG_FUNCTION (this);
115 
116  if (m_packets.empty ())
117  {
118  NS_LOG_LOGIC ("Queue empty");
119  return 0;
120  }
121 
122  Ptr<Packet> p = m_packets.front ();
123  m_packets.pop ();
124  m_bytesInQueue -= p->GetSize ();
125 
126  NS_LOG_LOGIC ("Popped " << p);
127 
128  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
129  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
130 
131  return p;
132 }
133 
136 {
137  NS_LOG_FUNCTION (this);
138 
139  if (m_packets.empty ())
140  {
141  NS_LOG_LOGIC ("Queue empty");
142  return 0;
143  }
144 
145  Ptr<Packet> p = m_packets.front ();
146 
147  NS_LOG_LOGIC ("Number packets " << m_packets.size ());
148  NS_LOG_LOGIC ("Number bytes " << m_bytesInQueue);
149 
150  return p;
151 }
152 
153 } // namespace ns3
154 
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 "...
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
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register the class in the ns-3 factory.
Definition: object-base.h:38
void SetMode(DropTailQueue::QueueMode mode)
Set the operating mode of this device.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:170
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:744
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
hold variables of type 'enum'
Definition: enum.h:37
Hold an unsigned integer type.
Definition: uinteger.h:46
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:233
Use number of bytes for maximum queue size.
Definition: queue.h:129
QueueMode
Enumeration of the modes supported in the class.
Definition: queue.h:126
Ptr< const AttributeAccessor > MakeEnumAccessor(T1 a1)
Definition: enum.h:118
std::queue< Ptr< Packet > > m_packets
the packets in the queue
Use number of packets for maximum queue size.
Definition: queue.h:128
QueueMode m_mode
queue mode (packets or bytes limited)
uint32_t m_bytesInQueue
actual bytes in the queue
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:610
void Drop(Ptr< Packet > packet)
Drop a packet.
Definition: queue.cc:191