A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Stefano Avallone <stavallo@unina.it>
7 */
8
9#include "block-ack-window.h"
10
11#include "wifi-utils.h"
12
13#include "ns3/log.h"
14
15namespace ns3
16{
17
18NS_LOG_COMPONENT_DEFINE("BlockAckWindow");
19
21 : m_winStart(0),
22 m_head(0)
23{
24}
25
26void
27BlockAckWindow::Init(uint16_t winStart, uint16_t winSize)
28{
29 NS_LOG_FUNCTION(this << winStart << winSize);
30 m_winStart = winStart;
31 m_window.assign(winSize, false);
32 m_head = 0;
33}
34
35void
36BlockAckWindow::Reset(uint16_t winStart)
37{
38 Init(winStart, m_window.size());
39}
40
41uint16_t
43{
44 return m_winStart;
45}
46
47uint16_t
49{
50 return (m_winStart + m_window.size() - 1) % SEQNO_SPACE_SIZE;
51}
52
53std::size_t
55{
56 return m_window.size();
57}
58
59std::vector<bool>::reference
60BlockAckWindow::At(std::size_t distance)
61{
62 NS_ASSERT(distance < m_window.size());
63
64 return m_window.at((m_head + distance) % m_window.size());
65}
66
67std::vector<bool>::const_reference
68BlockAckWindow::At(std::size_t distance) const
69{
70 NS_ASSERT(distance < m_window.size());
71
72 return m_window.at((m_head + distance) % m_window.size());
73}
74
75void
76BlockAckWindow::Advance(std::size_t count)
77{
78 NS_LOG_FUNCTION(this << count);
79
80 if (count >= m_window.size())
81 {
83 return;
84 }
85
86 for (std::size_t i = 0; i < count; i++)
87 {
88 m_window[m_head] = false;
89 m_head = (m_head + 1) % m_window.size();
90 }
92}
93
94} // 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:55
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition log.h:191
#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:176