rstp_ppm.c
Go to the documentation of this file.
1 /**
2  * @file rstp_ppm.c
3  * @brief Port Protocol Migration state machine (PPM)
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2019-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneSTP Open.
12  *
13  * This program is free software; you can redistribute it and/or
14  * modify it under the terms of the GNU General Public License
15  * as published by the Free Software Foundation; either version 2
16  * of the License, or (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program; if not, write to the Free Software Foundation,
25  * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
26  *
27  * @author Oryx Embedded SARL (www.oryx-embedded.com)
28  * @version 2.4.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL RSTP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "rstp/rstp.h"
36 #include "rstp/rstp_fsm.h"
37 #include "rstp/rstp_ppm.h"
38 #include "rstp/rstp_conditions.h"
39 #include "rstp/rstp_misc.h"
40 #include "debug.h"
41 
42 //Check TCP/IP stack configuration
43 #if (RSTP_SUPPORT == ENABLED)
44 
45 //PPM state machine's states
47 {
48  {RSTP_PPM_STATE_CHECKING_RSTP, "CHECKING_RSTP"},
49  {RSTP_PPM_STATE_SELECTING_STP, "SELECTING_STP"},
50  {RSTP_PPM_STATE_SENSING, "SENSING"}
51 };
52 
53 
54 /**
55  * @brief PPM state machine initialization
56  * @param[in] port Pointer to the bridge port context
57  **/
58 
60 {
61  //Enter initial state
63 }
64 
65 
66 /**
67  * @brief PPM state machine implementation
68  * @param[in] port Pointer to the bridge port context
69  **/
70 
72 {
73  //All conditions for the current state are evaluated continuously until one
74  //of the conditions is met (refer to IEEE Std 802.1D-2004, section 17.16)
75  switch(port->ppmState)
76  {
77  //CHECKING_RSTP state?
79  //Evaluate conditions for the current state
80  if(port->mdelayWhile == 0)
81  {
82  //Switch to SENSING state
84  }
85  else if(port->mdelayWhile != rstpMigrateTime(port->context) &&
86  !port->portEnabled)
87  {
88  //Switch to CHECKING_RSTP state
90  }
91  else
92  {
93  //Just for sanity
94  }
95 
96  break;
97 
98  //SELECTING_STP state?
100  //Evaluate conditions for the current state
101  if(port->mdelayWhile == 0 || !port->portEnabled || port->mcheck)
102  {
103  //Switch to SENSING state
105  }
106 
107  break;
108 
109  //SENSING state?
111  //Evaluate conditions for the current state
112  if(port->sendRstp && port->rcvdStp)
113  {
114  //Switch to SELECTING_STP state
116  }
117  else if(!port->portEnabled || port->mcheck ||
118  (rstpVersion(port->context) && !port->sendRstp && port->rcvdRstp))
119  {
120  //Switch to CHECKING_RSTP state
122  }
123  else
124  {
125  //Just for sanity
126  }
127 
128  break;
129 
130  //Invalid state?
131  default:
132  //Just for sanity
133  rstpFsmError(port->context);
134  break;
135  }
136 }
137 
138 
139 /**
140  * @brief Update PPM state machine state
141  * @param[in] port Pointer to the bridge port context
142  * @param[in] newState New state to switch to
143  **/
144 
146 {
147  //Dump the state transition
148  TRACE_VERBOSE("Port %" PRIu8 ": PPM state machine %s -> %s\r\n",
149  port->portIndex,
152 
153  //Switch to the new state
154  port->ppmState = newState;
155 
156  //On entry to a state, the procedures defined for the state are executed
157  //exactly once (refer to IEEE Std 802.1D-2004, section 17.16)
158  switch(port->ppmState)
159  {
160  //CHECKING_RSTP state?
162  //Clear mcheck flag
163  port->mcheck = FALSE;
164 
165  //Update sendRSTP to tell the Port Transmit state machine which BPDU
166  //types to transmit in order to support interoperability with the
167  //Spanning Tree algorithm
168  port->sendRstp = rstpVersion(port->context);
169 
170  //Reload the Migration Delay timer
171  port->mdelayWhile = rstpMigrateTime(port->context);
172  break;
173 
174  //SELECTING_STP state?
176  //Clear sendRSTP flag
177  port->sendRstp = FALSE;
178 
179  //Reload the Migration Delay timer
180  port->mdelayWhile = rstpMigrateTime(port->context);
181  break;
182 
183  //SENSING state?
185  //Clear sendRSTP and rcvdSTP flags
186  port->rcvdRstp = FALSE;
187  port->rcvdStp = FALSE;
188  break;
189 
190  //Invalid state?
191  default:
192  //Just for sanity
193  break;
194  }
195 
196  //The RSTP state machine is busy
197  port->context->busy = TRUE;
198 }
199 
200 #endif
RstpPpmState
Port Protocol Migration states.
Definition: rstp_ppm.h:48
RSTP state machine conditions.
#define TRUE
Definition: os_port.h:50
Port Protocol Migration state machine (PPM)
RSTP helper functions.
#define FALSE
Definition: os_port.h:46
RSTP (Rapid Spanning Tree Protocol)
@ RSTP_PPM_STATE_CHECKING_RSTP
Definition: rstp_ppm.h:49
@ RSTP_PPM_STATE_SELECTING_STP
Definition: rstp_ppm.h:50
void rstpPpmFsm(RstpBridgePort *port)
PPM state machine implementation.
Definition: rstp_ppm.c:71
void rstpPpmInit(RstpBridgePort *port)
PPM state machine initialization.
Definition: rstp_ppm.c:59
uint16_t port
Definition: dns_common.h:267
void rstpFsmError(RstpBridgeContext *context)
RSTP state machine error handler.
Definition: rstp_fsm.c:226
bool_t rstpVersion(RstpBridgeContext *context)
rstpVersion condition (17.20.11)
Parameter value/name binding.
Definition: rstp_misc.h:48
@ RSTP_PPM_STATE_SENSING
Definition: rstp_ppm.h:51
const RstpParamName rstpPpmStates[]
Definition: rstp_ppm.c:46
const char_t * rstpGetParamName(uint_t value, const RstpParamName *paramList, size_t paramListLen)
Convert a parameter to string representation.
Definition: rstp_misc.c:883
Debugging facilities.
#define TRACE_VERBOSE(...)
Definition: debug.h:124
#define RstpBridgePort
Definition: rstp.h:40
#define arraysize(a)
Definition: os_port.h:71
uint_t rstpMigrateTime(RstpBridgeContext *context)
MigrateTime variable evaluation (17.20.9)
void rstpPpmChangeState(RstpBridgePort *port, RstpPpmState newState)
Update PPM state machine state.
Definition: rstp_ppm.c:145
Rapid Spanning Tree state machines.