diff --git a/src/applications/model/three-gpp-http-client.cc b/src/applications/model/three-gpp-http-client.cc index 79a3bff57..fc5dcf83b 100644 --- a/src/applications/model/three-gpp-http-client.cc +++ b/src/applications/model/three-gpp-http-client.cc @@ -212,6 +212,7 @@ ThreeGppHttpClient::StartApplication () if (m_state == NOT_STARTED) { + m_httpVariables->Initialize (); OpenConnection (); } else diff --git a/src/applications/model/three-gpp-http-server.cc b/src/applications/model/three-gpp-http-server.cc index fe3e1601c..a365230d7 100644 --- a/src/applications/model/three-gpp-http-server.cc +++ b/src/applications/model/three-gpp-http-server.cc @@ -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. diff --git a/src/applications/model/three-gpp-http-variables.cc b/src/applications/model/three-gpp-http-variables.cc index dde9a03f7..ad80eef14 100644 --- a/src/applications/model/three-gpp-http-variables.cc +++ b/src/applications/model/three-gpp-http-variables.cc @@ -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 (); + } } diff --git a/src/applications/model/three-gpp-http-variables.h b/src/applications/model/three-gpp-http-variables.h index a862fa8a4..a1df1fd4e 100644 --- a/src/applications/model/three-gpp-http-variables.h +++ b/src/applications/model/three-gpp-http-variables.h @@ -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 m_parsingTimeRng; -}; // end of `class TreeGppHttpVariables` +}; // end of `class ThreeGppHttpVariables` } // end of `namespace ns3`