mikroSDK Reference Manual
lldp.h
Go to the documentation of this file.
1
31#ifndef _LLDP_H
32#define _LLDP_H
33
34//Forward declaration of LldpDataUnit structure
35struct _LldpDataUnit;
36#define LldpDataUnit struct _LldpDataUnit
37
38//Forward declaration of LldpAgentContext structure
40#define LldpAgentContext struct _LldpAgentContext
41
42//Forward declaration of LldpPortEntry structure
43struct _LldpPortEntry;
44#define LldpPortEntry struct _LldpPortEntry
45
46//Dependencies
47#include "core/net.h"
48#include "lldp/lldp_rx_fsm.h"
49#include "lldp/lldp_tx_fsm.h"
50#include "lldp/lldp_tlv.h"
51
52//LLDP agent support
53#ifndef LLDP_SUPPORT
54 #define LLDP_SUPPORT DISABLED
55#elif (LLDP_SUPPORT != ENABLED && LLDP_SUPPORT != DISABLED)
56 #error LLDP_SUPPORT parameter is not valid
57#endif
58
59//LLDP TX mode support
60#ifndef LLDP_TX_MODE_SUPPORT
61 #define LLDP_TX_MODE_SUPPORT ENABLED
62#elif (LLDP_TX_MODE_SUPPORT != ENABLED && LLDP_TX_MODE_SUPPORT != DISABLED)
63 #error LLDP_TX_MODE_SUPPORT parameter is not valid
64#endif
65
66//LLDP RX mode support
67#ifndef LLDP_RX_MODE_SUPPORT
68 #define LLDP_RX_MODE_SUPPORT ENABLED
69#elif (LLDP_RX_MODE_SUPPORT != ENABLED && LLDP_RX_MODE_SUPPORT != DISABLED)
70 #error LLDP_RX_MODE_SUPPORT parameter is not valid
71#endif
72
73//Stack size required to run the LLDP agent
74#ifndef LLDP_TASK_STACK_SIZE
75 #define LLDP_TASK_STACK_SIZE 500
76#elif (LLDP_TASK_STACK_SIZE < 1)
77 #error LLDP_TASK_STACK_SIZE parameter is not valid
78#endif
79
80//Priority at which the LLDP agent should run
81#ifndef LLDP_TASK_PRIORITY
82 #define LLDP_TASK_PRIORITY OS_TASK_PRIORITY_NORMAL
83#endif
84
85//LLDP tick interval (in milliseconds)
86#ifndef LLDP_TICK_INTERVAL
87 #define LLDP_TICK_INTERVAL 1000
88#elif (LLDP_TICK_INTERVAL < 10)
89 #error LLDP_TICK_INTERVAL parameter is not valid
90#endif
91
92//Maximum LLDP data unit size
93#ifndef LLDP_MAX_LLDPDU_SIZE
94 #define LLDP_MAX_LLDPDU_SIZE 500
95#elif (LLDP_MAX_LLDPDU_SIZE < 100 || LLDP_MAX_LLDPDU_SIZE > 1500)
96 #error LLDP_MAX_LLDPDU_SIZE parameter is not valid
97#endif
98
99//Maximum number of management addresses
100#ifndef LLDP_MAX_MGMT_ADDRS
101 #define LLDP_MAX_MGMT_ADDRS 10
102#elif (LLDP_MAX_MGMT_ADDRS < 1 || LLDP_MAX_MGMT_ADDRS > 32)
103 #error LLDP_MAX_MGMT_ADDRS parameter is not valid
104#endif
105
106//Minimum msgTxInterval value
107#define LLDP_MIN_MSG_TX_INTERVAL 1
108//Default msgTxInterval value
109#define LLDP_DEFAULT_MSG_TX_INTERVAL 30
110//Maximum msgTxInterval value
111#define LLDP_MAX_MSG_TX_INTERVAL 3600
112
113//Minimum msgTxHold value
114#define LLDP_MIN_MSG_TX_HOLD 1
115//Default msgTxHold value
116#define LLDP_DEFAULT_MSG_TX_HOLD 4
117//Maximum msgTxHold value
118#define LLDP_MAX_MSG_TX_HOLD 100
119
120//Minimum reinitDelay value
121#define LLDP_MIN_REINIT_DELAY 1
122//Default reinitDelay value
123#define LLDP_DEFAULT_REINIT_DELAY 2
124//Maximum reinitDelay value
125#define LLDP_MAX_REINIT_DELAY 10
126
127//Minimum txDelay value
128#define LLDP_MIN_TX_DELAY 1
129//Default txDelay value
130#define LLDP_DEFAULT_TX_DELAY 2
131//Maximum txDelay value
132#define LLDP_MAX_TX_DELAY 900
133
134//Minimum notification interval
135#define LLDP_MIN_NOTIFICATION_INTERVAL 5
136//Default notification interval
137#define LLDP_DEFAULT_NOTIFICATION_INTERVAL 5
138//Maximum notification interval
139#define LLDP_MAX_NOTIFICATION_INTERVAL 3600
140
141//Management address filter
142#define LLDP_MGMT_ADDR_FILTER_0 0x00000001
143#define LLDP_MGMT_ADDR_FILTER_1 0x00000002
144#define LLDP_MGMT_ADDR_FILTER_2 0x00000004
145#define LLDP_MGMT_ADDR_FILTER_3 0x00000008
146#define LLDP_MGMT_ADDR_FILTER_4 0x00000010
147#define LLDP_MGMT_ADDR_FILTER_5 0x00000020
148#define LLDP_MGMT_ADDR_FILTER_6 0x00000040
149#define LLDP_MGMT_ADDR_FILTER_7 0x00000080
150#define LLDP_MGMT_ADDR_FILTER_8 0x00000100
151#define LLDP_MGMT_ADDR_FILTER_9 0x00000200
152#define LLDP_MGMT_ADDR_FILTER_10 0x00000400
153#define LLDP_MGMT_ADDR_FILTER_11 0x00000800
154#define LLDP_MGMT_ADDR_FILTER_12 0x00001000
155#define LLDP_MGMT_ADDR_FILTER_13 0x00002000
156#define LLDP_MGMT_ADDR_FILTER_14 0x00004000
157#define LLDP_MGMT_ADDR_FILTER_15 0x00008000
158#define LLDP_MGMT_ADDR_FILTER_16 0x00010000
159#define LLDP_MGMT_ADDR_FILTER_17 0x00020000
160#define LLDP_MGMT_ADDR_FILTER_18 0x00040000
161#define LLDP_MGMT_ADDR_FILTER_19 0x00080000
162#define LLDP_MGMT_ADDR_FILTER_20 0x00100000
163#define LLDP_MGMT_ADDR_FILTER_21 0x00200000
164#define LLDP_MGMT_ADDR_FILTER_22 0x00400000
165#define LLDP_MGMT_ADDR_FILTER_23 0x00800000
166#define LLDP_MGMT_ADDR_FILTER_24 0x01000000
167#define LLDP_MGMT_ADDR_FILTER_25 0x02000000
168#define LLDP_MGMT_ADDR_FILTER_26 0x04000000
169#define LLDP_MGMT_ADDR_FILTER_27 0x08000000
170#define LLDP_MGMT_ADDR_FILTER_28 0x10000000
171#define LLDP_MGMT_ADDR_FILTER_29 0x20000000
172#define LLDP_MGMT_ADDR_FILTER_30 0x40000000
173#define LLDP_MGMT_ADDR_FILTER_31 0x80000000
174#define LLDP_MGMT_ADDR_FILTER_ALL 0xFFFFFFFF
175
176//C++ guard
177#ifdef __cplusplus
178extern "C" {
179#endif
180
181
186typedef enum
187{
191 LLDP_ADMIN_STATUS_ENABLED_TX_RX = 3,
193
194
207
208
213typedef void (*LldpSendCallback)(LldpPortEntry *port, LldpDataUnit *lldpdu);
214
215
220typedef void (*LldpReceiveCallback)(LldpPortEntry *port, LldpDataUnit *lldpdu);
221
222
227typedef void (*LldpTickCallback)(LldpAgentContext *context);
228
229
235{
236 uint8_t data[LLDP_MAX_LLDPDU_SIZE];
237 size_t length;
238 size_t pos;
239};
240
241
246typedef struct
247{
248 const uint8_t *chassisId;
250 const uint8_t *portId;
251 size_t portIdLen;
252} LldpMsapId;
253
254
259typedef struct
260{
261 uint32_t index;
262 uint32_t timeMark;
263 uint_t portIndex;
264 uint_t rxInfoTTL;
265 LldpDataUnit rxInfo;
267
268
274{
275 LldpAgentContext *context;
276 uint8_t portIndex;
278 bool_t portEnabled;
279
280#if (LLDP_TX_MODE_SUPPORT == ENABLED)
281 MacAddr macAddr;
282 LldpDataUnit txInfo;
284 uint32_t mgmtAddrFilter;
288 uint_t txTTR;
290 uint_t txTTL;
293#endif
294
295#if (LLDP_RX_MODE_SUPPORT == ENABLED)
298 bool_t rcvFrame;
299 uint_t rxInfoAge;
306#endif
307};
308
309
325
326
332{
333 NetInterface *interface;
334 uint_t numPorts;
335 LldpPortEntry *ports;
341
342 bool_t running;
343 bool_t stop;
347#if (OS_STATIC_TASK_SUPPORT == ENABLED)
348 OsTaskTcb taskTcb;
349 OsStackType taskStack[LLDP_TASK_STACK_SIZE];
350#endif
351 Socket *socket;
353 LldpDataUnit lldpdu;
354
355#if (LLDP_TX_MODE_SUPPORT == ENABLED)
356 LldpDataUnit txInfo;
358 uint_t msgTxHold;
359 uint_t reinitDelay;
360 uint_t txDelay;
361 uint32_t mgmtAddrMap;
362#endif
363
364#if (LLDP_RX_MODE_SUPPORT == ENABLED)
365 uint32_t index;
368 bool_t badFrame;
369 bool_t rxChanges;
370 uint_t rxTTL;
373 uint32_t statsRemTablesLastChangeTime;
374 uint32_t statsRemTablesInserts;
375 uint32_t statsRemTablesDeletes;
376 uint32_t statsRemTablesDrops;
377 uint32_t statsRemTablesAgeouts;
378#endif
379
380 bool_t busy;
381};
382
383
384//LLDP agent related functions
385void lldpGetDefaultSettings(LldpAgentSettings *settings);
386
387error_t lldpInit(LldpAgentContext *context,
388 const LldpAgentSettings *settings);
389
390error_t lldpStart(LldpAgentContext *context);
391error_t lldpStop(LldpAgentContext *context);
392
393error_t lldpSetPortAddr(LldpAgentContext *context, uint_t portIndex,
394 const MacAddr *macAddr);
395
396error_t lldpSetAdminStatus(LldpAgentContext *context, uint_t portIndex,
397 LldpAdminStatus adminStatus);
398
399error_t lldpSetBasicTlvFilter(LldpAgentContext *context, uint_t portIndex,
400 uint8_t mask);
401
402error_t lldpSetMgmtAddrFilter(LldpAgentContext *context, uint_t portIndex,
403 uint32_t mask);
404
405error_t lldpSetMsgTxInterval(LldpAgentContext *context, uint_t msgTxInterval);
406error_t lldpSetMsgTxHold(LldpAgentContext *context, uint_t msgTxHold);
407error_t lldpSetReinitDelay(LldpAgentContext *context, uint_t reinitDelay);
408error_t lldpSetTxDelay(LldpAgentContext *context, uint_t txDelay);
409
410error_t lldpSetLocalChassisId(LldpAgentContext *context,
411 LldpChassisIdSubtype chassisIdSubtype, const void *chassisId,
412 size_t chassisIdLen);
413
414error_t lldpSetLocalPortId(LldpAgentContext *context, uint_t portIndex,
415 LldpPortIdSubtype portIdSubtype, const void *portId, size_t portIdLen);
416
417error_t lldpSetLocalPortDesc(LldpAgentContext *context, uint_t portIndex,
418 const char_t *portDesc);
419
420error_t lldpSetLocalSysName(LldpAgentContext *context, const char_t *sysName);
421error_t lldpSetLocalSysDesc(LldpAgentContext *context, const char_t *sysDesc);
422
423error_t lldpSetLocalSysCap(LldpAgentContext *context, uint16_t supportedCap,
424 uint16_t enabledCap);
425
426error_t lldpSetLocalMgmtAddr(LldpAgentContext *context, uint_t index,
427 LldpMgmtAddrSubtype mgmtAddrSubtype, const void *mgmtAddr,
428 size_t mgmtAddrLen, LldpIfNumSubtype ifNumSubtype, uint32_t ifNum,
429 const uint8_t *oid, size_t oidLen);
430
431error_t lldpDeleteLocalTlv(LldpAgentContext *context, LldpTlvType type);
432
433void lldpTask(LldpAgentContext *context);
434
435void lldpDeinit(LldpAgentContext *context);
436
437//C++ guard
438#ifdef __cplusplus
439}
440#endif
441
442#endif
error_t
Error codes.
Definition error.h:43
void(* LldpSendCallback)(LldpPortEntry *port, LldpDataUnit *lldpdu)
LLDP frame transmission callback function.
Definition lldp.h:213
void(* LldpReceiveCallback)(LldpPortEntry *port, LldpDataUnit *lldpdu)
LLDP frame reception callback function.
Definition lldp.h:220
LldpAdminStatus
Administrative status.
Definition lldp.h:187
@ 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
LldpBasicTlvFilter
Basic TLV filter.
Definition lldp.h:200
@ LLDP_BASIC_TLV_FILTER_SYS_NAME
System Name TLV.
Definition lldp.h:202
@ LLDP_BASIC_TLV_FILTER_SYS_DESC
System Description TLV.
Definition lldp.h:203
@ LLDP_BASIC_TLV_FILTER_ALL
All Basic TLVs.
Definition lldp.h:205
@ LLDP_BASIC_TLV_FILTER_SYS_CAP
System Capabilities TLV.
Definition lldp.h:204
@ LLDP_BASIC_TLV_FILTER_PORT_DESC
Port Description TLV.
Definition lldp.h:201
void(* LldpTickCallback)(LldpAgentContext *context)
Tick callback function.
Definition lldp.h:227
LLDP receive state machine.
LldpRxState
LLDP receive states.
Definition lldp_rx_fsm.h:49
TLV parsing and formatting.
LldpMgmtAddrSubtype
Management address subtypes.
Definition lldp_tlv.h:162
LldpPortIdSubtype
Port ID subtypes.
Definition lldp_tlv.h:128
LldpChassisIdSubtype
Chassis ID subtypes.
Definition lldp_tlv.h:111
LldpIfNumSubtype
Interface numbering subtypes.
Definition lldp_tlv.h:175
LldpTlvType
TLV type values.
Definition lldp_tlv.h:92
LLDP transmit state machine.
LldpTxState
LLDP transmit states.
Definition lldp_tx_fsm.h:49
TCP/IP stack core.
uint_t OsMutex
Mutex object.
Definition os_port_none.h:118
uint_t OsEvent
Event object.
Definition os_port_none.h:104
uint_t OsTaskId
Task identifier.
Definition os_port_none.h:97
uint32_t systime_t
System time.
Definition os_port_none.h:90
LLDP agent settings.
Definition lldp.h:315
LldpSendCallback sendCallback
LLDP frame transmission callback function.
Definition lldp.h:321
NetInterface * interface
Network interface to configure.
Definition lldp.h:316
LldpPortEntry * ports
Port table.
Definition lldp.h:318
uint_t numNeighbors
Maximum number of entries in the neighbor table.
Definition lldp.h:319
uint_t numPorts
Number of ports.
Definition lldp.h:317
LldpTickCallback tickCallback
Tick callback function.
Definition lldp.h:323
LldpNeighborEntry * neighbors
Neighbor table.
Definition lldp.h:320
LldpReceiveCallback receiveCallback
LLDP frame reception callback function.
Definition lldp.h:322
MSAP identifier.
Definition lldp.h:247
size_t chassisIdLen
Length of the chassis identifier, in bytes.
Definition lldp.h:249
const uint8_t * chassisId
Chassis identifier.
Definition lldp.h:248
const uint8_t * portId
Port identifier.
Definition lldp.h:250
size_t portIdLen
Length of the port identifier, in bytes.
Definition lldp.h:251
LLDP neighbor entry.
Definition lldp.h:260
uint_t rxInfoTTL
Time remaining until the information is no longer valid.
Definition lldp.h:264
LldpDataUnit rxInfo
Remote system information.
Definition lldp.h:265
uint_t portIndex
Port on which the LLDPDU was received.
Definition lldp.h:263
uint32_t index
Arbitrary local integer value used to identify the entry.
Definition lldp.h:261
uint32_t timeMark
Timestamp used to implement time-filtered rows.
Definition lldp.h:262
LLDP agent context.
Definition lldp.h:332
LldpTickCallback tickCallback
Tick callback function.
Definition lldp.h:340
OsStackType taskStack[LLDP_TASK_STACK_SIZE]
Task stack.
Definition lldp.h:349
bool_t rxChanges
The incoming LLDPDU has been received with different TLV values.
Definition lldp.h:369
OsTaskId taskId
Task identifier.
Definition lldp.h:346
bool_t busy
Busy flag.
Definition lldp.h:380
OsTaskTcb taskTcb
Task control block.
Definition lldp.h:348
bool_t tooManyNeighbors
Insufficient space to store information from all neighbors.
Definition lldp.h:372
bool_t running
This flag tells whether the LLDP agent is running or not.
Definition lldp.h:342
NetInterface * interface
Underlying network interface.
Definition lldp.h:333
LldpDataUnit txInfo
Local system information.
Definition lldp.h:356
bool_t stop
Stop request.
Definition lldp.h:343
bool_t somethingChangedRemote
Per-MSAP variable set after all the information has been updated.
Definition lldp.h:371
LldpSendCallback sendCallback
LLDP frame transmission callback function.
Definition lldp.h:338
systime_t timestamp
Timestamp to manage timeout.
Definition lldp.h:352
uint_t rxTTL
The TTL extracted from the received LLDPDU.
Definition lldp.h:370
bool_t badFrame
Incoming failed validation and was discarded.
Definition lldp.h:368
LldpDataUnit lldpdu
Incoming/outgoing LLDP data unit.
Definition lldp.h:353
OsMutex mutex
Mutex preventing simultaneous access to LLDP agent context.
Definition lldp.h:344
LldpReceiveCallback receiveCallback
LLDP frame reception callback function.
Definition lldp.h:339
uint_t numPorts
Number of ports.
Definition lldp.h:334
uint32_t index
Monotonically increasing index used to identify entries.
Definition lldp.h:365
uint_t txDelay
Delay between successive LLDP frame transmissions.
Definition lldp.h:360
uint_t msgTxInterval
Interval at which LLDP frames are transmitted.
Definition lldp.h:357
uint_t msgTxHold
Transmit hold multiplier.
Definition lldp.h:358
LldpPortEntry * ports
Port table.
Definition lldp.h:335
uint32_t mgmtAddrMap
Bit-map indicating the management addresses that are configured.
Definition lldp.h:361
uint_t tooManyNeighborsTimer
Too many neighbors timer.
Definition lldp.h:367
LldpNeighborEntry * neighbors
Neighbor table.
Definition lldp.h:337
uint_t reinitDelay
Delay before re-initialization will be attempted.
Definition lldp.h:359
Socket * socket
Underlying socket.
Definition lldp.h:351
uint_t numNeighbors
Maximum number of entries in the neighbor table.
Definition lldp.h:336
OsEvent event
Event object used to poll the underlying socket.
Definition lldp.h:345
uint_t notificationInterval
Notification interval.
Definition lldp.h:366
LLDP data unit.
Definition lldp.h:235
LLDP port entry.
Definition lldp.h:274
uint32_t statsFramesInTotal
Count of all LLDP frames received.
Definition lldp.h:302
uint_t txTTR
Transmit time to refresh timer.
Definition lldp.h:288
uint8_t basicTlvFilter
Bit-map indicating the basic TLVs enabled for transmission.
Definition lldp.h:283
bool_t rcvFrame
An LLDP frame has been recognized by the LLDP LSAP function.
Definition lldp.h:298
uint_t txDelayWhile
Minimum delay between transmission of successive LLDP frames.
Definition lldp.h:287
uint32_t mgmtAddrFilter
Bit-map indicating the management addresses enabled for transmission.
Definition lldp.h:284
bool_t notificationEnable
Enable or disable notifications.
Definition lldp.h:297
uint32_t statsTLVsDiscardedTotal
Count of all TLVs received and then discarded for any reason.
Definition lldp.h:303
uint32_t statsFramesDiscardedTotal
Count of all LLDPDUs received and then discarded.
Definition lldp.h:300
LldpRxState rxState
LLDP receive state.
Definition lldp.h:296
bool_t portEnabled
Operational state of the MAC service supporting the port.
Definition lldp.h:278
uint32_t lldpduLengthErrors
The number of LLDPDU length errors recorded for the port.
Definition lldp.h:292
LldpDataUnit txInfo
Local system information.
Definition lldp.h:282
LldpAdminStatus adminStatus
Indicates whether the local LLDP agent is enabled.
Definition lldp.h:277
uint32_t statsTLVsUnrecognizedTotal
Count of all TLVs received on the port that are not recognized.
Definition lldp.h:304
LldpAgentContext * context
LLDP agent context.
Definition lldp.h:275
bool_t somethingChangedLocal
Status/value of one or more objects in the LLDP local system MIB has changed.
Definition lldp.h:289
uint_t txTTL
Time remaining before information in the outgoing LLDPDU will no longer be valid.
Definition lldp.h:290
uint_t txShutdownWhile
Number of seconds remaining until LLDP re-initialization can occur.
Definition lldp.h:286
uint_t rxInfoAge
The rxInfoTTL timing counter has expired.
Definition lldp.h:299
LldpTxState txState
LLDP transmit state.
Definition lldp.h:285
uint8_t portIndex
Port index.
Definition lldp.h:276
uint32_t statsFramesInErrorsTotal
Count of all LLDPDUs received with one or more detectable errors.
Definition lldp.h:301
MacAddr macAddr
MAC address of the port.
Definition lldp.h:281
uint32_t statsFramesOutTotal
Count of all LLDP frames transmitted.
Definition lldp.h:291
uint32_t statsAgeoutsTotal
Count of the times that a neighbor's information has been aged out.
Definition lldp.h:305