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 /* Note: this state mashine distinkts from described in P802.1t Clause 18. */
24*10491SRishi.Srivatsavai@Sun.COM /* I am ready to discuss it */
25*10491SRishi.Srivatsavai@Sun.COM
26*10491SRishi.Srivatsavai@Sun.COM #include "base.h"
27*10491SRishi.Srivatsavai@Sun.COM #include "stpm.h"
28*10491SRishi.Srivatsavai@Sun.COM #include "stp_vectors.h"
29*10491SRishi.Srivatsavai@Sun.COM
30*10491SRishi.Srivatsavai@Sun.COM #define STATES { \
31*10491SRishi.Srivatsavai@Sun.COM CHOOSE(DISABLED), \
32*10491SRishi.Srivatsavai@Sun.COM CHOOSE(DETECTED), \
33*10491SRishi.Srivatsavai@Sun.COM CHOOSE(DELAYED), \
34*10491SRishi.Srivatsavai@Sun.COM CHOOSE(RESOLVED) \
35*10491SRishi.Srivatsavai@Sun.COM }
36*10491SRishi.Srivatsavai@Sun.COM
37*10491SRishi.Srivatsavai@Sun.COM #define GET_STATE_NAME STP_edge_get_state_name
38*10491SRishi.Srivatsavai@Sun.COM #include "choose.h"
39*10491SRishi.Srivatsavai@Sun.COM
40*10491SRishi.Srivatsavai@Sun.COM #define DEFAULT_LINK_DELAY 3
41*10491SRishi.Srivatsavai@Sun.COM
42*10491SRishi.Srivatsavai@Sun.COM void
STP_edge_enter_state(STATE_MACH_T * s)43*10491SRishi.Srivatsavai@Sun.COM STP_edge_enter_state (STATE_MACH_T *s)
44*10491SRishi.Srivatsavai@Sun.COM {
45*10491SRishi.Srivatsavai@Sun.COM register PORT_T *port = s->owner.port;
46*10491SRishi.Srivatsavai@Sun.COM
47*10491SRishi.Srivatsavai@Sun.COM switch (s->State) {
48*10491SRishi.Srivatsavai@Sun.COM case BEGIN:
49*10491SRishi.Srivatsavai@Sun.COM break;
50*10491SRishi.Srivatsavai@Sun.COM case DISABLED:
51*10491SRishi.Srivatsavai@Sun.COM port->operEdge = port->adminEdge;
52*10491SRishi.Srivatsavai@Sun.COM port->wasInitBpdu = False;
53*10491SRishi.Srivatsavai@Sun.COM port->lnkWhile = 0;
54*10491SRishi.Srivatsavai@Sun.COM port->portEnabled = False;
55*10491SRishi.Srivatsavai@Sun.COM break;
56*10491SRishi.Srivatsavai@Sun.COM case DETECTED:
57*10491SRishi.Srivatsavai@Sun.COM port->portEnabled = True;
58*10491SRishi.Srivatsavai@Sun.COM port->lnkWhile = port->LinkDelay;
59*10491SRishi.Srivatsavai@Sun.COM port->operEdge = False;
60*10491SRishi.Srivatsavai@Sun.COM break;
61*10491SRishi.Srivatsavai@Sun.COM case DELAYED:
62*10491SRishi.Srivatsavai@Sun.COM break;
63*10491SRishi.Srivatsavai@Sun.COM case RESOLVED:
64*10491SRishi.Srivatsavai@Sun.COM if (! port->wasInitBpdu) {
65*10491SRishi.Srivatsavai@Sun.COM port->operEdge = port->adminEdge;
66*10491SRishi.Srivatsavai@Sun.COM }
67*10491SRishi.Srivatsavai@Sun.COM break;
68*10491SRishi.Srivatsavai@Sun.COM }
69*10491SRishi.Srivatsavai@Sun.COM }
70*10491SRishi.Srivatsavai@Sun.COM
71*10491SRishi.Srivatsavai@Sun.COM Bool
STP_edge_check_conditions(STATE_MACH_T * s)72*10491SRishi.Srivatsavai@Sun.COM STP_edge_check_conditions (STATE_MACH_T *s)
73*10491SRishi.Srivatsavai@Sun.COM {
74*10491SRishi.Srivatsavai@Sun.COM register PORT_T *port = s->owner.port;
75*10491SRishi.Srivatsavai@Sun.COM
76*10491SRishi.Srivatsavai@Sun.COM /* If we're disabled, then stay that way. */
77*10491SRishi.Srivatsavai@Sun.COM if (!port->adminEnable) {
78*10491SRishi.Srivatsavai@Sun.COM if (s->State == DISABLED)
79*10491SRishi.Srivatsavai@Sun.COM return False;
80*10491SRishi.Srivatsavai@Sun.COM else
81*10491SRishi.Srivatsavai@Sun.COM return STP_hop_2_state (s, DISABLED);
82*10491SRishi.Srivatsavai@Sun.COM }
83*10491SRishi.Srivatsavai@Sun.COM
84*10491SRishi.Srivatsavai@Sun.COM switch (s->State) {
85*10491SRishi.Srivatsavai@Sun.COM case BEGIN:
86*10491SRishi.Srivatsavai@Sun.COM return STP_hop_2_state (s, DISABLED);
87*10491SRishi.Srivatsavai@Sun.COM case DISABLED:
88*10491SRishi.Srivatsavai@Sun.COM if (port->adminEnable) {
89*10491SRishi.Srivatsavai@Sun.COM return STP_hop_2_state (s, DETECTED);
90*10491SRishi.Srivatsavai@Sun.COM }
91*10491SRishi.Srivatsavai@Sun.COM break;
92*10491SRishi.Srivatsavai@Sun.COM case DETECTED:
93*10491SRishi.Srivatsavai@Sun.COM return STP_hop_2_state (s, DELAYED);
94*10491SRishi.Srivatsavai@Sun.COM case DELAYED:
95*10491SRishi.Srivatsavai@Sun.COM if (port->wasInitBpdu) {
96*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
97*10491SRishi.Srivatsavai@Sun.COM if (s->debug)
98*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s 'edge' resolved by BPDU", port->port_name);
99*10491SRishi.Srivatsavai@Sun.COM #endif
100*10491SRishi.Srivatsavai@Sun.COM return STP_hop_2_state (s, RESOLVED);
101*10491SRishi.Srivatsavai@Sun.COM }
102*10491SRishi.Srivatsavai@Sun.COM
103*10491SRishi.Srivatsavai@Sun.COM if (! port->lnkWhile) {
104*10491SRishi.Srivatsavai@Sun.COM #ifdef STP_DBG
105*10491SRishi.Srivatsavai@Sun.COM if (s->debug)
106*10491SRishi.Srivatsavai@Sun.COM stp_trace ("port %s 'edge' resolved by timer", port->port_name);
107*10491SRishi.Srivatsavai@Sun.COM #endif
108*10491SRishi.Srivatsavai@Sun.COM return STP_hop_2_state (s, RESOLVED);
109*10491SRishi.Srivatsavai@Sun.COM }
110*10491SRishi.Srivatsavai@Sun.COM break;
111*10491SRishi.Srivatsavai@Sun.COM case RESOLVED:
112*10491SRishi.Srivatsavai@Sun.COM break;
113*10491SRishi.Srivatsavai@Sun.COM }
114*10491SRishi.Srivatsavai@Sun.COM return False;
115*10491SRishi.Srivatsavai@Sun.COM }
116