2005-08-10 09:59:38 -06:00
|
|
|
/*
|
2007-11-28 06:15:40 -07:00
|
|
|
* Packet RX/TX history data structures and routines for TFRC-based protocols.
|
2005-08-10 09:59:38 -06:00
|
|
|
*
|
2007-11-28 06:15:40 -07:00
|
|
|
* Copyright (c) 2007 The University of Aberdeen, Scotland, UK
|
2006-08-26 20:01:30 -06:00
|
|
|
* Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.
|
2005-08-10 09:59:38 -06:00
|
|
|
*
|
|
|
|
* This code has been developed by the University of Waikato WAND
|
|
|
|
* research group. For further information please see http://www.wand.net.nz/
|
2006-08-26 20:01:30 -06:00
|
|
|
* or e-mail Ian McDonald - ian.mcdonald@jandi.co.nz
|
2005-08-10 09:59:38 -06:00
|
|
|
*
|
|
|
|
* This code also uses code from Lulea University, rereleased as GPL by its
|
|
|
|
* authors:
|
|
|
|
* Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon
|
|
|
|
*
|
|
|
|
* Changes to meet Linux coding standards, to make it meet latest ccid3 draft
|
|
|
|
* and to make it work as a loadable module in the DCCP stack written by
|
|
|
|
* Arnaldo Carvalho de Melo <acme@conectiva.com.br>.
|
|
|
|
*
|
|
|
|
* Copyright (c) 2005 Arnaldo Carvalho de Melo <acme@conectiva.com.br>
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef _DCCP_PKT_HIST_
|
|
|
|
#define _DCCP_PKT_HIST_
|
|
|
|
|
2007-12-12 08:50:51 -07:00
|
|
|
#include <linux/list.h>
|
|
|
|
#include <linux/slab.h>
|
|
|
|
#include "tfrc.h"
|
2005-08-27 22:19:14 -06:00
|
|
|
|
2007-11-29 17:47:15 -07:00
|
|
|
struct tfrc_tx_hist_entry;
|
2005-08-10 09:59:38 -06:00
|
|
|
|
2007-11-28 06:15:40 -07:00
|
|
|
extern int tfrc_tx_hist_add(struct tfrc_tx_hist_entry **headp, u64 seqno);
|
|
|
|
extern void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp);
|
2007-11-29 17:47:15 -07:00
|
|
|
extern u32 tfrc_tx_hist_rtt(struct tfrc_tx_hist_entry *head,
|
|
|
|
const u64 seqno, const ktime_t now);
|
2005-08-10 09:59:38 -06:00
|
|
|
|
2007-12-06 08:18:11 -07:00
|
|
|
/* Subtraction a-b modulo-16, respects circular wrap-around */
|
|
|
|
#define SUB16(a, b) (((a) + 16 - (b)) & 0xF)
|
|
|
|
|
|
|
|
/* Number of packets to wait after a missing packet (RFC 4342, 6.1) */
|
|
|
|
#define TFRC_NDUPACK 3
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tfrc_rx_hist_entry - Store information about a single received packet
|
|
|
|
* @tfrchrx_seqno: DCCP packet sequence number
|
|
|
|
* @tfrchrx_ccval: window counter value of packet (RFC 4342, 8.1)
|
|
|
|
* @tfrchrx_ndp: the NDP count (if any) of the packet
|
|
|
|
* @tfrchrx_tstamp: actual receive time of packet
|
2006-12-09 19:24:11 -07:00
|
|
|
*/
|
2007-12-06 07:28:39 -07:00
|
|
|
struct tfrc_rx_hist_entry {
|
|
|
|
u64 tfrchrx_seqno:48,
|
|
|
|
tfrchrx_ccval:4,
|
|
|
|
tfrchrx_type:4;
|
|
|
|
u32 tfrchrx_ndp; /* In fact it is from 8 to 24 bits */
|
|
|
|
ktime_t tfrchrx_tstamp;
|
2006-12-09 19:24:11 -07:00
|
|
|
};
|
2005-08-10 09:59:38 -06:00
|
|
|
|
2007-12-06 08:18:11 -07:00
|
|
|
/**
|
|
|
|
* tfrc_rx_hist - RX history structure for TFRC-based protocols
|
|
|
|
*
|
|
|
|
* @ring: Packet history for RTT sampling and loss detection
|
|
|
|
* @loss_count: Number of entries in circular history
|
|
|
|
* @loss_start: Movable index (for loss detection)
|
|
|
|
* @rtt_sample_prev: Used during RTT sampling, points to candidate entry
|
|
|
|
*/
|
|
|
|
struct tfrc_rx_hist {
|
|
|
|
struct tfrc_rx_hist_entry *ring[TFRC_NDUPACK + 1];
|
|
|
|
u8 loss_count:2,
|
|
|
|
loss_start:2;
|
|
|
|
#define rtt_sample_prev loss_start
|
|
|
|
};
|
2006-12-09 19:24:11 -07:00
|
|
|
|
2007-12-12 07:28:40 -07:00
|
|
|
/**
|
|
|
|
* tfrc_rx_hist_index - index to reach n-th entry after loss_start
|
|
|
|
*/
|
|
|
|
static inline u8 tfrc_rx_hist_index(const struct tfrc_rx_hist *h, const u8 n)
|
|
|
|
{
|
|
|
|
return (h->loss_start + n) & TFRC_NDUPACK;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tfrc_rx_hist_last_rcv - entry with highest-received-seqno so far
|
|
|
|
*/
|
|
|
|
static inline struct tfrc_rx_hist_entry *
|
|
|
|
tfrc_rx_hist_last_rcv(const struct tfrc_rx_hist *h)
|
|
|
|
{
|
|
|
|
return h->ring[tfrc_rx_hist_index(h, h->loss_count)];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tfrc_rx_hist_entry - return the n-th history entry after loss_start
|
|
|
|
*/
|
|
|
|
static inline struct tfrc_rx_hist_entry *
|
|
|
|
tfrc_rx_hist_entry(const struct tfrc_rx_hist *h, const u8 n)
|
|
|
|
{
|
|
|
|
return h->ring[tfrc_rx_hist_index(h, n)];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* tfrc_rx_hist_loss_prev - entry with highest-received-seqno before loss was detected
|
|
|
|
*/
|
|
|
|
static inline struct tfrc_rx_hist_entry *
|
|
|
|
tfrc_rx_hist_loss_prev(const struct tfrc_rx_hist *h)
|
|
|
|
{
|
|
|
|
return h->ring[h->loss_start];
|
|
|
|
}
|
|
|
|
|
2007-12-12 09:03:01 -07:00
|
|
|
/* initialise loss detection and disable RTT sampling */
|
|
|
|
static inline void tfrc_rx_hist_loss_indicated(struct tfrc_rx_hist *h)
|
|
|
|
{
|
|
|
|
h->loss_count = 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* indicate whether previously a packet was detected missing */
|
|
|
|
static inline int tfrc_rx_hist_loss_pending(const struct tfrc_rx_hist *h)
|
|
|
|
{
|
|
|
|
return h->loss_count;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* any data packets missing between last reception and skb ? */
|
|
|
|
static inline int tfrc_rx_hist_new_loss_indicated(struct tfrc_rx_hist *h,
|
|
|
|
const struct sk_buff *skb,
|
|
|
|
u32 ndp)
|
|
|
|
{
|
|
|
|
int delta = dccp_delta_seqno(tfrc_rx_hist_last_rcv(h)->tfrchrx_seqno,
|
|
|
|
DCCP_SKB_CB(skb)->dccpd_seq);
|
|
|
|
|
|
|
|
if (delta > 1 && ndp < delta)
|
|
|
|
tfrc_rx_hist_loss_indicated(h);
|
|
|
|
|
|
|
|
return tfrc_rx_hist_loss_pending(h);
|
|
|
|
}
|
|
|
|
|
2007-12-06 08:18:11 -07:00
|
|
|
extern void tfrc_rx_hist_add_packet(struct tfrc_rx_hist *h,
|
|
|
|
const struct sk_buff *skb, const u32 ndp);
|
2005-08-10 09:59:38 -06:00
|
|
|
|
2007-12-06 08:18:11 -07:00
|
|
|
extern int tfrc_rx_hist_duplicate(struct tfrc_rx_hist *h, struct sk_buff *skb);
|
2007-12-12 09:03:01 -07:00
|
|
|
|
2007-12-12 08:50:51 -07:00
|
|
|
struct tfrc_loss_hist;
|
2007-12-12 09:03:01 -07:00
|
|
|
extern int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,
|
|
|
|
struct tfrc_loss_hist *lh,
|
2007-12-12 08:50:51 -07:00
|
|
|
struct sk_buff *skb, u32 ndp,
|
2007-12-12 09:03:01 -07:00
|
|
|
u32 (*first_li)(struct sock *sk),
|
|
|
|
struct sock *sk);
|
2007-12-06 08:18:11 -07:00
|
|
|
extern u32 tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h,
|
|
|
|
const struct sk_buff *skb);
|
|
|
|
extern int tfrc_rx_hist_alloc(struct tfrc_rx_hist *h);
|
|
|
|
extern void tfrc_rx_hist_purge(struct tfrc_rx_hist *h);
|
2005-08-27 23:00:28 -06:00
|
|
|
|
2005-08-10 09:59:38 -06:00
|
|
|
#endif /* _DCCP_PKT_HIST_ */
|