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
34namespace ns3 {
35
36class QueueDisc;
37template <typename Item> class Queue;
38class NetDeviceQueueInterface;
39
49class QueueDiscClass : public Object {
50public:
55 static TypeId GetTypeId (void);
56
58 virtual ~QueueDiscClass ();
59
64 Ptr<QueueDisc> GetQueueDisc (void) const;
65
71
72protected:
76 virtual void DoDispose (void);
77
78private:
80};
81
104{
108 NO_LIMITS
110
111
181class QueueDisc : public Object {
182public:
183
185 struct Stats
186 {
208 std::map<std::string, uint32_t, std::less<>> nDroppedPacketsBeforeEnqueue;
212 std::map<std::string, uint32_t, std::less<>> nDroppedPacketsAfterDequeue;
218 std::map<std::string, uint64_t, std::less<>> nDroppedBytesBeforeEnqueue;
222 std::map<std::string, uint64_t, std::less<>> nDroppedBytesAfterDequeue;
230 std::map<std::string, uint32_t, std::less<>> nMarkedPackets;
234 std::map<std::string, uint64_t, std::less<>> 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
291 // Delete copy constructor and assignment operator to avoid misuse
292 QueueDisc (const QueueDisc &) = delete;
293 QueueDisc & operator = (const QueueDisc &) = delete;
294
301 uint32_t GetNPackets (void) const;
302
309 uint32_t GetNBytes (void) const;
310
316 QueueSize GetMaxSize (void) const;
317
326 bool SetMaxSize (QueueSize size);
327
337
342 const Stats& GetStats (void);
343
351
359
361 typedef std::function<void (Ptr<QueueDiscItem>)> SendCallback;
362
369 void SetSendCallback (SendCallback func);
370
377 SendCallback GetSendCallback (void) const;
378
383 virtual void SetQuota (const uint32_t quota);
384
389 virtual uint32_t GetQuota (void) const;
390
398 bool Enqueue (Ptr<QueueDiscItem> item);
399
408
417
423 void Run (void);
424
427
433
439 Ptr<InternalQueue> GetInternalQueue (std::size_t i) const;
440
445 std::size_t GetNInternalQueues (void) const;
446
452
458 Ptr<PacketFilter> GetPacketFilter (std::size_t i) const;
459
464 std::size_t GetNPacketFilters (void) const;
465
471
477 Ptr<QueueDiscClass> GetQueueDiscClass (std::size_t i) const;
478
483 std::size_t GetNQueueDiscClasses (void) const;
484
494
501 {
502 WAKE_ROOT = 0x00,
503 WAKE_CHILD = 0x01
504 };
505
517 virtual WakeMode GetWakeMode (void) const;
518
519 // Reasons for dropping packets
520 static constexpr const char* INTERNAL_QUEUE_DROP = "Dropped by internal queue";
521 static constexpr const char* CHILD_QUEUE_DISC_DROP = "(Dropped by child queue disc) ";
522 static constexpr const char* CHILD_QUEUE_DISC_MARK = "(Marked by child queue disc) ";
523
524protected:
528 virtual void DoDispose (void);
529
539 void DoInitialize (void);
540
549 void DropBeforeEnqueue (Ptr<const QueueDiscItem> item, const char* reason);
550
559 void DropAfterDequeue (Ptr<const QueueDiscItem> item, const char* reason);
560
568 bool Mark (Ptr<QueueDiscItem> item, const char* reason);
569
570private:
576 virtual bool DoEnqueue (Ptr<QueueDiscItem> item) = 0;
577
582 virtual Ptr<QueueDiscItem> DoDequeue (void) = 0;
583
603 virtual Ptr<const QueueDiscItem> DoPeek (void);
604
616 virtual bool CheckConfig (void) = 0;
617
624 virtual void InitializeParams (void) = 0;
625
630 bool RunBegin (void);
631
636 void RunEnd (void);
637
643 bool Restart (void);
644
650
656 void Requeue (Ptr<QueueDiscItem> item);
657
665 bool Transmit (Ptr<QueueDiscItem> item);
666
673
680
681 static const uint32_t DEFAULT_QUOTA = 64;
682
683 std::vector<Ptr<InternalQueue> > m_queues;
684 std::vector<Ptr<PacketFilter> > m_filters;
685 std::vector<Ptr<QueueDiscClass> > m_classes;
686
691
698 bool m_peeked;
703
718
722 typedef std::function<void (Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscDropFunctor;
724 typedef std::function<void (Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscMarkFunctor;
725
736};
737
745std::ostream& operator<< (std::ostream& os, const QueueDisc::Stats &stats);
746
747} // namespace ns3
748
749#endif /* QueueDisc */
A base class which provides memory management and object aggregation.
Definition: object.h:88
Introspection did not find any typical Config paths.
QueueDiscClass is the base class for classes that are included in a queue disc.
Definition: queue-disc.h:49
virtual ~QueueDiscClass()
Definition: queue-disc.cc:58
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue-disc.cc:39
Ptr< QueueDisc > GetQueueDisc(void) const
Get the queue disc attached to this class.
Definition: queue-disc.cc:72
void SetQueueDisc(Ptr< QueueDisc > qd)
Set the queue disc attached to this class.
Definition: queue-disc.cc:79
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:64
Ptr< QueueDisc > m_queueDisc
Queue disc attached to this class.
Definition: queue-disc.h:79
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:181
bool Restart(void)
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
Definition: queue-disc.cc:994
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
Definition: queue-disc.h:684
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
Definition: queue-disc.h:685
std::function< void(Ptr< const QueueDiscItem >, const char *)> ChildQueueDiscMarkFunctor
Type for the function objects notifying that a packet has been marked by a child queue disc.
Definition: queue-disc.h:724
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
Definition: queue-disc.h:681
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:579
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:722
QueueSize GetCurrentSize(void)
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
Definition: queue-disc.cc:521
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
Definition: queue-disc.h:501
void RunEnd(void)
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
Definition: queue-disc.cc:987
void SetNetDeviceQueueInterface(Ptr< NetDeviceQueueInterface > ndqi)
Definition: queue-disc.cc:537
virtual ~QueueDisc()
Definition: queue-disc.cc:376
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
Definition: queue-disc.cc:632
QueueSize m_maxSize
max queue size
Definition: queue-disc.h:690
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue-disc.h:707
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)=0
This function actually enqueues a packet into the queue disc.
uint32_t GetNBytes(void) const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:445
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
Definition: queue-disc.h:694
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:1071
static constexpr const char * CHILD_QUEUE_DISC_MARK
Packet marked by a child queue disc.
Definition: queue-disc.h:522
QueueSize GetMaxSize(void) const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:452
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
Definition: queue-disc.h:520
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
Definition: queue-disc.h:713
QueueDisc(QueueDiscSizePolicy policy=QueueDiscSizePolicy::SINGLE_INTERNAL_QUEUE)
Constructor.
Definition: queue-disc.cc:321
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:687
Queue< QueueDiscItem > InternalQueue
Internal queues store QueueDiscItem objects.
Definition: queue-disc.h:426
Ptr< const QueueDiscItem > Peek(void)
Get a copy of the next packet the queue discipline will extract.
Definition: queue-disc.cc:928
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:599
void Run(void)
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
Definition: queue-disc.cc:953
static TypeId GetTypeId(void)
Get the type ID.
Definition: queue-disc.cc:262
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
Definition: queue-disc.h:697
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:1057
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:612
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue-disc.h:711
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
Definition: queue-disc.h:693
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:673
TracedCallback< Ptr< const QueueDiscItem > > m_traceRequeue
Traced callback: fired when a packet is requeued.
Definition: queue-disc.h:709
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue-disc.h:688
virtual void InitializeParams(void)=0
Initialize parameters (if any) before the first packet is enqueued.
void PacketEnqueued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet enqueue.
Definition: queue-disc.cc:693
bool m_prohibitChangeMode
True if changing mode is prohibited.
Definition: queue-disc.h:702
bool m_peeked
A packet was dequeued because Peek was called.
Definition: queue-disc.h:698
QueueDiscSizePolicy m_sizePolicy
The queue disc size policy.
Definition: queue-disc.h:701
Ptr< QueueDiscItem > Dequeue(void)
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
Definition: queue-disc.cc:894
bool m_running
The queue disc is performing multiple dequeue operations.
Definition: queue-disc.h:696
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:717
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue-disc.h:705
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue-disc.h:687
void DoInitialize(void)
Check whether the configuration is correct and initialize parameters.
Definition: queue-disc.cc:399
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:766
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:720
ChildQueueDiscMarkFunctor m_childQueueDiscMarkFunctor
Function object called when a child queue disc marked a packet.
Definition: queue-disc.h:735
Ptr< NetDeviceQueueInterface > GetNetDeviceQueueInterface(void) const
Definition: queue-disc.cc:544
std::size_t GetNPacketFilters(void) const
Get the number of packet filters.
Definition: queue-disc.cc:626
Stats m_stats
The collected statistics.
Definition: queue-disc.h:692
uint32_t GetNPackets(void) const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:438
bool RunBegin(void)
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:974
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:660
std::size_t GetNQueueDiscClasses(void) const
Get the number of queue disc classes.
Definition: queue-disc.cc:667
virtual Ptr< const QueueDiscItem > DoPeek(void)
Return a copy of the next packet the queue disc will extract.
Definition: queue-disc.cc:935
virtual uint32_t GetQuota(void) const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:572
Ptr< QueueDiscItem > DequeuePacket(void)
Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
Definition: queue-disc.cc:1008
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
Definition: queue-disc.h:731
std::string m_childQueueDiscMarkMsg
Reason why a packet was marked by a child queue disc.
Definition: queue-disc.h:700
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:565
QueueDisc & operator=(const QueueDisc &)=delete
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:480
std::string m_childQueueDiscDropMsg
Reason why a packet was dropped by a child queue disc.
Definition: queue-disc.h:699
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
Definition: queue-disc.h:727
std::function< void(Ptr< QueueDiscItem >)> SendCallback
Callback invoked to send a packet to the receiving object when Run is called.
Definition: queue-disc.h:361
virtual bool CheckConfig(void)=0
Check whether the current configuration is correct.
virtual void DoDispose(void)
Dispose of the object.
Definition: queue-disc.cc:382
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
Definition: queue-disc.h:715
SendCallback GetSendCallback(void) const
Definition: queue-disc.cc:558
SendCallback m_send
Callback used to send a packet to the receiving object.
Definition: queue-disc.h:695
const Stats & GetStats(void)
Retrieve all the collected statistics.
Definition: queue-disc.cc:419
TracedCallback< Time > m_sojourn
Sojourn time of the latest dequeued packet.
Definition: queue-disc.h:689
static constexpr const char * CHILD_QUEUE_DISC_DROP
Packet dropped by a child queue disc.
Definition: queue-disc.h:521
std::size_t GetNInternalQueues(void) const
Get the number of internal queues.
Definition: queue-disc.cc:606
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
Definition: queue-disc.h:683
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet after dequeue.
Definition: queue-disc.h:733
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
Definition: queue-disc.h:729
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:816
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:727
Ptr< PacketFilter > GetPacketFilter(std::size_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:619
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue.
Definition: queue-disc.cc:705
QueueDisc(const QueueDisc &)=delete
bool Enqueue(Ptr< QueueDiscItem > item)
Pass a packet to store to the queue discipline.
Definition: queue-disc.cc:859
void SetSendCallback(SendCallback func)
Definition: queue-disc.cc:551
Class for representing queue sizes.
Definition: queue-size.h:95
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:43
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:104
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
Definition: queue-disc.h:105
@ SINGLE_CHILD_QUEUE_DISC
Used by queue discs with single child queue disc.
Definition: queue-disc.h:106
@ MULTIPLE_QUEUES
Used by queue discs with multiple internal queues/child queue discs.
Definition: queue-disc.h:107
@ NO_LIMITS
Used by queue discs with unlimited size.
Definition: queue-disc.h:108
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:137
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:186
std::map< std::string, uint64_t, std::less<> > nDroppedBytesAfterDequeue
Bytes dropped after dequeue, for each reason.
Definition: queue-disc.h:222
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
Definition: queue-disc.cc:109
uint64_t nTotalRequeuedBytes
Total requeued bytes.
Definition: queue-disc.h:226
std::map< std::string, uint32_t, std::less<> > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
Definition: queue-disc.h:208
uint32_t nTotalEnqueuedPackets
Total enqueued packets.
Definition: queue-disc.h:196
uint64_t nTotalReceivedBytes
Total received bytes.
Definition: queue-disc.h:190
uint32_t nTotalRequeuedPackets
Total requeued packets.
Definition: queue-disc.h:224
uint64_t nTotalDroppedBytesBeforeEnqueue
Total bytes dropped before enqueue.
Definition: queue-disc.h:216
uint32_t nTotalDequeuedPackets
Total dequeued packets.
Definition: queue-disc.h:200
uint32_t nTotalDroppedPackets
Total dropped packets.
Definition: queue-disc.h:204
uint64_t GetNDroppedBytes(std::string reason) const
Get the amount of bytes dropped for the given reason.
Definition: queue-disc.cc:130
uint64_t nTotalEnqueuedBytes
Total enqueued bytes.
Definition: queue-disc.h:198
uint32_t nTotalSentPackets
Total sent packets – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:192
uint32_t nTotalMarkedBytes
Total marked bytes.
Definition: queue-disc.h:232
Stats()
constructor
Definition: queue-disc.cc:86
uint32_t nTotalMarkedPackets
Total marked packets.
Definition: queue-disc.h:228
uint64_t GetNMarkedBytes(std::string reason) const
Get the amount of bytes marked for the given reason.
Definition: queue-disc.cc:164
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
Definition: queue-disc.h:220
std::map< std::string, uint64_t, std::less<> > nMarkedBytes
Marked bytes, for each reason.
Definition: queue-disc.h:234
std::map< std::string, uint64_t, std::less<> > nDroppedBytesBeforeEnqueue
Bytes dropped before enqueue, for each reason.
Definition: queue-disc.h:218
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
Definition: queue-disc.h:206
uint64_t nTotalDroppedBytes
Total dropped bytes.
Definition: queue-disc.h:214
void Print(std::ostream &os) const
Print the statistics.
Definition: queue-disc.cc:177
uint32_t nTotalReceivedPackets
Total received packets.
Definition: queue-disc.h:188
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
Definition: queue-disc.cc:151
std::map< std::string, uint32_t, std::less<> > nDroppedPacketsAfterDequeue
Packets dropped after dequeue, for each reason.
Definition: queue-disc.h:212
std::map< std::string, uint32_t, std::less<> > nMarkedPackets
Marked packets, for each reason.
Definition: queue-disc.h:230
uint64_t nTotalSentBytes
Total sent bytes – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:194
uint32_t nTotalDroppedPacketsAfterDequeue
Total packets dropped after dequeue.
Definition: queue-disc.h:210
uint64_t nTotalDequeuedBytes
Total dequeued bytes.
Definition: queue-disc.h:202