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 NS_LOG_COMPONENT_DEFINE("SatRxPowerOutputTraceContainer");
31 
32 namespace ns3
33 {
34 
35 NS_OBJECT_ENSURE_REGISTERED(SatRxPowerOutputTraceContainer);
36 
37 TypeId
39 {
40  static TypeId tid = TypeId("ns3::SatRxPowerOutputTraceContainer")
41  .SetParent<SatBaseTraceContainer>()
42  .AddConstructor<SatRxPowerOutputTraceContainer>();
43  return tid;
44 }
45 
46 TypeId
48 {
49  NS_LOG_FUNCTION(this);
50 
51  return GetTypeId();
52 }
53 
55  : m_enableFigureOutput(true)
56 {
57  NS_LOG_FUNCTION(this);
58 }
59 
61 {
62  NS_LOG_FUNCTION(this);
63 
64  Reset();
65 }
66 
67 void
69 {
70  NS_LOG_FUNCTION(this);
71 
72  Reset();
73 
74  SatBaseTraceContainer::DoDispose();
75 }
76 
77 void
79 {
80  NS_LOG_FUNCTION(this);
81 
82  if (!m_container.empty())
83  {
84  WriteToFile();
85 
86  m_container.clear();
87  }
88  m_enableFigureOutput = true;
89 }
90 
91 Ptr<SatOutputFileStreamDoubleContainer>
93 {
94  NS_LOG_FUNCTION(this);
95 
96  std::stringstream filename;
97  std::string dataPath = Singleton<SatEnvVariables>::Get()->GetOutputPath();
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 << "/rx_power_output_trace_BEAM_" << beamId << "_UT_" << utId
112  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
113  }
114 
115  if (gwId >= 0 && utId < 0)
116  {
117  filename << dataPath << "/rx_power_output_trace_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<SatOutputFileStreamDoubleContainer>(
124  filename.str().c_str(),
125  std::ios::out,
127 
128  if (result.second == false)
129  {
130  NS_FATAL_ERROR("SatRxPowerOutputTraceContainer::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 
139 Ptr<SatOutputFileStreamDoubleContainer>
141 {
142  NS_LOG_FUNCTION(this);
143 
144  container_t::iterator iter = m_container.find(key);
145 
146  if (iter == m_container.end())
147  {
148  return AddNode(key);
149  }
150 
151  return iter->second;
152 }
153 
154 void
156 {
157  NS_LOG_FUNCTION(this);
158 
159  container_t::iterator iter;
160 
161  for (iter = m_container.begin(); iter != m_container.end(); iter++)
162  {
164  {
165  iter->second->EnableFigureOutput("Rx power density",
166  "Time (s)",
167  "Rx power (dBW / Hz)",
168  "set key top right",
170  Gnuplot2dDataset::LINES);
171  }
172  iter->second->WriteContainerToFile();
173  }
174 }
175 
176 void
177 SatRxPowerOutputTraceContainer::AddToContainer(key_t key, std::vector<double> newItem)
178 {
179  NS_LOG_FUNCTION(this);
180 
182  {
183  NS_FATAL_ERROR("SatRxPowerOutputTraceContainer::AddToContainer - Incorrect vector size");
184  }
185 
186  Ptr<SatOutputFileStreamDoubleContainer> node = FindNode(key);
187 
188  if (node != NULL)
189  {
190  node->AddToContainer(newItem);
191  }
192 }
193 
194 } // 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.