A Discrete-Event Network Simulator
QKDNetSim v2.0 (NS-3 v3.41) @ (+)
API
All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Modules Pages
block-ack-window.cc
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2019 Universita' degli Studi di Napoli Federico II
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  *
17  * Author: Stefano Avallone <stavallo@unina.it>
18  */
19 
20 #include "block-ack-window.h"
21 
22 #include "wifi-utils.h"
23 
24 #include "ns3/log.h"
25 
26 namespace ns3
27 {
28 
29 NS_LOG_COMPONENT_DEFINE("BlockAckWindow");
30 
32  : m_winStart(0),
33  m_head(0)
34 {
35 }
36 
37 void
38 BlockAckWindow::Init(uint16_t winStart, uint16_t winSize)
39 {
40  NS_LOG_FUNCTION(this << winStart << winSize);
41  m_winStart = winStart;
42  m_window.assign(winSize, false);
43  m_head = 0;
44 }
45 
46 void
47 BlockAckWindow::Reset(uint16_t winStart)
48 {
49  Init(winStart, m_window.size());
50 }
51 
52 uint16_t
54 {
55  return m_winStart;
56 }
57 
58 uint16_t
60 {
61  return (m_winStart + m_window.size() - 1) % SEQNO_SPACE_SIZE;
62 }
63 
64 std::size_t
66 {
67  return m_window.size();
68 }
69 
71 BlockAckWindow::At(std::size_t distance)
72 {
73  NS_ASSERT(distance < m_window.size());
74 
75  return m_window.at((m_head + distance) % m_window.size());
76 }
77 
78 std::vector<bool>::const_reference
79 BlockAckWindow::At(std::size_t distance) const
80 {
81  NS_ASSERT(distance < m_window.size());
82 
83  return m_window.at((m_head + distance) % m_window.size());
84 }
85 
86 void
87 BlockAckWindow::Advance(std::size_t count)
88 {
89  NS_LOG_FUNCTION(this << count);
90 
91  if (count >= m_window.size())
92  {
93  Reset((m_winStart + count) % SEQNO_SPACE_SIZE);
94  return;
95  }
96 
97  for (std::size_t i = 0; i < count; i++)
98  {
99  m_window[m_head] = false;
100  m_head = (m_head + 1) % m_window.size();
101  }
102  m_winStart = (m_winStart + count) % SEQNO_SPACE_SIZE;
103 }
104 
105 } // namespace ns3
void Reset(uint16_t winStart)
Reset the window by clearing all the elements and setting winStart to the given value.
BlockAckWindow()
Constructor.
std::size_t GetWinSize() const
Get the window size.
void Advance(std::size_t count)
Advance the current winStart by the given number of positions.
uint16_t GetWinStart() const
Get the current winStart value.
uint16_t GetWinEnd() const
Get the current winEnd value.
uint16_t m_winStart
window start (sequence number)
std::size_t m_head
index of winStart in the vector
void Init(uint16_t winStart, uint16_t winSize)
Initialize the window with the given starting sequence number and size.
std::vector< bool > m_window
window
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.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
Definition: assert.h:66
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:202
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
static constexpr uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition: wifi-utils.h:185