rstp_tcm.c
Go to the documentation of this file.
1 /**
2  * @file rstp_tcm.c
3  * @brief Topology change state machine (TCM)
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_tcm.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 //TCM state machine's states
47 {
48  {RSTP_TCM_STATE_INACTIVE, "INACTIVE"},
49  {RSTP_TCM_STATE_LEARNING, "LEARNING"},
50  {RSTP_TCM_STATE_DETECTED, "DETECTED"},
51  {RSTP_TCM_STATE_NOTIFIED_TCN, "NOTIFIED_TCN"},
52  {RSTP_TCM_STATE_NOTIFIED_TC, "NOTIFIED_TC"},
53  {RSTP_TCM_STATE_PROPAGATING, "PROPAGATING"},
54  {RSTP_TCM_STATE_ACKNOWLEDGED, "ACKNOWLEDGED"},
55  {RSTP_TCM_STATE_ACTIVE, "ACTIVE"}
56 };
57 
58 
59 /**
60  * @brief TCM state machine initialization
61  * @param[in] port Pointer to the bridge port context
62  **/
63 
65 {
66  //Enter initial state
68 }
69 
70 
71 /**
72  * @brief TCM state machine implementation
73  * @param[in] port Pointer to the bridge port context
74  **/
75 
77 {
78  //All conditions for the current state are evaluated continuously until one
79  //of the conditions is met (refer to IEEE Std 802.1D-2004, section 17.16)
80  switch(port->tcmState)
81  {
82  //INACTIVE state?
84  //Evaluate conditions for the current state
85  if(port->learn && !port->fdbFlush)
86  {
87  //Switch to LEARNING state
89  }
90 
91  break;
92 
93  //LEARNING state?
95  //Evaluate conditions for the current state
96  if(port->rcvdTc || port->rcvdTcn || port->rcvdTcAck || port->tcProp)
97  {
98  //Switch to LEARNING state
100  }
101  else if((port->role == STP_PORT_ROLE_ROOT ||
102  port->role == STP_PORT_ROLE_DESIGNATED) &&
103  port->forward && !port->operEdge)
104  {
105  //Switch to DETECTED state
107  }
108  else if(port->role != STP_PORT_ROLE_ROOT &&
109  port->role != STP_PORT_ROLE_DESIGNATED &&
110  !(port->learn || port->learning) &&
111  !(port->rcvdTc || port->rcvdTcn || port->rcvdTcAck || port->tcProp))
112  {
113  //Switch to INACTIVE state
115  }
116  else
117  {
118  //Just for sanity
119  }
120 
121  break;
122 
123  //NOTIFIED_TCN state?
125  //Unconditional transition (UCT) to NOTIFIED_TC state
127  break;
128 
129  //DETECTED, NOTIFIED_TC, PROPAGATING or ACKNOWLEDGED state?
134  //Unconditional transition (UCT) to ACTIVE state
136  break;
137 
138  //ACTIVE state?
140  //Evaluate conditions for the current state
141  if((port->role != STP_PORT_ROLE_ROOT &&
142  port->role != STP_PORT_ROLE_DESIGNATED) || port->operEdge)
143  {
144  //Switch to LEARNING state
146  }
147  else if(port->rcvdTcn)
148  {
149  //Switch to NOTIFIED_TCN state
151  }
152  else if(port->rcvdTc)
153  {
154  //Switch to NOTIFIED_TC state
156  }
157  else if(port->tcProp && !port->operEdge)
158  {
159  //Switch to PROPAGATING state
161  }
162  else if(port->rcvdTcAck)
163  {
164  //Switch to ACKNOWLEDGED state
166  }
167  else
168  {
169  //Just for sanity
170  }
171 
172  break;
173 
174  //Invalid state?
175  default:
176  //Just for sanity
177  rstpFsmError(port->context);
178  break;
179  }
180 }
181 
182 
183 /**
184  * @brief Update TCM state machine state
185  * @param[in] port Pointer to the bridge port context
186  * @param[in] newState New state to switch to
187  **/
188 
190 {
191  //Dump the state transition
192  TRACE_VERBOSE("Port %" PRIu8 ": TCM state machine %s -> %s\r\n",
193  port->portIndex,
196 
197  //Switch to the new state
198  port->tcmState = newState;
199 
200  //On entry to a state, the procedures defined for the state are executed
201  //exactly once (refer to IEEE Std 802.1D-2004, section 17.16)
202  switch(port->tcmState)
203  {
204  //INACTIVE state?
206  port->fdbFlush = TRUE;
207  port->tcWhile = 0;
208  port->tcAck = FALSE;
209  break;
210 
211  //LEARNING state?
213  port->rcvdTc = FALSE;
214  port->rcvdTcn = FALSE;
215  port->rcvdTcAck = FALSE;
216  port->tcProp = FALSE;
217  break;
218 
219  //DETECTED state?
223  port->newInfo = TRUE;
224  break;
225 
226  //NOTIFIED_TCN state?
229  break;
230 
231  //NOTIFIED_TC state?
233  port->rcvdTcn = FALSE;
234  port->rcvdTc = FALSE;
235 
236  if(port->role == STP_PORT_ROLE_DESIGNATED)
237  {
238  port->tcAck = TRUE;
239  }
240 
241  //Errata (refer to IEEE Std 802.1Q-2018, section 13.39)
243  break;
244 
245  //PROPAGATING state?
248  port->fdbFlush = TRUE;
249  port->tcProp = FALSE;
250  break;
251 
252  //ACKNOWLEDGED state?
254  port->tcWhile = 0;
255  port->rcvdTcAck = FALSE;
256  break;
257 
258  //ACTIVE state?
260  //No procedure defined for this state
261  break;
262 
263  //Invalid state?
264  default:
265  //Just for sanity
266  break;
267  }
268 
269  //The RSTP state machine is busy
270  port->context->busy = TRUE;
271 }
272 
273 #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 rstpNewTcWhile(RstpBridgePort *port)
Update the value of tcWhile (17.21.7)
void rstpSetTcPropTree(RstpBridgePort *port)
Set tcProp for all ports except the port that called the procedure (17.21.18)
RSTP state machine procedures.
void rstpTcmChangeState(RstpBridgePort *port, RstpTcmState newState)
Update TCM state machine state.
Definition: rstp_tcm.c:189
void rstpTcmFsm(RstpBridgePort *port)
TCM state machine implementation.
Definition: rstp_tcm.c:76
void rstpTcmInit(RstpBridgePort *port)
TCM state machine initialization.
Definition: rstp_tcm.c:64
const RstpParamName rstpTcmStates[]
Definition: rstp_tcm.c:46
Topology change state machine (TCM)
RstpTcmState
Topology Change machine states.
Definition: rstp_tcm.h:48
@ RSTP_TCM_STATE_INACTIVE
Definition: rstp_tcm.h:49
@ RSTP_TCM_STATE_ACKNOWLEDGED
Definition: rstp_tcm.h:55
@ RSTP_TCM_STATE_ACTIVE
Definition: rstp_tcm.h:56
@ RSTP_TCM_STATE_LEARNING
Definition: rstp_tcm.h:50
@ RSTP_TCM_STATE_DETECTED
Definition: rstp_tcm.h:51
@ RSTP_TCM_STATE_NOTIFIED_TCN
Definition: rstp_tcm.h:52
@ RSTP_TCM_STATE_PROPAGATING
Definition: rstp_tcm.h:54
@ RSTP_TCM_STATE_NOTIFIED_TC
Definition: rstp_tcm.h:53
@ STP_PORT_ROLE_ROOT
Definition: stp_common.h:125
@ STP_PORT_ROLE_DESIGNATED
Definition: stp_common.h:126
Parameter value/name binding.
Definition: rstp_misc.h:48