Loading...
Searching...
No Matches
satellite-rtn-link-time.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/assert.h"
24#include "ns3/log.h"
25#include "ns3/nstime.h"
26
27#include <math.h>
28
29NS_LOG_COMPONENT_DEFINE("SatRtnLinkTime");
30
31namespace ns3
32{
33
36{
37 NS_LOG_FUNCTION(this);
38}
39
43
44void
45SatRtnLinkTime::Initialize(Ptr<SatSuperframeSeq> seq)
46{
47 NS_LOG_FUNCTION(this);
48 m_superframeSeq = seq;
49}
50
51Time
52SatRtnLinkTime::GetSuperFrameDuration(uint8_t superFrameSeqId) const
53{
54 NS_LOG_FUNCTION(this << (uint32_t)superFrameSeqId);
55
56 return m_superframeSeq->GetDuration(superFrameSeqId);
57}
58
59uint32_t
60SatRtnLinkTime::GetCurrentSuperFrameCount(uint8_t superFrameSeqId) const
61{
62 NS_LOG_FUNCTION(this << (uint32_t)superFrameSeqId);
63
64 return (uint32_t)(Simulator::Now().GetInteger() /
65 m_superframeSeq->GetDuration(superFrameSeqId).GetInteger());
66}
67
68uint32_t
69SatRtnLinkTime::GetNextSuperFrameCount(uint8_t superFrameSeqId) const
70{
71 NS_LOG_FUNCTION(this << (uint32_t)superFrameSeqId);
72
73 return GetCurrentSuperFrameCount(superFrameSeqId) + 1;
74}
75
76Time
78{
79 NS_LOG_FUNCTION(this << (uint32_t)superFrameSeqId);
80
81 uint32_t count = GetCurrentSuperFrameCount(superFrameSeqId);
82 return Time(count * m_superframeSeq->GetDuration(superFrameSeqId).GetInteger());
83}
84
85Time
86SatRtnLinkTime::GetNextSuperFrameStartTime(uint8_t superFrameSeqId) const
87{
88 NS_LOG_FUNCTION(this << superFrameSeqId);
89
90 uint32_t count = GetNextSuperFrameCount(superFrameSeqId);
91 return Time(count * m_superframeSeq->GetDuration(superFrameSeqId).GetInteger());
92}
93
94Time
96 uint32_t superFrameCount,
97 Time timingAdvance) const
98{
99 NS_LOG_FUNCTION(this << (uint32_t)superFrameSeqId << superFrameCount
100 << timingAdvance.GetSeconds());
101
102 return (Time(superFrameCount * m_superframeSeq->GetDuration(superFrameSeqId).GetInteger()) -
103 timingAdvance);
104}
105
106uint32_t
107SatRtnLinkTime::GetCurrentSuperFrameCount(uint8_t superFrameSeqId, Time timingAdvance) const
108{
109 NS_LOG_FUNCTION(this << superFrameSeqId << timingAdvance.GetSeconds());
110
111 Time earliestRxTime = Simulator::Now() + timingAdvance;
112 uint32_t count =
113 earliestRxTime.GetInteger() / m_superframeSeq->GetDuration(superFrameSeqId).GetInteger();
114
115 return count;
116}
117
118uint32_t
119SatRtnLinkTime::GetNextSuperFrameCount(uint8_t superFrameSeqId, Time timingAdvance) const
120{
121 NS_LOG_FUNCTION(this << (uint32_t)superFrameSeqId << timingAdvance.GetSeconds());
122
123 uint32_t nextCount = GetCurrentSuperFrameCount(superFrameSeqId, timingAdvance) + 1;
124
125 return nextCount;
126}
127
128Time
129SatRtnLinkTime::GetCurrentSuperFrameTxTime(uint8_t superFrameSeqId, Time timingAdvance) const
130{
131 NS_LOG_FUNCTION(this << superFrameSeqId << timingAdvance.GetSeconds());
132
133 Time expectedSuperframeReceiveStartTime =
134 Time(GetCurrentSuperFrameCount(superFrameSeqId, timingAdvance) *
135 m_superframeSeq->GetDuration(superFrameSeqId).GetInteger());
136 Time transmitStart = expectedSuperframeReceiveStartTime - timingAdvance;
137
138 return transmitStart;
139}
140
141Time
142SatRtnLinkTime::GetNextSuperFrameTxTime(uint8_t superFrameSeqId, Time timingAdvance) const
143{
144 NS_LOG_FUNCTION(this << (uint32_t)superFrameSeqId << timingAdvance.GetSeconds());
145
146 Time expectedSuperframeReceiveStartTime =
147 Time(GetNextSuperFrameCount(superFrameSeqId, timingAdvance) *
148 m_superframeSeq->GetDuration(superFrameSeqId).GetInteger());
149 Time transmitStart = expectedSuperframeReceiveStartTime - timingAdvance;
150
151 return transmitStart;
152}
153
154} // namespace ns3
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.