A Discrete-Event Network Simulator
API
queue-disc.h
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2007, 2014 University of Washington
4  * 2015 Universita' degli Studi di Napoli Federico II
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */
19 
20 #ifndef QUEUE_DISC_H
21 #define QUEUE_DISC_H
22 
23 #include "ns3/object.h"
24 #include "ns3/traced-value.h"
25 #include <ns3/queue.h>
26 #include "ns3/net-device.h"
27 #include <vector>
28 #include "packet-filter.h"
29 
30 namespace ns3 {
31 
32 class Packet;
33 class QueueDisc;
34 
43 class QueueDiscItem : public QueueItem {
44 public:
51  QueueDiscItem (Ptr<Packet> p, const Address & addr, uint16_t protocol);
52 
53  virtual ~QueueDiscItem ();
54 
59  Address GetAddress (void) const;
60 
65  uint16_t GetProtocol (void) const;
66 
71  uint8_t GetTxQueueIndex (void) const;
72 
77  void SetTxQueueIndex (uint8_t txq);
78 
86  virtual void AddHeader (void) = 0;
87 
92  virtual void Print (std::ostream &os) const;
93 
94 private:
100  QueueDiscItem ();
106  QueueDiscItem (const QueueDiscItem &);
114 
116  uint16_t m_protocol;
117  uint8_t m_txq;
118 };
119 
120 
130 class QueueDiscClass : public Object {
131 public:
136  static TypeId GetTypeId (void);
137 
138  QueueDiscClass ();
139  virtual ~QueueDiscClass () {}
140 
145  Ptr<QueueDisc> GetQueueDisc (void) const;
146 
150  void SetQueueDisc (Ptr<QueueDisc> qd);
151 
152 protected:
156  virtual void DoDispose (void);
157 
158 private:
160 };
161 
162 
205 class QueueDisc : public Object {
206 public:
211  static TypeId GetTypeId (void);
212 
213  QueueDisc ();
214 
226  uint32_t GetNPackets (void) const;
227 
239  uint32_t GetNBytes (void) const;
240 
245  uint32_t GetTotalReceivedPackets (void) const;
246 
251  uint32_t GetTotalReceivedBytes (void) const;
252 
257  uint32_t GetTotalDroppedPackets (void) const;
258 
263  uint32_t GetTotalDroppedBytes (void) const;
264 
269  uint32_t GetTotalRequeuedPackets (void) const;
270 
275  uint32_t GetTotalRequeuedBytes (void) const;
276 
281  void SetNetDevice (Ptr<NetDevice> device);
282 
287  Ptr<NetDevice> GetNetDevice (void) const;
288 
293  virtual void SetQuota (const uint32_t quota);
294 
299  virtual uint32_t GetQuota (void) const;
300 
308  bool Enqueue (Ptr<QueueDiscItem> item);
309 
317 
324  Ptr<const QueueDiscItem> Peek (void) const;
325 
331  void Run (void);
332 
337  void AddInternalQueue (Ptr<Queue> queue);
338 
344  Ptr<Queue> GetInternalQueue (uint32_t i) const;
345 
350  uint32_t GetNInternalQueues (void) const;
351 
356  void AddPacketFilter (Ptr<PacketFilter> filter);
357 
363  Ptr<PacketFilter> GetPacketFilter (uint32_t i) const;
364 
369  uint32_t GetNPacketFilters (void) const;
370 
375  void AddQueueDiscClass (Ptr<QueueDiscClass> qdClass);
376 
382  Ptr<QueueDiscClass> GetQueueDiscClass (uint32_t i) const;
383 
388  uint32_t GetNQueueDiscClasses (void) const;
389 
398  int32_t Classify (Ptr<QueueDiscItem> item);
399 
405  enum WakeMode
406  {
407  WAKE_ROOT = 0x00,
408  WAKE_CHILD = 0x01
409  };
410 
422  WakeMode GetWakeMode (void);
423 
424 protected:
428  virtual void DoDispose (void);
429 
433  virtual void DoInitialize (void);
434 
440  void Drop (Ptr<QueueDiscItem> item);
441 
442 private:
443 
449  virtual bool DoEnqueue (Ptr<QueueDiscItem> item) = 0;
450 
455  virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
456 
461  virtual Ptr<const QueueDiscItem> DoPeek (void) const = 0;
462 
469  virtual bool CheckConfig (void) = 0;
470 
474  virtual void InitializeParams (void) = 0;
475 
480  bool RunBegin (void);
481 
486  void RunEnd (void);
487 
493  bool Restart (void);
494 
500 
506  void Requeue (Ptr<QueueDiscItem> p);
507 
514  bool Transmit (Ptr<QueueDiscItem> p);
515 
516  static const uint32_t DEFAULT_QUOTA = 64;
517 
518  std::vector<Ptr<Queue> > m_queues;
519  std::vector<Ptr<PacketFilter> > m_filters;
520  std::vector<Ptr<QueueDiscClass> > m_classes;
521 
524 
531  uint32_t m_quota;
534  bool m_running;
536 
545 };
546 
547 } // namespace ns3
548 
549 #endif /* QueueDisc */
uint8_t GetTxQueueIndex(void) const
Get the transmission queue index included in this item.
Definition: queue-disc.cc:59
TracedCallback< Ptr< const QueueItem > > m_traceRequeue
Traced callback: fired when a packet is requeued.
Definition: queue-disc.h:542
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:367
Base class to represent items of packet Queues.
Definition: net-device.h:55
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
Definition: queue-disc.h:535
uint32_t GetTotalReceivedPackets(void) const
Get the total number of received packets.
Definition: queue-disc.cc:242
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
Definition: queue-disc.cc:352
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:411
Ptr< Queue > GetInternalQueue(uint32_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:319
virtual ~QueueDiscItem()
Definition: queue-disc.cc:41
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:235
uint32_t GetTotalRequeuedPackets(void) const
Get the total number of requeued packets.
Definition: queue-disc.cc:270
uint8_t m_txq
Transmission queue index.
Definition: queue-disc.h:117
Ptr< QueueDisc > m_queueDisc
Queue disc attached to this class.
Definition: queue-disc.h:159
Forward calls to a chain of Callback.
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:103
void SetQueueDisc(Ptr< QueueDisc > qd)
Set the queue disc attached to this class.
Definition: queue-disc.cc:118
void SetTxQueueIndex(uint8_t txq)
Set the transmission queue index to store in this item.
Definition: queue-disc.cc:65
TracedCallback< Ptr< const QueueItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue-disc.h:538
uint32_t m_nTotalReceivedPackets
Total received packets.
Definition: queue-disc.h:525
virtual Ptr< QueueDiscItem > DoDequeue(void)=0
This function actually extracts a packet from the queue disc.
QueueDiscItem is the abstract base class for items that are stored in a queue disc.
Definition: queue-disc.h:43
QueueDiscItem & operator=(const QueueDiscItem &)
Assignment operator.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:205
Address GetAddress(void) const
Get the MAC address included in this item.
Definition: queue-disc.cc:47
bool Transmit(Ptr< QueueDiscItem > p)
Modelled after the Linux function sch_direct_xmit (net/sched/sch_generic.c) Sends a packet to the dev...
Definition: queue-disc.cc:571
a polymophic address class
Definition: address.h:90
uint32_t GetTotalReceivedBytes(void) const
Get the total amount of received bytes.
Definition: queue-disc.cc:249
std::vector< Ptr< Queue > > m_queues
Internal queues.
Definition: queue-disc.h:518
uint32_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:326
virtual void DoInitialize(void)
Check whether the configuration is correct and initialize parameters.
Definition: queue-disc.cc:201
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
Definition: queue-disc.h:533
uint16_t m_protocol
L3 Protocol number.
Definition: queue-disc.h:116
QueueDiscItem()
Default constructor.
void AddInternalQueue(Ptr< Queue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:312
uint32_t m_nTotalReceivedBytes
Total received bytes.
Definition: queue-disc.h:526
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets...
Definition: queue-disc.cc:454
Ptr< PacketFilter > GetPacketFilter(uint32_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:339
uint32_t m_nTotalDroppedBytes
Total dropped bytes.
Definition: queue-disc.h:528
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)=0
This function actually enqueues a packet into the queue disc.
TracedCallback< Ptr< const QueueItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue-disc.h:540
Ptr< QueueDisc > GetQueueDisc(void) const
Get the queue disc attached to this class.
Definition: queue-disc.cc:111
int32_t Classify(Ptr< QueueDiscItem > item)
Classify a packet by calling the packet filters, one at a time, until either a filter able to classif...
Definition: queue-disc.cc:373
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:188
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:346
TracedCallback< Ptr< const QueueItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue-disc.h:544
QueueDiscClass is the base class for classes that are included in a queue disc.
Definition: queue-disc.h:130
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
Definition: queue-disc.h:516
Ptr< QueueDiscItem > Dequeue(void)
Request the queue discipline to extract a packet.
Definition: queue-disc.cc:427
uint32_t m_nTotalRequeuedBytes
Total requeued bytes.
Definition: queue-disc.h:530
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t GetTotalDroppedPackets(void) const
Get the total number of dropped packets.
Definition: queue-disc.cc:256
WakeMode GetWakeMode(void)
When setting up the wake callbacks on the netdevice queues, it is necessary to determine which queue ...
Definition: queue-disc.cc:387
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
Definition: queue-disc.h:531
uint32_t GetTotalDroppedBytes(void) const
Get the total amount of dropped bytes.
Definition: queue-disc.cc:263
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:475
bool m_running
The queue disc is performing multiple dequeue operations.
Definition: queue-disc.h:534
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: queue-disc.cc:71
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:305
virtual bool CheckConfig(void)=0
Check whether the current configuration is correct.
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue-disc.h:523
void Drop(Ptr< QueueDiscItem > item)
Drop a packet.
Definition: queue-disc.cc:393
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue-disc.h:522
void Requeue(Ptr< QueueDiscItem > p)
Modelled after the Linux function dev_requeue_skb (net/sched/sch_generic.c) Requeues a packet whose t...
Definition: queue-disc.cc:555
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
Definition: queue-disc.h:519
Ptr< NetDevice > m_device
The NetDevice on which this queue discipline is installed.
Definition: queue-disc.h:532
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:298
uint32_t GetTotalRequeuedBytes(void) const
Get the total amount of requeued bytes.
Definition: queue-disc.cc:277
void AddPacketFilter(Ptr< PacketFilter > filter)
Add a packet filter to the tail of the list of filters used to classify packets.
Definition: queue-disc.cc:332
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
Definition: queue-disc.h:405
virtual void InitializeParams(void)=0
Initialize parameters (if any) before the first packet is enqueued.
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue-disc.cc:127
uint16_t GetProtocol(void) const
Get the L3 protocol included in this item.
Definition: queue-disc.cc:53
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual Ptr< const QueueDiscItem > DoPeek(void) const =0
This function returns a copy of the next packet the queue disc will extract.
bool Restart(void)
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
Definition: queue-disc.cc:495
Address m_address
MAC destination address.
Definition: queue-disc.h:115
virtual ~QueueDiscClass()
Definition: queue-disc.h:139
a unique identifier for an interface.
Definition: type-id.h:58
Ptr< QueueDiscItem > DequeuePacket(void)
Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
Definition: queue-disc.cc:509
Ptr< NetDevice > GetNetDevice(void) const
Get the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:291
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue-disc.cc:83
uint32_t m_nTotalRequeuedPackets
Total requeued packets.
Definition: queue-disc.h:529
Ptr< const QueueDiscItem > Peek(void) const
Get a copy of the next packet the queue discipline will extract, without actually extracting the pack...
Definition: queue-disc.cc:447
virtual void AddHeader(void)=0
Add the header to the packet.
uint32_t m_nTotalDroppedPackets
Total dropped packets.
Definition: queue-disc.h:527
void SetNetDevice(Ptr< NetDevice > device)
Set the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:284
Ptr< QueueDiscClass > GetQueueDiscClass(uint32_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:360
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
Definition: queue-disc.cc:488
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
Definition: queue-disc.h:520
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:228