A Discrete-Event Network Simulator
API
block-ack-window.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2019 Universita' degli Studi di Napoli Federico II
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: Stefano Avallone <stavallo@unina.it>
19  */
20 
21 #include "ns3/log.h"
22 #include "block-ack-window.h"
23 #include "wifi-utils.h"
24 
25 namespace ns3 {
26 
27 NS_LOG_COMPONENT_DEFINE ("BlockAckWindow");
28 
30  : m_winStart (0),
31  m_head (0)
32 {
33 }
34 
35 void
36 BlockAckWindow::Init (uint16_t winStart, uint16_t winSize)
37 {
38  NS_LOG_FUNCTION (this << winStart << winSize);
39  m_winStart = winStart;
40  m_window.assign (winSize, false);
41  m_head = 0;
42 }
43 
44 void
45 BlockAckWindow::Reset (uint16_t winStart)
46 {
47  Init (winStart, m_window.size ());
48 }
49 
50 uint16_t
52 {
53  return m_winStart;
54 }
55 
56 uint16_t
58 {
59  return (m_winStart + m_window.size () - 1) % SEQNO_SPACE_SIZE;
60 }
61 
62 std::size_t
64 {
65  return m_window.size ();
66 }
67 
69 BlockAckWindow::At (std::size_t distance)
70 {
71  NS_ASSERT (distance < m_window.size ());
72 
73  return m_window.at ((m_head + distance) % m_window.size ());
74 }
75 
76 std::vector<bool>::const_reference
77 BlockAckWindow::At (std::size_t distance) const
78 {
79  NS_ASSERT (distance < m_window.size ());
80 
81  return m_window.at ((m_head + distance) % m_window.size ());
82 }
83 
84 void
85 BlockAckWindow::Advance (std::size_t count)
86 {
87  NS_LOG_FUNCTION (this << count);
88 
89  if (count >= m_window.size ())
90  {
91  Reset ((m_winStart + count) % SEQNO_SPACE_SIZE);
92  return;
93  }
94 
95  for (std::size_t i = 0; i < count; i++)
96  {
97  m_window[m_head] = false;
98  m_head = (m_head + 1) % m_window.size ();
99  }
100  m_winStart = (m_winStart + count) % SEQNO_SPACE_SIZE;
101 }
102 
103 } //namespace ns3
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:205
NS_ASSERT
#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
ns3::BlockAckWindow::GetWinStart
uint16_t GetWinStart(void) const
Get the current winStart value.
Definition: block-ack-window.cc:51
ns3::BlockAckWindow::m_window
std::vector< bool > m_window
window
Definition: block-ack-window.h:124
ns3
Every class exported by the ns3 library is enclosed in the ns3 namespace.
ns3::BlockAckWindow::m_head
std::size_t m_head
index of winStart in the vector
Definition: block-ack-window.h:125
anonymous_namespace{print-introspected-doxygen.cc}::reference
std::string reference
reference tag
Definition: print-introspected-doxygen.cc:87
ns3::BlockAckWindow::m_winStart
uint16_t m_winStart
window start (sequence number)
Definition: block-ack-window.h:123
ns3::SEQNO_SPACE_SIZE
const uint16_t SEQNO_SPACE_SIZE
Size of the space of sequence numbers.
Definition: wifi-utils.h:222
ns3::BlockAckWindow::Reset
void Reset(uint16_t winStart)
Reset the window by clearing all the elements and setting winStart to the given value.
Definition: block-ack-window.cc:45
wifi-utils.h
ns3::BlockAckWindow::Advance
void Advance(std::size_t count)
Advance the current winStart by the given number of positions.
Definition: block-ack-window.cc:85
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Definition: log-macros-enabled.h:244
block-ack-window.h
ns3::BlockAckWindow::GetWinSize
std::size_t GetWinSize(void) const
Get the window size.
Definition: block-ack-window.cc:63
ns3::BlockAckWindow::GetWinEnd
uint16_t GetWinEnd(void) const
Get the current winEnd value.
Definition: block-ack-window.cc:57
ns3::BlockAckWindow::BlockAckWindow
BlockAckWindow()
Constructor.
Definition: block-ack-window.cc:29
ns3::BlockAckWindow::At
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.
Definition: block-ack-window.cc:69
ns3::BlockAckWindow::Init
void Init(uint16_t winStart, uint16_t winSize)
Initialize the window with the given starting sequence number and size.
Definition: block-ack-window.cc:36