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