lldp_tx_fsm.c
Go to the documentation of this file.
1 /**
2  * @file lldp_tx_fsm.c
3  * @brief LLDP transmit state machine
4  *
5  * @section License
6  *
7  * SPDX-License-Identifier: GPL-2.0-or-later
8  *
9  * Copyright (C) 2010-2024 Oryx Embedded SARL. All rights reserved.
10  *
11  * This file is part of CycloneTCP 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 LLDP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "lldp/lldp.h"
37 #include "lldp/lldp_fsm.h"
38 #include "lldp/lldp_tx_fsm.h"
39 #include "lldp/lldp_procedures.h"
40 #include "lldp/lldp_debug.h"
41 #include "debug.h"
42 
43 //Check TCP/IP stack configuration
44 #if (LLDP_SUPPORT == ENABLED && LLDP_TX_MODE_SUPPORT == ENABLED)
45 
46 //LLDP transmit states
48 {
49  {LLDP_STATE_TX_LLDP_INITIALIZE, "TX_LLDP_INITIALIZE"},
50  {LLDP_STATE_TX_IDLE, "TX_IDLE"},
51  {LLDP_STATE_TX_SHUTDOWN_FRAME, "TX_SHUTDOWN_FRAME"},
52  {LLDP_STATE_TX_INFO_FRAME, "TX_INFO_FRAME"}
53 };
54 
55 
56 /**
57  * @brief LLDP transmit state machine initialization
58  * @param[in] port Pointer to the port context
59  **/
60 
62 {
63  //Enter initial state
65 }
66 
67 
68 /**
69  * @brief LLDP transmit state machine implementation
70  * @param[in] port Pointer to the port context
71  **/
72 
74 {
75  //A global transition can occur from any of the possible states
76  if(!port->portEnabled)
77  {
78  //When the condition associated with a global transition is met, it
79  //supersedes all other exit conditions
81  }
82  else
83  {
84  //All exit conditions for the state are evaluated continuously until one
85  //of the conditions is met (refer to IEEE Std 802.1AB-2005, section 10.4)
86  switch(port->txState)
87  {
88  //TX_LLDP_INITIALIZE state?
90  //LLDP transmit module initialization shall be halted until the variable
91  //portEnabled is equal to TRUE and the value of adminStatus is either
92  //enabledTxRx or enabledTxOnly
93  if(port->adminStatus == LLDP_ADMIN_STATUS_ENABLED_TX_RX ||
95  {
96  //Switch to the TX_IDLE state
98  }
99 
100  break;
101 
102  //TX_IDLE state?
103  case LLDP_STATE_TX_IDLE:
104  //Monitoring both somethingChangedLocal and txTTR to determine when a
105  //new transmission cycle is required
106  if(port->adminStatus == LLDP_ADMIN_STATUS_DISABLED ||
107  port->adminStatus == LLDP_ADMIN_STATUS_ENABLED_RX_ONLY)
108  {
109  //Switch to the TX_SHUTDOWN_FRAME state
111  }
112  else if(port->txDelayWhile == 0 && (port->txTTR == 0 ||
113  port->somethingChangedLocal))
114  {
115  //Switch to the TX_INFO_FRAME state
117  }
118  else
119  {
120  //Just for sanity
121  }
122 
123  break;
124 
125  //TX_SHUTDOWN_FRAME state?
127  //The txShutdownWhile timer indicates the number of seconds remaining
128  //until LLDP re-initialization can occur
129  if(port->txShutdownWhile == 0)
130  {
131  //Switch to the TX_LLDP_INITIALIZE state
133  }
134 
135  break;
136 
137  //TX_INFO_FRAME state?
139  //Unconditional transition (UCT) to TX_IDLE state
141  break;
142 
143  //Invalid state?
144  default:
145  //Just for sanity
146  lldpFsmError(port->context);
147  break;
148  }
149  }
150 }
151 
152 
153 /**
154  * @brief Update LLDP transmit state
155  * @param[in] port Pointer to the port context
156  * @param[in] newState New state to switch to
157  **/
158 
160 {
161  LldpAgentContext *context;
162 
163  //Point to the LLDP agent context
164  context = port->context;
165 
166  //Any state change?
167  if(port->txState != newState)
168  {
169  //Dump the state transition
170  TRACE_DEBUG("Port %" PRIu8 ": TX state machine %s -> %s\r\n",
171  port->portIndex,
174  }
175 
176  //Switch to the new state
177  port->txState = newState;
178 
179  //On entry to a state, the procedures defined for the state are executed
180  //exactly once (refer to IEEE Std 802.1AB-2005, section 10.4)
181  switch(port->txState)
182  {
183  //TX_LLDP_INITIALIZE state?
185  //Initialize the LLDP transmit module
187  break;
188 
189  //TX_IDLE state?
190  case LLDP_STATE_TX_IDLE:
191  //The txTTL variable indicates the time remaining before information in
192  //the outgoing LLDPDU will no longer be valid
193  port->txTTL = MIN(65535, context->msgTxInterval * context->msgTxHold);
194 
195  //When the LLDPDU is complete, the MIB manager shall re-initialize the
196  //txTTR timing counter in the LLDP local system MIB
197  port->txTTR = context->msgTxInterval;
198 
199  //The somethingChangedLocal variable indicates that the status/value of
200  //one or more of the selected objects in the LLDP local system MIB has
201  //changed
202  port->somethingChangedLocal = FALSE;
203 
204  //The txDelayWhile timer introduces a minimum delay between transmission
205  //of successive LLDP frames
206  port->txDelayWhile = context->txDelay;
207  break;
208 
209  //TX_SHUTDOWN_FRAME state?
211  //Construct a shutdown LLDPDU
213  //Send the LLDPDU to the MAC for transmission
214  lldpTxFrame(port);
215 
216  //The txShutdownWhile timer indicates the number of seconds remaining
217  //until LLDP re-initialization can occur
218  port->txShutdownWhile = context->reinitDelay;
219  break;
220 
221  //TX_INFO_FRAME state?
223  //Construct an information LLDPDU
225  //Send the LLDPDU to the MAC for transmission
226  lldpTxFrame(port);
227  break;
228 
229  //Invalid state?
230  default:
231  //Just for sanity
232  break;
233  }
234 
235  //Check whether the port is enabled
236  if(port->portEnabled)
237  {
238  //The LLDP state machine is busy
239  port->context->busy = TRUE;
240  }
241 }
242 
243 #endif
Debugging facilities.
#define TRACE_DEBUG(...)
Definition: debug.h:107
uint16_t port
Definition: dns_common.h:267
LLDP (Link Layer Discovery Protocol)
#define LldpPortEntry
Definition: lldp.h:44
@ LLDP_ADMIN_STATUS_ENABLED_TX_RX
Definition: lldp.h:191
@ LLDP_ADMIN_STATUS_ENABLED_RX_ONLY
The local LLDP agent can only receive LLDP frames.
Definition: lldp.h:190
@ LLDP_ADMIN_STATUS_DISABLED
The local LLDP agent can neither transmit or receive LLDP frames.
Definition: lldp.h:188
@ LLDP_ADMIN_STATUS_ENABLED_TX_ONLY
The local LLDP agent can only transmit LLDP frames.
Definition: lldp.h:189
#define LldpAgentContext
Definition: lldp.h:40
const char_t * lldpGetParamName(uint_t value, const LldpParamName *paramList, size_t paramListLen)
Convert a parameter to string representation.
Definition: lldp_debug.c:245
Data logging functions for debugging purpose (LLDP)
void lldpFsmError(LldpAgentContext *context)
LLDP state machine error handler.
Definition: lldp_fsm.c:128
LLDP state machine.
void lldpMibConstrInfoLldpdu(LldpPortEntry *port)
Construct an information LLDPDU (10.5.4.2.1)
void lldpTxFrame(LldpPortEntry *port)
Send an LLDPDU to the MAC for transmission (10.5.4.2.3)
void lldpTxInitializeLLDP(LldpPortEntry *port)
Initialize the LLDP transmit module (10.5.4.2.3)
void lldpMibConstrShutdownLldpdu(LldpPortEntry *port)
Construct a shutdown LLDPDU (10.5.4.2.2)
LLDP state machine procedures.
const LldpParamName lldpTxStates[]
Definition: lldp_tx_fsm.c:47
void lldpInitTxFsm(LldpPortEntry *port)
LLDP transmit state machine initialization.
Definition: lldp_tx_fsm.c:61
void lldpChangeTxState(LldpPortEntry *port, LldpTxState newState)
Update LLDP transmit state.
Definition: lldp_tx_fsm.c:159
void lldpTxFsm(LldpPortEntry *port)
LLDP transmit state machine implementation.
Definition: lldp_tx_fsm.c:73
LLDP transmit state machine.
LldpTxState
LLDP transmit states.
Definition: lldp_tx_fsm.h:49
@ LLDP_STATE_TX_INFO_FRAME
Definition: lldp_tx_fsm.h:53
@ LLDP_STATE_TX_LLDP_INITIALIZE
Definition: lldp_tx_fsm.h:50
@ LLDP_STATE_TX_IDLE
Definition: lldp_tx_fsm.h:51
@ LLDP_STATE_TX_SHUTDOWN_FRAME
Definition: lldp_tx_fsm.h:52
TCP/IP stack core.
#define MIN(a, b)
Definition: os_port.h:63
#define arraysize(a)
Definition: os_port.h:71
#define TRUE
Definition: os_port.h:50
#define FALSE
Definition: os_port.h:46
Parameter value/name binding.
Definition: lldp_debug.h:49