A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
originator-block-ack-agreement.cc
Go to the documentation of this file.
1/*
2 * Copyright (c) 2009, 2010 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 * Authors: Mirko Banchi <mk.banchi@gmail.com>
18 * Tommaso Pecorella <tommaso.pecorella@unifi.it>
19 */
20
22
23#include "wifi-mpdu.h"
24#include "wifi-utils.h"
25
26#include "ns3/log.h"
27
28namespace ns3
29{
30
31NS_LOG_COMPONENT_DEFINE("OriginatorBlockAckAgreement");
32
34 : BlockAckAgreement(recipient, tid),
35 m_state(PENDING)
36{
37}
38
40{
41}
42
43void
45{
46 m_state = state;
47}
48
49bool
51{
52 return m_state == PENDING;
53}
54
55bool
57{
58 return m_state == ESTABLISHED;
59}
60
61bool
63{
64 return m_state == REJECTED;
65}
66
67bool
69{
70 return m_state == NO_REPLY;
71}
72
73bool
75{
76 return m_state == RESET;
77}
78
79uint16_t
81{
82 if (m_txWindow.GetWinSize() == 0)
83 {
84 // the TX window has not been initialized yet
85 return m_startingSeq;
86 }
87 return m_txWindow.GetWinStart();
88}
89
90std::size_t
92{
94}
95
96void
98{
100}
101
102void
104{
105 while (m_txWindow.At(0))
106 {
107 m_txWindow.Advance(1); // reset the current head -- ensures loop termination
108 }
109}
110
111void
113{
114 uint16_t mpduSeqNumber = mpdu->GetHeader().GetSequenceNumber();
115 uint16_t distance = GetDistance(mpduSeqNumber);
116
117 if (distance >= SEQNO_SPACE_HALF_SIZE)
118 {
119 NS_LOG_DEBUG("Transmitted an old MPDU, do nothing.");
120 return;
121 }
122
123 // advance the transmit window if an MPDU beyond the current transmit window
124 // is transmitted (see Section 10.24.7.7 of 802.11-2016)
125 if (distance >= m_txWindow.GetWinSize())
126 {
127 std::size_t count = distance - m_txWindow.GetWinSize() + 1;
128 m_txWindow.Advance(count);
129 // transmit window may advance further
132 "Transmitted MPDU beyond current transmit window. New starting sequence number: "
134 }
135}
136
137void
139{
140 uint16_t mpduSeqNumber = mpdu->GetHeader().GetSequenceNumber();
141 uint16_t distance = GetDistance(mpduSeqNumber);
142
143 if (distance >= SEQNO_SPACE_HALF_SIZE)
144 {
145 NS_LOG_DEBUG("Acked an old MPDU, do nothing.");
146 return;
147 }
148
149 // when an MPDU is transmitted, the transmit window is updated such that the
150 // transmitted MPDU is in the window, hence we cannot be notified of the
151 // acknowledgment of an MPDU which is beyond the transmit window
152 m_txWindow.At(distance) = true;
153
154 // the starting sequence number can be advanced to the sequence number of
155 // the nearest unacknowledged MPDU
157 NS_LOG_DEBUG("Starting sequence number: " << m_txWindow.GetWinStart());
158}
159
160void
162{
163 uint16_t mpduSeqNumber = mpdu->GetHeader().GetSequenceNumber();
164 uint16_t distance = GetDistance(mpduSeqNumber);
165
166 if (distance >= SEQNO_SPACE_HALF_SIZE)
167 {
168 NS_LOG_DEBUG("Discarded an old MPDU, do nothing.");
169 return;
170 }
171
172 m_txWindow.Advance(distance + 1);
173 // transmit window may advance further
175 NS_LOG_DEBUG("Discarded MPDU within current transmit window. New starting sequence number: "
177}
178
179} // namespace ns3
Maintains information for a block ack agreement.
uint16_t m_startingSeq
Starting sequence control.
uint16_t m_bufferSize
Buffer size.
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.
std::size_t GetWinSize() const
Get the window size.
void Advance(std::size_t count)
Advance the current winStart by the given number of positions.
uint16_t GetWinStart() const
Get the current winStart value.
void Init(uint16_t winStart, uint16_t winSize)
Initialize the window with the given starting sequence number and size.
std::vector< bool >::reference At(std::size_t distance)
Get a reference to the element in the window having the given distance from the current winStart.
an EUI-48 address
Definition: mac48-address.h:46
void NotifyDiscardedMpdu(Ptr< const WifiMpdu > mpdu)
Advance the transmit window beyond the MPDU that has been reported to be discarded.
uint16_t GetStartingSequence() const override
Return the starting sequence number of the transmit window, if a transmit window has been initialized...
BlockAckWindow m_txWindow
originator's transmit window
void NotifyTransmittedMpdu(Ptr< const WifiMpdu > mpdu)
Advance the transmit window so as to include the transmitted MPDU, if the latter is not an old packet...
void NotifyAckedMpdu(Ptr< const WifiMpdu > mpdu)
Record that the given MPDU has been acknowledged and advance the transmit window if possible.
bool IsPending() const
Check if the current state of this agreement is PENDING.
bool IsReset() const
Check if the current state of this agreement is RESET.
void AdvanceTxWindow()
Advance the transmit window so that the starting sequence number is the nearest unacknowledged MPDU.
OriginatorBlockAckAgreement(Mac48Address recipient, uint8_t tid)
Constructor.
bool IsEstablished() const
Check if the current state of this agreement is ESTABLISHED.
void SetState(State state)
Set the current state.
State
Represents the state for this agreement.
std::size_t GetDistance(uint16_t seqNumber) const
Get the distance between the current starting sequence number and the given sequence number.
bool IsNoReply() const
Check if the current state of this agreement is NO_REPLY.
bool IsRejected() const
Check if the current state of this agreement is REJECTED.
void InitTxWindow()
Initialize the originator's transmit window by setting its size and starting sequence number equal to...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:268
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr uint16_t SEQNO_SPACE_HALF_SIZE
Size of the half the space of sequence numbers (used to determine old packets)
Definition: wifi-utils.h:188