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 
27 namespace ns3 {
28 
29 NS_LOG_COMPONENT_DEFINE ("OriginatorBlockAckAgreement");
30 
32  : BlockAckAgreement (recipient, tid),
33  m_state (PENDING)
34 {
35 }
36 
38 {
39 }
40 
41 void
43 {
44  m_state = state;
45 }
46 
47 bool
49 {
50  return (m_state == PENDING) ? true : false;
51 }
52 
53 bool
55 {
56  return (m_state == ESTABLISHED) ? true : false;
57 }
58 
59 bool
61 {
62  return (m_state == REJECTED) ? true : false;
63 }
64 
65 bool
67 {
68  return (m_state == NO_REPLY) ? true : false;
69 }
70 
71 bool
73 {
74  return (m_state == RESET) ? true : false;
75 }
76 
77 uint16_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 
88 std::size_t
89 OriginatorBlockAckAgreement::GetDistance (uint16_t seqNumber) const
90 {
92 }
93 
94 void
96 {
98 }
99 
100 void
102 {
103  while (m_txWindow.At (0))
104  {
105  m_txWindow.Advance (1); // reset the current head -- ensures loop termination
106  }
107 }
108 
109 void
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
128  AdvanceTxWindow ();
129  NS_LOG_DEBUG ("Transmitted MPDU beyond current transmit window. New starting sequence number: "
130  << m_txWindow.GetWinStart ());
131  }
132 }
133 
134 void
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
153  AdvanceTxWindow ();
154  NS_LOG_DEBUG ("Starting sequence number: " << m_txWindow.GetWinStart ());
155 }
156 
157 void
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
171  AdvanceTxWindow ();
172  NS_LOG_DEBUG ("Discarded MPDU within current transmit window. New starting sequence number: "
173  << m_txWindow.GetWinStart ());
174 }
175 
176 } //namespace ns3
void AdvanceTxWindow(void)
Advance the transmit window so that the starting sequence number is the nearest unacknowledged MPDU...
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:73
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.
bool IsNoReply(void) const
Check if the current state of this agreement is NO_REPLY.
bool IsEstablished(void) const
Check if the current state of this agreement is ESTABLISHED.
bool IsPending(void) const
Check if the current state of this agreement is PENDING.
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:225
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
std::size_t GetDistance(uint16_t seqNumber) const
Get the distance between the current starting sequence number and the given sequence number...
void Advance(std::size_t count)
Advance the current winStart by the given number of positions.
uint16_t m_startingSeq
Starting sequence control.
bool IsRejected(void) const
Check if the current state of this agreement is REJECTED.
void Init(uint16_t winStart, uint16_t winSize)
Initialize the window with the given starting sequence number and size.
BlockAckWindow m_txWindow
originator&#39;s transmit window
void NotifyDiscardedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Advance the transmit window beyond the MPDU that has been reported to be discarded.
uint16_t GetWinStart(void) const
Get the current winStart value.
uint16_t m_bufferSize
Buffer size.
void SetState(State state)
Set the current state.
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...
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...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
an EUI-48 address
Definition: mac48-address.h:43
State
Represents the state for this agreement.
Maintains information for a block ack agreement.
std::size_t GetWinSize(void) const
Get the window size.
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
bool IsReset(void) const
Check if the current state of this agreement is RESET.
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 InitTxWindow(void)
Initialize the originator&#39;s transmit window by setting its size and starting sequence number equal to...