lldp_mib_impl_stats.c
Go to the documentation of this file.
1 /**
2  * @file lldp_mib_impl_stats.c
3  * @brief LLDP MIB module implementation (lldpStatistics subtree)
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.4
29  **/
30 
31 //Switch to the appropriate trace level
32 #define TRACE_LEVEL SNMP_TRACE_LEVEL
33 
34 //Dependencies
35 #include "core/net.h"
36 #include "mibs/mib_common.h"
37 #include "mibs/lldp_mib_module.h"
38 #include "mibs/lldp_mib_impl.h"
40 #include "core/crypto.h"
41 #include "encoding/asn1.h"
42 #include "encoding/oid.h"
43 #include "lldp/lldp_mgmt.h"
44 #include "debug.h"
45 
46 //Check TCP/IP stack configuration
47 #if (LLDP_MIB_SUPPORT == ENABLED)
48 
49 
50 /**
51  * @brief Get lldpStatsRemTablesLastChangeTime object value
52  * @param[in] object Pointer to the MIB object descriptor
53  * @param[in] oid Object identifier (object name and instance identifier)
54  * @param[in] oidLen Length of the OID, in bytes
55  * @param[out] value Object value
56  * @param[in,out] valueLen Length of the object value, in bytes
57  * @return Error code
58  **/
59 
61  size_t oidLen, MibVariant *value, size_t *valueLen)
62 {
63  error_t error;
64  uint32_t statsRemTablesLastChangeTime;
65 
66  //This object indicates the time at which an entry was created, modified,
67  //or deleted in tables
69  &statsRemTablesLastChangeTime);
70 
71  //Check status code
72  if(!error)
73  {
74  //Return the value of the object
75  value->timeTicks = statsRemTablesLastChangeTime;
76  }
77 
78  //Return status code
79  return NO_ERROR;
80 }
81 
82 
83 /**
84  * @brief Get lldpStatsRemTablesInserts object value
85  * @param[in] object Pointer to the MIB object descriptor
86  * @param[in] oid Object identifier (object name and instance identifier)
87  * @param[in] oidLen Length of the OID, in bytes
88  * @param[out] value Object value
89  * @param[in,out] valueLen Length of the object value, in bytes
90  * @return Error code
91  **/
92 
94  size_t oidLen, MibVariant *value, size_t *valueLen)
95 {
96  error_t error;
97  uint32_t statsRemTablesInserts;
98 
99  //This object indicates the number of times the complete set of information
100  //advertised by a particular MSAP has been inserted into tables
102  &statsRemTablesInserts);
103 
104  //Check status code
105  if(!error)
106  {
107  //Return the value of the statistics counter
108  value->gauge32 = statsRemTablesInserts;
109  }
110 
111  //Return status code
112  return NO_ERROR;
113 }
114 
115 
116 /**
117  * @brief Get lldpStatsRemTablesDeletes object value
118  * @param[in] object Pointer to the MIB object descriptor
119  * @param[in] oid Object identifier (object name and instance identifier)
120  * @param[in] oidLen Length of the OID, in bytes
121  * @param[out] value Object value
122  * @param[in,out] valueLen Length of the object value, in bytes
123  * @return Error code
124  **/
125 
127  size_t oidLen, MibVariant *value, size_t *valueLen)
128 {
129  error_t error;
130  uint32_t statsRemTablesDeletes;
131 
132  //This object indicates the number of times the complete set of information
133  //advertised by a particular MSAP has been deleted from tables
135  &statsRemTablesDeletes);
136 
137  //Check status code
138  if(!error)
139  {
140  //Return the value of the statistics counter
141  value->gauge32 = statsRemTablesDeletes;
142  }
143 
144  //Return status code
145  return NO_ERROR;
146 }
147 
148 
149 /**
150  * @brief Get lldpStatsRemTablesDrops object value
151  * @param[in] object Pointer to the MIB object descriptor
152  * @param[in] oid Object identifier (object name and instance identifier)
153  * @param[in] oidLen Length of the OID, in bytes
154  * @param[out] value Object value
155  * @param[in,out] valueLen Length of the object value, in bytes
156  * @return Error code
157  **/
158 
160  size_t oidLen, MibVariant *value, size_t *valueLen)
161 {
162  error_t error;
163  uint32_t statsRemTablesDrops;
164 
165  //This object indicates the number of times the complete set of information
166  //advertised by a particular MSAP could not be entered into tables because
167  //of insufficient resources
169  &statsRemTablesDrops);
170 
171  //Check status code
172  if(!error)
173  {
174  //Return the value of the statistics counter
175  value->gauge32 = statsRemTablesDrops;
176  }
177 
178  //Return status code
179  return NO_ERROR;
180 }
181 
182 
183 /**
184  * @brief Get lldpStatsRemTablesAgeouts object value
185  * @param[in] object Pointer to the MIB object descriptor
186  * @param[in] oid Object identifier (object name and instance identifier)
187  * @param[in] oidLen Length of the OID, in bytes
188  * @param[out] value Object value
189  * @param[in,out] valueLen Length of the object value, in bytes
190  * @return Error code
191  **/
192 
194  size_t oidLen, MibVariant *value, size_t *valueLen)
195 {
196  error_t error;
197  uint32_t statsRemTablesAgeouts;
198 
199  //This object indicates the number of times the complete set of information
200  //advertised by a particular MSAP has been deleted from tables because the
201  //information timeliness interval has expired
203  &statsRemTablesAgeouts);
204 
205  //Check status code
206  if(!error)
207  {
208  //Return the value of the statistics counter
209  value->gauge32 = statsRemTablesAgeouts;
210  }
211 
212  //Return status code
213  return NO_ERROR;
214 }
215 
216 
217 /**
218  * @brief Get lldpStatsTxPortEntry object value
219  * @param[in] object Pointer to the MIB object descriptor
220  * @param[in] oid Object identifier (object name and instance identifier)
221  * @param[in] oidLen Length of the OID, in bytes
222  * @param[out] value Object value
223  * @param[in,out] valueLen Length of the object value, in bytes
224  * @return Error code
225  **/
226 
227 error_t lldpMibGetLldpStatsTxPortEntry(const MibObject *object, const uint8_t *oid,
228  size_t oidLen, MibVariant *value, size_t *valueLen)
229 {
230  error_t error;
231  size_t n;
232  uint32_t counter;
233  uint_t lldpStatsTxPortNum;
234 
235  //Initialize the value of the statistics counter
236  counter = 0;
237 
238  //Point to the instance identifier
239  n = object->oidLen;
240 
241  //lldpStatsTxPortNum is used as instance identifier
242  error = mibDecodeIndex(oid, oidLen, &n, &lldpStatsTxPortNum);
243  //Invalid instance identifier?
244  if(error)
245  return error;
246 
247  //Sanity check
248  if(n != oidLen)
250 
251  //lldpStatsTxPortFramesTotal object?
252  if(osStrcmp(object->name, "lldpStatsTxPortFramesTotal") == 0)
253  {
254  //This object indicates the number of LLDP frames transmitted by this
255  //LLDP agent on the indicated port
257  lldpStatsTxPortNum, &counter);
258  }
259  //Unknown object?
260  else
261  {
262  //The specified object does not exist
263  error = ERROR_OBJECT_NOT_FOUND;
264  }
265 
266  //Check status code
267  if(!error)
268  {
269  //Return the value of the statistics counter
270  value->counter32 = counter;
271  }
272 
273  //Return status code
274  return error;
275 }
276 
277 
278 /**
279  * @brief Get next lldpStatsTxPortEntry object
280  * @param[in] object Pointer to the MIB object descriptor
281  * @param[in] oid Object identifier
282  * @param[in] oidLen Length of the OID, in bytes
283  * @param[out] nextOid OID of the next object in the MIB
284  * @param[out] nextOidLen Length of the next object identifier, in bytes
285  * @return Error code
286  **/
287 
289  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
290 {
291  error_t error;
292  uint_t i;
293  size_t n;
294  uint16_t portNum;
295  uint16_t curPortNum;
296  LldpAgentContext *context;
297 
298  //Initialize variable
299  portNum = 0;
300 
301  //Point to the LLDP agent context
302  context = lldpMibBase.lldpAgentContext;
303  //Make sure the context is valid
304  if(context == NULL)
305  return ERROR_OBJECT_NOT_FOUND;
306 
307  //Make sure the buffer is large enough to hold the OID prefix
308  if(*nextOidLen < object->oidLen)
309  return ERROR_BUFFER_OVERFLOW;
310 
311  //Copy OID prefix
312  osMemcpy(nextOid, object->oid, object->oidLen);
313 
314  //Loop through the ports of the bridge
315  for(i = 0; i < context->numPorts; i++)
316  {
317  //Retrieve the port number associated with the current port
318  curPortNum = context->ports[i].portIndex;
319 
320  //Append the instance identifier to the OID prefix
321  n = object->oidLen;
322 
323  //lldpStatsTxPortNum is used as instance identifier
324  error = mibEncodeIndex(nextOid, *nextOidLen, &n, curPortNum);
325  //Any error to report?
326  if(error)
327  return error;
328 
329  //Check whether the resulting object identifier lexicographically
330  //follows the specified OID
331  if(oidComp(nextOid, n, oid, oidLen) > 0)
332  {
333  //Save the closest object identifier that follows the specified
334  //OID in lexicographic order
335  if(portNum == 0 || curPortNum < portNum)
336  {
337  portNum = curPortNum;
338  }
339  }
340  }
341 
342  //The specified OID does not lexicographically precede the name
343  //of some object?
344  if(portNum == 0)
345  return ERROR_OBJECT_NOT_FOUND;
346 
347  //Append the instance identifier to the OID prefix
348  n = object->oidLen;
349 
350  //lldpStatsTxPortNum is used as instance identifier
351  error = mibEncodeIndex(nextOid, *nextOidLen, &n, portNum);
352  //Any error to report?
353  if(error)
354  return error;
355 
356  //Save the length of the resulting object identifier
357  *nextOidLen = n;
358  //Next object found
359  return NO_ERROR;
360 }
361 
362 
363 /**
364  * @brief Get lldpStatsRxPortEntry object value
365  * @param[in] object Pointer to the MIB object descriptor
366  * @param[in] oid Object identifier (object name and instance identifier)
367  * @param[in] oidLen Length of the OID, in bytes
368  * @param[out] value Object value
369  * @param[in,out] valueLen Length of the object value, in bytes
370  * @return Error code
371  **/
372 
373 error_t lldpMibGetLldpStatsRxPortEntry(const MibObject *object, const uint8_t *oid,
374  size_t oidLen, MibVariant *value, size_t *valueLen)
375 {
376  error_t error;
377  size_t n;
378  uint32_t counter;
379  uint_t lldpStatsRxPortNum;
380 
381  //Initialize the value of the statistics counter
382  counter = 0;
383 
384  //Point to the instance identifier
385  n = object->oidLen;
386 
387  //lldpStatsRxPortNum is used as instance identifier
388  error = mibDecodeIndex(oid, oidLen, &n, &lldpStatsRxPortNum);
389  //Invalid instance identifier?
390  if(error)
391  return error;
392 
393  //Sanity check
394  if(n != oidLen)
396 
397  //lldpStatsRxPortFramesDiscardedTotal object?
398  if(osStrcmp(object->name, "lldpStatsRxPortFramesDiscardedTotal") == 0)
399  {
400  //This object indicates the number of LLDP frames received by this LLDP
401  //agent on the indicated port, and then discarded for any reason
403  lldpStatsRxPortNum, &counter);
404  }
405  //lldpStatsRxPortFramesErrors object?
406  else if(osStrcmp(object->name, "lldpStatsRxPortFramesErrors") == 0)
407  {
408  //This object indicates the number of invalid LLDP frames received by
409  //this LLDP agent on the indicated port, while this LLDP agent is enabled
411  lldpStatsRxPortNum, &counter);
412  }
413  //lldpStatsRxPortFramesTotal object?
414  else if(osStrcmp(object->name, "lldpStatsRxPortFramesTotal") == 0)
415  {
416  //This object indicates the number of valid LLDP frames received by this
417  //LLDP agent on the indicated port, while this LLDP agent is enabled
419  lldpStatsRxPortNum, &counter);
420  }
421  //lldpStatsRxPortTLVsDiscardedTotal object?
422  else if(osStrcmp(object->name, "lldpStatsRxPortTLVsDiscardedTotal") == 0)
423  {
424  //This object indicates the number of LLDP TLVs discarded for any reason
425  //by this LLDP agent on the indicated port
427  lldpStatsRxPortNum, &counter);
428  }
429  //lldpStatsRxPortTLVsUnrecognizedTotal object?
430  else if(osStrcmp(object->name, "lldpStatsRxPortTLVsUnrecognizedTotal") == 0)
431  {
432  //This object indicates the number of LLDP TLVs received on the given
433  //port that are not recognized by this LLDP agent
435  lldpStatsRxPortNum, &counter);
436  }
437  //lldpStatsRxPortAgeoutsTotal object?
438  else if(osStrcmp(object->name, "lldpStatsRxPortAgeoutsTotal") == 0)
439  {
440  //This object indicates the number of age-outs that occurred on a given
441  //port. An age-out is the number of times the complete set of information
442  //advertised by a particular MSAP has been deleted from tables contained
443  //in lldpRemoteSystemsData and lldpExtensions objects because the
444  //information timeliness interval has expired
446  lldpStatsRxPortNum, &counter);
447  }
448  //Unknown object?
449  else
450  {
451  //The specified object does not exist
452  error = ERROR_OBJECT_NOT_FOUND;
453  }
454 
455  //Check status code
456  if(!error)
457  {
458  //Return the value of the statistics counter
459  value->counter32 = counter;
460  }
461 
462  //Return status code
463  return error;
464 }
465 
466 
467 /**
468  * @brief Get next lldpStatsRxPortEntry object
469  * @param[in] object Pointer to the MIB object descriptor
470  * @param[in] oid Object identifier
471  * @param[in] oidLen Length of the OID, in bytes
472  * @param[out] nextOid OID of the next object in the MIB
473  * @param[out] nextOidLen Length of the next object identifier, in bytes
474  * @return Error code
475  **/
476 
478  size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
479 {
480  error_t error;
481  uint_t i;
482  size_t n;
483  uint16_t portNum;
484  uint16_t curPortNum;
485  LldpAgentContext *context;
486 
487  //Initialize variable
488  portNum = 0;
489 
490  //Point to the LLDP agent context
491  context = lldpMibBase.lldpAgentContext;
492  //Make sure the context is valid
493  if(context == NULL)
494  return ERROR_OBJECT_NOT_FOUND;
495 
496  //Make sure the buffer is large enough to hold the OID prefix
497  if(*nextOidLen < object->oidLen)
498  return ERROR_BUFFER_OVERFLOW;
499 
500  //Copy OID prefix
501  osMemcpy(nextOid, object->oid, object->oidLen);
502 
503  //Loop through the ports of the bridge
504  for(i = 0; i < context->numPorts; i++)
505  {
506  //Retrieve the port number associated with the current port
507  curPortNum = context->ports[i].portIndex;
508 
509  //Append the instance identifier to the OID prefix
510  n = object->oidLen;
511 
512  //lldpStatsRxPortNum is used as instance identifier
513  error = mibEncodeIndex(nextOid, *nextOidLen, &n, curPortNum);
514  //Any error to report?
515  if(error)
516  return error;
517 
518  //Check whether the resulting object identifier lexicographically
519  //follows the specified OID
520  if(oidComp(nextOid, n, oid, oidLen) > 0)
521  {
522  //Save the closest object identifier that follows the specified
523  //OID in lexicographic order
524  if(portNum == 0 || curPortNum < portNum)
525  {
526  portNum = curPortNum;
527  }
528  }
529  }
530 
531  //The specified OID does not lexicographically precede the name
532  //of some object?
533  if(portNum == 0)
534  return ERROR_OBJECT_NOT_FOUND;
535 
536  //Append the instance identifier to the OID prefix
537  n = object->oidLen;
538 
539  //lldpStatsRxPortNum is used as instance identifier
540  error = mibEncodeIndex(nextOid, *nextOidLen, &n, portNum);
541  //Any error to report?
542  if(error)
543  return error;
544 
545  //Save the length of the resulting object identifier
546  *nextOidLen = n;
547  //Next object found
548  return NO_ERROR;
549 }
550 
551 #endif
@ ERROR_BUFFER_OVERFLOW
Definition: error.h:142
error_t lldpMgmtGetStatsRemTablesAgeouts(LldpAgentContext *context, uint32_t *statsRemTablesAgeouts)
Get the value of the statsRemTablesAgeouts statistics counter.
Definition: lldp_mgmt.c:2102
OID (Object Identifier)
error_t lldpMibGetLldpStatsRemTablesInserts(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpStatsRemTablesInserts object value.
error_t lldpMibGetLldpStatsRemTablesAgeouts(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpStatsRemTablesAgeouts object value.
error_t lldpMgmtGetStatsAgeoutsTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsAgeoutsTotal)
Get the value of the statsAgeoutsTotal statistics counter.
Definition: lldp_mgmt.c:1951
#define osStrcmp(s1, s2)
Definition: os_port.h:171
LldpAgentContext * lldpAgentContext
error_t lldpMgmtGetStatsTLVsDiscardedTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsTLVsDiscardedTotal)
Get the value of the statsTLVsDiscardedTotal statistics counter.
Definition: lldp_mgmt.c:1876
error_t lldpMgmtGetStatsTLVsUnrecognizedTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsTLVsUnrecognizedTotal)
Get the value of the statsTLVsUnrecognizedTotal statistics counter.
Definition: lldp_mgmt.c:1914
int_t oidComp(const uint8_t *oid1, size_t oidLen1, const uint8_t *oid2, size_t oidLen2)
Compare object identifiers.
Definition: oid.c:103
uint8_t oid[]
Definition: lldp_tlv.h:300
#define osMemcpy(dest, src, length)
Definition: os_port.h:141
error_t lldpMgmtGetStatsRemTablesDrops(LldpAgentContext *context, uint32_t *statsRemTablesDrops)
Get the value of the statsRemTablesDrops statistics counter.
Definition: lldp_mgmt.c:2073
error_t
Error codes.
Definition: error.h:43
@ ERROR_INSTANCE_NOT_FOUND
Definition: error.h:257
LLDP MIB module.
error_t lldpMibGetNextLldpStatsRxPortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next lldpStatsRxPortEntry object.
error_t lldpMibGetLldpStatsRemTablesDrops(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpStatsRemTablesDrops object value.
General definitions for cryptographic algorithms.
error_t lldpMgmtGetStatsFramesInTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesInTotal)
Get the value of the statsFramesInTotal statistics counter.
Definition: lldp_mgmt.c:1838
error_t lldpMibGetLldpStatsTxPortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpStatsTxPortEntry object value.
error_t lldpMibGetLldpStatsRemTablesLastChangeTime(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpStatsRemTablesLastChangeTime object value.
error_t lldpMgmtGetStatsFramesDiscardedTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesDiscardedTotal)
Get the value of the statsFramesDiscardedTotal statistics counter.
Definition: lldp_mgmt.c:1762
error_t lldpMgmtGetStatsRemTablesLastChangeTime(LldpAgentContext *context, uint32_t *statsRemTablesLastChangeTime)
Get the value of the statsRemTablesLastChangeTime statistics counter.
Definition: lldp_mgmt.c:1988
error_t lldpMibGetLldpStatsRxPortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpStatsRxPortEntry object value.
error_t lldpMgmtGetStatsRemTablesDeletes(LldpAgentContext *context, uint32_t *statsRemTablesDeletes)
Get the value of the statsRemTablesDeletes statistics counter.
Definition: lldp_mgmt.c:2044
error_t mibDecodeIndex(const uint8_t *oid, size_t oidLen, size_t *pos, uint_t *index)
Decode instance identifier (index)
Definition: mib_common.c:64
error_t lldpMgmtGetStatsFramesOutTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesOutTotal)
Get the value of the statsFramesOutTotal statistics counter.
Definition: lldp_mgmt.c:1724
Common definitions for MIB modules.
uint8_t n
@ ERROR_OBJECT_NOT_FOUND
Definition: error.h:256
#define MibObject
Definition: mib_common.h:46
uint8_t value[]
Definition: tcp.h:369
uint8_t oidLen
Definition: lldp_tlv.h:299
#define LldpAgentContext
Definition: lldp.h:40
Management of the LLDP agent.
error_t mibEncodeIndex(uint8_t *oid, size_t maxOidLen, size_t *pos, uint_t index)
Encode instance identifier (index)
Definition: mib_common.c:47
LldpMibBase lldpMibBase
LLDP MIB base.
MibVariant
Definition: mib_common.h:196
error_t lldpMibGetNextLldpStatsTxPortEntry(const MibObject *object, const uint8_t *oid, size_t oidLen, uint8_t *nextOid, size_t *nextOidLen)
Get next lldpStatsTxPortEntry object.
error_t lldpMibGetLldpStatsRemTablesDeletes(const MibObject *object, const uint8_t *oid, size_t oidLen, MibVariant *value, size_t *valueLen)
Get lldpStatsRemTablesDeletes object value.
unsigned int uint_t
Definition: compiler_port.h:50
TCP/IP stack core.
LLDP MIB module implementation.
@ NO_ERROR
Success.
Definition: error.h:44
LLDP MIB module implementation (lldpStatistics subtree)
Debugging facilities.
ASN.1 (Abstract Syntax Notation One)
error_t lldpMgmtGetStatsRemTablesInserts(LldpAgentContext *context, uint32_t *statsRemTablesInserts)
Get the value of the statsRemTablesInserts statistics counter.
Definition: lldp_mgmt.c:2016
error_t lldpMgmtGetStatsFramesInErrorsTotal(LldpAgentContext *context, uint_t portIndex, uint32_t *statsFramesInErrorsTotal)
Get the value of the statsFramesInErrorsTotal statistics counter.
Definition: lldp_mgmt.c:1800