A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
queue-disc.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007, 2014 University of Washington
3 * 2015 Universita' degli Studi di Napoli Federico II
4 *
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License version 2 as
7 * published by the Free Software Foundation;
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 */
18
19#ifndef QUEUE_DISC_H
20#define QUEUE_DISC_H
21
22#include "packet-filter.h"
23
24#include "ns3/object.h"
25#include "ns3/queue-fwd.h"
26#include "ns3/queue-item.h"
27#include "ns3/queue-size.h"
28#include "ns3/traced-callback.h"
29#include "ns3/traced-value.h"
30
31#include <functional>
32#include <map>
33#include <string>
34#include <vector>
35
36namespace ns3
37{
38
39class QueueDisc;
40class NetDeviceQueueInterface;
41
51class QueueDiscClass : public Object
52{
53 public:
58 static TypeId GetTypeId();
59
61 ~QueueDiscClass() override;
62
68
74
75 protected:
79 void DoDispose() override;
80
81 private:
83};
84
107{
111 NO_LIMITS
113
183class QueueDisc : public Object
184{
185 public:
187 struct Stats
188 {
210 std::map<std::string, uint32_t, std::less<>> nDroppedPacketsBeforeEnqueue;
214 std::map<std::string, uint32_t, std::less<>> nDroppedPacketsAfterDequeue;
220 std::map<std::string, uint64_t, std::less<>> nDroppedBytesBeforeEnqueue;
224 std::map<std::string, uint64_t, std::less<>> nDroppedBytesAfterDequeue;
232 std::map<std::string, uint32_t, std::less<>> nMarkedPackets;
236 std::map<std::string, uint64_t, std::less<>> nMarkedBytes;
237
239 Stats();
240
246 uint32_t GetNDroppedPackets(std::string reason) const;
252 uint64_t GetNDroppedBytes(std::string reason) const;
258 uint32_t GetNMarkedPackets(std::string reason) const;
264 uint64_t GetNMarkedBytes(std::string reason) const;
269 void Print(std::ostream& os) const;
270 };
271
276 static TypeId GetTypeId();
277
283
290
291 ~QueueDisc() override;
292
293 // Delete copy constructor and assignment operator to avoid misuse
294 QueueDisc(const QueueDisc&) = delete;
295 QueueDisc& operator=(const QueueDisc&) = delete;
296
303 uint32_t GetNPackets() const;
304
311 uint32_t GetNBytes() const;
312
318 QueueSize GetMaxSize() const;
319
328 bool SetMaxSize(QueueSize size);
329
339
344 const Stats& GetStats();
345
353
361
363 typedef std::function<void(Ptr<QueueDiscItem>)> SendCallback;
364
371 void SetSendCallback(SendCallback func);
372
380
385 virtual void SetQuota(const uint32_t quota);
386
391 virtual uint32_t GetQuota() const;
392
400 bool Enqueue(Ptr<QueueDiscItem> item);
401
410
419
425 void Run();
426
429
435
441 Ptr<InternalQueue> GetInternalQueue(std::size_t i) const;
442
447 std::size_t GetNInternalQueues() const;
448
454
460 Ptr<PacketFilter> GetPacketFilter(std::size_t i) const;
461
466 std::size_t GetNPacketFilters() const;
467
473
479 Ptr<QueueDiscClass> GetQueueDiscClass(std::size_t i) const;
480
485 std::size_t GetNQueueDiscClasses() const;
486
496
503 {
504 WAKE_ROOT = 0x00,
505 WAKE_CHILD = 0x01
506 };
507
519 virtual WakeMode GetWakeMode() const;
520
521 // Reasons for dropping packets
522 static constexpr const char* INTERNAL_QUEUE_DROP =
523 "Dropped by internal queue";
524 static constexpr const char* CHILD_QUEUE_DISC_DROP =
525 "(Dropped by child queue disc) ";
526 static constexpr const char* CHILD_QUEUE_DISC_MARK =
527 "(Marked by child queue disc) ";
528
529 protected:
533 void DoDispose() override;
534
544 void DoInitialize() override;
545
554 void DropBeforeEnqueue(Ptr<const QueueDiscItem> item, const char* reason);
555
564 void DropAfterDequeue(Ptr<const QueueDiscItem> item, const char* reason);
565
573 bool Mark(Ptr<QueueDiscItem> item, const char* reason);
574
575 private:
581 virtual bool DoEnqueue(Ptr<QueueDiscItem> item) = 0;
582
588
609
621 virtual bool CheckConfig() = 0;
622
629 virtual void InitializeParams() = 0;
630
636 bool RunBegin();
637
642 void RunEnd();
643
649 bool Restart();
650
656
662 void Requeue(Ptr<QueueDiscItem> item);
663
671 bool Transmit(Ptr<QueueDiscItem> item);
672
679
686
688 static const uint32_t DEFAULT_QUOTA = 64;
689
690 std::vector<Ptr<InternalQueue>> m_queues;
691 std::vector<Ptr<PacketFilter>> m_filters;
692 std::vector<Ptr<QueueDiscClass>> m_classes;
693
698
705 bool m_peeked;
710
725
729 typedef std::function<void(Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscDropFunctor;
731 typedef std::function<void(Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscMarkFunctor;
732
743};
744
752std::ostream& operator<<(std::ostream& os, const QueueDisc::Stats& stats);
753
754} // namespace ns3
755
756#endif /* QueueDisc */
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:78
QueueDiscClass is the base class for classes that are included in a queue disc.
Definition: queue-disc.h:52
~QueueDiscClass() override
Definition: queue-disc.cc:59
Ptr< QueueDisc > GetQueueDisc() const
Get the queue disc attached to this class.
Definition: queue-disc.cc:73
static TypeId GetTypeId()
Get the type ID.
Definition: queue-disc.cc:40
void DoDispose() override
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
Ptr< QueueDisc > m_queueDisc
Queue disc attached to this class.
Definition: queue-disc.h:82
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
Definition: queue-disc.h:184
std::vector< Ptr< PacketFilter > > m_filters
Packet filters.
Definition: queue-disc.h:691
std::vector< Ptr< QueueDiscClass > > m_classes
Classes.
Definition: queue-disc.h:692
static const uint32_t DEFAULT_QUOTA
Default quota (as in /proc/sys/net/core/dev_weight)
Definition: queue-disc.h:688
void AddInternalQueue(Ptr< InternalQueue > queue)
Add an internal queue to the tail of the list of queues.
Definition: queue-disc.cc:577
virtual uint32_t GetQuota() const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:570
WakeMode
Used to determine whether the queue disc itself or its children must be activated when a netdevice wa...
Definition: queue-disc.h:503
void SetNetDeviceQueueInterface(Ptr< NetDeviceQueueInterface > ndqi)
Definition: queue-disc.cc:535
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
Definition: queue-disc.cc:628
QueueSize m_maxSize
max queue size
Definition: queue-disc.h:697
QueueSize GetCurrentSize()
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
Definition: queue-disc.cc:519
SendCallback GetSendCallback() const
Definition: queue-disc.cc:556
TracedCallback< Ptr< const QueueDiscItem > > m_traceDequeue
Traced callback: fired when a packet is dequeued.
Definition: queue-disc.h:714
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
Definition: queue-disc.cc:436
virtual bool DoEnqueue(Ptr< QueueDiscItem > item)=0
This function actually enqueues a packet into the queue disc.
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:727
Ptr< NetDeviceQueueInterface > m_devQueueIface
NetDevice queue interface.
Definition: queue-disc.h:701
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:1072
static constexpr const char * CHILD_QUEUE_DISC_MARK
Packet marked by a child queue disc.
Definition: queue-disc.h:526
uint32_t GetNBytes() const
Get the amount of bytes stored by the queue disc.
Definition: queue-disc.cc:443
static constexpr const char * INTERNAL_QUEUE_DROP
Packet dropped by an internal queue.
Definition: queue-disc.h:522
Queue< QueueDiscItem > InternalQueue
Internal queues store QueueDiscItem objects.
Definition: queue-disc.h:428
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:731
Ptr< InternalQueue > GetInternalQueue(std::size_t i) const
Get the i-th internal queue.
Definition: queue-disc.cc:595
Ptr< QueueDiscItem > m_requeued
The last packet that failed to be transmitted.
Definition: queue-disc.h:704
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:1058
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:608
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue-disc.h:718
uint32_t m_quota
Maximum number of packets dequeued in a qdisc run.
Definition: queue-disc.h:700
virtual Ptr< const QueueDiscItem > DoPeek()
Return a copy of the next packet the queue disc will extract.
Definition: queue-disc.cc:935
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:671
TracedCallback< Ptr< const QueueDiscItem > > m_traceRequeue
Traced callback: fired when a packet is requeued.
Definition: queue-disc.h:716
TracedValue< uint32_t > m_nBytes
Number of bytes in the queue.
Definition: queue-disc.h:695
void PacketEnqueued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet enqueue.
Definition: queue-disc.cc:692
bool m_prohibitChangeMode
True if changing mode is prohibited.
Definition: queue-disc.h:709
void DoInitialize() override
Check whether the configuration is correct and initialize parameters.
Definition: queue-disc.cc:396
bool m_peeked
A packet was dequeued because Peek was called.
Definition: queue-disc.h:705
std::function< void(Ptr< QueueDiscItem >)> SendCallback
Callback invoked to send a packet to the receiving object when Run is called.
Definition: queue-disc.h:363
QueueDiscSizePolicy m_sizePolicy
The queue disc size policy.
Definition: queue-disc.h:708
bool m_running
The queue disc is performing multiple dequeue operations.
Definition: queue-disc.h:703
virtual bool CheckConfig()=0
Check whether the current configuration is correct.
TracedCallback< Ptr< const QueueDiscItem > > m_traceEnqueue
Traced callback: fired when a packet is enqueued.
Definition: queue-disc.h:712
Ptr< NetDeviceQueueInterface > GetNetDeviceQueueInterface() const
Definition: queue-disc.cc:542
void Run()
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
Definition: queue-disc.cc:953
TracedValue< uint32_t > m_nPackets
Number of packets in the queue.
Definition: queue-disc.h:694
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
ChildQueueDiscMarkFunctor m_childQueueDiscMarkFunctor
Function object called when a child queue disc marked a packet.
Definition: queue-disc.h:742
void RunEnd()
Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
Definition: queue-disc.cc:987
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
Definition: queue-disc.cc:665
virtual void InitializeParams()=0
Initialize parameters (if any) before the first packet is enqueued.
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:729
Stats m_stats
The collected statistics.
Definition: queue-disc.h:699
const Stats & GetStats()
Retrieve all the collected statistics.
Definition: queue-disc.cc:416
bool Restart()
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
Definition: queue-disc.cc:994
QueueSize GetMaxSize() const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:450
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:658
ChildQueueDiscDropFunctor m_childQueueDiscDbeFunctor
Function object called when a child queue disc dropped a packet before enqueue.
Definition: queue-disc.h:738
std::size_t GetNPacketFilters() const
Get the number of packet filters.
Definition: queue-disc.cc:622
std::string m_childQueueDiscMarkMsg
Reason why a packet was marked by a child queue disc.
Definition: queue-disc.h:707
virtual void SetQuota(const uint32_t quota)
Set the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:563
QueueDisc & operator=(const QueueDisc &)=delete
bool RunBegin()
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:974
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:478
std::string m_childQueueDiscDropMsg
Reason why a packet was dropped by a child queue disc.
Definition: queue-disc.h:706
InternalQueueDropFunctor m_internalQueueDbeFunctor
Function object called when an internal queue dropped a packet before enqueue.
Definition: queue-disc.h:734
std::size_t GetNInternalQueues() const
Get the number of internal queues.
Definition: queue-disc.cc:602
static TypeId GetTypeId()
Get the type ID.
Definition: queue-disc.cc:252
void DoDispose() override
Dispose of the object.
Definition: queue-disc.cc:379
SendCallback m_send
Callback used to send a packet to the receiving object.
Definition: queue-disc.h:702
virtual WakeMode GetWakeMode() const
When setting up the wake callbacks on the netdevice queues, it is necessary to determine which queue ...
Definition: queue-disc.cc:686
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropBeforeEnqueue
Traced callback: fired when a packet is dropped before enqueue.
Definition: queue-disc.h:720
TracedCallback< Time > m_sojourn
Sojourn time of the latest dequeued packet.
Definition: queue-disc.h:696
static constexpr const char * CHILD_QUEUE_DISC_DROP
Packet dropped by a child queue disc.
Definition: queue-disc.h:524
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceMark
Traced callback: fired when a packet is marked.
Definition: queue-disc.h:724
Ptr< QueueDiscItem > DequeuePacket()
Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
Definition: queue-disc.cc:1008
Ptr< QueueDiscItem > Dequeue()
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
Definition: queue-disc.cc:894
std::vector< Ptr< InternalQueue > > m_queues
Internal queues.
Definition: queue-disc.h:690
Ptr< const QueueDiscItem > Peek()
Get a copy of the next packet the queue discipline will extract.
Definition: queue-disc.cc:928
ChildQueueDiscDropFunctor m_childQueueDiscDadFunctor
Function object called when a child queue disc dropped a packet after dequeue.
Definition: queue-disc.h:740
TracedCallback< Ptr< const QueueDiscItem >, const char * > m_traceDropAfterDequeue
Traced callback: fired when a packet is dropped after dequeue.
Definition: queue-disc.h:722
InternalQueueDropFunctor m_internalQueueDadFunctor
Function object called when an internal queue dropped a packet after dequeue.
Definition: queue-disc.h:736
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:817
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:726
Ptr< PacketFilter > GetPacketFilter(std::size_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:615
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue.
Definition: queue-disc.cc:704
virtual Ptr< QueueDiscItem > DoDequeue()=0
This function actually extracts a packet from the queue disc.
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:549
~QueueDisc() override
Definition: queue-disc.cc:373
Template class for packet Queues.
Definition: queue.h:267
Class for representing queue sizes.
Definition: queue-size.h:96
Forward calls to a chain of Callback.
Trace classes with value semantics.
Definition: traced-value.h:116
a unique identifier for an interface.
Definition: type-id.h:59
QueueSizeUnit
Enumeration of the operating modes of queues.
Definition: queue-size.h:44
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
Definition: queue-disc.h:107
@ SINGLE_INTERNAL_QUEUE
Used by queue discs with single internal queue.
Definition: queue-disc.h:108
@ SINGLE_CHILD_QUEUE_DISC
Used by queue discs with single child queue disc.
Definition: queue-disc.h:109
@ MULTIPLE_QUEUES
Used by queue discs with multiple internal queues/child queue discs.
Definition: queue-disc.h:110
@ NO_LIMITS
Used by queue discs with unlimited size.
Definition: queue-disc.h:111
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:129
Structure that keeps the queue disc statistics.
Definition: queue-disc.h:188
std::map< std::string, uint64_t, std::less<> > nDroppedBytesAfterDequeue
Bytes dropped after dequeue, for each reason.
Definition: queue-disc.h:224
uint32_t GetNDroppedPackets(std::string reason) const
Get the number of packets dropped for the given reason.
Definition: queue-disc.cc:111
uint64_t nTotalRequeuedBytes
Total requeued bytes.
Definition: queue-disc.h:228
std::map< std::string, uint32_t, std::less<> > nDroppedPacketsBeforeEnqueue
Packets dropped before enqueue, for each reason.
Definition: queue-disc.h:210
uint32_t nTotalEnqueuedPackets
Total enqueued packets.
Definition: queue-disc.h:198
uint64_t nTotalReceivedBytes
Total received bytes.
Definition: queue-disc.h:192
uint32_t nTotalRequeuedPackets
Total requeued packets.
Definition: queue-disc.h:226
uint64_t nTotalDroppedBytesBeforeEnqueue
Total bytes dropped before enqueue.
Definition: queue-disc.h:218
uint32_t nTotalDequeuedPackets
Total dequeued packets.
Definition: queue-disc.h:202
uint32_t nTotalDroppedPackets
Total dropped packets.
Definition: queue-disc.h:206
uint64_t GetNDroppedBytes(std::string reason) const
Get the amount of bytes dropped for the given reason.
Definition: queue-disc.cc:132
uint64_t nTotalEnqueuedBytes
Total enqueued bytes.
Definition: queue-disc.h:200
uint32_t nTotalSentPackets
Total sent packets – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:194
uint32_t nTotalMarkedBytes
Total marked bytes.
Definition: queue-disc.h:234
Stats()
constructor
Definition: queue-disc.cc:88
uint32_t nTotalMarkedPackets
Total marked packets.
Definition: queue-disc.h:230
uint64_t GetNMarkedBytes(std::string reason) const
Get the amount of bytes marked for the given reason.
Definition: queue-disc.cc:166
uint64_t nTotalDroppedBytesAfterDequeue
Total bytes dropped after dequeue.
Definition: queue-disc.h:222
std::map< std::string, uint64_t, std::less<> > nMarkedBytes
Marked bytes, for each reason.
Definition: queue-disc.h:236
std::map< std::string, uint64_t, std::less<> > nDroppedBytesBeforeEnqueue
Bytes dropped before enqueue, for each reason.
Definition: queue-disc.h:220
uint32_t nTotalDroppedPacketsBeforeEnqueue
Total packets dropped before enqueue.
Definition: queue-disc.h:208
uint64_t nTotalDroppedBytes
Total dropped bytes.
Definition: queue-disc.h:216
void Print(std::ostream &os) const
Print the statistics.
Definition: queue-disc.cc:179
uint32_t nTotalReceivedPackets
Total received packets.
Definition: queue-disc.h:190
uint32_t GetNMarkedPackets(std::string reason) const
Get the number of packets marked for the given reason.
Definition: queue-disc.cc:153
std::map< std::string, uint32_t, std::less<> > nDroppedPacketsAfterDequeue
Packets dropped after dequeue, for each reason.
Definition: queue-disc.h:214
std::map< std::string, uint32_t, std::less<> > nMarkedPackets
Marked packets, for each reason.
Definition: queue-disc.h:232
uint64_t nTotalSentBytes
Total sent bytes – this value is not kept up to date, call GetStats first.
Definition: queue-disc.h:196
uint32_t nTotalDroppedPacketsAfterDequeue
Total packets dropped after dequeue.
Definition: queue-disc.h:212
uint64_t nTotalDequeuedBytes
Total dequeued bytes.
Definition: queue-disc.h:204