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