satellite-bstp-controller.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 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 "satellite-static-bstp.h"
24 
25 #include <ns3/boolean.h>
26 #include <ns3/double.h>
27 #include <ns3/enum.h>
28 #include <ns3/log.h>
29 #include <ns3/nstime.h>
30 #include <ns3/simulator.h>
31 #include <ns3/string.h>
32 
33 #include <algorithm>
34 #include <utility>
35 #include <vector>
36 
37 NS_LOG_COMPONENT_DEFINE("SatBstpController");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatBstpController);
43 
45  : m_gwNdCallbacks(),
46  m_bhMode(SatBstpController::BH_STATIC),
47  m_configFileName("SatBstpConf.txt"),
48  m_superFrameDuration(MilliSeconds(100)),
49  m_staticBstp()
50 {
51  NS_LOG_FUNCTION(this);
52 
53  ObjectBase::ConstructSelf(AttributeConstructionList());
54 
56  {
57  m_staticBstp = Create<SatStaticBstp>(m_configFileName);
58  }
60  {
61  NS_FATAL_ERROR("Beam hopping supports currently only STATIC mode!");
62  }
63 }
64 
66 {
67  m_staticBstp = nullptr;
68 }
69 
70 void
72 {
73  NS_LOG_FUNCTION(this);
74 
75  if (m_staticBstp)
76  {
77  m_staticBstp->CheckValidity();
78  }
79 
81 }
82 
83 TypeId
85 {
86  static TypeId tid =
87  TypeId("ns3::SatBstpController")
88  .SetParent<Object>()
89  .AddConstructor<SatBstpController>()
90  .AddAttribute("BeamHoppingMode",
91  "Beam hopping mode.",
93  MakeEnumAccessor<SatBstpController::BeamHoppingType_t>(
95  MakeEnumChecker(SatBstpController::BH_STATIC,
96  "Static",
98  "Dynamic"))
99  .AddAttribute("StaticBeamHoppingConfigFileName",
100  "Configuration file name for static beam hopping.",
101  StringValue("SatBstpConf_GW1.txt"),
102  MakeStringAccessor(&SatBstpController::m_configFileName),
103  MakeStringChecker())
104  .AddAttribute("SuperframeDuration",
105  "Superframe duration in Time.",
106  TimeValue(MilliSeconds(10)),
107  MakeTimeAccessor(&SatBstpController::m_superFrameDuration),
108  MakeTimeChecker());
109  return tid;
110 }
111 
112 TypeId
114 {
115  NS_LOG_FUNCTION(this);
116 
117  return GetTypeId();
118 }
119 
120 void
122 {
123  NS_LOG_FUNCTION(this);
124 
125  for (CallbackContainer_t::iterator it = m_gwNdCallbacks.begin(); it != m_gwNdCallbacks.end();
126  ++it)
127  {
128  it->second.Nullify();
129  }
130 
131  Object::DoDispose();
132 }
133 
134 void
136  uint32_t userFreqId,
137  uint32_t feederFreqId,
138  uint32_t gwId,
140 {
141  NS_LOG_FUNCTION(this << beamId << userFreqId << feederFreqId << gwId);
142 
148  NS_LOG_INFO("Add beam: " << beamId << ", userFreqId: " << userFreqId
149  << ", feederFreqId: " << feederFreqId << ", gwId: " << gwId);
150 
151  if (m_staticBstp)
152  {
153  m_staticBstp->AddEnabledBeamInfo(beamId, userFreqId, feederFreqId, gwId);
154  }
155 
156  m_gwNdCallbacks.insert(std::make_pair(beamId, cb));
157 }
158 
159 void
161 {
162  NS_LOG_FUNCTION(this);
163 
164  uint32_t validityInSuperframes(1);
165 
166  if (m_staticBstp)
167  {
168  // Read next BSTP configuration
169  std::vector<uint32_t> nextConf = m_staticBstp->GetNextConf();
170 
171  // First column is the validity
172  validityInSuperframes = nextConf.front();
173 
174  // Read BSTP entry and do configuration
175  for (CallbackContainer_t::iterator it = m_gwNdCallbacks.begin();
176  it != m_gwNdCallbacks.end();
177  ++it)
178  {
179  uint32_t beamId = (*it).first;
180 
186  if (std::find(nextConf.begin() + 1, nextConf.end(), beamId) != nextConf.end())
187  {
188  (*it).second(true);
189  }
190  else
191  {
192  (*it).second(false);
193  }
194  }
195  }
196  else
197  {
198  NS_FATAL_ERROR("Dynamic beam switching time plan not yet supported!");
199  }
200 
204  Time nextConfigurationDuration(validityInSuperframes * m_superFrameDuration);
205  Simulator::Schedule(nextConfigurationDuration, &SatBstpController::DoBstpConfiguration, this);
206 }
207 
208 } // namespace ns3
SatBstpController class is responsible of enabling and disabling configurable spot-beams defined by a...
virtual ~SatBstpController()
Destructor for SatRequestManager.
static TypeId GetTypeId(void)
inherited from Object
virtual TypeId GetInstanceTypeId(void) const
Get the type ID of instance.
CallbackContainer_t m_gwNdCallbacks
SatBstpController()
Default constructor.
void Initialize()
Initialize the beam hopping configurations.
Ptr< SatStaticBstp > m_staticBstp
Beam switching time plan.
void AddNetDeviceCallback(uint32_t beamId, uint32_t userFreqId, uint32_t feederFreqId, uint32_t gwId, SatBstpController::ToggleCallback cb)
Add a callback to the SatNetDevice of GW matching to a certain beam id.
virtual void DoDispose()
Dispose of this class instance.
Callback< void, bool > ToggleCallback
Callback to fetch queue statistics.
void DoBstpConfiguration()
Periodical method to enable/disable certain beam ids related to the scheduling and transmission of BB...
Time m_superFrameDuration
Superframe duration in Time.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.