Commit | Line | Data |
---|---|---|
920dae64 AT |
1 | \ ========== Copyright Header Begin ========================================== |
2 | \ | |
3 | \ Hypervisor Software File: tcb.fth | |
4 | \ | |
5 | \ Copyright (c) 2006 Sun Microsystems, Inc. All Rights Reserved. | |
6 | \ | |
7 | \ - Do no alter or remove copyright notices | |
8 | \ | |
9 | \ - Redistribution and use of this software in source and binary forms, with | |
10 | \ or without modification, are permitted provided that the following | |
11 | \ conditions are met: | |
12 | \ | |
13 | \ - Redistribution of source code must retain the above copyright notice, | |
14 | \ this list of conditions and the following disclaimer. | |
15 | \ | |
16 | \ - Redistribution in binary form must reproduce the above copyright notice, | |
17 | \ this list of conditions and the following disclaimer in the | |
18 | \ documentation and/or other materials provided with the distribution. | |
19 | \ | |
20 | \ Neither the name of Sun Microsystems, Inc. or the names of contributors | |
21 | \ may be used to endorse or promote products derived from this software | |
22 | \ without specific prior written permission. | |
23 | \ | |
24 | \ This software is provided "AS IS," without a warranty of any kind. | |
25 | \ ALL EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, | |
26 | \ INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A | |
27 | \ PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN | |
28 | \ MICROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR | |
29 | \ ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR | |
30 | \ DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN | |
31 | \ OR ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR | |
32 | \ FOR DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE | |
33 | \ DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, | |
34 | \ ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF | |
35 | \ SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. | |
36 | \ | |
37 | \ You acknowledge that this software is not designed, licensed or | |
38 | \ intended for use in the design, construction, operation or maintenance of | |
39 | \ any nuclear facility. | |
40 | \ | |
41 | \ ========== Copyright Header End ============================================ | |
42 | id: @(#)tcb.fth 1.1 04/09/07 | |
43 | purpose: TCP control block management | |
44 | copyright: Copyright 2004 Sun Microsystems, Inc. All Rights Reserved | |
45 | copyright: Use is subject to license terms. | |
46 | ||
47 | \ TCP maintains one Transmission Control Block (TCB) for each connection. | |
48 | \ The TCB contains all state information about the connection: window | |
49 | \ sizes, sequence numbers in both directions, current round trip time | |
50 | \ estimate, whether acknowledgement or retransmission is needed etc. | |
51 | \ | |
52 | \ TCP's send and receive buffers are maintained as circular buffers. | |
53 | \ The smoothed round trip time (SRTT) and the estimated variance (RTTVAR) | |
54 | \ are stored as fixed point numbers with scaling factors of 8 and 4 | |
55 | \ respectively. | |
56 | \ | |
57 | \ Segments can arrive out of order. The sequencing queue stores information | |
58 | \ about blocks of data as they arrive until it can be assembled into a | |
59 | \ contiguous stream. | |
60 | ||
61 | headerless | |
62 | ||
63 | \ TCP control block; one per connection | |
64 | struct | |
65 | /w field >tcb-state \ TCP FSM state | |
66 | /w field >tcb-flags \ TCP state flags | |
67 | /l field >tcb-error \ Error flags | |
68 | /n field >tcb-inpcb \ Backpointer to INPCB | |
69 | ||
70 | /queue-head field >tcb-segq \ Sequencing queue | |
71 | /tcp-buffer field >tcb-rcvbuf \ Receive buffer (circular) | |
72 | /l field >rcv-nxt \ Expected seq# on incoming segment | |
73 | /l field >rcv-wnd \ Current receive window | |
74 | /l field >tcb-pushseq \ PUSH sequence number, if TF_PUSH | |
75 | /l field >tcb-finseq \ FIN sequence number, if TF_RCVDFIN | |
76 | /l field >tcb-mss \ Maximum segment size | |
77 | ||
78 | /tcp-buffer field >tcb-sndbuf \ Send buffer (circular) | |
79 | /l field >snd-una \ Send Unacknowledged | |
80 | /l field >snd-nxt \ Send Next | |
81 | /l field >snd-wnd \ Send Window | |
82 | /l field >snd-wl1 \ Seq# used for last window update | |
83 | /l field >snd-wl2 \ Ack# used for last window update | |
84 | /l field >snd-cwnd \ Congestion window | |
85 | /l field >ssthresh \ Slow start threshold | |
86 | /l field >snd-max \ Highest sequence number sent | |
87 | ||
88 | /timer field >tcbt-rexmit \ Retransmission timer | |
89 | /timer field >tcbt-connect \ Connection establishment timer | |
90 | /l field >tcb-nrexmits \ Number of retransmissions | |
91 | ||
92 | /l field >tcb-rttseq \ Sequence number being timed | |
93 | /l field >tcb-rtt \ Measured round trip time | |
94 | /l field >tcb-srtt \ Smoothed RTT (scaled by 8) | |
95 | /l field >tcb-rttvar \ Variance in RTT (scaled by 4) | |
96 | /l field >tcb-rto \ Current retransmission timeout | |
97 | constant /tcp-control-block | |
98 | ||
99 | \ Sequencing queue entry | |
100 | struct | |
101 | /queue-entry field >tseg-link \ Doubly linked sequencing queue | |
102 | /l field >tseg-seq \ Seq number in segment | |
103 | /l field >tseg-len \ Segment length | |
104 | constant /tcp-segq-entry | |
105 | ||
106 | \ TCP state flags | |
107 | 1 constant TF_ACKNOW \ Send ACK immediately | |
108 | 2 constant TF_DELACK \ ACK, but try to delay it | |
109 | h# 4 constant TF_RCVDFIN \ FIN has been received | |
110 | h# 8 constant TF_SENTFIN \ FIN has been sent | |
111 | h# 10 constant TF_RTTGET \ A segment is being timed | |
112 | h# 20 constant TF_PUSH \ PSH has been received | |
113 | ||
114 | d# 75000 constant TCP_CONN_TIMEOUT \ Initial Connection timeout | |
115 | d# 12 constant TCP_MAXRETRIES \ Maximum number of retransmissions | |
116 | ||
117 | : tcb>inpcb ( tcb -- inpcb ) >tcb-inpcb @ ; | |
118 | : inpcb>tcb ( inpcb -- tcb ) >in-ppcb @ ; | |
119 | ||
120 | : so>tcb ( sockaddr -- tcb ) so>inpcb inpcb>tcb ; | |
121 | ||
122 | : tcb-state@ ( tcb -- state ) >tcb-state w@ ; | |
123 | : tcb-state! ( state tcb -- ) >tcb-state w! ; | |
124 | : tcb-error@ ( error tcb -- ) >tcb-error l@ ; | |
125 | : tcb-error! ( error tcb -- ) >tcb-error l! ; | |
126 | : tcb-flags@ ( tcb -- flags ) >tcb-flags w@ ; | |
127 | : tcb-flags! ( flags tcb -- ) >tcb-flags w! ; | |
128 | ||
129 | : tcb-set-flags ( tcb flags -- ) | |
130 | over tcb-flags@ or swap tcb-flags! | |
131 | ; | |
132 | : tcb-clear-flags ( tcb flags -- ) | |
133 | invert over tcb-flags@ and swap tcb-flags! | |
134 | ; | |
135 | ||
136 | : tcb-mss@ ( tcb -- n ) >tcb-mss l@ ; | |
137 | : tcb-mss! ( n tcb -- ) >tcb-mss l! ; | |
138 | ||
139 | : tcb>sndbuf ( tcb -- sndbuf ) >tcb-sndbuf ; | |
140 | : tcb>rcvbuf ( tcb -- rcvbuf ) >tcb-rcvbuf ; | |
141 | ||
142 | : rcv-nxt@ ( tcb -- n ) >rcv-nxt l@ ; | |
143 | : rcv-nxt! ( n tcb -- ) >rcv-nxt l! ; | |
144 | : rcv-wnd@ ( tcb -- n ) >rcv-wnd l@ ; | |
145 | : rcv-wnd! ( n tcb -- ) >rcv-wnd l! ; | |
146 | ||
147 | : rcv-lastseq@ ( tcb -- n ) dup rcv-nxt@ swap rcv-wnd@ + 1- ; | |
148 | ||
149 | : snd-una@ ( tcb -- n ) >snd-una l@ ; | |
150 | : snd-una! ( n tcb -- ) >snd-una l! ; | |
151 | : snd-nxt@ ( tcb -- n ) >snd-nxt l@ ; | |
152 | : snd-nxt! ( n tcb -- ) >snd-nxt l! ; | |
153 | : snd-wl1@ ( tcb -- n ) >snd-wl1 l@ ; | |
154 | : snd-wl1! ( n tcb -- ) >snd-wl1 l! ; | |
155 | : snd-wl2@ ( tcb -- n ) >snd-wl2 l@ ; | |
156 | : snd-wl2! ( n tcb -- ) >snd-wl2 l! ; | |
157 | : snd-wnd@ ( tcb -- n ) >snd-wnd l@ ; | |
158 | : snd-wnd! ( n tcb -- ) >snd-wnd l! ; | |
159 | : snd-max@ ( tcb -- n ) >snd-max l@ ; | |
160 | : snd-max! ( n tcb -- ) >snd-max l! ; | |
161 | : snd-cwnd@ ( tcb -- n ) >snd-cwnd l@ ; | |
162 | : snd-cwnd! ( n tcb -- ) >snd-cwnd l! ; | |
163 | : ssthresh@ ( tcb -- n ) >ssthresh l@ ; | |
164 | : ssthresh! ( n tcb -- ) >ssthresh l! ; | |
165 | ||
166 | : tcb-srtt@ ( tcb -- n ) >tcb-srtt l@ ; | |
167 | : tcb-srtt! ( n tcb -- ) >tcb-srtt l! ; | |
168 | : tcb-rttvar@ ( tcb -- n ) >tcb-rttvar l@ ; | |
169 | : tcb-rttvar! ( n tcb -- ) >tcb-rttvar l! ; | |
170 | : tcb-rto@ ( tcb -- n ) >tcb-rto l@ ; | |
171 | : tcb-rto! ( n tcb -- ) >tcb-rto l! ; | |
172 | ||
173 | : tcp-retransmitting? ( tcb -- flag ) >tcb-nrexmits l@ 0<> ; | |
174 | ||
175 | \ Create and initialize a TCP control block. Use a receive buffer size | |
176 | \ which is an even multiple of MSS as this increases the percentage of | |
177 | \ full-sized segments used during bulk data transfers. | |
178 | : tcb-alloc ( -- tcb ) | |
179 | /tcp-control-block dup alloc-mem tuck swap erase ( tcb ) | |
180 | dup >tcb-segq queue-init ( tcb ) | |
181 | ||
182 | TCPS_CLOSED over tcb-state! ( tcb ) | |
183 | if-mtu@ /tcpip-header - over tcb-mss! ( tcb ) | |
184 | ||
185 | dup tcb>sndbuf h# 2000 tcpbuf-init ( tcb ) | |
186 | h# 4000 over tcb-mss@ tuck 1- + over / * ( tcb rbsize ) | |
187 | over tcb>rcvbuf over tcpbuf-init ( tcb rbsize ) | |
188 | ||
189 | over rcv-wnd! ( tcb ) | |
190 | dup tcb-mss@ over snd-cwnd! ( tcb ) | |
191 | d# 65535 over ssthresh! ( tcb ) | |
192 | d# 3000 over tcb-rto! ( tcb ) | |
193 | ; | |
194 | ||
195 | \ Free resources held by a TCP control block. | |
196 | : tcb-free ( tcb -- ) | |
197 | dup tcb>sndbuf tcpbuf-free ( tcb ) | |
198 | dup tcb>rcvbuf tcpbuf-free ( tcb ) | |
199 | dup >tcb-segq begin dup dequeue ?dup while ( tcb segq elt ) | |
200 | /tcp-segq-entry free-mem ( tcb segq ) | |
201 | repeat drop ( tcb ) | |
202 | /tcp-control-block free-mem ( ) | |
203 | ; | |
204 | ||
205 | \ Kill all outstanding timers for this TCB. | |
206 | : tcb-kill-timers ( tcb -- ) | |
207 | dup >tcbt-rexmit clear-timer drop ( tcb ) | |
208 | >tcbt-connect clear-timer drop ( ) | |
209 | ; | |
210 | ||
211 | headers |