21 #define NS_LOG_APPEND_CONTEXT \
22 if (m_node) { std::clog << Simulator::Now ().GetSeconds () << " [node " << m_node->GetId () << "] "; }
24 #include "tcp-tahoe.h"
26 #include "ns3/trace-source-accessor.h"
27 #include "ns3/simulator.h"
28 #include "ns3/abort.h"
35 NS_OBJECT_ENSURE_REGISTERED (TcpTahoe);
38 TcpTahoe::GetTypeId (
void)
40 static TypeId tid = TypeId (
"ns3::TcpTahoe")
42 .AddConstructor<TcpTahoe> ()
43 .AddAttribute (
"ReTxThreshold",
"Threshold for fast retransmit",
45 MakeUintegerAccessor (&TcpTahoe::m_retxThresh),
46 MakeUintegerChecker<uint32_t> ())
47 .AddTraceSource (
"CongestionWindow",
48 "The TCP connection's congestion window",
62 m_ssThresh (sock.m_ssThresh),
63 m_initialCWnd (sock.m_initialCWnd),
64 m_retxThresh (sock.m_retxThresh)
70 TcpTahoe::~TcpTahoe (
void)
97 return std::min (m_rWnd.Get (), m_cWnd.Get ());
101 TcpTahoe::Fork (
void)
103 return CopyObject<TcpTahoe> (
this);
111 NS_LOG_LOGIC (
"TcpTahoe receieved ACK for seq " << seq <<
112 " cwnd " << m_cWnd <<
113 " ssthresh " << m_ssThresh);
114 if (m_cWnd < m_ssThresh)
116 m_cWnd += m_segmentSize;
117 NS_LOG_INFO (
"In SlowStart, updated to cwnd " << m_cWnd <<
" ssthresh " << m_ssThresh);
122 double adder =
static_cast<double> (m_segmentSize * m_segmentSize) / m_cWnd.Get ();
123 adder = std::max (1.0, adder);
124 m_cWnd +=
static_cast<uint32_t
> (adder);
125 NS_LOG_INFO (
"In CongAvoid, updated to cwnd " << m_cWnd <<
" ssthresh " << m_ssThresh);
127 TcpSocketBase::NewAck (seq);
135 if (count == m_retxThresh)
137 NS_LOG_INFO (
"Triple Dup Ack: old ssthresh " << m_ssThresh <<
" cwnd " << m_cWnd);
141 m_ssThresh = std::max (static_cast<unsigned> (m_cWnd / 2), m_segmentSize * 2);
142 m_cWnd = m_segmentSize;
144 NS_LOG_INFO (
"Triple Dup Ack: new ssthresh " << m_ssThresh <<
" cwnd " << m_cWnd);
156 if (m_state == CLOSED || m_state == TIME_WAIT)
return;
158 if (m_state <= ESTABLISHED && m_txBuffer.
HeadSequence () >= m_highTxMark)
return;
160 m_ssThresh = std::max (static_cast<unsigned> (m_cWnd / 2), m_segmentSize * 2);
161 m_cWnd = m_segmentSize;
163 m_rtt->IncreaseMultiplier ();
168 TcpTahoe::SetSegSize (uint32_t size)
170 NS_ABORT_MSG_UNLESS (m_state == CLOSED,
"TcpTahoe::SetSegSize() cannot change segment size after connection started.");
171 m_segmentSize = size;
175 TcpTahoe::SetSSThresh (uint32_t threshold)
177 m_ssThresh = threshold;
181 TcpTahoe::GetSSThresh (
void)
const
187 TcpTahoe::SetInitialCwnd (uint32_t cwnd)
189 NS_ABORT_MSG_UNLESS (m_state == CLOSED,
"TcpTahoe::SetInitialCwnd() cannot change initial cwnd after connection started.");
190 m_initialCWnd = cwnd;
194 TcpTahoe::GetInitialCwnd (
void)
const
196 return m_initialCWnd;
200 TcpTahoe::InitializeCwnd (
void)
207 m_cWnd = m_initialCWnd * m_segmentSize;
smart pointer class similar to boost::intrusive_ptr
#define NS_LOG_FUNCTION(parameters)
virtual uint32_t Window(void)
SequenceNumber32 HeadSequence(void) const
#define NS_LOG_COMPONENT_DEFINE(name)
#define NS_ABORT_MSG_UNLESS(cond, msg)
Abnormal program termination if cond is false.
An implementation of a stream socket using TCP.
a polymophic address class
A base class for implementation of a stream socket using TCP.
#define NS_LOG_LOGIC(msg)
virtual void Retransmit(void)
Ptr< const TraceSourceAccessor > MakeTraceSourceAccessor(T a)
virtual int Connect(const Address &address)
virtual void DupAck(const TcpHeader &t, uint32_t count)
virtual void NewAck(SequenceNumber32 const &seq)
virtual int Connect(const Address &address)