satellite-rx-power-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  */
20 
22 
23 #include "../utils/satellite-env-variables.h"
24 #include "satellite-id-mapper.h"
25 
26 #include <ns3/log.h>
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("SatRxPowerInputTraceContainer");
36 
37 namespace ns3
38 {
39 
40 NS_OBJECT_ENSURE_REGISTERED(SatRxPowerInputTraceContainer);
41 
42 TypeId
44 {
45  static TypeId tid = TypeId("ns3::SatRxPowerInputTraceContainer")
46  .SetParent<SatBaseTraceContainer>()
47  .AddConstructor<SatRxPowerInputTraceContainer>();
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 
92 Ptr<SatInputFileStreamTimeDoubleContainer>
94 {
95  NS_LOG_FUNCTION(this);
96 
97  std::stringstream filename;
98  std::string dataPath = Singleton<SatEnvVariables>::Get()->LocateDataDirectory();
99 
100  int32_t gwId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(key.first);
101  int32_t utId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(key.first);
102  int32_t beamId = Singleton<SatIdMapper>::Get()->GetBeamIdWithMac(key.first);
103 
104  if (beamId < 0 || (utId < 0 && gwId < 0))
105  {
106  return nullptr;
107  }
108  else
109  {
110  if (utId >= 0 && gwId < 0)
111  {
112  filename << dataPath << "/additional-input/rxpowertraces/input/BEAM_" << beamId
113  << "_UT_" << utId << "_channelType_"
114  << SatEnums::GetChannelTypeName(key.second);
115  }
116 
117  if (gwId >= 0 && utId < 0)
118  {
119  filename << dataPath << "/additional-input/rxpowertraces/input/BEAM_" << beamId
120  << "_GW_" << gwId << "_channelType_"
121  << SatEnums::GetChannelTypeName(key.second);
122  }
123 
124  std::pair<container_t::iterator, bool> result = m_container.insert(
125  std::make_pair(key,
126  CreateObject<SatInputFileStreamTimeDoubleContainer>(
127  filename.str().c_str(),
128  std::ios::in,
130 
131  if (result.second == false)
132  {
133  NS_FATAL_ERROR("SatRxPowerInputTraceContainer::AddNode failed");
134  }
135 
136  NS_LOG_INFO("Added node with MAC " << key.first << " channel type " << key.second);
137 
138  return result.first->second;
139  }
140 
141  NS_FATAL_ERROR("SatRxPowerInputTraceContainer::AddNode failed");
142  return nullptr;
143 }
144 
145 Ptr<SatInputFileStreamTimeDoubleContainer>
147 {
148  NS_LOG_FUNCTION(this);
149 
150  container_t::iterator iter = m_container.find(key);
151 
152  if (iter == m_container.end())
153  {
154  return AddNode(key);
155  }
156 
157  return iter->second;
158 }
159 
160 double
162 {
163  NS_LOG_FUNCTION(this);
164 
165  return FindNode(key)->ProceedToNextClosestTimeSample().at(
167 }
168 
169 } // namespace ns3
Base class for trace containers such as interference or fading traces.
static const uint32_t RX_POWER_TRACE_DEFAULT_RX_POWER_DENSITY_INDEX
Default Rx C/N0 index for C/N0 traces.
static const uint32_t RX_POWER_TRACE_DEFAULT_NUMBER_OF_COLUMNS
Default Rx C/N0 index for C/N0 traces.
static std::string GetChannelTypeName(ChannelType_t channelType)
TypeId GetInstanceTypeId(void) const
NS-3 instance type id function.
static TypeId GetTypeId(void)
NS-3 type id function.
std::pair< Address, SatEnums::ChannelType_t > key_t
typedef for map key
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.
Ptr< SatInputFileStreamTimeDoubleContainer > FindNode(key_t key)
Function for finding the container matching the key.
double GetRxPowerDensity(key_t key)
Function for getting the Rx power density.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.