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