tcp: Clean up tcp-rto-test.cc, tcp-slow-start-test.cc and tcp-cong-avoid-test.cc

This commit is contained in:
Eduardo Almeida
2022-02-17 11:22:47 +00:00
committed by Tom Henderson
parent bd46c2c0b6
commit a3e63cc706
3 changed files with 70 additions and 60 deletions

View File

@@ -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<TypeId> types;
types.insert (types.begin (), TcpNewReno::GetTypeId ());
std::list<TypeId> types = {
TcpNewReno::GetTypeId (),
};
for (std::list<TypeId>::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);
}
}

View File

@@ -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<TcpSeqErrorModel> errorModel = CreateObject<TcpSeqErrorModel> ();
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<const Packet> p)
Ptr<const Packet> p)
{
NS_LOG_DEBUG ("DROPPED! " << tcpH);
}
@@ -301,8 +301,8 @@ TcpSsThreshRtoTest::AfterRTOExpired (const Ptr<const TcpSocketState> tcb, Socket
NS_LOG_DEBUG ("After RTO for " << who);
Ptr<TcpSocketMsgBase> 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<TcpSocketMsgBase> CreateSenderSocket (Ptr<Node> 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<TcpSeqErrorModel> errorModel = CreateObject<TcpSeqErrorModel> ();
// 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<const Packet> 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<const Packet> 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<const TcpSocketState> 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<TypeId> types;
types.insert (types.begin (), TcpNewReno::GetTypeId ());
std::list<TypeId> types = {
TcpNewReno::GetTypeId (),
};
for (std::list<TypeId>::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

View File

@@ -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<TypeId> types;
types.insert (types.begin (), TcpNewReno::GetTypeId ());
std::list<TypeId> types = {
TcpNewReno::GetTypeId (),
};
for (std::list<TypeId>::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