Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1 | /* |
| 2 | * net/dccp/ccids/ccid3.c |
| 3 | * |
| 4 | * Copyright (c) 2005 The University of Waikato, Hamilton, New Zealand. |
Ian McDonald | 1bc0986 | 2005-08-20 00:23:43 -0300 | [diff] [blame] | 5 | * Copyright (c) 2005 Ian McDonald <iam4@cs.waikato.ac.nz> |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 6 | * |
| 7 | * An implementation of the DCCP protocol |
| 8 | * |
| 9 | * This code has been developed by the University of Waikato WAND |
| 10 | * research group. For further information please see http://www.wand.net.nz/ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 11 | * |
| 12 | * This code also uses code from Lulea University, rereleased as GPL by its |
| 13 | * authors: |
| 14 | * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon |
| 15 | * |
| 16 | * Changes to meet Linux coding standards, to make it meet latest ccid3 draft |
| 17 | * and to make it work as a loadable module in the DCCP stack written by |
| 18 | * Arnaldo Carvalho de Melo <acme@conectiva.com.br>. |
| 19 | * |
| 20 | * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br> |
| 21 | * |
| 22 | * This program is free software; you can redistribute it and/or modify |
| 23 | * it under the terms of the GNU General Public License as published by |
| 24 | * the Free Software Foundation; either version 2 of the License, or |
| 25 | * (at your option) any later version. |
| 26 | * |
| 27 | * This program is distributed in the hope that it will be useful, |
| 28 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 29 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 30 | * GNU General Public License for more details. |
| 31 | * |
| 32 | * You should have received a copy of the GNU General Public License |
| 33 | * along with this program; if not, write to the Free Software |
| 34 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
| 35 | */ |
| 36 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 37 | #include <linux/config.h> |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 38 | #include "../ccid.h" |
| 39 | #include "../dccp.h" |
Arnaldo Carvalho de Melo | 4524b25 | 2005-08-27 23:18:26 -0300 | [diff] [blame] | 40 | #include "lib/packet_history.h" |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 41 | #include "lib/loss_interval.h" |
Arnaldo Carvalho de Melo | 36729c1 | 2005-08-28 00:47:15 -0300 | [diff] [blame^] | 42 | #include "lib/tfrc.h" |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 43 | #include "ccid3.h" |
| 44 | |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 45 | /* |
| 46 | * Reason for maths with 10 here is to avoid 32 bit overflow when a is big. |
| 47 | */ |
| 48 | static inline u32 usecs_div(const u32 a, const u32 b) |
| 49 | { |
| 50 | const u32 tmp = a * (USEC_PER_SEC / 10); |
| 51 | return b > 20 ? tmp / (b / 10) : tmp; |
| 52 | } |
| 53 | |
Arnaldo Carvalho de Melo | cfc3c52 | 2005-08-27 20:20:37 -0300 | [diff] [blame] | 54 | static int ccid3_debug; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 55 | |
Arnaldo Carvalho de Melo | cfc3c52 | 2005-08-27 20:20:37 -0300 | [diff] [blame] | 56 | #ifdef CCID3_DEBUG |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 57 | #define ccid3_pr_debug(format, a...) \ |
| 58 | do { if (ccid3_debug) \ |
| 59 | printk(KERN_DEBUG "%s: " format, __FUNCTION__, ##a); \ |
| 60 | } while (0) |
| 61 | #else |
| 62 | #define ccid3_pr_debug(format, a...) |
| 63 | #endif |
| 64 | |
Arnaldo Carvalho de Melo | a1d3a35 | 2005-08-13 22:42:25 -0300 | [diff] [blame] | 65 | static struct dccp_tx_hist *ccid3_tx_hist; |
| 66 | static struct dccp_rx_hist *ccid3_rx_hist; |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 67 | static struct dccp_li_hist *ccid3_li_hist; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 68 | |
| 69 | static int ccid3_init(struct sock *sk) |
| 70 | { |
| 71 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 72 | return 0; |
| 73 | } |
| 74 | |
| 75 | static void ccid3_exit(struct sock *sk) |
| 76 | { |
| 77 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 78 | } |
| 79 | |
| 80 | /* TFRC sender states */ |
| 81 | enum ccid3_hc_tx_states { |
| 82 | TFRC_SSTATE_NO_SENT = 1, |
| 83 | TFRC_SSTATE_NO_FBACK, |
| 84 | TFRC_SSTATE_FBACK, |
| 85 | TFRC_SSTATE_TERM, |
| 86 | }; |
| 87 | |
| 88 | #ifdef CCID3_DEBUG |
| 89 | static const char *ccid3_tx_state_name(enum ccid3_hc_tx_states state) |
| 90 | { |
| 91 | static char *ccid3_state_names[] = { |
| 92 | [TFRC_SSTATE_NO_SENT] = "NO_SENT", |
| 93 | [TFRC_SSTATE_NO_FBACK] = "NO_FBACK", |
| 94 | [TFRC_SSTATE_FBACK] = "FBACK", |
| 95 | [TFRC_SSTATE_TERM] = "TERM", |
| 96 | }; |
| 97 | |
| 98 | return ccid3_state_names[state]; |
| 99 | } |
| 100 | #endif |
| 101 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 102 | static inline void ccid3_hc_tx_set_state(struct sock *sk, |
| 103 | enum ccid3_hc_tx_states state) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 104 | { |
| 105 | struct dccp_sock *dp = dccp_sk(sk); |
| 106 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
| 107 | enum ccid3_hc_tx_states oldstate = hctx->ccid3hctx_state; |
| 108 | |
| 109 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 110 | dccp_role(sk), sk, ccid3_tx_state_name(oldstate), |
| 111 | ccid3_tx_state_name(state)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 112 | WARN_ON(state == oldstate); |
| 113 | hctx->ccid3hctx_state = state; |
| 114 | } |
| 115 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 116 | /* Calculate new t_ipi (inter packet interval) by t_ipi = s / X_inst */ |
| 117 | static inline void ccid3_calc_new_t_ipi(struct ccid3_hc_tx_sock *hctx) |
| 118 | { |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 119 | /* |
| 120 | * If no feedback spec says t_ipi is 1 second (set elsewhere and then |
| 121 | * doubles after every no feedback timer (separate function) |
| 122 | */ |
| 123 | if (hctx->ccid3hctx_state != TFRC_SSTATE_NO_FBACK) |
| 124 | hctx->ccid3hctx_t_ipi = usecs_div(hctx->ccid3hctx_s, |
| 125 | hctx->ccid3hctx_x); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 126 | } |
| 127 | |
| 128 | /* Calculate new delta by delta = min(t_ipi / 2, t_gran / 2) */ |
| 129 | static inline void ccid3_calc_new_delta(struct ccid3_hc_tx_sock *hctx) |
| 130 | { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 131 | hctx->ccid3hctx_delta = min_t(u32, hctx->ccid3hctx_t_ipi / 2, |
| 132 | TFRC_OPSYS_HALF_TIME_GRAN); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 133 | } |
| 134 | |
| 135 | /* |
| 136 | * Update X by |
| 137 | * If (p > 0) |
| 138 | * x_calc = calcX(s, R, p); |
| 139 | * X = max(min(X_calc, 2 * X_recv), s / t_mbi); |
| 140 | * Else |
| 141 | * If (now - tld >= R) |
| 142 | * X = max(min(2 * X, 2 * X_recv), s / R); |
| 143 | * tld = now; |
| 144 | */ |
| 145 | static void ccid3_hc_tx_update_x(struct sock *sk) |
| 146 | { |
| 147 | struct dccp_sock *dp = dccp_sk(sk); |
| 148 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
| 149 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 150 | /* To avoid large error in calcX */ |
| 151 | if (hctx->ccid3hctx_p >= TFRC_SMALLEST_P) { |
Arnaldo Carvalho de Melo | 36729c1 | 2005-08-28 00:47:15 -0300 | [diff] [blame^] | 152 | hctx->ccid3hctx_x_calc = tfrc_calc_x(hctx->ccid3hctx_s, |
| 153 | hctx->ccid3hctx_rtt, |
| 154 | hctx->ccid3hctx_p); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 155 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_calc, |
| 156 | 2 * hctx->ccid3hctx_x_recv), |
| 157 | (hctx->ccid3hctx_s / |
| 158 | TFRC_MAX_BACK_OFF_TIME)); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 159 | } else { |
| 160 | struct timeval now; |
| 161 | |
| 162 | do_gettimeofday(&now); |
| 163 | if (timeval_delta(&now, &hctx->ccid3hctx_t_ld) >= |
| 164 | hctx->ccid3hctx_rtt) { |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 165 | hctx->ccid3hctx_x = max_t(u32, min_t(u32, hctx->ccid3hctx_x_recv, |
| 166 | hctx->ccid3hctx_x) * 2, |
| 167 | usecs_div(hctx->ccid3hctx_s, |
| 168 | hctx->ccid3hctx_rtt)); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 169 | hctx->ccid3hctx_t_ld = now; |
| 170 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 171 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 172 | } |
| 173 | |
| 174 | static void ccid3_hc_tx_no_feedback_timer(unsigned long data) |
| 175 | { |
| 176 | struct sock *sk = (struct sock *)data; |
| 177 | struct dccp_sock *dp = dccp_sk(sk); |
| 178 | unsigned long next_tmout = 0; |
| 179 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 180 | |
| 181 | bh_lock_sock(sk); |
| 182 | if (sock_owned_by_user(sk)) { |
| 183 | /* Try again later. */ |
| 184 | /* XXX: set some sensible MIB */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 185 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
| 186 | jiffies + HZ / 5); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 187 | goto out; |
| 188 | } |
| 189 | |
| 190 | ccid3_pr_debug("%s, sk=%p, state=%s\n", dccp_role(sk), sk, |
| 191 | ccid3_tx_state_name(hctx->ccid3hctx_state)); |
| 192 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 193 | switch (hctx->ccid3hctx_state) { |
| 194 | case TFRC_SSTATE_TERM: |
| 195 | goto out; |
| 196 | case TFRC_SSTATE_NO_FBACK: |
| 197 | /* Halve send rate */ |
| 198 | hctx->ccid3hctx_x /= 2; |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 199 | if (hctx->ccid3hctx_x < (hctx->ccid3hctx_s / |
| 200 | TFRC_MAX_BACK_OFF_TIME)) |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 201 | hctx->ccid3hctx_x = (hctx->ccid3hctx_s / |
| 202 | TFRC_MAX_BACK_OFF_TIME); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 203 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 204 | ccid3_pr_debug("%s, sk=%p, state=%s, updated tx rate to %d " |
| 205 | "bytes/s\n", |
| 206 | dccp_role(sk), sk, |
| 207 | ccid3_tx_state_name(hctx->ccid3hctx_state), |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 208 | hctx->ccid3hctx_x); |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 209 | next_tmout = max_t(u32, 2 * usecs_div(hctx->ccid3hctx_s, |
| 210 | hctx->ccid3hctx_x), |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 211 | TFRC_INITIAL_TIMEOUT); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 212 | /* |
| 213 | * FIXME - not sure above calculation is correct. See section |
| 214 | * 5 of CCID3 11 should adjust tx_t_ipi and double that to |
| 215 | * achieve it really |
| 216 | */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 217 | break; |
| 218 | case TFRC_SSTATE_FBACK: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 219 | /* |
| 220 | * Check if IDLE since last timeout and recv rate is less than |
| 221 | * 4 packets per RTT |
| 222 | */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 223 | if (!hctx->ccid3hctx_idle || |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 224 | (hctx->ccid3hctx_x_recv >= |
| 225 | 4 * usecs_div(hctx->ccid3hctx_s, hctx->ccid3hctx_rtt))) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 226 | ccid3_pr_debug("%s, sk=%p, state=%s, not idle\n", |
| 227 | dccp_role(sk), sk, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 228 | ccid3_tx_state_name(hctx->ccid3hctx_state)); |
| 229 | /* Halve sending rate */ |
| 230 | |
| 231 | /* If (X_calc > 2 * X_recv) |
| 232 | * X_recv = max(X_recv / 2, s / (2 * t_mbi)); |
| 233 | * Else |
| 234 | * X_recv = X_calc / 4; |
| 235 | */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 236 | BUG_ON(hctx->ccid3hctx_p >= TFRC_SMALLEST_P && |
| 237 | hctx->ccid3hctx_x_calc == 0); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 238 | |
| 239 | /* check also if p is zero -> x_calc is infinity? */ |
| 240 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P || |
| 241 | hctx->ccid3hctx_x_calc > 2 * hctx->ccid3hctx_x_recv) |
| 242 | hctx->ccid3hctx_x_recv = max_t(u32, hctx->ccid3hctx_x_recv / 2, |
| 243 | hctx->ccid3hctx_s / (2 * TFRC_MAX_BACK_OFF_TIME)); |
| 244 | else |
| 245 | hctx->ccid3hctx_x_recv = hctx->ccid3hctx_x_calc / 4; |
| 246 | |
| 247 | /* Update sending rate */ |
| 248 | ccid3_hc_tx_update_x(sk); |
| 249 | } |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 250 | /* |
| 251 | * Schedule no feedback timer to expire in |
| 252 | * max(4 * R, 2 * s / X) |
| 253 | */ |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 254 | next_tmout = max_t(u32, hctx->ccid3hctx_t_rto, |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 255 | 2 * usecs_div(hctx->ccid3hctx_s, |
| 256 | hctx->ccid3hctx_x)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 257 | break; |
| 258 | default: |
| 259 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 260 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 261 | dump_stack(); |
| 262 | goto out; |
| 263 | } |
| 264 | |
| 265 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 266 | jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout))); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 267 | hctx->ccid3hctx_idle = 1; |
| 268 | out: |
| 269 | bh_unlock_sock(sk); |
| 270 | sock_put(sk); |
| 271 | } |
| 272 | |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 273 | static int ccid3_hc_tx_send_packet(struct sock *sk, |
| 274 | struct sk_buff *skb, int len) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 275 | { |
| 276 | struct dccp_sock *dp = dccp_sk(sk); |
| 277 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 278 | struct dccp_tx_hist_entry *new_packet; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 279 | struct timeval now; |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 280 | long delay; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 281 | int rc = -ENOTCONN; |
| 282 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 283 | /* Check if pure ACK or Terminating*/ |
| 284 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 285 | /* |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 286 | * XXX: We only call this function for DATA and DATAACK, on, these |
| 287 | * packets can have zero length, but why the comment about "pure ACK"? |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 288 | */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 289 | if (hctx == NULL || len == 0 || |
| 290 | hctx->ccid3hctx_state == TFRC_SSTATE_TERM) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 291 | goto out; |
| 292 | |
| 293 | /* See if last packet allocated was not sent */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 294 | new_packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); |
| 295 | if (new_packet == NULL || new_packet->dccphtx_sent) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 296 | new_packet = dccp_tx_hist_entry_new(ccid3_tx_hist, |
| 297 | SLAB_ATOMIC); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 298 | |
| 299 | rc = -ENOBUFS; |
| 300 | if (new_packet == NULL) { |
| 301 | ccid3_pr_debug("%s, sk=%p, not enough mem to add " |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 302 | "to history, send refused\n", |
| 303 | dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 304 | goto out; |
| 305 | } |
| 306 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 307 | dccp_tx_hist_add_entry(&hctx->ccid3hctx_hist, new_packet); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 308 | } |
| 309 | |
| 310 | do_gettimeofday(&now); |
| 311 | |
| 312 | switch (hctx->ccid3hctx_state) { |
| 313 | case TFRC_SSTATE_NO_SENT: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 314 | ccid3_pr_debug("%s, sk=%p, first packet(%llu)\n", |
| 315 | dccp_role(sk), sk, dp->dccps_gss); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 316 | |
| 317 | hctx->ccid3hctx_no_feedback_timer.function = ccid3_hc_tx_no_feedback_timer; |
| 318 | hctx->ccid3hctx_no_feedback_timer.data = (unsigned long)sk; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 319 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
| 320 | jiffies + usecs_to_jiffies(TFRC_INITIAL_TIMEOUT)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 321 | hctx->ccid3hctx_last_win_count = 0; |
| 322 | hctx->ccid3hctx_t_last_win_count = now; |
| 323 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_NO_FBACK); |
| 324 | hctx->ccid3hctx_t_ipi = TFRC_INITIAL_TIMEOUT; |
| 325 | |
| 326 | /* Set nominal send time for initial packet */ |
| 327 | hctx->ccid3hctx_t_nom = now; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 328 | timeval_add_usecs(&hctx->ccid3hctx_t_nom, |
| 329 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 330 | ccid3_calc_new_delta(hctx); |
| 331 | rc = 0; |
| 332 | break; |
| 333 | case TFRC_SSTATE_NO_FBACK: |
| 334 | case TFRC_SSTATE_FBACK: |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 335 | delay = (timeval_delta(&now, &hctx->ccid3hctx_t_nom) - |
| 336 | hctx->ccid3hctx_delta); |
Arnaldo Carvalho de Melo | 27258ee | 2005-08-09 20:30:56 -0700 | [diff] [blame] | 337 | ccid3_pr_debug("send_packet delay=%ld\n", delay); |
| 338 | delay /= -1000; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 339 | /* divide by -1000 is to convert to ms and get sign right */ |
Arnaldo Carvalho de Melo | d6809c1 | 2005-08-27 03:06:35 -0300 | [diff] [blame] | 340 | rc = delay > 0 ? delay : 0; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 341 | break; |
| 342 | default: |
| 343 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 344 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 345 | dump_stack(); |
| 346 | rc = -EINVAL; |
| 347 | break; |
| 348 | } |
| 349 | |
| 350 | /* Can we send? if so add options and add to packet history */ |
| 351 | if (rc == 0) |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 352 | new_packet->dccphtx_ccval = |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 353 | DCCP_SKB_CB(skb)->dccpd_ccval = |
| 354 | hctx->ccid3hctx_last_win_count; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 355 | out: |
| 356 | return rc; |
| 357 | } |
| 358 | |
| 359 | static void ccid3_hc_tx_packet_sent(struct sock *sk, int more, int len) |
| 360 | { |
| 361 | struct dccp_sock *dp = dccp_sk(sk); |
| 362 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 363 | struct timeval now; |
| 364 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 365 | BUG_ON(hctx == NULL); |
| 366 | |
| 367 | if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) { |
| 368 | ccid3_pr_debug("%s, sk=%p, while state is TFRC_SSTATE_TERM!\n", |
| 369 | dccp_role(sk), sk); |
| 370 | return; |
| 371 | } |
| 372 | |
| 373 | do_gettimeofday(&now); |
| 374 | |
| 375 | /* check if we have sent a data packet */ |
| 376 | if (len > 0) { |
| 377 | unsigned long quarter_rtt; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 378 | struct dccp_tx_hist_entry *packet; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 379 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 380 | packet = dccp_tx_hist_head(&hctx->ccid3hctx_hist); |
| 381 | if (packet == NULL) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 382 | printk(KERN_CRIT "%s: packet doesn't exists in " |
| 383 | "history!\n", __FUNCTION__); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 384 | return; |
| 385 | } |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 386 | if (packet->dccphtx_sent) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 387 | printk(KERN_CRIT "%s: no unsent packet in history!\n", |
| 388 | __FUNCTION__); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 389 | return; |
| 390 | } |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 391 | packet->dccphtx_tstamp = now; |
| 392 | packet->dccphtx_seqno = dp->dccps_gss; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 393 | /* |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 394 | * Check if win_count have changed |
| 395 | * Algorithm in "8.1. Window Counter Valuer" in |
| 396 | * draft-ietf-dccp-ccid3-11.txt |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 397 | */ |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 398 | quarter_rtt = timeval_delta(&now, &hctx->ccid3hctx_t_last_win_count); |
| 399 | if (likely(hctx->ccid3hctx_rtt > 8)) |
| 400 | quarter_rtt /= hctx->ccid3hctx_rtt / 4; |
| 401 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 402 | if (quarter_rtt > 0) { |
| 403 | hctx->ccid3hctx_t_last_win_count = now; |
| 404 | hctx->ccid3hctx_last_win_count = (hctx->ccid3hctx_last_win_count + |
| 405 | min_t(unsigned long, quarter_rtt, 5)) % 16; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 406 | ccid3_pr_debug("%s, sk=%p, window changed from " |
| 407 | "%u to %u!\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 408 | dccp_role(sk), sk, |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 409 | packet->dccphtx_ccval, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 410 | hctx->ccid3hctx_last_win_count); |
| 411 | } |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 412 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 413 | hctx->ccid3hctx_idle = 0; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 414 | packet->dccphtx_rtt = hctx->ccid3hctx_rtt; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 415 | packet->dccphtx_sent = 1; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 416 | } else |
| 417 | ccid3_pr_debug("%s, sk=%p, seqno=%llu NOT inserted!\n", |
| 418 | dccp_role(sk), sk, dp->dccps_gss); |
| 419 | |
| 420 | switch (hctx->ccid3hctx_state) { |
| 421 | case TFRC_SSTATE_NO_SENT: |
| 422 | /* if first wasn't pure ack */ |
| 423 | if (len != 0) |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 424 | printk(KERN_CRIT "%s: %s, First packet sent is noted " |
| 425 | "as a data packet\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 426 | __FUNCTION__, dccp_role(sk)); |
| 427 | return; |
| 428 | case TFRC_SSTATE_NO_FBACK: |
| 429 | case TFRC_SSTATE_FBACK: |
| 430 | if (len > 0) { |
| 431 | hctx->ccid3hctx_t_nom = now; |
| 432 | ccid3_calc_new_t_ipi(hctx); |
| 433 | ccid3_calc_new_delta(hctx); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 434 | timeval_add_usecs(&hctx->ccid3hctx_t_nom, |
| 435 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 436 | } |
| 437 | break; |
| 438 | default: |
| 439 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 440 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 441 | dump_stack(); |
| 442 | break; |
| 443 | } |
| 444 | } |
| 445 | |
| 446 | static void ccid3_hc_tx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 447 | { |
| 448 | struct dccp_sock *dp = dccp_sk(sk); |
| 449 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
| 450 | struct ccid3_options_received *opt_recv; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 451 | struct dccp_tx_hist_entry *packet; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 452 | unsigned long next_tmout; |
Ian McDonald | 1bc0986 | 2005-08-20 00:23:43 -0300 | [diff] [blame] | 453 | u32 t_elapsed; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 454 | u32 pinv; |
| 455 | u32 x_recv; |
| 456 | u32 r_sample; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 457 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 458 | if (hctx == NULL) |
| 459 | return; |
| 460 | |
| 461 | if (hctx->ccid3hctx_state == TFRC_SSTATE_TERM) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 462 | ccid3_pr_debug("%s, sk=%p, received a packet when " |
| 463 | "terminating!\n", dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 464 | return; |
| 465 | } |
| 466 | |
| 467 | /* we are only interested in ACKs */ |
| 468 | if (!(DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK || |
| 469 | DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_DATAACK)) |
| 470 | return; |
| 471 | |
| 472 | opt_recv = &hctx->ccid3hctx_options_received; |
| 473 | |
| 474 | t_elapsed = dp->dccps_options_received.dccpor_elapsed_time; |
| 475 | x_recv = opt_recv->ccid3or_receive_rate; |
| 476 | pinv = opt_recv->ccid3or_loss_event_rate; |
| 477 | |
| 478 | switch (hctx->ccid3hctx_state) { |
| 479 | case TFRC_SSTATE_NO_SENT: |
| 480 | /* FIXME: what to do here? */ |
| 481 | return; |
| 482 | case TFRC_SSTATE_NO_FBACK: |
| 483 | case TFRC_SSTATE_FBACK: |
| 484 | /* Calculate new round trip sample by |
| 485 | * R_sample = (now - t_recvdata) - t_delay */ |
| 486 | /* get t_recvdata from history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 487 | packet = dccp_tx_hist_find_entry(&hctx->ccid3hctx_hist, |
| 488 | DCCP_SKB_CB(skb)->dccpd_ack_seq); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 489 | if (packet == NULL) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 490 | ccid3_pr_debug("%s, sk=%p, seqno %llu(%s) does't " |
| 491 | "exist in history!\n", |
| 492 | dccp_role(sk), sk, |
| 493 | DCCP_SKB_CB(skb)->dccpd_ack_seq, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 494 | dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); |
| 495 | return; |
| 496 | } |
| 497 | |
| 498 | /* Update RTT */ |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 499 | r_sample = timeval_now_delta(&packet->dccphtx_tstamp); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 500 | /* FIXME: */ |
| 501 | // r_sample -= usecs_to_jiffies(t_elapsed * 10); |
| 502 | |
| 503 | /* Update RTT estimate by |
| 504 | * If (No feedback recv) |
| 505 | * R = R_sample; |
| 506 | * Else |
| 507 | * R = q * R + (1 - q) * R_sample; |
| 508 | * |
| 509 | * q is a constant, RFC 3448 recomments 0.9 |
| 510 | */ |
| 511 | if (hctx->ccid3hctx_state == TFRC_SSTATE_NO_FBACK) { |
| 512 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_FBACK); |
| 513 | hctx->ccid3hctx_rtt = r_sample; |
| 514 | } else |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 515 | hctx->ccid3hctx_rtt = (hctx->ccid3hctx_rtt * 9) / 10 + |
| 516 | r_sample / 10; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 517 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 518 | ccid3_pr_debug("%s, sk=%p, New RTT estimate=%uus, " |
| 519 | "r_sample=%us\n", dccp_role(sk), sk, |
| 520 | hctx->ccid3hctx_rtt, r_sample); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 521 | |
| 522 | /* Update timeout interval */ |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 523 | hctx->ccid3hctx_t_rto = max_t(u32, 4 * hctx->ccid3hctx_rtt, |
| 524 | USEC_PER_SEC); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 525 | |
| 526 | /* Update receive rate */ |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 527 | hctx->ccid3hctx_x_recv = x_recv;/* X_recv in bytes per sec */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 528 | |
| 529 | /* Update loss event rate */ |
| 530 | if (pinv == ~0 || pinv == 0) |
| 531 | hctx->ccid3hctx_p = 0; |
| 532 | else { |
| 533 | hctx->ccid3hctx_p = 1000000 / pinv; |
| 534 | |
| 535 | if (hctx->ccid3hctx_p < TFRC_SMALLEST_P) { |
| 536 | hctx->ccid3hctx_p = TFRC_SMALLEST_P; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 537 | ccid3_pr_debug("%s, sk=%p, Smallest p used!\n", |
| 538 | dccp_role(sk), sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 539 | } |
| 540 | } |
| 541 | |
| 542 | /* unschedule no feedback timer */ |
| 543 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); |
| 544 | |
| 545 | /* Update sending rate */ |
| 546 | ccid3_hc_tx_update_x(sk); |
| 547 | |
| 548 | /* Update next send time */ |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 549 | timeval_sub_usecs(&hctx->ccid3hctx_t_nom, |
| 550 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 551 | ccid3_calc_new_t_ipi(hctx); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 552 | timeval_add_usecs(&hctx->ccid3hctx_t_nom, |
| 553 | hctx->ccid3hctx_t_ipi); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 554 | ccid3_calc_new_delta(hctx); |
| 555 | |
| 556 | /* remove all packets older than the one acked from history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 557 | dccp_tx_hist_purge_older(ccid3_tx_hist, |
| 558 | &hctx->ccid3hctx_hist, packet); |
| 559 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 560 | /* |
| 561 | * Schedule no feedback timer to expire in |
| 562 | * max(4 * R, 2 * s / X) |
| 563 | */ |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 564 | next_tmout = max(hctx->ccid3hctx_t_rto, |
Arnaldo Carvalho de Melo | 6b5e633 | 2005-08-27 20:11:28 -0300 | [diff] [blame] | 565 | 2 * usecs_div(hctx->ccid3hctx_s, |
| 566 | hctx->ccid3hctx_x)); |
| 567 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 568 | ccid3_pr_debug("%s, sk=%p, Scheduled no feedback timer to " |
| 569 | "expire in %lu jiffies (%luus)\n", |
| 570 | dccp_role(sk), sk, |
| 571 | usecs_to_jiffies(next_tmout), next_tmout); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 572 | |
| 573 | sk_reset_timer(sk, &hctx->ccid3hctx_no_feedback_timer, |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 574 | jiffies + max_t(u32, 1, usecs_to_jiffies(next_tmout))); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 575 | |
| 576 | /* set idle flag */ |
| 577 | hctx->ccid3hctx_idle = 1; |
| 578 | break; |
| 579 | default: |
| 580 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 581 | __FUNCTION__, dccp_role(sk), sk, hctx->ccid3hctx_state); |
| 582 | dump_stack(); |
| 583 | break; |
| 584 | } |
| 585 | } |
| 586 | |
| 587 | static void ccid3_hc_tx_insert_options(struct sock *sk, struct sk_buff *skb) |
| 588 | { |
| 589 | const struct dccp_sock *dp = dccp_sk(sk); |
| 590 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
| 591 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 592 | if (hctx == NULL || !(sk->sk_state == DCCP_OPEN || |
| 593 | sk->sk_state == DCCP_PARTOPEN)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 594 | return; |
| 595 | |
| 596 | DCCP_SKB_CB(skb)->dccpd_ccval = hctx->ccid3hctx_last_win_count; |
| 597 | } |
| 598 | |
| 599 | static int ccid3_hc_tx_parse_options(struct sock *sk, unsigned char option, |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 600 | unsigned char len, u16 idx, |
| 601 | unsigned char *value) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 602 | { |
| 603 | int rc = 0; |
| 604 | struct dccp_sock *dp = dccp_sk(sk); |
| 605 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
| 606 | struct ccid3_options_received *opt_recv; |
| 607 | |
| 608 | if (hctx == NULL) |
| 609 | return 0; |
| 610 | |
| 611 | opt_recv = &hctx->ccid3hctx_options_received; |
| 612 | |
| 613 | if (opt_recv->ccid3or_seqno != dp->dccps_gsr) { |
| 614 | opt_recv->ccid3or_seqno = dp->dccps_gsr; |
| 615 | opt_recv->ccid3or_loss_event_rate = ~0; |
| 616 | opt_recv->ccid3or_loss_intervals_idx = 0; |
| 617 | opt_recv->ccid3or_loss_intervals_len = 0; |
| 618 | opt_recv->ccid3or_receive_rate = 0; |
| 619 | } |
| 620 | |
| 621 | switch (option) { |
| 622 | case TFRC_OPT_LOSS_EVENT_RATE: |
| 623 | if (len != 4) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 624 | ccid3_pr_debug("%s, sk=%p, invalid len for " |
| 625 | "TFRC_OPT_LOSS_EVENT_RATE\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 626 | dccp_role(sk), sk); |
| 627 | rc = -EINVAL; |
| 628 | } else { |
| 629 | opt_recv->ccid3or_loss_event_rate = ntohl(*(u32 *)value); |
| 630 | ccid3_pr_debug("%s, sk=%p, LOSS_EVENT_RATE=%u\n", |
| 631 | dccp_role(sk), sk, |
| 632 | opt_recv->ccid3or_loss_event_rate); |
| 633 | } |
| 634 | break; |
| 635 | case TFRC_OPT_LOSS_INTERVALS: |
| 636 | opt_recv->ccid3or_loss_intervals_idx = idx; |
| 637 | opt_recv->ccid3or_loss_intervals_len = len; |
| 638 | ccid3_pr_debug("%s, sk=%p, LOSS_INTERVALS=(%u, %u)\n", |
| 639 | dccp_role(sk), sk, |
| 640 | opt_recv->ccid3or_loss_intervals_idx, |
| 641 | opt_recv->ccid3or_loss_intervals_len); |
| 642 | break; |
| 643 | case TFRC_OPT_RECEIVE_RATE: |
| 644 | if (len != 4) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 645 | ccid3_pr_debug("%s, sk=%p, invalid len for " |
| 646 | "TFRC_OPT_RECEIVE_RATE\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 647 | dccp_role(sk), sk); |
| 648 | rc = -EINVAL; |
| 649 | } else { |
| 650 | opt_recv->ccid3or_receive_rate = ntohl(*(u32 *)value); |
| 651 | ccid3_pr_debug("%s, sk=%p, RECEIVE_RATE=%u\n", |
| 652 | dccp_role(sk), sk, |
| 653 | opt_recv->ccid3or_receive_rate); |
| 654 | } |
| 655 | break; |
| 656 | } |
| 657 | |
| 658 | return rc; |
| 659 | } |
| 660 | |
| 661 | static int ccid3_hc_tx_init(struct sock *sk) |
| 662 | { |
| 663 | struct dccp_sock *dp = dccp_sk(sk); |
| 664 | struct ccid3_hc_tx_sock *hctx; |
| 665 | |
| 666 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 667 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 668 | hctx = dp->dccps_hc_tx_ccid_private = kmalloc(sizeof(*hctx), |
| 669 | gfp_any()); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 670 | if (hctx == NULL) |
| 671 | return -ENOMEM; |
| 672 | |
| 673 | memset(hctx, 0, sizeof(*hctx)); |
| 674 | |
| 675 | if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE && |
| 676 | dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE) |
| 677 | hctx->ccid3hctx_s = (u16)dp->dccps_avg_packet_size; |
| 678 | else |
| 679 | hctx->ccid3hctx_s = TFRC_STD_PACKET_SIZE; |
| 680 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 681 | /* Set transmission rate to 1 packet per second */ |
| 682 | hctx->ccid3hctx_x = hctx->ccid3hctx_s; |
Arnaldo Carvalho de Melo | c68e64c | 2005-08-21 05:07:37 -0300 | [diff] [blame] | 683 | hctx->ccid3hctx_t_rto = USEC_PER_SEC; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 684 | hctx->ccid3hctx_state = TFRC_SSTATE_NO_SENT; |
| 685 | INIT_LIST_HEAD(&hctx->ccid3hctx_hist); |
| 686 | init_timer(&hctx->ccid3hctx_no_feedback_timer); |
| 687 | |
| 688 | return 0; |
| 689 | } |
| 690 | |
| 691 | static void ccid3_hc_tx_exit(struct sock *sk) |
| 692 | { |
| 693 | struct dccp_sock *dp = dccp_sk(sk); |
| 694 | struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 695 | |
| 696 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 697 | BUG_ON(hctx == NULL); |
| 698 | |
| 699 | ccid3_hc_tx_set_state(sk, TFRC_SSTATE_TERM); |
| 700 | sk_stop_timer(sk, &hctx->ccid3hctx_no_feedback_timer); |
| 701 | |
| 702 | /* Empty packet history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 703 | dccp_tx_hist_purge(ccid3_tx_hist, &hctx->ccid3hctx_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 704 | |
| 705 | kfree(dp->dccps_hc_tx_ccid_private); |
| 706 | dp->dccps_hc_tx_ccid_private = NULL; |
| 707 | } |
| 708 | |
| 709 | /* |
| 710 | * RX Half Connection methods |
| 711 | */ |
| 712 | |
| 713 | /* TFRC receiver states */ |
| 714 | enum ccid3_hc_rx_states { |
| 715 | TFRC_RSTATE_NO_DATA = 1, |
| 716 | TFRC_RSTATE_DATA, |
| 717 | TFRC_RSTATE_TERM = 127, |
| 718 | }; |
| 719 | |
| 720 | #ifdef CCID3_DEBUG |
| 721 | static const char *ccid3_rx_state_name(enum ccid3_hc_rx_states state) |
| 722 | { |
| 723 | static char *ccid3_rx_state_names[] = { |
| 724 | [TFRC_RSTATE_NO_DATA] = "NO_DATA", |
| 725 | [TFRC_RSTATE_DATA] = "DATA", |
| 726 | [TFRC_RSTATE_TERM] = "TERM", |
| 727 | }; |
| 728 | |
| 729 | return ccid3_rx_state_names[state]; |
| 730 | } |
| 731 | #endif |
| 732 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 733 | static inline void ccid3_hc_rx_set_state(struct sock *sk, |
| 734 | enum ccid3_hc_rx_states state) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 735 | { |
| 736 | struct dccp_sock *dp = dccp_sk(sk); |
| 737 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
| 738 | enum ccid3_hc_rx_states oldstate = hcrx->ccid3hcrx_state; |
| 739 | |
| 740 | ccid3_pr_debug("%s(%p) %-8.8s -> %s\n", |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 741 | dccp_role(sk), sk, ccid3_rx_state_name(oldstate), |
| 742 | ccid3_rx_state_name(state)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 743 | WARN_ON(state == oldstate); |
| 744 | hcrx->ccid3hcrx_state = state; |
| 745 | } |
| 746 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 747 | static int ccid3_hc_rx_add_hist(struct sock *sk, |
| 748 | struct dccp_rx_hist_entry *packet) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 749 | { |
| 750 | struct dccp_sock *dp = dccp_sk(sk); |
| 751 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 752 | struct dccp_rx_hist_entry *entry, *next, *iter; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 753 | u8 num_later = 0; |
| 754 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 755 | iter = dccp_rx_hist_head(&hcrx->ccid3hcrx_hist); |
| 756 | if (iter == NULL) |
| 757 | dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist, packet); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 758 | else { |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 759 | const u64 seqno = packet->dccphrx_seqno; |
| 760 | |
| 761 | if (after48(seqno, iter->dccphrx_seqno)) |
| 762 | dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist, packet); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 763 | else { |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 764 | if (dccp_rx_hist_entry_data_packet(iter)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 765 | num_later = 1; |
| 766 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 767 | list_for_each_entry_continue(iter, |
| 768 | &hcrx->ccid3hcrx_hist, |
| 769 | dccphrx_node) { |
| 770 | if (after48(seqno, iter->dccphrx_seqno)) { |
| 771 | dccp_rx_hist_add_entry(&iter->dccphrx_node, |
| 772 | packet); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 773 | goto trim_history; |
| 774 | } |
| 775 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 776 | if (dccp_rx_hist_entry_data_packet(iter)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 777 | num_later++; |
| 778 | |
| 779 | if (num_later == TFRC_RECV_NUM_LATE_LOSS) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 780 | dccp_rx_hist_entry_delete(ccid3_rx_hist, |
| 781 | packet); |
| 782 | ccid3_pr_debug("%s, sk=%p, packet" |
| 783 | "(%llu) already lost!\n", |
| 784 | dccp_role(sk), sk, |
| 785 | seqno); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 786 | return 1; |
| 787 | } |
| 788 | } |
| 789 | |
| 790 | if (num_later < TFRC_RECV_NUM_LATE_LOSS) |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 791 | dccp_rx_hist_add_entry(&hcrx->ccid3hcrx_hist, |
| 792 | packet); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 793 | /* |
| 794 | * FIXME: else what? should we destroy the packet |
| 795 | * like above? |
| 796 | */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 797 | } |
| 798 | } |
| 799 | |
| 800 | trim_history: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 801 | /* |
| 802 | * Trim history (remove all packets after the NUM_LATE_LOSS + 1 |
| 803 | * data packets) |
| 804 | */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 805 | num_later = TFRC_RECV_NUM_LATE_LOSS + 1; |
| 806 | |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 807 | if (!list_empty(&hcrx->ccid3hcrx_li_hist)) { |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 808 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, |
| 809 | dccphrx_node) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 810 | if (num_later == 0) { |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 811 | list_del_init(&entry->dccphrx_node); |
| 812 | dccp_rx_hist_entry_delete(ccid3_rx_hist, entry); |
| 813 | } else if (dccp_rx_hist_entry_data_packet(entry)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 814 | --num_later; |
| 815 | } |
| 816 | } else { |
| 817 | int step = 0; |
| 818 | u8 win_count = 0; /* Not needed, but lets shut up gcc */ |
| 819 | int tmp; |
| 820 | /* |
| 821 | * We have no loss interval history so we need at least one |
| 822 | * rtt:s of data packets to approximate rtt. |
| 823 | */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 824 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, |
| 825 | dccphrx_node) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 826 | if (num_later == 0) { |
| 827 | switch (step) { |
| 828 | case 0: |
| 829 | step = 1; |
| 830 | /* OK, find next data packet */ |
| 831 | num_later = 1; |
| 832 | break; |
| 833 | case 1: |
| 834 | step = 2; |
| 835 | /* OK, find next data packet */ |
| 836 | num_later = 1; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 837 | win_count = entry->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 838 | break; |
| 839 | case 2: |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 840 | tmp = win_count - entry->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 841 | if (tmp < 0) |
| 842 | tmp += TFRC_WIN_COUNT_LIMIT; |
| 843 | if (tmp > TFRC_WIN_COUNT_PER_RTT + 1) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 844 | /* |
| 845 | * We have found a packet older |
| 846 | * than one rtt remove the rest |
| 847 | */ |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 848 | step = 3; |
| 849 | } else /* OK, find next data packet */ |
| 850 | num_later = 1; |
| 851 | break; |
| 852 | case 3: |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 853 | list_del_init(&entry->dccphrx_node); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 854 | dccp_rx_hist_entry_delete(ccid3_rx_hist, |
| 855 | entry); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 856 | break; |
| 857 | } |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 858 | } else if (dccp_rx_hist_entry_data_packet(entry)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 859 | --num_later; |
| 860 | } |
| 861 | } |
| 862 | |
| 863 | return 0; |
| 864 | } |
| 865 | |
| 866 | static void ccid3_hc_rx_send_feedback(struct sock *sk) |
| 867 | { |
| 868 | struct dccp_sock *dp = dccp_sk(sk); |
| 869 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 870 | struct dccp_rx_hist_entry *packet; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 871 | struct timeval now; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 872 | |
| 873 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 874 | |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 875 | do_gettimeofday(&now); |
| 876 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 877 | switch (hcrx->ccid3hcrx_state) { |
| 878 | case TFRC_RSTATE_NO_DATA: |
| 879 | hcrx->ccid3hcrx_x_recv = 0; |
| 880 | break; |
| 881 | case TFRC_RSTATE_DATA: { |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 882 | const u32 delta = timeval_delta(&now, |
| 883 | &hcrx->ccid3hcrx_tstamp_last_feedback); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 884 | |
Arnaldo Carvalho de Melo | cef07fd | 2005-08-10 13:29:27 -0300 | [diff] [blame] | 885 | hcrx->ccid3hcrx_x_recv = (hcrx->ccid3hcrx_bytes_recv * |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 886 | USEC_PER_SEC); |
| 887 | if (likely(delta > 1)) |
| 888 | hcrx->ccid3hcrx_x_recv /= delta; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 889 | } |
| 890 | break; |
| 891 | default: |
| 892 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 893 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); |
| 894 | dump_stack(); |
| 895 | return; |
| 896 | } |
| 897 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 898 | packet = dccp_rx_hist_find_data_packet(&hcrx->ccid3hcrx_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 899 | if (packet == NULL) { |
| 900 | printk(KERN_CRIT "%s: %s, sk=%p, no data packet in history!\n", |
| 901 | __FUNCTION__, dccp_role(sk), sk); |
| 902 | dump_stack(); |
| 903 | return; |
| 904 | } |
| 905 | |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 906 | hcrx->ccid3hcrx_tstamp_last_feedback = now; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 907 | hcrx->ccid3hcrx_last_counter = packet->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 908 | hcrx->ccid3hcrx_seqno_last_counter = packet->dccphrx_seqno; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 909 | hcrx->ccid3hcrx_bytes_recv = 0; |
| 910 | |
| 911 | /* Convert to multiples of 10us */ |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 912 | hcrx->ccid3hcrx_elapsed_time = |
| 913 | timeval_delta(&now, &packet->dccphrx_tstamp) / 10; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 914 | if (hcrx->ccid3hcrx_p == 0) |
| 915 | hcrx->ccid3hcrx_pinv = ~0; |
| 916 | else |
| 917 | hcrx->ccid3hcrx_pinv = 1000000 / hcrx->ccid3hcrx_p; |
| 918 | dccp_send_ack(sk); |
| 919 | } |
| 920 | |
| 921 | static void ccid3_hc_rx_insert_options(struct sock *sk, struct sk_buff *skb) |
| 922 | { |
| 923 | const struct dccp_sock *dp = dccp_sk(sk); |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 924 | u32 x_recv, pinv; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 925 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
| 926 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 927 | if (hcrx == NULL || !(sk->sk_state == DCCP_OPEN || |
| 928 | sk->sk_state == DCCP_PARTOPEN)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 929 | return; |
| 930 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 931 | DCCP_SKB_CB(skb)->dccpd_ccval = hcrx->ccid3hcrx_last_counter; |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 932 | |
| 933 | if (dccp_packet_without_ack(skb)) |
| 934 | return; |
| 935 | |
| 936 | if (hcrx->ccid3hcrx_elapsed_time != 0) |
| 937 | dccp_insert_option_elapsed_time(sk, skb, |
| 938 | hcrx->ccid3hcrx_elapsed_time); |
| 939 | dccp_insert_option_timestamp(sk, skb); |
| 940 | x_recv = htonl(hcrx->ccid3hcrx_x_recv); |
| 941 | pinv = htonl(hcrx->ccid3hcrx_pinv); |
| 942 | dccp_insert_option(sk, skb, TFRC_OPT_LOSS_EVENT_RATE, |
| 943 | &pinv, sizeof(pinv)); |
| 944 | dccp_insert_option(sk, skb, TFRC_OPT_RECEIVE_RATE, |
| 945 | &x_recv, sizeof(x_recv)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 946 | } |
| 947 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 948 | /* calculate first loss interval |
| 949 | * |
| 950 | * returns estimated loss interval in usecs */ |
| 951 | |
| 952 | static u32 ccid3_hc_rx_calc_first_li(struct sock *sk) |
| 953 | { |
| 954 | struct dccp_sock *dp = dccp_sk(sk); |
| 955 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 956 | struct dccp_rx_hist_entry *entry, *next, *tail = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 957 | u32 rtt, delta, x_recv, fval, p, tmp2; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 958 | struct timeval tstamp = { 0, }; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 959 | int interval = 0; |
| 960 | int win_count = 0; |
| 961 | int step = 0; |
| 962 | u64 tmp1; |
| 963 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 964 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, |
| 965 | dccphrx_node) { |
| 966 | if (dccp_rx_hist_entry_data_packet(entry)) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 967 | tail = entry; |
| 968 | |
| 969 | switch (step) { |
| 970 | case 0: |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 971 | tstamp = entry->dccphrx_tstamp; |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 972 | win_count = entry->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 973 | step = 1; |
| 974 | break; |
| 975 | case 1: |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 976 | interval = win_count - entry->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 977 | if (interval < 0) |
| 978 | interval += TFRC_WIN_COUNT_LIMIT; |
| 979 | if (interval > 4) |
| 980 | goto found; |
| 981 | break; |
| 982 | } |
| 983 | } |
| 984 | } |
| 985 | |
| 986 | if (step == 0) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 987 | printk(KERN_CRIT "%s: %s, sk=%p, packet history contains no " |
| 988 | "data packets!\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 989 | __FUNCTION__, dccp_role(sk), sk); |
| 990 | return ~0; |
| 991 | } |
| 992 | |
| 993 | if (interval == 0) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 994 | ccid3_pr_debug("%s, sk=%p, Could not find a win_count " |
| 995 | "interval > 0. Defaulting to 1\n", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 996 | dccp_role(sk), sk); |
| 997 | interval = 1; |
| 998 | } |
| 999 | found: |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1000 | rtt = timeval_delta(&tstamp, &tail->dccphrx_tstamp) * 4 / interval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1001 | ccid3_pr_debug("%s, sk=%p, approximated RTT to %uus\n", |
| 1002 | dccp_role(sk), sk, rtt); |
| 1003 | if (rtt == 0) |
| 1004 | rtt = 1; |
| 1005 | |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1006 | delta = timeval_now_delta(&hcrx->ccid3hcrx_tstamp_last_feedback); |
| 1007 | x_recv = hcrx->ccid3hcrx_bytes_recv * USEC_PER_SEC; |
| 1008 | if (likely(delta > 1)) |
| 1009 | x_recv /= delta; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1010 | |
| 1011 | tmp1 = (u64)x_recv * (u64)rtt; |
| 1012 | do_div(tmp1,10000000); |
| 1013 | tmp2 = (u32)tmp1; |
| 1014 | fval = (hcrx->ccid3hcrx_s * 100000) / tmp2; |
| 1015 | /* do not alter order above or you will get overflow on 32 bit */ |
Arnaldo Carvalho de Melo | 36729c1 | 2005-08-28 00:47:15 -0300 | [diff] [blame^] | 1016 | p = tfrc_calc_x_reverse_lookup(fval); |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1017 | ccid3_pr_debug("%s, sk=%p, receive rate=%u bytes/s, implied " |
| 1018 | "loss rate=%u\n", dccp_role(sk), sk, x_recv, p); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1019 | |
| 1020 | if (p == 0) |
| 1021 | return ~0; |
| 1022 | else |
| 1023 | return 1000000 / p; |
| 1024 | } |
| 1025 | |
| 1026 | static void ccid3_hc_rx_update_li(struct sock *sk, u64 seq_loss, u8 win_loss) |
| 1027 | { |
| 1028 | struct dccp_sock *dp = dccp_sk(sk); |
| 1029 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1030 | |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1031 | if (seq_loss != DCCP_MAX_SEQNO + 1 && |
| 1032 | list_empty(&hcrx->ccid3hcrx_li_hist)) { |
| 1033 | struct dccp_li_hist_entry *li_tail; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1034 | |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1035 | li_tail = dccp_li_hist_interval_new(ccid3_li_hist, |
| 1036 | &hcrx->ccid3hcrx_li_hist, |
| 1037 | seq_loss, win_loss); |
| 1038 | if (li_tail == NULL) |
| 1039 | return; |
| 1040 | li_tail->dccplih_interval = ccid3_hc_rx_calc_first_li(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1041 | } |
| 1042 | /* FIXME: find end of interval */ |
| 1043 | } |
| 1044 | |
| 1045 | static void ccid3_hc_rx_detect_loss(struct sock *sk) |
| 1046 | { |
| 1047 | struct dccp_sock *dp = dccp_sk(sk); |
| 1048 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1049 | struct dccp_rx_hist_entry *entry, *next, *packet; |
| 1050 | struct dccp_rx_hist_entry *a_loss = NULL; |
| 1051 | struct dccp_rx_hist_entry *b_loss = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1052 | u64 seq_loss = DCCP_MAX_SEQNO + 1; |
| 1053 | u8 win_loss = 0; |
| 1054 | u8 num_later = TFRC_RECV_NUM_LATE_LOSS; |
| 1055 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1056 | list_for_each_entry_safe(entry, next, &hcrx->ccid3hcrx_hist, |
| 1057 | dccphrx_node) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1058 | if (num_later == 0) { |
| 1059 | b_loss = entry; |
| 1060 | break; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1061 | } else if (dccp_rx_hist_entry_data_packet(entry)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1062 | --num_later; |
| 1063 | } |
| 1064 | |
| 1065 | if (b_loss == NULL) |
| 1066 | goto out_update_li; |
| 1067 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1068 | num_later = 1; |
Arnaldo Carvalho de Melo | 757f612 | 2005-08-09 20:16:04 -0700 | [diff] [blame] | 1069 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1070 | list_for_each_entry_safe_continue(entry, next, &hcrx->ccid3hcrx_hist, |
| 1071 | dccphrx_node) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1072 | if (num_later == 0) { |
| 1073 | a_loss = entry; |
| 1074 | break; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1075 | } else if (dccp_rx_hist_entry_data_packet(entry)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1076 | --num_later; |
| 1077 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1078 | |
| 1079 | if (a_loss == NULL) { |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1080 | if (list_empty(&hcrx->ccid3hcrx_li_hist)) { |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1081 | /* no loss event have occured yet */ |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1082 | LIMIT_NETDEBUG("%s: TODO: find a lost data packet by " |
| 1083 | "comparing to initial seqno\n", |
| 1084 | dccp_role(sk)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1085 | goto out_update_li; |
| 1086 | } else { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1087 | pr_info("%s: %s, sk=%p, ERROR! Less than 4 data " |
| 1088 | "packets in history", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1089 | __FUNCTION__, dccp_role(sk), sk); |
| 1090 | return; |
| 1091 | } |
| 1092 | } |
| 1093 | |
| 1094 | /* Locate a lost data packet */ |
| 1095 | entry = packet = b_loss; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1096 | list_for_each_entry_safe_continue(entry, next, &hcrx->ccid3hcrx_hist, |
| 1097 | dccphrx_node) { |
| 1098 | u64 delta = dccp_delta_seqno(entry->dccphrx_seqno, |
| 1099 | packet->dccphrx_seqno); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1100 | |
| 1101 | if (delta != 0) { |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1102 | if (dccp_rx_hist_entry_data_packet(packet)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1103 | --delta; |
| 1104 | /* |
| 1105 | * FIXME: check this, probably this % usage is because |
| 1106 | * in earlier drafts the ndp count was just 8 bits |
| 1107 | * long, but now it cam be up to 24 bits long. |
| 1108 | */ |
| 1109 | #if 0 |
| 1110 | if (delta % DCCP_NDP_LIMIT != |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1111 | (packet->dccphrx_ndp - |
| 1112 | entry->dccphrx_ndp) % DCCP_NDP_LIMIT) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1113 | #endif |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1114 | if (delta != |
| 1115 | packet->dccphrx_ndp - entry->dccphrx_ndp) { |
| 1116 | seq_loss = entry->dccphrx_seqno; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1117 | dccp_inc_seqno(&seq_loss); |
| 1118 | } |
| 1119 | } |
| 1120 | packet = entry; |
| 1121 | if (packet == a_loss) |
| 1122 | break; |
| 1123 | } |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1124 | |
| 1125 | if (seq_loss != DCCP_MAX_SEQNO + 1) |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 1126 | win_loss = a_loss->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1127 | |
| 1128 | out_update_li: |
| 1129 | ccid3_hc_rx_update_li(sk, seq_loss, win_loss); |
| 1130 | } |
| 1131 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1132 | static void ccid3_hc_rx_packet_recv(struct sock *sk, struct sk_buff *skb) |
| 1133 | { |
| 1134 | struct dccp_sock *dp = dccp_sk(sk); |
| 1135 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1136 | const struct dccp_options_received *opt_recv; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1137 | struct dccp_rx_hist_entry *packet; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1138 | struct timeval now; |
| 1139 | u8 win_count; |
| 1140 | u32 p_prev; |
| 1141 | int ins; |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1142 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1143 | if (hcrx == NULL) |
| 1144 | return; |
| 1145 | |
| 1146 | BUG_ON(!(hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA || |
| 1147 | hcrx->ccid3hcrx_state == TFRC_RSTATE_DATA)); |
| 1148 | |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1149 | opt_recv = &dp->dccps_options_received; |
| 1150 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1151 | switch (DCCP_SKB_CB(skb)->dccpd_type) { |
| 1152 | case DCCP_PKT_ACK: |
| 1153 | if (hcrx->ccid3hcrx_state == TFRC_RSTATE_NO_DATA) |
| 1154 | return; |
| 1155 | case DCCP_PKT_DATAACK: |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1156 | if (opt_recv->dccpor_timestamp_echo == 0) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1157 | break; |
| 1158 | p_prev = hcrx->ccid3hcrx_rtt; |
| 1159 | do_gettimeofday(&now); |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1160 | hcrx->ccid3hcrx_rtt = timeval_usecs(&now) - |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1161 | (opt_recv->dccpor_timestamp_echo - |
| 1162 | opt_recv->dccpor_elapsed_time) * 10; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1163 | if (p_prev != hcrx->ccid3hcrx_rtt) |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1164 | ccid3_pr_debug("%s, New RTT=%luus, elapsed time=%u\n", |
| 1165 | dccp_role(sk), hcrx->ccid3hcrx_rtt, |
| 1166 | opt_recv->dccpor_elapsed_time); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1167 | break; |
| 1168 | case DCCP_PKT_DATA: |
| 1169 | break; |
| 1170 | default: |
| 1171 | ccid3_pr_debug("%s, sk=%p, not DATA/DATAACK/ACK packet(%s)\n", |
| 1172 | dccp_role(sk), sk, |
| 1173 | dccp_packet_name(DCCP_SKB_CB(skb)->dccpd_type)); |
| 1174 | return; |
| 1175 | } |
| 1176 | |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1177 | packet = dccp_rx_hist_entry_new(ccid3_rx_hist, opt_recv->dccpor_ndp, |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1178 | skb, SLAB_ATOMIC); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1179 | if (packet == NULL) { |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1180 | ccid3_pr_debug("%s, sk=%p, Not enough mem to add rx packet " |
| 1181 | "to history (consider it lost)!", |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1182 | dccp_role(sk), sk); |
| 1183 | return; |
| 1184 | } |
| 1185 | |
Arnaldo Carvalho de Melo | c173437 | 2005-08-13 20:34:23 -0300 | [diff] [blame] | 1186 | win_count = packet->dccphrx_ccval; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1187 | |
| 1188 | ins = ccid3_hc_rx_add_hist(sk, packet); |
| 1189 | |
| 1190 | if (DCCP_SKB_CB(skb)->dccpd_type == DCCP_PKT_ACK) |
| 1191 | return; |
| 1192 | |
| 1193 | switch (hcrx->ccid3hcrx_state) { |
| 1194 | case TFRC_RSTATE_NO_DATA: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1195 | ccid3_pr_debug("%s, sk=%p(%s), skb=%p, sending initial " |
| 1196 | "feedback\n", |
| 1197 | dccp_role(sk), sk, |
| 1198 | dccp_state_name(sk->sk_state), skb); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1199 | ccid3_hc_rx_send_feedback(sk); |
| 1200 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_DATA); |
| 1201 | return; |
| 1202 | case TFRC_RSTATE_DATA: |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1203 | hcrx->ccid3hcrx_bytes_recv += skb->len - |
| 1204 | dccp_hdr(skb)->dccph_doff * 4; |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1205 | if (ins != 0) |
| 1206 | break; |
| 1207 | |
| 1208 | do_gettimeofday(&now); |
| 1209 | if (timeval_delta(&now, &hcrx->ccid3hcrx_tstamp_last_ack) >= |
| 1210 | hcrx->ccid3hcrx_rtt) { |
| 1211 | hcrx->ccid3hcrx_tstamp_last_ack = now; |
| 1212 | ccid3_hc_rx_send_feedback(sk); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1213 | } |
Arnaldo Carvalho de Melo | b6ee3d4 | 2005-08-27 18:18:18 -0300 | [diff] [blame] | 1214 | return; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1215 | default: |
| 1216 | printk(KERN_CRIT "%s: %s, sk=%p, Illegal state (%d)!\n", |
| 1217 | __FUNCTION__, dccp_role(sk), sk, hcrx->ccid3hcrx_state); |
| 1218 | dump_stack(); |
| 1219 | return; |
| 1220 | } |
| 1221 | |
| 1222 | /* Dealing with packet loss */ |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1223 | ccid3_pr_debug("%s, sk=%p(%s), data loss! Reacting...\n", |
| 1224 | dccp_role(sk), sk, dccp_state_name(sk->sk_state)); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1225 | |
| 1226 | ccid3_hc_rx_detect_loss(sk); |
| 1227 | p_prev = hcrx->ccid3hcrx_p; |
| 1228 | |
| 1229 | /* Calculate loss event rate */ |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1230 | if (!list_empty(&hcrx->ccid3hcrx_li_hist)) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1231 | /* Scaling up by 1000000 as fixed decimal */ |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1232 | hcrx->ccid3hcrx_p = 1000000 / dccp_li_hist_calc_i_mean(&hcrx->ccid3hcrx_li_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1233 | |
| 1234 | if (hcrx->ccid3hcrx_p > p_prev) { |
| 1235 | ccid3_hc_rx_send_feedback(sk); |
| 1236 | return; |
| 1237 | } |
| 1238 | } |
| 1239 | |
| 1240 | static int ccid3_hc_rx_init(struct sock *sk) |
| 1241 | { |
| 1242 | struct dccp_sock *dp = dccp_sk(sk); |
| 1243 | struct ccid3_hc_rx_sock *hcrx; |
| 1244 | |
| 1245 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 1246 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1247 | hcrx = dp->dccps_hc_rx_ccid_private = kmalloc(sizeof(*hcrx), |
| 1248 | gfp_any()); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1249 | if (hcrx == NULL) |
| 1250 | return -ENOMEM; |
| 1251 | |
| 1252 | memset(hcrx, 0, sizeof(*hcrx)); |
| 1253 | |
| 1254 | if (dp->dccps_avg_packet_size >= TFRC_MIN_PACKET_SIZE && |
| 1255 | dp->dccps_avg_packet_size <= TFRC_MAX_PACKET_SIZE) |
| 1256 | hcrx->ccid3hcrx_s = (u16)dp->dccps_avg_packet_size; |
| 1257 | else |
| 1258 | hcrx->ccid3hcrx_s = TFRC_STD_PACKET_SIZE; |
| 1259 | |
| 1260 | hcrx->ccid3hcrx_state = TFRC_RSTATE_NO_DATA; |
| 1261 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_hist); |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1262 | INIT_LIST_HEAD(&hcrx->ccid3hcrx_li_hist); |
Arnaldo Carvalho de Melo | 4fded33 | 2005-08-23 21:51:59 -0700 | [diff] [blame] | 1263 | /* |
| 1264 | * XXX this seems to be paranoid, need to think more about this, for |
| 1265 | * now start with something different than zero. -acme |
| 1266 | */ |
| 1267 | hcrx->ccid3hcrx_rtt = USEC_PER_SEC / 5; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1268 | return 0; |
| 1269 | } |
| 1270 | |
| 1271 | static void ccid3_hc_rx_exit(struct sock *sk) |
| 1272 | { |
| 1273 | struct dccp_sock *dp = dccp_sk(sk); |
| 1274 | struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
| 1275 | |
| 1276 | ccid3_pr_debug("%s, sk=%p\n", dccp_role(sk), sk); |
| 1277 | |
| 1278 | if (hcrx == NULL) |
| 1279 | return; |
| 1280 | |
| 1281 | ccid3_hc_rx_set_state(sk, TFRC_RSTATE_TERM); |
| 1282 | |
| 1283 | /* Empty packet history */ |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1284 | dccp_rx_hist_purge(ccid3_rx_hist, &hcrx->ccid3hcrx_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1285 | |
| 1286 | /* Empty loss interval history */ |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1287 | dccp_li_hist_purge(ccid3_li_hist, &hcrx->ccid3hcrx_li_hist); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1288 | |
| 1289 | kfree(dp->dccps_hc_rx_ccid_private); |
| 1290 | dp->dccps_hc_rx_ccid_private = NULL; |
| 1291 | } |
| 1292 | |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1293 | static void ccid3_hc_rx_get_info(struct sock *sk, struct tcp_info *info) |
| 1294 | { |
| 1295 | const struct dccp_sock *dp = dccp_sk(sk); |
| 1296 | const struct ccid3_hc_rx_sock *hcrx = dp->dccps_hc_rx_ccid_private; |
| 1297 | |
| 1298 | if (hcrx == NULL) |
| 1299 | return; |
| 1300 | |
| 1301 | info->tcpi_ca_state = hcrx->ccid3hcrx_state; |
| 1302 | info->tcpi_options |= TCPI_OPT_TIMESTAMPS; |
| 1303 | info->tcpi_rcv_rtt = hcrx->ccid3hcrx_rtt; |
| 1304 | } |
| 1305 | |
| 1306 | static void ccid3_hc_tx_get_info(struct sock *sk, struct tcp_info *info) |
| 1307 | { |
| 1308 | const struct dccp_sock *dp = dccp_sk(sk); |
| 1309 | const struct ccid3_hc_tx_sock *hctx = dp->dccps_hc_tx_ccid_private; |
| 1310 | |
| 1311 | if (hctx == NULL) |
| 1312 | return; |
| 1313 | |
| 1314 | info->tcpi_rto = hctx->ccid3hctx_t_rto; |
| 1315 | info->tcpi_rtt = hctx->ccid3hctx_rtt; |
| 1316 | } |
| 1317 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1318 | static struct ccid ccid3 = { |
| 1319 | .ccid_id = 3, |
| 1320 | .ccid_name = "ccid3", |
| 1321 | .ccid_owner = THIS_MODULE, |
| 1322 | .ccid_init = ccid3_init, |
| 1323 | .ccid_exit = ccid3_exit, |
| 1324 | .ccid_hc_tx_init = ccid3_hc_tx_init, |
| 1325 | .ccid_hc_tx_exit = ccid3_hc_tx_exit, |
| 1326 | .ccid_hc_tx_send_packet = ccid3_hc_tx_send_packet, |
| 1327 | .ccid_hc_tx_packet_sent = ccid3_hc_tx_packet_sent, |
| 1328 | .ccid_hc_tx_packet_recv = ccid3_hc_tx_packet_recv, |
| 1329 | .ccid_hc_tx_insert_options = ccid3_hc_tx_insert_options, |
| 1330 | .ccid_hc_tx_parse_options = ccid3_hc_tx_parse_options, |
| 1331 | .ccid_hc_rx_init = ccid3_hc_rx_init, |
| 1332 | .ccid_hc_rx_exit = ccid3_hc_rx_exit, |
| 1333 | .ccid_hc_rx_insert_options = ccid3_hc_rx_insert_options, |
| 1334 | .ccid_hc_rx_packet_recv = ccid3_hc_rx_packet_recv, |
Arnaldo Carvalho de Melo | 2babe1f | 2005-08-23 21:52:35 -0700 | [diff] [blame] | 1335 | .ccid_hc_rx_get_info = ccid3_hc_rx_get_info, |
| 1336 | .ccid_hc_tx_get_info = ccid3_hc_tx_get_info, |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1337 | }; |
| 1338 | |
| 1339 | module_param(ccid3_debug, int, 0444); |
| 1340 | MODULE_PARM_DESC(ccid3_debug, "Enable debug messages"); |
| 1341 | |
| 1342 | static __init int ccid3_module_init(void) |
| 1343 | { |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1344 | int rc = -ENOBUFS; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1345 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1346 | ccid3_rx_hist = dccp_rx_hist_new("ccid3"); |
| 1347 | if (ccid3_rx_hist == NULL) |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1348 | goto out; |
| 1349 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1350 | ccid3_tx_hist = dccp_tx_hist_new("ccid3"); |
| 1351 | if (ccid3_tx_hist == NULL) |
| 1352 | goto out_free_rx; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1353 | |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1354 | ccid3_li_hist = dccp_li_hist_new("ccid3"); |
| 1355 | if (ccid3_li_hist == NULL) |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1356 | goto out_free_tx; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1357 | |
| 1358 | rc = ccid_register(&ccid3); |
| 1359 | if (rc != 0) |
| 1360 | goto out_free_loss_interval_history; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1361 | out: |
| 1362 | return rc; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1363 | |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1364 | out_free_loss_interval_history: |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1365 | dccp_li_hist_delete(ccid3_li_hist); |
| 1366 | ccid3_li_hist = NULL; |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1367 | out_free_tx: |
| 1368 | dccp_tx_hist_delete(ccid3_tx_hist); |
| 1369 | ccid3_tx_hist = NULL; |
| 1370 | out_free_rx: |
| 1371 | dccp_rx_hist_delete(ccid3_rx_hist); |
| 1372 | ccid3_rx_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1373 | goto out; |
| 1374 | } |
| 1375 | module_init(ccid3_module_init); |
| 1376 | |
| 1377 | static __exit void ccid3_module_exit(void) |
| 1378 | { |
Arnaldo Carvalho de Melo | 725ba8e | 2005-08-13 20:35:39 -0300 | [diff] [blame] | 1379 | #ifdef CONFIG_IP_DCCP_UNLOAD_HACK |
| 1380 | /* |
| 1381 | * Hack to use while developing, so that we get rid of the control |
| 1382 | * sock, that is what keeps a refcount on dccp.ko -acme |
| 1383 | */ |
| 1384 | extern void dccp_ctl_sock_exit(void); |
| 1385 | |
| 1386 | dccp_ctl_sock_exit(); |
| 1387 | #endif |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1388 | ccid_unregister(&ccid3); |
| 1389 | |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1390 | if (ccid3_tx_hist != NULL) { |
| 1391 | dccp_tx_hist_delete(ccid3_tx_hist); |
| 1392 | ccid3_tx_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1393 | } |
Arnaldo Carvalho de Melo | 8c60f3f | 2005-08-10 12:59:38 -0300 | [diff] [blame] | 1394 | if (ccid3_rx_hist != NULL) { |
| 1395 | dccp_rx_hist_delete(ccid3_rx_hist); |
| 1396 | ccid3_rx_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1397 | } |
Arnaldo Carvalho de Melo | ae6706f | 2005-08-27 23:03:09 -0300 | [diff] [blame] | 1398 | if (ccid3_li_hist != NULL) { |
| 1399 | dccp_li_hist_delete(ccid3_li_hist); |
| 1400 | ccid3_li_hist = NULL; |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1401 | } |
| 1402 | } |
| 1403 | module_exit(ccid3_module_exit); |
| 1404 | |
Arnaldo Carvalho de Melo | 1f2333a | 2005-08-27 03:51:58 -0300 | [diff] [blame] | 1405 | MODULE_AUTHOR("Ian McDonald <iam4@cs.waikato.ac.nz>, " |
| 1406 | "Arnaldo Carvalho de Melo <acme@ghostprotocols.net>"); |
Arnaldo Carvalho de Melo | 7c65787 | 2005-08-09 20:14:34 -0700 | [diff] [blame] | 1407 | MODULE_DESCRIPTION("DCCP TFRC CCID3 CCID"); |
| 1408 | MODULE_LICENSE("GPL"); |
| 1409 | MODULE_ALIAS("net-dccp-ccid-3"); |