xref: /onnv-gate/usr/src/lib/librstp/common/migrate.c (revision 10491:8893b747ecdf)
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 /* Port Protocol Migration state machine : 17.26 */
24*10491SRishi.Srivatsavai@Sun.COM 
25*10491SRishi.Srivatsavai@Sun.COM #include "base.h"
26*10491SRishi.Srivatsavai@Sun.COM #include "stpm.h"
27*10491SRishi.Srivatsavai@Sun.COM 
28*10491SRishi.Srivatsavai@Sun.COM #define STATES { \
29*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(INIT),     \
30*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(SEND_RSTP),    \
31*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(SENDING_RSTP), \
32*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(SEND_STP), \
33*10491SRishi.Srivatsavai@Sun.COM   CHOOSE(SENDING_STP)  \
34*10491SRishi.Srivatsavai@Sun.COM }
35*10491SRishi.Srivatsavai@Sun.COM 
36*10491SRishi.Srivatsavai@Sun.COM #define GET_STATE_NAME STP_migrate_get_state_name
37*10491SRishi.Srivatsavai@Sun.COM #include "choose.h"
38*10491SRishi.Srivatsavai@Sun.COM 
39*10491SRishi.Srivatsavai@Sun.COM #define MigrateTime 3 /* 17,16.4 */
40*10491SRishi.Srivatsavai@Sun.COM 
41*10491SRishi.Srivatsavai@Sun.COM void
STP_migrate_enter_state(STATE_MACH_T * this)42*10491SRishi.Srivatsavai@Sun.COM STP_migrate_enter_state (STATE_MACH_T* this)
43*10491SRishi.Srivatsavai@Sun.COM {
44*10491SRishi.Srivatsavai@Sun.COM   register PORT_T*       port = this->owner.port;
45*10491SRishi.Srivatsavai@Sun.COM 
46*10491SRishi.Srivatsavai@Sun.COM   switch (this->State) {
47*10491SRishi.Srivatsavai@Sun.COM     case BEGIN:
48*10491SRishi.Srivatsavai@Sun.COM     case INIT:
49*10491SRishi.Srivatsavai@Sun.COM       port->initPm = True;
50*10491SRishi.Srivatsavai@Sun.COM       port->mcheck = False;
51*10491SRishi.Srivatsavai@Sun.COM       break;
52*10491SRishi.Srivatsavai@Sun.COM     case SEND_RSTP:
53*10491SRishi.Srivatsavai@Sun.COM       port->mdelayWhile = MigrateTime;
54*10491SRishi.Srivatsavai@Sun.COM       port->mcheck = port->initPm = False;
55*10491SRishi.Srivatsavai@Sun.COM       port->sendRSTP = True;
56*10491SRishi.Srivatsavai@Sun.COM       break;
57*10491SRishi.Srivatsavai@Sun.COM     case SENDING_RSTP:
58*10491SRishi.Srivatsavai@Sun.COM       port->rcvdRSTP = port->rcvdSTP = False;
59*10491SRishi.Srivatsavai@Sun.COM       break;
60*10491SRishi.Srivatsavai@Sun.COM     case SEND_STP:
61*10491SRishi.Srivatsavai@Sun.COM       port->mdelayWhile = MigrateTime;
62*10491SRishi.Srivatsavai@Sun.COM       port->sendRSTP = False;
63*10491SRishi.Srivatsavai@Sun.COM       port->initPm = False;
64*10491SRishi.Srivatsavai@Sun.COM       break;
65*10491SRishi.Srivatsavai@Sun.COM     case SENDING_STP:
66*10491SRishi.Srivatsavai@Sun.COM       port->rcvdRSTP = port->rcvdSTP = False;
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_migrate_check_conditions(STATE_MACH_T * this)72*10491SRishi.Srivatsavai@Sun.COM STP_migrate_check_conditions (STATE_MACH_T* this)
73*10491SRishi.Srivatsavai@Sun.COM {
74*10491SRishi.Srivatsavai@Sun.COM   register PORT_T*    port = this->owner.port;
75*10491SRishi.Srivatsavai@Sun.COM 
76*10491SRishi.Srivatsavai@Sun.COM   if ((!port->portEnabled && !port->initPm) || BEGIN == this->State)
77*10491SRishi.Srivatsavai@Sun.COM     return STP_hop_2_state (this, INIT);
78*10491SRishi.Srivatsavai@Sun.COM 
79*10491SRishi.Srivatsavai@Sun.COM   switch (this->State) {
80*10491SRishi.Srivatsavai@Sun.COM     case INIT:
81*10491SRishi.Srivatsavai@Sun.COM       if (port->portEnabled) {
82*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, (port->owner->ForceVersion >= 2) ?
83*10491SRishi.Srivatsavai@Sun.COM                                    SEND_RSTP : SEND_STP);
84*10491SRishi.Srivatsavai@Sun.COM       }
85*10491SRishi.Srivatsavai@Sun.COM       break;
86*10491SRishi.Srivatsavai@Sun.COM     case SEND_RSTP:
87*10491SRishi.Srivatsavai@Sun.COM       return STP_hop_2_state (this, SENDING_RSTP);
88*10491SRishi.Srivatsavai@Sun.COM     case SENDING_RSTP:
89*10491SRishi.Srivatsavai@Sun.COM       if (port->mcheck)
90*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, SEND_RSTP);
91*10491SRishi.Srivatsavai@Sun.COM       if (port->mdelayWhile &&
92*10491SRishi.Srivatsavai@Sun.COM           (port->rcvdSTP || port->rcvdRSTP)) {
93*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, SENDING_RSTP);
94*10491SRishi.Srivatsavai@Sun.COM       }
95*10491SRishi.Srivatsavai@Sun.COM 
96*10491SRishi.Srivatsavai@Sun.COM       if (!port->mdelayWhile && port->rcvdSTP) {
97*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, SEND_STP);
98*10491SRishi.Srivatsavai@Sun.COM       }
99*10491SRishi.Srivatsavai@Sun.COM 
100*10491SRishi.Srivatsavai@Sun.COM       if (port->owner->ForceVersion < 2) {
101*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, SEND_STP);
102*10491SRishi.Srivatsavai@Sun.COM       }
103*10491SRishi.Srivatsavai@Sun.COM 
104*10491SRishi.Srivatsavai@Sun.COM       break;
105*10491SRishi.Srivatsavai@Sun.COM     case SEND_STP:
106*10491SRishi.Srivatsavai@Sun.COM       return STP_hop_2_state (this, SENDING_STP);
107*10491SRishi.Srivatsavai@Sun.COM     case SENDING_STP:
108*10491SRishi.Srivatsavai@Sun.COM       if (port->mcheck)
109*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, SEND_RSTP);
110*10491SRishi.Srivatsavai@Sun.COM       if (port->mdelayWhile &&
111*10491SRishi.Srivatsavai@Sun.COM           (port->rcvdSTP || port->rcvdRSTP))
112*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, SENDING_STP);
113*10491SRishi.Srivatsavai@Sun.COM       if (!port->mdelayWhile && port->rcvdRSTP)
114*10491SRishi.Srivatsavai@Sun.COM         return STP_hop_2_state (this, SEND_RSTP);
115*10491SRishi.Srivatsavai@Sun.COM       break;
116*10491SRishi.Srivatsavai@Sun.COM   }
117*10491SRishi.Srivatsavai@Sun.COM   return False;
118*10491SRishi.Srivatsavai@Sun.COM }
119*10491SRishi.Srivatsavai@Sun.COM 
120