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 TCPVEGAS_H
28 #define TCPVEGAS_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 Vegas
40  *
41  * TCP Vegas is a pure delay-based congestion control algorithm implementing a proactive
42  * scheme that tries to prevent packet drops by maintaining a small backlog at the
43  * bottleneck queue.
44  *
45  * Vegas continuously measures the actual throughput a connection achieves as shown in
46  * Equation (1) and compares it with the expected throughput calculated in Equation (2).
47  * The difference between these 2 sending rates in Equation (3) reflects the amount of
48  * extra packets being queued at the bottleneck.
49  *
50  *              actual = cwnd / RTT        (1)
51  *              expected = cwnd / BaseRTT  (2)
52  *              diff = expected - actual   (3)
53  *
54  * To avoid congestion, Vegas linearly increases/decreases its congestion window to ensure
55  * the diff value fall between the 2 predefined thresholds, alpha and beta.
56  * diff and another threshold, gamma, are used to determine when Vegas should change from
57  * its slow-start mode to linear increase/decrease mode.
58  *
59  * Following the implementation of Vegas in Linux, we use 2, 4, and 1 as the default values
60  * of alpha, beta, and gamma, respectively.
61  *
62  * More information: http://dx.doi.org/10.1109/49.464716
63  */
64 
65 class TcpVegas : public TcpNewReno
66 {
67 public:
68   /**
69    * \brief Get the type ID.
70    * \return the object TypeId
71    */
72   static TypeId GetTypeId (void);
73 
74   /**
75    * Create an unbound tcp socket.
76    */
77   TcpVegas (void);
78 
79   /**
80    * \brief Copy constructor
81    * \param sock the object to copy
82    */
83   TcpVegas (const TcpVegas& sock);
84   virtual ~TcpVegas (void);
85 
86   virtual std::string GetName () const;
87 
88   /**
89    * \brief Compute RTTs needed to execute Vegas algorithm
90    *
91    * The function filters RTT samples from the last RTT to find
92    * the current smallest propagation delay + queueing delay (minRtt).
93    * We take the minimum to avoid the effects of delayed ACKs.
94    *
95    * The function also min-filters all RTT measurements seen to find the
96    * propagation delay (baseRtt).
97    *
98    * \param tcb internal congestion state
99    * \param segmentsAcked count of segments ACKed
100    * \param rtt last RTT
101    *
102    */
103   virtual void PktsAcked (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked,
104                           const Time& rtt);
105 
106   /**
107    * \brief Enable/disable Vegas algorithm depending on the congestion state
108    *
109    * We only start a Vegas cycle when we are in normal congestion state (CA_OPEN state).
110    *
111    * \param tcb internal congestion state
112    * \param newState new congestion state to which the TCP is going to switch
113    */
114   virtual void CongestionStateSet (Ptr<TcpSocketState> tcb,
115                                    const TcpSocketState::TcpCongState_t newState);
116 
117   /**
118    * \brief Adjust cwnd following Vegas linear increase/decrease algorithm
119    *
120    * \param tcb internal congestion state
121    * \param segmentsAcked count of segments ACKed
122    */
123   virtual void IncreaseWindow (Ptr<TcpSocketState> tcb, uint32_t segmentsAcked);
124 
125   /**
126    * \brief Get slow start threshold following Vegas principle
127    *
128    * \param tcb internal congestion state
129    * \param bytesInFlight bytes in flight
130    *
131    * \return the slow start threshold value
132    */
133   virtual uint32_t GetSsThresh (Ptr<const TcpSocketState> tcb,
134                                 uint32_t bytesInFlight);
135 
136   virtual Ptr<TcpCongestionOps> Fork ();
137 
138 protected:
139 private:
140   /**
141    * \brief Enable Vegas algorithm to start taking Vegas samples
142    *
143    * Vegas algorithm is enabled in the following situations:
144    * 1. at the establishment of a connection
145    * 2. after an RTO
146    * 3. after fast recovery
147    * 4. when an idle connection is restarted
148    *
149    * \param tcb internal congestion state
150    */
151   void EnableVegas (Ptr<TcpSocketState> tcb);
152 
153   /**
154    * \brief Stop taking Vegas samples
155    */
156   void DisableVegas ();
157 
158 private:
159   uint32_t m_alpha;                  //!< Alpha threshold, lower bound of packets in network
160   uint32_t m_beta;                   //!< Beta threshold, upper bound of packets in network
161   uint32_t m_gamma;                  //!< Gamma threshold, limit on increase
162   Time m_baseRtt;                    //!< Minimum of all Vegas RTT measurements seen during connection
163   Time m_minRtt;                     //!< Minimum of all RTT measurements within last RTT
164   uint32_t m_cntRtt;                 //!< Number of RTT measurements during last RTT
165   bool m_doingVegasNow;              //!< If true, do Vegas for this RTT
166   SequenceNumber32 m_begSndNxt;      //!< Right edge during last RTT
167 };
168 
169 } // namespace ns3
170 
171 #endif // TCPVEGAS_H
172