20#include "ns3/attribute.h"
21#include "ns3/drop-tail-queue.h"
24#include "ns3/net-device-queue-interface.h"
25#include "ns3/object-factory.h"
26#include "ns3/simulator.h"
27#include "ns3/uinteger.h"
40 TypeId(
"ns3::TbfQueueDisc")
42 .SetGroupName(
"TrafficControl")
44 .AddAttribute(
"MaxSize",
49 .AddAttribute(
"Burst",
50 "Size of the first bucket in bytes",
55 "Size of the second bucket in bytes. If null, it is initialized"
56 " to the MTU of the receiving NetDevice (if any)",
61 "Rate at which tokens enter the first bucket in bps or Bps.",
65 .AddAttribute(
"PeakRate",
66 "Rate at which tokens enter the second bucket in bps or Bps."
67 "If null, there is no second bucket",
71 .AddTraceSource(
"TokensInFirstBucket",
72 "Number of First Bucket Tokens in bytes",
74 "ns3::TracedValueCallback::Uint32")
75 .AddTraceSource(
"TokensInSecondBucket",
76 "Number of Second Bucket Tokens in bytes",
78 "ns3::TracedValueCallback::Uint32");
212 NS_LOG_LOGIC(
"Number of ptokens we can consume " << ptoks);
224 NS_LOG_LOGIC(
"Number of btokens we can consume " << btoks);
228 if ((btoks | ptoks) >= 0)
233 NS_LOG_DEBUG(
"That's odd! Expecting the peeked packet, we got no packet.");
242 <<
" ptokens after packet dequeue");
256 Time requiredDelayTime;
259 NS_ASSERT_MSG(btoks < 0,
"Logic error; btoks must be < 0 here");
264 if (btoks < 0 && ptoks >= 0)
268 else if (btoks >= 0 && ptoks < 0)
292 NS_LOG_ERROR(
"TbfQueueDisc cannot have internal queues");
298 NS_LOG_ERROR(
"TbfQueueDisc cannot have packet filters");
311 NS_LOG_ERROR(
"Cannot set the max size of the child queue disc to that of TbfQueueDisc");
336 if (ndqi && (dev = ndqi->GetObject<
NetDevice>()))
338 m_mtu = dev->GetMtu();
345 "A non-null peak rate has been set, but the mtu is null. No packet will be dequeued");
353 <<
"greater than the size of the second bucket (" <<
m_mtu <<
").");
360 <<
"greater than the rate for the first bucket (" <<
m_rate <<
").");
Class for representing data rates.
uint64_t GetBitRate() const
Get the underlying bitrate.
Time CalculateBytesTxTime(uint32_t bytes) const
Calculate transmission time.
An identifier for simulation events.
bool IsExpired() const
This method is syntactic sugar for the ns3::Simulator::IsExpired method.
Network layer to device interface.
Instantiate subclasses of ns3::Object.
Ptr< Object > Create() const
Create an Object instance of the configured TypeId.
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Smart pointer class similar to boost::intrusive_ptr.
QueueDisc is an abstract base class providing the interface and implementing the operations common to...
void AddQueueDiscClass(Ptr< QueueDiscClass > qdClass)
Add a queue disc class to the tail of the list of classes.
uint32_t GetNPackets() const
Get the number of packets stored by the queue disc.
uint32_t GetNBytes() const
Get the amount of bytes stored by the queue disc.
Ptr< NetDeviceQueueInterface > GetNetDeviceQueueInterface() const
void Run()
Modelled after the Linux function __qdisc_run (net/sched/sch_generic.c) Dequeues multiple packets,...
std::size_t GetNQueueDiscClasses() const
Get the number of queue disc classes.
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.
std::size_t GetNPacketFilters() const
Get the number of packet filters.
bool SetMaxSize(QueueSize size)
Set the maximum size of the queue disc.
std::size_t GetNInternalQueues() const
Get the number of internal queues.
void DoDispose() override
Dispose of the object.
Class for representing queue sizes.
static EventId Schedule(const Time &delay, FUNC f, Ts &&... args)
Schedule an event to expire after delay.
static Time Now()
Return the current simulation virtual time.
DataRate GetRate() const
Get the rate of the tokens entering the first bucket.
TbfQueueDisc()
TbfQueueDisc Constructor.
void SetBurst(uint32_t burst)
Set the size of the first bucket in bytes.
TracedValue< uint32_t > m_ptokens
Current number of tokens in second bucket.
Ptr< QueueDiscItem > DoDequeue() override
This function actually extracts a packet from the queue disc.
Time m_timeCheckPoint
Time check-point.
uint32_t m_mtu
Size of second bucket in bytes.
~TbfQueueDisc() override
Destructor.
void DoDispose() override
Dispose of the object.
bool DoEnqueue(Ptr< QueueDiscItem > item) override
This function actually enqueues a packet into the queue disc.
void SetPeakRate(DataRate peakRate)
Set the rate of the tokens entering the second bucket.
uint32_t m_burst
Size of first bucket in bytes.
DataRate m_rate
Rate at which tokens enter the first bucket.
EventId m_id
EventId of the scheduled queue waking event when enough tokens are available.
void InitializeParams() override
Initialize parameters (if any) before the first packet is enqueued.
DataRate GetPeakRate() const
Get the rate of the tokens entering the second bucket.
void SetRate(DataRate rate)
Set the rate of the tokens entering the first bucket.
void SetMtu(uint32_t mtu)
Set the size of the second bucket in bytes.
uint32_t GetBurst() const
Get the size of the first bucket in bytes.
uint32_t GetFirstBucketTokens() const
Get the current number of tokens inside the first bucket in bytes.
static TypeId GetTypeId()
Get the type ID.
bool CheckConfig() override
Check whether the current configuration is correct.
uint32_t GetSecondBucketTokens() const
Get the current number of tokens inside the second bucket in bytes.
uint32_t GetMtu() const
Get the size of the second bucket in bytes.
TracedValue< uint32_t > m_btokens
Current number of tokens in first bucket.
DataRate m_peakRate
Rate at which tokens enter the second bucket.
Simulation virtual time values and global simulation resolution.
TimeWithUnit As(const Unit unit=Time::AUTO) const
Attach a unit to a Time, to facilitate output in a specific unit.
double GetSeconds() const
Get an approximation of the time stored in this instance in the indicated unit.
a unique identifier for an interface.
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Hold an unsigned integer type.
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
#define NS_LOG_ERROR(msg)
Use NS_LOG to output a message of level LOG_ERROR.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
#define NS_LOG_LOGIC(msg)
Use NS_LOG to output a message of level LOG_LOGIC.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Ptr< T > CreateObject(Args &&... args)
Create an object by type, with varying number of constructor parameters.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Time Seconds(double value)
Construct a Time in the indicated unit.
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
Create a TraceSourceAccessor which will control access to the underlying trace source.
QueueDiscSizePolicy
Enumeration of the available policies to handle the queue disc size.
@ SINGLE_CHILD_QUEUE_DISC
Used by queue discs with single child queue disc.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeAccessor > MakeQueueSizeAccessor(T1 a1)
Ptr< const AttributeChecker > MakeUintegerChecker()
Ptr< const AttributeAccessor > MakeDataRateAccessor(T1 a1)
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Ptr< const AttributeChecker > MakeDataRateChecker()
Ptr< const AttributeChecker > MakeQueueSizeChecker()
uint32_t pktSize
packet size used for the simulation (in bytes)