satellite-rx-power-output-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/boolean.h>
27 #include <ns3/singleton.h>
28 #include <ns3/string.h>
29 
30 #include <ios>
31 #include <sstream>
32 #include <stdint.h>
33 #include <string>
34 #include <utility>
35 #include <vector>
36 
37 NS_LOG_COMPONENT_DEFINE("SatRxPowerOutputTraceContainer");
38 
39 namespace ns3
40 {
41 
42 NS_OBJECT_ENSURE_REGISTERED(SatRxPowerOutputTraceContainer);
43 
44 TypeId
46 {
47  static TypeId tid = TypeId("ns3::SatRxPowerOutputTraceContainer")
48  .SetParent<SatBaseTraceContainer>()
49  .AddConstructor<SatRxPowerOutputTraceContainer>();
50  return tid;
51 }
52 
53 TypeId
55 {
56  NS_LOG_FUNCTION(this);
57 
58  return GetTypeId();
59 }
60 
62  : m_enableFigureOutput(true)
63 {
64  NS_LOG_FUNCTION(this);
65 }
66 
68 {
69  NS_LOG_FUNCTION(this);
70 
71  Reset();
72 }
73 
74 void
76 {
77  NS_LOG_FUNCTION(this);
78 
79  Reset();
80 
81  SatBaseTraceContainer::DoDispose();
82 }
83 
84 void
86 {
87  NS_LOG_FUNCTION(this);
88 
89  if (!m_container.empty())
90  {
91  WriteToFile();
92 
93  m_container.clear();
94  }
95  m_enableFigureOutput = true;
96 }
97 
98 Ptr<SatOutputFileStreamDoubleContainer>
100 {
101  NS_LOG_FUNCTION(this);
102 
103  std::stringstream filename;
104  std::string dataPath = Singleton<SatEnvVariables>::Get()->GetOutputPath();
105 
106  int32_t gwId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(key.first);
107  int32_t utId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(key.first);
108  int32_t beamId = Singleton<SatIdMapper>::Get()->GetBeamIdWithMac(key.first);
109 
110  if (beamId < 0 || (utId < 0 && gwId < 0))
111  {
112  return nullptr;
113  }
114  else
115  {
116  if (utId >= 0 && gwId < 0)
117  {
118  filename << dataPath << "/rx_power_output_trace_BEAM_" << beamId << "_UT_" << utId
119  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
120  }
121 
122  if (gwId >= 0 && utId < 0)
123  {
124  filename << dataPath << "/rx_power_output_trace_BEAM_" << beamId << "_GW_" << gwId
125  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
126  }
127 
128  std::pair<container_t::iterator, bool> result = m_container.insert(
129  std::make_pair(key,
130  CreateObject<SatOutputFileStreamDoubleContainer>(
131  filename.str().c_str(),
132  std::ios::out,
134 
135  if (result.second == false)
136  {
137  NS_FATAL_ERROR("SatRxPowerOutputTraceContainer::AddNode failed");
138  }
139 
140  NS_LOG_INFO("Added node with MAC " << key.first << " channel type " << key.second);
141 
142  return result.first->second;
143  }
144 }
145 
146 Ptr<SatOutputFileStreamDoubleContainer>
148 {
149  NS_LOG_FUNCTION(this);
150 
151  container_t::iterator iter = m_container.find(key);
152 
153  if (iter == m_container.end())
154  {
155  return AddNode(key);
156  }
157 
158  return iter->second;
159 }
160 
161 void
163 {
164  NS_LOG_FUNCTION(this);
165 
166  container_t::iterator iter;
167 
168  for (iter = m_container.begin(); iter != m_container.end(); iter++)
169  {
171  {
172  iter->second->EnableFigureOutput("Rx power density",
173  "Time (s)",
174  "Rx power (dBW / Hz)",
175  "set key top right",
177  Gnuplot2dDataset::LINES);
178  }
179  iter->second->WriteContainerToFile();
180  }
181 }
182 
183 void
184 SatRxPowerOutputTraceContainer::AddToContainer(key_t key, std::vector<double> newItem)
185 {
186  NS_LOG_FUNCTION(this);
187 
189  {
190  NS_FATAL_ERROR("SatRxPowerOutputTraceContainer::AddToContainer - Incorrect vector size");
191  }
192 
193  Ptr<SatOutputFileStreamDoubleContainer> node = FindNode(key);
194 
195  if (node != nullptr)
196  {
197  node->AddToContainer(newItem);
198  }
199 }
200 
201 } // namespace ns3
Base class for trace containers such as interference or fading 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)
Ptr< SatOutputFileStreamDoubleContainer > AddNode(std::pair< Address, SatEnums::ChannelType_t > key)
Function for adding the node to the map.
void Reset()
Function for resetting the variables.
static TypeId GetTypeId(void)
NS-3 type id function.
Ptr< SatOutputFileStreamDoubleContainer > FindNode(key_t key)
Function for finding the container matching the key.
std::pair< Address, SatEnums::ChannelType_t > key_t
typedef for map key
void WriteToFile()
Write the contents of a container matching to the key into a file.
void AddToContainer(key_t key, std::vector< double > newItem)
Add the vector containing the values to container matching the key.
TypeId GetInstanceTypeId(void) const
NS-3 instance type id function.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.