1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2016 ResiliNets, ITTC, University of Kansas
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
17  *
18  * Author: Truc Anh N. Nguyen <annguyen@ittc.ku.edu>
19  *
20  * James P.G. Sterbenz <jpgs@ittc.ku.edu>, director
21  * ResiliNets Research Group  http://wiki.ittc.ku.edu/resilinets
22  * Information and Telecommunication Technology Center (ITTC)
23  * and Department of Electrical Engineering and Computer Science
24  * The University of Kansas Lawrence, KS USA.
25  */
26 
27 #ifndef TCPVENO_H
28 #define TCPVENO_H
29 
30 #include "tcp-congestion-ops.h"
31 
32 namespace ns3 {
33 
34 class TcpSocketState;
35 
36 /**
37  * \ingroup congestionOps
38  *
39  * \brief An implementation of TCP Veno
40  *
41  * TCP Veno enhances Reno algorithm for more effectively dealing with random
42  * packet loss in wireless access networks by employing Vegas's method in
43  * estimating the backlog at the bottleneck queue to distinguish between
44  * congestive and non-congestive states.
45  *
46  * The backlog (the number of packets accumulated at the bottleneck queue) is
47  * calculated using Equation (1):
48  *
49  *         N = Actual * (RTT - BaseRTT) = Diff * BaseRTT        (1)
50  * where
51  *         Diff = Expected - Actual = cwnd/BaseRTT - cwnd/RTT
52  *
53  * Veno makes decision on cwnd modification based on the calculated N and its
54  * predefined threshold beta.
55  *
56  * Specifically, it refines the additive increase algorithm of Reno so that the
57  * connection can stay longer in the stable state by incrementing cwnd by
58  * 1/cwnd for every other new ACK received after the available bandwidth has
59  * been fully utilized, i.e. when N exceeds beta.  Otherwise, Veno increases
60  * its cwnd by 1/cwnd upon every new ACK receipt as in Reno.
61  *
62  * In the multiplicative decrease algorithm, when Veno is in the non-congestive
63  * state, i.e. when N is less than beta, Veno decrements its cwnd by only 1/5
64  * because the loss encountered is more likely a corruption-based loss than a
65  * congestion-based.  Only when N is greater than beta, Veno halves its sending
66  * rate as in Reno.
67  *
68  * More information: http://dx.doi.org/10.1109/JSAC.2002.807336
69  */
70 
71 class TcpVeno : public TcpNewReno
72 {
73 public:
74   /**
75    * \brief Get the type ID.
76    * \return the object TypeId
77    */
78   static TypeId GetTypeId (void);
79 
80   /**
81    * Create an unbound tcp socket.
82    */
83   TcpVeno (void);
84 
85   /**
86    * \brief Copy constructor
87    * \param sock the object to copy
88    */
89   TcpVeno (const TcpVeno& sock);
90   virtual ~TcpVeno (void);
91 
92   virtual std::string GetName () const;
93 
94   /**
95    * \brief Perform RTT sampling needed to execute Veno algorithm
96    *
97    * The function filters RTT samples from the last RTT to find
98    * the current smallest propagation delay + queueing delay (m_minRtt).
99    * We take the minimum to avoid the effects of delayed ACKs.
100    *
101    * The function also min-filters all RTT measurements seen to find the
102    * propagation delay (m_baseRtt).
103    *
104    * \param tcb internal congestion state
105    * \param segmentsAcked count of segments ACKed
106    * \param rtt last RTT
107    *
108    */
109   virtual void PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
110                           const Time& rtt);
111 
112   /**
113    * \brief Enable/disable Veno depending on the congestion state
114    *
115    * We only start a Veno when we are in normal congestion state (CA_OPEN state).
116    *
117    * \param tcb internal congestion state
118    * \param newState new congestion state to which the TCP is going to switch
119    */
120   virtual void CongestionStateSet (Ptr<TcpSocketState> tcb,
121                                    const TcpSocketState::TcpCongState_t newState);
122 
123   /**
124    * \brief Adjust cwnd following Veno additive increase algorithm
125    *
126    * \param tcb internal congestion state
127    * \param segmentsAcked count of segments ACKed
128    */
129   virtual void IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
130 
131   /**
132    * \brief Get slow start threshold during Veno multiplicative-decrease phase
133    *
134    * \param tcb internal congestion state
135    * \param bytesInFlight bytes in flight
136    *
137    * \return the slow start threshold value
138    */
139   virtual uint32_t GetSsThresh (Ptr<const TcpSocketState> tcb,
140                                 uint32_t bytesInFlight);
141 
142   virtual Ptr<TcpCongestionOps> Fork ();
143 
144 protected:
145 private:
146   /**
147    * \brief Enable Veno algorithm to start Veno sampling
148    *
149    * Veno algorithm is enabled in the following situations:
150    * 1. at the establishment of a connection
151    * 2. after an RTO
152    * 3. after fast recovery
153    * 4. when an idle connection is restarted
154    *
155    */
156   void EnableVeno ();
157 
158   /**
159    * \brief Turn off Veno
160    */
161   void DisableVeno ();
162 
163 private:
164   Time m_baseRtt;                    //!< Minimum of all RTT measurements seen during connection
165   Time m_minRtt;                     //!< Minimum of RTTs measured within last RTT
166   uint32_t m_cntRtt;                 //!< Number of RTT measurements during last RTT
167   bool m_doingVenoNow;               //!< If true, do Veno for this RTT
168   uint32_t m_diff;                   //!< Difference between expected and actual throughput
169   bool m_inc;                        //!< If true, cwnd needs to be incremented
170   uint32_t m_ackCnt;                 //!< Number of received ACK
171   uint32_t m_beta;                   //!< Threshold for congestion detection
172 };
173 
174 } // namespace ns3
175 
176 #endif // TCPVENO_H
177