From a3e63cc706aac06eec17bcaf83fbe528af40ac6b Mon Sep 17 00:00:00 2001 From: Eduardo Almeida Date: Thu, 17 Feb 2022 11:22:47 +0000 Subject: [PATCH] tcp: Clean up tcp-rto-test.cc, tcp-slow-start-test.cc and tcp-cong-avoid-test.cc --- src/internet/test/tcp-cong-avoid-test.cc | 19 ++++--- src/internet/test/tcp-rto-test.cc | 72 +++++++++++++----------- src/internet/test/tcp-slow-start-test.cc | 39 +++++++------ 3 files changed, 70 insertions(+), 60 deletions(-) diff --git a/src/internet/test/tcp-cong-avoid-test.cc b/src/internet/test/tcp-cong-avoid-test.cc index 72185a6f3..bfbc508a1 100644 --- a/src/internet/test/tcp-cong-avoid-test.cc +++ b/src/internet/test/tcp-cong-avoid-test.cc @@ -65,7 +65,7 @@ public: * \param desc The test description. */ TcpNewRenoCongAvoidNormalTest (uint32_t segmentSize, uint32_t packetSize, - uint32_t packets, TypeId& congControl, + uint32_t packets, const TypeId& congControl, const std::string &desc); protected: virtual void CWndTrace (uint32_t oldValue, uint32_t newValue); @@ -94,7 +94,7 @@ private: TcpNewRenoCongAvoidNormalTest::TcpNewRenoCongAvoidNormalTest (uint32_t segmentSize, uint32_t packetSize, uint32_t packets, - TypeId &typeId, + const TypeId &typeId, const std::string &desc) : TcpGeneralTest (desc), m_segmentSize (segmentSize), @@ -192,18 +192,19 @@ class TcpRenoCongAvoidTestSuite : public TestSuite public: TcpRenoCongAvoidTestSuite () : TestSuite ("tcp-cong-avoid-test", UNIT) { - std::list types; - types.insert (types.begin (), TcpNewReno::GetTypeId ()); + std::list types = { + TcpNewReno::GetTypeId (), + }; - for (std::list::iterator it = types.begin (); it != types.end (); ++it) + for (const auto &t : types) { + std::string typeName = t.GetName (); + for (uint32_t i = 10; i <= 50; i += 10) { - AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 500, i, (*it), - "cong avoid MSS=500, pkt_size=500," + (*it).GetName ()), + AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 500, i, t, "cong avoid MSS=500, pkt_size=500," + typeName), TestCase::QUICK); - AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 1000, i, (*it), - "cong avoid MSS=500, pkt_size=1000," + (*it).GetName ()), + AddTestCase (new TcpNewRenoCongAvoidNormalTest (500, 1000, i, t, "cong avoid MSS=500, pkt_size=1000," + typeName), TestCase::QUICK); } } diff --git a/src/internet/test/tcp-rto-test.cc b/src/internet/test/tcp-rto-test.cc index 00cc1d217..4ec74f29c 100644 --- a/src/internet/test/tcp-rto-test.cc +++ b/src/internet/test/tcp-rto-test.cc @@ -49,7 +49,7 @@ public: * \param congControl Congestion control type. * \param msg Test description. */ - TcpRtoTest (TypeId &congControl, const std::string &msg); + TcpRtoTest (const TypeId &congControl, const std::string &msg); protected: @@ -68,7 +68,7 @@ private: bool m_segmentReceived; //!< True if segments have been received. }; -TcpRtoTest::TcpRtoTest (TypeId &congControl, const std::string &desc) +TcpRtoTest::TcpRtoTest (const TypeId &congControl, const std::string &desc) : TcpGeneralTest (desc), m_afterRTOExpired (false), m_segmentReceived (false) @@ -182,12 +182,12 @@ class TcpSsThreshRtoTest : public TcpGeneralTest public: /** * \brief Constructor. - * \param congControl Congestion control type. + * \param congControl congestion control type * \param seqToDrop sequence number to drop * \param minRto minimum RTO - * \param msg Test description. + * \param msg test description */ - TcpSsThreshRtoTest (TypeId &congControl, uint32_t seqToDrop, Time minRto, const std::string &msg); + TcpSsThreshRtoTest (const TypeId &congControl, uint32_t seqToDrop, Time minRto, const std::string &msg); protected: @@ -200,7 +200,7 @@ protected: virtual void ConfigureEnvironment (); - /** + /** * \brief Called when a packet has been dropped. * \param ipH IPv4 header. * \param tcpH TCP header. @@ -216,7 +216,7 @@ private: Time m_minRtoTime; //!< the minimum RTO time }; -TcpSsThreshRtoTest::TcpSsThreshRtoTest (TypeId &congControl, uint32_t seqToDrop, Time minRto, const std::string &desc) +TcpSsThreshRtoTest::TcpSsThreshRtoTest (const TypeId &congControl, uint32_t seqToDrop, Time minRto, const std::string &desc) : TcpGeneralTest (desc), m_seqToDrop (seqToDrop), m_minRtoTime (minRto) @@ -250,7 +250,7 @@ TcpSsThreshRtoTest::CreateReceiverErrorModel () Ptr errorModel = CreateObject (); - for (uint32_t i = 0; i<3; ++i) + for (uint32_t i = 0; i < 3; ++i) { errorModel->AddSeqToKill (SequenceNumber32 (m_seqToDrop)); } @@ -262,7 +262,7 @@ TcpSsThreshRtoTest::CreateReceiverErrorModel () void TcpSsThreshRtoTest::PktDropped (const Ipv4Header &ipH, const TcpHeader& tcpH, - Ptr p) + Ptr p) { NS_LOG_DEBUG ("DROPPED! " << tcpH); } @@ -301,8 +301,8 @@ TcpSsThreshRtoTest::AfterRTOExpired (const Ptr tcb, Socket NS_LOG_DEBUG ("After RTO for " << who); Ptr senderSocket = GetSenderSocket(); - // compute the ssThresh according to RFC 5681, using the - uint32_t ssThresh = std::max(m_bytesInFlightBeforeRto/2, 2*tcb->m_segmentSize); + // compute the ssThresh according to RFC 5681, using the + uint32_t ssThresh = std::max (m_bytesInFlightBeforeRto / 2, 2 * tcb->m_segmentSize); NS_LOG_DEBUG ("ssThresh " << ssThresh << " m_ssThreshSocket " << m_ssThreshSocket); @@ -327,7 +327,7 @@ public: * \param congControl Congestion control type. * \param msg Test description. */ - TcpTimeRtoTest (TypeId &congControl, const std::string &msg); + TcpTimeRtoTest (const TypeId &congControl, const std::string &msg); protected: virtual Ptr CreateSenderSocket (Ptr node); @@ -354,8 +354,8 @@ private: }; -TcpTimeRtoTest::TcpTimeRtoTest (TypeId &congControl, const std::string &desc) - : TcpGeneralTest (desc), +TcpTimeRtoTest::TcpTimeRtoTest (const TypeId &congControl, const std::string &desc) + : TcpGeneralTest (desc), m_senderSentSegments (0), m_closed (false) { @@ -385,7 +385,7 @@ TcpTimeRtoTest::CreateReceiverErrorModel () Ptr errorModel = CreateObject (); // Drop packet for 7 times. At the 7th, the connection should be dropped. - for (uint32_t i = 0; i<7; ++i) + for (uint32_t i = 0; i < 7; ++i) { errorModel->AddSeqToKill (SequenceNumber32 (1)); } @@ -433,13 +433,13 @@ TcpTimeRtoTest::Tx (const Ptr p, const TcpHeader&h, SocketWho who) Time clockGranularity = GetClockGranularity (SENDER); m_previousRTO = rttEstimator->GetEstimate (); - if (clockGranularity > rttEstimator->GetVariation ()*4) + if (clockGranularity > rttEstimator->GetVariation () * 4) { m_previousRTO += clockGranularity; } else { - m_previousRTO += rttEstimator->GetVariation ()*4; + m_previousRTO += rttEstimator->GetVariation () * 4; } m_previousRTO = Max (m_previousRTO, GetMinRto (SENDER)); @@ -458,12 +458,11 @@ TcpTimeRtoTest::Tx (const Ptr p, const TcpHeader&h, SocketWho who) } else if (who == RECEIVER) { - } } void -TcpTimeRtoTest::ErrorClose (SocketWho who) +TcpTimeRtoTest::ErrorClose (SocketWho who) { m_closed = true; } @@ -477,7 +476,7 @@ TcpTimeRtoTest::AfterRTOExpired (const Ptr tcb, SocketWho if (actualRto < Seconds (60)) { - NS_TEST_ASSERT_MSG_EQ_TOL (actualRto, m_previousRTO+m_previousRTO, Seconds (0.01), + NS_TEST_ASSERT_MSG_EQ_TOL (actualRto, m_previousRTO + m_previousRTO, Seconds (0.01), "RTO has not doubled after an expiration"); m_previousRTO += m_previousRTO; } @@ -514,24 +513,31 @@ class TcpRtoTestSuite : public TestSuite public: TcpRtoTestSuite () : TestSuite ("tcp-rto-test", UNIT) { - std::list types; - types.insert (types.begin (), TcpNewReno::GetTypeId ()); + std::list types = { + TcpNewReno::GetTypeId (), + }; - for (std::list::iterator it = types.begin (); it != types.end (); ++it) + for (const auto &t : types) { - AddTestCase (new TcpRtoTest ((*it), (*it).GetName () + " RTO retransmit testing"), TestCase::QUICK); - uint32_t seqToDrop = 25001; - Time minRto = Seconds (0.5); + AddTestCase (new TcpRtoTest (t, t.GetName () + " RTO retransmit testing"), TestCase::QUICK); + + constexpr uint32_t seqToDrop = 25001; + // With RTO of 0.5 seconds, BytesInFlight winds down to zero before RTO - AddTestCase (new TcpSsThreshRtoTest ((*it), seqToDrop, minRto, (*it).GetName () + " RTO ssthresh testing, set to 2*MSL"), TestCase::QUICK); - // With RTO of 0.005 seconds, FlightSize/2 > 2*SMSS - minRto = Seconds (0.005); - AddTestCase (new TcpSsThreshRtoTest ((*it), seqToDrop, minRto, (*it).GetName () + " RTO ssthresh testing, set to half of BytesInFlight"), TestCase::QUICK); - AddTestCase (new TcpTimeRtoTest ((*it), (*it).GetName () + " RTO timing testing"), TestCase::QUICK); + AddTestCase (new TcpSsThreshRtoTest ( + t, seqToDrop, Seconds (0.5), + t.GetName () + " RTO ssthresh testing, set to 2*MSL"), + TestCase::QUICK); + + // With RTO of 0.005 seconds, FlightSize/2 > 2*SMSS + AddTestCase (new TcpSsThreshRtoTest ( + t, seqToDrop, Seconds (0.005), + t.GetName () + " RTO ssthresh testing, set to half of BytesInFlight"), + TestCase::QUICK); + + AddTestCase (new TcpTimeRtoTest (t, t.GetName () + " RTO timing testing"), TestCase::QUICK); } } }; static TcpRtoTestSuite g_TcpRtoTestSuite; //!< Static variable for test initialization - - diff --git a/src/internet/test/tcp-slow-start-test.cc b/src/internet/test/tcp-slow-start-test.cc index c63670b20..81ce59556 100644 --- a/src/internet/test/tcp-slow-start-test.cc +++ b/src/internet/test/tcp-slow-start-test.cc @@ -57,7 +57,7 @@ public: * \param desc Test description. */ TcpSlowStartNormalTest (uint32_t segmentSize, uint32_t packetSize, - uint32_t initSsTh, uint32_t packets, TypeId& congControl, + uint32_t initSsTh, uint32_t packets, const TypeId& congControl, const std::string &desc); protected: @@ -87,7 +87,7 @@ TcpSlowStartNormalTest::TcpSlowStartNormalTest (uint32_t segmentSize, uint32_t packetSize, uint32_t initSsTh, uint32_t packets, - TypeId &typeId, + const TypeId &typeId, const std::string &desc) : TcpGeneralTest (desc), m_ackedBytes (0), @@ -230,7 +230,7 @@ public: * \param desc Test description. */ TcpSlowStartAttackerTest (uint32_t segmentSize, uint32_t packetSize, - uint32_t initSsTh, uint32_t packets, TypeId& congControl, + uint32_t initSsTh, uint32_t packets, const TypeId& congControl, const std::string &desc); protected: @@ -241,7 +241,8 @@ TcpSlowStartAttackerTest::TcpSlowStartAttackerTest (uint32_t segmentSize, uint32_t packetSize, uint32_t initSsTh, uint32_t packets, - TypeId &typeId, const std::string &msg) + const TypeId &typeId, + const std::string &msg) : TcpSlowStartNormalTest (segmentSize, packetSize, initSsTh, packets, typeId, msg) { @@ -272,29 +273,31 @@ public: TcpSlowStartTestSuite () : TestSuite ("tcp-slow-start-test", UNIT) { // This test have less packets to transmit than SsTh - std::list types; - types.insert (types.begin (), TcpNewReno::GetTypeId ()); + std::list types = { + TcpNewReno::GetTypeId (), + }; - for (std::list::iterator it = types.begin (); it != types.end (); ++it) + for (const auto &t : types) { - AddTestCase (new TcpSlowStartNormalTest (500, 500, 10000, 10, (*it), - "slow start 500 byte, " + (*it).GetName ()), + std::string typeName = t.GetName (); + + AddTestCase (new TcpSlowStartNormalTest (500, 500, 10000, 10, t, + "slow start 500 byte, " + typeName), TestCase::QUICK); - AddTestCase (new TcpSlowStartNormalTest (1000, 1000, 10000, 9, (*it), - "slow start 1000 byte, " + (*it).GetName ()), + AddTestCase (new TcpSlowStartNormalTest (1000, 1000, 10000, 9, t, + "slow start 1000 byte, " + typeName), TestCase::QUICK); - AddTestCase (new TcpSlowStartNormalTest (500, 250, 10000, 10, (*it), - "slow start small packets, " + (*it).GetName ()), + AddTestCase (new TcpSlowStartNormalTest (500, 250, 10000, 10, t, + "slow start small packets, " + typeName), TestCase::QUICK); - AddTestCase (new TcpSlowStartAttackerTest (500, 500, 10000, 10, (*it), - "slow start ack attacker, 500 byte, " + (*it).GetName ()), + AddTestCase (new TcpSlowStartAttackerTest (500, 500, 10000, 10, t, + "slow start ack attacker, 500 byte, " + typeName), TestCase::QUICK); - AddTestCase (new TcpSlowStartAttackerTest (1000, 1000, 10000, 9, (*it), - "slow start ack attacker, 1000 byte, " + (*it).GetName ()), + AddTestCase (new TcpSlowStartAttackerTest (1000, 1000, 10000, 9, t, + "slow start ack attacker, 1000 byte, " + typeName), TestCase::QUICK); } } }; static TcpSlowStartTestSuite g_tcpSlowStartTestSuite; //!< Static variable for test initialization -