applications: Fix initialization problem for related attributes

This commit is contained in:
Tom Henderson
2018-06-21 18:28:31 -07:00
parent 7c128bc929
commit 9c5205a056
4 changed files with 65 additions and 36 deletions

View File

@@ -212,6 +212,7 @@ ThreeGppHttpClient::StartApplication ()
if (m_state == NOT_STARTED)
{
m_httpVariables->Initialize ();
OpenConnection ();
}
else

View File

@@ -203,6 +203,7 @@ ThreeGppHttpServer::StartApplication ()
if (m_state == NOT_STARTED)
{
m_httpVariables->Initialize ();
if (m_initialSocket == 0)
{
// Find the current default MTU value of TCP sockets.

View File

@@ -339,6 +339,13 @@ ThreeGppHttpVariables::AssignStreams (int64_t stream)
return 9;
}
void
ThreeGppHttpVariables::DoInitialize (void)
{
NS_LOG_FUNCTION (this);
UpdateMainObjectMuAndSigma ();
UpdateEmbeddedObjectMuAndSigma ();
}
// SETTER METHODS /////////////////////////////////////////////////////////////
@@ -360,15 +367,10 @@ ThreeGppHttpVariables::SetMainObjectGenerationDelay (Time constant)
DoubleValue (constant.GetSeconds ()));
}
void
ThreeGppHttpVariables::SetMainObjectSizeMean (uint32_t mean)
ThreeGppHttpVariables::UpdateMainObjectMuAndSigma (void)
{
NS_LOG_FUNCTION (this << mean);
NS_ASSERT_MSG (mean > 0, "Mean must be greater than zero.");
m_mainObjectSizeMean = mean;
// Update Mu and Sigma.
NS_LOG_FUNCTION (this);
const double a1 = std::pow (m_mainObjectSizeStdDev, 2.0);
const double a2 = std::pow (m_mainObjectSizeMean, 2.0);
const double a = std::log (1.0 + (a1 / a2));
@@ -379,22 +381,44 @@ ThreeGppHttpVariables::SetMainObjectSizeMean (uint32_t mean)
m_mainObjectSizeRng->SetAttribute ("Sigma", DoubleValue (sigma));
}
void
ThreeGppHttpVariables::UpdateEmbeddedObjectMuAndSigma (void)
{
NS_LOG_FUNCTION (this);
const double a1 = std::pow (m_embeddedObjectSizeStdDev, 2.0);
const double a2 = std::pow (m_embeddedObjectSizeMean, 2.0);
const double a = std::log (1.0 + (a1 / a2));
const double mu = std::log (m_embeddedObjectSizeMean) - (0.5 * a);
const double sigma = std::sqrt (a);
NS_LOG_DEBUG (this << " Mu= " << mu << " Sigma= " << sigma << ".");
m_embeddedObjectSizeRng->SetAttribute ("Mu", DoubleValue (mu));
m_embeddedObjectSizeRng->SetAttribute ("Sigma", DoubleValue (sigma));
}
void
ThreeGppHttpVariables::SetMainObjectSizeMean (uint32_t mean)
{
NS_LOG_FUNCTION (this << mean);
NS_ASSERT_MSG (mean > 0, "Mean must be greater than zero.");
m_mainObjectSizeMean = mean;
if (IsInitialized ())
{
UpdateMainObjectMuAndSigma ();
}
}
void
ThreeGppHttpVariables::SetMainObjectSizeStdDev (uint32_t stdDev)
{
NS_LOG_FUNCTION (this << stdDev);
m_mainObjectSizeStdDev = stdDev;
// Update Mu and Sigma. Same piece of code as in SetMainObjectSizeMean().
const double a1 = std::pow (m_mainObjectSizeStdDev, 2.0);
const double a2 = std::pow (m_mainObjectSizeMean, 2.0);
const double a = std::log (1.0 + (a1 / a2));
const double mu = std::log (m_mainObjectSizeMean) - (0.5 * a);
const double sigma = std::sqrt (a);
NS_LOG_DEBUG (this << " Mu= " << mu << " Sigma= " << sigma << ".");
m_mainObjectSizeRng->SetAttribute ("Mu", DoubleValue (mu));
m_mainObjectSizeRng->SetAttribute ("Sigma", DoubleValue (sigma));
if (IsInitialized ())
{
UpdateMainObjectMuAndSigma ();
}
}
@@ -414,15 +438,10 @@ ThreeGppHttpVariables::SetEmbeddedObjectSizeMean (uint32_t mean)
NS_ASSERT_MSG (mean > 0, "Mean must be greater than zero.");
m_embeddedObjectSizeMean = mean;
// Update Mu and Sigma.
const double a1 = std::pow (m_embeddedObjectSizeStdDev, 2.0);
const double a2 = std::pow (m_embeddedObjectSizeMean, 2.0);
const double a = std::log (1.0 + (a1 / a2));
const double mu = std::log (m_embeddedObjectSizeMean) - (0.5 * a);
const double sigma = std::sqrt (a);
NS_LOG_DEBUG (this << " Mu= " << mu << " Sigma= " << sigma << ".");
m_embeddedObjectSizeRng->SetAttribute ("Mu", DoubleValue (mu));
m_embeddedObjectSizeRng->SetAttribute ("Sigma", DoubleValue (sigma));
if (IsInitialized ())
{
UpdateEmbeddedObjectMuAndSigma ();
}
}
@@ -432,15 +451,10 @@ ThreeGppHttpVariables::SetEmbeddedObjectSizeStdDev (uint32_t stdDev)
NS_LOG_FUNCTION (this << stdDev);
m_embeddedObjectSizeStdDev = stdDev;
// Update Mu and Sigma. Same piece of code as in SetEmbeddedObjectSizeMean().
const double a1 = std::pow (m_embeddedObjectSizeStdDev, 2.0);
const double a2 = std::pow (m_embeddedObjectSizeMean, 2.0);
const double a = std::log (1.0 + (a1 / a2));
const double mu = std::log (m_embeddedObjectSizeMean) - (0.5 * a);
const double sigma = std::sqrt (a);
NS_LOG_DEBUG (this << " Mu= " << mu << " Sigma= " << sigma << ".");
m_embeddedObjectSizeRng->SetAttribute ("Mu", DoubleValue (mu));
m_embeddedObjectSizeRng->SetAttribute ("Sigma", DoubleValue (sigma));
if (IsInitialized ())
{
UpdateEmbeddedObjectMuAndSigma ();
}
}

View File

@@ -267,6 +267,19 @@ public:
void SetParsingTimeMean (Time mean);
private:
/**
* \brief Upon and after object initialization, update random variable
* Mu and Sigma based on changes to attribute values.
*/
void UpdateMainObjectMuAndSigma (void);
/**
* \brief Upon and after object initialization, update random variable
* Mu and Sigma based on changes to attribute values.
*/
void UpdateEmbeddedObjectMuAndSigma (void);
void DoInitialize (void); // overridden from base class
/**
* Random variable for determining MTU size (in bytes).
*/
@@ -330,7 +343,7 @@ private:
*/
Ptr<ExponentialRandomVariable> m_parsingTimeRng;
}; // end of `class TreeGppHttpVariables`
}; // end of `class ThreeGppHttpVariables`
} // end of `namespace ns3`