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