Left: | ||
Right: |
OLD | NEW |
---|---|
(Empty) | |
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ | |
2 /* | |
3 * Copyright (c) 2014 Natale Patriciello <natale.patriciello@gmail.com> | |
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 */ | |
19 | |
20 #ifndef TCPCUBIC_H | |
21 #define TCPCUBIC_H | |
22 | |
23 #include "ns3/tcp-socket-base.h" | |
24 #include "ns3/timer.h" | |
25 | |
26 | |
27 namespace ns3 { | |
28 | |
29 /** | |
30 * \brief The Cubic Congestion Control Algorithm | |
31 * | |
32 * CUBIC is an implementation of TCP with an optimized congestion control | |
33 * algorithm for high bandwidth networks with high latency (LFN: long fat | |
34 * networks). | |
35 * | |
36 * It is a less aggressive and more systematic derivative of BIC TCP, | |
37 * in which the window is a cubic function of time since the last | |
38 * congestion event, with the inflection point set to the window prior to | |
39 * the event. Being a cubic function, there are two components to window | |
40 * growth. The first is a concave portion where the window quickly ramps | |
41 * up to the window size before the last congestion event. Next is the convex | |
42 * growth where CUBIC probes for more bandwidth, slowly at first then very | |
43 * rapidly. CUBIC spends a lot of time at a plateau between the concave | |
44 * and convex growth region which allows the network to stabilize before | |
45 * CUBIC begins looking for more bandwidth. | |
46 * | |
47 * Another major difference between CUBIC and standard TCP flavors is | |
48 * that it does not rely on the receipt of ACKs to increase the | |
49 * window size. CUBIC's window size is dependent only on the last | |
50 * congestion event. With standard TCP, flows with very short RTTs | |
51 * will receive ACKs faster and therefore have their congestion windows | |
52 * grow faster than other flows with longer RTTs. CUBIC allows for more | |
53 * fairness between flows since the window growth is independent of RTT. | |
54 * | |
55 * CUBIC TCP is implemented and used by default in Linux kernels 2.6.19 | |
56 * and above; this version follows the implementation in Linux 3.14, which | |
57 * slightly differ from the CUBIC paper. It also features HyStart. | |
58 * | |
59 * Home page: | |
60 * http://netsrv.csc.ncsu.edu/twiki/bin/view/Main/BIC | |
61 * The work starts from the implementation of CUBIC TCP in | |
62 * Sangtae Ha, Injong Rhee and Lisong Xu, | |
63 * "CUBIC: A New TCP-Friendly High-Speed TCP Variant" | |
64 * in ACM SIGOPS Operating System Review, July 2008. | |
65 * Available from: | |
66 * http://netsrv.csc.ncsu.edu/export/cubic_a_new_tcp_2008.pdf | |
67 * | |
68 * CUBIC integrates a new slow start algorithm, called HyStart. | |
69 * The details of HyStart are presented in | |
70 * Sangtae Ha and Injong Rhee, | |
71 * "Taming the Elephants: New TCP Slow Start", NCSU TechReport 2008. | |
72 * Available from: | |
73 * http://netsrv.csc.ncsu.edu/export/hystart_techreport_2008.pdf | |
74 */ | |
75 class TcpCubic : public TcpSocketBase | |
76 { | |
77 public: | |
78 /** | |
79 * \brief Get the type ID. | |
80 * \return the object TypeId | |
81 */ | |
82 static TypeId GetTypeId (void); | |
83 | |
84 TcpCubic (); | |
85 | |
86 // From TcpSocketBase | |
87 virtual int Connect (const Address &address); | |
88 virtual int Listen (void); | |
89 | |
90 protected: | |
91 // From TcpSocketBase | |
92 virtual uint32_t Window (void); | |
93 virtual Ptr<TcpSocketBase> Fork (void); | |
94 virtual void NewAck (SequenceNumber32 const& seq); | |
95 virtual void DupAck (const TcpHeader& t, uint32_t count); | |
96 virtual void Retransmit (void); | |
97 | |
98 // Implementing ns3::TcpSocket -- Attribute get/set | |
99 virtual void SetInitialSSThresh (uint32_t threshold); | |
100 virtual uint32_t GetInitialSSThresh (void) const; | |
101 virtual void SetInitialCwnd (uint32_t cwnd); | |
102 virtual uint32_t GetInitialCwnd (void) const; | |
103 virtual void ScaleSsThresh (uint8_t scaleFactor); | |
104 | |
105 | |
106 protected: | |
107 /** | |
108 * \brief Values to detect the Slow Start mode of HyStart | |
109 */ | |
110 enum HybridSSDetectionMode | |
111 { | |
112 PACKET_TRAIN = 0x1, //!< Detection by trains of packet | |
113 DELAY = 0x2 //!< Detection by delay value | |
114 }; | |
115 | |
116 /** | |
117 * \brief State of the congestion control machine: open or loss | |
118 */ | |
119 enum CubicState | |
120 { | |
121 OPEN = 0x1, //!< Open state | |
122 LOSS = 0x2, //!< Loss state | |
123 }; | |
Tom Henderson
2015/06/09 18:42:58
(question also applies to BIC) Do you think that C
| |
124 | |
125 bool m_fastConvergence; //!< Enable or disable fast convergence algorithm | |
126 double m_beta; //!< Beta for cubic multiplicative increase | |
127 | |
128 bool m_hystart; //!< Enable or disable HyStart algorithm | |
129 int m_hystartDetect; //!< Detect way for HyStart algorithm \see Hybrid SSDetectionMode | |
130 uint32_t m_hystartLowWindow; //!< Lower bound cWnd for hybrid slow start (segm ents) | |
131 Time m_hystartAckDelta; //!< Spacing between ack's indicating train | |
132 Time m_hystartDelayMin; //!< Minimum time for hystart algorithm | |
133 Time m_hystartDelayMax; //!< Maximum time for hystart algorithm | |
134 uint8_t m_hystartMinSamples;//!< Number of delay samples for detecting the in crease of delay | |
135 | |
136 uint32_t m_initialCwnd; //!< Initial cWnd | |
137 uint8_t m_cntClamp; //!< Modulo of the (avoided) float division for c Wnd | |
138 | |
139 double m_c; //!< Cubic Scaling factor | |
140 | |
141 // Cubic parameters | |
142 CubicState m_cubicState; //!< Cubic state \see CubicState | |
143 uint32_t m_cWndCnt; //!< cWnd integer-to-float counter | |
144 uint32_t m_lastMaxCwnd; //!< Last maximum cWnd | |
145 uint32_t m_bicOriginPoint; //!< Origin point of bic function | |
146 uint32_t m_bicK; //!< Time to origin point from the beginning of the current epoch | |
147 Time m_delayMin; //!< Min delay | |
148 Time m_epochStart; //!< Beginning of an epoch | |
149 uint8_t m_found; //!< The exit point is found? | |
150 Time m_roundStart; //!< Beginning of each round | |
151 SequenceNumber32 m_endSeq; //!< End sequence of the round | |
152 Time m_lastAck; //!< Last time when the ACK spacing is close | |
153 Time m_cubicDelta; //!< Time to wait after recovery before updat e | |
154 Time m_currRtt; //!< Current Rtt | |
155 uint32_t m_sampleCnt; | |
156 | |
157 TracedValue<uint32_t> m_cWnd; //!< Congestion window | |
158 TracedValue<uint32_t> m_ssThresh; //!< Slow start threshold | |
159 | |
160 private: | |
161 /** | |
162 * \brief Reset BIC parameters | |
163 */ | |
164 void Reset (void); | |
165 | |
166 /** | |
167 * \brief Reset HyStart parameters | |
168 */ | |
169 void HystartReset (void); | |
170 | |
171 /** | |
172 * \brief Initialize the algorithm | |
173 */ | |
174 void Init (void); | |
175 | |
176 /** | |
177 * \brief Update HyStart parameters | |
178 * | |
179 * \param delay Delay for HyStart algorithm | |
180 */ | |
181 void HystartUpdate (const Time& delay); | |
Tom Henderson
2015/06/09 18:42:58
for API consistency, pass Time in as value (you do
| |
182 | |
183 /** | |
184 * \brief Clamp time value in a range | |
185 * | |
186 * The returned value is t, clamped in a range specified | |
187 * by attributes (HystartDelayMin < t < HystartDelayMax) | |
188 * | |
189 * \param t Time value to clamp | |
190 * \return t itself if it is in range, otherwise the min or max | |
191 * value | |
192 */ | |
193 Time HystartDelayThresh (Time t) const; | |
194 | |
195 /** | |
196 * \brief Timing calculation about acks | |
197 */ | |
198 void PktsAcked (void); | |
199 | |
200 /** | |
201 * \brief The congestion avoidance phase of Cubic | |
202 * | |
203 * \param seq The sequence number acked | |
204 */ | |
205 void CongAvoid (const SequenceNumber32 &seq); | |
206 | |
207 /** | |
208 * \brief Cubic window update after a new ack received | |
209 */ | |
210 uint32_t WindowUpdate (void); | |
211 | |
212 /** | |
213 * \brief Cubic window update after a loss | |
214 */ | |
215 void RecalcSsthresh (void); | |
216 }; | |
217 | |
218 } | |
219 | |
220 #endif // TCPCUBIC_H | |
OLD | NEW |