satellite-arq-sequence-number.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2013 Magister Solutions Ltd.
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: Jani Puttonen <jani.puttonen@magister.fi>
19  */
20 
22 
23 #include <ns3/log.h>
24 
25 NS_LOG_COMPONENT_DEFINE("SatArqSequenceNumber");
26 
27 namespace ns3
28 {
29 
31  : m_seqNoMap(),
32  m_currSeqNo(-1),
33  m_windowSize(0),
34  m_maxSn(std::numeric_limits<uint8_t>::max())
35 {
36  NS_LOG_FUNCTION(this);
37  NS_ASSERT(false);
38 
42 }
43 
45  : m_seqNoMap(),
46  m_currSeqNo(-1),
47  m_windowSize(windowSize),
48  m_maxSn(std::numeric_limits<uint8_t>::max())
49 {
50  NS_LOG_FUNCTION(this << (uint32_t)windowSize);
51 }
52 
53 bool
55 {
56  NS_LOG_FUNCTION(this);
57  return (m_seqNoMap.size() < m_windowSize);
58 }
59 
60 uint8_t
62 {
63  NS_LOG_FUNCTION(this);
64  NS_ASSERT(SeqNoAvailable());
65 
66  m_currSeqNo++;
67  uint8_t sn = uint8_t(m_currSeqNo % m_maxSn);
68  m_seqNoMap[m_currSeqNo] = false;
69 
70  return sn;
71 }
72 
73 void
75 {
76  NS_LOG_FUNCTION(this << (uint32_t)seqNo);
77 
78  uint32_t factor = uint32_t(m_currSeqNo / m_maxSn);
79  uint32_t mod = uint32_t(m_currSeqNo % m_maxSn);
80  uint32_t sn;
81 
82  // Same seqNo window
83  if (seqNo <= mod)
84  {
85  sn = factor * m_maxSn + seqNo;
86  }
87  // Different seqNo window
88  else
89  {
90  sn = (factor - 1) * m_maxSn + seqNo;
91  }
92 
93  m_seqNoMap[sn] = true;
94 
95  CleanUp();
96 }
97 
98 void
100 {
101  NS_LOG_FUNCTION(this);
102 
103  std::map<uint32_t, bool>::iterator it = m_seqNoMap.begin();
104 
105  while (it != m_seqNoMap.end() && it->second == true)
106  {
107  m_seqNoMap.erase(it);
108  it = m_seqNoMap.begin();
109  }
110 }
111 
112 } // namespace ns3
uint8_t NextSequenceNumber()
Returns the next free sequence number.
bool SeqNoAvailable() const
Check whether there are free (released) sequence numbers.
std::map< uint32_t, bool > m_seqNoMap
void CleanUp()
Clean ups the sequence number map.
void Release(uint8_t seqNo)
Release a sequence number if either ACK is received or maximum retransmissions have been reached.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.