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