satellite-cno-helper.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
4  * Copyright (c) 2020 CNES
5  *
6  * This program is free software; you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License version 2 as
8  * published by the Free Software Foundation;
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  *
19  * Author: Bastien Tauran <bastien.tauran@viveris.fr>
20  */
21 
22 #include "satellite-cno-helper.h"
23 
24 #include "ns3/core-module.h"
25 #include "ns3/enum.h"
26 #include "ns3/satellite-id-mapper.h"
27 #include "ns3/satellite-rx-cno-input-trace-container.h"
28 #include "ns3/singleton.h"
29 
30 NS_LOG_COMPONENT_DEFINE("SatelliteCnoHelper");
31 
32 namespace ns3
33 {
34 
35 NS_OBJECT_ENSURE_REGISTERED(SatCnoHelper);
36 
37 TypeId
39 {
40  static TypeId tid =
41  TypeId("ns3::SatCnoHelper").SetParent<Object>().AddConstructor<SatCnoHelper>();
42  return tid;
43 }
44 
45 TypeId
47 {
48  NS_LOG_FUNCTION(this);
49 
50  return GetTypeId();
51 }
52 
54  : m_satHelper(NULL),
55  m_useTraces(false)
56 {
57  Config::Set("/ChannelList/*/$ns3::SatChannel/RxPowerCalculationMode",
58  EnumValue(SatEnums::RX_CNO_INPUT_TRACE));
59 }
60 
61 SatCnoHelper::SatCnoHelper(Ptr<SatHelper> satHelper)
62  : m_satHelper(satHelper),
63  m_useTraces(false)
64 {
65  Config::Set("/ChannelList/*/$ns3::SatChannel/RxPowerCalculationMode",
66  EnumValue(SatEnums::RX_CNO_INPUT_TRACE));
67 }
68 
69 void
71 {
72  m_useTraces = useTraces;
74 }
75 
76 void
77 SatCnoHelper::SetGwNodeCno(Ptr<Node> node, SatEnums::ChannelType_t channel, double cno)
78 {
79  if (channel != SatEnums::FORWARD_FEEDER_CH && channel != SatEnums::RETURN_FEEDER_CH)
80  {
81  NS_FATAL_ERROR("Can only apply custom GWs C/N0 on feeder channels");
82  }
83  if (CheckDuplicate(node, channel))
84  {
85  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
86  }
87  cnoCustomParams_s params;
88  params.node = node;
89  params.isGw = true;
90  params.constant = true;
91  params.channelType = channel;
92  params.cno = cno;
93  m_customCno.push_back(params);
94 
96 }
97 
98 void
99 SatCnoHelper::SetUtNodeCno(Ptr<Node> node, SatEnums::ChannelType_t channel, double cno)
100 {
101  if (channel != SatEnums::FORWARD_USER_CH && channel != SatEnums::RETURN_USER_CH)
102  {
103  NS_FATAL_ERROR("Can only apply custom UTs C/N0 on user channels");
104  }
105  if (CheckDuplicate(node, channel))
106  {
107  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
108  }
109  cnoCustomParams_s params;
110  params.node = node;
111  params.isGw = false;
112  params.constant = true;
113  params.channelType = channel;
114  params.cno = cno;
115  m_customCno.push_back(params);
116 
118 }
119 
120 void
121 SatCnoHelper::SetGwNodeCno(uint32_t nodeId, SatEnums::ChannelType_t channel, double cno)
122 {
123  SetGwNodeCno(m_satHelper->GetBeamHelper()->GetGwNodes().Get(nodeId), channel, cno);
124 }
125 
126 void
127 SatCnoHelper::SetUtNodeCno(uint32_t nodeId, SatEnums::ChannelType_t channel, double cno)
128 {
129  SetUtNodeCno(m_satHelper->GetBeamHelper()->GetUtNodes().Get(nodeId), channel, cno);
130 }
131 
132 void
133 SatCnoHelper::SetGwNodeCno(NodeContainer nodes, SatEnums::ChannelType_t channel, double cno)
134 {
135  for (uint32_t i = 0; i < nodes.GetN(); i++)
136  {
137  SetGwNodeCno(nodes.Get(i), channel, cno);
138  }
139 }
140 
141 void
142 SatCnoHelper::SetUtNodeCno(NodeContainer nodes, SatEnums::ChannelType_t channel, double cno)
143 {
144  for (uint32_t i = 0; i < nodes.GetN(); i++)
145  {
146  SetUtNodeCno(nodes.Get(i), channel, cno);
147  }
148 }
149 
150 void
151 SatCnoHelper::SetGwNodeCnoFile(Ptr<Node> node, SatEnums::ChannelType_t channel, std::string path)
152 {
153  if (channel != SatEnums::FORWARD_FEEDER_CH && channel != SatEnums::RETURN_FEEDER_CH)
154  {
155  NS_FATAL_ERROR("Can only apply custom GWs C/N0 on feeder channels");
156  }
157  if (CheckDuplicate(node, channel))
158  {
159  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
160  }
161  cnoCustomParams_s params;
162  params.node = node;
163  params.isGw = true;
164  params.constant = false;
165  params.channelType = channel;
166  params.pathToFile = path;
167  m_customCno.push_back(params);
168 
170 }
171 
172 void
173 SatCnoHelper::SetUtNodeCnoFile(Ptr<Node> node, SatEnums::ChannelType_t channel, std::string path)
174 {
175  if (channel != SatEnums::FORWARD_USER_CH && channel != SatEnums::RETURN_USER_CH)
176  {
177  NS_FATAL_ERROR("Can only apply custom UTs C/N0 on user channels");
178  }
179  if (CheckDuplicate(node, channel))
180  {
181  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
182  }
183  cnoCustomParams_s params;
184  params.node = node;
185  params.isGw = false;
186  params.constant = false;
187  params.channelType = channel;
188  params.pathToFile = path;
189  m_customCno.push_back(params);
190 
192 }
193 
194 void
195 SatCnoHelper::SetGwNodeCnoFile(uint32_t nodeId, SatEnums::ChannelType_t channel, std::string path)
196 {
197  SetGwNodeCnoFile(m_satHelper->GetBeamHelper()->GetGwNodes().Get(nodeId), channel, path);
198 }
199 
200 void
201 SatCnoHelper::SetUtNodeCnoFile(uint32_t nodeId, SatEnums::ChannelType_t channel, std::string path)
202 {
203  SetUtNodeCnoFile(m_satHelper->GetBeamHelper()->GetUtNodes().Get(nodeId), channel, path);
204 }
205 
206 void
208 {
209  Singleton<SatRxCnoInputTraceContainer>::Get()->Reset();
210 
211  std::pair<Address, SatEnums::ChannelType_t> key;
212  // set default value for all nodes
213  if (!m_useTraces)
214  {
215  // use power calculation from satellite-channel
216  Ptr<Node> gwNode;
217  for (uint32_t i = 0; i < m_satHelper->GetBeamHelper()->GetGwNodes().GetN(); i++)
218  {
219  gwNode = m_satHelper->GetBeamHelper()->GetGwNodes().Get(i);
220  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
222  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
223  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
225  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
226  }
227  Ptr<Node> utNode;
228  for (uint32_t i = 0; i < m_satHelper->GetBeamHelper()->GetUtNodes().GetN(); i++)
229  {
230  utNode = m_satHelper->GetBeamHelper()->GetUtNodes().Get(i);
231  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
233  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
234  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
236  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
237  }
238  }
239  else
240  {
241  // use input files from data/rxcnotraces/input folder
242  Ptr<Node> gwNode;
243  for (uint32_t i = 0; i < m_satHelper->GetBeamHelper()->GetGwNodes().GetN(); i++)
244  {
245  gwNode = m_satHelper->GetBeamHelper()->GetGwNodes().Get(i);
246  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
248  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
249  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
251  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
252  }
253  Ptr<Node> utNode;
254  for (uint32_t i = 0; i < m_satHelper->GetBeamHelper()->GetUtNodes().GetN(); i++)
255  {
256  utNode = m_satHelper->GetBeamHelper()->GetUtNodes().Get(i);
257  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
259  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
260  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
262  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
263  }
264  }
265 
266  // set custom values. The values will cancel the default values set above
267  for (cnoCustomParams_s params : m_customCno)
268  {
269  if (params.isGw)
270  {
271  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(params.node),
272  params.channelType);
273  }
274  else
275  {
276  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(params.node),
277  params.channelType);
278  }
279  if (params.constant)
280  {
281  // Set constant value
282  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, params.cno);
283  }
284  else
285  {
286  // Set custom input file
287  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCnoFile(key, params.pathToFile);
288  }
289  }
290 }
291 
292 bool
294 {
295  for (cnoCustomParams_s params : m_customCno)
296  {
297  if (params.node == node && params.channelType == channel)
298  {
299  return true;
300  }
301  }
302  return false;
303 }
304 
305 } // namespace ns3
void ApplyConfiguration()
Apply configuration to all the satellite channels Needs to be done after node creation.
void SetGwNodeCnoFile(Ptr< Node > node, SatEnums::ChannelType_t channel, std::string path)
Set a constant C/N0 for one GW node and one channel direction.
static TypeId GetTypeId(void)
Get the type ID.
bool m_useTraces
Use C/N0 input traces instead of power calculation from antenna gain.
std::vector< cnoCustomParams_s > m_customCno
Array storing manual C/N0 updates (constant or custom file)
void UseTracesForDefault(bool useTraces)
Set m_useTraces attribute.
void SetUtNodeCnoFile(Ptr< Node > node, SatEnums::ChannelType_t channel, std::string path)
Set a constant C/N0 for one UT node and one channel direction.
void SetGwNodeCno(Ptr< Node > node, SatEnums::ChannelType_t channel, double cno)
Set a constant C/N0 for one GW node and one channel direction.
bool CheckDuplicate(Ptr< Node > node, SatEnums::ChannelType_t channel)
Verify if a node has already been set.
TypeId GetInstanceTypeId(void) const
Get the type ID of object instance.
void SetUtNodeCno(Ptr< Node > node, SatEnums::ChannelType_t channel, double cno)
Set a constant C/N0 for one UT node and one channel direction.
Ptr< SatHelper > m_satHelper
Pointer to the SatHelper objet.
SatCnoHelper()
Default constructor.
ChannelType_t
Types of channel.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.
Struct for storing the custom C/N0 for some nodes.