rstp_pst.c
Go to the documentation of this file.
1 /**
2  * @file rstp_pst.c
3  * @brief Port State Transition state machine (PST)
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.0
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_pst.h"
38 #include "rstp/rstp_procedures.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 //PST state machine's states
47 {
48  {RSTP_PST_STATE_DISCARDING, "DISCARDING"},
49  {RSTP_PST_STATE_LEARNING, "LEARNING"},
50  {RSTP_PST_STATE_FORWARDING, "FORWARDING"}
51 };
52 
53 
54 /**
55  * @brief PST 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 PST 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->pstState)
76  {
77  //DISCARDING state?
79  //Check the learn flag
80  if(port->learn)
81  {
82  //Enable learning
84  }
85 
86  break;
87 
88  //LEARNING state?
90  //Check the learn and forward flags
91  if(port->forward)
92  {
93  //Enable forwarding
95  }
96  else if(!port->learn)
97  {
98  //Disable learning
100  }
101  else
102  {
103  //Just for sanity
104  }
105 
106  break;
107 
108  //FORWARDING state?
110  //Check the forward flag
111  if(!port->forward)
112  {
113  //Disable learning and forwarding
115  }
116 
117  break;
118 
119  //Invalid state?
120  default:
121  //Just for sanity
122  rstpFsmError(port->context);
123  break;
124  }
125 }
126 
127 
128 /**
129  * @brief Update PST state machine state
130  * @param[in] port Pointer to the bridge port context
131  * @param[in] newState New state to switch to
132  **/
133 
135 {
136  //Dump the state transition
137  TRACE_VERBOSE("Port %" PRIu8 ": PST state machine %s -> %s\r\n",
138  port->portIndex,
141 
142  //Switch to the new state
143  port->pstState = newState;
144 
145  //On entry to a state, the procedures defined for the state are executed
146  //exactly once (refer to IEEE Std 802.1D-2004, section 17.16)
147  switch(port->pstState)
148  {
149  //DISCARDING state?
151  //Disable learning and forwarding
153  port->learning = FALSE;
155  port->forwarding = FALSE;
156  break;
157 
158  //LEARNING state?
160  //Enable learning
162  port->learning = TRUE;
163  break;
164 
165  //FORWARDING state?
167  //Enable forwarding
169  port->forwarding = TRUE;
170  break;
171 
172  //Invalid state?
173  default:
174  //Just for sanity
175  break;
176  }
177 
178  //The RSTP state machine is busy
179  port->context->busy = TRUE;
180 }
181 
182 #endif
Debugging facilities.
#define TRACE_VERBOSE(...)
Definition: debug.h:124
uint16_t port
Definition: dns_common.h:267
#define arraysize(a)
Definition: os_port.h:71
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
RSTP (Rapid Spanning Tree Protocol)
#define RstpBridgePort
Definition: rstp.h:40
void rstpFsmError(RstpBridgeContext *context)
RSTP state machine error handler.
Definition: rstp_fsm.c:226
Rapid Spanning Tree state machines.
const char_t * rstpGetParamName(uint_t value, const RstpParamName *paramList, size_t paramListLen)
Convert a parameter to string representation.
Definition: rstp_misc.c:883
RSTP helper functions.
void rstpEnableLearning(RstpBridgePort *port)
Start learning from frames received on the port (17.21.6)
void rstpDisableForwarding(RstpBridgePort *port)
Stop forwarding frames through the port (17.21.3)
void rstpDisableLearning(RstpBridgePort *port)
Stop learning from frames received on the port (17.21.4)
void rstpEnableForwarding(RstpBridgePort *port)
Start forwarding frames through the port (17.21.5)
RSTP state machine procedures.
const RstpParamName rstpPstStates[]
Definition: rstp_pst.c:46
void rstpPstInit(RstpBridgePort *port)
PST state machine initialization.
Definition: rstp_pst.c:59
void rstpPstFsm(RstpBridgePort *port)
PST state machine implementation.
Definition: rstp_pst.c:71
void rstpPstChangeState(RstpBridgePort *port, RstpPstState newState)
Update PST state machine state.
Definition: rstp_pst.c:134
Port State Transition state machine (PST)
RstpPstState
Port State Transition machine states.
Definition: rstp_pst.h:48
@ RSTP_PST_STATE_LEARNING
Definition: rstp_pst.h:50
@ RSTP_PST_STATE_DISCARDING
Definition: rstp_pst.h:49
@ RSTP_PST_STATE_FORWARDING
Definition: rstp_pst.h:51
Parameter value/name binding.
Definition: rstp_misc.h:48