blob: 7df6c52999999a4c76c99802d0dbcf54a8654211 [file] [log] [blame]
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -03001/*
Arnaldo Carvalho de Melo276f2ed2007-11-28 11:15:40 -02002 * Packet RX/TX history data structures and routines for TFRC-based protocols.
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -03003 *
Arnaldo Carvalho de Melo276f2ed2007-11-28 11:15:40 -02004 * Copyright (c) 2007 The University of Aberdeen, Scotland, UK
Ian McDonalde6bccd32006-08-26 19:01:30 -07005 * Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -03006 *
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -03007 * This code has been developed by the University of Waikato WAND
8 * research group. For further information please see http://www.wand.net.nz/
Ian McDonalde6bccd32006-08-26 19:01:30 -07009 * or e-mail Ian McDonald - ian.mcdonald@jandi.co.nz
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -030010 *
11 * This code also uses code from Lulea University, rereleased as GPL by its
12 * authors:
13 * Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
14 *
15 * Changes to meet Linux coding standards, to make it meet latest ccid3 draft
16 * and to make it work as a loadable module in the DCCP stack written by
17 * Arnaldo Carvalho de Melo <acme@conectiva.com.br>.
18 *
19 * Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
20 *
21 * This program is free software; you can redistribute it and/or modify
22 * it under the terms of the GNU General Public License as published by
23 * the Free Software Foundation; either version 2 of the License, or
24 * (at your option) any later version.
25 *
26 * This program is distributed in the hope that it will be useful,
27 * but WITHOUT ANY WARRANTY; without even the implied warranty of
28 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
29 * GNU General Public License for more details.
30 *
31 * You should have received a copy of the GNU General Public License
32 * along with this program; if not, write to the Free Software
33 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
34 */
35
36#ifndef _DCCP_PKT_HIST_
37#define _DCCP_PKT_HIST_
38
Gerrit Renker8a9c7e92007-12-12 13:50:51 -020039#include <linux/list.h>
40#include <linux/slab.h>
41#include "tfrc.h"
Arnaldo Carvalho de Melo072ab6c2005-08-28 01:19:14 -030042
Arnaldo Carvalho de Melo9108d5f2007-11-29 22:47:15 -020043struct tfrc_tx_hist_entry;
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -030044
Arnaldo Carvalho de Melo276f2ed2007-11-28 11:15:40 -020045extern int tfrc_tx_hist_add(struct tfrc_tx_hist_entry **headp, u64 seqno);
46extern void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp);
Arnaldo Carvalho de Melo9108d5f2007-11-29 22:47:15 -020047extern u32 tfrc_tx_hist_rtt(struct tfrc_tx_hist_entry *head,
48 const u64 seqno, const ktime_t now);
Gerrit Renker85dcb1f2006-12-10 00:24:11 -020049
Arnaldo Carvalho de Melob84a2182007-12-06 13:18:11 -020050/* Subtraction a-b modulo-16, respects circular wrap-around */
51#define SUB16(a, b) (((a) + 16 - (b)) & 0xF)
52
53/* Number of packets to wait after a missing packet (RFC 4342, 6.1) */
54#define TFRC_NDUPACK 3
55
56/**
57 * tfrc_rx_hist_entry - Store information about a single received packet
58 * @tfrchrx_seqno: DCCP packet sequence number
59 * @tfrchrx_ccval: window counter value of packet (RFC 4342, 8.1)
60 * @tfrchrx_ndp: the NDP count (if any) of the packet
61 * @tfrchrx_tstamp: actual receive time of packet
Gerrit Renker85dcb1f2006-12-10 00:24:11 -020062 */
Arnaldo Carvalho de Melod58d1af2007-12-06 12:28:39 -020063struct tfrc_rx_hist_entry {
Arnaldo Carvalho de Melod58d1af2007-12-06 12:28:39 -020064 u64 tfrchrx_seqno:48,
65 tfrchrx_ccval:4,
66 tfrchrx_type:4;
Gerrit Renker5b5d0e72008-07-13 11:51:40 +010067 u64 tfrchrx_ndp:48;
Arnaldo Carvalho de Melod58d1af2007-12-06 12:28:39 -020068 ktime_t tfrchrx_tstamp;
Gerrit Renker85dcb1f2006-12-10 00:24:11 -020069};
70
Arnaldo Carvalho de Melob84a2182007-12-06 13:18:11 -020071/**
72 * tfrc_rx_hist - RX history structure for TFRC-based protocols
Arnaldo Carvalho de Melob84a2182007-12-06 13:18:11 -020073 * @ring: Packet history for RTT sampling and loss detection
74 * @loss_count: Number of entries in circular history
75 * @loss_start: Movable index (for loss detection)
76 * @rtt_sample_prev: Used during RTT sampling, points to candidate entry
77 */
78struct tfrc_rx_hist {
79 struct tfrc_rx_hist_entry *ring[TFRC_NDUPACK + 1];
80 u8 loss_count:2,
81 loss_start:2;
82#define rtt_sample_prev loss_start
83};
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -030084
Gerrit Renker8995a232007-12-12 12:28:40 -020085/**
86 * tfrc_rx_hist_index - index to reach n-th entry after loss_start
87 */
88static inline u8 tfrc_rx_hist_index(const struct tfrc_rx_hist *h, const u8 n)
89{
90 return (h->loss_start + n) & TFRC_NDUPACK;
91}
92
93/**
94 * tfrc_rx_hist_last_rcv - entry with highest-received-seqno so far
95 */
96static inline struct tfrc_rx_hist_entry *
97 tfrc_rx_hist_last_rcv(const struct tfrc_rx_hist *h)
98{
99 return h->ring[tfrc_rx_hist_index(h, h->loss_count)];
100}
101
102/**
103 * tfrc_rx_hist_entry - return the n-th history entry after loss_start
104 */
105static inline struct tfrc_rx_hist_entry *
106 tfrc_rx_hist_entry(const struct tfrc_rx_hist *h, const u8 n)
107{
108 return h->ring[tfrc_rx_hist_index(h, n)];
109}
110
111/**
112 * tfrc_rx_hist_loss_prev - entry with highest-received-seqno before loss was detected
113 */
114static inline struct tfrc_rx_hist_entry *
115 tfrc_rx_hist_loss_prev(const struct tfrc_rx_hist *h)
116{
117 return h->ring[h->loss_start];
118}
119
Gerrit Renkerde0d4112007-12-12 14:03:01 -0200120/* indicate whether previously a packet was detected missing */
Gerrit Renkerb552c622008-07-13 11:51:40 +0100121static inline bool tfrc_rx_hist_loss_pending(const struct tfrc_rx_hist *h)
Gerrit Renkerde0d4112007-12-12 14:03:01 -0200122{
Gerrit Renkerb552c622008-07-13 11:51:40 +0100123 return h->loss_count > 0;
Gerrit Renkerde0d4112007-12-12 14:03:01 -0200124}
125
Arnaldo Carvalho de Melob84a2182007-12-06 13:18:11 -0200126extern void tfrc_rx_hist_add_packet(struct tfrc_rx_hist *h,
Gerrit Renker5b5d0e72008-07-13 11:51:40 +0100127 const struct sk_buff *skb, const u64 ndp);
Gerrit Renker85dcb1f2006-12-10 00:24:11 -0200128
Arnaldo Carvalho de Melob84a2182007-12-06 13:18:11 -0200129extern int tfrc_rx_hist_duplicate(struct tfrc_rx_hist *h, struct sk_buff *skb);
Gerrit Renkerde0d4112007-12-12 14:03:01 -0200130
Gerrit Renker8a9c7e92007-12-12 13:50:51 -0200131struct tfrc_loss_hist;
Gerrit Renkerde0d4112007-12-12 14:03:01 -0200132extern int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,
133 struct tfrc_loss_hist *lh,
Gerrit Renker5b5d0e72008-07-13 11:51:40 +0100134 struct sk_buff *skb, const u64 ndp,
Gerrit Renkerde0d4112007-12-12 14:03:01 -0200135 u32 (*first_li)(struct sock *sk),
136 struct sock *sk);
Arnaldo Carvalho de Melob84a2182007-12-06 13:18:11 -0200137extern u32 tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h,
138 const struct sk_buff *skb);
139extern int tfrc_rx_hist_alloc(struct tfrc_rx_hist *h);
140extern void tfrc_rx_hist_purge(struct tfrc_rx_hist *h);
Arnaldo Carvalho de Melo29e4f8b2005-08-28 02:00:28 -0300141
Arnaldo Carvalho de Melo8c60f3f2005-08-10 12:59:38 -0300142#endif /* _DCCP_PKT_HIST_ */