A Discrete-Event Network Simulator
API
net-device-queue-interface.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2017 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  * Author: Stefano Avallone <stefano.avallone@.unina.it>
19  */
20 
21 #include "ns3/abort.h"
22 #include "ns3/queue-limits.h"
23 #include "ns3/net-device-queue-interface.h"
24 #include "ns3/simulator.h"
25 #include "ns3/uinteger.h"
26 #include "ns3/queue-item.h"
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("NetDeviceQueueInterface");
31 
32 TypeId
34 {
35  static TypeId tid = TypeId ("ns3::NetDeviceQueue")
36  .SetParent<Object> ()
37  .SetGroupName("Network")
38  .AddConstructor<NetDeviceQueue> ()
39  ;
40  return tid;
41 }
42 
44  : m_stoppedByDevice (false),
45  m_stoppedByQueueLimits (false),
46  NS_LOG_TEMPLATE_DEFINE ("NetDeviceQueueInterface")
47 {
48  NS_LOG_FUNCTION (this);
49 }
50 
52 {
53  NS_LOG_FUNCTION (this);
54 
55  m_queueLimits = 0;
57  m_device = 0;
58 }
59 
60 bool
62 {
63  NS_LOG_FUNCTION (this);
65 }
66 
67 void
69 {
70  NS_LOG_FUNCTION (this);
71  m_stoppedByDevice = false;
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION (this);
78  m_stoppedByDevice = true;
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION (this);
85 
86  bool wasStoppedByDevice = m_stoppedByDevice;
87  m_stoppedByDevice = false;
88 
89  // Request the queue disc to dequeue a packet
90  if (wasStoppedByDevice && !m_wakeCallback.IsNull ())
91  {
93  }
94 }
95 
96 void
98 {
99  NS_LOG_FUNCTION (this << ndqi);
100 
101  m_device = ndqi->GetObject<NetDevice> ();
102  NS_ABORT_MSG_IF (!m_device, "No NetDevice object was aggregated to the NetDeviceQueueInterface");
103 }
104 
105 void
107 {
108  m_wakeCallback = cb;
109 }
110 
111 void
113 {
114  NS_LOG_FUNCTION (this << bytes);
115  if (!m_queueLimits)
116  {
117  return;
118  }
119  m_queueLimits->Queued (bytes);
120  if (m_queueLimits->Available () >= 0)
121  {
122  return;
123  }
124  m_stoppedByQueueLimits = true;
125 }
126 
127 void
129 {
130  NS_LOG_FUNCTION (this << bytes);
131  if ((!m_queueLimits) || (!bytes))
132  {
133  return;
134  }
135  m_queueLimits->Completed (bytes);
136  if (m_queueLimits->Available () < 0)
137  {
138  return;
139  }
140  bool wasStoppedByQueueLimits = m_stoppedByQueueLimits;
141  m_stoppedByQueueLimits = false;
142  // Request the queue disc to dequeue a packet
143  if (wasStoppedByQueueLimits && !m_wakeCallback.IsNull ())
144  {
146  }
147 }
148 
149 void
151 {
152  NS_LOG_FUNCTION (this);
153  if (!m_queueLimits)
154  {
155  return;
156  }
157  m_queueLimits->Reset ();
158 }
159 
160 void
162 {
163  NS_LOG_FUNCTION (this << ql);
164  m_queueLimits = ql;
165 }
166 
169 {
170  NS_LOG_FUNCTION (this);
171  return m_queueLimits;
172 }
173 
174 
176 
177 TypeId
179 {
180  static TypeId tid = TypeId ("ns3::NetDeviceQueueInterface")
181  .SetParent<Object> ()
182  .SetGroupName("Network")
183  .AddConstructor<NetDeviceQueueInterface> ()
184  .AddAttribute ("TxQueuesType",
185  "The type of transmission queues to be used",
190  .AddAttribute ("NTxQueues", "The number of device transmission queues",
192  UintegerValue (1),
195  MakeUintegerChecker<uint16_t> (1, 65535))
196  ;
197  return tid;
198 }
199 
201 {
202  NS_LOG_FUNCTION (this);
203 
204  // the default select queue callback returns 0
205  m_selectQueueCallback = [] (Ptr<QueueItem> item) { return 0; };
206 }
207 
209 {
210  NS_LOG_FUNCTION (this);
211 }
212 
215 {
216  NS_ASSERT (i < m_txQueuesVector.size ());
217  return m_txQueuesVector[i];
218 }
219 
220 std::size_t
222 {
223  return m_txQueuesVector.size ();
224 }
225 
226 void
228 {
229  NS_LOG_FUNCTION (this);
230 
231  m_txQueuesVector.clear ();
233 }
234 
235 void
237 {
238  NS_LOG_FUNCTION (this);
239 
240  // Notify the NetDeviceQueue objects that an object was aggregated
241  for (auto& tx : m_txQueuesVector)
242  {
243  tx->NotifyAggregatedObject (this);
244  }
246 }
247 
248 void
250 {
251  NS_LOG_FUNCTION (this << type);
252 
253  NS_ABORT_MSG_IF (!m_txQueuesVector.empty (), "Cannot call SetTxQueuesType after creating device queues");
254 
256  m_txQueues.SetTypeId (type);
257 }
258 
259 void
260 NetDeviceQueueInterface::SetNTxQueues (std::size_t numTxQueues)
261 {
262  NS_LOG_FUNCTION (this << numTxQueues);
263  NS_ASSERT (numTxQueues > 0);
264 
265  NS_ABORT_MSG_IF (!m_txQueuesVector.empty (), "Cannot call SetNTxQueues after creating device queues");
266 
267  // create the netdevice queues
268  for (std::size_t i = 0; i < numTxQueues; i++)
269  {
271  }
272 }
273 
274 void
276 {
278 }
279 
282 {
283  return m_selectQueueCallback;
284 }
285 
286 } // namespace ns3
ns3::TypeId
a unique identifier for an interface.
Definition: type-id.h:59
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::Object::NotifyNewAggregate
virtual void NotifyNewAggregate(void)
Notify all Objects aggregated to this one of a new Object being aggregated.
Definition: object.cc:325
ns3::NetDeviceQueueInterface::NotifyNewAggregate
virtual void NotifyNewAggregate(void)
Notify that an object was aggregated.
Definition: net-device-queue-interface.cc:236
NS_OBJECT_ENSURE_REGISTERED
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
NS_ASSERT
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:67
ns3::TypeId::ATTR_CONSTRUCT
@ ATTR_CONSTRUCT
The attribute can be written at construction-time.
Definition: type-id.h:66
ns3::NetDeviceQueueInterface::m_txQueues
ObjectFactory m_txQueues
Device transmission queues TypeId.
Definition: net-device-queue-interface.h:313
ns3::NetDeviceQueueInterface::GetTxQueue
Ptr< NetDeviceQueue > GetTxQueue(std::size_t i) const
Get the i-th transmission queue of the device.
Definition: net-device-queue-interface.cc:214
ns3::Callback< void >
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::NetDeviceQueue::m_wakeCallback
WakeCallback m_wakeCallback
Wake callback.
Definition: net-device-queue-interface.h:210
ns3::Callback::IsNull
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1386
ns3::NetDeviceQueue::SetQueueLimits
void SetQueueLimits(Ptr< QueueLimits > ql)
Set queue limits to this queue.
Definition: net-device-queue-interface.cc:161
ns3::NetDeviceQueue::Wake
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue.
Definition: net-device-queue-interface.cc:82
ns3::NetDeviceQueueInterface::SetTxQueuesType
void SetTxQueuesType(TypeId type)
Set the type of device transmission queues to create.
Definition: net-device-queue-interface.cc:249
ns3::Object::GetObject
Ptr< T > GetObject(void) const
Get a pointer to the requested aggregated Object.
Definition: object.h:470
ns3::NetDeviceQueueInterface::GetSelectQueueCallback
SelectQueueCallback GetSelectQueueCallback(void) const
Get the select queue callback.
Definition: net-device-queue-interface.cc:281
ns3::TypeId::ATTR_GET
@ ATTR_GET
The attribute can be read.
Definition: type-id.h:64
ns3::NetDeviceQueue::m_queueLimits
Ptr< QueueLimits > m_queueLimits
Queue limits object.
Definition: net-device-queue-interface.h:209
ns3::TypeId::SetParent
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:923
ns3::NetDeviceQueueInterface::~NetDeviceQueueInterface
virtual ~NetDeviceQueueInterface()
Definition: net-device-queue-interface.cc:208
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::NetDeviceQueueInterface::DoDispose
virtual void DoDispose(void)
Dispose of the object.
Definition: net-device-queue-interface.cc:227
ns3::NetDeviceQueueInterface::NetDeviceQueueInterface
NetDeviceQueueInterface()
Constructor.
Definition: net-device-queue-interface.cc:200
ns3::TypeIdValue
AttributeValue implementation for TypeId.
Definition: type-id.h:595
ns3::NetDeviceQueue::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device-queue-interface.cc:33
ns3::Object
A base class which provides memory management and object aggregation.
Definition: object.h:88
ns3::NetDeviceQueue::IsStopped
virtual bool IsStopped(void) const
Get the status of the device transmission queue.
Definition: net-device-queue-interface.cc:61
ns3::NetDeviceQueue::m_device
Ptr< NetDevice > m_device
the netdevice aggregated to the NetDeviceQueueInterface
Definition: net-device-queue-interface.h:211
ns3::NetDeviceQueueInterface::SetNTxQueues
void SetNTxQueues(std::size_t numTxQueues)
Set the number of device transmission queues to create.
Definition: net-device-queue-interface.cc:260
ns3::NetDeviceQueue
Network device transmission queue.
Definition: net-device-queue-interface.h:57
ns3::NetDeviceQueue::m_stoppedByQueueLimits
bool m_stoppedByQueueLimits
True if the queue has been stopped by a queue limits object.
Definition: net-device-queue-interface.h:208
NS_ABORT_MSG_IF
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
ns3::Object::ObjectFactory
friend class ObjectFactory
Friends.
Definition: object.h:328
ns3::NetDeviceQueueInterface::SetSelectQueueCallback
void SetSelectQueueCallback(SelectQueueCallback cb)
Set the select queue callback.
Definition: net-device-queue-interface.cc:275
ns3::NetDeviceQueue::NetDeviceQueue
NetDeviceQueue()
Definition: net-device-queue-interface.cc:43
ns3::NetDeviceQueue::~NetDeviceQueue
virtual ~NetDeviceQueue()
Definition: net-device-queue-interface.cc:51
ns3::NetDeviceQueue::Stop
virtual void Stop(void)
Called by the device to stop this device transmission queue.
Definition: net-device-queue-interface.cc:75
ns3::NetDeviceQueueInterface
Network device transmission queue interface.
Definition: net-device-queue-interface.h:231
ns3::NetDeviceQueue::m_stoppedByDevice
bool m_stoppedByDevice
True if the queue has been stopped by the device.
Definition: net-device-queue-interface.h:207
ns3::NetDeviceQueueInterface::m_txQueuesVector
std::vector< Ptr< NetDeviceQueue > > m_txQueuesVector
Device transmission queues.
Definition: net-device-queue-interface.h:314
NS_LOG_TEMPLATE_DEFINE
#define NS_LOG_TEMPLATE_DEFINE(name)
Initialize a reference to a Log component.
Definition: log.h:239
ns3::NetDeviceQueueInterface::m_selectQueueCallback
SelectQueueCallback m_selectQueueCallback
Select queue callback.
Definition: net-device-queue-interface.h:315
ns3::NetDeviceQueue::NotifyQueuedBytes
virtual void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue.
Definition: net-device-queue-interface.cc:112
ns3::NetDeviceQueue::SetWakeCallback
virtual void SetWakeCallback(WakeCallback cb)
Set the wake callback.
Definition: net-device-queue-interface.cc:106
ns3::NetDeviceQueueInterface::SelectQueueCallback
std::function< std::size_t(Ptr< QueueItem >)> SelectQueueCallback
Callback invoked to determine the tx queue selected for a given packet.
Definition: net-device-queue-interface.h:282
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
ns3::NetDeviceQueue::NotifyAggregatedObject
void NotifyAggregatedObject(Ptr< NetDeviceQueueInterface > ndqi)
Notify this NetDeviceQueue that the NetDeviceQueueInterface was aggregated to an object.
Definition: net-device-queue-interface.cc:97
ns3::ObjectFactory::SetTypeId
void SetTypeId(TypeId tid)
Set the TypeId of the Objects to be created by this factory.
Definition: object-factory.cc:40
ns3::UintegerValue
Hold an unsigned integer type.
Definition: uinteger.h:44
ns3::NetDeviceQueue::GetQueueLimits
Ptr< QueueLimits > GetQueueLimits()
Get queue limits to this queue.
Definition: net-device-queue-interface.cc:168
ns3::ObjectFactory::Create
Ptr< Object > Create(void) const
Create an Object instance of the configured TypeId.
Definition: object-factory.cc:98
ns3::NetDeviceQueue::Start
virtual void Start(void)
Called by the device to start this device transmission queue.
Definition: net-device-queue-interface.cc:68
ns3::NetDeviceQueue::NotifyTransmittedBytes
virtual void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
Definition: net-device-queue-interface.cc:128
ns3::MakeUintegerAccessor
Ptr< const AttributeAccessor > MakeUintegerAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: uinteger.h:45
ns3::NetDeviceQueueInterface::GetNTxQueues
std::size_t GetNTxQueues(void) const
Get the number of device transmission queues.
Definition: net-device-queue-interface.cc:221
ns3::NetDeviceQueue::ResetQueueLimits
void ResetQueueLimits()
Reset queue limits state.
Definition: net-device-queue-interface.cc:150
ns3::Object::DoDispose
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
ns3::Simulator::ScheduleNow
static EventId ScheduleNow(FUNC f, Ts &&... args)
Schedule an event to expire Now.
Definition: simulator.h:588
ns3::NetDeviceQueueInterface::GetTypeId
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device-queue-interface.cc:178
ns3::MakeTypeIdChecker
Ptr< const AttributeChecker > MakeTypeIdChecker(void)
Definition: type-id.cc:1227
ns3::MakeTypeIdAccessor
Ptr< const AttributeAccessor > MakeTypeIdAccessor(T1 a1)
Create an AttributeAccessor for a class data member, or a lone class get functor or set method.
Definition: type-id.h:595
ns3::NetDevice
Network layer to device interface.
Definition: net-device.h:96
ns3::Callback::Nullify
void Nullify(void)
Discard the implementation, set it to null.
Definition: callback.h:1391