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
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
ns3::OriginatorBlockAckAgreement::IsEstablished
bool IsEstablished(void) const
Check if the current state of this agreement is ESTABLISHED.
Definition: originator-block-ack-agreement.cc:54
ns3::BlockAckAgreement::m_bufferSize
uint16_t m_bufferSize
Buffer size.
Definition: block-ack-agreement.h:183
ns3::BlockAckWindow::GetWinStart
uint16_t GetWinStart(void) const
Get the current winStart value.
Definition: block-ack-window.cc:51
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::OriginatorBlockAckAgreement::OriginatorBlockAckAgreement
OriginatorBlockAckAgreement(Mac48Address recipient, uint8_t tid)
Constructor.
Definition: originator-block-ack-agreement.cc:31
ns3::OriginatorBlockAckAgreement::IsPending
bool IsPending(void) const
Check if the current state of this agreement is PENDING.
Definition: originator-block-ack-agreement.cc:48
ns3::OriginatorBlockAckAgreement::NO_REPLY
@ NO_REPLY
Definition: originator-block-ack-agreement.h:105
ns3::BlockAckAgreement::m_startingSeq
uint16_t m_startingSeq
Starting sequence control.
Definition: block-ack-agreement.h:185
ns3::OriginatorBlockAckAgreement::IsNoReply
bool IsNoReply(void) const
Check if the current state of this agreement is NO_REPLY.
Definition: originator-block-ack-agreement.cc:66
ns3::Mac48Address
an EUI-48 address
Definition: mac48-address.h:44
wifi-mac-queue-item.h
ns3::OriginatorBlockAckAgreement::PENDING
@ PENDING
Definition: originator-block-ack-agreement.h:103
ns3::OriginatorBlockAckAgreement::REJECTED
@ REJECTED
Definition: originator-block-ack-agreement.h:107
ns3::BlockAckAgreement
Maintains information for a block ack agreement.
Definition: block-ack-agreement.h:34
ns3::OriginatorBlockAckAgreement::InitTxWindow
void InitTxWindow(void)
Initialize the originator's transmit window by setting its size and starting sequence number equal to...
Definition: originator-block-ack-agreement.cc:95
ns3::OriginatorBlockAckAgreement::NotifyDiscardedMpdu
void NotifyDiscardedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Advance the transmit window beyond the MPDU that has been reported to be discarded.
Definition: originator-block-ack-agreement.cc:158
ns3::OriginatorBlockAckAgreement::NotifyTransmittedMpdu
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...
Definition: originator-block-ack-agreement.cc:110
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:74
ns3::OriginatorBlockAckAgreement::SetState
void SetState(State state)
Set the current state.
Definition: originator-block-ack-agreement.cc:42
originator-block-ack-agreement.h
ns3::OriginatorBlockAckAgreement::GetDistance
std::size_t GetDistance(uint16_t seqNumber) const
Get the distance between the current starting sequence number and the given sequence number.
Definition: originator-block-ack-agreement.cc:89
ns3::OriginatorBlockAckAgreement::State
State
Represents the state for this agreement.
Definition: originator-block-ack-agreement.h:102
ns3::OriginatorBlockAckAgreement::ESTABLISHED
@ ESTABLISHED
Definition: originator-block-ack-agreement.h:104
ns3::OriginatorBlockAckAgreement::~OriginatorBlockAckAgreement
~OriginatorBlockAckAgreement()
Definition: originator-block-ack-agreement.cc:37
ns3::OriginatorBlockAckAgreement::NotifyAckedMpdu
void NotifyAckedMpdu(Ptr< const WifiMacQueueItem > mpdu)
Record that the given MPDU has been acknowledged and advance the transmit window if possible.
Definition: originator-block-ack-agreement.cc:135
ns3::OriginatorBlockAckAgreement::AdvanceTxWindow
void AdvanceTxWindow(void)
Advance the transmit window so that the starting sequence number is the nearest unacknowledged MPDU.
Definition: originator-block-ack-agreement.cc:101
ns3::OriginatorBlockAckAgreement::IsReset
bool IsReset(void) const
Check if the current state of this agreement is RESET.
Definition: originator-block-ack-agreement.cc:72
ns3::OriginatorBlockAckAgreement::IsRejected
bool IsRejected(void) const
Check if the current state of this agreement is REJECTED.
Definition: originator-block-ack-agreement.cc:60
NS_LOG_DEBUG
#define NS_LOG_DEBUG(msg)
Use NS_LOG to output a message of level LOG_DEBUG.
Definition: log.h:273
ns3::OriginatorBlockAckAgreement::m_state
State m_state
state
Definition: originator-block-ack-agreement.h:205
wifi-utils.h
ns3::BlockAckWindow::Advance
void Advance(std::size_t count)
Advance the current winStart by the given number of positions.
Definition: block-ack-window.cc:85
ns3::SEQNO_SPACE_HALF_SIZE
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
ns3::BlockAckWindow::GetWinSize
std::size_t GetWinSize(void) const
Get the window size.
Definition: block-ack-window.cc:63
ns3::BlockAckAgreement::GetDistance
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.
Definition: block-ack-agreement.cc:195
ns3::OriginatorBlockAckAgreement::m_txWindow
BlockAckWindow m_txWindow
originator's transmit window
Definition: originator-block-ack-agreement.h:206
ns3::OriginatorBlockAckAgreement::RESET
@ RESET
Definition: originator-block-ack-agreement.h:106
ns3::OriginatorBlockAckAgreement::GetStartingSequence
uint16_t GetStartingSequence(void) const override
Return the starting sequence number of the transmit window, if a transmit window has been initialized...
Definition: originator-block-ack-agreement.cc:78
ns3::BlockAckWindow::At
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.
Definition: block-ack-window.cc:69
ns3::BlockAckWindow::Init
void Init(uint16_t winStart, uint16_t winSize)
Initialize the window with the given starting sequence number and size.
Definition: block-ack-window.cc:36