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 
24 #include "../utils/satellite-env-variables.h"
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 
35 NS_LOG_COMPONENT_DEFINE("SatRxCnoInputTraceContainer");
36 
37 namespace ns3
38 {
39 
40 NS_OBJECT_ENSURE_REGISTERED(SatRxCnoInputTraceContainer);
41 
42 TypeId
44 {
45  static TypeId tid = TypeId("ns3::SatRxCnoInputTraceContainer")
46  .SetParent<SatBaseTraceContainer>()
47  .AddConstructor<SatRxCnoInputTraceContainer>();
48  return tid;
49 }
50 
51 TypeId
53 {
54  NS_LOG_FUNCTION(this);
55 
56  return GetTypeId();
57 }
58 
60 {
61  NS_LOG_FUNCTION(this);
62 }
63 
65 {
66  NS_LOG_FUNCTION(this);
67 
68  Reset();
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION(this);
75 
76  Reset();
77 
78  SatBaseTraceContainer::DoDispose();
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION(this);
85 
86  if (!m_container.empty())
87  {
88  m_container.clear();
89  }
90 
91  if (!m_containerConstantCno.empty())
92  {
93  m_containerConstantCno.clear();
94  }
95 }
96 
97 Ptr<SatInputFileStreamTimeDoubleContainer>
99 {
100  NS_LOG_FUNCTION(this);
101 
102  std::stringstream filename;
103  std::string dataPath = Singleton<SatEnvVariables>::Get()->LocateDataDirectory();
104 
105  int32_t gwId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(key.first);
106  int32_t utId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(key.first);
107  int32_t beamId = Singleton<SatIdMapper>::Get()->GetBeamIdWithMac(key.first);
108 
109  if (beamId < 0 || (utId < 0 && gwId < 0))
110  {
111  return nullptr;
112  }
113  else
114  {
115  if (utId >= 0 && gwId < 0)
116  {
117  filename << dataPath << "/rxcnotraces/input/BEAM_" << beamId << "_UT_" << utId
118  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
119  }
120 
121  if (gwId >= 0 && utId < 0)
122  {
123  filename << dataPath << "/rxcnotraces/input/BEAM_" << beamId << "_GW_" << gwId
124  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
125  }
126 
127  std::pair<container_t::iterator, bool> result = m_container.insert(
128  std::make_pair(key,
129  CreateObject<SatInputFileStreamTimeDoubleContainer>(
130  filename.str().c_str(),
131  std::ios::in,
133 
134  if (result.second == false)
135  {
136  NS_FATAL_ERROR("SatRxCnoInputTraceContainer::AddNode failed");
137  }
138 
139  NS_LOG_INFO("Added node with MAC " << key.first << " channel type " << key.second);
140 
141  return result.first->second;
142  }
143 
144  NS_FATAL_ERROR("SatRxCnoInputTraceContainer::AddNode failed");
145  return nullptr;
146 }
147 
148 Ptr<SatInputFileStreamTimeDoubleContainer>
150 {
151  NS_LOG_FUNCTION(this);
152 
153  container_t::iterator iter = m_container.find(key);
154 
155  if (iter == m_container.end())
156  {
157  return AddNode(key);
158  }
159 
160  return iter->second;
161 }
162 
163 double
165 {
166  NS_LOG_FUNCTION(this);
167 
168  containerConstantCno_t::iterator iter = m_containerConstantCno.find(key);
169  if (iter == m_containerConstantCno.end())
170  {
171  // No manual value has been set, read it from file
172  return FindNode(key)->ProceedToNextClosestTimeSample().at(
174  }
175 
176  // Otherwise return the manual value stored in the container
177  return iter->second;
178 }
179 
180 void
182 {
183  NS_LOG_FUNCTION(this << cno);
184 
185  containerConstantCno_t::iterator iter = m_containerConstantCno.find(key);
186  if (iter != m_containerConstantCno.end())
187  {
188  // Key already existing, updating value
189  iter->second = cno;
190  }
191  else
192  {
193  // Add a new key and corresponding value to container
194  std::pair<containerConstantCno_t::iterator, bool> result =
195  m_containerConstantCno.insert(std::make_pair(key, cno));
196  if (result.second == false)
197  {
198  NS_FATAL_ERROR("SatRxCnoInputTraceContainer::SetRxCno failed");
199  }
200  }
201 }
202 
203 void
205 {
206  NS_LOG_FUNCTION(this);
207 
208  container_t::iterator iter = m_container.find(key);
209  if (iter != m_container.end())
210  {
211  // Key already existing, updating value
212  iter->second = CreateObject<SatInputFileStreamTimeDoubleContainer>(
213  path,
214  std::ios::in,
216  }
217  else
218  {
219  // Add a new key and corresponding value to container
220  std::pair<container_t::iterator, bool> result = m_container.insert(
221  std::make_pair(key,
222  CreateObject<SatInputFileStreamTimeDoubleContainer>(
223  path,
224  std::ios::in,
226 
227  if (result.second == false)
228  {
229  NS_FATAL_ERROR("SatRxCnoInputTraceContainer::SetRxCnoFile failed");
230  }
231  }
232 
233  // Remove key in m_containerConstantCno
234  if (m_containerConstantCno.find(key) != m_containerConstantCno.end())
235  {
236  // Key already existing, updating value
237  m_containerConstantCno.erase(key);
238  }
239 }
240 
241 } // namespace ns3
Base class for trace containers such as interference or fading traces.
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)
containerConstantCno_t m_containerConstantCno
Container to store the constant values of C/N0.
TypeId GetInstanceTypeId(void) const
NS-3 instance type id function.
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.