xref: /illumos-gate/usr/src/lib/librstp/common/statmch.h (revision 5422785d352a2bb398daceab3d1898a8aa64d006)
1 /************************************************************************
2  * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3  * Copyright (C) 2001-2003 Optical Access
4  * Author: Alex Rozin
5  *
6  * This file is part of RSTP library.
7  *
8  * RSTP library is free software; you can redistribute it and/or modify it
9  * under the terms of the GNU Lesser General Public License as published by the
10  * Free Software Foundation; version 2.1
11  *
12  * RSTP library is distributed in the hope that it will be useful, but
13  * WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Lesser
15  * General Public License for more details.
16  *
17  * You should have received a copy of the GNU Lesser General Public License
18  * along with RSTP library; see the file COPYING.  If not, write to the Free
19  * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20  * 02111-1307, USA.
21  **********************************************************************/
22 
23 /* Generic (abstract state machine) state machine : 17.13, 17.14 */
24 
25 #ifndef _STP_STATER_H__
26 #define _STP_STATER_H__
27 
28 #define BEGIN  9999 /* distinct from any valid state */
29 
30 #define STP_DBG 1
31 
32 typedef struct state_mach_t {
33   struct state_mach_t* next;
34 
35   char*         name; /* for debugging */
36 #ifdef STP_DBG
37   char          debug; /* 0- no dbg, 1 - port, 2 - stpm */
38   unsigned int  ignoreHop2State;
39 #endif
40 
41   Bool          changeState;
42   unsigned int  State;
43 
44   void          (* concreteEnterState) (struct state_mach_t * );
45   Bool          (* concreteCheckCondition) (struct state_mach_t * );
46   char*         (* concreteGetStatName) (int);
47   union {
48     struct stpm_t* stpm;
49     struct port_t* port;
50     void         * owner;
51   } owner;
52 
53 } STATE_MACH_T;
54 
55 #define STP_STATE_MACH_IN_LIST(WHAT)                              \
56   {                                                               \
57     STATE_MACH_T* abstr;                                          \
58                                                                   \
59     abstr = STP_state_mach_create (STP_##WHAT##_enter_state,      \
60                                   STP_##WHAT##_check_conditions,  \
61                                   STP_##WHAT##_get_state_name,    \
62                                   this,                           \
63                                   #WHAT);                         \
64     abstr->next = this->machines;                                 \
65     this->machines = abstr;                                       \
66     this->WHAT = abstr;                       \
67   }
68 
69 
70 STATE_MACH_T *
71 STP_state_mach_create (void (* concreteEnterState) (STATE_MACH_T*),
72                        Bool (* concreteCheckCondition) (STATE_MACH_T*),
73                        char * (* concreteGetStatName) (int),
74                        void* owner, char* name);
75 
76 void
77 STP_state_mach_delete (STATE_MACH_T* this);
78 
79 Bool
80 STP_check_condition (STATE_MACH_T* this);
81 
82 Bool
83 STP_change_state (STATE_MACH_T* this);
84 
85 Bool
86 STP_hop_2_state (STATE_MACH_T* this, unsigned int new_state);
87 
88 #endif /* _STP_STATER_H__ */
89 
90