satellite-ut-mac-state.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2014 Magister Solutions Ltd
4  * Copyright (c) 2018 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
20  */
21 
22 #include "satellite-ut-mac-state.h"
23 
24 #include <ns3/log.h>
25 
26 NS_LOG_COMPONENT_DEFINE("SatUtMacState");
27 
28 namespace ns3
29 {
30 
31 NS_OBJECT_ENSURE_REGISTERED(SatUtMacState);
32 
33 TypeId
35 {
36  static TypeId tid =
37  TypeId("ns3::SatUtMacState")
38  .SetParent<Object>()
39  .AddConstructor<SatUtMacState>()
40  .AddAttribute("NcrSyncTimeout",
41  "Time allowed before switching to NCR_RECOVERY state",
42  TimeValue(Seconds(1)),
43  MakeTimeAccessor(&SatUtMacState::m_ncrSyncTimeout),
44  MakeTimeChecker())
45  .AddAttribute("NcrRecoveryTimeout",
46  "Time allowed before switching from NCR_RECOVERY to OFF_STANDBY",
47  TimeValue(Seconds(1)),
48  MakeTimeAccessor(&SatUtMacState::m_ncrRecoveryTimeout),
49  MakeTimeChecker());
50  return tid;
51 }
52 
53 TypeId
55 {
56  NS_LOG_FUNCTION(this);
57 
58  return GetTypeId();
59 }
60 
62  : m_rcstState(HOLD_STANDBY),
63  m_lastNcrDateReceived(Seconds(0)),
64  m_checkNcrRecoveryScheduled(Seconds(0)),
65  m_ncrSyncTimeout(Seconds(1)),
66  m_ncrRecoveryTimeout(Seconds(10))
67 {
68  NS_LOG_FUNCTION(this);
69 }
70 
72 {
73  NS_LOG_FUNCTION(this);
74 }
75 
76 void
78 {
79  NS_LOG_FUNCTION(this);
80 
81  m_logOffCallback = cb;
82 }
83 
86 {
87  NS_LOG_FUNCTION(this);
88 
89  return m_rcstState;
90 }
91 
92 void
94 {
95  NS_LOG_FUNCTION(this);
96 
97  // Can transition from all other states including itself
99 }
100 
101 void
103 {
104  NS_LOG_FUNCTION(this);
105 
106  // Can transition from all other states including itself
108 }
109 
110 void
112 {
113  NS_LOG_FUNCTION(this);
114 
115  // Can transition from OFF_STANDBY, NCR_RECOVERY or itself
118  {
120  }
121  else
122  {
123  NS_FATAL_ERROR("Cannot transition to READY_FOR_LOGON state");
124  }
125 }
126 
127 void
129 {
130  NS_LOG_FUNCTION(this);
131 
132  // Can transition from READY_FOR_LOGON or NCR_RECOVERY
134  {
136  }
137  else
138  {
139  NS_FATAL_ERROR("Cannot transition to READY_FOR_TDMA_SYNC state");
140  }
141 }
142 
143 void
145 {
146  NS_LOG_FUNCTION(this);
147 
148  // Can transition from READY_FOR_TDMA_SYNC or itself
151  {
153  Simulator::Schedule(m_ncrSyncTimeout, &SatUtMacState::CheckNcrTimeout, this);
154  }
155  else
156  {
157  NS_FATAL_ERROR("Cannot transition to TDMA_SYNC state");
158  }
159 }
160 
161 void
163 {
164  NS_LOG_FUNCTION(this);
165 
166  // Can transition from TDMA_SYNC
168  {
170  }
171  else
172  {
173  NS_FATAL_ERROR("Cannot transition to NCR_RECOVERY state");
174  }
175 }
176 
177 void
179 {
180  NS_LOG_FUNCTION(this);
181 
182  m_lastNcrDateReceived = Simulator::Now();
183 
184  if (GetState() == NCR_RECOVERY)
185  {
187  }
188 }
189 
190 bool
192 {
193  NS_LOG_FUNCTION(this);
194 
195  return Simulator::Now() > m_lastNcrDateReceived + m_ncrSyncTimeout;
196 }
197 
198 void
200 {
201  NS_LOG_FUNCTION(this);
202 
203  if (GetState() != TDMA_SYNC)
204  {
205  return;
206  }
207 
208  if (m_lastNcrDateReceived + m_ncrSyncTimeout <= Simulator::Now())
209  {
211  m_checkNcrRecoveryScheduled = Simulator::Now();
213  }
214  else
215  {
216  Time nextTimeout = m_lastNcrDateReceived + m_ncrSyncTimeout - Simulator::Now();
217  Simulator::Schedule(nextTimeout, &SatUtMacState::CheckNcrTimeout, this);
218  }
219 }
220 
221 void
223 {
224  NS_LOG_FUNCTION(this);
225 
226  if ((m_checkNcrRecoveryScheduled + m_ncrRecoveryTimeout <= Simulator::Now()) &&
227  (GetState() == NCR_RECOVERY))
228  {
230  }
231 }
232 
233 } // namespace ns3
void SwitchToReadyForTdmaSync()
Change state to READY_FOR_TDMA_SYNC.
void SwitchToNcrRecovery()
Change state to NCR_RECOVERY.
void SetLogOffCallback(LogOffCallback cb)
Set logOff callback.
LogOffCallback m_logOffCallback
void SwitchToOffStandby()
Change state to OFF_STANDBY.
void NcrControlMessageReceived()
Inform the state diagram that a NCR message has been received.
void SwitchToReadyForLogon()
Change state to READY_FOR_LOGON.
RcstState_t GetState() const
Get the current state.
~SatUtMacState()
Destroy a SatUtMacState.
void SwitchToTdmaSync()
Change state to TDMA_SYNC.
SatUtMacState()
Default constructor, which is not used.
virtual TypeId GetInstanceTypeId(void) const
Derived from Object.
void SwitchToHoldStandby()
Change state to HOLD_STANDBY.
Callback< void > LogOffCallback
LogOff callback.
void CheckNcrTimeout()
Check if NCR has been received before sending a timeout.
void CheckNcrRecoveryTimeout()
Check if timeout reached in NCR_RECOVERY state.
bool IsNcrTimeout() const
Check if NCR m_ncrSyncTimeout has been reached.
static TypeId GetTypeId(void)
Derived from Object.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.