Loading...
Searching...
No Matches
satellite-interference-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
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
38NS_LOG_COMPONENT_DEFINE("SatInterferenceOutputTraceContainer");
39
40namespace ns3
41{
42
43NS_OBJECT_ENSURE_REGISTERED(SatInterferenceOutputTraceContainer);
44
45TypeId
47{
48 static TypeId tid = TypeId("ns3::SatInterferenceOutputTraceContainer")
49 .SetParent<SatBaseTraceContainer>()
50 .AddConstructor<SatInterferenceOutputTraceContainer>();
51 return tid;
52}
53
59
66
67void
69{
70 NS_LOG_FUNCTION(this);
71
72 Reset();
73
74 SatBaseTraceContainer::DoDispose();
75}
76
77void
79{
80 NS_LOG_FUNCTION(this);
81
82 if (!m_container.empty())
83 {
85
86 m_container.clear();
87 }
89}
90
91Ptr<SatOutputFileStreamDoubleContainer>
93{
94 NS_LOG_FUNCTION(this);
95
96 std::stringstream filename;
97 std::string dataPath = SatEnvVariables::GetInstance()->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 nullptr;
106 }
107 else
108 {
109 if (utId >= 0 && gwId < 0)
110 {
111 filename << dataPath << "/interference_output_trace_BEAM_" << beamId << "_UT_" << utId
112 << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
113 }
114
115 if (gwId >= 0 && utId < 0)
116 {
117 filename << dataPath << "/interference_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("SatInterferenceOutputTraceContainer::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
139Ptr<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
154void
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("Interference density",
166 "Time (s)",
167 "Interference (W / Hz)",
168 "set key top right",
170 Gnuplot2dDataset::LINES_POINTS);
171 }
172 iter->second->WriteContainerToFile();
173 }
174}
175
176void
178{
179 NS_LOG_FUNCTION(this);
180
182 {
183 NS_FATAL_ERROR(
184 "SatInterferenceOutputTraceContainer::AddToContainer - Incorrect vector size");
185 }
186
187 Ptr<SatOutputFileStreamDoubleContainer> node = FindNode(key);
188
189 if (node != nullptr)
190 {
191 node->AddToContainer(newItem);
192 }
193}
194
195} // namespace ns3
static const uint32_t INTF_TRACE_DEFAULT_NUMBER_OF_COLUMNS
Default number of columns for interference traces.
static std::string GetChannelTypeName(ChannelType_t channelType)
static Ptr< SatEnvVariables > GetInstance()
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.
Ptr< SatOutputFileStreamDoubleContainer > AddNode(std::pair< Address, SatEnums::ChannelType_t > key)
Function for adding the node to the map.
void AddToContainer(key_t key, std::vector< double > newItem)
Add the vector containing the values to container matching the key.
void WriteToFile()
Write the contents of a container matching to the key into a file.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.