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/traced-callback.h"
26 #include "ns3/queue-item.h"
27 #include "ns3/queue-size.h"
28 #include <vector>
29 #include <map>
30 #include <functional>
31 #include <string>
32 #include "packet-filter.h"
33 
34 namespace ns3 {
35 
36 class QueueDisc;
37 template <typename Item> class Queue;
38 class NetDeviceQueueInterface;
39 
49 class QueueDiscClass : public Object {
50 public:
55  static TypeId GetTypeId (void);
56 
57  QueueDiscClass ();
58  virtual ~QueueDiscClass ();
59 
64  Ptr<QueueDisc> GetQueueDisc (void) const;
65 
70  void SetQueueDisc (Ptr<QueueDisc> qd);
71 
72 protected:
76  virtual void DoDispose (void);
77 
78 private:
80 };
81 
104 {
109 };
110 
111 
181 class QueueDisc : public Object {
182 public:
183 
185  struct Stats
186  {
194  uint64_t nTotalSentBytes;
208  std::map<std::string, uint32_t> nDroppedPacketsBeforeEnqueue;
212  std::map<std::string, uint32_t> nDroppedPacketsAfterDequeue;
218  std::map<std::string, uint64_t> nDroppedBytesBeforeEnqueue;
222  std::map<std::string, uint64_t> nDroppedBytesAfterDequeue;
230  std::map<std::string, uint32_t> nMarkedPackets;
234  std::map<std::string, uint64_t> nMarkedBytes;
235 
237  Stats ();
238 
244  uint32_t GetNDroppedPackets (std::string reason) const;
250  uint64_t GetNDroppedBytes (std::string reason) const;
256  uint32_t GetNMarkedPackets (std::string reason) const;
262  uint64_t GetNMarkedBytes (std::string reason) const;
267  void Print (std::ostream &os) const;
268  };
269 
274  static TypeId GetTypeId (void);
275 
281 
288 
289  virtual ~QueueDisc ();
290 
297  uint32_t GetNPackets (void) const;
298 
305  uint32_t GetNBytes (void) const;
306 
312  QueueSize GetMaxSize (void) const;
313 
322  bool SetMaxSize (QueueSize size);
323 
332  QueueSize GetCurrentSize (void);
333 
338  const Stats& GetStats (void);
339 
347 
355 
357  typedef std::function<void (Ptr<QueueDiscItem>)> SendCallback;
358 
365  void SetSendCallback (SendCallback func);
366 
373  SendCallback GetSendCallback (void) const;
374 
379  virtual void SetQuota (const uint32_t quota);
380 
385  virtual uint32_t GetQuota (void) const;
386 
394  bool Enqueue (Ptr<QueueDiscItem> item);
395 
404 
413 
419  void Run (void);
420 
423 
429 
435  Ptr<InternalQueue> GetInternalQueue (std::size_t i) const;
436 
441  std::size_t GetNInternalQueues (void) const;
442 
447  void AddPacketFilter (Ptr<PacketFilter> filter);
448 
454  Ptr<PacketFilter> GetPacketFilter (std::size_t i) const;
455 
460  std::size_t GetNPacketFilters (void) const;
461 
466  void AddQueueDiscClass (Ptr<QueueDiscClass> qdClass);
467 
473  Ptr<QueueDiscClass> GetQueueDiscClass (std::size_t i) const;
474 
479  std::size_t GetNQueueDiscClasses (void) const;
480 
489  int32_t Classify (Ptr<QueueDiscItem> item);
490 
496  enum WakeMode
497  {
498  WAKE_ROOT = 0x00,
499  WAKE_CHILD = 0x01
500  };
501 
513  virtual WakeMode GetWakeMode (void) const;
514 
515  // Reasons for dropping packets
516  static constexpr const char* INTERNAL_QUEUE_DROP = "Dropped by internal queue";
517  static constexpr const char* CHILD_QUEUE_DISC_DROP = "(Dropped by child queue disc) ";
518 
519 protected:
523  virtual void DoDispose (void);
524 
534  void DoInitialize (void);
535 
544  void DropBeforeEnqueue (Ptr<const QueueDiscItem> item, const char* reason);
545 
554  void DropAfterDequeue (Ptr<const QueueDiscItem> item, const char* reason);
555 
563  bool Mark (Ptr<QueueDiscItem> item, const char* reason);
564 
565 private:
572  QueueDisc (const QueueDisc &o);
573 
581  QueueDisc &operator = (const QueueDisc &o);
582 
588  virtual bool DoEnqueue (Ptr<QueueDiscItem> item) = 0;
589 
594  virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
595 
615  virtual Ptr<const QueueDiscItem> DoPeek (void);
616 
628  virtual bool CheckConfig (void) = 0;
629 
636  virtual void InitializeParams (void) = 0;
637 
642  bool RunBegin (void);
643 
648  void RunEnd (void);
649 
655  bool Restart (void);
656 
662 
668  void Requeue (Ptr<QueueDiscItem> item);
669 
677  bool Transmit (Ptr<QueueDiscItem> item);
678 
685 
692 
693  static const uint32_t DEFAULT_QUOTA = 64;
694 
695  std::vector<Ptr<InternalQueue> > m_queues;
696  std::vector<Ptr<PacketFilter> > m_filters;
697  std::vector<Ptr<QueueDiscClass> > m_classes;
698 
703 
705  uint32_t m_quota;
708  bool m_running;
710  bool m_peeked;
714 
729 
731  typedef std::function<void (Ptr<const QueueDiscItem>)> InternalQueueDropFunctor;
733  typedef std::function<void (Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscDropFunctor;
734 
743 };
744 
752 std::ostream& operator<< (std::ostream& os, const QueueDisc::Stats &stats);
753 
754 } // namespace ns3
755 
756 #endif /* QueueDisc */
uint32_t nTotalDequeuedPackets
Total dequeued packets.
Definition: queue-disc.h:200
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:185
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract.
Definition: queue-disc.cc:922
Stats()
constructor
Definition: queue-disc.cc:87
TracedCallback< Time > m_sojourn
Sojourn time of the latest dequeued packet.
Definition: queue-disc.h:701
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:435
uint32_t nTotalMarkedPackets
Total marked packets.
Definition: queue-disc.h:228
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
Definition: queue-disc.h:709
std::map< std::string, uint32_t > nDroppedPacketsAfterDequeue
Packets dropped after dequeue, for each reason.
Definition: queue-disc.h:212
Class for representing queue sizes.
Definition: queue-size.h:94
uint32_t nTotalDroppedPackets
Total dropped packets.
Definition: queue-disc.h:204
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
Definition: queue-disc.cc:629
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:721
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:853
virtual ~QueueDiscClass()
Definition: queue-disc.cc:59
virtual ~QueueDisc()
Definition: queue-disc.cc:372
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:42
uint32_t nTotalRequeuedPackets
Total requeued packets.
Definition: queue-disc.h:224
bool Mark(Ptr< QueueDiscItem > item, const char *reason)
Marks the given packet and, if successful, updates the counters associated with the given reason...
Definition: queue-disc.cc:810
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:518
Ptr< QueueDisc > m_queueDisc
Queue disc attached to this class.
Definition: queue-disc.h:79
bool m_prohibitChangeMode
True if changing mode is prohibited.
Definition: queue-disc.h:713
Forward calls to a chain of Callback.
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:65
void SetQueueDisc(Ptr< QueueDisc > qd)
Set the queue disc attached to this class.
Definition: queue-disc.cc:80
Used by queue discs with unlimited size.
Definition: queue-disc.h:108
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
Definition: queue-disc.h:740
uint32_t nTotalSentPackets
Total sent packets – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:192
virtual Ptr< QueueDiscItem > DoDequeue(void)=0
This function actually extracts a packet from the queue disc.
TracedCallback< Ptr< const QueueDiscItem >, const char *> m_traceMark
Traced callback: fired when a packet is marked.
Definition: queue-disc.h:728
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:442
QueueSize m_maxSize
max queue size
Definition: queue-disc.h:702
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:181
std::function< void(Ptr< const QueueDiscItem >, const char *)> ChildQueueDiscDropFunctor
Type for the function objects notifying that a packet has been dropped by a child queue disc...
Definition: queue-disc.h:733
TracedCallback< Ptr< const QueueDiscItem >, const char *> m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
Definition: queue-disc.h:726
Ptr< NetDeviceQueueInterface > GetNetDeviceQueueInterface(void) const
Definition: queue-disc.cc:541
Used by queue discs with single child queue disc.
Definition: queue-disc.h:106
uint64_t GetNMarkedBytes(std::string reason) const
Get the amount of bytes marked for the given reason.
Definition: queue-disc.cc:165
uint32_t nTotalMarkedBytes
Total marked bytes.
Definition: queue-disc.h:232
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
Definition: queue-disc.h:206
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:569
bool m_peeked
A packet was dequeued because Peek was called.
Definition: queue-disc.h:710
static constexpr const char * CHILD_QUEUE_DISC_DROP
Packet dropped by a child queue disc.
Definition: queue-disc.h:517
virtual Ptr< const QueueDiscItem > DoPeek(void)
Return a copy of the next packet the queue disc will extract.
Definition: queue-disc.cc:929
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:576
uint64_t nTotalEnqueuedBytes
Total enqueued bytes.
Definition: queue-disc.h:198
void PacketEnqueued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet enqueue. ...
Definition: queue-disc.cc:687
std::string m_childQueueDiscDropMsg
Reason why a packet was dropped by a child queue disc.
Definition: queue-disc.h:711
void DoInitialize(void)
Check whether the configuration is correct and initialize parameters.
Definition: queue-disc.cc:395
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
Definition: queue-disc.h:706
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
Definition: queue-disc.h:736
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:596
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue-disc.h:718
SendCallback m_send
Callback used to send a packet to the receiving object.
Definition: queue-disc.h:707
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
Definition: queue-disc.cc:110
Ptr< PacketFilter > GetPacketFilter(std::size_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:616
QueueDisc & operator=(const QueueDisc &o)
Assignment operator.
uint64_t nTotalSentBytes
Total sent bytes – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:194
QueueDisc(QueueDiscSizePolicy policy=QueueDiscSizePolicy::SINGLE_INTERNAL_QUEUE)
Constructor.
Definition: queue-disc.cc:322
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets...
Definition: queue-disc.cc:947
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)=0
This function actually enqueues a packet into the queue disc.
const Stats & GetStats(void)
Retrieve all the collected statistics.
Definition: queue-disc.cc:416
std::map< std::string, uint64_t > nDroppedBytesAfterDequeue
Bytes dropped after dequeue, for each reason.
Definition: queue-disc.h:222
bool Transmit(Ptr< QueueDiscItem > item)
Modelled after the Linux function sch_direct_xmit (net/sched/sch_generic.c) Sends a packet to the dev...
Definition: queue-disc.cc:1065
uint64_t nTotalDroppedBytesBeforeEnqueue
Total bytes dropped before enqueue.
Definition: queue-disc.h:216
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:667
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:378
std::function< void(Ptr< QueueDiscItem >)> SendCallback
Callback invoked to send a packet to the receiving object when Run is called.
Definition: queue-disc.h:357
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:654
std::map< std::string, uint32_t > nMarkedPackets
Marked packets, for each reason.
Definition: queue-disc.h:230
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
Definition: queue-disc.h:738
QueueDiscClass is the base class for classes that are included in a queue disc.
Definition: queue-disc.h:49
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
Definition: queue-disc.h:693
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any...
Definition: queue-disc.cc:888
uint64_t nTotalRequeuedBytes
Total requeued bytes.
Definition: queue-disc.h:226
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
uint32_t nTotalDroppedPacketsAfterDequeue
Total packets dropped after dequeue.
Definition: queue-disc.h:210
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:661
uint32_t nTotalReceivedPackets
Total received packets.
Definition: queue-disc.h:188
TracedCallback< Ptr< const QueueDiscItem >, const char *> m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
Definition: queue-disc.h:724
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
Definition: queue-disc.h:705
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
Definition: queue-disc.cc:152
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
Definition: queue-disc.h:695
SendCallback GetSendCallback(void) const
Definition: queue-disc.cc:555
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:968
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue-disc.h:716
bool m_running
The queue disc is performing multiple dequeue operations.
Definition: queue-disc.h:708
uint64_t nTotalReceivedBytes
Total received bytes.
Definition: queue-disc.h:190
uint64_t GetNDroppedBytes(std::string reason) const
Get the amount of bytes dropped for the given reason.
Definition: queue-disc.cc:131
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:700
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:449
void Requeue(Ptr< QueueDiscItem > item)
Modelled after the Linux function dev_requeue_skb (net/sched/sch_generic.c) Requeues a packet whose t...
Definition: queue-disc.cc:1051
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:103
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue-disc.h:699
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue. ...
Definition: queue-disc.cc:699
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
Definition: queue-disc.h:696
Used by queue discs with single internal queue.
Definition: queue-disc.h:105
void Print(std::ostream &os) const
Print the statistics.
Definition: queue-disc.cc:178
uint64_t nTotalDequeuedBytes
Total dequeued bytes.
Definition: queue-disc.h:202
std::map< std::string, uint64_t > nDroppedBytesBeforeEnqueue
Bytes dropped before enqueue, for each reason.
Definition: queue-disc.h:218
Used by queue discs with multiple internal queues/child queue discs.
Definition: queue-disc.h:107
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
Definition: queue-disc.h:220
Introspection did not find any typical Config paths.
QueueDiscSizePolicy m_sizePolicy
The queue disc size policy.
Definition: queue-disc.h:712
Queue< QueueDiscItem > InternalQueue
Internal queues store QueueDiscItem objects.
Definition: queue-disc.h:422
std::size_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:623
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:562
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet after dequeue.
Definition: queue-disc.h:742
uint32_t nTotalEnqueuedPackets
Total enqueued packets.
Definition: queue-disc.h:196
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:609
std::function< void(Ptr< const QueueDiscItem >)> InternalQueueDropFunctor
Type for the function objects notifying that a packet has been dropped by an internal queue...
Definition: queue-disc.h:731
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:477
void DropAfterDequeue(Ptr< const QueueDiscItem > item, const char *reason)
Perform the actions required when the queue disc is notified of a packet dropped after dequeue...
Definition: queue-disc.cc:760
Stats m_stats
The collected statistics.
Definition: queue-disc.h:704
uint64_t nTotalDroppedBytes
Total dropped bytes.
Definition: queue-disc.h:214
std::map< std::string, uint64_t > nMarkedBytes
Marked bytes, for each reason.
Definition: queue-disc.h:234
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue-disc.h:722
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
Definition: queue-disc.h:496
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:263
Ptr< QueueDisc > GetQueueDisc(void) const
Get the queue disc attached to this class.
Definition: queue-disc.cc:73
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual WakeMode GetWakeMode(void) const
When setting up the wake callbacks on the netdevice queues, it is necessary to determine which queue ...
Definition: queue-disc.cc:681
bool Restart(void)
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
Definition: queue-disc.cc:988
a unique identifier for an interface.
Definition: type-id.h:58
void SetSendCallback(SendCallback func)
Definition: queue-disc.cc:548
Ptr< QueueDiscItem > DequeuePacket(void)
Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
Definition: queue-disc.cc:1002
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue-disc.cc:40
TracedCallback< Ptr< const QueueDiscItem > > m_traceRequeue
Traced callback: fired when a packet is requeued.
Definition: queue-disc.h:720
void SetNetDeviceQueueInterface(Ptr< NetDeviceQueueInterface > ndqi)
Definition: queue-disc.cc:534
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
Definition: queue-disc.h:516
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
Definition: queue-disc.cc:981
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
Definition: queue-disc.h:697
std::size_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:603
std::map< std::string, uint32_t > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
Definition: queue-disc.h:208