A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
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
NS_LOG_COMPONENT_DEFINE
(
"BlockAckCache"
);
29
30
namespace
ns3 {
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
void
43
BlockAckCache::UpdateWithMpdu
(
const
WifiMacHeader
*hdr)
44
{
45
NS_LOG_FUNCTION
(
this
<< hdr);
46
uint16_t seqNumber = hdr->
GetSequenceNumber
();
47
if
(!
QosUtilsIsOldPacket
(
m_winStart
, seqNumber))
48
{
49
if
(!
IsInWindow
(seqNumber))
50
{
51
uint16_t delta = (seqNumber -
m_winEnd
+ 4096) % 4096;
52
if
(delta > 1)
53
{
54
ResetPortionOfBitmap
((
m_winEnd
+ 1) % 4096, ((seqNumber - 1) + 4096) % 4096);
55
}
56
m_winStart
= (
m_winStart
+ delta) % 4096;
57
m_winEnd
= seqNumber;
58
59
WINSIZE_ASSERT
;
60
}
61
m_bitmap
[seqNumber] |= (0x0001 << hdr->
GetFragmentNumber
());
62
}
63
}
64
65
void
66
BlockAckCache::UpdateWithBlockAckReq
(uint16_t startingSeq)
67
{
68
NS_LOG_FUNCTION
(
this
<< startingSeq);
69
if
(!
QosUtilsIsOldPacket
(
m_winStart
, startingSeq))
70
{
71
if
(
IsInWindow
(startingSeq))
72
{
73
if
(startingSeq !=
m_winStart
)
74
{
75
m_winStart
= startingSeq;
76
uint16_t newWinEnd = (
m_winStart
+
m_winSize
- 1) % 4096;
77
ResetPortionOfBitmap
((
m_winEnd
+ 1) % 4096, newWinEnd);
78
m_winEnd
= newWinEnd;
79
80
WINSIZE_ASSERT
;
81
}
82
}
83
else
84
{
85
m_winStart
= startingSeq;
86
m_winEnd
= (
m_winStart
+
m_winSize
- 1) % 4096;
87
ResetPortionOfBitmap
(
m_winStart
,
m_winEnd
);
88
89
WINSIZE_ASSERT
;
90
}
91
}
92
}
93
94
void
95
BlockAckCache::ResetPortionOfBitmap
(uint16_t
start
, uint16_t end)
96
{
97
NS_LOG_FUNCTION
(
this
<< start << end);
98
uint32_t i =
start
;
99
for
(; i != end; i = (i + 1) % 4096)
100
{
101
m_bitmap
[i] = 0;
102
}
103
m_bitmap
[i] = 0;
104
}
105
106
bool
107
BlockAckCache::IsInWindow
(uint16_t seq)
108
{
109
NS_LOG_FUNCTION
(
this
<< seq);
110
return
((seq -
m_winStart
+ 4096) % 4096) <
m_winSize
;
111
}
112
113
void
114
BlockAckCache::FillBlockAckBitmap
(
CtrlBAckResponseHeader
*blockAckHeader)
115
{
116
NS_LOG_FUNCTION
(
this
<< blockAckHeader);
117
if
(blockAckHeader->
IsBasic
())
118
{
119
NS_FATAL_ERROR
(
"Basic block ack is only partially implemented."
);
120
}
121
else
if
(blockAckHeader->
IsCompressed
())
122
{
123
uint32_t i = blockAckHeader->
GetStartingSequence
();
124
uint32_t end = (i +
m_winSize
- 1) % 4096;
125
for
(; i != end; i = (i + 1) % 4096)
126
{
127
if
(
m_bitmap
[i] == 1)
128
{
129
blockAckHeader->
SetReceivedPacket
(i);
130
}
131
}
132
if
(
m_bitmap
[i] == 1)
133
{
134
blockAckHeader->
SetReceivedPacket
(i);
135
}
136
}
137
else
if
(blockAckHeader->
IsMultiTid
())
138
{
139
NS_FATAL_ERROR
(
"Multi-tid block ack is not supported."
);
140
}
141
}
142
143
}
// namespace ns3
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
Definition:
log.h:345
ns3::WifiMacHeader::GetFragmentNumber
uint16_t GetFragmentNumber(void) const
Return the fragment number of the header.
Definition:
wifi-mac-header.cc:723
ns3::BlockAckCache::ResetPortionOfBitmap
void ResetPortionOfBitmap(uint16_t start, uint16_t end)
Definition:
block-ack-cache.cc:95
ns3::CtrlBAckResponseHeader::GetStartingSequence
uint16_t GetStartingSequence(void) const
Return the starting sequence number.
Definition:
ctrl-headers.cc:463
ns3::BlockAckCache::IsInWindow
bool IsInWindow(uint16_t seq)
Definition:
block-ack-cache.cc:107
ns3::BlockAckCache::m_winStart
uint16_t m_winStart
Definition:
block-ack-cache.h:48
ns3::BlockAckCache::UpdateWithBlockAckReq
void UpdateWithBlockAckReq(uint16_t startingSeq)
Definition:
block-ack-cache.cc:66
ns3::BlockAckCache::Init
void Init(uint16_t winStart, uint16_t winSize)
Definition:
block-ack-cache.cc:33
ns3::CtrlBAckResponseHeader::IsCompressed
bool IsCompressed(void) const
Check if the current ACK policy is compressed ACK and not multiple TID.
Definition:
ctrl-headers.cc:477
ns3::BlockAckCache::UpdateWithMpdu
void UpdateWithMpdu(const WifiMacHeader *hdr)
Definition:
block-ack-cache.cc:43
ns3::QosUtilsIsOldPacket
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
visualizer.core.start
def start
Definition:
core.py:1482
qos-utils.h
NS_FATAL_ERROR
#define NS_FATAL_ERROR(msg)
fatal error handling
Definition:
fatal-error.h:72
ctrl-headers.h
wifi-mac-header.h
ns3::CtrlBAckResponseHeader
Headers for Block ack response.
Definition:
ctrl-headers.h:183
block-ack-cache.h
WINSIZE_ASSERT
#define WINSIZE_ASSERT
Definition:
block-ack-cache.cc:26
NS_LOG_COMPONENT_DEFINE
NS_LOG_COMPONENT_DEFINE("BlockAckCache")
ns3::CtrlBAckResponseHeader::IsBasic
bool IsBasic(void) const
Check if the current ACK policy is basic (i.e.
Definition:
ctrl-headers.cc:470
ns3::BlockAckCache::FillBlockAckBitmap
void FillBlockAckBitmap(CtrlBAckResponseHeader *blockAckHeader)
Definition:
block-ack-cache.cc:114
ns3::BlockAckCache::m_winSize
uint8_t m_winSize
Definition:
block-ack-cache.h:49
ns3::BlockAckCache::m_winEnd
uint16_t m_winEnd
Definition:
block-ack-cache.h:50
ns3::CtrlBAckResponseHeader::SetReceivedPacket
void SetReceivedPacket(uint16_t seq)
Set the bitmap that the packet with the given sequence number was received.
Definition:
ctrl-headers.cc:602
ns3::BlockAckCache::m_bitmap
uint16_t m_bitmap[4096]
Definition:
block-ack-cache.h:52
ns3::CtrlBAckResponseHeader::IsMultiTid
bool IsMultiTid(void) const
Check if the current ACK policy has multiple TID.
Definition:
ctrl-headers.cc:484
ns3::WifiMacHeader
Implements the IEEE 802.11 MAC header.
Definition:
wifi-mac-header.h:80
ns3::WifiMacHeader::GetSequenceNumber
uint16_t GetSequenceNumber(void) const
Return the sequence number of the header.
Definition:
wifi-mac-header.cc:718
src
wifi
model
block-ack-cache.cc
Generated on Sat Apr 19 2014 14:07:10 for ns-3 by
1.8.6