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/net-device.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 
344  void SetNetDevice (Ptr<NetDevice> device);
345 
350  Ptr<NetDevice> GetNetDevice (void) const;
351 
356  virtual void SetQuota (const uint32_t quota);
357 
362  virtual uint32_t GetQuota (void) const;
363 
371  bool Enqueue (Ptr<QueueDiscItem> item);
372 
380 
388 
396 
402  void Run (void);
403 
406 
412 
418  Ptr<InternalQueue> GetInternalQueue (uint32_t i) const;
419 
424  uint32_t GetNInternalQueues (void) const;
425 
430  void AddPacketFilter (Ptr<PacketFilter> filter);
431 
437  Ptr<PacketFilter> GetPacketFilter (uint32_t i) const;
438 
443  uint32_t GetNPacketFilters (void) const;
444 
449  void AddQueueDiscClass (Ptr<QueueDiscClass> qdClass);
450 
456  Ptr<QueueDiscClass> GetQueueDiscClass (uint32_t i) const;
457 
462  uint32_t GetNQueueDiscClasses (void) const;
463 
472  int32_t Classify (Ptr<QueueDiscItem> item);
473 
479  enum WakeMode
480  {
481  WAKE_ROOT = 0x00,
482  WAKE_CHILD = 0x01
483  };
484 
496  virtual WakeMode GetWakeMode (void) const;
497 
498  // Reasons for dropping packets
499  static constexpr const char* INTERNAL_QUEUE_DROP = "Dropped by internal queue";
500  static constexpr const char* CHILD_QUEUE_DISC_DROP = "(Dropped by child queue disc) ";
501 
502 protected:
506  virtual void DoDispose (void);
507 
515  void DoInitialize (void);
516 
525  void DropBeforeEnqueue (Ptr<const QueueDiscItem> item, const char* reason);
526 
535  void DropAfterDequeue (Ptr<const QueueDiscItem> item, const char* reason);
536 
544  bool Mark (Ptr<QueueDiscItem> item, const char* reason);
545 
560 
561 private:
568  QueueDisc (const QueueDisc &o);
569 
577  QueueDisc &operator = (const QueueDisc &o);
578 
584  virtual bool DoEnqueue (Ptr<QueueDiscItem> item) = 0;
585 
590  virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
591 
596  virtual Ptr<const QueueDiscItem> DoPeek (void) = 0;
597 
604  virtual bool CheckConfig (void) = 0;
605 
609  virtual void InitializeParams (void) = 0;
610 
615  bool RunBegin (void);
616 
621  void RunEnd (void);
622 
628  bool Restart (void);
629 
635 
641  void Requeue (Ptr<QueueDiscItem> item);
642 
650  bool Transmit (Ptr<QueueDiscItem> item);
651 
658 
665 
666  static const uint32_t DEFAULT_QUOTA = 64;
667 
668  std::vector<Ptr<InternalQueue> > m_queues;
669  std::vector<Ptr<PacketFilter> > m_filters;
670  std::vector<Ptr<QueueDiscClass> > m_classes;
671 
676 
678  uint32_t m_quota;
681  bool m_running;
686 
701 
703  typedef std::function<void (Ptr<const QueueDiscItem>)> InternalQueueDropFunctor;
705  typedef std::function<void (Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscDropFunctor;
706 
715 };
716 
724 std::ostream& operator<< (std::ostream& os, const QueueDisc::Stats &stats);
725 
726 } // namespace ns3
727 
728 #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, without actually extracting the pack...
Definition: queue-disc.cc:873
TracedValue< Time > m_sojourn
Sojourn time of the latest dequeued packet.
Definition: queue-disc.h:674
Stats()
constructor
Definition: queue-disc.cc:90
uint32_t nTotalMarkedPackets
Total marked packets.
Definition: queue-disc.h:228
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:652
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
Definition: queue-disc.h:682
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:620
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:704
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:825
virtual ~QueueDiscClass()
Definition: queue-disc.cc:62
virtual ~QueueDisc()
Definition: queue-disc.cc:375
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:42
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:447
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:782
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:523
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:685
Forward calls to a chain of Callback.
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:68
void SetQueueDisc(Ptr< QueueDisc > qd)
Set the queue disc attached to this class.
Definition: queue-disc.cc:83
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:712
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:700
QueueSize m_maxSize
max queue size
Definition: queue-disc.h:675
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:705
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
Definition: queue-disc.h:479
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
Definition: queue-disc.h:698
Used by queue discs with single child queue disc.
Definition: queue-disc.h:106
Ptr< QueueDiscItem > DequeuePeeked(void)
Extract from the queue disc the packet that has been dequeued by calling PeekDequeued.
Definition: queue-disc.cc:892
uint32_t nTotalMarkedBytes
Total marked bytes.
Definition: queue-disc.h:232
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
Definition: queue-disc.h:206
Ptr< InternalQueue > GetInternalQueue(uint32_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:587
uint64_t GetNDroppedBytes(std::string reason) const
Get the amount of bytes dropped for the given reason.
Definition: queue-disc.cc:134
static constexpr const char * CHILD_QUEUE_DISC_DROP
Packet dropped by a child queue disc.
Definition: queue-disc.h:500
virtual Ptr< const QueueDiscItem > DoPeek(void)=0
This function returns a copy of the next packet the queue disc will extract.
uint32_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:594
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:567
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:678
std::string m_childQueueDiscDropMsg
Reason why a packet was dropped by a child queue disc.
Definition: queue-disc.h:683
void DoInitialize(void)
Check whether the configuration is correct and initialize parameters.
Definition: queue-disc.cc:394
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
Definition: queue-disc.h:680
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
Definition: queue-disc.h:708
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue-disc.h:690
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:325
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets...
Definition: queue-disc.cc:911
Ptr< PacketFilter > GetPacketFilter(uint32_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:607
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:421
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:1020
Ptr< QueueDisc > GetQueueDisc(void) const
Get the queue disc attached to this class.
Definition: queue-disc.cc:76
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:658
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:381
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:614
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
Definition: queue-disc.cc:113
std::map< std::string, uint32_t > nMarkedPackets
Marked packets, for each reason.
Definition: queue-disc.h:230
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:672
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
Definition: queue-disc.h:710
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:666
Ptr< QueueDiscItem > Dequeue(void)
Request the queue discipline to extract a packet.
Definition: queue-disc.cc:860
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.
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:696
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
Definition: queue-disc.h:678
uint64_t GetNMarkedBytes(std::string reason) const
Get the amount of bytes marked for the given reason.
Definition: queue-disc.cc:168
void Print(std::ostream &os) const
Print the statistics.
Definition: queue-disc.cc:181
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
Definition: queue-disc.h:668
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:932
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue-disc.h:688
bool m_running
The queue disc is performing multiple dequeue operations.
Definition: queue-disc.h:681
uint64_t nTotalReceivedBytes
Total received bytes.
Definition: queue-disc.h:190
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:560
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:673
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:1006
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:672
Ptr< const QueueDiscItem > PeekDequeued(void)
Dequeue a packet and retain it in the queue disc as a requeued packet.
Definition: queue-disc.cc:880
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue. ...
Definition: queue-disc.cc:690
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
Definition: queue-disc.h:669
Used by queue discs with single internal queue.
Definition: queue-disc.h:105
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:684
Queue< QueueDiscItem > InternalQueue
Internal queues store QueueDiscItem objects.
Definition: queue-disc.h:405
Ptr< NetDevice > m_device
The NetDevice on which this queue discipline is installed.
Definition: queue-disc.h:679
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:553
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet after dequeue.
Definition: queue-disc.h:714
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:600
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:703
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:482
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:743
Stats m_stats
The collected statistics.
Definition: queue-disc.h:677
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:694
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:266
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
Definition: queue-disc.cc:155
A base class which provides memory management and object aggregation.
Definition: object.h:87
bool Restart(void)
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
Definition: queue-disc.cc:952
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:966
Ptr< NetDevice > GetNetDevice(void) const
Get the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:546
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue-disc.cc:43
TracedCallback< Ptr< const QueueDiscItem > > m_traceRequeue
Traced callback: fired when a packet is requeued.
Definition: queue-disc.h:692
void SetNetDevice(Ptr< NetDevice > device)
Set the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:539
Ptr< QueueDiscClass > GetQueueDiscClass(uint32_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:645
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
Definition: queue-disc.h:499
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
Definition: queue-disc.cc:945
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:454
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
Definition: queue-disc.h:670
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:440
std::map< std::string, uint32_t > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
Definition: queue-disc.h:208