Loading...
Searching...
No Matches
satellite-rx-cno-input-trace-container.cc
Go to the documentation of this file.
1/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2/*
3 * Copyright (c) 2013 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: Frans Laakso <frans.laakso@magister.fi>
19 * Bastien Tauran <bastien.tauran@viveris.fr>
20 */
21
23
25#include "satellite-id-mapper.h"
26
27#include "ns3/singleton.h"
28
29#include <ios>
30#include <sstream>
31#include <stdint.h>
32#include <string>
33#include <utility>
34
35NS_LOG_COMPONENT_DEFINE("SatRxCnoInputTraceContainer");
36
37namespace ns3
38{
39
40NS_OBJECT_ENSURE_REGISTERED(SatRxCnoInputTraceContainer);
41
42TypeId
44{
45 static TypeId tid = TypeId("ns3::SatRxCnoInputTraceContainer")
46 .SetParent<SatBaseTraceContainer>()
47 .AddConstructor<SatRxCnoInputTraceContainer>();
48 return tid;
49}
50
55
57{
58 NS_LOG_FUNCTION(this);
59
60 Reset();
61}
62
63void
65{
66 NS_LOG_FUNCTION(this);
67
68 Reset();
69
70 SatBaseTraceContainer::DoDispose();
71}
72
73void
75{
76 NS_LOG_FUNCTION(this);
77
78 if (!m_container.empty())
79 {
80 m_container.clear();
81 }
82
83 if (!m_containerConstantCno.empty())
84 {
86 }
87}
88
89Ptr<SatInputFileStreamTimeDoubleContainer>
91{
92 NS_LOG_FUNCTION(this);
93
94 std::stringstream filename;
95 std::string dataPath = SatEnvVariables::GetInstance()->LocateDataDirectory();
96
97 int32_t gwId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(key.first);
98 int32_t utId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(key.first);
99 int32_t beamId = Singleton<SatIdMapper>::Get()->GetBeamIdWithMac(key.first);
100
101 if (beamId < 0 || (utId < 0 && gwId < 0))
102 {
103 return nullptr;
104 }
105 else
106 {
107 if (utId >= 0 && gwId < 0)
108 {
109 filename << dataPath << "/rxcnotraces/input/BEAM_" << beamId << "_UT_" << utId
110 << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
111 }
112
113 if (gwId >= 0 && utId < 0)
114 {
115 filename << dataPath << "/rxcnotraces/input/BEAM_" << beamId << "_GW_" << gwId
116 << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
117 }
118
119 std::pair<container_t::iterator, bool> result = m_container.insert(
120 std::make_pair(key,
121 CreateObject<SatInputFileStreamTimeDoubleContainer>(
122 filename.str().c_str(),
123 std::ios::in,
125
126 if (result.second == false)
127 {
128 NS_FATAL_ERROR("SatRxCnoInputTraceContainer::AddNode failed");
129 }
130
131 NS_LOG_INFO("Added node with MAC " << key.first << " channel type " << key.second);
132
133 return result.first->second;
134 }
135
136 NS_FATAL_ERROR("SatRxCnoInputTraceContainer::AddNode failed");
137 return nullptr;
138}
139
140Ptr<SatInputFileStreamTimeDoubleContainer>
142{
143 NS_LOG_FUNCTION(this);
144
145 container_t::iterator iter = m_container.find(key);
146
147 if (iter == m_container.end())
148 {
149 return AddNode(key);
150 }
151
152 return iter->second;
153}
154
155double
157{
158 NS_LOG_FUNCTION(this);
159
160 containerConstantCno_t::iterator iter = m_containerConstantCno.find(key);
161 if (iter == m_containerConstantCno.end())
162 {
163 // No manual value has been set, read it from file
164 return FindNode(key)->ProceedToNextClosestTimeSample().at(
166 }
167
168 // Otherwise return the manual value stored in the container
169 return iter->second;
170}
171
172void
174{
175 NS_LOG_FUNCTION(this << cno);
176
177 containerConstantCno_t::iterator iter = m_containerConstantCno.find(key);
178 if (iter != m_containerConstantCno.end())
179 {
180 // Key already existing, updating value
181 iter->second = cno;
182 }
183 else
184 {
185 // Add a new key and corresponding value to container
186 std::pair<containerConstantCno_t::iterator, bool> result =
187 m_containerConstantCno.insert(std::make_pair(key, cno));
188 if (result.second == false)
189 {
190 NS_FATAL_ERROR("SatRxCnoInputTraceContainer::SetRxCno failed");
191 }
192 }
193}
194
195void
197{
198 NS_LOG_FUNCTION(this);
199
200 container_t::iterator iter = m_container.find(key);
201 if (iter != m_container.end())
202 {
203 // Key already existing, updating value
204 iter->second = CreateObject<SatInputFileStreamTimeDoubleContainer>(
205 path,
206 std::ios::in,
208 }
209 else
210 {
211 // Add a new key and corresponding value to container
212 std::pair<container_t::iterator, bool> result = m_container.insert(
213 std::make_pair(key,
214 CreateObject<SatInputFileStreamTimeDoubleContainer>(
215 path,
216 std::ios::in,
218
219 if (result.second == false)
220 {
221 NS_FATAL_ERROR("SatRxCnoInputTraceContainer::SetRxCnoFile failed");
222 }
223 }
224
225 // Remove key in m_containerConstantCno
226 if (m_containerConstantCno.find(key) != m_containerConstantCno.end())
227 {
228 // Key already existing, updating value
229 m_containerConstantCno.erase(key);
230 }
231}
232
233} // namespace ns3
static const uint32_t RX_CNO_TRACE_DEFAULT_RX_POWER_DENSITY_INDEX
Default Rx power density index for Rx power traces.
static const uint32_t RX_CNO_TRACE_DEFAULT_NUMBER_OF_COLUMNS
Default Rx power density index for Rx power traces.
static std::string GetChannelTypeName(ChannelType_t channelType)
static Ptr< SatEnvVariables > GetInstance()
Class for Rx C/N0 input trace container.
containerConstantCno_t m_containerConstantCno
Container to store the constant values of C/N0.
void Reset()
Function for resetting the variables.
Ptr< SatInputFileStreamTimeDoubleContainer > AddNode(std::pair< Address, SatEnums::ChannelType_t > key)
Function for adding the node to the map.
void SetRxCno(key_t key, double cno)
Function for setting the Rx C/N0 with constant value.
std::pair< Address, SatEnums::ChannelType_t > key_t
typedef for map key
double GetRxCno(key_t key)
Function for getting the Rx C/N0.
void SetRxCnoFile(key_t key, std::string path)
Function for setting the Rx C/N0 with input file.
Ptr< SatInputFileStreamTimeDoubleContainer > FindNode(key_t key)
Function for finding the container matching the key.
static TypeId GetTypeId(void)
NS-3 type id function.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.