Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Added smooth start
SmoothStart class implemented as child of TcNewReno in a new file
  • Loading branch information
AsavariLimaye authored Apr 5, 2017
commit fb59d0a08ce47b27fd01568ca8d2407aa2634095
164 changes: 164 additions & 0 deletions src/internet/model/smooth-start.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,164 @@
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
/*
* Copyright (c) 2015 Natale Patriciello <[email protected]>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation;
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 U SA
*
*/
#include "tcp-congestion-ops.h"
#include "tcp-socket-base.h"
#include "ns3/log.h"
#include "smooth-start.h"

namespace ns3 {
NS_LOG_COMPONENT_DEFINE ("SmoothStart");

//NS_OBJECT_ENSURE_REGISTERED (SmoothStart);


//Smooth Start

/**
* \brief SmoothStart, a variant of SlowStart
*
*
* \param tcb internal congestion state
* \param segmentsAcked count of segments acked
* \return the number of segments not considered for increasing the cWnd
*/

NS_OBJECT_ENSURE_REGISTERED (SmoothStart);

TypeId
SmoothStart::GetTypeId (void)
{
static TypeId tid = TypeId ("ns3::SmoothStart")
.SetParent<TcpNewReno> ()
.SetGroupName ("Internet")
.AddConstructor<SmoothStart> ()
.AddAttribute ("GrainNumber",
"Grain number used for Smooth Start",
UintegerValue (2),
MakeUintegerAccessor (&SmoothStart::m_grainNumber),
MakeUintegerChecker<uint16_t> ()
)
.AddAttribute ("Depth",
"Depth used for Smooth Start",
UintegerValue (2),
MakeUintegerAccessor (&SmoothStart::m_depth),
MakeUintegerChecker<uint16_t> ()
);
return tid;
}


SmoothStart::SmoothStart (void) : TcpNewReno ()
{
NS_LOG_FUNCTION (this);
m_nAcked = 0;
m_grainNumber = 0;
m_depth = 0;
m_ackThresh = 0;
m_smsThresh = 0;
m_firstFlag = 0;
}

SmoothStart::SmoothStart (const SmoothStart& other)
: TcpNewReno (other)
{
NS_LOG_FUNCTION (this);
m_nAcked = other.m_nAcked;
m_grainNumber = other.m_grainNumber;
m_depth = other.m_depth;
m_ackThresh = other.m_ackThresh;
m_smsThresh = other.m_smsThresh;
m_firstFlag = other.m_firstFlag;
}

SmoothStart::~SmoothStart (void)
{
}

uint32_t
SmoothStart::SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
{
NS_LOG_FUNCTION (this << tcb << segmentsAcked);
m_smsThresh = tcb->m_ssThresh / pow(2,m_depth);

NS_LOG_INFO ("Before Decision: smsThresh: "<< m_smsThresh << " ssThresh: " << tcb->m_ssThresh << " nAcked: " << m_nAcked << " Ackthresh: "<<m_ackThresh<< " cwnd: "<< tcb->m_cWnd) ;

if (segmentsAcked >= 1)
{

if (tcb->m_cWnd <= m_smsThresh)
{
NS_LOG_INFO("++ Slow Start ++");
tcb->m_cWnd += tcb->m_segmentSize;
NS_LOG_INFO ("In SlowStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " << tcb->m_ssThresh);
return segmentsAcked - 1;
}

m_nAcked += 1;

if (m_nAcked == m_ackThresh)
{
NS_LOG_INFO("++ Smooth Start increasing cwnd++");
tcb->m_cWnd += tcb->m_segmentSize;
NS_LOG_INFO ("In SmoothStart, updated to cwnd " << tcb->m_cWnd << " ssthresh " << tcb->m_ssThresh);
m_ackThresh = m_ackThresh + 1;
m_nAcked = 0;
return segmentsAcked - 1;
}
else NS_LOG_INFO("++ Smooth Start not cwnd++ m_nAcked!=m_ackThresh"<< m_nAcked <<" " <<m_ackThresh);
return segmentsAcked - 1;
}
return 0;
}


void
SmoothStart::IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked)
{
NS_LOG_FUNCTION (this << tcb << segmentsAcked);

if (tcb->m_cWnd < tcb->m_ssThresh)
{
NS_LOG_INFO ("Doing SmoothStart") ;
if (m_firstFlag == 0)
{
m_firstFlag = 1 ;
m_ackThresh = m_grainNumber ;
}
segmentsAcked = SlowStart (tcb, segmentsAcked);
}

if (tcb->m_cWnd >= tcb->m_ssThresh)
{
m_firstFlag = 0;
NS_LOG_INFO("SmoothStart: Calling Congestion Avoidance");
CongestionAvoidance (tcb, segmentsAcked);
}

/* At this point, we could have segmentsAcked != 0. This because RFC says
* that in slow start, we should increase cWnd by min (N, SMSS); if in
* slow start we receive a cumulative ACK, it counts only for 1 SMSS of
* increase, wasting the others.
*
* // Uncorrect assert, I am sorry
* NS_ASSERT (segmentsAcked == 0);
*/
}

} // namespace ns3

47 changes: 47 additions & 0 deletions src/internet/model/smooth-start.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@

#ifndef SMOOTHSTART_H
#define SMOOTHSTART_H

#include "ns3/object.h"
#include "ns3/timer.h"
#include "ns3/tcp-socket-base.h"
#include "tcp-congestion-ops.h"

namespace ns3 {
/**
* \brief The Smooth Start implementation
*
* Implements Smooth Start, a variant of Slow Start
* \see SlowStart
* Function SlowStart overridden in this class, to implement Smooth Start
*/
class SmoothStart : public TcpNewReno
{
// Smooth Start
uint32_t m_grainNumber; //!< Grain Number in Smooth-Start
uint32_t m_depth; //!< Depth in Smooth-Start
uint32_t m_ackThresh; //!< The number of acknowledgements to be recieved before increasing cwnd
TracedValue<uint32_t> m_smsThresh; //!< Smooth Start threshold
uint32_t m_firstFlag; //!< Set to zero when CongestionAvoidance starts
uint32_t m_nAcked; //!< Number of acknowldgements recieved since last increase of cwnd

protected:
virtual uint32_t SlowStart (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);

public:
static TypeId GetTypeId (void);
SmoothStart ();
/**
* \brief Copy constructor.
* \param sock object to copy.
*/
SmoothStart (const SmoothStart& sock);

~SmoothStart ();
virtual void IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);

};

} // namespace ns3

#endif // SMOOTHSTART_H