rstp_prs.c
Go to the documentation of this file.
1 /**
2  * @file rstp_prs.c
3  * @brief Port Role Selection state machine (PRS)
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_prs.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 //PRS state machine's states
47 {
48  {RSTP_PRS_STATE_INIT_BRIDGE, "INIT_BRIDGE"},
49  {RSTP_PRS_STATE_ROLE_SELECTION, "ROLE_SELECTION"}
50 };
51 
52 
53 /**
54  * @brief PRS state machine initialization
55  * @param[in] context Pointer to the RSTP bridge context
56  **/
57 
59 {
60  //Enter initial state
62 }
63 
64 
65 /**
66  * @brief PRS state machine implementation
67  * @param[in] context Pointer to the RSTP bridge context
68  **/
69 
71 {
72  uint_t i;
73  bool_t reselect;
74 
75  //All conditions for the current state are evaluated continuously until one
76  //of the conditions is met (refer to IEEE Std 802.1D-2004, section 17.16)
77  switch(context->prsState)
78  {
79  //INIT_BRIDGE state?
81  //Unconditional transition (UCT) to ROLE_SELECTION state
83  break;
84 
85  //ROLE_SELECTION state?
87  //Check whether the reselect variable is TRUE for any port
88  for(reselect = FALSE, i = 0; i < context->numPorts; i++)
89  {
90  reselect |= context->ports[i].reselect;
91  }
92 
93  //Whenever any bridge port's reselect variable is set by the Port
94  //Information state machine, spanning tree information is recomputed
95  if(reselect)
96  {
98  }
99 
100  break;
101 
102  //Invalid state?
103  default:
104  //Just for sanity
105  rstpFsmError(context);
106  break;
107  }
108 }
109 
110 
111 /**
112  * @brief Update PRS state machine state
113  * @param[in] context Pointer to the RSTP bridge context
114  * @param[in] newState New state to switch to
115  **/
116 
118 {
119  //Dump the state transition
120  TRACE_VERBOSE("PRS state machine %s -> %s\r\n",
123 
124  //Switch to the new state
125  context->prsState = newState;
126 
127  //On entry to a state, the procedures defined for the state are executed
128  //exactly once (refer to IEEE Std 802.1D-2004, section 17.16)
129  switch(context->prsState)
130  {
131  //INIT_BRIDGE state?
133  //On initialization all ports are assigned the Disabled port role
134  rstpUpdtRoleDisabledTree(context);
135  break;
136 
137  //ROLE_SELECTION state?
139  //Update spanning tree information and port roles
140  rstpClearReselectTree(context);
141  rstpUpdtRolesTree(context);
142  rstpSetSelectedTree(context);
143  break;
144 
145  //Invalid state?
146  default:
147  //Just for sanity
148  break;
149  }
150 
151  //The RSTP state machine is busy
152  context->busy = TRUE;
153 }
154 
155 #endif
int bool_t
Definition: compiler_port.h:53
void rstpPrsChangeState(RstpBridgeContext *context, RstpPrsState newState)
Update PRS state machine state.
Definition: rstp_prs.c:117
#define TRUE
Definition: os_port.h:50
void rstpClearReselectTree(RstpBridgeContext *context)
Clear reselect for all ports of the bridge (17.21.2)
RSTP helper functions.
void rstpPrsFsm(RstpBridgeContext *context)
PRS state machine implementation.
Definition: rstp_prs.c:70
#define RstpBridgeContext
Definition: rstp.h:36
#define FALSE
Definition: os_port.h:46
const RstpParamName rstpPrsStates[]
Definition: rstp_prs.c:46
RstpPrsState
Port Role Selection machine states.
Definition: rstp_prs.h:48
RSTP (Rapid Spanning Tree Protocol)
@ RSTP_PRS_STATE_ROLE_SELECTION
Definition: rstp_prs.h:50
void rstpSetSelectedTree(RstpBridgeContext *context)
Set the selected variable for all ports of the bridge (17.21.16)
Port Role Selection state machine (PRS)
void rstpUpdtRoleDisabledTree(RstpBridgeContext *context)
Set the selectedRole to DisabledPort for all ports of the bridge (17.21.24)
@ RSTP_PRS_STATE_INIT_BRIDGE
Definition: rstp_prs.h:49
RSTP state machine procedures.
void rstpFsmError(RstpBridgeContext *context)
RSTP state machine error handler.
Definition: rstp_fsm.c:226
Parameter value/name binding.
Definition: rstp_misc.h:48
void rstpPrsInit(RstpBridgeContext *context)
PRS state machine initialization.
Definition: rstp_prs.c:58
unsigned int uint_t
Definition: compiler_port.h:50
void rstpUpdtRolesTree(RstpBridgeContext *context)
Update spanning tree information and port roles (17.21.25)
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 arraysize(a)
Definition: os_port.h:71
Rapid Spanning Tree state machines.