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