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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Jahanzeb Farooq <jahanzeb.farooq@sophia.inria.fr>
7 */
8
9#ifndef WIMAX_MAC_QUEUE_H
10#define WIMAX_MAC_QUEUE_H
11
12#include "wimax-mac-header.h"
13
14#include "ns3/nstime.h"
15#include "ns3/object.h"
16#include "ns3/packet.h"
17#include "ns3/traced-callback.h"
18
19#include <queue>
20#include <stdint.h>
21
22namespace ns3
23{
24
25/**
26 * \ingroup wimax
27 * Class implementing the device packet queue
28 */
29class WimaxMacQueue : public Object
30{
31 public:
32 /**
33 * \brief Get the type ID.
34 * \return the object TypeId
35 */
36 static TypeId GetTypeId();
38 /**
39 * Constructor
40 *
41 * \param maxSize maximum size of queue
42 */
43 WimaxMacQueue(uint32_t maxSize);
44 ~WimaxMacQueue() override;
45 /**
46 * \brief set the maximum queue size
47 * \param maxSize the max queue size
48 */
49 void SetMaxSize(uint32_t maxSize);
50 /**
51 * \return the maximum queue size
52 */
53 uint32_t GetMaxSize() const;
54 /**
55 * \brief Enqueue a packet
56 * \param packet the packet to enqueue
57 * \param hdrType the mac header type of the packet
58 * \param hdr the header of the packet
59 * \return true if successful
60 */
61 bool Enqueue(Ptr<Packet> packet, const MacHeaderType& hdrType, const GenericMacHeader& hdr);
62 /**
63 * \brief Dequeue a packet of type packetType from the queue
64 * \param packetType the type of the packet
65 * \return the first packet in the queue
66 */
68 /**
69 * \brief Dequeue a fragment of size availableByte from the queue
70 * \param packetType the type of the packet
71 * \param availableByte the size of the fragment
72 * \return the first packet in the queue if its size is lower than availableByte, the first
73 * availableByte of the first packet otherwise
74 */
75 Ptr<Packet> Dequeue(MacHeaderType::HeaderType packetType, uint32_t availableByte);
76
77 /**
78 * \brief Exclusively for BS.
79 * Two versions of Peek function (with Generic MAC Header as parameter) only
80 * for BS, as BS's scheduler needs to know the CID in Generic MAC Header.
81 * \param hdr the header of the packet
82 * \return the first packet in the queue
83 */
85 /**
86 * \brief Exclusively for BS.
87 * Two versions of Peek function (with Generic MAC Header as parameter) only
88 * for BS, as BS's scheduler needs to know the CID in Generic MAC Header.
89 * \param hdr the header of the packet
90 * \param timeStamp the timestamp of the packet
91 * \return the first packet in the queue
92 */
93 Ptr<Packet> Peek(GenericMacHeader& hdr, Time& timeStamp) const;
94
95 /**
96 * \brief Two versions for SS without Generic MAC Header parameter, as SS's
97 * scheduler does not require to know the CID in Generic MAC Header.
98 * \param packetType the type of the packet
99 * \return the first packet in the queue
100 */
102 /**
103 * \brief Two versions for SS without Generic MAC Header parameter, as SS's
104 * scheduler does not require to know the CID in Generic MAC Header.
105 * \param packetType the type of the packet
106 * \param timeStamp the timestamp of the packet
107 * \return the first packet in the queue
108 */
109 Ptr<Packet> Peek(MacHeaderType::HeaderType packetType, Time& timeStamp) const;
110
111 /**
112 * Check if queue is empty
113 * \returns true if empty
114 */
115 bool IsEmpty() const;
116
117 /**
118 * Exclusively for SS.
119 * \return true if queue is empty of type packetType
120 * \param packetType packet type to check
121 */
122 bool IsEmpty(MacHeaderType::HeaderType packetType) const;
123
124 /**
125 * Get size of queue
126 * \returns the size
127 */
128 uint32_t GetSize() const;
129 /**
130 * Get number of bytes in queue
131 * \returns the number of bytes
132 */
133 uint32_t GetNBytes() const;
134
135 /**
136 * Check for fragmentation of the first packet of the specified type
137 * \param packetType the packet type
138 * \returns true if fragmented
139 */
141 /**
142 * Get first packet header size of the specified type
143 * \param packetType the packet type
144 * \returns the first packet header size
145 */
147 /**
148 * Get first packet payload size of the specified type
149 * \param packetType the packet type
150 * \returns the first packet payload size
151 */
153 /**
154 * Get required number of bytes to hold first packet of packetType
155 * \param packetType the packet type
156 * \returns the sum of the first packet header and payload (of specified type)
157 */
159 /**
160 * Get queue length considering also the MAC overhead
161 * \return queue length
162 */
164 /// Set fragmentation function
165 /**
166 * Set fragmentation state for first packet of type packetType
167 * \param packetType packetType to check
168 */
170 /**
171 * Set fragment number for first packet of type packetType
172 * \param packetType packetType to check
173 */
175 /**
176 * Set fragment offset for first packet of type packetType
177 * \param packetType packetType to check
178 * \param offset offset value to set
179 */
181
182 /// QueueElement structure
184 {
185 QueueElement();
186 /**
187 * Constructor
188 *
189 * \param packet the packet
190 * \param hdrType MAC header type
191 * \param hdr MAC header
192 * \param timeStamp time stamp
193 */
195 const MacHeaderType& hdrType,
196 const GenericMacHeader& hdr,
197 Time timeStamp);
198 /**
199 * Get size function
200 * \returns the size
201 */
202 uint32_t GetSize() const;
204 MacHeaderType m_hdrType; ///< header type
206 Time m_timeStamp; ///< timestamp
207
208 /**
209 To manage fragmentation feature, each QueueElement have 3 new fields:
210 m_fragmentation that becomes true when the fragmentation starts;
211 m_fragmentNumber that is incremented when a new fragment is sent
212 m_fragmentOffset that tracks the start of the next fragment into the packet
213 */
214 bool m_fragmentation; ///< becomes true when the fragmentation starts
215 uint32_t m_fragmentNumber; ///< incremented when a new fragment is sent
216 uint32_t m_fragmentOffset; ///< tracks the start of the next fragment into the packet
217
218 /// Set fragmentation
219 void SetFragmentation();
220 /// Set fragment number
221 void SetFragmentNumber();
222 /**
223 * Set fragment offset
224 * \param offset the offset
225 */
226 void SetFragmentOffset(uint32_t offset);
227 };
228
229 private:
230 /**
231 In the case of non-UGS service flows at the SS side the queue will store both data packets
232 and bandwidth request packets. The two are distinguished by their headers. The below two
233 functions are for this purpose exclusively. The Front function returns the first packet of a
234 specific packet type from the queue (which may not necessarily be at the front of the queue),
235 and the Pop function pops that elements.
236 * \param packetType the type of the packet
237 * \returns the first packet in the queue of the specified type
238 */
240 /**
241 * Pop function
242 * \param packetType the packet type
243 */
244 void Pop(MacHeaderType::HeaderType packetType);
245
246 /// PacketQueue typedef
247 typedef std::deque<QueueElement> PacketQueue;
248 PacketQueue m_queue; ///< the queue
249 uint32_t m_maxSize; ///< maximum size
250 uint32_t m_bytes; ///< bytes
251 uint32_t m_nrDataPackets; ///< number data packets
252 uint32_t m_nrRequestPackets; ///< number request packets
253
257 public:
258 /**
259 * Get packet queue function
260 * \returns the packet queue
261 */
263};
264
265} // namespace ns3
266
267#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:78
Smart pointer class similar to boost::intrusive_ptr.
Simulation virtual time values and global simulation resolution.
Definition nstime.h:94
Forward calls to a chain of Callback.
a unique identifier for an interface.
Definition type-id.h:48
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
void SetFragmentOffset(uint32_t offset)
Set fragment offset.
void SetFragmentation()
Set fragmentation.