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
42/**
43 * \ingroup traffic-control
44 *
45 * QueueDiscClass is the base class for classes that are included in a queue
46 * disc. It has a single attribute, QueueDisc, used to set the child queue disc
47 * attached to the class. Classful queue discs needing to set parameters for
48 * their classes can subclass QueueDiscClass and add the required parameters
49 * as attributes.
50 */
51class QueueDiscClass : public Object
52{
53 public:
54 /**
55 * \brief Get the type ID.
56 * \return the object TypeId
57 */
58 static TypeId GetTypeId();
59
61 ~QueueDiscClass() override;
62
63 /**
64 * \brief Get the queue disc attached to this class
65 * \return the queue disc attached to this class.
66 */
68
69 /**
70 * \brief Set the queue disc attached to this class
71 * \param qd The queue disc to attach to this class
72 */
74
75 protected:
76 /**
77 * \brief Dispose of the object
78 */
79 void DoDispose() override;
80
81 private:
82 Ptr<QueueDisc> m_queueDisc; //!< Queue disc attached to this class
83};
84
85/**
86 * \ingroup traffic-control
87 * \brief Enumeration of the available policies to handle the queue disc size.
88 *
89 * - SINGLE_INTERNAL_QUEUE is intended to handle the maxSize attribute
90 * of queue discs having a single internal queue. If no internal queue is
91 * yet attached to the queue disc, setting/getting this attribute involves
92 * setting/getting the member variable of the queue disc; otherwise, the
93 * corresponding attribute of the internal queue is set/get.
94 * - SINGLE_CHILD_QUEUE_DISC is intended to handle the maxSize attribute
95 * of queue discs having a single child queue disc. If no child queue disc is
96 * yet attached to the queue disc, setting/getting this attribute involves
97 * setting/getting the member variable of the queue disc; otherwise, the
98 * corresponding attribute of the child queue disc is set/get.
99 * - MULTIPLE_QUEUES is intended to handle the maxSize attribute of queue
100 * discs having multiple internal queues or child queue discs. Setting/getting
101 * this attribute always involves setting/getting the member variable of the
102 * queue disc. Queue discs should warn the user if a packet is dropped by an
103 * internal queue/child queue disc because of lack of space, while the queue
104 * disc limit is not exceeded.
105 */
107{
108 SINGLE_INTERNAL_QUEUE, //!< Used by queue discs with single internal queue
109 SINGLE_CHILD_QUEUE_DISC, //!< Used by queue discs with single child queue disc
110 MULTIPLE_QUEUES, //!< Used by queue discs with multiple internal queues/child queue discs
111 NO_LIMITS //!< Used by queue discs with unlimited size
113
114/**
115 * \ingroup traffic-control
116 *
117 * QueueDisc is an abstract base class providing the interface and implementing
118 * the operations common to all the queueing disciplines. Child classes
119 * need to implement the methods used to enqueue a packet (DoEnqueue),
120 * dequeue a single packet (DoDequeue), get a copy of the next packet
121 * to extract (DoPeek), check whether the current configuration is correct
122 * (CheckConfig).
123 *
124 * As in Linux, a queue disc may contain distinct elements:
125 * - queues, which actually store the packets waiting for transmission
126 * - classes, which allow to reserve a different treatment to different packets
127 * - filters, which determine the queue or class which a packet is destined to
128 *
129 * Notice that a child queue disc must be attached to every class and a packet
130 * filter is only able to classify packets of a single protocol. Also, while in Linux
131 * some queue discs (e.g., fq-codel) use an internal classifier and do not make use of
132 * packet filters, in ns-3 every queue disc including multiple queues or multiple classes
133 * needs an external filter to classify packets (this is to avoid having the traffic-control
134 * module depend on other modules such as internet).
135 *
136 * Queue disc configuration vary from queue disc to queue disc. A typical taxonomy divides
137 * queue discs in classful (i.e., support classes) and classless (i.e., do not support
138 * classes). More recently, after the appearance of multi-queue devices (such as Wifi),
139 * some multi-queue aware queue discs have been introduced. Multi-queue aware queue discs
140 * handle as many queues (or queue discs -- without using classes) as the number of
141 * transmission queues used by the device on which the queue disc is installed.
142 * An attempt is made, also, to enqueue each packet in the "same" queue both within the
143 * queue disc and within the device.
144 *
145 * The traffic control layer interacts with a queue disc in a simple manner: after
146 * requesting to enqueue a packet, the traffic control layer requests the qdisc to
147 * "run", i.e., to dequeue a set of packets, until a predefined number ("quota")
148 * of packets is dequeued or the netdevice stops the queue disc. A netdevice shall
149 * stop the queue disc when its transmission queue does not have room for another
150 * packet. Also, a netdevice shall wake the queue disc when it detects that there
151 * is room for another packet in its transmission queue, but the transmission queue
152 * is stopped. Waking a queue disc is equivalent to make it run.
153 *
154 * Every queue disc collects statistics about the total number of packets/bytes
155 * received from the upper layers (in case of root queue disc) or from the parent
156 * queue disc (in case of child queue disc), enqueued, dequeued, requeued, dropped,
157 * dropped before enqueue, dropped after dequeue, queued in the queue disc and
158 * sent to the netdevice or to the parent queue disc. Note that packets that are
159 * dequeued may be requeued, i.e., retained by the traffic control infrastructure,
160 * if the netdevice is not ready to receive them. Requeued packets are not part
161 * of the queue disc. The following identities hold:
162 * - dropped = dropped before enqueue + dropped after dequeue
163 * - received = dropped before enqueue + enqueued
164 * - queued = enqueued - dequeued
165 * - sent = dequeued - dropped after dequeue (- 1 if there is a requeued packet)
166 *
167 * Separate counters are also kept for each possible reason to drop a packet.
168 * When a packet is dropped by an internal queue, e.g., because the queue is full,
169 * the reason is "Dropped by internal queue". When a packet is dropped by a child
170 * queue disc, the reason is "(Dropped by child queue disc) " followed by the
171 * reason why the child queue disc dropped the packet.
172 *
173 * The QueueDisc base class provides the SojournTime trace source, which provides
174 * the sojourn time of every packet dequeued from a queue disc, including packets
175 * that are dropped or requeued after being dequeued. The sojourn time is taken
176 * when the packet is dequeued from the queue disc, hence it does not account for
177 * the additional time the packet is retained within the traffic control
178 * infrastructure in case it is requeued.
179 *
180 * The design and implementation of this class is heavily inspired by Linux.
181 * For more details, see the traffic-control model page.
182 */
183class QueueDisc : public Object
184{
185 public:
186 /// \brief Structure that keeps the queue disc statistics
187 struct Stats
188 {
189 /// Total received packets
191 /// Total received bytes
193 /// Total sent packets -- this value is not kept up to date, call GetStats first
195 /// Total sent bytes -- this value is not kept up to date, call GetStats first
197 /// Total enqueued packets
199 /// Total enqueued bytes
201 /// Total dequeued packets
203 /// Total dequeued bytes
205 /// Total dropped packets
207 /// Total packets dropped before enqueue
209 /// Packets dropped before enqueue, for each reason
210 std::map<std::string, uint32_t, std::less<>> nDroppedPacketsBeforeEnqueue;
211 /// Total packets dropped after dequeue
213 /// Packets dropped after dequeue, for each reason
214 std::map<std::string, uint32_t, std::less<>> nDroppedPacketsAfterDequeue;
215 /// Total dropped bytes
217 /// Total bytes dropped before enqueue
219 /// Bytes dropped before enqueue, for each reason
220 std::map<std::string, uint64_t, std::less<>> nDroppedBytesBeforeEnqueue;
221 /// Total bytes dropped after dequeue
223 /// Bytes dropped after dequeue, for each reason
224 std::map<std::string, uint64_t, std::less<>> nDroppedBytesAfterDequeue;
225 /// Total requeued packets
227 /// Total requeued bytes
229 /// Total marked packets
231 /// Marked packets, for each reason
232 std::map<std::string, uint32_t, std::less<>> nMarkedPackets;
233 /// Total marked bytes
235 /// Marked bytes, for each reason
236 std::map<std::string, uint64_t, std::less<>> nMarkedBytes;
237
238 /// constructor
239 Stats();
240
241 /**
242 * \brief Get the number of packets dropped for the given reason
243 * \param reason the reason why packets were dropped
244 * \return the number of packets dropped for the given reason
245 */
246 uint32_t GetNDroppedPackets(std::string reason) const;
247 /**
248 * \brief Get the amount of bytes dropped for the given reason
249 * \param reason the reason why packets were dropped
250 * \return the amount of bytes dropped for the given reason
251 */
252 uint64_t GetNDroppedBytes(std::string reason) const;
253 /**
254 * \brief Get the number of packets marked for the given reason
255 * \param reason the reason why packets were marked
256 * \return the number of packets marked for the given reason
257 */
258 uint32_t GetNMarkedPackets(std::string reason) const;
259 /**
260 * \brief Get the amount of bytes marked for the given reason
261 * \param reason the reason why packets were marked
262 * \return the amount of bytes marked for the given reason
263 */
264 uint64_t GetNMarkedBytes(std::string reason) const;
265 /**
266 * \brief Print the statistics.
267 * \param os output stream in which the data should be printed.
268 */
269 void Print(std::ostream& os) const;
270 };
271
272 /**
273 * \brief Get the type ID.
274 * \return the object TypeId
275 */
276 static TypeId GetTypeId();
277
278 /**
279 * \brief Constructor
280 * \param policy the policy to handle the queue disc size
281 */
283
284 /**
285 * \brief Constructor
286 * \param policy the policy to handle the queue disc size
287 * \param unit The fixed operating mode of this queue disc
288 */
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
297 /**
298 * \brief Get the number of packets stored by the queue disc
299 * \return the number of packets stored by the queue disc.
300 *
301 * The requeued packet, if any, is counted.
302 */
303 uint32_t GetNPackets() const;
304
305 /**
306 * \brief Get the amount of bytes stored by the queue disc
307 * \return the amount of bytes stored by the queue disc.
308 *
309 * The requeued packet, if any, is counted.
310 */
311 uint32_t GetNBytes() const;
312
313 /**
314 * \brief Get the maximum size of the queue disc.
315 *
316 * \returns the maximum size of the queue disc.
317 */
318 QueueSize GetMaxSize() const;
319
320 /**
321 * \brief Set the maximum size of the queue disc.
322 *
323 * Trying to set a null size has no effect.
324 *
325 * \param size the maximum size.
326 * \returns true if setting the size succeeded, false otherwise.
327 */
328 bool SetMaxSize(QueueSize size);
329
330 /**
331 * \brief Get the current size of the queue disc in bytes, if
332 * operating in bytes mode, or packets, otherwise.
333 *
334 * Do not call this method if the queue disc size is not limited.
335 *
336 * \returns The queue disc size in bytes or packets.
337 */
339
340 /**
341 * \brief Retrieve all the collected statistics.
342 * \return the collected statistics.
343 */
344 const Stats& GetStats();
345
346 /**
347 * \param ndqi the NetDeviceQueueInterface aggregated to the receiving object.
348 *
349 * Set the pointer to the NetDeviceQueueInterface object aggregated to the
350 * object receiving the packets dequeued from this queue disc.
351 */
353
354 /**
355 * \return the NetDeviceQueueInterface aggregated to the receiving object.
356 *
357 * Get the pointer to the NetDeviceQueueInterface object aggregated to the
358 * object receiving the packets dequeued from this queue disc.
359 */
361
362 /// Callback invoked to send a packet to the receiving object when Run is called
363 typedef std::function<void(Ptr<QueueDiscItem>)> SendCallback;
364
365 /**
366 * \param func the callback to send a packet to the receiving object.
367 *
368 * Set the callback used by the Transmit method (called eventually by the Run
369 * method) to send a packet to the receiving object.
370 */
371 void SetSendCallback(SendCallback func);
372
373 /**
374 * \return the callback to send a packet to the receiving object.
375 *
376 * Get the callback used by the Transmit method (called eventually by the Run
377 * method) to send a packet to the receiving object.
378 */
380
381 /**
382 * \brief Set the maximum number of dequeue operations following a packet enqueue
383 * \param quota the maximum number of dequeue operations following a packet enqueue.
384 */
385 virtual void SetQuota(const uint32_t quota);
386
387 /**
388 * \brief Get the maximum number of dequeue operations following a packet enqueue
389 * \return the maximum number of dequeue operations following a packet enqueue.
390 */
391 virtual uint32_t GetQuota() const;
392
393 /**
394 * Pass a packet to store to the queue discipline. This function only updates
395 * the statistics and calls the (private) DoEnqueue function, which must be
396 * implemented by derived classes.
397 * \param item item to enqueue
398 * \return True if the operation was successful; false otherwise
399 */
400 bool Enqueue(Ptr<QueueDiscItem> item);
401
402 /**
403 * Extract from the queue disc the packet that has been dequeued by calling
404 * Peek, if any, or call the private DoDequeue method (which must be
405 * implemented by derived classes) to dequeue a packet, otherwise.
406 *
407 * \return 0 if the operation was not successful; the item otherwise.
408 */
410
411 /**
412 * Get a copy of the next packet the queue discipline will extract. This
413 * function only calls the (private) DoPeek function. This base class provides
414 * a default implementation of DoPeek, which dequeues the next packet but
415 * retains it into the queue disc.
416 * \return 0 if the operation was not successful; the item otherwise.
417 */
419
420 /**
421 * Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c)
422 * Dequeues multiple packets, until a quota is exceeded or sending a packet
423 * to the device failed.
424 */
425 void Run();
426
427 /// Internal queues store QueueDiscItem objects
429
430 /**
431 * \brief Add an internal queue to the tail of the list of queues.
432 * \param queue the queue to be added
433 */
435
436 /**
437 * \brief Get the i-th internal queue
438 * \param i the index of the queue
439 * \return the i-th internal queue.
440 */
441 Ptr<InternalQueue> GetInternalQueue(std::size_t i) const;
442
443 /**
444 * \brief Get the number of internal queues
445 * \return the number of internal queues.
446 */
447 std::size_t GetNInternalQueues() const;
448
449 /**
450 * \brief Add a packet filter to the tail of the list of filters used to classify packets.
451 * \param filter the packet filter to be added
452 */
454
455 /**
456 * \brief Get the i-th packet filter
457 * \param i the index of the packet filter
458 * \return the i-th packet filter.
459 */
460 Ptr<PacketFilter> GetPacketFilter(std::size_t i) const;
461
462 /**
463 * \brief Get the number of packet filters
464 * \return the number of packet filters.
465 */
466 std::size_t GetNPacketFilters() const;
467
468 /**
469 * \brief Add a queue disc class to the tail of the list of classes.
470 * \param qdClass the queue disc class to be added
471 */
473
474 /**
475 * \brief Get the i-th queue disc class
476 * \param i the index of the queue disc class
477 * \return the i-th queue disc class.
478 */
479 Ptr<QueueDiscClass> GetQueueDiscClass(std::size_t i) const;
480
481 /**
482 * \brief Get the number of queue disc classes
483 * \return the number of queue disc classes.
484 */
485 std::size_t GetNQueueDiscClasses() const;
486
487 /**
488 * Classify a packet by calling the packet filters, one at a time, until either
489 * a filter able to classify the packet is found or all the filters have been
490 * processed.
491 * \param item item to classify
492 * \return -1 if no filter able to classify the packet has been found, the value
493 * returned by first filter found to be able to classify the packet otherwise.
494 */
496
497 /**
498 * \enum WakeMode
499 * \brief Used to determine whether the queue disc itself or its children must
500 * be activated when a netdevice wakes a transmission queue
501 */
503 {
504 WAKE_ROOT = 0x00,
505 WAKE_CHILD = 0x01
506 };
507
508 /**
509 * When setting up the wake callbacks on the netdevice queues, it is necessary to
510 * determine which queue disc (the root queue disc or one of its children) should
511 * be activated when the netdevice wakes one of its transmission queues. The
512 * implementation of this method for the base class returns WAKE_ROOT, i.e., the
513 * root queue disc is activated. Subclasses implementing queue discs adopting
514 * a different strategy (e.g., multi-queue aware queue discs such as mq) have
515 * to redefine this method.
516 *
517 * \return the wake mode adopted by this queue disc.
518 */
519 virtual WakeMode GetWakeMode() const;
520
521 // Reasons for dropping packets
522 static constexpr const char* INTERNAL_QUEUE_DROP =
523 "Dropped by internal queue"; //!< Packet dropped by an internal queue
524 static constexpr const char* CHILD_QUEUE_DISC_DROP =
525 "(Dropped by child queue disc) "; //!< Packet dropped by a child queue disc
526 static constexpr const char* CHILD_QUEUE_DISC_MARK =
527 "(Marked by child queue disc) "; //!< Packet marked by a child queue disc
528
529 protected:
530 /**
531 * \brief Dispose of the object
532 */
533 void DoDispose() override;
534
535 /**
536 * \brief Check whether the configuration is correct and initialize parameters
537 *
538 * This method is not virtual to prevent subclasses from redefining it.
539 * Subclasses must instead provide the implementation of the CheckConfig
540 * and InitializeParams methods (which are called by this method).
541 * \sa QueueDisc::InitializeParams
542 * \sa QueueDisc::CheckConfig
543 */
544 void DoInitialize() override;
545
546 /**
547 * \brief Perform the actions required when the queue disc is notified of
548 * a packet dropped before enqueue
549 * \param item item that was dropped
550 * \param reason the reason why the item was dropped
551 * This method must be called by subclasses to record that a packet was
552 * dropped before enqueue for the specified reason
553 */
554 void DropBeforeEnqueue(Ptr<const QueueDiscItem> item, const char* reason);
555
556 /**
557 * \brief Perform the actions required when the queue disc is notified of
558 * a packet dropped after dequeue
559 * \param item item that was dropped
560 * \param reason the reason why the item was dropped
561 * This method must be called by subclasses to record that a packet was
562 * dropped after dequeue for the specified reason
563 */
564 void DropAfterDequeue(Ptr<const QueueDiscItem> item, const char* reason);
565
566 /**
567 * \brief Marks the given packet and, if successful, updates the counters
568 * associated with the given reason
569 * \param item item that has to be marked
570 * \param reason the reason why the item has to be marked
571 * \return true if the item was successfully marked, false otherwise
572 */
573 bool Mark(Ptr<QueueDiscItem> item, const char* reason);
574
575 private:
576 /**
577 * This function actually enqueues a packet into the queue disc.
578 * \param item item to enqueue
579 * \return True if the operation was successful; false otherwise
580 */
581 virtual bool DoEnqueue(Ptr<QueueDiscItem> item) = 0;
582
583 /**
584 * This function actually extracts a packet from the queue disc.
585 * \return 0 if the operation was not successful; the item otherwise.
586 */
588
589 /**
590 * \brief Return a copy of the next packet the queue disc will extract.
591 *
592 * The implementation of this method is based on the qdisc_peek_dequeued
593 * function of the Linux kernel, which dequeues a packet and retains it in the
594 * queue disc as a requeued packet. The packet is not traced as requeued, nor
595 * is the total count of requeued packets increased. The packet is still
596 * considered to be part of the queue disc and the dequeue trace is fired
597 * when Dequeue is called and the packet is actually extracted from the
598 * queue disc.
599 *
600 * This approach is especially recommended for queue discs for which it is not
601 * obvious what is the next packet that will be dequeued (e.g., queue discs
602 * having multiple internal queues or child queue discs or queue discs that
603 * drop packets after dequeue). Subclasses can however provide their own
604 * implementation of this method that overrides the default one.
605 *
606 * \return 0 if the operation was not successful; the packet otherwise.
607 */
609
610 /**
611 * Check whether the current configuration is correct. Default objects (such
612 * as internal queues) might be created by this method to ensure the
613 * configuration is correct. This method is automatically called at
614 * simulation initialization time, and it is called before
615 * the InitializeParams () method. It is appropriate to promote parameter
616 * initialization to this method if it aids in checking for correct
617 * configuration.
618 * \sa QueueDisc::InitializeParams
619 * \return true if the configuration is correct, false otherwise
620 */
621 virtual bool CheckConfig() = 0;
622
623 /**
624 * Initialize parameters (if any) before the first packet is enqueued.
625 * This method is automatically called at simulation initialization time,
626 * after the CheckConfig() method has been called.
627 * \sa QueueDisc::CheckConfig
628 */
629 virtual void InitializeParams() = 0;
630
631 /**
632 * Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
633 * \return false if the qdisc is already running; otherwise, set the qdisc as running and return
634 * true.
635 */
636 bool RunBegin();
637
638 /**
639 * Modelled after the Linux function qdisc_run_end (include/net/sch_generic.h).
640 * Set the qdisc as not running.
641 */
642 void RunEnd();
643
644 /**
645 * Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c)
646 * Dequeue a packet (by calling DequeuePacket) and send it to the device (by calling Transmit).
647 * \return true if a packet is successfully sent to the device.
648 */
649 bool Restart();
650
651 /**
652 * Modelled after the Linux function dequeue_skb (net/sched/sch_generic.c)
653 * \return the requeued packet, if any, or the packet dequeued by the queue disc, otherwise.
654 */
656
657 /**
658 * Modelled after the Linux function dev_requeue_skb (net/sched/sch_generic.c)
659 * Requeues a packet whose transmission failed.
660 * \param item the packet to requeue
661 */
662 void Requeue(Ptr<QueueDiscItem> item);
663
664 /**
665 * Modelled after the Linux function sch_direct_xmit (net/sched/sch_generic.c)
666 * Sends a packet to the device if the device queue is not stopped, and requeues
667 * it otherwise.
668 * \param item the packet to transmit
669 * \return true if the device queue is not stopped and the queue disc is not empty
670 */
671 bool Transmit(Ptr<QueueDiscItem> item);
672
673 /**
674 * \brief Perform the actions required when the queue disc is notified of
675 * a packet enqueue
676 * \param item item that was enqueued
677 */
679
680 /**
681 * \brief Perform the actions required when the queue disc is notified of
682 * a packet dequeue
683 * \param item item that was dequeued
684 */
686
687 /// Default quota (as in /proc/sys/net/core/dev_weight)
688 static const uint32_t DEFAULT_QUOTA = 64;
689
690 std::vector<Ptr<InternalQueue>> m_queues; //!< Internal queues
691 std::vector<Ptr<PacketFilter>> m_filters; //!< Packet filters
692 std::vector<Ptr<QueueDiscClass>> m_classes; //!< Classes
693
694 TracedValue<uint32_t> m_nPackets; //!< Number of packets in the queue
695 TracedValue<uint32_t> m_nBytes; //!< Number of bytes in the queue
696 TracedCallback<Time> m_sojourn; //!< Sojourn time of the latest dequeued packet
697 QueueSize m_maxSize; //!< max queue size
698
699 Stats m_stats; //!< The collected statistics
700 uint32_t m_quota; //!< Maximum number of packets dequeued in a qdisc run
701 Ptr<NetDeviceQueueInterface> m_devQueueIface; //!< NetDevice queue interface
702 SendCallback m_send; //!< Callback used to send a packet to the receiving object
703 bool m_running; //!< The queue disc is performing multiple dequeue operations
704 Ptr<QueueDiscItem> m_requeued; //!< The last packet that failed to be transmitted
705 bool m_peeked; //!< A packet was dequeued because Peek was called
706 std::string m_childQueueDiscDropMsg; //!< Reason why a packet was dropped by a child queue disc
707 std::string m_childQueueDiscMarkMsg; //!< Reason why a packet was marked by a child queue disc
708 QueueDiscSizePolicy m_sizePolicy; //!< The queue disc size policy
709 bool m_prohibitChangeMode; //!< True if changing mode is prohibited
710
711 /// Traced callback: fired when a packet is enqueued
713 /// Traced callback: fired when a packet is dequeued
715 /// Traced callback: fired when a packet is requeued
717 /// Traced callback: fired when a packet is dropped
719 /// Traced callback: fired when a packet is dropped before enqueue
721 /// Traced callback: fired when a packet is dropped after dequeue
723 /// Traced callback: fired when a packet is marked
725
726 /// Type for the function objects notifying that a packet has been dropped by an internal queue
728 /// Type for the function objects notifying that a packet has been dropped by a child queue disc
729 typedef std::function<void(Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscDropFunctor;
730 /// Type for the function objects notifying that a packet has been marked by a child queue disc
731 typedef std::function<void(Ptr<const QueueDiscItem>, const char*)> ChildQueueDiscMarkFunctor;
732
733 /// Function object called when an internal queue dropped a packet before enqueue
735 /// Function object called when an internal queue dropped a packet after dequeue
737 /// Function object called when a child queue disc dropped a packet before enqueue
739 /// Function object called when a child queue disc dropped a packet after dequeue
741 /// Function object called when a child queue disc marked a packet
743};
744
745/**
746 * \brief Stream insertion operator.
747 *
748 * \param os the stream
749 * \param stats the queue disc statistics
750 * \returns a reference to the stream
751 */
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:77
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:573
virtual uint32_t GetQuota() const
Get the maximum number of dequeue operations following a packet enqueue.
Definition: queue-disc.cc:566
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:531
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
Definition: queue-disc.cc:624
QueueSize m_maxSize
max queue size
Definition: queue-disc.h:697
SendCallback GetSendCallback() const
Definition: queue-disc.cc:552
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:432
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:1064
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:439
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:591
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:1050
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:604
TracedCallback< Ptr< const QueueDiscItem > > m_traceDrop
Traced callback: fired when a packet is dropped.
Definition: queue-disc.h:718
QueueSize GetCurrentSize() const
Get the current size of the queue disc in bytes, if operating in bytes mode, or packets,...
Definition: queue-disc.cc:515
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:927
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:667
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:686
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:393
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:538
void Run()
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
Definition: queue-disc.cc:945
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:759
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:979
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
Definition: queue-disc.cc:661
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:412
bool Restart()
Modelled after the Linux function qdisc_restart (net/sched/sch_generic.c) Dequeue a packet (by callin...
Definition: queue-disc.cc:986
QueueSize GetMaxSize() const
Get the maximum size of the queue disc.
Definition: queue-disc.cc:446
Ptr< QueueDiscClass > GetQueueDiscClass(std::size_t i) const
Get the i-th queue disc class.
Definition: queue-disc.cc:654
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:618
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:559
QueueDisc & operator=(const QueueDisc &)=delete
bool RunBegin()
Modelled after the Linux function qdisc_run_begin (include/net/sch_generic.h).
Definition: queue-disc.cc:966
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
Definition: queue-disc.cc:474
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:598
static TypeId GetTypeId()
Get the type ID.
Definition: queue-disc.cc:249
void DoDispose() override
Dispose of the object.
Definition: queue-disc.cc:376
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:680
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:1000
Ptr< QueueDiscItem > Dequeue()
Extract from the queue disc the packet that has been dequeued by calling Peek, if any,...
Definition: queue-disc.cc:886
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:920
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:809
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:720
Ptr< PacketFilter > GetPacketFilter(std::size_t i) const
Get the i-th packet filter.
Definition: queue-disc.cc:611
void PacketDequeued(Ptr< const QueueDiscItem > item)
Perform the actions required when the queue disc is notified of a packet dequeue.
Definition: queue-disc.cc:698
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:851
void SetSendCallback(SendCallback func)
Definition: queue-disc.cc:545
~QueueDisc() override
Definition: queue-disc.cc:370
Template class for packet Queues.
Definition: queue.h:268
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:159
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