dmake: do not set MAKEFLAGS=k
[unleashed/tickless.git] / usr / src / lib / librstp / common / migrate.c
blob08540d3a244f14c2bd8ba41ba0dcc51691281015
1 /************************************************************************
2 * RSTP library - Rapid Spanning Tree (802.1t, 802.1w)
3 * Copyright (C) 2001-2003 Optical Access
4 * Author: Alex Rozin
5 *
6 * This file is part of RSTP library.
7 *
8 * RSTP library is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU Lesser General Public License as published by the
10 * Free Software Foundation; version 2.1
12 * RSTP library is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser
15 * General Public License for more details.
17 * You should have received a copy of the GNU Lesser General Public License
18 * along with RSTP library; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
20 * 02111-1307, USA.
21 **********************************************************************/
23 /* Port Protocol Migration state machine : 17.26 */
25 #include "base.h"
26 #include "stpm.h"
28 #define STATES { \
29 CHOOSE(INIT), \
30 CHOOSE(SEND_RSTP), \
31 CHOOSE(SENDING_RSTP), \
32 CHOOSE(SEND_STP), \
33 CHOOSE(SENDING_STP) \
36 #define GET_STATE_NAME STP_migrate_get_state_name
37 #include "choose.h"
39 #define MigrateTime 3 /* 17,16.4 */
41 void
42 STP_migrate_enter_state (STATE_MACH_T* this)
44 register PORT_T* port = this->owner.port;
46 switch (this->State) {
47 case BEGIN:
48 case INIT:
49 port->initPm = True;
50 port->mcheck = False;
51 break;
52 case SEND_RSTP:
53 port->mdelayWhile = MigrateTime;
54 port->mcheck = port->initPm = False;
55 port->sendRSTP = True;
56 break;
57 case SENDING_RSTP:
58 port->rcvdRSTP = port->rcvdSTP = False;
59 break;
60 case SEND_STP:
61 port->mdelayWhile = MigrateTime;
62 port->sendRSTP = False;
63 port->initPm = False;
64 break;
65 case SENDING_STP:
66 port->rcvdRSTP = port->rcvdSTP = False;
67 break;
71 Bool
72 STP_migrate_check_conditions (STATE_MACH_T* this)
74 register PORT_T* port = this->owner.port;
76 if ((!port->portEnabled && !port->initPm) || BEGIN == this->State)
77 return STP_hop_2_state (this, INIT);
79 switch (this->State) {
80 case INIT:
81 if (port->portEnabled) {
82 return STP_hop_2_state (this, (port->owner->ForceVersion >= 2) ?
83 SEND_RSTP : SEND_STP);
85 break;
86 case SEND_RSTP:
87 return STP_hop_2_state (this, SENDING_RSTP);
88 case SENDING_RSTP:
89 if (port->mcheck)
90 return STP_hop_2_state (this, SEND_RSTP);
91 if (port->mdelayWhile &&
92 (port->rcvdSTP || port->rcvdRSTP)) {
93 return STP_hop_2_state (this, SENDING_RSTP);
96 if (!port->mdelayWhile && port->rcvdSTP) {
97 return STP_hop_2_state (this, SEND_STP);
100 if (port->owner->ForceVersion < 2) {
101 return STP_hop_2_state (this, SEND_STP);
104 break;
105 case SEND_STP:
106 return STP_hop_2_state (this, SENDING_STP);
107 case SENDING_STP:
108 if (port->mcheck)
109 return STP_hop_2_state (this, SEND_RSTP);
110 if (port->mdelayWhile &&
111 (port->rcvdSTP || port->rcvdRSTP))
112 return STP_hop_2_state (this, SENDING_STP);
113 if (!port->mdelayWhile && port->rcvdRSTP)
114 return STP_hop_2_state (this, SEND_RSTP);
115 break;
117 return False;