A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
net-device-queue-interface.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2017 Universita' degli Studi di Napoli Federico II
3 *
4 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stefano.avallone@.unina.it>
7 */
8
10
11#include "queue-item.h"
12#include "queue-limits.h"
13
14#include "ns3/abort.h"
15#include "ns3/uinteger.h"
16
17namespace ns3
18{
19
20NS_LOG_COMPONENT_DEFINE("NetDeviceQueueInterface");
21
22TypeId
24{
25 static TypeId tid = TypeId("ns3::NetDeviceQueue")
27 .SetGroupName("Network")
28 .AddConstructor<NetDeviceQueue>();
29 return tid;
30}
31
33 : m_stoppedByDevice(false),
34 m_stoppedByQueueLimits(false),
35 NS_LOG_TEMPLATE_DEFINE("NetDeviceQueueInterface")
36{
37 NS_LOG_FUNCTION(this);
38}
39
41{
42 NS_LOG_FUNCTION(this);
43
44 m_queueLimits = nullptr;
46 m_device = nullptr;
47}
48
49bool
55
56void
62
63void
69
70void
72{
73 NS_LOG_FUNCTION(this);
74
75 bool wasStoppedByDevice = m_stoppedByDevice;
76 m_stoppedByDevice = false;
77
78 // Request the queue disc to dequeue a packet
79 if (wasStoppedByDevice && !m_wakeCallback.IsNull())
80 {
82 }
83}
84
85void
87{
88 NS_LOG_FUNCTION(this << ndqi);
89
90 m_device = ndqi->GetObject<NetDevice>();
91 NS_ABORT_MSG_IF(!m_device, "No NetDevice object was aggregated to the NetDeviceQueueInterface");
92}
93
94void
99
100void
102{
103 NS_LOG_FUNCTION(this << bytes);
104 if (!m_queueLimits)
105 {
106 return;
107 }
108 m_queueLimits->Queued(bytes);
109 if (m_queueLimits->Available() >= 0)
110 {
111 return;
112 }
114}
115
116void
118{
119 NS_LOG_FUNCTION(this << bytes);
120 if ((!m_queueLimits) || (!bytes))
121 {
122 return;
123 }
124 m_queueLimits->Completed(bytes);
125 if (m_queueLimits->Available() < 0)
126 {
127 return;
128 }
129 bool wasStoppedByQueueLimits = m_stoppedByQueueLimits;
131 // Request the queue disc to dequeue a packet
132 if (wasStoppedByQueueLimits && !m_wakeCallback.IsNull())
133 {
135 }
136}
137
138void
140{
141 NS_LOG_FUNCTION(this);
142 if (!m_queueLimits)
143 {
144 return;
145 }
146 m_queueLimits->Reset();
147}
148
149void
155
162
164
165TypeId
167{
168 static TypeId tid =
169 TypeId("ns3::NetDeviceQueueInterface")
170 .SetParent<Object>()
171 .SetGroupName("Network")
172 .AddConstructor<NetDeviceQueueInterface>()
173 .AddAttribute("TxQueuesType",
174 "The type of transmission queues to be used",
179 .AddAttribute("NTxQueues",
180 "The number of device transmission queues",
182 UintegerValue(1),
186 return tid;
187}
188
190{
191 NS_LOG_FUNCTION(this);
192
193 // the default select queue callback returns 0
194 m_selectQueueCallback = [](Ptr<QueueItem> item) { return 0; };
195}
196
201
204{
205 NS_ASSERT(i < m_txQueuesVector.size());
206 return m_txQueuesVector[i];
207}
208
209std::size_t
211{
212 return m_txQueuesVector.size();
213}
214
215void
223
224void
226{
227 NS_LOG_FUNCTION(this);
228
229 // Notify the NetDeviceQueue objects that an object was aggregated
230 for (auto& tx : m_txQueuesVector)
231 {
232 tx->NotifyAggregatedObject(this);
233 }
235}
236
237void
239{
240 NS_LOG_FUNCTION(this << type);
241
243 "Cannot call SetTxQueuesType after creating device queues");
244
246 m_txQueues.SetTypeId(type);
247}
248
249void
251{
252 NS_LOG_FUNCTION(this << numTxQueues);
253 NS_ASSERT(numTxQueues > 0);
254
256 "Cannot call SetNTxQueues after creating device queues");
257
258 // create the netdevice queues
259 for (std::size_t i = 0; i < numTxQueues; i++)
260 {
262 }
263}
264
265void
270
276
277} // namespace ns3
void Nullify()
Discard the implementation, set it to null.
Definition callback.h:561
bool IsNull() const
Check for null implementation.
Definition callback.h:555
Network layer to device interface.
Definition net-device.h:87
Network device transmission queue.
bool m_stoppedByQueueLimits
True if the queue has been stopped by a queue limits object.
virtual void Stop()
Called by the device to stop this device transmission queue.
void NotifyAggregatedObject(Ptr< NetDeviceQueueInterface > ndqi)
Notify this NetDeviceQueue that the NetDeviceQueueInterface was aggregated to an object.
Ptr< QueueLimits > GetQueueLimits()
Get queue limits to this queue.
Ptr< QueueLimits > m_queueLimits
Queue limits object.
virtual void Wake()
Called by the device to wake the queue disc associated with this device transmission queue.
virtual bool IsStopped() const
Get the status of the device transmission queue.
void SetQueueLimits(Ptr< QueueLimits > ql)
Set queue limits to this queue.
void ResetQueueLimits()
Reset queue limits state.
virtual void Start()
Called by the device to start this device transmission queue.
virtual void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
virtual void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue.
Ptr< NetDevice > m_device
the netdevice aggregated to the NetDeviceQueueInterface
WakeCallback m_wakeCallback
Wake callback.
bool m_stoppedByDevice
True if the queue has been stopped by the device.
static TypeId GetTypeId()
Get the type ID.
virtual void SetWakeCallback(WakeCallback cb)
Set the wake callback.
Network device transmission queue interface.
SelectQueueCallback m_selectQueueCallback
Select queue callback.
std::vector< Ptr< NetDeviceQueue > > m_txQueuesVector
Device transmission queues.
std::size_t GetNTxQueues() const
Get the number of device transmission queues.
Ptr< NetDeviceQueue > GetTxQueue(std::size_t i) const
Get the i-th transmission queue of the device.
std::function< std::size_t(Ptr< QueueItem >)> SelectQueueCallback
Callback invoked to determine the tx queue selected for a given packet.
ObjectFactory m_txQueues
Device transmission queues TypeId.
void SetSelectQueueCallback(SelectQueueCallback cb)
Set the select queue callback.
void DoDispose() override
Dispose of the object.
SelectQueueCallback GetSelectQueueCallback() const
Get the select queue callback.
void SetTxQueuesType(TypeId type)
Set the type of device transmission queues to create.
void SetNTxQueues(std::size_t numTxQueues)
Set the number of device transmission queues to create.
void NotifyNewAggregate() override
Notify that an object was aggregated.
static TypeId GetTypeId()
Get the type ID.
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.
A base class which provides memory management and object aggregation.
Definition object.h:78
friend class ObjectFactory
Friends.
Definition object.h:357
virtual void NotifyNewAggregate()
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition object.cc:412
Ptr< T > GetObject() const
Get a pointer to the requested aggregated Object.
Definition object.h:511
virtual void DoDispose()
Destructor implementation.
Definition object.cc:433
Smart pointer class similar to boost::intrusive_ptr.
a unique identifier for an interface.
Definition type-id.h:48
@ ATTR_GET
The attribute can be read.
Definition type-id.h:53
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
Definition type-id.h:55
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition type-id.cc:1001
Hold an unsigned integer type.
Definition uinteger.h:34
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition assert.h:55
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition abort.h:97
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition log.h:225
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition object-base.h:35
Every class exported by the ns3 library is enclosed in the ns3 namespace.
Ptr< const AttributeChecker > MakeUintegerChecker()
Definition uinteger.h:85
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Definition uinteger.h:35
Ptr< const AttributeChecker > MakeTypeIdChecker()
Definition type-id.cc:1320
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Definition type-id.h:617