Files
eden-sim/contrib/tsn/model/frer-latent-error-detection-function.cc

128 lines
5.6 KiB
C++
Raw Permalink Normal View History

2025-12-01 15:56:02 +01:00
#include "frer-latent-error-detection-function.h"
#include "ns3/log.h"
#include "ns3/simulator.h"
#include "ns3/uinteger.h"
namespace ns3
{
NS_LOG_COMPONENT_DEFINE("LatentErrorDetectionFunction");
NS_OBJECT_ENSURE_REGISTERED(LatentErrorDetectionFunction);
TypeId
LatentErrorDetectionFunction::GetTypeId()
{
static TypeId tid =
TypeId("ns3::LatentErrorDetectionFunction")
.SetParent<Object>()
.SetGroupName("tsn")
.AddConstructor<LatentErrorDetectionFunction>()
.AddAttribute("TestTimer",
"Test timer duration",
TimeValue(Seconds(2)),
MakeTimeAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyLatentErrorPeriod),
MakeTimeChecker())
.AddAttribute("ResetTimer",
"Reset timer duration",
TimeValue(Seconds(30)),
MakeTimeAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyLatentResetPeriod),
MakeTimeChecker())
.AddAttribute("LatentErrorPaths",
"Number of Latent Error Paths",
UintegerValue(2),
MakeUintegerAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyLatentErrorPaths),
MakeUintegerChecker<uint>())
.AddAttribute("LatentErrorDifference",
"Latent Error Difference threshold",
UintegerValue(0),
MakeUintegerAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyLatentErrorDifference),
MakeUintegerChecker<uint>())
.AddAttribute("MinTestTimer",
"Min test timer duration",
TimeValue(Seconds(0)),
MakeTimeAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyMinLatentErrorPeriod),
MakeTimeChecker())
.AddAttribute("MaxTestTimer",
"Max test timer duration",
TimeValue(Seconds(65535)),
MakeTimeAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyMaxLatentErrorPeriod),
MakeTimeChecker())
.AddAttribute("MinResetTimer",
"Min reset timer duration",
TimeValue(Seconds(0)),
MakeTimeAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyMinLatentResetPeriod),
MakeTimeChecker())
.AddAttribute("MaxResetTimer",
"Max reset timer duration",
TimeValue(Seconds(65535)),
MakeTimeAccessor(&LatentErrorDetectionFunction::m_frerSeqRcvyMaxLatentResetPeriod),
MakeTimeChecker());
return tid;
}
LatentErrorDetectionFunction::LatentErrorDetectionFunction()
{
NS_LOG_FUNCTION(this);
m_resetEvent = Simulator::Schedule(m_frerSeqRcvyLatentResetPeriod, &LatentErrorDetectionFunction::LatentErrorReset, this);
m_testEvent = Simulator::Schedule(m_frerSeqRcvyLatentErrorPeriod, &LatentErrorDetectionFunction::LatentErrorTest, this);
}
LatentErrorDetectionFunction::~LatentErrorDetectionFunction()
{
NS_LOG_FUNCTION(this);
}
void
LatentErrorDetectionFunction::SetRecoveryFunction(Ptr<BaseRecoveryFunction> recoveryFunction)
{
NS_LOG_FUNCTION(this);
m_recoveryFunction = recoveryFunction;
}
void
LatentErrorDetectionFunction::LatentErrorReset()
{
NS_LOG_FUNCTION(this);
// NS_LOG_INFO("Latent Error Reset ! ");
NS_ASSERT_MSG(m_recoveryFunction!=nullptr, "Recovery function not set ...");
m_curBaseDifference = (m_recoveryFunction->GetFrerCpsSeqRcvyPassedPackets() *(m_frerSeqRcvyLatentErrorPaths - 1)) - m_recoveryFunction->GetFrerCpsSeqRcvyDiscardedPackets();
m_frerCpsSeqRcvyLatentErrorResets += 1;
m_resetEvent = Simulator::Schedule(m_frerSeqRcvyLatentResetPeriod, &LatentErrorDetectionFunction::LatentErrorReset, this);
}
void
LatentErrorDetectionFunction::LatentErrorTest()
{
NS_LOG_FUNCTION(this);
NS_ASSERT_MSG(m_frerSeqRcvyLatentErrorPeriod >= m_frerSeqRcvyMinLatentErrorPeriod, "Trying to use a latent error test timer shorter than " << m_frerSeqRcvyMaxLatentErrorPeriod << ".");
NS_ASSERT_MSG(m_frerSeqRcvyLatentErrorPeriod <= m_frerSeqRcvyMaxLatentErrorPeriod, "Trying to use a latent error test timer longer than " << m_frerSeqRcvyMaxLatentErrorPeriod << ".");
NS_ASSERT_MSG(m_frerSeqRcvyLatentResetPeriod >= m_frerSeqRcvyMinLatentResetPeriod, "Trying to use a latent error reset timer shorter than " << m_frerSeqRcvyMinLatentResetPeriod << ".");
NS_ASSERT_MSG(m_frerSeqRcvyLatentResetPeriod <= m_frerSeqRcvyMaxLatentResetPeriod, "Trying to use a latent error reset timer longer than " << m_frerSeqRcvyMaxLatentResetPeriod << ".");
// NS_LOG_INFO("Latent Error Test ! ");
NS_ASSERT_MSG(m_recoveryFunction!=nullptr, "Recovery function not set ...");
int diff = m_curBaseDifference - ((m_recoveryFunction->GetFrerCpsSeqRcvyPassedPackets() *(m_frerSeqRcvyLatentErrorPaths - 1)) - m_recoveryFunction->GetFrerCpsSeqRcvyDiscardedPackets());
if (m_frerSeqRcvyLatentErrorPaths > 1 )
{
if (diff < 0)
{
diff = - diff;
}
if (diff > (int)m_frerSeqRcvyLatentErrorDifference)
{
NS_LOG_INFO("Latent Error Detected ! ");
//Hit a trace ?
}
}
m_testEvent = Simulator::Schedule(m_frerSeqRcvyLatentErrorPeriod, &LatentErrorDetectionFunction::LatentErrorTest, this);
}
}