A Discrete-Event Network Simulator
API
net-device.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2005,2006 INRIA
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: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
19  */
20 
21 #include "ns3/object.h"
22 #include "ns3/log.h"
23 #include "ns3/abort.h"
24 #include "ns3/uinteger.h"
25 #include "ns3/queue-limits.h"
26 #include "net-device.h"
27 #include "packet.h"
28 
29 namespace ns3 {
30 
31 NS_LOG_COMPONENT_DEFINE ("NetDevice");
32 
34 {
35  m_packet = p;
36 }
37 
39 {
40  NS_LOG_FUNCTION (this);
41  m_packet = 0;
42 }
43 
46 {
47  return m_packet;
48 }
49 
50 uint32_t
52 {
53  NS_ASSERT (m_packet != 0);
54  return m_packet->GetSize ();
55 }
56 
57 bool
58 QueueItem::GetUint8Value (QueueItem::Uint8Values field, uint8_t& value) const
59 {
60  return false;
61 }
62 
63 void
64 QueueItem::Print (std::ostream& os) const
65 {
66  os << GetPacket();
67 }
68 
69 std::ostream & operator << (std::ostream &os, const QueueItem &item)
70 {
71  item.Print (os);
72  return os;
73 }
74 
76  : m_stoppedByDevice (false),
77  m_stoppedByQueueLimits (false)
78 {
79  NS_LOG_FUNCTION (this);
80 }
81 
83 {
84  NS_LOG_FUNCTION (this);
85 }
86 
87 bool
89 {
91 }
92 
93 void
95 {
96  m_stoppedByDevice = false;
97 }
98 
99 void
101 {
102  m_stoppedByDevice = true;
103 }
104 
105 void
107 {
108  Start ();
109 
110  // Request the queue disc to dequeue a packet
111  if (!m_wakeCallback.IsNull ())
112  {
113  m_wakeCallback ();
114  }
115 }
116 
117 void
119 {
120  m_wakeCallback = cb;
121 }
122 
123 void
125 {
126  NS_LOG_FUNCTION (this << bytes);
127  if (!m_queueLimits)
128  {
129  return;
130  }
131  m_queueLimits->Queued (bytes);
132  if (m_queueLimits->Available () >= 0)
133  {
134  return;
135  }
136  m_stoppedByQueueLimits = true;
137 }
138 
139 void
141 {
142  NS_LOG_FUNCTION (this << bytes);
143  if ((!m_queueLimits) || (!bytes))
144  {
145  return;
146  }
147  m_queueLimits->Completed (bytes);
148  if (m_queueLimits->Available () < 0)
149  {
150  return;
151  }
152  m_stoppedByQueueLimits = false;
153  // Request the queue disc to dequeue a packet
154  if (!m_wakeCallback.IsNull ())
155  {
156  m_wakeCallback ();
157  }
158 }
159 
160 void
162 {
163  NS_LOG_FUNCTION (this);
164  if (!m_queueLimits)
165  {
166  return;
167  }
168  m_queueLimits->Reset ();
169 }
170 
171 void
173 {
174  NS_LOG_FUNCTION (this << ql);
175  m_queueLimits = ql;
176 }
177 
180 {
181  NS_LOG_FUNCTION (this);
182  return m_queueLimits;
183 }
184 
185 
187 
189 {
190  static TypeId tid = TypeId ("ns3::NetDeviceQueueInterface")
191  .SetParent<Object> ()
192  .SetGroupName("Network")
193  ;
194  return tid;
195 }
196 
198  : m_numTxQueues (1)
199 {
200  NS_LOG_FUNCTION (this);
201 }
202 
204 {
205  NS_LOG_FUNCTION (this);
206 }
207 
210 {
211  NS_ASSERT (i < m_txQueuesVector.size ());
212  return m_txQueuesVector[i];
213 }
214 
215 uint8_t
217 {
218  return m_txQueuesVector.size ();
219 }
220 
221 void
223 {
224  NS_LOG_FUNCTION (this);
225  m_txQueuesVector.clear ();
227 }
228 
229 void
231 {
232  NS_LOG_FUNCTION (this << numTxQueues);
233  NS_ASSERT (numTxQueues > 0);
234 
235  NS_ABORT_MSG_IF (m_txQueuesVector.size (), "Cannot change the number of"
236  " device transmission queues once they have been created.");
237 
238  m_numTxQueues = numTxQueues;
239 }
240 
241 void
243 {
244  NS_LOG_FUNCTION (this);
245 
246  NS_ABORT_MSG_IF (m_txQueuesVector.size (), "The device transmission queues"
247  " have been already created.");
248 
249  for (uint8_t i = 0; i < m_numTxQueues; i++)
250  {
251  Ptr<NetDeviceQueue> devQueue = Create<NetDeviceQueue> ();
252  m_txQueuesVector.push_back (devQueue);
253  }
254 }
255 
256 void
258 {
260 }
261 
264 {
265  return m_selectQueueCallback;
266 }
267 
269 
271 {
272  static TypeId tid = TypeId ("ns3::NetDevice")
273  .SetParent<Object> ()
274  .SetGroupName("Network")
275  ;
276  return tid;
277 }
278 
280 {
281  NS_LOG_FUNCTION (this);
282 }
283 
284 } // namespace ns3
Base class to represent items of packet Queues.
Definition: net-device.h:56
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint8_t GetNTxQueues(void) const
Get the number of device transmission queues.
Definition: net-device.cc:216
#define NS_OBJECT_ENSURE_REGISTERED(type)
Register an Object subclass with the TypeId system.
Definition: object-base.h:44
QueueItem()
Default constructor.
virtual ~QueueItem()
Definition: net-device.cc:38
bool m_stoppedByDevice
True if the queue has been stopped by the device.
Definition: net-device.h:240
void NotifyQueuedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes queued to the device queue. ...
Definition: net-device.cc:124
bool m_stoppedByQueueLimits
True if the queue has been stopped by a queue limits object.
Definition: net-device.h:241
bool IsNull(void) const
Check for null implementation.
Definition: callback.h:1270
#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.
Definition: net-device.h:243
Ptr< Packet > m_packet
The packet contained in the queue item.
Definition: net-device.h:137
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:792
void SetSelectQueueCallback(SelectQueueCallback cb)
Set the select queue callback.
Definition: net-device.cc:257
virtual void DoDispose(void)
Destructor implementation.
Definition: object.cc:346
virtual ~NetDevice()
Definition: net-device.cc:279
virtual void Start(void)
Called by the device to start this device transmission queue.
Definition: net-device.cc:94
bool IsStopped(void) const
Get the status of the device transmission queue.
Definition: net-device.cc:88
virtual uint32_t GetPacketSize(void) const
Use this method (instead of GetPacket ()->GetSize ()) to get the packet size.
Definition: net-device.cc:51
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device.cc:270
SelectQueueCallback GetSelectQueueCallback(void) const
Get the select queue callback.
Definition: net-device.cc:263
static TypeId GetTypeId(void)
Get the type ID.
Definition: net-device.cc:188
SelectQueueCallback m_selectQueueCallback
Select queue callback.
Definition: net-device.h:343
Network device transmission queue interface.
Definition: net-device.h:262
uint8_t m_numTxQueues
Number of transmission queues to create.
Definition: net-device.h:344
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition: angles.cc:42
void ResetQueueLimits()
Reset queue limits state.
Definition: net-device.cc:161
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.
Definition: net-device.cc:100
std::vector< Ptr< NetDeviceQueue > > m_txQueuesVector
Device transmission queues.
Definition: net-device.h:342
virtual bool GetUint8Value(Uint8Values field, uint8_t &value) const
Retrieve the value of a given field from the packet, if present.
Definition: net-device.cc:58
virtual void DoDispose(void)
Dispose of the object.
Definition: net-device.cc:222
void SetQueueLimits(Ptr< QueueLimits > ql)
Set queue limits to this queue.
Definition: net-device.cc:172
void NotifyTransmittedBytes(uint32_t bytes)
Called by the netdevice to report the number of bytes it is going to transmit.
Definition: net-device.cc:140
Uint8Values
1-byte fields of the packet whose value can be retrieved, if present
Definition: net-device.h:86
virtual void Print(std::ostream &os) const
Print the item contents.
Definition: net-device.cc:64
Ptr< QueueLimits > m_queueLimits
Queue limits object.
Definition: net-device.h:242
NetDeviceQueueInterface()
Constructor.
Definition: net-device.cc:197
#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...
Definition: net-device.cc:106
Network layer to device interface.
Definition: net-device.h:405
Ptr< NetDeviceQueue > GetTxQueue(uint8_t i) const
Get the i-th transmission queue of the device.
Definition: net-device.cc:209
void CreateTxQueues(void)
Create the device transmission queues.
Definition: net-device.cc:242
Ptr< QueueLimits > GetQueueLimits()
Get queue limits to this queue.
Definition: net-device.cc:179
virtual void SetWakeCallback(WakeCallback cb)
Set the wake callback.
Definition: net-device.cc:118
A base class which provides memory management and object aggregation.
Definition: object.h:87
virtual ~NetDeviceQueue()
Definition: net-device.cc:82
a unique identifier for an interface.
Definition: type-id.h:58
TypeId SetParent(TypeId tid)
Set the parent TypeId.
Definition: type-id.cc:904
void SetTxQueuesN(uint8_t numTxQueues)
Set the number of device transmission queues to create.
Definition: net-device.cc:230
Ptr< Packet > GetPacket(void) const
Definition: net-device.cc:45