A Discrete-Event Network Simulator
API
originator-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, 2010 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 * Authors: Mirko Banchi <mk.banchi@gmail.com>
19 * Tommaso Pecorella <tommaso.pecorella@unifi.it>
20 */
21
22#include "ns3/log.h"
24#include "wifi-mac-queue-item.h"
25#include "wifi-utils.h"
26
27namespace ns3 {
28
29NS_LOG_COMPONENT_DEFINE ("OriginatorBlockAckAgreement");
30
32 : BlockAckAgreement (recipient, tid),
33 m_state (PENDING)
34{
35}
36
38{
39}
40
41void
43{
44 m_state = state;
45}
46
47bool
49{
50 return m_state == PENDING;
51}
52
53bool
55{
56 return m_state == ESTABLISHED;
57}
58
59bool
61{
62 return m_state == REJECTED;
63}
64
65bool
67{
68 return m_state == NO_REPLY;
69}
70
71bool
73{
74 return m_state == RESET;
75}
76
77uint16_t
79{
80 if (m_txWindow.GetWinSize () == 0)
81 {
82 // the TX window has not been initialized yet
83 return m_startingSeq;
84 }
85 return m_txWindow.GetWinStart ();
86}
87
88std::size_t
90{
92}
93
94void
96{
98}
99
100void
102{
103 while (m_txWindow.At (0))
104 {
105 m_txWindow.Advance (1); // reset the current head -- ensures loop termination
106 }
107}
108
109void
111{
112 uint16_t mpduSeqNumber = mpdu->GetHeader ().GetSequenceNumber ();
113 uint16_t distance = GetDistance (mpduSeqNumber);
114
115 if (distance >= SEQNO_SPACE_HALF_SIZE)
116 {
117 NS_LOG_DEBUG ("Transmitted an old MPDU, do nothing.");
118 return;
119 }
120
121 // advance the transmit window if an MPDU beyond the current transmit window
122 // is transmitted (see Section 10.24.7.7 of 802.11-2016)
123 if (distance >= m_txWindow.GetWinSize ())
124 {
125 std::size_t count = distance - m_txWindow.GetWinSize () + 1;
126 m_txWindow.Advance (count);
127 // transmit window may advance further
129 NS_LOG_DEBUG ("Transmitted MPDU beyond current transmit window. New starting sequence number: "
130 << m_txWindow.GetWinStart ());
131 }
132}
133
134void
136{
137 uint16_t mpduSeqNumber = mpdu->GetHeader ().GetSequenceNumber ();
138 uint16_t distance = GetDistance (mpduSeqNumber);
139
140 if (distance >= SEQNO_SPACE_HALF_SIZE)
141 {
142 NS_LOG_DEBUG ("Acked an old MPDU, do nothing.");
143 return;
144 }
145
146 // when an MPDU is transmitted, the transmit window is updated such that the
147 // transmitted MPDU is in the window, hence we cannot be notified of the
148 // acknowledgment of an MPDU which is beyond the transmit window
149 m_txWindow.At (distance) = true;
150
151 // the starting sequence number can be advanced to the sequence number of
152 // the nearest unacknowledged MPDU
154 NS_LOG_DEBUG ("Starting sequence number: " << m_txWindow.GetWinStart ());
155}
156
157void
159{
160 uint16_t mpduSeqNumber = mpdu->GetHeader ().GetSequenceNumber ();
161 uint16_t distance = GetDistance (mpduSeqNumber);
162
163 if (distance >= SEQNO_SPACE_HALF_SIZE)
164 {
165 NS_LOG_DEBUG ("Discarded an old MPDU, do nothing.");
166 return;
167 }
168
169 m_txWindow.Advance (distance + 1);
170 // transmit window may advance further
172 NS_LOG_DEBUG ("Discarded MPDU within current transmit window. New starting sequence number: "
173 << m_txWindow.GetWinStart ());
174}
175
176} //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(void) const
Get the window size.
void Advance(std::size_t count)
Advance the current winStart by the given number of positions.
uint16_t GetWinStart(void) 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:44
bool IsRejected(void) const
Check if the current state of this agreement is REJECTED.
bool IsPending(void) const
Check if the current state of this agreement is PENDING.
void InitTxWindow(void)
Initialize the originator's transmit window by setting its size and starting sequence number equal to...
bool IsEstablished(void) const
Check if the current state of this agreement is ESTABLISHED.
void AdvanceTxWindow(void)
Advance the transmit window so that the starting sequence number is the nearest unacknowledged MPDU.
void NotifyAckedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Record that the given MPDU has been acknowledged and advance the transmit window if possible.
void NotifyTransmittedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Advance the transmit window so as to include the transmitted MPDU, if the latter is not an old packet...
BlockAckWindow m_txWindow
originator's transmit window
uint16_t GetStartingSequence(void) const override
Return the starting sequence number of the transmit window, if a transmit window has been initialized...
OriginatorBlockAckAgreement(Mac48Address recipient, uint8_t tid)
Constructor.
void SetState(State state)
Set the current state.
bool IsReset(void) const
Check if the current state of this agreement is RESET.
void NotifyDiscardedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Advance the transmit window beyond the MPDU that has been reported to be discarded.
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(void) const
Check if the current state of this agreement is NO_REPLY.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint16_t SEQNO_SPACE_HALF_SIZE
Size of the half the space of sequence numbers (used to determine old packets)
Definition: wifi-utils.h:134