INET Framework for OMNeT++/OMNEST
inet::tcp::TCPWestwood Class Reference

#include <TCPWestwood.h>

Inheritance diagram for inet::tcp::TCPWestwood:
inet::tcp::TCPBaseAlg inet::tcp::TCPAlgorithm

Public Member Functions

 TCPWestwood ()
 Ctor. More...
 
virtual void receivedDataAck (uint32 firstSeqAcked) override
 Redefine what should happen when data got acked, to add congestion window management. More...
 
virtual void receivedDuplicateAck () override
 Redefine what should happen when dupAck was received, to add congestion window management. More...
 
virtual void dataSent (uint32 fromseq) override
 Called after we send data. More...
 
virtual void segmentRetransmitted (uint32 fromseq, uint32 toseq) override
 Called after we retransmitted segment. More...
 
- Public Member Functions inherited from inet::tcp::TCPBaseAlg
 TCPBaseAlg ()
 Ctor. More...
 
virtual ~TCPBaseAlg ()
 Virtual dtor. More...
 
virtual void initialize () override
 Create timers, etc. More...
 
virtual void established (bool active) override
 Called when the connection is going to ESTABLISHED from SYN_SENT or SYN_RCVD. More...
 
virtual void connectionClosed () override
 Called when the connection closes, it should cancel all running timers. More...
 
virtual void processTimer (cMessage *timer, TCPEventCode &event) override
 Process REXMIT, PERSIST, DELAYED-ACK and KEEP-ALIVE timers. More...
 
virtual void sendCommandInvoked () override
 Called after user sent TCP_C_SEND command to us. More...
 
virtual void receivedOutOfOrderSegment () override
 Called after receiving data which are in the window, but not at its left edge (seq != rcv_nxt). More...
 
virtual void receiveSeqChanged () override
 Called after rcv_nxt got advanced, either because we received in-sequence data ("text" in RFC 793 lingo) or a FIN. More...
 
virtual void receivedAckForDataNotYetSent (uint32 seq) override
 Called after we received an ACK for data not yet sent. More...
 
virtual void ackSent () override
 Called after we sent an ACK. More...
 
virtual void restartRexmitTimer () override
 Restart REXMIT timer. More...
 
- Public Member Functions inherited from inet::tcp::TCPAlgorithm
 TCPAlgorithm ()
 Ctor. More...
 
virtual ~TCPAlgorithm ()
 Virtual dtor. More...
 
void setConnection (TCPConnection *_conn)
 Assign this object to a TCPConnection. More...
 
TCPStateVariablesgetStateVariables ()
 Creates and returns the TCP state variables. More...
 

Protected Member Functions

virtual TCPStateVariablescreateStateVariables () override
 Create and return a TCPvegasStateVariables object. More...
 
virtual void recalculateSlowStartThreshold ()
 Utility function to recalculate ssthresh. More...
 
virtual void processRexmitTimer (TCPEventCode &event) override
 Redefine what should happen on retransmission. More...
 
virtual void recalculateBWE (uint32 cumul_ack)
 Recalculate BWE. More...
 
- Protected Member Functions inherited from inet::tcp::TCPBaseAlg
virtual void startRexmitTimer ()
 Start REXMIT timer and initialize retransmission variables. More...
 
virtual void rttMeasurementComplete (simtime_t tSent, simtime_t tAcked)
 Update state vars with new measured RTT value. More...
 
virtual void rttMeasurementCompleteUsingTS (uint32 echoedTS) override
 Converting uint32 echoedTS to simtime_t and calling rttMeasurementComplete() to update state vars with new measured RTT value. More...
 
virtual bool sendData (bool sendCommandInvoked)
 Send data, observing Nagle's algorithm and congestion window. More...
 
cMessage * cancelEvent (cMessage *msg)
 Utility function. More...
 
virtual void processPersistTimer (TCPEventCode &event)
 
virtual void processDelayedAckTimer (TCPEventCode &event)
 
virtual void processKeepAliveTimer (TCPEventCode &event)
 

Protected Attributes

TCPWestwoodStateVariables *& state
 
- Protected Attributes inherited from inet::tcp::TCPBaseAlg
TCPBaseAlgStateVariables *& state
 
cMessage * rexmitTimer
 
cMessage * persistTimer
 
cMessage * delayedAckTimer
 
cMessage * keepAliveTimer
 
cOutVector * cwndVector
 
cOutVector * ssthreshVector
 
cOutVector * rttVector
 
cOutVector * srttVector
 
cOutVector * rttvarVector
 
cOutVector * rtoVector
 
cOutVector * numRtosVector
 
- Protected Attributes inherited from inet::tcp::TCPAlgorithm
TCPConnectionconn
 
TCPStateVariablesstate
 

Constructor & Destructor Documentation

inet::tcp::TCPWestwood::TCPWestwood ( )

Ctor.

62  : TCPBaseAlg(), state((TCPWestwoodStateVariables *&)TCPAlgorithm::state)
63 {
64 }
TCPStateVariables * state
Definition: TCPAlgorithm.h:41
TCPBaseAlg()
Ctor.
Definition: TCPBaseAlg.cc:98
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58

Member Function Documentation

virtual TCPStateVariables* inet::tcp::TCPWestwood::createStateVariables ( )
inlineoverrideprotectedvirtual

Create and return a TCPvegasStateVariables object.

Implements inet::tcp::TCPAlgorithm.

62  {
63  return new TCPWestwoodStateVariables();
64  }
void inet::tcp::TCPWestwood::dataSent ( uint32  fromseq)
overridevirtual

Called after we send data.

Reimplemented from inet::tcp::TCPBaseAlg.

296 {
297  TCPBaseAlg::dataSent(fromseq);
298 
299  // save time when packet is sent
300  // fromseq is the seq number of the 1st sent byte
301 
302  simtime_t sendtime = simTime();
304  state->regions.set(fromseq, state->snd_max, sendtime);
305 }
virtual void dataSent(uint32 fromseq) override
Called after we sent data.
Definition: TCPBaseAlg.cc:649
void clearTo(uint32_t endseg)
Definition: TCPSegmentTransmitInfoList.cc:87
void set(uint32_t beg, uint32_t end, simtime_t sentTime)
Definition: TCPSegmentTransmitInfoList.cc:28
uint32 snd_una
Definition: TCPConnection.h:164
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58
TCPSegmentTransmitInfoList regions
Definition: TCPWestwood.h:52
uint32 snd_max
Definition: TCPConnection.h:166
void inet::tcp::TCPWestwood::processRexmitTimer ( TCPEventCode event)
overrideprotectedvirtual

Redefine what should happen on retransmission.

Reimplemented from inet::tcp::TCPBaseAlg.

93 {
95 
96  if (event == TCP_E_ABORT)
97  return;
98 
99  // TCP Westwood: congestion control with faster recovery. S. Mascolo, C. Casetti, M. Gerla, S.S. Lee, M. Sanadidi
100  // After REXMIT timeout in TCP Westwood: a increases from 1 to 4, in steps of 1 during slow start,
101  // and is set to 1 in cong. avoidance.
102  // the cong. window is reset to 1 after a timeout, as is done by TCP Reno. Conservative. Reaseon: fairness.
103 
104  if (state->snd_cwnd < state->ssthresh) { // Slow start
105  state->w_a = state->w_a + 1;
106  if (state->w_a > 4)
107  state->w_a = 4;
108  }
109  else { // Cong. avoidance
110  state->w_a = 1;
111  }
112 
114  if (state->ssthresh < 2 * state->snd_mss)
115  state->ssthresh = 2 * state->snd_mss;
116 
118 
119  if (cwndVector)
120  cwndVector->record(state->snd_cwnd);
121 
122  state->afterRto = true;
123  conn->retransmitOneSegment(true);
124 }
virtual void retransmitOneSegment(bool called_at_rto)
Utility: retransmit one segment from snd_una.
Definition: TCPConnectionUtil.cc:802
cOutVector * cwndVector
Definition: TCPBaseAlg.h:115
virtual void processRexmitTimer(TCPEventCode &event)
Definition: TCPBaseAlg.cc:231
uint32 snd_mss
Definition: TCPConnection.h:159
Definition: TCPConnection.h:90
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58
virtual void recalculateSlowStartThreshold()
Utility function to recalculate ssthresh.
Definition: TCPWestwood.cc:66
bool afterRto
Definition: TCPConnection.h:213
TCPConnection * conn
Definition: TCPAlgorithm.h:40
double w_a
Definition: TCPWestwood.h:45
uint32 ssthresh
slow start threshold
Definition: TCPWestwood.h:42
uint32 snd_cwnd
congestion window
Definition: TCPBaseAlg.h:54
void inet::tcp::TCPWestwood::recalculateBWE ( uint32  cumul_ack)
protectedvirtual

Recalculate BWE.

Referenced by receivedDataAck(), and receivedDuplicateAck().

77 {
78  simtime_t currentTime = simTime();
79  simtime_t timeAck = currentTime - state->w_lastAckTime;
80 
81  // Update BWE
82  if (timeAck > 0) {
83  double old_sample_bwe = state->w_sample_bwe;
84  double old_bwe = state->w_bwe;
85  state->w_sample_bwe = (cumul_ack) / timeAck;
86  state->w_bwe = (19.0 / 21.0) * old_bwe + (1.0 / 21.0) * (state->w_sample_bwe + old_sample_bwe);
87  EV_DEBUG << "recalculateBWE(), new w_bwe=" << state->w_bwe << "\n";
88  }
89  state->w_lastAckTime = currentTime;
90 }
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58
double w_bwe
Definition: TCPWestwood.h:49
double w_sample_bwe
Definition: TCPWestwood.h:50
simtime_t w_lastAckTime
Definition: TCPWestwood.h:47
void inet::tcp::TCPWestwood::recalculateSlowStartThreshold ( )
protectedvirtual

Utility function to recalculate ssthresh.

Referenced by processRexmitTimer(), and receivedDuplicateAck().

67 {
68  state->ssthresh = (uint32)((state->w_bwe * SIMTIME_DBL(state->w_RTTmin)) / (state->w_a));
69 
70  if (ssthreshVector)
71  ssthreshVector->record(state->ssthresh);
72 
73  EV_DEBUG << "recalculateSlowStartThreshold(), ssthresh=" << state->ssthresh << "\n";
74 }
simtime_t w_RTTmin
Definition: TCPWestwood.h:44
uint32_t uint32
Definition: Compat.h:30
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58
double w_bwe
Definition: TCPWestwood.h:49
cOutVector * ssthreshVector
Definition: TCPBaseAlg.h:116
double w_a
Definition: TCPWestwood.h:45
uint32 ssthresh
slow start threshold
Definition: TCPWestwood.h:42
void inet::tcp::TCPWestwood::receivedDataAck ( uint32  firstSeqAcked)
overridevirtual

Redefine what should happen when data got acked, to add congestion window management.

Reimplemented from inet::tcp::TCPBaseAlg.

127 {
128  TCPBaseAlg::receivedDataAck(firstSeqAcked);
129 
131  const TCPSegmentTransmitInfoList::Item *found = state->regions.get(firstSeqAcked);
132 
133  if (found != nullptr) {
134  simtime_t currentTime = simTime();
135  simtime_t newRTT = currentTime - found->getFirstSentTime();
136 
137  // Update RTTmin
138  if (newRTT < state->w_RTTmin && newRTT > 0 && found->getTransmitCount() == 1)
139  state->w_RTTmin = newRTT;
140 
141  // cumul_ack: cumulative ack's that acks 2 or more pkts count 1,
142  // because DUPACKs count them
143  uint32 cumul_ack = state->snd_una - firstSeqAcked; // acked bytes
144  if ((state->dupacks * state->snd_mss) >= cumul_ack)
145  cumul_ack = state->snd_mss; // cumul_ack = 1:
146  else
147  cumul_ack -= (state->dupacks * state->snd_mss);
148 
149  // security check: if previous steps are right cumul_ack shoudl be > 2:
150  if (cumul_ack > (2 * state->snd_mss))
151  cumul_ack = 2 * state->snd_mss;
152 
153  recalculateBWE(cumul_ack);
154  } // Closes if w_sendtime != nullptr
155 
156  // Same behavior of Reno during fast recovery, slow start and cong. avoidance
157 
158  if (state->dupacks >= DUPTHRESH) { // DUPTHRESH = 3
159  //
160  // Perform Fast Recovery: set cwnd to ssthresh (deflating the window).
161  //
162  EV_DETAIL << "Fast Recovery: setting cwnd to ssthresh=" << state->ssthresh << "\n";
164 
165  if (cwndVector)
166  cwndVector->record(state->snd_cwnd);
167  }
168  else {
169  //
170  // Perform slow start and congestion avoidance.
171  //
172  if (state->snd_cwnd < state->ssthresh) {
173  EV_DETAIL << "cwnd <= ssthresh: Slow Start: increasing cwnd by one SMSS bytes to ";
174 
175  // perform Slow Start. RFC 2581: "During slow start, a TCP increments cwnd
176  // by at most SMSS bytes for each ACK received that acknowledges new data."
178 
179  // Note: we could increase cwnd based on the number of bytes being
180  // acknowledged by each arriving ACK, rather than by the number of ACKs
181  // that arrive. This is called "Appropriate Byte Counting" (ABC) and is
182  // described in RFC 3465. This RFC is experimental and probably not
183  // implemented in real-life TCPs, hence it's commented out. Also, the ABC
184  // RFC would require other modifications as well in addition to the
185  // two lines below.
186  //
187  // int bytesAcked = state->snd_una - firstSeqAcked;
188  // state->snd_cwnd += bytesAcked * state->snd_mss;
189 
190  if (cwndVector)
191  cwndVector->record(state->snd_cwnd);
192 
193  EV_DETAIL << "cwnd=" << state->snd_cwnd << "\n";
194  }
195  else {
196  // perform Congestion Avoidance (RFC 2581)
198 
199  if (incr == 0)
200  incr = 1;
201 
202  state->snd_cwnd += incr;
203 
204  if (cwndVector)
205  cwndVector->record(state->snd_cwnd);
206 
207  //
208  // Note: some implementations use extra additive constant mss / 8 here
209  // which is known to be incorrect (RFC 2581 p5)
210  //
211  // Note 2: RFC 3465 (experimental) "Appropriate Byte Counting" (ABC)
212  // would require maintaining a bytes_acked variable here which we don't do
213  //
214 
215  EV_DETAIL << "cwnd > ssthresh: Congestion Avoidance: increasing cwnd linearly, to " << state->snd_cwnd << "\n";
216  }
217  }
218 
219  sendData(false);
220 }
cOutVector * cwndVector
Definition: TCPBaseAlg.h:115
void clearTo(uint32_t endseg)
Definition: TCPSegmentTransmitInfoList.cc:87
virtual void receivedDataAck(uint32 firstSeqAcked) override
Called after we received an ACK which acked some data (that is, we could advance snd_una).
Definition: TCPBaseAlg.cc:529
virtual void recalculateBWE(uint32 cumul_ack)
Recalculate BWE.
Definition: TCPWestwood.cc:76
uint32 snd_mss
Definition: TCPConnection.h:159
simtime_t w_RTTmin
Definition: TCPWestwood.h:44
uint32 dupacks
Definition: TCPConnection.h:255
#define DUPTHRESH
Definition: TCPConnection.h:126
uint32 snd_una
Definition: TCPConnection.h:164
uint32_t uint32
Definition: Compat.h:30
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58
const Item * get(uint32_t seq) const
returns pointer to Item, or nullptr if not found
Definition: TCPSegmentTransmitInfoList.cc:76
TCPSegmentTransmitInfoList regions
Definition: TCPWestwood.h:52
uint32 ssthresh
slow start threshold
Definition: TCPWestwood.h:42
uint32 snd_cwnd
congestion window
Definition: TCPBaseAlg.h:54
if(!(yy_init))
Definition: lexer.cc:1644
virtual bool sendData(bool sendCommandInvoked)
Send data, observing Nagle&#39;s algorithm and congestion window.
Definition: TCPBaseAlg.cc:429
void inet::tcp::TCPWestwood::receivedDuplicateAck ( )
overridevirtual

Redefine what should happen when dupAck was received, to add congestion window management.

Reimplemented from inet::tcp::TCPBaseAlg.

223 {
225 
226  {
227  // BWE calculation: dupack counts 1
228  uint32 cumul_ack = state->snd_mss;
229  recalculateBWE(cumul_ack);
230  } // Closes if w_sendtime != nullptr
231 
232  if (state->dupacks == DUPTHRESH) { // DUPTHRESH = 3
233  EV_DETAIL << "Westwood on dupAcks == DUPTHRESH(=3): Faster Retransmit \n";
234 
235  // TCP Westwood: congestion control with faster recovery. S. Mascolo, C. Casetti, M. Gerla, S.S. Lee, M. Sanadidi
236  // During the cong. avoidance phase we are probing for extra available bandwidth.
237  // Therefore, when n DUPACKS are received, it means that we have hit the network
238  // capacity. Thus, the slow start threshold is set equal to the available pipe size
239  // (BWE*RTTmin), the cong. window is set equal to ssthresh and the cong. avoidance phase
240  // is entered again to gently probe for new available bandwitdh.
241 
242  // During the slow start phase we are still probing for the available bandwidth.
243  // Therefore the BWE we obtain after n duplicate ACKs is used to set the slow start threshold.
244  // After ssthresh has been set, the cong. window is set equal to the slow start theshold only
245  // if cwin>ssthresh. In other words, during slow start, cwin still features an exponential
246  // increase as in the current implementation of TCP Reno.
247 
248  // a increases from 1 to 4 in steps of 0.25 every time 3 DUPACKS are received in slow start.
249  // while is set to 1 in cong. avoidance. (is initialized as 1).
250  // The purpose of the theshold reduction factor a is to dampen a possible overestimation of
251  // the available bandwidth. the more frequently a triple DUPACK is received during slow start,
252  // the bigger the reduction factor becomes.
253  // a is restored to 1 in cong. avoidance: ssthresh was set correctly and there is no need to reduce
254  // the impact of BWE
255 
256  if (state->snd_cwnd < state->ssthresh) { // Slow start
257  state->w_a = state->w_a + 0.25;
258  if (state->w_a > 4)
259  state->w_a = 4;
260  }
261  else { // Cong. avoidance
262  state->w_a = 1;
263  }
264 
266  // reset cwnd to ssthresh, if larger
267  if (state->snd_cwnd > state->ssthresh)
269 
270  if (cwndVector)
271  cwndVector->record(state->snd_cwnd);
272 
273  EV_DETAIL << " set cwnd=" << state->snd_cwnd << ", ssthresh=" << state->ssthresh << "\n";
274 
275  // Fast Retransmission: retransmit missing segment without waiting
276  // for the REXMIT timer to expire
278  conn->retransmitOneSegment(false);
279 
280  sendData(false);
281  }
282  // Behavior like Reno:
283  else if (state->dupacks > DUPTHRESH) { // DUPTHRESH = 3
284  // Westwood: like Reno
286  EV_DETAIL << "Westwood on dupAcks > DUPTHRESH(=3): Fast Recovery: inflating cwnd by SMSS, new cwnd=" << state->snd_cwnd << "\n";
287 
288  if (cwndVector)
289  cwndVector->record(state->snd_cwnd);
290 
291  sendData(false);
292  }
293 }
virtual void retransmitOneSegment(bool called_at_rto)
Utility: retransmit one segment from snd_una.
Definition: TCPConnectionUtil.cc:802
cOutVector * cwndVector
Definition: TCPBaseAlg.h:115
virtual void recalculateBWE(uint32 cumul_ack)
Recalculate BWE.
Definition: TCPWestwood.cc:76
uint32 snd_mss
Definition: TCPConnection.h:159
uint32 dupacks
Definition: TCPConnection.h:255
#define DUPTHRESH
Definition: TCPConnection.h:126
virtual void restartRexmitTimer() override
Restart REXMIT timer.
Definition: TCPBaseAlg.cc:674
uint32_t uint32
Definition: Compat.h:30
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58
virtual void recalculateSlowStartThreshold()
Utility function to recalculate ssthresh.
Definition: TCPWestwood.cc:66
virtual void receivedDuplicateAck() override
Called after we received a duplicate ACK (that is: ackNo == snd_una, no data in segment, segment doesn&#39;t carry window update, and also, we have unacked data).
Definition: TCPBaseAlg.cc:611
TCPConnection * conn
Definition: TCPAlgorithm.h:40
double w_a
Definition: TCPWestwood.h:45
uint32 ssthresh
slow start threshold
Definition: TCPWestwood.h:42
uint32 snd_cwnd
congestion window
Definition: TCPBaseAlg.h:54
virtual bool sendData(bool sendCommandInvoked)
Send data, observing Nagle&#39;s algorithm and congestion window.
Definition: TCPBaseAlg.cc:429
void inet::tcp::TCPWestwood::segmentRetransmitted ( uint32  fromseq,
uint32  toseq 
)
overridevirtual

Called after we retransmitted segment.

The argument fromseq is the seqno of the first byte sent. The argument toseq is the seqno of the last byte sent+1.

Reimplemented from inet::tcp::TCPBaseAlg.

308 {
309  TCPBaseAlg::segmentRetransmitted(fromseq, toseq);
310 
311  state->regions.set(fromseq, toseq, simTime());
312 }
void set(uint32_t beg, uint32_t end, simtime_t sentTime)
Definition: TCPSegmentTransmitInfoList.cc:28
TCPWestwoodStateVariables *& state
Definition: TCPWestwood.h:58
virtual void segmentRetransmitted(uint32 fromseq, uint32 toseq) override
Called after we retransmitted segment.
Definition: TCPBaseAlg.cc:670
TCPSegmentTransmitInfoList regions
Definition: TCPWestwood.h:52

Member Data Documentation


The documentation for this class was generated from the following files: