rstp_conditions.c
Go to the documentation of this file.
1 /**
2  * @file rstp_conditions.c
3  * @brief RSTP state machine conditions
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_conditions.h"
37 #include "debug.h"
38 
39 //Check TCP/IP stack configuration
40 #if (RSTP_SUPPORT == ENABLED)
41 
42 
43 /**
44  * @brief AdminEdge variable evaluation (17.20.1)
45  * @param[in] port Pointer to the bridge port context
46  * @return AdminEdgePort parameter for the port
47  **/
48 
50 {
51  //The function returns the AdminEdgePort parameter for the port
52  return port->params.adminEdgePort;
53 }
54 
55 
56 /**
57  * @brief AutoEdge variable evaluation (17.20.2)
58  * @param[in] port Pointer to the bridge port context
59  * @return AutoEdgePort parameter for the port
60  **/
61 
63 {
64  //The function returns the AutoEdgePort parameter for the port
65  return port->params.autoEdgePort;
66 }
67 
68 
69 /**
70  * @brief allSynced condition (17.20.3)
71  * @param[in] context Pointer to the RSTP bridge context
72  * @return Boolean
73  **/
74 
76 {
77  uint_t i;
78  bool_t res;
80 
81  //Initialize boolean
82  res = TRUE;
83 
84  //The condition allSynced is TRUE if and only if, for all ports for the
85  //given tree, selected is TRUE and the port's role is the same as its
86  //selectedRole, updtInfo is FALSE (refer to IEEE Std 802.1D-2004 errata)
87  //and either: synced is TRUE or the port is the Root port
88  for(i = 0; i < context->numPorts; i++)
89  {
90  //Point to the current bridge port
91  port = &context->ports[i];
92 
93  //Evaluate the condition for the current port
94  if(!port->selected)
95  {
96  res = FALSE;
97  }
98  else if(port->role != port->selectedRole)
99  {
100  res = FALSE;
101  }
102  else if(port->updtInfo)
103  {
104  res = FALSE;
105  }
106  else if(!port->synced && port->role != STP_PORT_ROLE_ROOT)
107  {
108  res = FALSE;
109  }
110  else
111  {
112  //Just for sanity
113  }
114  }
115 
116  //Return TRUE if the condition is met for all the ports
117  return res;
118 }
119 
120 
121 /**
122  * @brief EdgeDelay variable evaluation (17.20.4)
123  * @param[in] port Pointer to the bridge port context
124  * @return MigrateTime if operPointToPointMAC is TRUE, else MaxAge
125  **/
126 
128 {
129  uint_t value;
130 
131  //The function returns the value of MigrateTime if operPointToPointMAC is
132  //TRUE, and the value of MaxAge otherwise
133  if(port->operPointToPointMac)
134  {
135  value = rstpMigrateTime(port->context);
136  }
137  else
138  {
139  value = rstpMaxAge(port);
140  }
141 
142  //Return the relevant value
143  return value;
144 }
145 
146 
147 /**
148  * @brief forwardDelay variable evaluation (17.20.5)
149  * @param[in] port Pointer to the bridge port context
150  * @return HelloTime if sendRSTP is TRUE, else FwdDelay
151  **/
152 
154 {
155  uint_t value;
156 
157  //The function returns the value of HelloTime if sendRSTP is TRUE, and the
158  //value of FwdDelay otherwise
159  if(port->sendRstp)
160  {
162  }
163  else
164  {
166  }
167 
168  //Return the relevant value
169  return value;
170 }
171 
172 
173 /**
174  * @brief FwdDelay variable evaluation (17.20.6)
175  * @param[in] port Pointer to the bridge port context
176  * @return Forward Delay component of designatedTimes
177  **/
178 
180 {
181  //The function returns the Forward Delay component of designatedTimes
182  return port->designatedTimes.forwardDelay;
183 }
184 
185 
186 /**
187  * @brief HelloTime variable evaluation (17.20.7)
188  * @param[in] port Pointer to the bridge port context
189  * @return Hello Time component of designatedTimes
190  **/
191 
193 {
194  //The function returns the Hello Time component of designatedTimes
195  return port->designatedTimes.helloTime;
196 }
197 
198 
199 /**
200  * @brief MaxAge variable evaluation (17.20.8)
201  * @param[in] port Pointer to the bridge port context
202  * @return Max Age component of designatedTimes
203  **/
204 
206 {
207  //The function returns the Max Age component of designatedTimes
208  return port->designatedTimes.maxAge;
209 }
210 
211 
212 /**
213  * @brief MigrateTime variable evaluation (17.20.9)
214  * @param[in] context Pointer to the RSTP bridge context
215  * @return Migrate Time parameter
216  **/
217 
219 {
220  //The function returns the Migrate Time parameter
221  return context->params.migrateTime;
222 }
223 
224 
225 /**
226  * @brief reRooted condition (17.20.10)
227  * @param[in] port Pointer to the bridge port context
228  * @return Boolean
229  **/
230 
232 {
233  uint_t i;
234  bool_t res;
235  RstpBridgeContext *context;
236 
237  //Initialize boolean
238  res = TRUE;
239 
240  //Point to the RSTP bridge context
241  context = port->context;
242 
243  //Loop through the ports of the bridge
244  for(i = 0; i < context->numPorts; i++)
245  {
246  //Check the value of the rrWhile timer
247  if(&context->ports[i] != port && context->ports[i].rrWhile != 0)
248  {
249  res = FALSE;
250  }
251  }
252 
253  //Return TRUE if the rrWhile timer is zero for all ports other than the
254  //given port
255  return res;
256 }
257 
258 
259 /**
260  * @brief rstpVersion condition (17.20.11)
261  * @param[in] context Pointer to the RSTP bridge context
262  * @return Boolean
263  **/
264 
266 {
267  bool_t res;
268 
269  //Check protocol version
270  if(context->params.forceProtocolVersion >= RSTP_PROTOCOL_VERSION)
271  {
272  //Normal operation
273  res = TRUE;
274  }
275  else
276  {
277  //STP compatibility mode
278  res = FALSE;
279  }
280 
281  //Return TRUE if Force Protocol Version is greater than or equal to 2
282  return res;
283 }
284 
285 
286 /**
287  * @brief stpVersion condition (17.20.12)
288  * @param[in] context Pointer to the RSTP bridge context
289  * @return Boolean
290  **/
291 
293 {
294  //Return TRUE if Force Protocol Version is less than 2
295  return !rstpVersion(context);
296 }
297 
298 
299 /**
300  * @brief TxHoldCount variable evaluation (17.20.13)
301  * @param[in] context Pointer to the RSTP bridge context
302  * @return Transmit Hold Count parameter
303  **/
304 
306 {
307  //The function returns the Transmit Hold Count parameter
308  return context->params.transmitHoldCount;
309 }
310 
311 #endif
unsigned int uint_t
Definition: compiler_port.h:50
int bool_t
Definition: compiler_port.h:53
Debugging facilities.
uint16_t port
Definition: dns_common.h:267
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
const uint8_t res[]
RSTP (Rapid Spanning Tree Protocol)
#define RstpBridgeContext
Definition: rstp.h:36
#define RstpBridgePort
Definition: rstp.h:40
uint_t rstpAdminEdge(RstpBridgePort *port)
AdminEdge variable evaluation (17.20.1)
uint_t rstpHelloTime(RstpBridgePort *port)
HelloTime variable evaluation (17.20.7)
bool_t rstpVersion(RstpBridgeContext *context)
rstpVersion condition (17.20.11)
uint_t rstpAutoEdge(RstpBridgePort *port)
AutoEdge variable evaluation (17.20.2)
uint_t rstpMigrateTime(RstpBridgeContext *context)
MigrateTime variable evaluation (17.20.9)
uint_t rstpTxHoldCount(RstpBridgeContext *context)
TxHoldCount variable evaluation (17.20.13)
uint_t rstpMaxAge(RstpBridgePort *port)
MaxAge variable evaluation (17.20.8)
uint_t rstpForwardDelay(RstpBridgePort *port)
forwardDelay variable evaluation (17.20.5)
uint_t rstpFwdDelay(RstpBridgePort *port)
FwdDelay variable evaluation (17.20.6)
bool_t stpVersion(RstpBridgeContext *context)
stpVersion condition (17.20.12)
bool_t rstpReRooted(RstpBridgePort *port)
reRooted condition (17.20.10)
bool_t rstpAllSynced(RstpBridgeContext *context)
allSynced condition (17.20.3)
uint_t rstpEdgeDelay(RstpBridgePort *port)
EdgeDelay variable evaluation (17.20.4)
RSTP state machine conditions.
@ RSTP_PROTOCOL_VERSION
RSTP version.
Definition: stp_common.h:98
@ STP_PORT_ROLE_ROOT
Definition: stp_common.h:125
uint8_t value[]
Definition: tcp.h:369