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/satellite-topology.h"
29 #include "ns3/singleton.h"
30 
31 #include <string>
32 #include <utility>
33 
34 NS_LOG_COMPONENT_DEFINE("SatelliteCnoHelper");
35 
36 namespace ns3
37 {
38 
39 NS_OBJECT_ENSURE_REGISTERED(SatCnoHelper);
40 
41 TypeId
43 {
44  static TypeId tid =
45  TypeId("ns3::SatCnoHelper").SetParent<Object>().AddConstructor<SatCnoHelper>();
46  return tid;
47 }
48 
49 TypeId
51 {
52  NS_LOG_FUNCTION(this);
53 
54  return GetTypeId();
55 }
56 
58  : m_satHelper(nullptr),
59  m_useTraces(false)
60 {
61  Config::Set("/ChannelList/*/$ns3::SatChannel/RxPowerCalculationMode",
62  EnumValue(SatEnums::RX_CNO_INPUT_TRACE));
63 }
64 
65 SatCnoHelper::SatCnoHelper(Ptr<SatHelper> satHelper)
66  : m_satHelper(satHelper),
67  m_useTraces(false)
68 {
69  Config::Set("/ChannelList/*/$ns3::SatChannel/RxPowerCalculationMode",
70  EnumValue(SatEnums::RX_CNO_INPUT_TRACE));
71 }
72 
73 void
75 {
76  m_useTraces = useTraces;
78 }
79 
80 void
81 SatCnoHelper::SetGwNodeCno(Ptr<Node> node, SatEnums::ChannelType_t channel, double cno)
82 {
83  if (channel != SatEnums::FORWARD_FEEDER_CH && channel != SatEnums::RETURN_FEEDER_CH)
84  {
85  NS_FATAL_ERROR("Can only apply custom GWs C/N0 on feeder channels");
86  }
87  if (CheckDuplicate(node, channel))
88  {
89  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
90  }
91  cnoCustomParams_s params;
92  params.node = node;
93  params.isGw = true;
94  params.constant = true;
95  params.channelType = channel;
96  params.cno = cno;
97  m_customCno.push_back(params);
98 
100 }
101 
102 void
103 SatCnoHelper::SetUtNodeCno(Ptr<Node> node, SatEnums::ChannelType_t channel, double cno)
104 {
105  if (channel != SatEnums::FORWARD_USER_CH && channel != SatEnums::RETURN_USER_CH)
106  {
107  NS_FATAL_ERROR("Can only apply custom UTs C/N0 on user channels");
108  }
109  if (CheckDuplicate(node, channel))
110  {
111  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
112  }
113  cnoCustomParams_s params;
114  params.node = node;
115  params.isGw = false;
116  params.constant = true;
117  params.channelType = channel;
118  params.cno = cno;
119  m_customCno.push_back(params);
120 
122 }
123 
124 void
125 SatCnoHelper::SetGwNodeCno(uint32_t nodeId, SatEnums::ChannelType_t channel, double cno)
126 {
127  SetGwNodeCno(Singleton<SatTopology>::Get()->GetGwNode(nodeId), channel, cno);
128 }
129 
130 void
131 SatCnoHelper::SetUtNodeCno(uint32_t nodeId, SatEnums::ChannelType_t channel, double cno)
132 {
133  SetUtNodeCno(Singleton<SatTopology>::Get()->GetUtNode(nodeId), channel, cno);
134 }
135 
136 void
137 SatCnoHelper::SetGwNodeCno(NodeContainer nodes, SatEnums::ChannelType_t channel, double cno)
138 {
139  for (uint32_t i = 0; i < nodes.GetN(); i++)
140  {
141  SetGwNodeCno(nodes.Get(i), channel, cno);
142  }
143 }
144 
145 void
146 SatCnoHelper::SetUtNodeCno(NodeContainer nodes, SatEnums::ChannelType_t channel, double cno)
147 {
148  for (uint32_t i = 0; i < nodes.GetN(); i++)
149  {
150  SetUtNodeCno(nodes.Get(i), channel, cno);
151  }
152 }
153 
154 void
155 SatCnoHelper::SetGwNodeCnoFile(Ptr<Node> node, SatEnums::ChannelType_t channel, std::string path)
156 {
157  if (channel != SatEnums::FORWARD_FEEDER_CH && channel != SatEnums::RETURN_FEEDER_CH)
158  {
159  NS_FATAL_ERROR("Can only apply custom GWs C/N0 on feeder channels");
160  }
161  if (CheckDuplicate(node, channel))
162  {
163  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
164  }
165  cnoCustomParams_s params;
166  params.node = node;
167  params.isGw = true;
168  params.constant = false;
169  params.channelType = channel;
170  params.pathToFile = path;
171  m_customCno.push_back(params);
172 
174 }
175 
176 void
177 SatCnoHelper::SetUtNodeCnoFile(Ptr<Node> node, SatEnums::ChannelType_t channel, std::string path)
178 {
179  if (channel != SatEnums::FORWARD_USER_CH && channel != SatEnums::RETURN_USER_CH)
180  {
181  NS_FATAL_ERROR("Can only apply custom UTs C/N0 on user channels");
182  }
183  if (CheckDuplicate(node, channel))
184  {
185  NS_FATAL_ERROR("Trying to set custom C/N0 several time for same node and channel");
186  }
187  cnoCustomParams_s params;
188  params.node = node;
189  params.isGw = false;
190  params.constant = false;
191  params.channelType = channel;
192  params.pathToFile = path;
193  m_customCno.push_back(params);
194 
196 }
197 
198 void
199 SatCnoHelper::SetGwNodeCnoFile(uint32_t nodeId, SatEnums::ChannelType_t channel, std::string path)
200 {
201  SetGwNodeCnoFile(Singleton<SatTopology>::Get()->GetGwNode(nodeId), channel, path);
202 }
203 
204 void
205 SatCnoHelper::SetUtNodeCnoFile(uint32_t nodeId, SatEnums::ChannelType_t channel, std::string path)
206 {
207  SetUtNodeCnoFile(Singleton<SatTopology>::Get()->GetUtNode(nodeId), channel, path);
208 }
209 
210 void
212 {
213  Singleton<SatRxCnoInputTraceContainer>::Get()->Reset();
214 
215  std::pair<Address, SatEnums::ChannelType_t> key;
216  NodeContainer gws = Singleton<SatTopology>::Get()->GetGwNodes();
217  NodeContainer uts = Singleton<SatTopology>::Get()->GetUtNodes();
218  // set default value for all nodes
219  if (!m_useTraces)
220  {
221  // use power calculation from satellite-channel
222  Ptr<Node> gwNode;
223  for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); it++)
224  {
225  gwNode = *it;
226  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
228  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
229  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
231  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
232  }
233  Ptr<Node> utNode;
234  for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
235  {
236  utNode = *it;
237  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
239  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
240  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
242  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, 0);
243  }
244  }
245  else
246  {
247  // use input files from data/rxcnotraces/input folder
248  Ptr<Node> gwNode;
249  for (NodeContainer::Iterator it = gws.Begin(); it != gws.End(); it++)
250  {
251  gwNode = *it;
252  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
254  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
255  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(gwNode),
257  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
258  }
259  Ptr<Node> utNode;
260  for (NodeContainer::Iterator it = uts.Begin(); it != uts.End(); it++)
261  {
262  utNode = *it;
263  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
265  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
266  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(utNode),
268  Singleton<SatRxCnoInputTraceContainer>::Get()->AddNode(key);
269  }
270  }
271 
272  // set custom values. The values will cancel the default values set above
273  for (cnoCustomParams_s params : m_customCno)
274  {
275  if (params.isGw)
276  {
277  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetGwMacWithNode(params.node),
278  params.channelType);
279  }
280  else
281  {
282  key = std::make_pair(Singleton<SatIdMapper>::Get()->GetUtMacWithNode(params.node),
283  params.channelType);
284  }
285  if (params.constant)
286  {
287  // Set constant value
288  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCno(key, params.cno);
289  }
290  else
291  {
292  // Set custom input file
293  Singleton<SatRxCnoInputTraceContainer>::Get()->SetRxCnoFile(key, params.pathToFile);
294  }
295  }
296 }
297 
298 bool
300 {
301  for (cnoCustomParams_s params : m_customCno)
302  {
303  if (params.node == node && params.channelType == channel)
304  {
305  return true;
306  }
307  }
308  return false;
309 }
310 
311 } // 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.
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.