A Discrete-Event Network Simulator
API
block-ack-agreement.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 MIRKO BANCHI
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: Mirko Banchi <mk.banchi@gmail.com>
19  */
20 
21 #include "ns3/log.h"
22 #include "block-ack-agreement.h"
23 #include "wifi-utils.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("BlockAckAgreement");
28 
30  : m_peer (peer),
31  m_amsduSupported (0),
32  m_blockAckPolicy (1),
33  m_tid (tid),
34  m_htSupported (0),
35  m_inactivityEvent ()
36 {
37  NS_LOG_FUNCTION (this << peer << +tid);
38 }
39 
41 {
42  NS_LOG_FUNCTION (this);
44 }
45 
46 void
47 BlockAckAgreement::SetBufferSize (uint16_t bufferSize)
48 {
49  NS_LOG_FUNCTION (this << bufferSize);
50  NS_ASSERT (bufferSize <= 256);
51  NS_ASSERT (bufferSize % 16 == 0);
52  m_bufferSize = bufferSize;
53 }
54 
55 void
57 {
58  NS_LOG_FUNCTION (this << timeout);
60 }
61 
62 void
64 {
65  NS_LOG_FUNCTION (this << seq);
66  NS_ASSERT (seq < 4096);
67  m_startingSeq = seq;
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION (this << seq);
74  NS_ASSERT (((seq >> 4) & 0x0fff) < 4096);
75  m_startingSeq = (seq >> 4) & 0x0fff;
76 }
77 
78 void
80 {
81  NS_LOG_FUNCTION (this);
82  m_blockAckPolicy = 1;
83 }
84 
85 void
87 {
88  NS_LOG_FUNCTION (this);
89  m_blockAckPolicy = 0;
90 }
91 
92 void
94 {
95  NS_LOG_FUNCTION (this << supported);
96  m_amsduSupported = supported;
97 }
98 
99 uint8_t
101 {
102  return m_tid;
103 }
104 
107 {
108  NS_LOG_FUNCTION (this);
109  return m_peer;
110 }
111 
112 uint16_t
114 {
115  return m_bufferSize;
116 }
117 
118 uint16_t
120 {
121  return m_timeout;
122 }
123 
124 uint16_t
126 {
127  return m_startingSeq;
128 }
129 
130 uint16_t
132 {
133  uint16_t seqControl = (m_startingSeq << 4) & 0xfff0;
134  return seqControl;
135 }
136 
137 bool
139 {
140  return (m_blockAckPolicy == 1);
141 }
142 
143 bool
145 {
146  return (m_amsduSupported == 1) ? true : false;
147 }
148 
149 uint16_t
151 {
152  return (GetStartingSequence () + GetBufferSize () - 1) % SEQNO_SPACE_SIZE;
153 }
154 
155 void
157 {
158  NS_LOG_FUNCTION (this << htSupported);
159  m_htSupported = htSupported;
160 }
161 
162 bool
164 {
165  return (m_htSupported == 1) ? true : false;
166 }
167 
170 {
171  if (!m_htSupported)
172  {
173  return BlockAckType::BASIC;
174  }
175  // Multi-TID Block Ack is not currently supported
176  if (m_bufferSize > 64)
177  {
178  return {BlockAckType::COMPRESSED, {32}};
179  }
180  return {BlockAckType::COMPRESSED, {8}};
181 }
182 
185 {
186  if (!m_htSupported)
187  {
188  return BlockAckReqType::BASIC;
189  }
190  // Multi-TID Block Ack Request is not currently supported
192 }
193 
194 std::size_t
195 BlockAckAgreement::GetDistance (uint16_t seqNumber, uint16_t startingSeqNumber)
196 {
197  NS_ASSERT (seqNumber < SEQNO_SPACE_SIZE && startingSeqNumber < SEQNO_SPACE_SIZE);
198  return (seqNumber - startingSeqNumber + SEQNO_SPACE_SIZE) % SEQNO_SPACE_SIZE;
199 }
200 
201 } //namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Mac48Address m_peer
Peer address.
uint16_t GetWinEnd(void) const
Return the last sequence number covered by the ack window.
#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
virtual uint16_t GetStartingSequence(void) const
Return the starting sequence number.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
BlockAckReqType GetBlockAckReqType(void) const
Get the type of the Block Ack Requests sent by the originator of this agreement.
uint16_t m_startingSeq
Starting sequence control.
ns3::Time timeout
The different BlockAckRequest variants.
bool IsHtSupported(void) const
Check whether HT is supported.
bool IsImmediateBlockAck(void) const
Check whether the current ack policy is immediate BlockAck.
uint16_t m_timeout
Timeout.
uint8_t m_tid
Traffic ID.
uint8_t m_htSupported
Flag whether HT is supported.
uint16_t GetTimeout(void) const
Return the timeout.
uint8_t m_blockAckPolicy
Type of block ack: immediate or delayed.
void SetStartingSequenceControl(uint16_t seq)
Set starting sequence control.
uint16_t m_bufferSize
Buffer size.
Mac48Address GetPeer(void) const
Return the peer address.
void SetStartingSequence(uint16_t seq)
Set starting sequence number.
Every class exported by the ns3 library is enclosed in the ns3 namespace.
an EUI-48 address
Definition: mac48-address.h:43
uint8_t m_amsduSupported
Flag whether MSDU aggregation is supported.
bool IsAmsduSupported(void) const
Check whether A-MSDU is supported.
void SetDelayedBlockAck(void)
Set block ack policy to delayed Ack.
EventId m_inactivityEvent
inactivity event
void SetAmsduSupport(bool supported)
Enable or disable A-MSDU support.
uint16_t GetBufferSize(void) const
Return the buffer size.
uint16_t GetStartingSequenceControl(void) const
Return the starting sequence control.
The different BlockAck variants.
BlockAckType GetBlockAckType(void) const
Get the type of the Block Acks sent by the recipient of this agreement.
void Cancel(void)
This method is syntactic sugar for the ns3::Simulator::Cancel method.
Definition: event-id.cc:53
const uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition: wifi-utils.h:222
void SetImmediateBlockAck(void)
Set block ack policy to immediate Ack.
void SetTimeout(uint16_t timeout)
Set timeout.
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...
void SetBufferSize(uint16_t bufferSize)
Set buffer size.
uint8_t GetTid(void) const
Return the Traffic ID (TID).
void SetHtSupported(bool htSupported)
Enable or disable HT support.
BlockAckAgreement(Mac48Address peer, uint8_t tid)
Constructor for BlockAckAgreement with given peer and TID.