604ab87292d7f9c8370a54249f56e95d9a3b1f3b
[dragonfly.git] / usr.sbin / atm / scspd / scsp_timer.c
1 /*
2  *
3  * ===================================
4  * HARP  |  Host ATM Research Platform
5  * ===================================
6  *
7  *
8  * This Host ATM Research Platform ("HARP") file (the "Software") is
9  * made available by Network Computing Services, Inc. ("NetworkCS")
10  * "AS IS".  NetworkCS does not provide maintenance, improvements or
11  * support of any kind.
12  *
13  * NETWORKCS MAKES NO WARRANTIES OR REPRESENTATIONS, EXPRESS OR IMPLIED,
14  * INCLUDING, BUT NOT LIMITED TO, IMPLIED WARRANTIES OF MERCHANTABILITY
15  * AND FITNESS FOR A PARTICULAR PURPOSE, AS TO ANY ELEMENT OF THE
16  * SOFTWARE OR ANY SUPPORT PROVIDED IN CONNECTION WITH THIS SOFTWARE.
17  * In no event shall NetworkCS be responsible for any damages, including
18  * but not limited to consequential damages, arising from or relating to
19  * any use of the Software or related support.
20  *
21  * Copyright 1994-1998 Network Computing Services, Inc.
22  *
23  * Copies of this Software may be made, however, the above copyright
24  * notice must be reproduced on all copies.
25  *
26  *      @(#) $FreeBSD: src/usr.sbin/atm/scspd/scsp_timer.c,v 1.3 1999/08/28 01:15:34 peter Exp $
27  *      @(#) $DragonFly: src/usr.sbin/atm/scspd/scsp_timer.c,v 1.3 2003/11/15 20:33:43 eirikn Exp $
28  */
29
30 /*
31  * Server Cache Synchronization Protocol (SCSP) Support
32  * ----------------------------------------------------
33  *
34  * Timer processing
35  *
36  */
37
38 #include <sys/types.h>
39 #include <sys/param.h>
40 #include <sys/socket.h>
41 #include <net/if.h>
42 #include <netinet/in.h>
43 #include <netatm/queue.h> 
44 #include <netatm/atm.h>
45 #include <netatm/atm_if.h>
46 #include <netatm/atm_sap.h>
47 #include <netatm/atm_sys.h>
48 #include <netatm/atm_ioctl.h>
49
50 #include <errno.h>
51 #include <libatm.h>
52 #include <stdio.h>
53 #include <syslog.h>
54
55 #include "scsp_msg.h"
56 #include "scsp_if.h"
57 #include "scsp_var.h"
58
59 /*
60  * Process an SCSP Open timeout
61  *
62  * The open timer is set when an attempt to open a VCC to a DCS fails.
63  * This routine will be called when the timer fires and will retry
64  * the open.  Retries can continue indefinitely.
65  *
66  * Arguments:
67  *      stp     pointer to an SCSP timer block
68  *
69  * Returns:
70  *      None
71  *
72  */
73 void
74 scsp_open_timeout(Harp_timer *stp)
75 {
76         Scsp_dcs        *dcsp;
77
78         /*
79          * Back off to start of DCS entry
80          */
81         dcsp = (Scsp_dcs *) ((caddr_t)stp -
82                         (int)(&((Scsp_dcs *)0)->sd_open_t));
83
84         /*
85          * Retry the connection
86          */
87         if (scsp_dcs_connect(dcsp)) {
88                 /*
89                  * Connect failed -- we hope the error was temporary
90                  * and set the timer to try again later
91                  */
92                 HARP_TIMER(&dcsp->sd_open_t, SCSP_Open_Interval,
93                                 scsp_open_timeout);
94         }
95 }
96
97
98 /*
99  * Process an SCSP Hello timeout
100  *
101  * The Hello timer fires every SCSP_HELLO_Interval seconds.  This
102  * routine will notify the Hello FSM when the timer fires.
103  *
104  * Arguments:
105  *      stp     pointer to an SCSP timer block
106  *
107  * Returns:
108  *      None
109  *
110  */
111 void
112 scsp_hello_timeout(Harp_timer *stp)
113 {
114         Scsp_dcs        *dcsp;
115
116         /*
117          * Back off to start of DCS entry
118          */
119         dcsp = (Scsp_dcs *) ((caddr_t)stp -
120                         (int)(&((Scsp_dcs *)0)->sd_hello_h_t));
121
122         /*
123          * Call the Hello FSM
124          */
125         (void)scsp_hfsm(dcsp, SCSP_HFSM_HELLO_T, (Scsp_msg *)0);
126
127         return;
128 }
129
130
131 /*
132  * Process an SCSP receive timeout
133  *
134  * The receive timer is started whenever the Hello FSM receives a
135  * Hello message from its DCS.  If the timer fires, it means that no
136  * Hello messages have been received in the DCS's Hello interval.
137  *
138  * Arguments:
139  *      stp     pointer to an SCSP timer block
140  *
141  * Returns:
142  *      None
143  *
144  */
145 void
146 scsp_hello_rcv_timeout(Harp_timer *stp)
147 {
148         Scsp_dcs        *dcsp;
149
150         /*
151          * Back off to start of DCS entry
152          */
153         dcsp = (Scsp_dcs *) ((caddr_t)stp -
154                         (int)(&((Scsp_dcs *)0)->sd_hello_rcv_t));
155
156         /*
157          * Call the Hello FSM
158          */
159         (void)scsp_hfsm(dcsp, SCSP_HFSM_RCV_T, (void *)0);
160
161         return;
162 }
163
164
165 /*
166  * Process an SCSP CA retransmit timeout
167  *
168  * Arguments:
169  *      stp     pointer to an SCSP timer block
170  *
171  * Returns:
172  *      None
173  *
174  */
175 void
176 scsp_ca_retran_timeout(Harp_timer *stp)
177 {
178         Scsp_dcs        *dcsp;
179
180         /*
181          * Back off to start of DCS entry
182          */
183         dcsp = (Scsp_dcs *) ((caddr_t)stp -
184                         (int)(&((Scsp_dcs *)0)->sd_ca_rexmt_t));
185
186         /*
187          * Call the CA FSM
188          */
189         (void)scsp_cafsm(dcsp, SCSP_CAFSM_CA_T, (void *)0);
190
191         return;
192 }
193
194
195 /*
196  * Process an SCSP CSUS retransmit timeout
197  *
198  * Arguments:
199  *      stp     pointer to an SCSP timer block
200  *
201  * Returns:
202  *      None
203  *
204  */
205 void
206 scsp_csus_retran_timeout(Harp_timer *stp)
207 {
208         Scsp_dcs        *dcsp;
209
210         /*
211          * Back off to start of DCS entry
212          */
213         dcsp = (Scsp_dcs *) ((caddr_t)stp -
214                         (int)(&((Scsp_dcs *)0)->sd_csus_rexmt_t));
215
216         /*
217          * Call the CA FSM
218          */
219         (void)scsp_cafsm(dcsp, SCSP_CAFSM_CSUS_T, (void *)0);
220
221         return;
222 }
223
224
225 /*
226  * Process an SCSP CSU Req retransmit timeout
227  *
228  * Arguments:
229  *      stp     pointer to an SCSP timer block
230  *
231  * Returns:
232  *      None
233  *
234  */
235 void
236 scsp_csu_req_retran_timeout(Harp_timer *stp)
237 {
238         Scsp_csu_rexmt  *rxp;
239         Scsp_dcs        *dcsp;
240
241         /*
242          * Back off to start of CSU Request retransmission entry
243          */
244         rxp = (Scsp_csu_rexmt *) ((caddr_t)stp -
245                         (int)(&((Scsp_csu_rexmt *)0)->sr_t));
246         dcsp = rxp->sr_dcs;
247
248         /*
249          * Call the CA FSM
250          */
251         (void)scsp_cafsm(dcsp, SCSP_CAFSM_CSU_T, (void *)rxp);
252
253         return;
254 }