1 /*-
2 * Copyright (c) 1982, 1986, 1988, 1990, 1993, 1994, 1995
3 * The Regents of the University of California.
4 * Copyright (c) 2007-2008,2010
5 * Swinburne University of Technology, Melbourne, Australia.
6 * Copyright (c) 2009-2010 Lawrence Stewart <lstewart@freebsd.org>
7 * Copyright (c) 2010 The FreeBSD Foundation
8 * All rights reserved.
9 *
10 * This software was developed at the Centre for Advanced Internet
11 * Architectures, Swinburne University of Technology, by Lawrence Stewart, James
12 * Healy and David Hayes, made possible in part by a grant from the Cisco
13 * University Research Program Fund at Community Foundation Silicon Valley.
14 *
15 * Portions of this software were developed at the Centre for Advanced
16 * Internet Architectures, Swinburne University of Technology, Melbourne,
17 * Australia by David Hayes under sponsorship from the FreeBSD Foundation.
18 *
19 * Redistribution and use in source and binary forms, with or without
20 * modification, are permitted provided that the following conditions
21 * are met:
22 * 1. Redistributions of source code must retain the above copyright
23 * notice, this list of conditions and the following disclaimer.
24 * 2. Redistributions in binary form must reproduce the above copyright
25 * notice, this list of conditions and the following disclaimer in the
26 * documentation and/or other materials provided with the distribution.
27 *
28 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
29 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
30 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
31 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
32 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
33 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
34 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
35 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
36 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
37 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 * SUCH DAMAGE.
39 */
40
41 /*
42 * This software was first released in 2007 by James Healy and Lawrence Stewart
43 * whilst working on the NewTCP research project at Swinburne University of
44 * Technology's Centre for Advanced Internet Architectures, Melbourne,
45 * Australia, which was made possible in part by a grant from the Cisco
46 * University Research Program Fund at Community Foundation Silicon Valley.
47 * More details are available at:
48 * http://caia.swin.edu.au/urp/newtcp/
49 */
50
51 /* samkumar: Removed/replaced a bunch of #include's. */
52
53 #include "../cc.h"
54 #include "../tcp.h"
55 #include "../tcp_seq.h"
56 #include "../tcp_var.h"
57 #include "cc_module.h"
58
59 #include "../tcp_const.h"
60
min(int a,int b)61 static int min(int a, int b) { return (a < b) ? a : b; }
62
63 static void newreno_ack_received(struct cc_var *ccv, uint16_t type);
64 static void newreno_after_idle(struct cc_var *ccv);
65 static void newreno_cong_signal(struct cc_var *ccv, uint32_t type);
66 static void newreno_post_recovery(struct cc_var *ccv);
67
68 const struct cc_algo newreno_cc_algo = {
69 .name = "newreno",
70 .ack_received = newreno_ack_received,
71 .after_idle = newreno_after_idle,
72 .cong_signal = newreno_cong_signal,
73 .post_recovery = newreno_post_recovery,
74 };
75
76 /*
77 * samkumar: Normally, this is done in cc.c. It's commented out since we
78 * just hardcode using New Reno in TCPlp (for now). We don't use FreeBSD's
79 * mechanism to have multiple congestion control modules and choose among
80 * them.
81 */
82 //struct cc_algo* V_default_cc_ptr = &newreno_cc_algo;
83
84 /* samkumar: Constant that is referenced (may want to change this later) */
85 enum {
86 V_tcp_do_rfc3465 = 1
87 };
88
89 static void
newreno_ack_received(struct cc_var * ccv,uint16_t type)90 newreno_ack_received(struct cc_var *ccv, uint16_t type)
91 {
92 if (type == CC_ACK && !IN_RECOVERY(CCV(ccv, t_flags)) &&
93 (ccv->flags & CCF_CWND_LIMITED)) {
94 uint32_t cw = CCV(ccv, snd_cwnd);
95 uint32_t incr = CCV(ccv, t_maxseg);
96
97 /*
98 * Regular in-order ACK, open the congestion window.
99 * Method depends on which congestion control state we're
100 * in (slow start or cong avoid) and if ABC (RFC 3465) is
101 * enabled.
102 *
103 * slow start: cwnd <= ssthresh
104 * cong avoid: cwnd > ssthresh
105 *
106 * slow start and ABC (RFC 3465):
107 * Grow cwnd exponentially by the amount of data
108 * ACKed capping the max increment per ACK to
109 * (abc_l_var * maxseg) bytes.
110 *
111 * slow start without ABC (RFC 5681):
112 * Grow cwnd exponentially by maxseg per ACK.
113 *
114 * cong avoid and ABC (RFC 3465):
115 * Grow cwnd linearly by maxseg per RTT for each
116 * cwnd worth of ACKed data.
117 *
118 * cong avoid without ABC (RFC 5681):
119 * Grow cwnd linearly by approximately maxseg per RTT using
120 * maxseg^2 / cwnd per ACK as the increment.
121 * If cwnd > maxseg^2, fix the cwnd increment at 1 byte to
122 * avoid capping cwnd.
123 */
124 if (cw > CCV(ccv, snd_ssthresh)) {
125 if (V_tcp_do_rfc3465) {
126 if (ccv->flags & CCF_ABC_SENTAWND)
127 ccv->flags &= ~CCF_ABC_SENTAWND;
128 else
129 incr = 0;
130 } else
131 incr = max((incr * incr / cw), 1);
132 } else if (V_tcp_do_rfc3465) {
133 /*
134 * In slow-start with ABC enabled and no RTO in sight?
135 * (Must not use abc_l_var > 1 if slow starting after
136 * an RTO. On RTO, snd_nxt = snd_una, so the
137 * snd_nxt == snd_max check is sufficient to
138 * handle this).
139 *
140 * XXXLAS: Find a way to signal SS after RTO that
141 * doesn't rely on tcpcb vars.
142 */
143 if (CCV(ccv, snd_nxt) == CCV(ccv, snd_max))
144 incr = min(ccv->bytes_this_ack,
145 V_tcp_abc_l_var * CCV(ccv, t_maxseg));
146 else
147 incr = min(ccv->bytes_this_ack, CCV(ccv, t_maxseg));
148 }
149 /* ABC is on by default, so incr equals 0 frequently. */
150 if (incr > 0)
151 CCV(ccv, snd_cwnd) = min(cw + incr,
152 TCP_MAXWIN << CCV(ccv, snd_scale));
153 }
154 }
155
156 static void
newreno_after_idle(struct cc_var * ccv)157 newreno_after_idle(struct cc_var *ccv)
158 {
159 int rw;
160
161 /*
162 * If we've been idle for more than one retransmit timeout the old
163 * congestion window is no longer current and we have to reduce it to
164 * the restart window before we can transmit again.
165 *
166 * The restart window is the initial window or the last CWND, whichever
167 * is smaller.
168 *
169 * This is done to prevent us from flooding the path with a full CWND at
170 * wirespeed, overloading router and switch buffers along the way.
171 *
172 * See RFC5681 Section 4.1. "Restarting Idle Connections".
173 */
174 if (V_tcp_do_rfc3390)
175 rw = min(4 * CCV(ccv, t_maxseg),
176 max(2 * CCV(ccv, t_maxseg), 4380));
177 else
178 rw = CCV(ccv, t_maxseg) * 2;
179
180 CCV(ccv, snd_cwnd) = min(rw, CCV(ccv, snd_cwnd));
181 }
182
183 /*
184 * Perform any necessary tasks before we enter congestion recovery.
185 */
186 static void
newreno_cong_signal(struct cc_var * ccv,uint32_t type)187 newreno_cong_signal(struct cc_var *ccv, uint32_t type)
188 {
189 uint32_t win;
190
191 /* Catch algos which mistakenly leak private signal types. */
192 KASSERT((type & CC_SIGPRIVMASK) == 0,
193 ("%s: congestion signal type 0x%08x is private", __func__, (unsigned int) type));
194
195 win = max(CCV(ccv, snd_cwnd) / 2 / CCV(ccv, t_maxseg), 2) *
196 CCV(ccv, t_maxseg);
197
198 switch (type) {
199 case CC_NDUPACK:
200 if (!IN_FASTRECOVERY(CCV(ccv, t_flags))) {
201 if (!IN_CONGRECOVERY(CCV(ccv, t_flags)))
202 CCV(ccv, snd_ssthresh) = win;
203 ENTER_RECOVERY(CCV(ccv, t_flags));
204 }
205 break;
206 case CC_ECN:
207 if (!IN_CONGRECOVERY(CCV(ccv, t_flags))) {
208 CCV(ccv, snd_ssthresh) = win;
209 CCV(ccv, snd_cwnd) = win;
210 ENTER_CONGRECOVERY(CCV(ccv, t_flags));
211 }
212 break;
213 }
214 }
215
216 /*
217 * Perform any necessary tasks before we exit congestion recovery.
218 */
219 static void
newreno_post_recovery(struct cc_var * ccv)220 newreno_post_recovery(struct cc_var *ccv)
221 {
222 if (IN_FASTRECOVERY(CCV(ccv, t_flags))) {
223 /*
224 * Fast recovery will conclude after returning from this
225 * function. Window inflation should have left us with
226 * approximately snd_ssthresh outstanding data. But in case we
227 * would be inclined to send a burst, better to do it via the
228 * slow start mechanism.
229 *
230 * XXXLAS: Find a way to do this without needing curack
231 */
232 if (SEQ_GT(ccv->curack + CCV(ccv, snd_ssthresh),
233 CCV(ccv, snd_max)))
234 CCV(ccv, snd_cwnd) = CCV(ccv, snd_max) -
235 ccv->curack + CCV(ccv, t_maxseg);
236 else
237 CCV(ccv, snd_cwnd) = CCV(ccv, snd_ssthresh);
238 }
239 }
240
241 /*
242 * samkumar: I commented this out because it's not necessary for TCPlp. See the
243 * comment above about not using FreeBSD's mechanism for having multiple
244 * congestion control modules.
245 */
246 //DECLARE_CC_MODULE(newreno, &newreno_cc_algo);
247