satellite-fading-input-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/log.h>
27 #include <ns3/singleton.h>
28 
29 #include <ios>
30 #include <sstream>
31 #include <stdint.h>
32 #include <string>
33 #include <utility>
34 
35 NS_LOG_COMPONENT_DEFINE("SatFadingInputTraceContainer");
36 
37 namespace ns3
38 {
39 
40 NS_OBJECT_ENSURE_REGISTERED(SatFadingInputTraceContainer);
41 
42 TypeId
44 {
45  static TypeId tid = TypeId("ns3::SatFadingInputTraceContainer")
46  .SetParent<SatBaseTraceContainer>()
47  .AddConstructor<SatFadingInputTraceContainer>();
48  return tid;
49 }
50 
51 TypeId
53 {
54  NS_LOG_FUNCTION(this);
55 
56  return GetTypeId();
57 }
58 
60 {
61  NS_LOG_FUNCTION(this);
62 }
63 
65 {
66  NS_LOG_FUNCTION(this);
67 
68  Reset();
69 }
70 
71 void
73 {
74  NS_LOG_FUNCTION(this);
75 
76  Reset();
77 
78  SatBaseTraceContainer::DoDispose();
79 }
80 
81 void
83 {
84  NS_LOG_FUNCTION(this);
85 
86  if (!m_container.empty())
87  {
88  m_container.clear();
89  }
90 }
91 
92 Ptr<SatInputFileStreamTimeDoubleContainer>
94 {
95  NS_LOG_FUNCTION(this);
96 
97  std::stringstream filename;
98  std::string dataPath = Singleton<SatEnvVariables>::Get()->LocateDataDirectory();
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  NS_FATAL_ERROR(
107  "SatFadingInputTraceContainer::AddNode - No such MAC address in the trace ID mapper");
108  }
109  else
110  {
111  if (utId >= 0 && gwId < 0)
112  {
113  filename << dataPath << "/additional-input/fadingtraces/input/BEAM_" << beamId << "_UT_"
114  << utId << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
115  }
116 
117  if (gwId >= 0 && utId < 0)
118  {
119  filename << dataPath << "/additional-input/fadingtraces/input/BEAM_" << beamId << "_GW_"
120  << gwId << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
121  }
122  std::pair<container_t::iterator, bool> result = m_container.insert(
123  std::make_pair(key,
124  CreateObject<SatInputFileStreamTimeDoubleContainer>(
125  filename.str().c_str(),
126  std::ios::in,
128 
129  if (result.second == false)
130  {
131  NS_FATAL_ERROR("SatFadingInputTraceContainer::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  NS_FATAL_ERROR("SatFadingInputTraceContainer::AddNode failed");
140  return nullptr;
141 }
142 
143 Ptr<SatInputFileStreamTimeDoubleContainer>
145 {
146  NS_LOG_FUNCTION(this);
147 
148  container_t::iterator iter = m_container.find(key);
149 
150  if (iter == m_container.end())
151  {
152  return AddNode(key);
153  }
154 
155  return iter->second;
156 }
157 
158 double
160 {
161  NS_LOG_FUNCTION(this);
162 
163  return FindNode(key)->ProceedToNextClosestTimeSample().at(
165 }
166 
167 } // namespace ns3
Base class for trace containers such as interference or fading traces.
static const uint32_t FADING_TRACE_DEFAULT_NUMBER_OF_COLUMNS
Default number of columns for fading traces.
static const uint32_t FADING_TRACE_DEFAULT_FADING_VALUE_INDEX
Default fading value index for fading traces.
static std::string GetChannelTypeName(ChannelType_t channelType)
std::pair< Address, SatEnums::ChannelType_t > key_t
typedef for map key
static TypeId GetTypeId(void)
NS-3 type id function.
double GetFadingValue(key_t key)
Function for getting the fading value.
void Reset()
Function for resetting the variables.
Ptr< SatInputFileStreamTimeDoubleContainer > 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.
Ptr< SatInputFileStreamTimeDoubleContainer > FindNode(key_t key)
Function for finding the container matching the key.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.