Loading...
Searching...
No Matches
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
23
24#include "ns3/log.h"
25
26#include <stdint.h>
27
28NS_LOG_COMPONENT_DEFINE("SatUtMacState");
29
30namespace ns3
31{
32
33NS_OBJECT_ENSURE_REGISTERED(SatUtMacState);
34
35TypeId
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
57 m_lastNcrDateReceived(Seconds(0)),
59 m_ncrSyncTimeout(Seconds(1)),
60 m_ncrRecoveryTimeout(Seconds(10))
61{
62 NS_LOG_FUNCTION(this);
63}
64
66{
67 NS_LOG_FUNCTION(this);
68}
69
70void
77
80{
81 NS_LOG_FUNCTION(this);
82
83 return m_rcstState;
84}
85
86void
88{
89 NS_LOG_FUNCTION(this);
90
91 // Can transition from all other states including itself
93}
94
95void
97{
98 NS_LOG_FUNCTION(this);
99
100 // Can transition from all other states including itself
102}
103
104void
106{
107 NS_LOG_FUNCTION(this);
108
109 // Can transition from OFF_STANDBY, NCR_RECOVERY or itself
112 {
114 }
115 else
116 {
117 NS_FATAL_ERROR("Cannot transition to READY_FOR_LOGON state");
118 }
119}
120
121void
123{
124 NS_LOG_FUNCTION(this);
125
126 // Can transition from READY_FOR_LOGON or NCR_RECOVERY
128 {
130 }
131 else
132 {
133 NS_FATAL_ERROR("Cannot transition to READY_FOR_TDMA_SYNC state");
134 }
135}
136
137void
139{
140 NS_LOG_FUNCTION(this);
141
142 // Can transition from READY_FOR_TDMA_SYNC or itself
145 {
147 Simulator::Schedule(m_ncrSyncTimeout, &SatUtMacState::CheckNcrTimeout, this);
148 }
149 else
150 {
151 NS_FATAL_ERROR("Cannot transition to TDMA_SYNC state");
152 }
153}
154
155void
157{
158 NS_LOG_FUNCTION(this);
159
160 // Can transition from TDMA_SYNC
162 {
164 }
165 else
166 {
167 NS_FATAL_ERROR("Cannot transition to NCR_RECOVERY state");
168 }
169}
170
171void
173{
174 NS_LOG_FUNCTION(this);
175
176 m_lastNcrDateReceived = Simulator::Now();
177
178 if (GetState() == NCR_RECOVERY)
179 {
181 }
182}
183
184bool
186{
187 NS_LOG_FUNCTION(this);
188
189 return Simulator::Now() > m_lastNcrDateReceived + m_ncrSyncTimeout;
190}
191
192void
194{
195 NS_LOG_FUNCTION(this);
196
197 if (GetState() != TDMA_SYNC)
198 {
199 return;
200 }
201
202 if (m_lastNcrDateReceived + m_ncrSyncTimeout <= Simulator::Now())
203 {
205 m_checkNcrRecoveryScheduled = Simulator::Now();
207 }
208 else
209 {
210 Time nextTimeout = m_lastNcrDateReceived + m_ncrSyncTimeout - Simulator::Now();
211 Simulator::Schedule(nextTimeout, &SatUtMacState::CheckNcrTimeout, this);
212 }
213}
214
215void
217{
218 NS_LOG_FUNCTION(this);
219
220 if ((m_checkNcrRecoveryScheduled + m_ncrRecoveryTimeout <= Simulator::Now()) &&
221 (GetState() == NCR_RECOVERY))
222 {
224 }
225}
226
227} // namespace ns3
Class handling UT Mac states and transitions.
void SwitchToReadyForTdmaSync()
Change state to READY_FOR_TDMA_SYNC.
void SwitchToNcrRecovery()
Change state to NCR_RECOVERY.
void SetLogOffCallback(LogOffCallback cb)
Set logOff callback.
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.
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.