Loading...
Searching...
No Matches
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
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
37NS_LOG_COMPONENT_DEFINE("SatRxPowerOutputTraceContainer");
38
39namespace ns3
40{
41
42NS_OBJECT_ENSURE_REGISTERED(SatRxPowerOutputTraceContainer);
43
44TypeId
46{
47 static TypeId tid = TypeId("ns3::SatRxPowerOutputTraceContainer")
48 .SetParent<SatBaseTraceContainer>()
49 .AddConstructor<SatRxPowerOutputTraceContainer>();
50 return tid;
51}
52
58
65
66void
68{
69 NS_LOG_FUNCTION(this);
70
71 Reset();
72
73 SatBaseTraceContainer::DoDispose();
74}
75
76void
78{
79 NS_LOG_FUNCTION(this);
80
81 if (!m_container.empty())
82 {
84
85 m_container.clear();
86 }
88}
89
90Ptr<SatOutputFileStreamDoubleContainer>
92{
93 NS_LOG_FUNCTION(this);
94
95 std::stringstream filename;
96 std::string dataPath = SatEnvVariables::GetInstance()->GetOutputPath();
97
98 int32_t gwId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(key.first);
99 int32_t utId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(key.first);
100 int32_t beamId = Singleton<SatIdMapper>::Get()->GetBeamIdWithMac(key.first);
101
102 if (beamId < 0 || (utId < 0 && gwId < 0))
103 {
104 return nullptr;
105 }
106 else
107 {
108 if (utId >= 0 && gwId < 0)
109 {
110 filename << dataPath << "/rx_power_output_trace_BEAM_" << beamId << "_UT_" << utId
111 << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
112 }
113
114 if (gwId >= 0 && utId < 0)
115 {
116 filename << dataPath << "/rx_power_output_trace_BEAM_" << beamId << "_GW_" << gwId
117 << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
118 }
119
120 std::pair<container_t::iterator, bool> result = m_container.insert(
121 std::make_pair(key,
122 CreateObject<SatOutputFileStreamDoubleContainer>(
123 filename.str().c_str(),
124 std::ios::out,
126
127 if (result.second == false)
128 {
129 NS_FATAL_ERROR("SatRxPowerOutputTraceContainer::AddNode failed");
130 }
131
132 NS_LOG_INFO("Added node with MAC " << key.first << " channel type " << key.second);
133
134 return result.first->second;
135 }
136}
137
138Ptr<SatOutputFileStreamDoubleContainer>
140{
141 NS_LOG_FUNCTION(this);
142
143 container_t::iterator iter = m_container.find(key);
144
145 if (iter == m_container.end())
146 {
147 return AddNode(key);
148 }
149
150 return iter->second;
151}
152
153void
155{
156 NS_LOG_FUNCTION(this);
157
158 container_t::iterator iter;
159
160 for (iter = m_container.begin(); iter != m_container.end(); iter++)
161 {
163 {
164 iter->second->EnableFigureOutput("Rx power density",
165 "Time (s)",
166 "Rx power (dBW / Hz)",
167 "set key top right",
169 Gnuplot2dDataset::LINES);
170 }
171 iter->second->WriteContainerToFile();
172 }
173}
174
175void
177{
178 NS_LOG_FUNCTION(this);
179
181 {
182 NS_FATAL_ERROR("SatRxPowerOutputTraceContainer::AddToContainer - Incorrect vector size");
183 }
184
185 Ptr<SatOutputFileStreamDoubleContainer> node = FindNode(key);
186
187 if (node != nullptr)
188 {
189 node->AddToContainer(newItem);
190 }
191}
192
193} // namespace ns3
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)
static Ptr< SatEnvVariables > GetInstance()
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.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.