A Discrete-Event Network Simulator
API
block-ack-agreement.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 MIRKO BANCHI
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: Mirko Banchi <mk.banchi@gmail.com>
18  */
19 
20 #include "block-ack-agreement.h"
21 
22 #include "wifi-utils.h"
23 
24 #include "ns3/log.h"
25 
26 #include <set>
27 
28 namespace ns3
29 {
30 
31 NS_LOG_COMPONENT_DEFINE("BlockAckAgreement");
32 
34  : m_peer(peer),
35  m_amsduSupported(0),
36  m_blockAckPolicy(1),
37  m_tid(tid),
38  m_htSupported(0),
39  m_inactivityEvent()
40 {
41  NS_LOG_FUNCTION(this << peer << +tid);
42 }
43 
45 {
46  NS_LOG_FUNCTION(this);
48 }
49 
50 void
52 {
53  NS_LOG_FUNCTION(this << bufferSize);
54  m_bufferSize = bufferSize;
55 }
56 
57 void
59 {
60  NS_LOG_FUNCTION(this << timeout);
62 }
63 
64 void
66 {
67  NS_LOG_FUNCTION(this << seq);
68  NS_ASSERT(seq < 4096);
69  m_startingSeq = seq;
70 }
71 
72 void
74 {
75  NS_LOG_FUNCTION(this << seq);
76  NS_ASSERT(((seq >> 4) & 0x0fff) < 4096);
77  m_startingSeq = (seq >> 4) & 0x0fff;
78 }
79 
80 void
82 {
83  NS_LOG_FUNCTION(this);
84  m_blockAckPolicy = 1;
85 }
86 
87 void
89 {
90  NS_LOG_FUNCTION(this);
91  m_blockAckPolicy = 0;
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION(this << supported);
98  m_amsduSupported = supported;
99 }
100 
101 uint8_t
103 {
104  return m_tid;
105 }
106 
109 {
110  NS_LOG_FUNCTION(this);
111  return m_peer;
112 }
113 
114 uint16_t
116 {
117  return m_bufferSize;
118 }
119 
120 uint16_t
122 {
123  return m_timeout;
124 }
125 
126 uint16_t
128 {
129  return m_startingSeq;
130 }
131 
132 uint16_t
134 {
135  uint16_t seqControl = (m_startingSeq << 4) & 0xfff0;
136  return seqControl;
137 }
138 
139 bool
141 {
142  return m_blockAckPolicy == 1;
143 }
144 
145 bool
147 {
148  return m_amsduSupported == 1;
149 }
150 
151 uint16_t
153 {
155 }
156 
157 void
159 {
160  NS_LOG_FUNCTION(this << htSupported);
161  m_htSupported = htSupported;
162 }
163 
164 bool
166 {
167  return m_htSupported == 1;
168 }
169 
172 {
173  if (!m_htSupported)
174  {
175  return BlockAckType::BASIC;
176  }
177 
178  std::set<uint16_t> lengths{64, 256, 512, 1024}; // bitmap lengths in bits
179  // first bitmap length that is greater than or equal to the buffer size
180  auto it = lengths.lower_bound(m_bufferSize);
181  NS_ASSERT_MSG(it != lengths.cend(), "Buffer size too large: " << m_bufferSize);
182  // Multi-TID Block Ack is not currently supported
183  return {BlockAckType::COMPRESSED, {static_cast<uint8_t>(*it / 8)}};
184 }
185 
188 {
189  if (!m_htSupported)
190  {
191  return BlockAckReqType::BASIC;
192  }
193  // Multi-TID Block Ack Request is not currently supported
195 }
196 
197 std::size_t
198 BlockAckAgreement::GetDistance(uint16_t seqNumber, uint16_t startingSeqNumber)
199 {
200  NS_ASSERT(seqNumber < SEQNO_SPACE_SIZE && startingSeqNumber < SEQNO_SPACE_SIZE);
201  return (seqNumber - startingSeqNumber + SEQNO_SPACE_SIZE) % SEQNO_SPACE_SIZE;
202 }
203 
204 } // namespace ns3
uint16_t GetTimeout() const
Return the timeout.
bool IsHtSupported() const
Check whether HT is supported.
BlockAckAgreement(Mac48Address peer, uint8_t tid)
Constructor for BlockAckAgreement with given peer and TID.
Mac48Address m_peer
Peer address.
void SetImmediateBlockAck()
Set block ack policy to immediate Ack.
void SetStartingSequence(uint16_t seq)
Set starting sequence number.
uint8_t m_htSupported
Flag whether HT is supported.
virtual uint16_t GetStartingSequence() const
Return the starting sequence number.
void SetStartingSequenceControl(uint16_t seq)
Set starting sequence control.
BlockAckType GetBlockAckType() const
Get the type of the Block Acks sent by the recipient of this agreement.
EventId m_inactivityEvent
inactivity event
BlockAckReqType GetBlockAckReqType() const
Get the type of the Block Ack Requests sent by the originator of this agreement.
void SetBufferSize(uint16_t bufferSize)
Set buffer size.
uint8_t m_blockAckPolicy
Type of block ack: immediate or delayed.
void SetDelayedBlockAck()
Set block ack policy to delayed Ack.
void SetAmsduSupport(bool supported)
Enable or disable A-MSDU support.
uint16_t GetWinEnd() const
Return the last sequence number covered by the ack window.
uint8_t m_tid
Traffic ID.
uint8_t GetTid() const
Return the Traffic ID (TID).
uint16_t m_startingSeq
Starting sequence control.
uint16_t m_bufferSize
Buffer size.
void SetTimeout(uint16_t timeout)
Set timeout.
bool IsImmediateBlockAck() const
Check whether the current ack policy is immediate BlockAck.
uint8_t m_amsduSupported
Flag whether MSDU aggregation is supported.
static std::size_t GetDistance(uint16_t seqNumber, uint16_t startingSeqNumber)
Get the distance between the given starting sequence number and the given sequence number.
uint16_t GetStartingSequenceControl() const
Return the starting sequence control.
uint16_t GetBufferSize() const
Return the buffer size.
void SetHtSupported(bool htSupported)
Enable or disable HT support.
bool IsAmsduSupported() const
Check whether A-MSDU is supported.
Mac48Address GetPeer() const
Return the peer address.
void Cancel()
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:55
an EUI-48 address
Definition: mac48-address.h:46
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_ASSERT_MSG(condition, message)
At runtime, in debugging builds, if this condition is not true, the program prints the message to out...
Definition: assert.h:86
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition: wifi-utils.h:185
ns3::Time timeout
The different BlockAckRequest variants.
The different BlockAck variants.