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 
36 NS_LOG_COMPONENT_DEFINE("SatTbtpContainer");
37 
38 namespace ns3
39 {
40 
41 NS_OBJECT_ENSURE_REGISTERED(SatTbtpContainer);
42 
43 TypeId
45 {
46  static TypeId tid = TypeId("ns3::SatTbtpContainer")
47  .SetParent<Object>()
48  .AddConstructor<SatTbtpContainer>()
49  .AddAttribute("MaxStoredTbtps",
50  "Maximum amount of stored TBTPs",
51  UintegerValue(100),
52  MakeUintegerAccessor(&SatTbtpContainer::m_maxStoredTbtps),
53  MakeUintegerChecker<uint32_t>());
54  return tid;
55 }
56 
58  : m_address(),
59  m_maxStoredTbtps(100),
60  m_rcvdTbtps(0),
61  m_superFrameDuration(0)
62 {
63  NS_FATAL_ERROR("SatTbtpContainer::SatTbtpContainer - Constructor not in use");
64 }
65 
66 SatTbtpContainer::SatTbtpContainer(Ptr<SatSuperframeSeq> seq)
67  : m_address(),
68  m_superframeSeq(seq),
69  m_maxStoredTbtps(100),
70  m_rcvdTbtps(0),
71  m_superFrameDuration(
72  seq->GetSuperframeConf(SatConstVariables::SUPERFRAME_SEQUENCE)->GetDuration())
73 {
74 }
75 
77 {
78 }
79 
80 void
82 {
83  m_tbtps.clear();
84  Object::DoDispose();
85 }
86 
87 void
88 SatTbtpContainer::SetMacAddress(Mac48Address address)
89 {
90  NS_LOG_FUNCTION(this);
91  m_address = address;
92 }
93 
94 void
95 SatTbtpContainer::Add(Time startTime, Ptr<SatTbtpMessage> tbtp)
96 {
97  NS_LOG_FUNCTION(this << startTime.GetSeconds());
98 
99  ++m_rcvdTbtps;
100 
101  m_tbtps.insert(std::make_pair(startTime, tbtp));
102 
103  // If there are too many TBTPs in the container, erase the first
104  if (m_tbtps.size() > m_maxStoredTbtps)
105  {
106  m_tbtps.erase(m_tbtps.begin());
107  }
108 }
109 
110 void
112 {
113  NS_LOG_FUNCTION(this);
114 
115  m_tbtps.clear();
116 }
117 
118 void
120 {
121  NS_LOG_FUNCTION(this);
122 
123  for (TbtpMap_t::iterator it = m_tbtps.begin(); it != m_tbtps.end();)
124  {
125  if ((it->first + m_superFrameDuration) < Now())
126  {
127  m_tbtps.erase(it++);
128  }
129  else
130  {
131  ++it;
132  }
133  }
134 }
135 
136 bool
138 {
139  NS_LOG_FUNCTION(this);
140 
141  bool hasScheduledTimeSlots = false;
142 
143  if (!m_tbtps.empty())
144  {
145  RemovePastTbtps();
146 
148  for (TbtpMap_t::const_reverse_iterator it = m_tbtps.rbegin(); it != m_tbtps.rend(); ++it)
149  {
150  info = it->second->GetDaTimeslots(m_address);
151 
152  // This TBTP has time slots for this UT
153  if (!info.second.empty())
154  {
155  Time superframeStartTime = it->first;
156 
157  // If superframe start time is in the future
158  if (superframeStartTime >= Simulator::Now())
159  {
160  NS_LOG_INFO("Superframe counter: " << it->second->GetSuperframeCounter()
161  << ", start time: "
162  << superframeStartTime.GetSeconds());
163 
164  hasScheduledTimeSlots = true;
165  break;
166  }
167  // On-going superframe
168  else
169  {
174  std::sort(info.second.begin(), info.second.end(), SortTimeSlots());
175 
176  // Start time offset for the last time slot for this UT
177  Time startTimeOffsetForLastSlot = (*(info.second.rbegin()))->GetStartTime();
178 
183  Ptr<SatSuperframeConf> superframeConf =
185  uint8_t frameId = info.first;
186  Ptr<SatFrameConf> frameConf = superframeConf->GetFrameConf(frameId);
187  uint32_t wfId = (*(info.second.rbegin()))->GetWaveFormId();
188  Ptr<SatWaveform> wf = m_superframeSeq->GetWaveformConf()->GetWaveform(wfId);
189  Time lastSlotDuration =
190  wf->GetBurstDuration(frameConf->GetBtuConf()->GetSymbolRateInBauds());
191 
192  NS_LOG_INFO(
193  "Superframe counter: "
194  << it->second->GetSuperframeCounter() << ", start time: "
195  << superframeStartTime.GetSeconds() << ", last allocated slot start time: "
196  << (superframeStartTime + startTimeOffsetForLastSlot).GetSeconds()
197  << ", last allocated slot end time: "
198  << (superframeStartTime + startTimeOffsetForLastSlot + lastSlotDuration)
199  .GetSeconds());
200 
207  if ((superframeStartTime + startTimeOffsetForLastSlot + lastSlotDuration) >
208  Simulator::Now())
209  {
210  hasScheduledTimeSlots = true;
211  }
212  break;
213  }
214  }
215  }
216  }
217 
218  return hasScheduledTimeSlots;
219 }
220 
221 } // namespace ns3
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.
constexpr uint8_t SUPERFRAME_SEQUENCE
Used superframe sequence in the RTN link.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.