1*4eaa4710SRishi Srivatsavai /************************************************************************ 2*4eaa4710SRishi Srivatsavai * RSTP library - Rapid Spanning Tree (802.1t, 802.1w) 3*4eaa4710SRishi Srivatsavai * Copyright (C) 2001-2003 Optical Access 4*4eaa4710SRishi Srivatsavai * Author: Alex Rozin 5*4eaa4710SRishi Srivatsavai * 6*4eaa4710SRishi Srivatsavai * This file is part of RSTP library. 7*4eaa4710SRishi Srivatsavai * 8*4eaa4710SRishi Srivatsavai * RSTP library is free software; you can redistribute it and/or modify it 9*4eaa4710SRishi Srivatsavai * under the terms of the GNU Lesser General Public License as published by the 10*4eaa4710SRishi Srivatsavai * Free Software Foundation; version 2.1 11*4eaa4710SRishi Srivatsavai * 12*4eaa4710SRishi Srivatsavai * RSTP library is distributed in the hope that it will be useful, but 13*4eaa4710SRishi Srivatsavai * WITHOUT ANY WARRANTY; without even the implied warranty of 14*4eaa4710SRishi Srivatsavai * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser 15*4eaa4710SRishi Srivatsavai * General Public License for more details. 16*4eaa4710SRishi Srivatsavai * 17*4eaa4710SRishi Srivatsavai * You should have received a copy of the GNU Lesser General Public License 18*4eaa4710SRishi Srivatsavai * along with RSTP library; see the file COPYING. If not, write to the Free 19*4eaa4710SRishi Srivatsavai * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 20*4eaa4710SRishi Srivatsavai * 02111-1307, USA. 21*4eaa4710SRishi Srivatsavai **********************************************************************/ 22*4eaa4710SRishi Srivatsavai 23*4eaa4710SRishi Srivatsavai /* STP PORT instance : 17.18, 17.15 */ 24*4eaa4710SRishi Srivatsavai 25*4eaa4710SRishi Srivatsavai #ifndef _STP_PORT_H__ 26*4eaa4710SRishi Srivatsavai #define _STP_PORT_H__ 27*4eaa4710SRishi Srivatsavai 28*4eaa4710SRishi Srivatsavai #include "statmch.h" 29*4eaa4710SRishi Srivatsavai 30*4eaa4710SRishi Srivatsavai #define TIMERS_NUMBER 9 31*4eaa4710SRishi Srivatsavai typedef unsigned int PORT_TIMER_T; 32*4eaa4710SRishi Srivatsavai 33*4eaa4710SRishi Srivatsavai typedef enum { 34*4eaa4710SRishi Srivatsavai Mine, 35*4eaa4710SRishi Srivatsavai Aged, 36*4eaa4710SRishi Srivatsavai Received, 37*4eaa4710SRishi Srivatsavai Disabled 38*4eaa4710SRishi Srivatsavai } INFO_IS_T; 39*4eaa4710SRishi Srivatsavai 40*4eaa4710SRishi Srivatsavai typedef enum { 41*4eaa4710SRishi Srivatsavai SuperiorDesignateMsg, 42*4eaa4710SRishi Srivatsavai RepeatedDesignateMsg, 43*4eaa4710SRishi Srivatsavai ConfirmedRootMsg, 44*4eaa4710SRishi Srivatsavai OtherMsg 45*4eaa4710SRishi Srivatsavai } RCVD_MSG_T; 46*4eaa4710SRishi Srivatsavai 47*4eaa4710SRishi Srivatsavai typedef enum { 48*4eaa4710SRishi Srivatsavai DisabledPort = 0, 49*4eaa4710SRishi Srivatsavai AlternatePort, 50*4eaa4710SRishi Srivatsavai BackupPort, 51*4eaa4710SRishi Srivatsavai RootPort, 52*4eaa4710SRishi Srivatsavai DesignatedPort, 53*4eaa4710SRishi Srivatsavai NonStpPort 54*4eaa4710SRishi Srivatsavai } PORT_ROLE_T; 55*4eaa4710SRishi Srivatsavai 56*4eaa4710SRishi Srivatsavai typedef struct port_t { 57*4eaa4710SRishi Srivatsavai struct port_t* next; 58*4eaa4710SRishi Srivatsavai 59*4eaa4710SRishi Srivatsavai /* per Port state machines */ 60*4eaa4710SRishi Srivatsavai STATE_MACH_T* info; /* 17.21 */ 61*4eaa4710SRishi Srivatsavai STATE_MACH_T* roletrns; /* 17.23 */ 62*4eaa4710SRishi Srivatsavai STATE_MACH_T* sttrans; /* 17.24 */ 63*4eaa4710SRishi Srivatsavai STATE_MACH_T* topoch; /* 17.25 */ 64*4eaa4710SRishi Srivatsavai STATE_MACH_T* migrate; /* 17.26 */ 65*4eaa4710SRishi Srivatsavai STATE_MACH_T* transmit; /* 17.26 */ 66*4eaa4710SRishi Srivatsavai STATE_MACH_T* p2p; /* 6.4.3, 6.5.1 */ 67*4eaa4710SRishi Srivatsavai STATE_MACH_T* edge; /* */ 68*4eaa4710SRishi Srivatsavai STATE_MACH_T* pcost; /* */ 69*4eaa4710SRishi Srivatsavai 70*4eaa4710SRishi Srivatsavai STATE_MACH_T* machines; /* list of machines */ 71*4eaa4710SRishi Srivatsavai 72*4eaa4710SRishi Srivatsavai struct stpm_t* owner; /* Bridge, that this port belongs to */ 73*4eaa4710SRishi Srivatsavai 74*4eaa4710SRishi Srivatsavai /* per port Timers */ 75*4eaa4710SRishi Srivatsavai PORT_TIMER_T fdWhile; /* 17.15.1 */ 76*4eaa4710SRishi Srivatsavai PORT_TIMER_T helloWhen; /* 17.15.2 */ 77*4eaa4710SRishi Srivatsavai PORT_TIMER_T mdelayWhile; /* 17.15.3 */ 78*4eaa4710SRishi Srivatsavai PORT_TIMER_T rbWhile; /* 17.15.4 */ 79*4eaa4710SRishi Srivatsavai PORT_TIMER_T rcvdInfoWhile;/* 17.15.5 */ 80*4eaa4710SRishi Srivatsavai PORT_TIMER_T rrWhile; /* 17.15.6 */ 81*4eaa4710SRishi Srivatsavai PORT_TIMER_T tcWhile; /* 17.15.7 */ 82*4eaa4710SRishi Srivatsavai PORT_TIMER_T txCount; /* 17.18.40 */ 83*4eaa4710SRishi Srivatsavai PORT_TIMER_T lnkWhile; 84*4eaa4710SRishi Srivatsavai 85*4eaa4710SRishi Srivatsavai PORT_TIMER_T* timers[TIMERS_NUMBER]; /*list of timers */ 86*4eaa4710SRishi Srivatsavai 87*4eaa4710SRishi Srivatsavai Bool agreed; /* 17.18.1 */ 88*4eaa4710SRishi Srivatsavai PRIO_VECTOR_T designPrio; /* 17.18.2 */ 89*4eaa4710SRishi Srivatsavai TIMEVALUES_T designTimes; /* 17.18.3 */ 90*4eaa4710SRishi Srivatsavai Bool forward; /* 17.18.4 */ 91*4eaa4710SRishi Srivatsavai Bool forwarding; /* 17.18.5 */ 92*4eaa4710SRishi Srivatsavai INFO_IS_T infoIs; /* 17.18.6 */ 93*4eaa4710SRishi Srivatsavai Bool initPm; /* 17.18.7 */ 94*4eaa4710SRishi Srivatsavai Bool learn; /* 17.18.8 */ 95*4eaa4710SRishi Srivatsavai Bool learning; /* 17.18.9 */ 96*4eaa4710SRishi Srivatsavai Bool mcheck; /* 17.18.10 */ 97*4eaa4710SRishi Srivatsavai PRIO_VECTOR_T msgPrio; /* 17.18.11 */ 98*4eaa4710SRishi Srivatsavai TIMEVALUES_T msgTimes; /* 17.18.12 */ 99*4eaa4710SRishi Srivatsavai Bool newInfo; /* 17.18.13 */ 100*4eaa4710SRishi Srivatsavai Bool operEdge; /* 17.18.14 */ 101*4eaa4710SRishi Srivatsavai Bool adminEdge; /* 17.18.14 */ 102*4eaa4710SRishi Srivatsavai Bool portEnabled; /* 17.18.15 */ 103*4eaa4710SRishi Srivatsavai PORT_ID port_id; /* 17.18.16 */ 104*4eaa4710SRishi Srivatsavai PRIO_VECTOR_T portPrio; /* 17.18.17 */ 105*4eaa4710SRishi Srivatsavai TIMEVALUES_T portTimes; /* 17.18.18 */ 106*4eaa4710SRishi Srivatsavai Bool proposed; /* 17.18.19 */ 107*4eaa4710SRishi Srivatsavai Bool proposing; /* 17.18.20 */ 108*4eaa4710SRishi Srivatsavai Bool rcvdBpdu; /* 17.18.21 */ 109*4eaa4710SRishi Srivatsavai RCVD_MSG_T rcvdMsg; /* 17.18.22 */ 110*4eaa4710SRishi Srivatsavai Bool rcvdRSTP; /* 17/18.23 */ 111*4eaa4710SRishi Srivatsavai Bool rcvdSTP; /* 17.18.24 */ 112*4eaa4710SRishi Srivatsavai Bool rcvdTc; /* 17.18.25 */ 113*4eaa4710SRishi Srivatsavai Bool rcvdTcAck; /* 17.18.26 */ 114*4eaa4710SRishi Srivatsavai Bool rcvdTcn; /* 17.18.27 */ 115*4eaa4710SRishi Srivatsavai Bool reRoot; /* 17.18.28 */ 116*4eaa4710SRishi Srivatsavai Bool reselect; /* 17.18.29 */ 117*4eaa4710SRishi Srivatsavai PORT_ROLE_T role; /* 17.18.30 */ 118*4eaa4710SRishi Srivatsavai Bool selected; /* 17.18.31 */ 119*4eaa4710SRishi Srivatsavai PORT_ROLE_T selectedRole; /* 17.18.32 */ 120*4eaa4710SRishi Srivatsavai Bool sendRSTP; /* 17.18.33 */ 121*4eaa4710SRishi Srivatsavai Bool sync; /* 17.18.34 */ 122*4eaa4710SRishi Srivatsavai Bool synced; /* 17.18.35 */ 123*4eaa4710SRishi Srivatsavai Bool tc; /* 17.18.36 */ 124*4eaa4710SRishi Srivatsavai Bool tcAck; /* 17.18.37 */ 125*4eaa4710SRishi Srivatsavai Bool tcProp; /* 17.18.38 */ 126*4eaa4710SRishi Srivatsavai 127*4eaa4710SRishi Srivatsavai Bool updtInfo; /* 17.18.41 */ 128*4eaa4710SRishi Srivatsavai 129*4eaa4710SRishi Srivatsavai /* message information */ 130*4eaa4710SRishi Srivatsavai unsigned char msgBpduVersion; 131*4eaa4710SRishi Srivatsavai unsigned char msgBpduType; 132*4eaa4710SRishi Srivatsavai unsigned char msgPortRole; 133*4eaa4710SRishi Srivatsavai unsigned char msgFlags; 134*4eaa4710SRishi Srivatsavai 135*4eaa4710SRishi Srivatsavai unsigned long adminPCost; /* may be ADMIN_PORT_PATH_COST_AUTO */ 136*4eaa4710SRishi Srivatsavai unsigned long operPCost; 137*4eaa4710SRishi Srivatsavai unsigned long operSpeed; 138*4eaa4710SRishi Srivatsavai unsigned long usedSpeed; 139*4eaa4710SRishi Srivatsavai int LinkDelay; /* TBD: LinkDelay may be managed ? */ 140*4eaa4710SRishi Srivatsavai Bool adminEnable; /* 'has LINK' */ 141*4eaa4710SRishi Srivatsavai Bool wasInitBpdu; 142*4eaa4710SRishi Srivatsavai Bool admin_non_stp; 143*4eaa4710SRishi Srivatsavai 144*4eaa4710SRishi Srivatsavai Bool p2p_recompute; 145*4eaa4710SRishi Srivatsavai Bool operPointToPointMac; 146*4eaa4710SRishi Srivatsavai ADMIN_P2P_T adminPointToPointMac; 147*4eaa4710SRishi Srivatsavai 148*4eaa4710SRishi Srivatsavai /* statistics */ 149*4eaa4710SRishi Srivatsavai unsigned long rx_cfg_bpdu_cnt; 150*4eaa4710SRishi Srivatsavai unsigned long rx_rstp_bpdu_cnt; 151*4eaa4710SRishi Srivatsavai unsigned long rx_tcn_bpdu_cnt; 152*4eaa4710SRishi Srivatsavai 153*4eaa4710SRishi Srivatsavai unsigned long uptime; /* 14.8.2.1.3.a */ 154*4eaa4710SRishi Srivatsavai 155*4eaa4710SRishi Srivatsavai int port_index; 156*4eaa4710SRishi Srivatsavai char* port_name; 157*4eaa4710SRishi Srivatsavai 158*4eaa4710SRishi Srivatsavai #ifdef STP_DBG 159*4eaa4710SRishi Srivatsavai unsigned int skip_rx; 160*4eaa4710SRishi Srivatsavai unsigned int skip_tx; 161*4eaa4710SRishi Srivatsavai #endif 162*4eaa4710SRishi Srivatsavai } PORT_T; 163*4eaa4710SRishi Srivatsavai 164*4eaa4710SRishi Srivatsavai PORT_T* 165*4eaa4710SRishi Srivatsavai STP_port_create (struct stpm_t* stpm, int port_index); 166*4eaa4710SRishi Srivatsavai 167*4eaa4710SRishi Srivatsavai void 168*4eaa4710SRishi Srivatsavai STP_port_delete (PORT_T* this); 169*4eaa4710SRishi Srivatsavai 170*4eaa4710SRishi Srivatsavai int 171*4eaa4710SRishi Srivatsavai STP_port_rx_bpdu (PORT_T* this, BPDU_T* bpdu, size_t len); 172*4eaa4710SRishi Srivatsavai 173*4eaa4710SRishi Srivatsavai void 174*4eaa4710SRishi Srivatsavai STP_port_init (PORT_T* this, struct stpm_t* stpm, Bool check_link); 175*4eaa4710SRishi Srivatsavai 176*4eaa4710SRishi Srivatsavai #ifdef STP_DBG 177*4eaa4710SRishi Srivatsavai int 178*4eaa4710SRishi Srivatsavai STP_port_trace_state_machine (PORT_T* this, char* mach_name, int enadis); 179*4eaa4710SRishi Srivatsavai 180*4eaa4710SRishi Srivatsavai void 181*4eaa4710SRishi Srivatsavai STP_port_trace_flags (char* title, PORT_T* this); 182*4eaa4710SRishi Srivatsavai #endif 183*4eaa4710SRishi Srivatsavai 184*4eaa4710SRishi Srivatsavai #endif /* _STP_PORT_H__ */ 185*4eaa4710SRishi Srivatsavai 186