23 #include "../utils/satellite-env-variables.h"
25 #include <ns3/double.h>
28 #include <ns3/singleton.h>
29 #include <ns3/string.h>
39 NS_LOG_COMPONENT_DEFINE(
"SatFadingExternalInputTraceContainer");
44 NS_OBJECT_ENSURE_REGISTERED(SatFadingExternalInputTraceContainer);
50 TypeId(
"ns3::SatFadingExternalInputTraceContainer")
52 .AddConstructor<SatFadingExternalInputTraceContainer>()
53 .AddAttribute(
"UtInputMode",
54 "Input mode to read trace source files from given index table.",
56 MakeEnumAccessor<SatFadingExternalInputTraceContainer::InputMode_t>(
65 "UtRtnUpIndexFileName",
66 "Index file defining trace source files for return up link/UTs.",
67 StringValue(
"BeamId-1_256_UT_fading_rtnup_trace_index.txt"),
71 "UtFwdDownIndexFileName",
72 "Index file defining trace source files for forward down link/UTs.",
73 StringValue(
"BeamId-1_256_UT_fading_fwddwn_trace_index.txt"),
77 "GwFwdUpIndexFileName",
78 "Index file defining trace source files for forward up link/GWs.",
79 StringValue(
"GW_fading_fwdup_traces.txt"),
83 "GwRtnDownIndexFileName",
84 "Index file defining trace source files for return down link/GWs.",
85 StringValue(
"GW_fading_rtndwn_traces.txt"),
90 "Maximum distance allowed to fading source in position based mode [m].",
93 MakeDoubleChecker<double>());
104 : m_utInputMode(LIST_MODE),
105 m_indexFilesLoaded(false),
106 m_maxDistanceToFading(0)
108 NS_LOG_FUNCTION(
this);
110 ObjectBase::ConstructSelf(AttributeConstructionList());
111 m_dataPath = Singleton<SatEnvVariables>::Get()->LocateDataDirectory() +
112 "/additional-input/ext-fadingtraces/input/";
117 NS_LOG_FUNCTION(
this);
126 NS_LOG_FUNCTION(
this);
141 Ptr<MobilityModel> mobility)
143 NS_LOG_FUNCTION(
this << utId);
150 Ptr<SatFadingExternalInputTrace> ftRet =
156 Ptr<SatFadingExternalInputTrace> ftFwd =
165 m_utFadingMap.insert(std::make_pair(utId, std::make_pair(ftRet, ftFwd)));
170 Ptr<MobilityModel> mobility)
172 NS_LOG_FUNCTION(
this << gwId);
179 Ptr<SatFadingExternalInputTrace> ftRet =
185 Ptr<SatFadingExternalInputTrace> ftFwd =
194 m_gwFadingMap.insert(std::make_pair(gwId, std::make_pair(ftRet, ftFwd)));
197 Ptr<SatFadingExternalInputTrace>
200 Ptr<MobilityModel> mobility)
202 NS_LOG_FUNCTION(
this << nodeId);
204 Ptr<SatFadingExternalInputTrace> ft;
208 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_utFadingMap.find(nodeId);
219 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_utFadingMap.find(nodeId);
230 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_gwFadingMap.find(nodeId);
241 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_gwFadingMap.find(nodeId);
252 NS_LOG_ERROR(
this <<
" not valid channel type!");
262 NS_LOG_FUNCTION(
this);
263 NS_ASSERT(numOfUts > 0);
264 NS_ASSERT(numOfGws > 0);
278 for (uint32_t i = 1; i <= numOfUts; i++)
280 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_utFadingMap.find(i);
289 for (uint32_t i = 1; i <= numOfGws; i++)
291 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_gwFadingMap.find(i);
305 std::map<uint32_t, ChannelTracePair_t>::const_iterator cit;
308 if (!cit->second.first->TestFadingTrace())
312 if (!cit->second.second->TestFadingTrace())
321 if (!cit->second.first->TestFadingTrace())
325 if (!cit->second.second->TestFadingTrace())
339 NS_LOG_FUNCTION(
this << indexFile);
342 std::ifstream* ifs =
new std::ifstream((
m_dataPath + indexFile).c_str(), std::ios::in);
346 double lat, lon, alt;
348 std::string fileName;
350 *ifs >>
id >> fileName >> lat >> lon >> alt;
354 NS_LOG_DEBUG(
this <<
" id = " <<
id <<
" file = " << fileName
355 <<
" latitude [deg] = " << lat <<
" longitude [deg] = " << lon);
359 container.push_back(item);
362 *ifs >>
id >> fileName >> lat >> lon >> alt;
369 NS_FATAL_ERROR(
m_dataPath << indexFile <<
" index file not found.");
375 Ptr<SatFadingExternalInputTrace>
381 Ptr<MobilityModel> mobility)
383 NS_LOG_FUNCTION(
this << mobility);
385 Ptr<SatFadingExternalInputTrace> trace;
386 std::string fileName;
391 if (container.empty() || (
id > container.size()))
393 NS_FATAL_ERROR(
"No input available!");
397 fileName = container.at(
id).first;
402 if (container.empty())
404 NS_FATAL_ERROR(
"No input available!");
408 fileName = container.at(std::rand() % container.size()).first;
417 NS_FATAL_ERROR(
"Not supported mode.");
421 NS_LOG_INFO(
"Creation info: Mode=" <<
m_utInputMode <<
", ID (GW/UT)=" <<
id
422 <<
", FileName=" << fileName);
426 TraceInputContainer_t::iterator it =
m_loadedTraces.find(fileName);
431 trace = Create<SatFadingExternalInputTrace>(fileType,
m_dataPath + fileName);
444 Ptr<MobilityModel> mobility)
446 NS_LOG_FUNCTION(
this << mobility);
448 std::string fileName;
449 double currentDistanceToFading = std::numeric_limits<double>::max();
450 Vector position = mobility->GetPosition();
452 for (TraceFileContainer_t::iterator it = container.begin(); it != container.end(); it++)
454 Vector fadingPosition = it->second.ToVector();
456 double distanceToFading = CalculateDistance(position, fadingPosition);
458 if (distanceToFading < currentDistanceToFading)
460 currentDistanceToFading = distanceToFading;
461 fileName = it->first;
468 "No valid fading based on position (min found distance, max allowed distance): "
473 NS_LOG_INFO(
"Minimum distance to fading trace source: " << currentDistanceToFading);
GeoCoordinate class is used to store and operate with geodetic coordinates.
ChannelType_t
Types of channel.
SatArqSequenceNumber is handling the sequence numbers for the ARQ process.