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 #include <ios>
32 #include <sstream>
33 #include <stdint.h>
34 #include <string>
35 #include <utility>
36 #include <vector>
37 
38 NS_LOG_COMPONENT_DEFINE("SatCompositeSinrOutputTraceContainer");
39 
40 namespace ns3
41 {
42 
43 NS_OBJECT_ENSURE_REGISTERED(SatCompositeSinrOutputTraceContainer);
44 
45 TypeId
47 {
48  static TypeId tid = TypeId("ns3::SatCompositeSinrOutputTraceContainer")
49  .SetParent<SatBaseTraceContainer>()
50  .AddConstructor<SatCompositeSinrOutputTraceContainer>();
51  return tid;
52 }
53 
54 TypeId
56 {
57  NS_LOG_FUNCTION(this);
58 
59  return GetTypeId();
60 }
61 
63  : m_enableFigureOutput(true)
64 {
65  NS_LOG_FUNCTION(this);
66 }
67 
69 {
70  NS_LOG_FUNCTION(this);
71 
72  Reset();
73 }
74 
75 void
77 {
78  NS_LOG_FUNCTION(this);
79 
80  Reset();
81 
82  SatBaseTraceContainer::DoDispose();
83 }
84 
85 void
87 {
88  NS_LOG_FUNCTION(this);
89 
90  if (!m_container.empty())
91  {
92  WriteToFile();
93 
94  m_container.clear();
95  }
96  m_enableFigureOutput = true;
97 }
98 
99 Ptr<SatOutputFileStreamDoubleContainer>
101 {
102  NS_LOG_FUNCTION(this);
103 
104  std::stringstream filename;
105  std::string dataPath = Singleton<SatEnvVariables>::Get()->GetOutputPath();
106 
107  int32_t gwId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(key.first);
108  int32_t utId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(key.first);
109  int32_t beamId = Singleton<SatIdMapper>::Get()->GetBeamIdWithMac(key.first);
110 
111  if (beamId < 0 || (utId < 0 && gwId < 0))
112  {
113  return nullptr;
114  }
115  else
116  {
117  if (utId >= 0 && gwId < 0)
118  {
119  filename << dataPath << "/composite_sinr_output_trace_BEAM_" << beamId << "_UT_" << utId
120  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
121  }
122 
123  if (gwId >= 0 && utId < 0)
124  {
125  filename << dataPath << "/composite_sinr_output_trace_BEAM_" << beamId << "_GW_" << gwId
126  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
127  }
128 
129  std::pair<container_t::iterator, bool> result = m_container.insert(
130  std::make_pair(key,
131  CreateObject<SatOutputFileStreamDoubleContainer>(
132  filename.str().c_str(),
133  std::ios::out,
135 
136  if (result.second == false)
137  {
138  NS_FATAL_ERROR("SatCompositeSinrOutputTraceContainer::AddNode failed");
139  }
140 
141  NS_LOG_INFO("Added node with MAC " << key.first << " channel type " << key.second);
142 
143  return result.first->second;
144  }
145 }
146 
147 Ptr<SatOutputFileStreamDoubleContainer>
149 {
150  NS_LOG_FUNCTION(this);
151 
152  container_t::iterator iter = m_container.find(key);
153 
154  if (iter == m_container.end())
155  {
156  return AddNode(key);
157  }
158 
159  return iter->second;
160 }
161 
162 void
164 {
165  NS_LOG_FUNCTION(this);
166 
167  container_t::iterator iter;
168 
169  for (iter = m_container.begin(); iter != m_container.end(); iter++)
170  {
172  {
173  iter->second->EnableFigureOutput("Composite SINR",
174  "Time (s)",
175  "SINR (dB)",
176  "set key top right",
178  Gnuplot2dDataset::LINES_POINTS);
179  }
180  iter->second->WriteContainerToFile();
181  }
182 }
183 
184 void
186 {
187  NS_LOG_FUNCTION(this);
188 
190  {
191  NS_FATAL_ERROR(
192  "SatCompositeSinrOutputTraceContainer::AddToContainer - Incorrect vector size");
193  }
194 
195  Ptr<SatOutputFileStreamDoubleContainer> node = FindNode(key);
196 
197  if (node != nullptr)
198  {
199  node->AddToContainer(newItem);
200  }
201 }
202 
203 } // 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.