dccp_tfrc.h revision 1.2 1 /* $KAME: dccp_tfrc.h,v 1.10 2005/10/26 11:36:49 nishida Exp $ */
2 /* $NetBSD: dccp_tfrc.h,v 1.2 2016/07/07 06:55:43 msaitoh Exp $ */
3
4 /*
5 * Copyright (c) 2003 Nils-Erik Mattsson
6 * All rights reserved.
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 *
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. The name of the author may not be used to endorse or promote products
18 * derived from this software without specific prior written permission.
19 *
20 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
21 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
22 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
23 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
25 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
26 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
27 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
28 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
29 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
30 *
31 * Id: dccp_tfrc.h,v 1.34 2003/05/28 17:36:15 nilmat-8 Exp
32 */
33
34
35 #ifndef _NETINET_DCCP_TFRC_H_
36 #define _NETINET_DCCP_TFRC_H_
37
38 #define TFRC_STD_PACKET_SIZE 256
39 #define TFRC_MIN_PACKET_SIZE 16
40 #define TFRC_MAX_PACKET_SIZE 65535
41
42 #define TFRC_OPSYS_TIME_GRAN 10000
43 #define TFRC_WIN_COUNT_LIMIT 16
44 #define TFRC_WIN_COUNT_PER_RTT 4
45 #define TFRC_SMALLEST_P 4 /* 0.00004 */
46 /*
47 * TFRC sender
48 */
49
50 /* TFRC sender states */
51 #define TFRC_SSTATE_NO_SENT 1
52 #define TFRC_SSTATE_NO_FBACK 2
53 #define TFRC_SSTATE_FBACK 3
54 #define TFRC_SSTATE_TERM 4
55
56 /* Mechanism parameters */
57 #define TFRC_INITIAL_TIMEOUT 2
58 #define TFRC_MAX_BACK_OFF_TIME 64
59 #define TFRC_RTT_FILTER_CONST 9000 /* 0.9 */
60 #define TFRC_SEND_WAIT_TERM 20
61
62 /* Packet history */
63 TAILQ_HEAD(s_hist_head,s_hist_entry);
64
65 struct fixpoint {
66 long long num;
67 long long denom;
68 };
69
70 struct s_hist_entry {
71 TAILQ_ENTRY(s_hist_entry) linfo; /* Tail queue. */
72 u_int64_t seq; /* Sequence number */
73 struct timeval t_sent; /* When the packet was sent */
74 u_int8_t win_count; /* Windowcounter for packet */
75 };
76
77 /* TFRC sender congestion control block (ccb) */
78 struct tfrc_send_ccb {
79 kmutex_t mutex; /* Lock for this structure */
80 struct dccpcb *pcb; /* Pointer to associated dccpcb */
81 u_int8_t state; /* Sender state */
82
83 struct fixpoint x; /* Current sending rate */
84 struct fixpoint x_recv; /* Receive rate */
85 struct fixpoint x_calc; /* Calculated send (?) rate */
86
87 u_int16_t s; /* Packet size */
88
89 u_int32_t rtt; /* Estimate of current round trip time */
90 struct fixpoint p; /* Current loss event rate */
91 u_int8_t last_win_count; /* Last window counter sent */
92 /* Timestamp of earliest packet with last_win_count value sent */
93 struct timeval t_last_win_count;
94 u_int8_t idle;
95 u_int32_t t_rto; /* Time out value = 4*rtt */
96 struct timeval t_ld; /* Time last doubled during slow start */
97
98 struct timeval t_nom; /* Nominal send time of next packet */
99 struct timeval t_ipi; /* Interpacket (send) interval */
100 struct timeval delta; /* Send timer delta */
101
102 struct callout ch_stimer; /* Handle to scheduled send timer */
103 struct callout ch_nftimer; /* Handle to no feedback timer */
104
105 struct s_hist_head hist; /* Packet history */
106 };
107
108 #ifdef _KERNEL
109
110 /* Functions declared in struct dccp_cc_sw */
111
112 /*
113 * Initialises the sender side
114 * args: pcb - pointer to dccpcb of associated connection
115 * returns: pointer to a tfrc_send_ccb struct on success, otherwise 0
116 */
117 void *tfrc_send_init(struct dccpcb *);
118
119 /*
120 * Free the sender side
121 * args: ccb - ccb of sender
122 */
123 void tfrc_send_free(void *);
124
125 /*
126 * Ask TFRC wheter one can send a packet or not
127 * args: ccb - ccb block for current connection
128 * returns: 1 if ok, else 0.
129 */
130 int tfrc_send_packet(void *, long);
131
132 /*
133 * Notify sender that a packet has been sent
134 * args: ccb - ccb block for current connection
135 * moreToSend - if there exists more packets to send
136 * datasize - packet size
137 */
138 void tfrc_send_packet_sent(void *, int, long);
139
140 /*
141 * Notify that a an ack package was received (i.e. a feedback packet)
142 * args: ccb - ccb block for current connection
143 */
144 void tfrc_send_packet_recv(void *, char *, int);
145
146 #endif
147
148 /*
149 * TFRC Receiver
150 */
151
152 /* TFRC specific dccp options */
153 #define TFRC_OPT_LOSS_RATE 192
154 #define TFRC_OPT_LOSS_INTERVAL 193
155 //#define TFRC_OPT_ELAPSED_TIME 193
156 #define TFRC_OPT_RECEIVE_RATE 194
157
158 /* TFRC receiver states */
159 #define TFRC_RSTATE_NO_DATA 1
160 #define TFRC_RSTATE_DATA 2
161 #define TFRC_RSTATE_TERM 127
162
163 /* Receiver mechanism parameters */
164 /*
165 * seq_num x,y; if y-x is smaller than this number (note, wrap around) then
166 * y is newer than x
167 */
168 #define TFRC_RECV_NEW_SEQ_RANGE 10000000
169 /* number of later packets received before one is considered lost */
170 #define TFRC_RECV_NUM_LATE_LOSS 3
171 /* length(w[]) */
172 #define TFRC_RECV_IVAL_F_LENGTH 8
173
174 /* Packet history */
175 TAILQ_HEAD(r_hist_head,r_hist_entry);
176
177 struct r_hist_entry {
178 TAILQ_ENTRY(r_hist_entry) linfo; /* Tail queue. */
179 u_int64_t seq; /* Sequence number */
180 struct timeval t_recv; /* When the packet was received */
181 u_int8_t win_count; /* Window counter for that packet */
182 u_int8_t type; /* Packet type received */
183 u_int8_t ndp; /* no data packets value */
184 };
185
186 /* Loss interval history */
187 TAILQ_HEAD(li_hist_head,li_hist_entry);
188
189 struct li_hist_entry {
190 TAILQ_ENTRY(li_hist_entry) linfo; /* Tail queue. */
191 u_int32_t interval; /* Loss interval */
192 u_int64_t seq; /* Sequence number of the packet that started the interval */
193 u_int8_t win_count; /* Window counter for previous received packet */
194 };
195
196 /* TFRC receiver congestion control block (ccb) */
197 struct tfrc_recv_ccb {
198 kmutex_t mutex; /* Lock for this structure */
199 struct dccpcb *pcb; /* Pointer to associated dccpcb */
200 u_int8_t state; /* Receiver state */
201
202 struct fixpoint p; /* Loss event rate */
203
204 struct li_hist_head li_hist; /* Loss interval history */
205
206 /*
207 * Highest value of the window counter received when last feedback
208 * was sent
209 */
210 u_int8_t last_counter;
211 /* Sequence number of the packet above */
212 u_int64_t seq_last_counter;
213
214 /* Timestamp of when last feedback was sent */
215 struct timeval t_last_feedback;
216 u_int32_t bytes_recv; /* Bytes received since t_last_feedback */
217
218 struct r_hist_head hist; /* Packet history */
219
220 u_int16_t s; /* Packet size */
221 };
222
223 #ifdef _KERNEL
224
225 /* Functions declared in struct dccp_cc_sw */
226
227 /* Initialises the receiver side
228 * args: pcb - pointer to dccpcb of associated connection
229 * returns: pointer to a tfrc_recv_ccb struct on success, otherwise 0
230 */
231 void *tfrc_recv_init(struct dccpcb *);
232
233 /* Free the receiver side
234 * args: ccb - ccb of recevier
235 */
236 void tfrc_recv_free(void *);
237
238 /*
239 * Tell TFRC that a packet has been received
240 * args: ccb - ccb block for current connection
241 */
242 void tfrc_recv_packet_recv(void *, char *, int);
243
244 #endif
245
246 #endif
247