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 
35 NS_LOG_COMPONENT_DEFINE("SatBstpController");
36 
37 namespace ns3
38 {
39 
40 NS_OBJECT_ENSURE_REGISTERED(SatBstpController);
41 
43  : m_gwNdCallbacks(),
44  m_bhMode(SatBstpController::BH_STATIC),
45  m_configFileName("SatBstpConf.txt"),
46  m_superFrameDuration(MilliSeconds(100)),
47  m_staticBstp()
48 {
49  NS_LOG_FUNCTION(this);
50 
51  ObjectBase::ConstructSelf(AttributeConstructionList());
52 
54  {
55  m_staticBstp = Create<SatStaticBstp>(m_configFileName);
56  }
58  {
59  NS_FATAL_ERROR("Beam hopping supports currently only STATIC mode!");
60  }
61 }
62 
64 {
65  m_staticBstp = NULL;
66 }
67 
68 void
70 {
71  NS_LOG_FUNCTION(this);
72 
73  if (m_staticBstp)
74  {
75  m_staticBstp->CheckValidity();
76  }
77 
79 }
80 
81 TypeId
83 {
84  static TypeId tid =
85  TypeId("ns3::SatBstpController")
86  .SetParent<Object>()
87  .AddConstructor<SatBstpController>()
88  .AddAttribute("BeamHoppingMode",
89  "Beam hopping mode.",
91  MakeEnumAccessor(&SatBstpController::m_bhMode),
92  MakeEnumChecker(SatBstpController::BH_STATIC,
93  "Static",
95  "Dynamic"))
96  .AddAttribute("StaticBeamHoppingConfigFileName",
97  "Configuration file name for static beam hopping.",
98  StringValue("SatBstpConf_GW1.txt"),
99  MakeStringAccessor(&SatBstpController::m_configFileName),
100  MakeStringChecker())
101  .AddAttribute("SuperframeDuration",
102  "Superframe duration in Time.",
103  TimeValue(MilliSeconds(10)),
104  MakeTimeAccessor(&SatBstpController::m_superFrameDuration),
105  MakeTimeChecker());
106  return tid;
107 }
108 
109 TypeId
111 {
112  NS_LOG_FUNCTION(this);
113 
114  return GetTypeId();
115 }
116 
117 void
119 {
120  NS_LOG_FUNCTION(this);
121 
122  for (CallbackContainer_t::iterator it = m_gwNdCallbacks.begin(); it != m_gwNdCallbacks.end();
123  ++it)
124  {
125  it->second.Nullify();
126  }
127 
128  Object::DoDispose();
129 }
130 
131 void
133  uint32_t userFreqId,
134  uint32_t feederFreqId,
135  uint32_t gwId,
137 {
138  NS_LOG_FUNCTION(this << beamId << userFreqId << feederFreqId << gwId);
139 
145  NS_LOG_INFO("Add beam: " << beamId << ", userFreqId: " << userFreqId
146  << ", feederFreqId: " << feederFreqId << ", gwId: " << gwId);
147 
148  if (m_staticBstp)
149  {
150  m_staticBstp->AddEnabledBeamInfo(beamId, userFreqId, feederFreqId, gwId);
151  }
152 
153  m_gwNdCallbacks.insert(std::make_pair(beamId, cb));
154 }
155 
156 void
158 {
159  NS_LOG_FUNCTION(this);
160 
161  uint32_t validityInSuperframes(1);
162 
163  if (m_staticBstp)
164  {
165  // Read next BSTP configuration
166  std::vector<uint32_t> nextConf = m_staticBstp->GetNextConf();
167 
168  // First column is the validity
169  validityInSuperframes = nextConf.front();
170 
171  // Read BSTP entry and do configuration
172  for (CallbackContainer_t::iterator it = m_gwNdCallbacks.begin();
173  it != m_gwNdCallbacks.end();
174  ++it)
175  {
176  uint32_t beamId = (*it).first;
177 
183  if (std::find(nextConf.begin() + 1, nextConf.end(), beamId) != nextConf.end())
184  {
185  (*it).second(true);
186  }
187  else
188  {
189  (*it).second(false);
190  }
191  }
192  }
193  else
194  {
195  NS_FATAL_ERROR("Dynamic beam switching time plan not yet supported!");
196  }
197 
201  Time nextConfigurationDuration(validityInSuperframes * m_superFrameDuration);
202  Simulator::Schedule(nextConfigurationDuration, &SatBstpController::DoBstpConfiguration, this);
203 }
204 
205 } // 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.