Loading...
Searching...
No Matches
satellite-tbtp-container.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
26
27#include "ns3/log.h"
28#include "ns3/mac48-address.h"
29#include "ns3/nstime.h"
30#include "ns3/simulator.h"
31#include "ns3/uinteger.h"
32
33#include <algorithm>
34#include <iostream>
35#include <utility>
36
37NS_LOG_COMPONENT_DEFINE("SatTbtpContainer");
38
39namespace ns3
40{
41
42NS_OBJECT_ENSURE_REGISTERED(SatTbtpContainer);
43
44TypeId
46{
47 static TypeId tid = TypeId("ns3::SatTbtpContainer")
48 .SetParent<Object>()
49 .AddConstructor<SatTbtpContainer>()
50 .AddAttribute("MaxStoredTbtps",
51 "Maximum amount of stored TBTPs",
52 UintegerValue(100),
53 MakeUintegerAccessor(&SatTbtpContainer::m_maxStoredTbtps),
54 MakeUintegerChecker<uint32_t>());
55 return tid;
56}
57
59 : m_address(),
61 m_rcvdTbtps(0),
63{
64 NS_FATAL_ERROR("SatTbtpContainer::SatTbtpContainer - Constructor not in use");
65}
66
67SatTbtpContainer::SatTbtpContainer(Ptr<SatSuperframeSeq> seq)
68 : m_address(),
69 m_superframeSeq(seq),
71 m_rcvdTbtps(0),
73 seq->GetSuperframeConf(SatConstVariables::SUPERFRAME_SEQUENCE)->GetDuration())
74{
75}
76
80
81void
83{
84 m_tbtps.clear();
85 Object::DoDispose();
86}
87
88void
90{
91 NS_LOG_FUNCTION(this);
92 m_address = address;
93}
94
95void
96SatTbtpContainer::Add(Time startTime, Ptr<SatTbtpMessage> tbtp)
97{
98 NS_LOG_FUNCTION(this << startTime.GetSeconds());
99
100 ++m_rcvdTbtps;
101
102 m_tbtps.insert(std::make_pair(startTime, tbtp));
103
104 // If there are too many TBTPs in the container, erase the first
105 if (m_tbtps.size() > m_maxStoredTbtps)
106 {
107 m_tbtps.erase(m_tbtps.begin());
108 }
109}
110
111void
113{
114 NS_LOG_FUNCTION(this);
115
116 m_tbtps.clear();
117}
118
119void
121{
122 NS_LOG_FUNCTION(this);
123
124 for (TbtpMap_t::iterator it = m_tbtps.begin(); it != m_tbtps.end();)
125 {
126 if ((it->first + m_superFrameDuration) < Now())
127 {
128 m_tbtps.erase(it++);
129 }
130 else
131 {
132 ++it;
133 }
134 }
135}
136
137bool
139{
140 NS_LOG_FUNCTION(this);
141
142 bool hasScheduledTimeSlots = false;
143
144 if (!m_tbtps.empty())
145 {
147
149 for (TbtpMap_t::const_reverse_iterator it = m_tbtps.rbegin(); it != m_tbtps.rend(); ++it)
150 {
151 info = it->second->GetDaTimeslots(m_address);
152
153 // This TBTP has time slots for this UT
154 if (!info.second.empty())
155 {
156 Time superframeStartTime = it->first;
157
158 // If superframe start time is in the future
159 if (superframeStartTime >= Simulator::Now())
160 {
161 NS_LOG_INFO("Superframe counter: " << it->second->GetSuperframeCounter()
162 << ", start time: "
163 << superframeStartTime.GetSeconds());
164
165 hasScheduledTimeSlots = true;
166 break;
167 }
168 // On-going superframe
169 else
170 {
175 std::sort(info.second.begin(), info.second.end(), SortTimeSlots());
176
177 // Start time offset for the last time slot for this UT
178 Time startTimeOffsetForLastSlot = (*(info.second.rbegin()))->GetStartTime();
179
184 Ptr<SatSuperframeConf> superframeConf =
186 uint8_t frameId = info.first;
187 Ptr<SatFrameConf> frameConf = superframeConf->GetFrameConf(frameId);
188 uint32_t wfId = (*(info.second.rbegin()))->GetWaveFormId();
189 Ptr<SatWaveform> wf = m_superframeSeq->GetWaveformConf()->GetWaveform(wfId);
190 Time lastSlotDuration =
191 wf->GetBurstDuration(frameConf->GetBtuConf()->GetSymbolRateInBauds());
192
193 NS_LOG_INFO(
194 "Superframe counter: "
195 << it->second->GetSuperframeCounter() << ", start time: "
196 << superframeStartTime.GetSeconds() << ", last allocated slot start time: "
197 << (superframeStartTime + startTimeOffsetForLastSlot).GetSeconds()
198 << ", last allocated slot end time: "
199 << (superframeStartTime + startTimeOffsetForLastSlot + lastSlotDuration)
200 .GetSeconds());
201
208 if ((superframeStartTime + startTimeOffsetForLastSlot + lastSlotDuration) >
209 Simulator::Now())
210 {
211 hasScheduledTimeSlots = true;
212 }
213 break;
214 }
215 }
216 }
217 }
218
219 return hasScheduledTimeSlots;
220}
221
222} // namespace ns3
A container of received TBTPs.
Ptr< SatSuperframeSeq > m_superframeSeq
Superframe sequence.
Mac48Address m_address
Address of this UT.
static TypeId GetTypeId(void)
Get the type ID.
uint32_t m_rcvdTbtps
Number of received TBTPs.
virtual void DoDispose()
Dispose of this class instance.
bool HasScheduledTimeSlots()
Method of checking whether the UT has been scheduled time slots into the future.
uint32_t m_maxStoredTbtps
Maximum stored TBTPs in the container.
void Add(Time startTime, Ptr< SatTbtpMessage > tbtp)
Add a TBTP message to the container.
~SatTbtpContainer()
Destructor for SatTbtpContainer.
void RemovePastTbtps()
Function for removing the TBTPs which are in the past.
void SetMacAddress(Mac48Address address)
Set the MAC address of this node.
Time m_superFrameDuration
Superframe duration.
SatTbtpContainer()
Default constructor.
std::pair< uint8_t, DaTimeSlotConfContainer_t > DaTimeSlotInfoItem_t
Item for DA time slot information.
This class sorts time slots within TBTP into increasing order based on start time.
SatConstVariables is used for const variable definitions in satellite module.
constexpr uint8_t SUPERFRAME_SEQUENCE
Used superframe sequence in the RTN link.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.