23 #include "../utils/satellite-env-variables.h"
25 #include <ns3/double.h>
28 #include <ns3/singleton.h>
29 #include <ns3/string.h>
33 NS_LOG_COMPONENT_DEFINE(
"SatFadingExternalInputTraceContainer");
38 NS_OBJECT_ENSURE_REGISTERED(SatFadingExternalInputTraceContainer);
44 TypeId(
"ns3::SatFadingExternalInputTraceContainer")
46 .AddConstructor<SatFadingExternalInputTraceContainer>()
47 .AddAttribute(
"UtInputMode",
48 "Input mode to read trace source files from given index table.",
58 "UtRtnUpIndexFileName",
59 "Index file defining trace source files for return up link/UTs.",
60 StringValue(
"BeamId-1_256_UT_fading_rtnup_trace_index.txt"),
64 "UtFwdDownIndexFileName",
65 "Index file defining trace source files for forward down link/UTs.",
66 StringValue(
"BeamId-1_256_UT_fading_fwddwn_trace_index.txt"),
70 "GwFwdUpIndexFileName",
71 "Index file defining trace source files for forward up link/GWs.",
72 StringValue(
"GW_fading_fwdup_traces.txt"),
76 "GwRtnDownIndexFileName",
77 "Index file defining trace source files for return down link/GWs.",
78 StringValue(
"GW_fading_rtndwn_traces.txt"),
83 "Maximum distance allowed to fading source in position based mode [m].",
86 MakeDoubleChecker<double>());
97 : m_utInputMode(LIST_MODE),
98 m_indexFilesLoaded(false),
99 m_maxDistanceToFading(0)
101 NS_LOG_FUNCTION(
this);
103 ObjectBase::ConstructSelf(AttributeConstructionList());
105 Singleton<SatEnvVariables>::Get()->LocateDataDirectory() +
"/ext-fadingtraces/input/";
110 NS_LOG_FUNCTION(
this);
119 NS_LOG_FUNCTION(
this);
134 Ptr<MobilityModel> mobility)
136 NS_LOG_FUNCTION(
this << utId);
143 Ptr<SatFadingExternalInputTrace> ftRet =
149 Ptr<SatFadingExternalInputTrace> ftFwd =
158 m_utFadingMap.insert(std::make_pair(utId, std::make_pair(ftRet, ftFwd)));
163 Ptr<MobilityModel> mobility)
165 NS_LOG_FUNCTION(
this << gwId);
172 Ptr<SatFadingExternalInputTrace> ftRet =
178 Ptr<SatFadingExternalInputTrace> ftFwd =
187 m_gwFadingMap.insert(std::make_pair(gwId, std::make_pair(ftRet, ftFwd)));
190 Ptr<SatFadingExternalInputTrace>
193 Ptr<MobilityModel> mobility)
195 NS_LOG_FUNCTION(
this << nodeId);
197 Ptr<SatFadingExternalInputTrace> ft;
201 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_utFadingMap.find(nodeId);
212 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_utFadingMap.find(nodeId);
223 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_gwFadingMap.find(nodeId);
234 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_gwFadingMap.find(nodeId);
245 NS_LOG_ERROR(
this <<
" not valid channel type!");
255 NS_LOG_FUNCTION(
this);
256 NS_ASSERT(numOfUts > 0);
257 NS_ASSERT(numOfGws > 0);
271 for (uint32_t i = 1; i <= numOfUts; i++)
273 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_utFadingMap.find(i);
282 for (uint32_t i = 1; i <= numOfGws; i++)
284 std::map<uint32_t, ChannelTracePair_t>::iterator iter =
m_gwFadingMap.find(i);
298 std::map<uint32_t, ChannelTracePair_t>::const_iterator cit;
301 if (!cit->second.first->TestFadingTrace())
305 if (!cit->second.second->TestFadingTrace())
314 if (!cit->second.first->TestFadingTrace())
318 if (!cit->second.second->TestFadingTrace())
332 NS_LOG_FUNCTION(
this << indexFile);
335 std::ifstream* ifs =
new std::ifstream((
m_dataPath + indexFile).c_str(), std::ios::in);
339 double lat, lon, alt;
341 std::string fileName;
343 *ifs >>
id >> fileName >> lat >> lon >> alt;
347 NS_LOG_DEBUG(
this <<
" id = " <<
id <<
" file = " << fileName
348 <<
" latitude [deg] = " << lat <<
" longitude [deg] = " << lon);
352 container.push_back(item);
355 *ifs >>
id >> fileName >> lat >> lon >> alt;
362 NS_FATAL_ERROR(
m_dataPath << indexFile <<
" index file not found.");
368 Ptr<SatFadingExternalInputTrace>
374 Ptr<MobilityModel> mobility)
376 NS_LOG_FUNCTION(
this << mobility);
378 Ptr<SatFadingExternalInputTrace> trace;
379 std::string fileName;
384 if (container.empty() || (
id > container.size()))
386 NS_FATAL_ERROR(
"No input available!");
390 fileName = container.at(
id).first;
395 if (container.empty())
397 NS_FATAL_ERROR(
"No input available!");
401 fileName = container.at(std::rand() % container.size()).first;
410 NS_FATAL_ERROR(
"Not supported mode.");
414 NS_LOG_INFO(
"Creation info: Mode=" <<
m_utInputMode <<
", ID (GW/UT)=" <<
id
415 <<
", FileName=" << fileName);
419 TraceInputContainer_t::iterator it =
m_loadedTraces.find(fileName);
424 trace = Create<SatFadingExternalInputTrace>(fileType,
m_dataPath + fileName);
437 Ptr<MobilityModel> mobility)
439 NS_LOG_FUNCTION(
this << mobility);
441 std::string fileName;
442 double currentDistanceToFading = std::numeric_limits<double>::max();
443 Vector position = mobility->GetPosition();
445 for (TraceFileContainer_t::iterator it = container.begin(); it != container.end(); it++)
447 Vector fadingPosition = it->second.ToVector();
449 double distanceToFading = CalculateDistance(position, fadingPosition);
451 if (distanceToFading < currentDistanceToFading)
453 currentDistanceToFading = distanceToFading;
454 fileName = it->first;
461 "No valid fading based on position (min found distance, max allowed distance): "
466 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.