A Discrete-Event Network Simulator
API
block-ack-cache.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 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  * Author: Mirko Banchi <mk.banchi@gmail.com>
19  */
20 #include "block-ack-cache.h"
21 #include "ctrl-headers.h"
22 #include "wifi-mac-header.h"
23 #include "qos-utils.h"
24 #include "ns3/log.h"
25 
26 #define WINSIZE_ASSERT NS_ASSERT ((m_winEnd - m_winStart + 4096) % 4096 == m_winSize - 1)
27 
28 namespace ns3 {
29 
30 NS_LOG_COMPONENT_DEFINE ("BlockAckCache");
31 
32 void
33 BlockAckCache::Init (uint16_t winStart, uint16_t winSize)
34 {
35  NS_LOG_FUNCTION (this << winStart << winSize);
36  m_winStart = winStart;
37  m_winSize = winSize <= 64 ? winSize : 64;
38  m_winEnd = (m_winStart + m_winSize - 1) % 4096;
39  memset (m_bitmap, 0, sizeof (m_bitmap));
40 }
41 
42 uint16_t
44 {
45  return m_winStart;
46 }
47 
48 void
50 {
51  NS_LOG_FUNCTION (this << hdr);
52  uint16_t seqNumber = hdr->GetSequenceNumber ();
53  if (!QosUtilsIsOldPacket (m_winStart, seqNumber))
54  {
55  if (!IsInWindow (seqNumber))
56  {
57  uint16_t delta = (seqNumber - m_winEnd + 4096) % 4096;
58  if (delta > 1)
59  {
60  ResetPortionOfBitmap ((m_winEnd + 1) % 4096, ((seqNumber - 1) + 4096) % 4096);
61  }
62  m_winStart = (m_winStart + delta) % 4096;
63  m_winEnd = seqNumber;
64 
66  }
67  m_bitmap[seqNumber] |= (0x0001 << hdr->GetFragmentNumber ());
68  }
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION (this << startingSeq);
75  if (!QosUtilsIsOldPacket (m_winStart, startingSeq))
76  {
77  if (IsInWindow (startingSeq))
78  {
79  if (startingSeq != m_winStart)
80  {
81  m_winStart = startingSeq;
82  uint16_t newWinEnd = (m_winStart + m_winSize - 1) % 4096;
83  ResetPortionOfBitmap ((m_winEnd + 1) % 4096, newWinEnd);
84  m_winEnd = newWinEnd;
85 
87  }
88  }
89  else
90  {
91  m_winStart = startingSeq;
92  m_winEnd = (m_winStart + m_winSize - 1) % 4096;
94 
96  }
97  }
98 }
99 
100 void
102 {
103  NS_LOG_FUNCTION (this << start << end);
104  uint32_t i = start;
105  for (; i != end; i = (i + 1) % 4096)
106  {
107  m_bitmap[i] = 0;
108  }
109  m_bitmap[i] = 0;
110 }
111 
112 bool
114 {
115  NS_LOG_FUNCTION (this << seq);
116  return ((seq - m_winStart + 4096) % 4096) < m_winSize;
117 }
118 
119 void
121 {
122  NS_LOG_FUNCTION (this << blockAckHeader);
123  if (blockAckHeader->IsBasic ())
124  {
125  NS_FATAL_ERROR ("Basic block ack is only partially implemented.");
126  }
127  else if (blockAckHeader->IsCompressed ())
128  {
129  uint32_t i = blockAckHeader->GetStartingSequence ();
130  uint32_t end = (i + m_winSize - 1) % 4096;
131  for (; i != end; i = (i + 1) % 4096)
132  {
133  if (m_bitmap[i] == 1)
134  {
135  blockAckHeader->SetReceivedPacket (i);
136  }
137  }
138  if (m_bitmap[i] == 1)
139  {
140  blockAckHeader->SetReceivedPacket (i);
141  }
142  }
143  else if (blockAckHeader->IsMultiTid ())
144  {
145  NS_FATAL_ERROR ("Multi-tid block ack is not supported.");
146  }
147 }
148 
149 } // namespace ns3
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
uint16_t GetFragmentNumber(void) const
Return the fragment number of the header.
void ResetPortionOfBitmap(uint16_t start, uint16_t end)
uint16_t GetStartingSequence(void) const
Return the starting sequence number.
bool IsInWindow(uint16_t seq)
def start()
Definition: core.py:1482
void UpdateWithBlockAckReq(uint16_t startingSeq)
void Init(uint16_t winStart, uint16_t winSize)
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
bool IsCompressed(void) const
Check if the current ACK policy is compressed ACK and not multiple TID.
void UpdateWithMpdu(const WifiMacHeader *hdr)
#define NS_FATAL_ERROR(msg)
Fatal error handling.
Definition: fatal-error.h:100
bool QosUtilsIsOldPacket(uint16_t startingSeq, uint16_t seqNumber)
This function checks if packet with sequence number seqNumber is an "old" packet. ...
Definition: qos-utils.cc:86
Headers for Block ack response.
Definition: ctrl-headers.h:183
#define WINSIZE_ASSERT
Every class exported by the ns3 library is enclosed in the ns3 namespace.
bool IsBasic(void) const
Check if the current ACK policy is basic (i.e.
void FillBlockAckBitmap(CtrlBAckResponseHeader *blockAckHeader)
void SetReceivedPacket(uint16_t seq)
Set the bitmap that the packet with the given sequence number was received.
uint16_t GetWinStart(void)
When an A-MPDU is received, the window start may change to a new value depending on the sequence numb...
uint16_t m_bitmap[4096]
bool IsMultiTid(void) const
Check if the current ACK policy has multiple TID.
Implements the IEEE 802.11 MAC header.
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.