Path: blob/master/net/dccp/ccids/lib/packet_history.h
15112 views
/*1* Packet RX/TX history data structures and routines for TFRC-based protocols.2*3* Copyright (c) 2007 The University of Aberdeen, Scotland, UK4* Copyright (c) 2005-6 The University of Waikato, Hamilton, New Zealand.5*6* This code has been developed by the University of Waikato WAND7* research group. For further information please see http://www.wand.net.nz/8* or e-mail Ian McDonald - [email protected]9*10* This code also uses code from Lulea University, rereleased as GPL by its11* authors:12* Copyright (c) 2003 Nils-Erik Mattsson, Joacim Haggmark, Magnus Erixzon13*14* Changes to meet Linux coding standards, to make it meet latest ccid3 draft15* and to make it work as a loadable module in the DCCP stack written by16* Arnaldo Carvalho de Melo <[email protected]>.17*18* Copyright (c) 2005 Arnaldo Carvalho de Melo <[email protected]>19*20* This program is free software; you can redistribute it and/or modify21* it under the terms of the GNU General Public License as published by22* the Free Software Foundation; either version 2 of the License, or23* (at your option) any later version.24*25* This program is distributed in the hope that it will be useful,26* but WITHOUT ANY WARRANTY; without even the implied warranty of27* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the28* GNU General Public License for more details.29*30* You should have received a copy of the GNU General Public License31* along with this program; if not, write to the Free Software32* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.33*/3435#ifndef _DCCP_PKT_HIST_36#define _DCCP_PKT_HIST_3738#include <linux/list.h>39#include <linux/slab.h>40#include "tfrc.h"4142/**43* tfrc_tx_hist_entry - Simple singly-linked TX history list44* @next: next oldest entry (LIFO order)45* @seqno: sequence number of this entry46* @stamp: send time of packet with sequence number @seqno47*/48struct tfrc_tx_hist_entry {49struct tfrc_tx_hist_entry *next;50u64 seqno;51ktime_t stamp;52};5354static inline struct tfrc_tx_hist_entry *55tfrc_tx_hist_find_entry(struct tfrc_tx_hist_entry *head, u64 seqno)56{57while (head != NULL && head->seqno != seqno)58head = head->next;59return head;60}6162extern int tfrc_tx_hist_add(struct tfrc_tx_hist_entry **headp, u64 seqno);63extern void tfrc_tx_hist_purge(struct tfrc_tx_hist_entry **headp);6465/* Subtraction a-b modulo-16, respects circular wrap-around */66#define SUB16(a, b) (((a) + 16 - (b)) & 0xF)6768/* Number of packets to wait after a missing packet (RFC 4342, 6.1) */69#define TFRC_NDUPACK 37071/**72* tfrc_rx_hist_entry - Store information about a single received packet73* @tfrchrx_seqno: DCCP packet sequence number74* @tfrchrx_ccval: window counter value of packet (RFC 4342, 8.1)75* @tfrchrx_ndp: the NDP count (if any) of the packet76* @tfrchrx_tstamp: actual receive time of packet77*/78struct tfrc_rx_hist_entry {79u64 tfrchrx_seqno:48,80tfrchrx_ccval:4,81tfrchrx_type:4;82u64 tfrchrx_ndp:48;83ktime_t tfrchrx_tstamp;84};8586/**87* tfrc_rx_hist - RX history structure for TFRC-based protocols88* @ring: Packet history for RTT sampling and loss detection89* @loss_count: Number of entries in circular history90* @loss_start: Movable index (for loss detection)91* @rtt_sample_prev: Used during RTT sampling, points to candidate entry92*/93struct tfrc_rx_hist {94struct tfrc_rx_hist_entry *ring[TFRC_NDUPACK + 1];95u8 loss_count:2,96loss_start:2;97#define rtt_sample_prev loss_start98};99100/**101* tfrc_rx_hist_index - index to reach n-th entry after loss_start102*/103static inline u8 tfrc_rx_hist_index(const struct tfrc_rx_hist *h, const u8 n)104{105return (h->loss_start + n) & TFRC_NDUPACK;106}107108/**109* tfrc_rx_hist_last_rcv - entry with highest-received-seqno so far110*/111static inline struct tfrc_rx_hist_entry *112tfrc_rx_hist_last_rcv(const struct tfrc_rx_hist *h)113{114return h->ring[tfrc_rx_hist_index(h, h->loss_count)];115}116117/**118* tfrc_rx_hist_entry - return the n-th history entry after loss_start119*/120static inline struct tfrc_rx_hist_entry *121tfrc_rx_hist_entry(const struct tfrc_rx_hist *h, const u8 n)122{123return h->ring[tfrc_rx_hist_index(h, n)];124}125126/**127* tfrc_rx_hist_loss_prev - entry with highest-received-seqno before loss was detected128*/129static inline struct tfrc_rx_hist_entry *130tfrc_rx_hist_loss_prev(const struct tfrc_rx_hist *h)131{132return h->ring[h->loss_start];133}134135/* indicate whether previously a packet was detected missing */136static inline bool tfrc_rx_hist_loss_pending(const struct tfrc_rx_hist *h)137{138return h->loss_count > 0;139}140141extern void tfrc_rx_hist_add_packet(struct tfrc_rx_hist *h,142const struct sk_buff *skb, const u64 ndp);143144extern int tfrc_rx_hist_duplicate(struct tfrc_rx_hist *h, struct sk_buff *skb);145146struct tfrc_loss_hist;147extern int tfrc_rx_handle_loss(struct tfrc_rx_hist *h,148struct tfrc_loss_hist *lh,149struct sk_buff *skb, const u64 ndp,150u32 (*first_li)(struct sock *sk),151struct sock *sk);152extern u32 tfrc_rx_hist_sample_rtt(struct tfrc_rx_hist *h,153const struct sk_buff *skb);154extern int tfrc_rx_hist_alloc(struct tfrc_rx_hist *h);155extern void tfrc_rx_hist_purge(struct tfrc_rx_hist *h);156157#endif /* _DCCP_PKT_HIST_ */158159160