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 <vector>
28 #include <map>
29 #include <functional>
30 #include <string>
31 #include "packet-filter.h"
32 
33 namespace ns3 {
34 
35 class QueueDisc;
36 template <typename Item> class Queue;
37 class NetDeviceQueueInterface;
38 
48 class QueueDiscClass : public Object {
49 public:
54  static TypeId GetTypeId (void);
55 
56  QueueDiscClass ();
57  virtual ~QueueDiscClass ();
58 
63  Ptr<QueueDisc> GetQueueDisc (void) const;
64 
69  void SetQueueDisc (Ptr<QueueDisc> qd);
70 
71 protected:
75  virtual void DoDispose (void);
76 
77 private:
79 };
80 
81 
151 class QueueDisc : public Object {
152 public:
153 
155  struct Stats
156  {
164  uint64_t nTotalSentBytes;
178  std::map<std::string, uint32_t> nDroppedPacketsBeforeEnqueue;
182  std::map<std::string, uint32_t> nDroppedPacketsAfterDequeue;
188  std::map<std::string, uint64_t> nDroppedBytesBeforeEnqueue;
192  std::map<std::string, uint64_t> nDroppedBytesAfterDequeue;
200  std::map<std::string, uint32_t> nMarkedPackets;
204  std::map<std::string, uint64_t> nMarkedBytes;
205 
207  Stats ();
208 
214  uint32_t GetNDroppedPackets (std::string reason) const;
220  uint64_t GetNDroppedBytes (std::string reason) const;
226  uint32_t GetNMarkedPackets (std::string reason) const;
232  uint64_t GetNMarkedBytes (std::string reason) const;
237  void Print (std::ostream &os) const;
238  };
239 
244  static TypeId GetTypeId (void);
245 
246  QueueDisc ();
247  virtual ~QueueDisc ();
248 
255  uint32_t GetNPackets (void) const;
256 
263  uint32_t GetNBytes (void) const;
264 
269  const Stats& GetStats (void);
270 
275  void SetNetDevice (Ptr<NetDevice> device);
276 
281  Ptr<NetDevice> GetNetDevice (void) const;
282 
287  virtual void SetQuota (const uint32_t quota);
288 
293  virtual uint32_t GetQuota (void) const;
294 
302  bool Enqueue (Ptr<QueueDiscItem> item);
303 
311 
318  Ptr<const QueueDiscItem> Peek (void) const;
319 
325  void Run (void);
326 
329 
335 
341  Ptr<InternalQueue> GetInternalQueue (uint32_t i) const;
342 
347  uint32_t GetNInternalQueues (void) const;
348 
353  void AddPacketFilter (Ptr<PacketFilter> filter);
354 
360  Ptr<PacketFilter> GetPacketFilter (uint32_t i) const;
361 
366  uint32_t GetNPacketFilters (void) const;
367 
372  void AddQueueDiscClass (Ptr<QueueDiscClass> qdClass);
373 
379  Ptr<QueueDiscClass> GetQueueDiscClass (uint32_t i) const;
380 
385  uint32_t GetNQueueDiscClasses (void) const;
386 
395  int32_t Classify (Ptr<QueueDiscItem> item);
396 
402  enum WakeMode
403  {
404  WAKE_ROOT = 0x00,
405  WAKE_CHILD = 0x01
406  };
407 
419  virtual WakeMode GetWakeMode (void) const;
420 
421  // Reasons for dropping packets
422  static constexpr const char* INTERNAL_QUEUE_DROP = "Dropped by internal queue";
423  static constexpr const char* CHILD_QUEUE_DISC_DROP = "(Dropped by child queue disc) ";
424 
425 protected:
429  virtual void DoDispose (void);
430 
438  void DoInitialize (void);
439 
448  void DropBeforeEnqueue (Ptr<const QueueDiscItem> item, const char* reason);
449 
458  void DropAfterDequeue (Ptr<const QueueDiscItem> item, const char* reason);
459 
467  bool Mark (Ptr<QueueDiscItem> item, const char* reason);
468 
469 private:
476  QueueDisc (const QueueDisc &o);
477 
485  QueueDisc &operator = (const QueueDisc &o);
486 
492  virtual bool DoEnqueue (Ptr<QueueDiscItem> item) = 0;
493 
498  virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
499 
504  virtual Ptr<const QueueDiscItem> DoPeek (void) const = 0;
505 
512  virtual bool CheckConfig (void) = 0;
513 
517  virtual void InitializeParams (void) = 0;
518 
523  bool RunBegin (void);
524 
529  void RunEnd (void);
530 
536  bool Restart (void);
537 
543 
549  void Requeue (Ptr<QueueDiscItem> item);
550 
558  bool Transmit (Ptr<QueueDiscItem> item);
559 
566 
573 
574  static const uint32_t DEFAULT_QUOTA = 64;
575 
576  std::vector<Ptr<InternalQueue> > m_queues;
577  std::vector<Ptr<PacketFilter> > m_filters;
578  std::vector<Ptr<QueueDiscClass> > m_classes;
579 
583 
585  uint32_t m_quota;
588  bool m_running;
591 
606 
608  typedef std::function<void (Ptr<const QueueDiscItem>)> InternalQueueDropFunctor;
610  typedef std::function<void (Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscDropFunctor;
611 
620 };
621 
629 std::ostream& operator<< (std::ostream& os, const QueueDisc::Stats &stats);
630 
631 } // namespace ns3
632 
633 #endif /* QueueDisc */
uint32_t nTotalDequeuedPackets
Total dequeued packets.
Definition: queue-disc.h:170
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:155
TracedValue< Time > m_sojourn
Sojourn time of the latest dequeued packet.
Definition: queue-disc.h:582
Stats()
constructor
Definition: queue-disc.cc:90
uint32_t nTotalMarkedPackets
Total marked packets.
Definition: queue-disc.h:198
uint32_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:557
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
Definition: queue-disc.h:589
std::map< std::string, uint32_t > nDroppedPacketsAfterDequeue
Packets dropped after dequeue, for each reason.
Definition: queue-disc.h:182
uint32_t nTotalDroppedPackets
Total dropped packets.
Definition: queue-disc.h:174
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
Definition: queue-disc.cc:525
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:609
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:730
virtual ~QueueDiscClass()
Definition: queue-disc.cc:62
virtual ~QueueDisc()
Definition: queue-disc.cc:365
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:437
uint32_t nTotalRequeuedPackets
Total requeued packets.
Definition: queue-disc.h:194
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:687
Ptr< QueueDisc > m_queueDisc
Queue disc attached to this class.
Definition: queue-disc.h:78
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
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
Definition: queue-disc.h:617
uint32_t nTotalSentPackets
Total sent packets – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:162
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:605
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:151
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:610
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
Definition: queue-disc.h:402
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
Definition: queue-disc.h:603
uint32_t nTotalMarkedBytes
Total marked bytes.
Definition: queue-disc.h:202
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
Definition: queue-disc.h:176
Ptr< InternalQueue > GetInternalQueue(uint32_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:492
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:423
uint32_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:499
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:472
uint64_t nTotalEnqueuedBytes
Total enqueued bytes.
Definition: queue-disc.h:168
void PacketEnqueued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet enqueue. ...
Definition: queue-disc.cc:583
std::string m_childQueueDiscDropMsg
Reason why a packet was dropped by a child queue disc.
Definition: queue-disc.h:590
void DoInitialize(void)
Check whether the configuration is correct and initialize parameters.
Definition: queue-disc.cc:384
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
Definition: queue-disc.h:587
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
Definition: queue-disc.h:613
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue-disc.h:595
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:164
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets...
Definition: queue-disc.cc:785
Ptr< PacketFilter > GetPacketFilter(uint32_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:512
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:411
std::map< std::string, uint64_t > nDroppedBytesAfterDequeue
Bytes dropped after dequeue, for each reason.
Definition: queue-disc.h:192
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:894
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:186
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:563
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:371
uint32_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:519
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:200
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:577
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
Definition: queue-disc.h:615
QueueDiscClass is the base class for classes that are included in a queue disc.
Definition: queue-disc.h:48
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
Definition: queue-disc.h:574
Ptr< QueueDiscItem > Dequeue(void)
Request the queue discipline to extract a packet.
Definition: queue-disc.cc:765
uint64_t nTotalRequeuedBytes
Total requeued bytes.
Definition: queue-disc.h:196
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:180
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t nTotalReceivedPackets
Total received packets.
Definition: queue-disc.h:158
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
Definition: queue-disc.h:601
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
Definition: queue-disc.h:585
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:576
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:806
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue-disc.h:593
bool m_running
The queue disc is performing multiple dequeue operations.
Definition: queue-disc.h:588
uint64_t nTotalReceivedBytes
Total received bytes.
Definition: queue-disc.h:160
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:465
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:581
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:880
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue-disc.h:580
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue. ...
Definition: queue-disc.cc:595
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
Definition: queue-disc.h:577
uint64_t nTotalDequeuedBytes
Total dequeued bytes.
Definition: queue-disc.h:172
std::map< std::string, uint64_t > nDroppedBytesBeforeEnqueue
Bytes dropped before enqueue, for each reason.
Definition: queue-disc.h:188
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
Definition: queue-disc.h:190
Introspection did not find any typical Config paths.
Queue< QueueDiscItem > InternalQueue
Internal queues store QueueDiscItem objects.
Definition: queue-disc.h:328
Ptr< NetDevice > m_device
The NetDevice on which this queue discipline is installed.
Definition: queue-disc.h:586
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:458
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet after dequeue.
Definition: queue-disc.h:619
uint32_t nTotalEnqueuedPackets
Total enqueued packets.
Definition: queue-disc.h:166
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:505
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:608
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:648
Stats m_stats
The collected statistics.
Definition: queue-disc.h:584
uint64_t nTotalDroppedBytes
Total dropped bytes.
Definition: queue-disc.h:184
std::map< std::string, uint64_t > nMarkedBytes
Marked bytes, for each reason.
Definition: queue-disc.h:204
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue-disc.h:599
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
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:826
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:840
Ptr< NetDevice > GetNetDevice(void) const
Get the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:451
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:597
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:778
void SetNetDevice(Ptr< NetDevice > device)
Set the NetDevice on which this queue discipline is installed.
Definition: queue-disc.cc:444
Ptr< QueueDiscClass > GetQueueDiscClass(uint32_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:550
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
Definition: queue-disc.h:422
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
Definition: queue-disc.cc:819
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
Definition: queue-disc.h:578
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:430
std::map< std::string, uint32_t > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
Definition: queue-disc.h:178