]> git.ipfire.org Git - people/ms/rstp.git/blob - rstplib/statmch.h
4b399c77c8a066856bea599f95f575f0ebe0d8d4
[people/ms/rstp.git] / rstplib / statmch.h
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 typedef struct state_mach_t {
31 struct state_mach_t* next;
32
33 char* name; /* for debugging */
34 #ifdef STP_DBG
35 char debug; /* 0- no dbg, 1 - port, 2 - stpm */
36 unsigned int ignoreHop2State;
37 #endif
38
39 Bool changeState;
40 unsigned int State;
41
42 void (* concreteEnterState) (struct state_mach_t * );
43 Bool (* concreteCheckCondition) (struct state_mach_t * );
44 char* (* concreteGetStatName) (int);
45 union {
46 struct stpm_t* stpm;
47 struct port_t* port;
48 void * owner;
49 } owner;
50
51 } STATE_MACH_T;
52
53 #define STP_STATE_MACH_IN_LIST(WHAT) \
54 { \
55 STATE_MACH_T* abstr; \
56 \
57 abstr = STP_state_mach_create (STP_##WHAT##_enter_state, \
58 STP_##WHAT##_check_conditions, \
59 STP_##WHAT##_get_state_name, \
60 this, \
61 #WHAT); \
62 abstr->next = this->machines; \
63 this->machines = abstr; \
64 this->WHAT = abstr; \
65 }
66
67
68 STATE_MACH_T *
69 STP_state_mach_create (void (* concreteEnterState) (STATE_MACH_T*),
70 Bool (* concreteCheckCondition) (STATE_MACH_T*),
71 char * (* concreteGetStatName) (int),
72 void* owner, char* name);
73
74 void
75 STP_state_mach_delete (STATE_MACH_T* this);
76
77 Bool
78 STP_check_condition (STATE_MACH_T* this);
79
80 Bool
81 STP_change_state (STATE_MACH_T* this);
82
83 Bool
84 STP_hop_2_state (STATE_MACH_T* this, unsigned int new_state);
85
86 #endif /* _STP_STATER_H__ */
87