Import Upstream version 1.2.2
[quagga-debian.git] / ospfd / ospf_ism.h
1 /*
2  * OSPF version 2  Interface State Machine.
3  *   From RFC2328 [OSPF Version 2]
4  * Copyright (C) 1999 Toshiaki Takada
5  *
6  * This file is part of GNU Zebra.
7  *
8  * GNU Zebra is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU General Public License as published by the
10  * Free Software Foundation; either version 2, or (at your option) any
11  * later version.
12  *
13  * GNU Zebra is distributed in the hope that it will be useful, but
14  * WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
16  * General Public License for more details.
17  *
18  * You should have received a copy of the GNU General Public License
19  * along with GNU Zebra; see the file COPYING.  If not, write to the Free
20  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
21  * 02111-1307, USA.
22  */
23
24 #ifndef _ZEBRA_OSPF_ISM_H
25 #define _ZEBRA_OSPF_ISM_H
26
27 /* OSPF Interface State Machine Status. */
28 #define ISM_DependUpon                    0
29 #define ISM_Down                          1
30 #define ISM_Loopback                      2
31 #define ISM_Waiting                       3
32 #define ISM_PointToPoint                  4
33 #define ISM_DROther                       5
34 #define ISM_Backup                        6
35 #define ISM_DR                            7
36 #define OSPF_ISM_STATE_MAX                8
37
38 /* Because DR/DROther values are exhanged wrt RFC */
39 #define ISM_SNMP(x) (((x) == ISM_DROther) ? ISM_DR : \
40                      ((x) == ISM_DR) ? ISM_DROther : (x))
41
42 /* OSPF Interface State Machine Event. */
43 #define ISM_NoEvent                       0
44 #define ISM_InterfaceUp                   1
45 #define ISM_WaitTimer                     2
46 #define ISM_BackupSeen                    3
47 #define ISM_NeighborChange                4
48 #define ISM_LoopInd                       5
49 #define ISM_UnloopInd                     6
50 #define ISM_InterfaceDown                 7
51 #define OSPF_ISM_EVENT_MAX                8
52
53 #define OSPF_ISM_WRITE_ON(O)                                                  \
54       do                                                                      \
55         {                                                                     \
56           if (oi->on_write_q == 0)                                            \
57             {                                                                 \
58               listnode_add ((O)->oi_write_q, oi);                             \
59               oi->on_write_q = 1;                                             \
60             }                                                                 \
61           if ((O)->t_write == NULL)                                           \
62             (O)->t_write =                                                    \
63               thread_add_write (master, ospf_write, (O), (O)->fd);            \
64         } while (0)
65      
66 /* Macro for OSPF ISM timer turn on. */
67 #define OSPF_ISM_TIMER_ON(T,F,V) \
68   do { \
69     if (!(T)) \
70       (T) = thread_add_timer (master, (F), oi, (V)); \
71   } while (0)
72 #define OSPF_ISM_TIMER_MSEC_ON(T,F,V) \
73   do { \
74     if (!(T)) \
75       (T) = thread_add_timer_msec (master, (F), oi, (V)); \
76   } while (0)
77
78 /* convenience macro to set hello timer correctly, according to
79  * whether fast-hello is set or not
80  */
81 #define OSPF_HELLO_TIMER_ON(O) \
82   do { \
83     if (OSPF_IF_PARAM ((O), fast_hello)) \
84         OSPF_ISM_TIMER_MSEC_ON ((O)->t_hello, ospf_hello_timer, \
85                                 1000 / OSPF_IF_PARAM ((O), fast_hello)); \
86     else \
87         OSPF_ISM_TIMER_ON ((O)->t_hello, ospf_hello_timer, \
88                                 OSPF_IF_PARAM ((O), v_hello)); \
89   } while (0)
90
91 /* Macro for OSPF ISM timer turn off. */
92 #define OSPF_ISM_TIMER_OFF(X) \
93   do { \
94     if (X) \
95       { \
96         thread_cancel (X); \
97         (X) = NULL; \
98       } \
99   } while (0)
100
101 /* Macro for OSPF schedule event. */
102 #define OSPF_ISM_EVENT_SCHEDULE(I,E) \
103       thread_add_event (master, ospf_ism_event, (I), (E))
104
105 /* Macro for OSPF execute event. */
106 #define OSPF_ISM_EVENT_EXECUTE(I,E) \
107       thread_execute (master, ospf_ism_event, (I), (E))
108
109 /* Prototypes. */
110 extern int ospf_ism_event (struct thread *);
111 extern void ism_change_status (struct ospf_interface *, int);
112 extern int ospf_hello_timer (struct thread *thread);
113
114 #endif /* _ZEBRA_OSPF_ISM_H */