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/net-device.h"
27 #include "ns3/queue-item.h"
28 #include "ns3/queue-size.h"
29 #include <vector>
30 #include <map>
31 #include <functional>
32 #include <string>
33 #include "packet-filter.h"
34 
35 namespace ns3 {
36 
37 class QueueDisc;
38 template <typename Item> class Queue;
39 class NetDeviceQueueInterface;
40 
50 class QueueDiscClass : public Object {
51 public:
56  static TypeId GetTypeId (void);
57 
58  QueueDiscClass ();
59  virtual ~QueueDiscClass ();
60 
65  Ptr<QueueDisc> GetQueueDisc (void) const;
66 
71  void SetQueueDisc (Ptr<QueueDisc> qd);
72 
73 protected:
77  virtual void DoDispose (void);
78 
79 private:
81 };
82 
105 {
110 };
111 
112 
182 class QueueDisc : public Object {
183 public:
184 
186  struct Stats
187  {
195  uint64_t nTotalSentBytes;
209  std::map<std::string, uint32_t> nDroppedPacketsBeforeEnqueue;
213  std::map<std::string, uint32_t> nDroppedPacketsAfterDequeue;
219  std::map<std::string, uint64_t> nDroppedBytesBeforeEnqueue;
223  std::map<std::string, uint64_t> nDroppedBytesAfterDequeue;
231  std::map<std::string, uint32_t> nMarkedPackets;
235  std::map<std::string, uint64_t> nMarkedBytes;
236 
238  Stats ();
239 
245  uint32_t GetNDroppedPackets (std::string reason) const;
251  uint64_t GetNDroppedBytes (std::string reason) const;
257  uint32_t GetNMarkedPackets (std::string reason) const;
263  uint64_t GetNMarkedBytes (std::string reason) const;
268  void Print (std::ostream &os) const;
269  };
270 
275  static TypeId GetTypeId (void);
276 
282 
289 
290  virtual ~QueueDisc ();
291 
298  uint32_t GetNPackets (void) const;
299 
306  uint32_t GetNBytes (void) const;
307 
313  QueueSize GetMaxSize (void) const;
314 
323  bool SetMaxSize (QueueSize size);
324 
333  QueueSize GetCurrentSize (void);
334 
339  const Stats& GetStats (void);
340 
345  void SetNetDevice (Ptr<NetDevice> device);
346 
351  Ptr<NetDevice> GetNetDevice (void) const;
352 
357  virtual void SetQuota (const uint32_t quota);
358 
363  virtual uint32_t GetQuota (void) const;
364 
372  bool Enqueue (Ptr<QueueDiscItem> item);
373 
382 
391 
397  void Run (void);
398 
401 
407 
413  Ptr<InternalQueue> GetInternalQueue (std::size_t i) const;
414 
419  std::size_t GetNInternalQueues (void) const;
420 
425  void AddPacketFilter (Ptr<PacketFilter> filter);
426 
432  Ptr<PacketFilter> GetPacketFilter (std::size_t i) const;
433 
438  std::size_t GetNPacketFilters (void) const;
439 
444  void AddQueueDiscClass (Ptr<QueueDiscClass> qdClass);
445 
451  Ptr<QueueDiscClass> GetQueueDiscClass (std::size_t i) const;
452 
457  std::size_t GetNQueueDiscClasses (void) const;
458 
467  int32_t Classify (Ptr<QueueDiscItem> item);
468 
474  enum WakeMode
475  {
476  WAKE_ROOT = 0x00,
477  WAKE_CHILD = 0x01
478  };
479 
491  virtual WakeMode GetWakeMode (void) const;
492 
493  // Reasons for dropping packets
494  static constexpr const char* INTERNAL_QUEUE_DROP = "Dropped by internal queue";
495  static constexpr const char* CHILD_QUEUE_DISC_DROP = "(Dropped by child queue disc) ";
496 
497 protected:
501  virtual void DoDispose (void);
502 
510  void DoInitialize (void);
511 
520  void DropBeforeEnqueue (Ptr<const QueueDiscItem> item, const char* reason);
521 
530  void DropAfterDequeue (Ptr<const QueueDiscItem> item, const char* reason);
531 
539  bool Mark (Ptr<QueueDiscItem> item, const char* reason);
540 
541 private:
548  QueueDisc (const QueueDisc &o);
549 
557  QueueDisc &operator = (const QueueDisc &o);
558 
564  virtual bool DoEnqueue (Ptr<QueueDiscItem> item) = 0;
565 
570  virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
571 
591  virtual Ptr<const QueueDiscItem> DoPeek (void);
592 
599  virtual bool CheckConfig (void) = 0;
600 
604  virtual void InitializeParams (void) = 0;
605 
610  bool RunBegin (void);
611 
616  void RunEnd (void);
617 
623  bool Restart (void);
624 
630 
636  void Requeue (Ptr<QueueDiscItem> item);
637 
645  bool Transmit (Ptr<QueueDiscItem> item);
646 
653 
660 
661  static const uint32_t DEFAULT_QUOTA = 64;
662 
663  std::vector<Ptr<InternalQueue> > m_queues;
664  std::vector<Ptr<PacketFilter> > m_filters;
665  std::vector<Ptr<QueueDiscClass> > m_classes;
666 
671 
673  uint32_t m_quota;
676  bool m_running;
678  bool m_peeked;
682 
697 
699  typedef std::function<void (Ptr<const QueueDiscItem>)> InternalQueueDropFunctor;
701  typedef std::function<void (Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscDropFunctor;
702 
711 };
712 
720 std::ostream& operator<< (std::ostream& os, const QueueDisc::Stats &stats);
721 
722 } // namespace ns3
723 
724 #endif /* QueueDisc */
uint32_t nTotalDequeuedPackets
Total dequeued packets.
Definition: queue-disc.h:201
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:186
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract.
Definition: queue-disc.cc:913
Stats()
constructor
Definition: queue-disc.cc:90
Ptr< NetDevice > GetNetDevice(void) const
Get the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:546
TracedCallback< Time > m_sojourn
Sojourn time of the latest dequeued packet.
Definition: queue-disc.h:669
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:440
uint32_t nTotalMarkedPackets
Total marked packets.
Definition: queue-disc.h:229
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
Definition: queue-disc.h:677
std::map< std::string, uint32_t > nDroppedPacketsAfterDequeue
Packets dropped after dequeue, for each reason.
Definition: queue-disc.h:213
Class for representing queue sizes.
Definition: queue-size.h:94
uint32_t nTotalDroppedPackets
Total dropped packets.
Definition: queue-disc.h:205
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:712
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:844
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 nTotalRequeuedPackets
Total requeued packets.
Definition: queue-disc.h:225
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:801
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:80
bool m_prohibitChangeMode
True if changing mode is prohibited.
Definition: queue-disc.h:681
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:109
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
Definition: queue-disc.h:708
uint32_t nTotalSentPackets
Total sent packets – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:193
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:696
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:447
QueueSize m_maxSize
max queue size
Definition: queue-disc.h:670
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:182
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:701
TracedCallback< Ptr< const QueueDiscItem >, const char *> m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
Definition: queue-disc.h:694
Used by queue discs with single child queue disc.
Definition: queue-disc.h:107
uint64_t GetNMarkedBytes(std::string reason) const
Get the amount of bytes marked for the given reason.
Definition: queue-disc.cc:168
uint32_t nTotalMarkedBytes
Total marked bytes.
Definition: queue-disc.h:233
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
Definition: queue-disc.h:207
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:560
bool m_peeked
A packet was dequeued because Peek was called.
Definition: queue-disc.h:678
static constexpr const char * CHILD_QUEUE_DISC_DROP
Packet dropped by a child queue disc.
Definition: queue-disc.h:495
virtual Ptr< const QueueDiscItem > DoPeek(void)
Return a copy of the next packet the queue disc will extract.
Definition: queue-disc.cc:920
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:199
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:679
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:675
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
Definition: queue-disc.h:704
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:587
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue-disc.h:686
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
Definition: queue-disc.cc:113
Ptr< PacketFilter > GetPacketFilter(std::size_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:607
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:195
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:938
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:223
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:1055
uint64_t nTotalDroppedBytesBeforeEnqueue
Total bytes dropped before enqueue.
Definition: queue-disc.h:217
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
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:645
std::map< std::string, uint32_t > nMarkedPackets
Marked packets, for each reason.
Definition: queue-disc.h:231
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
Definition: queue-disc.h:706
QueueDiscClass is the base class for classes that are included in a queue disc.
Definition: queue-disc.h:50
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
Definition: queue-disc.h:661
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any...
Definition: queue-disc.cc:879
uint64_t nTotalRequeuedBytes
Total requeued bytes.
Definition: queue-disc.h:227
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:211
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:652
uint32_t nTotalReceivedPackets
Total received packets.
Definition: queue-disc.h:189
TracedCallback< Ptr< const QueueDiscItem >, const char *> m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
Definition: queue-disc.h:692
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
Definition: queue-disc.h:673
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
Definition: queue-disc.cc:155
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
Definition: queue-disc.h:663
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:959
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue-disc.h:684
bool m_running
The queue disc is performing multiple dequeue operations.
Definition: queue-disc.h:676
uint64_t nTotalReceivedBytes
Total received bytes.
Definition: queue-disc.h:191
uint64_t GetNDroppedBytes(std::string reason) const
Get the amount of bytes dropped for the given reason.
Definition: queue-disc.cc:134
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:668
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:454
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:1041
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:104
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue-disc.h:667
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:664
Used by queue discs with single internal queue.
Definition: queue-disc.h:106
void Print(std::ostream &os) const
Print the statistics.
Definition: queue-disc.cc:181
uint64_t nTotalDequeuedBytes
Total dequeued bytes.
Definition: queue-disc.h:203
std::map< std::string, uint64_t > nDroppedBytesBeforeEnqueue
Bytes dropped before enqueue, for each reason.
Definition: queue-disc.h:219
Used by queue discs with multiple internal queues/child queue discs.
Definition: queue-disc.h:108
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
Definition: queue-disc.h:221
Introspection did not find any typical Config paths.
QueueDiscSizePolicy m_sizePolicy
The queue disc size policy.
Definition: queue-disc.h:680
Queue< QueueDiscItem > InternalQueue
Internal queues store QueueDiscItem objects.
Definition: queue-disc.h:400
Ptr< NetDevice > m_device
The NetDevice on which this queue discipline is installed.
Definition: queue-disc.h:674
std::size_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:614
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:710
uint32_t nTotalEnqueuedPackets
Total enqueued packets.
Definition: queue-disc.h:197
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:699
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:751
Stats m_stats
The collected statistics.
Definition: queue-disc.h:672
uint64_t nTotalDroppedBytes
Total dropped bytes.
Definition: queue-disc.h:215
std::map< std::string, uint64_t > nMarkedBytes
Marked bytes, for each reason.
Definition: queue-disc.h:235
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue-disc.h:690
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
Definition: queue-disc.h:474
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
Ptr< QueueDisc > GetQueueDisc(void) const
Get the queue disc attached to this class.
Definition: queue-disc.cc:76
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:672
bool Restart(void)
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
Definition: queue-disc.cc:979
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:993
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:688
void SetNetDevice(Ptr< NetDevice > device)
Set the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:539
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
Definition: queue-disc.h:494
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
Definition: queue-disc.cc:972
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
Definition: queue-disc.h:665
std::size_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:594
std::map< std::string, uint32_t > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
Definition: queue-disc.h:209