rstp_prx.c
Go to the documentation of this file.
1 /**
2  * @file rstp_prx.c
3  * @brief Port Receive state machine (PRX)
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_prx.h"
38 #include "rstp/rstp_procedures.h"
39 #include "rstp/rstp_conditions.h"
40 #include "rstp/rstp_misc.h"
41 #include "debug.h"
42 
43 //Check TCP/IP stack configuration
44 #if (RSTP_SUPPORT == ENABLED)
45 
46 //PRX state machine's states
48 {
49  {RSTP_PRX_STATE_DISCARD, "DISCARD"},
50  {RSTP_PRX_STATE_RECEIVE, "RECEIVE"}
51 };
52 
53 
54 /**
55  * @brief PRX 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 PRX state machine implementation
68  * @param[in] port Pointer to the bridge port context
69  **/
70 
72 {
73  //A global transition can occur from any of the possible states
74  if((port->rcvdBpdu || port->edgeDelayWhile != rstpMigrateTime(port->context)) &&
75  !port->portEnabled)
76  {
77  //When the condition associated with a global transition is met, it
78  //supersedes all other exit conditions
80  }
81  else
82  {
83  //All conditions for the current state are evaluated continuously until one
84  //of the conditions is met (refer to IEEE Std 802.1D-2004, section 17.16)
85  switch(port->prxState)
86  {
87  //DISCARD state?
89  //Check whether a valid BPDU has been received
90  if(port->rcvdBpdu && port->portEnabled)
91  {
92  //Switch to RECEIVE state
94  }
95 
96  break;
97 
98  //RECEIVE state?
100  //Check whether a valid BPDU has been received
101  if(port->rcvdBpdu && port->portEnabled && !port->rcvdMsg)
102  {
103  //Switch to RECEIVE state
105  }
106 
107  break;
108 
109  //Invalid state?
110  default:
111  //Just for sanity
112  rstpFsmError(port->context);
113  break;
114  }
115  }
116 }
117 
118 
119 /**
120  * @brief Update PRX state machine state
121  * @param[in] port Pointer to the bridge port context
122  * @param[in] newState New state to switch to
123  **/
124 
126 {
127  //Dump the state transition
128  TRACE_VERBOSE("Port %" PRIu8 ": PRX state machine %s -> %s\r\n",
129  port->portIndex,
132 
133  //Switch to the new state
134  port->prxState = newState;
135 
136  //On entry to a state, the procedures defined for the state are executed
137  //exactly once (refer to IEEE Std 802.1D-2004, section 17.16)
138  switch(port->prxState)
139  {
140  //DISCARD state?
142  //Clear flags
143  port->rcvdBpdu = FALSE;
144  port->rcvdRstp = FALSE;
145  port->rcvdStp = FALSE;
146  port->rcvdMsg = FALSE;
147 
148  //Reload the Edge Delay timer
149  port->edgeDelayWhile = rstpMigrateTime(port->context);
150  break;
151 
152  //RECEIVE state?
154  //Either rcvdRSTP or rcvdSTP is set to communicate the BPDU's arrival
155  //and type to the Port Protocol Migration state machine
157  port->operEdge = FALSE;
158  port->rcvdBpdu = FALSE;
159 
160  //Set rcvdMsg to communicate the BPDU's arrival to the Port Information
161  //state machine
162  port->rcvdMsg = TRUE;
163 
164  //Reload the Edge Delay timer
165  port->edgeDelayWhile = rstpMigrateTime(port->context);
166  break;
167 
168  //Invalid state?
169  default:
170  //Just for sanity
171  break;
172  }
173 
174  //The RSTP state machine is busy
175  port->context->busy = TRUE;
176 }
177 
178 #endif
RSTP state machine conditions.
#define TRUE
Definition: os_port.h:50
@ RSTP_PRX_STATE_RECEIVE
Definition: rstp_prx.h:50
RSTP helper functions.
void rstpUpdtBpduVersion(RstpBridgePort *port)
Update rcvdSTP and rcvdRSTP variables depending on BPDU version (17.21.22)
void rstpPrxInit(RstpBridgePort *port)
PRX state machine initialization.
Definition: rstp_prx.c:59
#define FALSE
Definition: os_port.h:46
RSTP (Rapid Spanning Tree Protocol)
Port Receive state machine (PRX)
uint16_t port
Definition: dns_common.h:267
RSTP state machine procedures.
void rstpFsmError(RstpBridgeContext *context)
RSTP state machine error handler.
Definition: rstp_fsm.c:226
void rstpPrxFsm(RstpBridgePort *port)
PRX state machine implementation.
Definition: rstp_prx.c:71
const RstpParamName rstpPrxStates[]
Definition: rstp_prx.c:47
Parameter value/name binding.
Definition: rstp_misc.h:48
RstpPrxState
Port Receive machine states.
Definition: rstp_prx.h:48
@ RSTP_PRX_STATE_DISCARD
Definition: rstp_prx.h:49
void rstpPrxChangeState(RstpBridgePort *port, RstpPrxState newState)
Update PRX state machine state.
Definition: rstp_prx.c:125
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)
Rapid Spanning Tree state machines.