summaryrefslogtreecommitdiff
path: root/sys/netinet/dccp_tfrc.h
blob: 5c13c277b2518f478f7272b710b79968cce126f6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
/*	$KAME: dccp_tfrc.h,v 1.10 2005/10/26 11:36:49 nishida Exp $	*/
/*	$NetBSD: dccp_tfrc.h,v 1.3 2019/06/04 10:15:22 msaitoh Exp $ */

/*
 * Copyright (c) 2003  Nils-Erik Mattsson 
 * All rights reserved.
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 * 3. The name of the author may not be used to endorse or promote products
 *    derived from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 * Id: dccp_tfrc.h,v 1.34 2003/05/28 17:36:15 nilmat-8 Exp
 */


#ifndef _NETINET_DCCP_TFRC_H_
#define _NETINET_DCCP_TFRC_H_

#define TFRC_STD_PACKET_SIZE    256
#define TFRC_MIN_PACKET_SIZE    16
#define TFRC_MAX_PACKET_SIZE    65535

#define TFRC_OPSYS_TIME_GRAN    10000
#define TFRC_WIN_COUNT_LIMIT    16
#define TFRC_WIN_COUNT_PER_RTT  4
#define TFRC_SMALLEST_P         4	/* 0.00004 */
/* 
 * TFRC sender 
 */

/* TFRC sender states */
#define TFRC_SSTATE_NO_SENT     1
#define TFRC_SSTATE_NO_FBACK	2
#define TFRC_SSTATE_FBACK	3
#define TFRC_SSTATE_TERM	4

/* Mechanism parameters */
#define TFRC_INITIAL_TIMEOUT    2
#define TFRC_MAX_BACK_OFF_TIME  64
#define TFRC_RTT_FILTER_CONST   9000	/* 0.9 */
#define TFRC_SEND_WAIT_TERM     20

/* Packet history */
TAILQ_HEAD(s_hist_head,s_hist_entry);

struct fixpoint {
	long long num;
	long long denom;
};
 
struct s_hist_entry {
	TAILQ_ENTRY(s_hist_entry) linfo;	/* Tail queue. */
	u_int64_t seq;		/* Sequence number */
	struct timeval t_sent;	/* When the packet was sent */
	u_int8_t win_count;	/* Windowcounter for packet */
};

/* TFRC sender congestion control block (ccb) */
struct tfrc_send_ccb {
	kmutex_t mutex;		/* Lock for this structure */
	struct dccpcb *pcb;	/* Pointer to associated dccpcb */
	u_int8_t state;		/* Sender state */

	struct fixpoint x;		/* Current sending rate */
	struct fixpoint x_recv;	/* Receive rate */
	struct fixpoint x_calc;	/* Calculated send (?) rate */ 

	u_int16_t s;		/* Packet size */

	u_int32_t rtt;		/* Estimate of current round trip time */
	struct fixpoint p;	/* Current loss event rate */  
	u_int8_t last_win_count;	/* Last window counter sent */
	/* Timestamp of earliest packet with last_win_count value sent */
	struct timeval t_last_win_count;
	u_int8_t idle;
	u_int32_t t_rto;	/* Time out value = 4*rtt */
	struct timeval t_ld;	/* Time last doubled during slow start */

	struct timeval t_nom;	/* Nominal send time of next packet */
	struct timeval t_ipi;	/* Interpacket (send) interval */
	struct timeval delta;	/* Send timer delta */    

	struct callout ch_stimer;	/* Handle to scheduled send timer */ 
	struct callout ch_nftimer;	/* Handle to no feedback timer */

	struct s_hist_head hist;	/* Packet history */
};

#ifdef _KERNEL

/* Functions declared in struct dccp_cc_sw */

/*
 * Initialises the sender side
 * args: pcb  - pointer to dccpcb of associated connection
 * returns: pointer to a tfrc_send_ccb struct on success, otherwise 0
 */ 
void *tfrc_send_init(struct dccpcb *);

/*
 * Free the sender side
 * args: ccb - ccb of sender
 */
void tfrc_send_free(void *);

/*
 * Ask TFRC wheter one can send a packet or not 
 * args: ccb  -  ccb block for current connection
 * returns: 1 if ok, else 0.
 */ 
int tfrc_send_packet(void *, long);

/*
 * Notify sender that a packet has been sent 
 * args: ccb - ccb block for current connection
 *	 moreToSend - if there exists more packets to send
 *       datasize   - packet size
 */
void tfrc_send_packet_sent(void *, int, long);

/*
 * Notify that a an ack package was received (i.e. a feedback packet)
 * args: ccb  -  ccb block for current connection
 */ 
void tfrc_send_packet_recv(void *, char *, int);

#endif

/* 
 * TFRC Receiver 
 */

/* TFRC specific dccp options */
#define TFRC_OPT_LOSS_RATE	192
#define TFRC_OPT_LOSS_INTERVAL	193
//#define TFRC_OPT_ELAPSED_TIME	193
#define TFRC_OPT_RECEIVE_RATE	194

/* TFRC receiver states */
#define TFRC_RSTATE_NO_DATA	1
#define TFRC_RSTATE_DATA	2
#define TFRC_RSTATE_TERM        127

/* Receiver mechanism parameters */
/*
 * seq_num x,y; if y-x is smaller than this number (note, wrap around) then
 * y is newer than x
 */
#define TFRC_RECV_NEW_SEQ_RANGE 10000000
/* number of later packets received before one is considered lost */
#define TFRC_RECV_NUM_LATE_LOSS 3
/* length(w[]) */
#define TFRC_RECV_IVAL_F_LENGTH  8

/* Packet history */
TAILQ_HEAD(r_hist_head,r_hist_entry);
 
struct r_hist_entry {
	TAILQ_ENTRY(r_hist_entry) linfo;	/* Tail queue. */
	u_int64_t seq;		/* Sequence number */
	struct timeval t_recv;	/* When the packet was received */
	u_int8_t win_count;	/* Window counter for that packet */
	u_int8_t type;		/* Packet type received */
	u_int8_t ndp;		/* no data packets value */
};

/* Loss interval history */
TAILQ_HEAD(li_hist_head,li_hist_entry);
 
struct li_hist_entry {
	TAILQ_ENTRY(li_hist_entry) linfo;	/* Tail queue. */
	u_int32_t interval;	/* Loss interval */
	u_int64_t seq;		/* Sequence number of the packet that started the interval */
	u_int8_t win_count;	/* Window counter for previous received packet */
};

/* TFRC receiver congestion control block (ccb) */
struct tfrc_recv_ccb {
	kmutex_t mutex;		/* Lock for this structure */
	struct dccpcb *pcb;	/* Pointer to associated dccpcb */
	u_int8_t state;		/* Receiver state */

	struct fixpoint p;	/* Loss event rate */

	struct li_hist_head li_hist;	/* Loss interval history */

	/*
	 * Highest value of the window counter received when last feedback
	 * was sent
	 */
	u_int8_t	last_counter;
	/* Sequence number of the packet above */
	u_int64_t	seq_last_counter;

	/* Timestamp of when last feedback was sent */
	struct timeval t_last_feedback;
	u_int32_t bytes_recv;	/* Bytes received since t_last_feedback */

	struct r_hist_head hist;	/* Packet history */

	u_int16_t s;		/* Packet size */
};

#ifdef _KERNEL

/* Functions declared in struct dccp_cc_sw */

/* Initialises the receiver side
 * args: pcb  -  pointer to dccpcb of associated connection
 * returns: pointer to a tfrc_recv_ccb struct on success, otherwise 0
 */ 
void *tfrc_recv_init(struct dccpcb *);

/* Free the receiver side
 * args: ccb - ccb of receiver
 */
void tfrc_recv_free(void *);

/*
 * Tell TFRC that a packet has been received
 * args: ccb  -  ccb block for current connection 
 */
void tfrc_recv_packet_recv(void *, char *, int);

#endif

#endif