satellite-interference-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 NS_LOG_COMPONENT_DEFINE("SatInterferenceInputTraceContainer");
30 
31 namespace ns3
32 {
33 
34 NS_OBJECT_ENSURE_REGISTERED(SatInterferenceInputTraceContainer);
35 
36 TypeId
38 {
39  static TypeId tid = TypeId("ns3::SatInterferenceInputTraceContainer")
40  .SetParent<SatBaseTraceContainer>()
41  .AddConstructor<SatInterferenceInputTraceContainer>();
42  return tid;
43 }
44 
45 TypeId
47 {
48  NS_LOG_FUNCTION(this);
49 
50  return GetTypeId();
51 }
52 
54 {
55  NS_LOG_FUNCTION(this);
56 }
57 
59 {
60  NS_LOG_FUNCTION(this);
61 
62  Reset();
63 }
64 
65 void
67 {
68  NS_LOG_FUNCTION(this);
69 
70  Reset();
71 
72  SatBaseTraceContainer::DoDispose();
73 }
74 
75 void
77 {
78  NS_LOG_FUNCTION(this);
79 
80  if (!m_container.empty())
81  {
82  m_container.clear();
83  }
84 }
85 
86 Ptr<SatInputFileStreamTimeDoubleContainer>
88 {
89  NS_LOG_FUNCTION(this);
90 
91  std::stringstream filename;
92  std::string dataPath = Singleton<SatEnvVariables>::Get()->LocateDataDirectory();
93 
94  int32_t gwId = Singleton<SatIdMapper>::Get()->GetGwIdWithMac(key.first);
95  int32_t utId = Singleton<SatIdMapper>::Get()->GetUtIdWithMac(key.first);
96  int32_t beamId = Singleton<SatIdMapper>::Get()->GetBeamIdWithMac(key.first);
97 
98  if (beamId < 0 || (utId < 0 && gwId < 0))
99  {
100  return NULL;
101  }
102  else
103  {
104  if (utId >= 0 && gwId < 0)
105  {
106  filename << dataPath << "/interferencetraces/input/BEAM_" << beamId << "_UT_" << utId
107  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
108  }
109 
110  if (gwId >= 0 && utId < 0)
111  {
112  filename << dataPath << "/interferencetraces/input/BEAM_" << beamId << "_GW_" << gwId
113  << "_channelType_" << SatEnums::GetChannelTypeName(key.second);
114  }
115 
116  std::pair<container_t::iterator, bool> result = m_container.insert(
117  std::make_pair(key,
118  CreateObject<SatInputFileStreamTimeDoubleContainer>(
119  filename.str().c_str(),
120  std::ios::in,
122 
123  if (result.second == false)
124  {
125  NS_FATAL_ERROR("SatInterferenceInputTraceContainer::AddNode failed");
126  }
127 
128  NS_LOG_INFO("Added node with MAC " << key.first << " channel type " << key.second);
129 
130  return result.first->second;
131  }
132 
133  NS_FATAL_ERROR("SatInterferenceInputTraceContainer::AddNode failed");
134  return NULL;
135 }
136 
137 Ptr<SatInputFileStreamTimeDoubleContainer>
139 {
140  NS_LOG_FUNCTION(this);
141 
142  container_t::iterator iter = m_container.find(key);
143 
144  if (iter == m_container.end())
145  {
146  return AddNode(key);
147  }
148 
149  return iter->second;
150 }
151 
152 double
154 {
155  NS_LOG_FUNCTION(this);
156 
157  return FindNode(key)->ProceedToNextClosestTimeSample().at(
159 }
160 
161 } // namespace ns3
Base class for trace containers such as interference or fading traces.
static const uint32_t INTF_TRACE_DEFAULT_INTF_DENSITY_INDEX
Default interference density index for interference traces.
static const uint32_t INTF_TRACE_DEFAULT_NUMBER_OF_COLUMNS
Default number of columns for interference traces.
static std::string GetChannelTypeName(ChannelType_t channelType)
double GetInterferenceDensity(key_t key)
Function for getting the interference density.
Ptr< SatInputFileStreamTimeDoubleContainer > FindNode(key_t key)
Function for finding the container matching the key.
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.
std::pair< Address, SatEnums::ChannelType_t > key_t
typedef for map key
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.