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/log.h"
22 #include "ns3/abort.h"
23 #include "ns3/queue-limits.h"
24 #include "ns3/net-device-queue-interface.h"
25 #include "ns3/simulator.h"
26 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("NetDeviceQueueInterface");
30 
32  : m_stoppedByDevice (false),
33  m_stoppedByQueueLimits (false)
34 {
35  NS_LOG_FUNCTION (this);
36 }
37 
39 {
40  NS_LOG_FUNCTION (this);
41 }
42 
43 bool
45 {
46  NS_LOG_FUNCTION (this);
48 }
49 
50 void
52 {
53  NS_LOG_FUNCTION (this);
54  m_stoppedByDevice = false;
55 }
56 
57 void
59 {
60  NS_LOG_FUNCTION (this);
61  m_stoppedByDevice = true;
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION (this);
68 
69  bool wasStoppedByDevice = m_stoppedByDevice;
70  m_stoppedByDevice = false;
71 
72  // Request the queue disc to dequeue a packet
73  if (wasStoppedByDevice && !m_wakeCallback.IsNull ())
74  {
76  }
77 }
78 
79 void
81 {
82  m_wakeCallback = cb;
83 }
84 
85 void
87 {
88  NS_LOG_FUNCTION (this << bytes);
89  if (!m_queueLimits)
90  {
91  return;
92  }
93  m_queueLimits->Queued (bytes);
94  if (m_queueLimits->Available () >= 0)
95  {
96  return;
97  }
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION (this << bytes);
105  if ((!m_queueLimits) || (!bytes))
106  {
107  return;
108  }
109  m_queueLimits->Completed (bytes);
110  if (m_queueLimits->Available () < 0)
111  {
112  return;
113  }
114  bool wasStoppedByQueueLimits = m_stoppedByQueueLimits;
115  m_stoppedByQueueLimits = false;
116  // Request the queue disc to dequeue a packet
117  if (wasStoppedByQueueLimits && !m_wakeCallback.IsNull ())
118  {
120  }
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this);
127  if (!m_queueLimits)
128  {
129  return;
130  }
131  m_queueLimits->Reset ();
132 }
133 
134 void
136 {
137  NS_LOG_FUNCTION (this << ql);
138  m_queueLimits = ql;
139 }
140 
143 {
144  NS_LOG_FUNCTION (this);
145  return m_queueLimits;
146 }
147 
148 
150 
152 {
153  static TypeId tid = TypeId ("ns3::NetDeviceQueueInterface")
154  .SetParent<Object> ()
155  .SetGroupName("Network")
156  .AddConstructor<NetDeviceQueueInterface> ()
157  ;
158  return tid;
159 }
160 
162  : m_numTxQueues (1),
163  m_lateTxQueuesCreation (false)
164 {
165  NS_LOG_FUNCTION (this);
166 }
167 
169 {
170  NS_LOG_FUNCTION (this);
171 }
172 
175 {
176  NS_ASSERT (i < m_txQueuesVector.size ());
177  return m_txQueuesVector[i];
178 }
179 
180 uint8_t
182 {
183  return m_txQueuesVector.size ();
184 }
185 
186 void
188 {
189  NS_LOG_FUNCTION (this);
190 
191  for (auto t : m_traceMap)
192  {
193  if (!t.first->TraceDisconnectWithoutContext ("Enqueue", t.second[0])
194  || !t.first->TraceDisconnectWithoutContext ("Dequeue", t.second[1])
195  || !t.first->TraceDisconnectWithoutContext ("DropAfterDequeue", t.second[1])
196  || !t.first->TraceDisconnectWithoutContext ("DropBeforeEnqueue", t.second[2]))
197  {
198  NS_LOG_WARN ("NetDeviceQueueInterface: Trying to disconnected a callback that"
199  " has not been connected to a traced callback");
200  }
201  }
202 
203  m_traceMap.clear ();
204  m_txQueuesVector.clear ();
206 }
207 
208 void
210 {
211  NS_LOG_FUNCTION (this << numTxQueues);
212  NS_ASSERT (numTxQueues > 0);
213 
214  NS_ABORT_MSG_IF (m_txQueuesVector.size (), "Cannot change the number of"
215  " device transmission queues once they have been created.");
216 
217  m_numTxQueues = numTxQueues;
218 }
219 
220 void
222 {
223  NS_LOG_FUNCTION (this);
224 
225  NS_ABORT_MSG_IF (m_txQueuesVector.size (), "The device transmission queues"
226  " have been already created.");
227 
228  for (uint8_t i = 0; i < m_numTxQueues; i++)
229  {
230  Ptr<NetDeviceQueue> devQueue = Create<NetDeviceQueue> ();
231  m_txQueuesVector.push_back (devQueue);
232  }
233 }
234 
235 bool
237 {
238  return m_lateTxQueuesCreation;
239 }
240 
241 void
243 {
244  NS_LOG_FUNCTION (this << value);
245  m_lateTxQueuesCreation = value;
246 }
247 
248 void
250 {
252 }
253 
256 {
257  return m_selectQueueCallback;
258 }
259 
260 } // namespace ns3
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
std::map< Ptr< QueueBase >, std::vector< CallbackBase > > m_traceMap
Map storing all the connected traces.
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:45
bool m_stoppedByDevice
True if the queue has been stopped by the device.
void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue. ...
bool m_stoppedByQueueLimits
True if the queue has been stopped by a queue limits object.
#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
WakeCallback m_wakeCallback
Wake callback.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
void SetSelectQueueCallback(SelectQueueCallback cb)
Set the select queue callback.
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
uint8_t GetNTxQueues(void) const
Get the number of device transmission queues.
bool IsStopped(void) const
Get the status of the device transmission queue.
virtual void Start(void)
Called by the device to start this device transmission queue.
bool GetLateTxQueuesCreation(void) const
Get the value of the late TX queues creation flag.
static TypeId GetTypeId(void)
Get the type ID.
SelectQueueCallback m_selectQueueCallback
Select queue callback.
Network device transmission queue interface.
SelectQueueCallback GetSelectQueueCallback(void) const
Get the select queue callback.
uint8_t m_numTxQueues
Number of transmission queues to create.
bool m_lateTxQueuesCreation
True if a device wants to create the TX queues by itself.
void ResetQueueLimits()
Reset queue limits state.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
virtual void Stop(void)
Called by the device to stop this device transmission queue.
std::vector< Ptr< NetDeviceQueue > > m_txQueuesVector
Device transmission queues.
virtual void DoDispose(void)
Dispose of the object.
void SetQueueLimits(Ptr< QueueLimits > ql)
Set queue limits to this queue.
static EventId ScheduleNow(MEM mem_ptr, OBJ obj)
Schedule an event to expire Now.
Definition: simulator.h:1570
void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
void SetLateTxQueuesCreation(bool value)
Set the late TX queues creation flag.
Ptr< QueueLimits > m_queueLimits
Queue limits object.
#define NS_ABORT_MSG_IF(cond, msg)
Abnormal program termination if a condition is true, with a message.
Definition: abort.h:108
virtual void Wake(void)
Called by the device to wake the queue disc associated with this device transmission queue...
#define NS_LOG_WARN(msg)
Use NS_LOG to output a message of level LOG_WARN.
Definition: log.h:262
void CreateTxQueues(void)
Create the device transmission queues.
Ptr< QueueLimits > GetQueueLimits()
Get queue limits to this queue.
virtual void SetWakeCallback(WakeCallback cb)
Set the wake callback.
Ptr< NetDeviceQueue > GetTxQueue(uint8_t i) const
Get the i-th transmission queue of the device.
A base class which provides memory management and object aggregation.
Definition: object.h:87
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:915
void SetTxQueuesN(uint8_t numTxQueues)
Set the number of device transmission queues to create.