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 #include <stdint.h>
27 
28 NS_LOG_COMPONENT_DEFINE("SatUtMacState");
29 
30 namespace ns3
31 {
32 
33 NS_OBJECT_ENSURE_REGISTERED(SatUtMacState);
34 
35 TypeId
37 {
38  static TypeId tid =
39  TypeId("ns3::SatUtMacState")
40  .SetParent<Object>()
41  .AddConstructor<SatUtMacState>()
42  .AddAttribute("NcrSyncTimeout",
43  "Time allowed before switching to NCR_RECOVERY state",
44  TimeValue(Seconds(1)),
45  MakeTimeAccessor(&SatUtMacState::m_ncrSyncTimeout),
46  MakeTimeChecker())
47  .AddAttribute("NcrRecoveryTimeout",
48  "Time allowed before switching from NCR_RECOVERY to OFF_STANDBY",
49  TimeValue(Seconds(1)),
50  MakeTimeAccessor(&SatUtMacState::m_ncrRecoveryTimeout),
51  MakeTimeChecker());
52  return tid;
53 }
54 
55 TypeId
57 {
58  NS_LOG_FUNCTION(this);
59 
60  return GetTypeId();
61 }
62 
64  : m_rcstState(HOLD_STANDBY),
65  m_lastNcrDateReceived(Seconds(0)),
66  m_checkNcrRecoveryScheduled(Seconds(0)),
67  m_ncrSyncTimeout(Seconds(1)),
68  m_ncrRecoveryTimeout(Seconds(10))
69 {
70  NS_LOG_FUNCTION(this);
71 }
72 
74 {
75  NS_LOG_FUNCTION(this);
76 }
77 
78 void
80 {
81  NS_LOG_FUNCTION(this);
82 
83  m_logOffCallback = cb;
84 }
85 
88 {
89  NS_LOG_FUNCTION(this);
90 
91  return m_rcstState;
92 }
93 
94 void
96 {
97  NS_LOG_FUNCTION(this);
98 
99  // Can transition from all other states including itself
101 }
102 
103 void
105 {
106  NS_LOG_FUNCTION(this);
107 
108  // Can transition from all other states including itself
110 }
111 
112 void
114 {
115  NS_LOG_FUNCTION(this);
116 
117  // Can transition from OFF_STANDBY, NCR_RECOVERY or itself
120  {
122  }
123  else
124  {
125  NS_FATAL_ERROR("Cannot transition to READY_FOR_LOGON state");
126  }
127 }
128 
129 void
131 {
132  NS_LOG_FUNCTION(this);
133 
134  // Can transition from READY_FOR_LOGON or NCR_RECOVERY
136  {
138  }
139  else
140  {
141  NS_FATAL_ERROR("Cannot transition to READY_FOR_TDMA_SYNC state");
142  }
143 }
144 
145 void
147 {
148  NS_LOG_FUNCTION(this);
149 
150  // Can transition from READY_FOR_TDMA_SYNC or itself
153  {
155  Simulator::Schedule(m_ncrSyncTimeout, &SatUtMacState::CheckNcrTimeout, this);
156  }
157  else
158  {
159  NS_FATAL_ERROR("Cannot transition to TDMA_SYNC state");
160  }
161 }
162 
163 void
165 {
166  NS_LOG_FUNCTION(this);
167 
168  // Can transition from TDMA_SYNC
170  {
172  }
173  else
174  {
175  NS_FATAL_ERROR("Cannot transition to NCR_RECOVERY state");
176  }
177 }
178 
179 void
181 {
182  NS_LOG_FUNCTION(this);
183 
184  m_lastNcrDateReceived = Simulator::Now();
185 
186  if (GetState() == NCR_RECOVERY)
187  {
189  }
190 }
191 
192 bool
194 {
195  NS_LOG_FUNCTION(this);
196 
197  return Simulator::Now() > m_lastNcrDateReceived + m_ncrSyncTimeout;
198 }
199 
200 void
202 {
203  NS_LOG_FUNCTION(this);
204 
205  if (GetState() != TDMA_SYNC)
206  {
207  return;
208  }
209 
210  if (m_lastNcrDateReceived + m_ncrSyncTimeout <= Simulator::Now())
211  {
213  m_checkNcrRecoveryScheduled = Simulator::Now();
215  }
216  else
217  {
218  Time nextTimeout = m_lastNcrDateReceived + m_ncrSyncTimeout - Simulator::Now();
219  Simulator::Schedule(nextTimeout, &SatUtMacState::CheckNcrTimeout, this);
220  }
221 }
222 
223 void
225 {
226  NS_LOG_FUNCTION(this);
227 
228  if ((m_checkNcrRecoveryScheduled + m_ncrRecoveryTimeout <= Simulator::Now()) &&
229  (GetState() == NCR_RECOVERY))
230  {
232  }
233 }
234 
235 } // 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.