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 #include <limits>
26 #include <map>
27 
28 NS_LOG_COMPONENT_DEFINE("SatArqSequenceNumber");
29 
30 namespace ns3
31 {
32 
34  : m_seqNoMap(),
35  m_currSeqNo(-1),
36  m_windowSize(0),
37  m_maxSn(std::numeric_limits<uint8_t>::max())
38 {
39  NS_LOG_FUNCTION(this);
40  NS_ASSERT(false);
41 
45 }
46 
48  : m_seqNoMap(),
49  m_currSeqNo(-1),
50  m_windowSize(windowSize),
51  m_maxSn(std::numeric_limits<uint8_t>::max())
52 {
53  NS_LOG_FUNCTION(this << (uint32_t)windowSize);
54 }
55 
56 bool
58 {
59  NS_LOG_FUNCTION(this);
60  return (m_seqNoMap.size() < m_windowSize);
61 }
62 
63 uint8_t
65 {
66  NS_LOG_FUNCTION(this);
67  NS_ASSERT(SeqNoAvailable());
68 
69  m_currSeqNo++;
70  uint8_t sn = uint8_t(m_currSeqNo % m_maxSn);
71  m_seqNoMap[m_currSeqNo] = false;
72 
73  return sn;
74 }
75 
76 void
78 {
79  NS_LOG_FUNCTION(this << (uint32_t)seqNo);
80 
81  uint32_t factor = uint32_t(m_currSeqNo / m_maxSn);
82  uint32_t mod = uint32_t(m_currSeqNo % m_maxSn);
83  uint32_t sn;
84 
85  // Same seqNo window
86  if (seqNo <= mod)
87  {
88  sn = factor * m_maxSn + seqNo;
89  }
90  // Different seqNo window
91  else
92  {
93  sn = (factor - 1) * m_maxSn + seqNo;
94  }
95 
96  m_seqNoMap[sn] = true;
97 
98  CleanUp();
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION(this);
105 
106  std::map<uint32_t, bool>::iterator it = m_seqNoMap.begin();
107 
108  while (it != m_seqNoMap.end() && it->second == true)
109  {
110  m_seqNoMap.erase(it);
111  it = m_seqNoMap.begin();
112  }
113 }
114 
115 } // 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.