rstp_bdm.c
Go to the documentation of this file.
1 /**
2  * @file rstp_bdm.c
3  * @brief Bridge Detection state machine (BDM)
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_bdm.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 //BDM state machine's states
47 {
48  {RSTP_BDM_STATE_EDGE, "EDGE"},
49  {RSTP_BDM_STATE_NOT_EDGE, "NOT_EDGE"}
50 };
51 
52 
53 /**
54  * @brief BDM state machine initialization
55  * @param[in] port Pointer to the bridge port context
56  **/
57 
59 {
60  //Enter initial state
61  if(rstpAdminEdge(port))
62  {
64  }
65  else
66  {
68  }
69 }
70 
71 
72 /**
73  * @brief BDM state machine implementation
74  * @param[in] port Pointer to the bridge port context
75  **/
76 
78 {
79  //All conditions for the current state are evaluated continuously until one
80  //of the conditions is met (refer to IEEE Std 802.1D-2004, section 17.16)
81  switch(port->bdmState)
82  {
83  //EDGE state?
85  //Evaluate conditions for the current state
86  if((!port->portEnabled && !rstpAdminEdge(port)) || !port->operEdge)
87  {
88  //Switch to NOT_EDGE state
90  }
91 
92  break;
93 
94  //NOT_EDGE state?
96  //Evaluate conditions for the current state
97  if((!port->portEnabled && rstpAdminEdge(port)) ||
98  (port->edgeDelayWhile == 0 && rstpAutoEdge(port) &&
99  port->sendRstp && port->proposing))
100  {
101  //Switch to EDGE state
103  }
104 
105  break;
106 
107  //Invalid state?
108  default:
109  //Just for sanity
110  rstpFsmError(port->context);
111  break;
112  }
113 }
114 
115 
116 /**
117  * @brief Update BDM state machine state
118  * @param[in] port Pointer to the bridge port context
119  * @param[in] newState New state to switch to
120  **/
121 
123 {
124  //Dump the state transition
125  TRACE_VERBOSE("Port %" PRIu8 ": BDM state machine %s -> %s\r\n",
126  port->portIndex,
129 
130  //Switch to the new state
131  port->bdmState = newState;
132 
133  //On entry to a state, the procedures defined for the state are executed
134  //exactly once (refer to IEEE Std 802.1D-2004, section 17.16)
135  switch(port->bdmState)
136  {
137  //EDGE state?
138  case RSTP_BDM_STATE_EDGE:
139  //Set operEdge flag
140  port->operEdge = TRUE;
141  break;
142 
143  //NOT_EDGE state?
145  //Clear operEdge flag
146  port->operEdge = FALSE;
147  break;
148 
149  //Invalid state?
150  default:
151  //Just for sanity
152  break;
153  }
154 
155  //The RSTP state machine is busy
156  port->context->busy = TRUE;
157 }
158 
159 #endif
RSTP state machine conditions.
#define TRUE
Definition: os_port.h:50
RSTP helper functions.
uint_t rstpAutoEdge(RstpBridgePort *port)
AutoEdge variable evaluation (17.20.2)
void rstpBdmChangeState(RstpBridgePort *port, RstpBdmState newState)
Update BDM state machine state.
Definition: rstp_bdm.c:122
#define FALSE
Definition: os_port.h:46
@ RSTP_BDM_STATE_NOT_EDGE
Definition: rstp_bdm.h:50
void rstpBdmFsm(RstpBridgePort *port)
BDM state machine implementation.
Definition: rstp_bdm.c:77
RSTP (Rapid Spanning Tree Protocol)
uint_t rstpAdminEdge(RstpBridgePort *port)
AdminEdge variable evaluation (17.20.1)
void rstpBdmInit(RstpBridgePort *port)
BDM state machine initialization.
Definition: rstp_bdm.c:58
uint16_t port
Definition: dns_common.h:267
void rstpFsmError(RstpBridgeContext *context)
RSTP state machine error handler.
Definition: rstp_fsm.c:226
@ RSTP_BDM_STATE_EDGE
Definition: rstp_bdm.h:49
Parameter value/name binding.
Definition: rstp_misc.h:48
RstpBdmState
Bridge Detection machine states.
Definition: rstp_bdm.h:48
Bridge Detection state machine (BDM)
const RstpParamName rstpBdmStates[]
Definition: rstp_bdm.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
Rapid Spanning Tree state machines.