A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
wimax-mac-queue.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007,2008 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
18 */
19
20#ifndef WIMAX_MAC_QUEUE_H
21#define WIMAX_MAC_QUEUE_H
22
23#include "wimax-mac-header.h"
24
25#include "ns3/nstime.h"
26#include "ns3/object.h"
27#include "ns3/packet.h"
28#include "ns3/traced-callback.h"
29
30#include <queue>
31#include <stdint.h>
32
33namespace ns3
34{
35
36/**
37 * \ingroup wimax
38 * Class implementing the device packet queue
39 */
40class WimaxMacQueue : public Object
41{
42 public:
43 /**
44 * \brief Get the type ID.
45 * \return the object TypeId
46 */
47 static TypeId GetTypeId();
49 /**
50 * Constructor
51 *
52 * \param maxSize maximum size of queue
53 */
54 WimaxMacQueue(uint32_t maxSize);
55 ~WimaxMacQueue() override;
56 /**
57 * \brief set the maximum queue size
58 * \param maxSize the max queue size
59 */
60 void SetMaxSize(uint32_t maxSize);
61 /**
62 * \return the maximum queue size
63 */
64 uint32_t GetMaxSize() const;
65 /**
66 * \brief Enqueue a packet
67 * \param packet the packet to enqueue
68 * \param hdrType the mac header type of the packet
69 * \param hdr the header of the packet
70 * \return true if successful
71 */
72 bool Enqueue(Ptr<Packet> packet, const MacHeaderType& hdrType, const GenericMacHeader& hdr);
73 /**
74 * \brief Dequeue a packet of type packetType from the queue
75 * \param packetType the type of the packet
76 * \return the first packet in the queue
77 */
79 /**
80 * \brief Dequeue a fragment of size availableByte from the queue
81 * \param packetType the type of the packet
82 * \param availableByte the size of the fragment
83 * \return the first packet in the queue if its size is lower than availableByte, the first
84 * availableByte of the first packet otherwise
85 */
86 Ptr<Packet> Dequeue(MacHeaderType::HeaderType packetType, uint32_t availableByte);
87
88 /**
89 * \brief Exclusively for BS.
90 * Two versions of Peek function (with Generic MAC Header as parameter) only
91 * for BS, as BS's scheduler needs to know the CID in Generic MAC Header.
92 * \param hdr the header of the packet
93 * \return the first packet in the queue
94 */
96 /**
97 * \brief Exclusively for BS.
98 * Two versions of Peek function (with Generic MAC Header as parameter) only
99 * for BS, as BS's scheduler needs to know the CID in Generic MAC Header.
100 * \param hdr the header of the packet
101 * \param timeStamp the timestamp of the packet
102 * \return the first packet in the queue
103 */
104 Ptr<Packet> Peek(GenericMacHeader& hdr, Time& timeStamp) const;
105
106 /**
107 * \brief Two versions for SS without Generic MAC Header parameter, as SS's
108 * scheduler does not require to know the CID in Generic MAC Header.
109 * \param packetType the type of the packet
110 * \return the first packet in the queue
111 */
113 /**
114 * \brief Two versions for SS without Generic MAC Header parameter, as SS's
115 * scheduler does not require to know the CID in Generic MAC Header.
116 * \param packetType the type of the packet
117 * \param timeStamp the timestamp of the packet
118 * \return the first packet in the queue
119 */
120 Ptr<Packet> Peek(MacHeaderType::HeaderType packetType, Time& timeStamp) const;
121
122 /**
123 * Check if queue is empty
124 * \returns true if empty
125 */
126 bool IsEmpty() const;
127
128 /**
129 * Exclusively for SS.
130 * \return true if queue is empty of type packetType
131 * \param packetType packet type to check
132 */
133 bool IsEmpty(MacHeaderType::HeaderType packetType) const;
134
135 /**
136 * Get size of queue
137 * \returns the size
138 */
139 uint32_t GetSize() const;
140 /**
141 * Get number of bytes in queue
142 * \returns the number of bytes
143 */
144 uint32_t GetNBytes() const;
145
146 /**
147 * Check for fragmentation of the first packet of the specified type
148 * \param packetType the packet type
149 * \returns true if fragmented
150 */
152 /**
153 * Get first packet header size of the specified type
154 * \param packetType the packet type
155 * \returns the first packet header size
156 */
158 /**
159 * Get first packet payload size of the specified type
160 * \param packetType the packet type
161 * \returns the first packet payload size
162 */
164 /**
165 * Get required number of bytes to hold first packet of packetType
166 * \param packetType the packet type
167 * \returns the sum of the first packet header and payload (of specified type)
168 */
170 /**
171 * Get queue length considering also the MAC overhead
172 * \return queue length
173 */
175 /// Set fragmentation function
176 /**
177 * Set fragmentation state for first packet of type packetType
178 * \param packetType packetType to check
179 */
181 /**
182 * Set fragment number for first packet of type packetType
183 * \param packetType packetType to check
184 */
186 /**
187 * Set fragment offset for first packet of type packetType
188 * \param packetType packetType to check
189 * \param offset offset value to set
190 */
192
193 /// QueueElement structure
195 {
196 QueueElement();
197 /**
198 * Constructor
199 *
200 * \param packet the packet
201 * \param hdrType MAC header type
202 * \param hdr MAC header
203 * \param timeStamp time stamp
204 */
206 const MacHeaderType& hdrType,
207 const GenericMacHeader& hdr,
208 Time timeStamp);
209 /**
210 * Get size function
211 * \returns the size
212 */
213 uint32_t GetSize() const;
215 MacHeaderType m_hdrType; ///< header type
217 Time m_timeStamp; ///< timestamp
218
219 /**
220 To manage fragmentation feature, each QueueElement have 3 new fields:
221 m_fragmentation that becomes true when the fragmentation starts;
222 m_fragmentNumber that is incremented when a new fragment is sent
223 m_fragmentOffset that tracks the start of the next fragment into the packet
224 */
225 bool m_fragmentation; ///< becomes true when the fragmentation starts
226 uint32_t m_fragmentNumber; ///< incremented when a new fragment is sent
227 uint32_t m_fragmentOffset; ///< tracks the start of the next fragment into the packet
228
229 /// Set fragmentation
230 void SetFragmentation();
231 /// Set fragment number
232 void SetFragmentNumber();
233 /**
234 * Set fragment offset
235 * \param offset the offset
236 */
237 void SetFragmentOffset(uint32_t offset);
238 };
239
240 private:
241 /**
242 In the case of non-UGS service flows at the SS side the queue will store both data packets
243 and bandwidth request packets. The two are distinguished by their headers. The below two
244 functions are for this purpose exclusively. The Front function returns the first packet of a
245 specific packet type from the queue (which may not necessarily be at the front of the queue),
246 and the Pop function pops that elements.
247 * \param packetType the type of the packet
248 * \returns the first packet in the queue of the specified type
249 */
251 /**
252 * Pop function
253 * \param packetType the packet type
254 */
255 void Pop(MacHeaderType::HeaderType packetType);
256
257 /// PacketQueue typedef
258 typedef std::deque<QueueElement> PacketQueue;
259 PacketQueue m_queue; ///< the queue
260 uint32_t m_maxSize; ///< maximum size
261 uint32_t m_bytes; ///< bytes
262 uint32_t m_nrDataPackets; ///< number data packets
263 uint32_t m_nrRequestPackets; ///< number request packets
264
268 public:
269 /**
270 * Get packet queue function
271 * \returns the packet queue
272 */
274};
275
276} // namespace ns3
277
278#endif /* WIMAX_MAC_QUEUE_H */
This class implements the Generic mac Header as described by IEEE Standard for Local and metropolitan...
This class Represents the HT (Header Type) field of generic MAC and bandwidth request headers.
HeaderType
Header type enumeration.
A base class which provides memory management and object aggregation.
Definition: object.h:89
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition: type-id.h:59
Class implementing the device packet queue.
std::deque< QueueElement > PacketQueue
PacketQueue typedef.
Ptr< Packet > Peek(GenericMacHeader &hdr) const
Exclusively for BS.
uint32_t GetFirstPacketPayloadSize(MacHeaderType::HeaderType packetType)
Get first packet payload size of the specified type.
WimaxMacQueue::QueueElement Front(MacHeaderType::HeaderType packetType) const
In the case of non-UGS service flows at the SS side the queue will store both data packets and bandwi...
void Pop(MacHeaderType::HeaderType packetType)
Pop function.
void SetMaxSize(uint32_t maxSize)
set the maximum queue size
TracedCallback< Ptr< const Packet > > m_traceDequeue
dequeue trace callback
uint32_t GetFirstPacketRequiredByte(MacHeaderType::HeaderType packetType)
Get required number of bytes to hold first packet of packetType.
Ptr< Packet > Dequeue(MacHeaderType::HeaderType packetType)
Dequeue a packet of type packetType from the queue.
TracedCallback< Ptr< const Packet > > m_traceEnqueue
enqueue trace callback
uint32_t GetNBytes() const
Get number of bytes in queue.
static TypeId GetTypeId()
Get the type ID.
uint32_t GetFirstPacketHdrSize(MacHeaderType::HeaderType packetType)
Get first packet header size of the specified type.
uint32_t m_bytes
bytes
void SetFragmentNumber(MacHeaderType::HeaderType packetType)
Set fragment number for first packet of type packetType.
void SetFragmentation(MacHeaderType::HeaderType packetType)
Set fragmentation function.
void SetFragmentOffset(MacHeaderType::HeaderType packetType, uint32_t offset)
Set fragment offset for first packet of type packetType.
bool CheckForFragmentation(MacHeaderType::HeaderType packetType)
Check for fragmentation of the first packet of the specified type.
uint32_t m_nrDataPackets
number data packets
uint32_t m_maxSize
maximum size
bool Enqueue(Ptr< Packet > packet, const MacHeaderType &hdrType, const GenericMacHeader &hdr)
Enqueue a packet.
PacketQueue m_queue
the queue
uint32_t m_nrRequestPackets
number request packets
uint32_t GetQueueLengthWithMACOverhead()
Get queue length considering also the MAC overhead.
bool IsEmpty() const
Check if queue is empty.
const WimaxMacQueue::PacketQueue & GetPacketQueue() const
Get packet queue function.
TracedCallback< Ptr< const Packet > > m_traceDrop
drop trace callback
uint32_t GetMaxSize() const
uint32_t GetSize() const
Get size of queue.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t m_fragmentNumber
incremented when a new fragment is sent
uint32_t GetSize() const
Get size function.
uint32_t m_fragmentOffset
tracks the start of the next fragment into the packet
bool m_fragmentation
To manage fragmentation feature, each QueueElement have 3 new fields: m_fragmentation that becomes tr...
void SetFragmentNumber()
Set fragment number.
MacHeaderType m_hdrType
header type
GenericMacHeader m_hdr
header
void SetFragmentOffset(uint32_t offset)
Set fragment offset.
void SetFragmentation()
Set fragmentation.