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 {
91  NS_ASSERT (seqNumber < SEQNO_SPACE_SIZE);
92  return (seqNumber - GetStartingSequence () + SEQNO_SPACE_SIZE) % SEQNO_SPACE_SIZE;
93 }
94 
95 void
97 {
99 }
100 
101 void
103 {
104  while (m_txWindow.At (0))
105  {
106  m_txWindow.Advance (1); // reset the current head -- ensures loop termination
107  }
108 }
109 
110 void
112 {
113  uint16_t mpduSeqNumber = mpdu->GetHeader ().GetSequenceNumber ();
114  uint16_t distance = GetDistance (mpduSeqNumber);
115 
116  if (distance >= SEQNO_SPACE_HALF_SIZE)
117  {
118  NS_LOG_DEBUG ("Transmitted an old MPDU, do nothing.");
119  return;
120  }
121 
122  // advance the transmit window if an MPDU beyond the current transmit window
123  // is transmitted (see Section 10.24.7.7 of 802.11-2016)
124  if (distance >= m_txWindow.GetWinSize ())
125  {
126  std::size_t count = distance - m_txWindow.GetWinSize () + 1;
127  m_txWindow.Advance (count);
128  // transmit window may advance further
129  AdvanceTxWindow ();
130  NS_LOG_DEBUG ("Transmitted MPDU beyond current transmit window. New starting sequence number: "
131  << m_txWindow.GetWinStart ());
132  }
133 }
134 
135 void
137 {
138  uint16_t mpduSeqNumber = mpdu->GetHeader ().GetSequenceNumber ();
139  uint16_t distance = GetDistance (mpduSeqNumber);
140 
141  if (distance >= SEQNO_SPACE_HALF_SIZE)
142  {
143  NS_LOG_DEBUG ("Acked an old MPDU, do nothing.");
144  return;
145  }
146 
147  // when an MPDU is transmitted, the transmit window is updated such that the
148  // transmitted MPDU is in the window, hence we cannot be notified of the
149  // acknowledgment of an MPDU which is beyond the transmit window
150  m_txWindow.At (distance) = true;
151 
152  // the starting sequence number can be advanced to the sequence number of
153  // the nearest unacknowledged MPDU
154  AdvanceTxWindow ();
155  NS_LOG_DEBUG ("Starting sequence number: " << m_txWindow.GetWinStart ());
156 }
157 
158 void
160 {
161  uint16_t mpduSeqNumber = mpdu->GetHeader ().GetSequenceNumber ();
162  uint16_t distance = GetDistance (mpduSeqNumber);
163 
164  if (distance >= SEQNO_SPACE_HALF_SIZE)
165  {
166  NS_LOG_DEBUG ("Discarded an old MPDU, do nothing.");
167  return;
168  }
169 
170  m_txWindow.Advance (distance + 1);
171  // transmit window may advance further
172  AdvanceTxWindow ();
173  NS_LOG_DEBUG ("Discarded MPDU within current transmit window. New starting sequence number: "
174  << m_txWindow.GetWinStart ());
175 }
176 
177 } //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
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.
#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
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:190
#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.
const uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition: wifi-utils.h:187
uint16_t GetStartingSequence(void) const
Return the starting sequence number of the transmit window, if a transmit window has been initialized...
void InitTxWindow(void)
Initialize the originator&#39;s transmit window by setting its size and starting sequence number equal to...