RDK Documentation (Open Sourced RDK Components)
Device_IP_Interface_Stats.cpp
1 /*
2  * If not stated otherwise in this file or this component's Licenses.txt file the
3  * following copyright and licenses apply:
4  *
5  * Copyright 2016 RDK Management
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18 */
19 
20 /**
21  * @file Device_IP_Interface_Statss.cpp
22  * @brief This source file contains the APIs of device IPv4 interface stats.
23  */
24 
25 /*****************************************************************************
26  * STANDARD INCLUDE FILES
27  *****************************************************************************/
28 
29 
30 
31 /**
32 * @defgroup tr69hostif
33 * @{
34 * @defgroup hostif
35 * @{
36 **/
37 
38 
39 #include <sys/sysinfo.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
42 #include <sys/types.h>
43 #include <net/if.h>
44 #include <arpa/inet.h>
46 #include "Device_IP.h"
47 
48 
49 IPInterfaceStats hostIf_IPInterfaceStats::curntIpStat = {0,};
50 
51 GMutex* hostIf_IPInterfaceStats::m_mutex = NULL;
52 
53 GHashTable *hostIf_IPInterfaceStats::ifHash = NULL;
54 
55 
56 void hostIf_IPInterfaceStats::refreshInterfaceName ()
57 {
58  nameOfInterface[0] = 0;
59  if (NULL == hostIf_IP::getInterfaceName (dev_id, nameOfInterface))
60  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "%s: error getting interface name for Device.IP.Interface.%d\n", __FUNCTION__, dev_id);
61 }
62 
63 hostIf_IPInterfaceStats* hostIf_IPInterfaceStats::getInstance(int dev_id)
64 {
65  hostIf_IPInterfaceStats* pRet = NULL;
66 
67  if(ifHash)
68  {
69  pRet = (hostIf_IPInterfaceStats *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
70  }
71  else
72  {
73  ifHash = g_hash_table_new(NULL,NULL);
74  }
75 
76  if(!pRet)
77  {
78  try {
79  pRet = new hostIf_IPInterfaceStats(dev_id);
80  } catch(int e)
81  {
82  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create hostIf_IPInterfaceStats instance..\n");
83  }
84  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
85  }
86 
87  // make sure returned instance has interface name set
88  if (pRet)
89  pRet->refreshInterfaceName ();
90 
91  return pRet;
92 }
93 
94 GList* hostIf_IPInterfaceStats::getAllInstances()
95 {
96  if(ifHash)
97  return g_hash_table_get_keys(ifHash);
98  return NULL;
99 }
100 
101 void hostIf_IPInterfaceStats::closeInstance(hostIf_IPInterfaceStats *pDev)
102 {
103  if(pDev)
104  {
105  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
106  delete pDev;
107  }
108 }
109 
110 void hostIf_IPInterfaceStats::closeAllInstances()
111 {
112  if(ifHash)
113  {
114  GList* tmp_list = g_hash_table_get_values (ifHash);
115 
116  while(tmp_list)
117  {
118  hostIf_IPInterfaceStats* pDev = (hostIf_IPInterfaceStats *)tmp_list->data;
119  tmp_list = tmp_list->next;
120  closeInstance(pDev);
121  }
122  }
123 }
124 
125 void hostIf_IPInterfaceStats::getLock()
126 {
127  if(!m_mutex)
128  {
129  m_mutex = g_mutex_new();
130  }
131  g_mutex_lock(m_mutex);
132 }
133 
134 void hostIf_IPInterfaceStats::releaseLock()
135 {
136  g_mutex_unlock(m_mutex);
137 }
138 
139 /**
140  * @brief Class Constructor of the class hostIf_IPInterfaceStats.
141  *
142  * It will initialize the device id.
143  *
144  * @param[in] dev_id Identification number of the device to communicate.
145  */
147  dev_id(dev_id),
148  backupBytesSent(0),
149  backupBytesReceived(0),
150  backupPacketsSent(0),
151  backupPacketsReceived(0),
152  backupErrorsSent(0),
153  backupErrorsReceived(0),
154  backupUnicastPacketsSent(0),
155  backupUnicastPacketsReceived(0),
156  backupDiscardPacketsSent(0),
157  backupDiscardPacketsReceived(0),
158  backupMulticastPacketsSent(0),
159  backupMulticastPacketsReceived(0),
160  backupBroadcastPacketsSent(0),
161  backupBroadcastPacketsReceived(0),
162  backupUnknownProtoPacketsReceived(0),
163  bCalledBytesSent(false),
164  bCalledBytesReceived(false),
165  bCalledPacketsSent(false),
166  bCalledPacketsReceived(false),
167  bCalledErrorsSent(false),
168  bCalledErrorsReceived(false),
169  bCalledUnicastPacketsSent(false),
170  bCalledUnicastPacketsReceived(false),
171  bCalledDiscardPacketsSent(false),
172  bCalledDiscardPacketsReceived(false),
173  bCalledMulticastPacketsSent(false),
174  bCalledMulticastPacketsReceived(false),
175  bCalledBroadcastPacketsSent(false),
176  bCalledBroadcastPacketsReceived(false),
177  bCalledUnknownProtoPacketsReceived(false)
178 {
179 }
180 
181 int hostIf_IPInterfaceStats::handleGetMsg (const char* pSetting, HOSTIF_MsgData_t* stMsgData)
182 {
183  int ret = NOT_HANDLED;
184 
185  if (!strcasecmp (pSetting, "Stats.BytesSent"))
186  {
187  ret = get_Device_IP_Interface_Stats_BytesSent (stMsgData);
188  }
189  else if (!strcasecmp (pSetting, "Stats.BytesReceived"))
190  {
192  }
193  else if (!strcasecmp (pSetting, "Stats.PacketsSent"))
194  {
196  }
197  else if (!strcasecmp (pSetting, "Stats.PacketsReceived"))
198  {
200  }
201  else if (!strcasecmp (pSetting, "Stats.ErrorsSent"))
202  {
204  }
205  else if (!strcasecmp (pSetting, "Stats.ErrorsReceived"))
206  {
208  }
209  else if (!strcasecmp (pSetting, "Stats.UnicastPacketsSent"))
210  {
212  }
213  else if (!strcasecmp (pSetting, "Stats.UnicastPacketsReceived"))
214  {
216  }
217  else if (!strcasecmp (pSetting, "Stats.DiscardPacketsSent"))
218  {
220  }
221  else if (!strcasecmp (pSetting, "Stats.DiscardPacketsReceived"))
222  {
224  }
225  else if (!strcasecmp (pSetting, "Stats.MulticastPacketsSent"))
226  {
228  }
229  else if (!strcasecmp (pSetting, "Stats.MulticastPacketsReceived"))
230  {
232  }
233  else if (!strcasecmp (pSetting, "Stats.BroadcastPacketsSent"))
234  {
236  }
237  else if (!strcasecmp (pSetting, "Stats.BroadcastPacketsReceived"))
238  {
240  }
241  else if (!strcasecmp (pSetting, "Stats.UnknownProtoPacketsReceived"))
242  {
244  }
245 
246  return ret;
247 }
248 
249 int hostIf_IPInterfaceStats::getSysClassNetStatistic (char* statistic, unsigned long* result)
250 {
251  int ret = NOK;
252  char filename[BUFF_LENGTH_64];
253  sprintf (filename, "/sys/class/net/%s/statistics/%s", nameOfInterface, statistic);
254 
255  FILE* fp = fopen (filename, "r");
256  if (fp == NULL)
257  {
258  RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF, "\n[%s(), %d] Error in fopen(%s)\n", __FUNCTION__, __LINE__, filename);
259  return NOK;
260  }
261 
262  if (1 == fscanf (fp, "%ld", result))
263  ret = OK;
264 
265  fclose (fp);
266 
267  return ret;
268 }
269 
270 /****************************************************************************************************************************************************/
271 // Device_IP_Interface_Stats Profile. Getters:
272 /****************************************************************************************************************************************************/
273 
274 /**
275  * @brief This function gets the number of bytes sent on the IP Interface. It provides the
276  * total number of bytes transmitted out of the interface, including framing characters.
277  *
278  * @param[out] stMsgData TR-069 Host interface message request.
279  * @param[in] pChanged Status of the operation.
280  *
281  * @return Returns the status of the operation.
282  *
283  * @retval OK if it is successfully fetch the data from the device.
284  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
285  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
286  */
288 {
289  curntIpStat.bytesSent = 0;
290  getSysClassNetStatistic ("tx_bytes", &curntIpStat.bytesSent);
291 
292  if(bCalledBytesSent && pChanged && (backupBytesSent != curntIpStat.bytesSent))
293  {
294  *pChanged = true;
295  }
296  bCalledBytesSent = true;
297  backupBytesSent = curntIpStat.bytesSent;
298  put_int(stMsgData->paramValue,curntIpStat.bytesSent);
299  stMsgData->paramtype = hostIf_UnsignedLongType;
300  stMsgData->paramLen = sizeof(unsigned long);
301 
302  return OK;
303 }
304 
305 /**
306  * @brief This function gets the number of bytes received on the IP Interface. It provides
307  * the total number of bytes received on the interface, including framing characters.
308  *
309  * @param[out] stMsgData TR-069 Host interface message request.
310  * @param[in] pChanged Status of the operation.
311  *
312  * @return Returns the status of the operation.
313  *
314  * @retval OK if it is successfully fetch the data from the device.
315  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
316  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
317  */
319 {
320  curntIpStat.bytesReceived = 0;
321  getSysClassNetStatistic ("rx_bytes", &curntIpStat.bytesReceived);
322 
323  if(bCalledBytesReceived && pChanged && (backupBytesReceived != curntIpStat.bytesReceived))
324  {
325  *pChanged = true;
326  }
327  bCalledBytesReceived = true;
328  backupBytesReceived = curntIpStat.bytesReceived;
329  put_int(stMsgData->paramValue,curntIpStat.bytesReceived);
330  stMsgData->paramtype = hostIf_UnsignedLongType;
331  stMsgData->paramLen = sizeof(unsigned long);
332 
333  return OK;
334 }
335 
336 /**
337  * @brief This function gets the number of packets sent on the IP Interface. It provides
338  * the total number of packets transmitted out of the interface.
339  *
340  * @param[out] stMsgData TR-069 Host interface message request.
341  * @param[in] pChanged Status of the operation.
342  *
343  * @return Returns the status of the operation.
344  *
345  * @retval OK if it is successfully fetch the data from the device.
346  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
347  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
348  */
350 {
351  curntIpStat.packetsSent = 0;
352  getSysClassNetStatistic ("tx_packets", &curntIpStat.packetsSent);
353 
354  if(bCalledPacketsSent && pChanged && (backupPacketsSent != curntIpStat.packetsSent))
355  {
356  *pChanged = true;
357  }
358  bCalledPacketsSent = true;
359  backupPacketsSent = curntIpStat.packetsSent;
360  put_int(stMsgData->paramValue,curntIpStat.packetsSent);
361  stMsgData->paramtype = hostIf_UnsignedLongType;
362  stMsgData->paramLen = sizeof(unsigned long);
363 
364  return OK;
365 }
366 
367 /**
368  * @brief This function gets the total number of packets received on the IP Interface.
369  *
370  * @param[out] stMsgData TR-069 Host interface message request.
371  * @param[in] pChanged Status of the operation.
372  *
373  * @return Returns the status of the operation.
374  *
375  * @retval OK if it is successfully fetch the data from the device.
376  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
377  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
378  */
380 {
381  curntIpStat.packetsReceived = 0;
382  getSysClassNetStatistic ("rx_packets", &curntIpStat.packetsReceived);
383  // TODO: rx_packets only "Indicates the total number of good packets received by this network device."
384  // as per https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net-statistics but
385  // as per the TR069 spec, PacketsReceived is "The total number of packets received on the interface.".
386 
387  if(bCalledPacketsReceived && pChanged && (backupPacketsReceived != curntIpStat.packetsReceived))
388  {
389  *pChanged = true;
390  }
391  bCalledPacketsReceived = true;
392  backupPacketsReceived = curntIpStat.packetsReceived;
393  put_int(stMsgData->paramValue,curntIpStat.packetsReceived);
394  stMsgData->paramtype = hostIf_UnsignedLongType;
395  stMsgData->paramLen = sizeof(unsigned long);
396 
397  return OK;
398 }
399 
400 /**
401  * @brief This function gets the number of send errors on the IP Interface. It provides
402  * the total number of outbound packets that could not be transmitted because of errors.
403  *
404  * @param[out] stMsgData TR-069 Host interface message request.
405  * @param[in] pChanged Status of the operation.
406  *
407  * @return Returns the status of the operation.
408  *
409  * @retval OK if it successfully fetch the data from the device.
410  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
411  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
412  */
414 {
415  curntIpStat.errorsSent = 0;
416  getSysClassNetStatistic ("tx_errors", &curntIpStat.errorsSent);
417 
418  if(bCalledErrorsSent && pChanged && (backupErrorsSent != curntIpStat.errorsSent))
419  {
420  *pChanged = true;
421  }
422  bCalledErrorsSent = true;
423  backupErrorsSent = curntIpStat.errorsSent;
424  put_int(stMsgData->paramValue,curntIpStat.errorsSent);
425  stMsgData->paramtype = hostIf_UnsignedIntType;
426  stMsgData->paramLen = 4;
427 
428  return OK;
429 }
430 
431 /**
432  * @brief This function gets the number of receive errors on the IP Interface. It provides
433  * the total number of inbound packets that contained errors preventing them from being
434  * delivered to a higher-layer protocol.
435  *
436  * @param[out] stMsgData TR-069 Host interface message request.
437  * @param[in] pChanged Status of the operation.
438  *
439  * @return Returns the status of the operation.
440  *
441  * @retval OK if it is successfully fetch the data from the device.
442  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
443  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
444  */
446 {
447  curntIpStat.errorsReceived = 0;
448  getSysClassNetStatistic ("rx_errors", &curntIpStat.errorsReceived);
449 
450  if(bCalledErrorsReceived && pChanged && (backupErrorsReceived != curntIpStat.errorsReceived))
451  {
452  *pChanged = true;
453  }
454  bCalledErrorsReceived = true;
455  backupErrorsReceived = curntIpStat.errorsReceived;
456  put_int(stMsgData->paramValue,curntIpStat.errorsReceived);
457  stMsgData->paramtype = hostIf_UnsignedIntType;
458  stMsgData->paramLen = 4;
459 
460  return OK;
461 }
462 
463 /**
464  * @brief This function gets the number of unicast packets for which a request to send on the IP
465  * Interface was received. It provides the total number of packets requested for transmission which
466  * were not addressed to a multicast or broadcast address at this layer, including those that
467  * were discarded or not sent.
468  *
469  * @param[out] stMsgData TR-069 Host interface message request.
470  * @param[in] pChanged Status of the operation.
471  *
472  * @return Returns the status of the operation.
473  *
474  * @retval OK if it is successfully fetch the data from the device.
475  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
476  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
477  */
479 {
480  curntIpStat.unicastPacketsSent = 0;
481  getSysClassNetStatistic ("tx_packets", &curntIpStat.unicastPacketsSent);
482 
483  if(bCalledUnicastPacketsSent && pChanged && (backupUnicastPacketsSent != curntIpStat.unicastPacketsSent))
484  {
485  *pChanged = true;
486  }
487  bCalledUnicastPacketsSent = true;
488  backupUnicastPacketsSent = curntIpStat.unicastPacketsSent;
489  put_int(stMsgData->paramValue,curntIpStat.unicastPacketsSent);
490  stMsgData->paramtype = hostIf_UnsignedLongType;
491  stMsgData->paramLen = sizeof(unsigned long);
492 
493  return OK;
494 }
495 
496 /**
497  * @brief This function gets the number of unicast packets received on the IP Interface. Provides
498  * the total number of received packets, delivered by this layer to a higher layer, which were
499  * not addressed to a multicast or broadcast address at this layer.
500  *
501  * @param[out] stMsgData TR-069 Host interface message request.
502  * @param[in] pChanged Status of the operation.
503  *
504  * @return Returns the status of the operation.
505  *
506  * @retval OK if it is successfully fetch the data from the device.
507  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
508  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
509  */
511 {
512  curntIpStat.unicastPacketsReceived = 0;
513  getSysClassNetStatistic ("rx_packets", &curntIpStat.unicastPacketsReceived);
514 
515  if(bCalledUnicastPacketsReceived && pChanged && (backupUnicastPacketsReceived != curntIpStat.unicastPacketsReceived))
516  {
517  *pChanged = true;
518  }
519  bCalledUnicastPacketsReceived = true;
520  backupUnicastPacketsReceived = curntIpStat.unicastPacketsReceived;
521  put_int(stMsgData->paramValue,curntIpStat.unicastPacketsReceived);
522  stMsgData->paramtype = hostIf_UnsignedLongType;
523  stMsgData->paramLen = sizeof(unsigned long);
524 
525  return OK;
526 }
527 
528 /**
529  * @brief This function gets the number of discarded outbound packets on the IP Interface. It
530  * provides the total number of outbound packets which were chosen to be discarded even though
531  * no errors had been detected to prevent their being transmitted.
532  *
533  * @note One possible reason for discarding such a packet could be to free up buffer space.
534  *
535  * @param[out] stMsgData TR-069 Host interface message request.
536  * @param[in] pChanged Status of the operation.
537  *
538  * @return Returns the status of the operation.
539  *
540  * @retval OK if it is successfully fetch the data from the device.
541  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
542  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
543  */
545 {
546  curntIpStat.discardPacketsSent = 0;
547  getSysClassNetStatistic ("tx_dropped", &curntIpStat.discardPacketsSent);
548 
549  if(bCalledDiscardPacketsSent && pChanged && (backupDiscardPacketsSent != curntIpStat.discardPacketsSent))
550  {
551  *pChanged = true;
552  }
553  bCalledDiscardPacketsSent = true;
554  backupDiscardPacketsSent = curntIpStat.discardPacketsSent;
555  put_int(stMsgData->paramValue,curntIpStat.discardPacketsSent);
556  stMsgData->paramtype = hostIf_UnsignedIntType;
557  stMsgData->paramLen = 4;
558 
559  return OK;
560 }
561 
562 /**
563  * @brief This function gets the number of discarded inbound packets on the IP Interface. It provides
564  * the total number of inbound packets which were chosen to be discarded even though no errors had
565  * been detected to prevent their being delivered.
566  *
567  * @note One possible reason for discarding such a packet could be to free up buffer space.
568  *
569  * @param[out] stMsgData TR-069 Host interface message request.
570  * @param[in] pChanged Status of the operation.
571  *
572  * @return Returns the status of the operation.
573  *
574  * @retval OK if it is successfully fetch the data from the device.
575  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
576  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
577  */
579 {
580  curntIpStat.discardPacketsReceived = 0;
581  getSysClassNetStatistic ("rx_dropped", &curntIpStat.discardPacketsReceived);
582 
583  if(bCalledDiscardPacketsReceived && pChanged && (backupDiscardPacketsReceived != curntIpStat.discardPacketsReceived))
584  {
585  *pChanged = true;
586  }
587  bCalledDiscardPacketsReceived = true;
588  backupDiscardPacketsReceived = curntIpStat.discardPacketsReceived;
589  put_int(stMsgData->paramValue,curntIpStat.discardPacketsReceived);
590  stMsgData->paramtype = hostIf_UnsignedIntType;
591  stMsgData->paramLen = 4;
592 
593  return OK;
594 }
595 
596 /**
597  * @brief This function gets the number of Multicast Packets sent on the IP Interface. It provides
598  * the total number of packets that higher-level protocols requested for transmission and which were
599  * addressed to a multicast address at this layer, including those that were discarded or not sent.
600  *
601  * @param[out] stMsgData TR-069 Host interface message request.
602  * @param[in] pChanged Status of the operation.
603  *
604  * @return Returns the status of the operation.
605  *
606  * @retval OK if it is successfully fetch the data from the device.
607  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
608  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
609  */
611 {
612  curntIpStat.multicastPacketsSent = 0;
613  getSysClassNetStatistic ("tx_packets", &curntIpStat.multicastPacketsSent);
614 
615  if(bCalledMulticastPacketsSent && pChanged && (backupMulticastPacketsSent != curntIpStat.multicastPacketsSent))
616  {
617  *pChanged = true;
618  }
619  bCalledMulticastPacketsSent = true;
620  backupMulticastPacketsSent = curntIpStat.multicastPacketsSent;
621  put_int(stMsgData->paramValue,curntIpStat.multicastPacketsSent);
622  stMsgData->paramtype = hostIf_UnsignedLongType;
623  stMsgData->paramLen = sizeof(unsigned long);
624 
625  return OK;
626 }
627 
628 /**
629  * @brief This function gets the number of Multicast Packets received on the IP Interface. It provides the
630  * total number of received packets, delivered by this layer to a higher layer, which were addressed
631  * to a multicast address at this layer.
632  *
633  * @param[out] stMsgData TR-069 Host interface message request.
634  * @param[in] pChanged Status of the operation.
635  *
636  * @return Returns the status of the operation.
637  *
638  * @retval OK if it is successfully fetch the data from the device.
639  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
640  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
641  */
643 {
644  curntIpStat.multicastPacketsReceived = 0;
645  getSysClassNetStatistic ("multicast", &curntIpStat.multicastPacketsReceived);
646 
647  if(bCalledMulticastPacketsReceived && pChanged && (backupMulticastPacketsReceived != curntIpStat.multicastPacketsReceived))
648  {
649  *pChanged = true;
650  }
651  bCalledMulticastPacketsReceived = true;
652  backupMulticastPacketsReceived = curntIpStat.multicastPacketsReceived;
653  put_int(stMsgData->paramValue,curntIpStat.multicastPacketsReceived);
654  stMsgData->paramtype = hostIf_UnsignedLongType;
655  stMsgData->paramLen = sizeof(unsigned long);
656 
657  return OK;
658 }
659 
660 /**
661  * @brief This function gets the number of broadcast packets sent on the IP Interface. It provides
662  * the total number of packets that higher-level protocols requested for transmission and which
663  * were addressed to a broadcast address at this layer, including those that were discarded or not sent.
664  *
665  * @note IPv6 does not define broadcast addresses, so IPv6 packets will never cause this counter to increment.
666  *
667  * @param[out] stMsgData TR-069 Host interface message request.
668  * @param[in] pChanged Status of the operation.
669  *
670  * @return Returns the status of the operation.
671  *
672  * @retval OK if it is successfully fetch the data from the device.
673  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
674  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
675  */
677 {
678  curntIpStat.broadcastPacketsSent = 0;
679  getSysClassNetStatistic ("tx_packets", &curntIpStat.broadcastPacketsSent);
680 
681  if(bCalledBroadcastPacketsSent && pChanged && (backupBroadcastPacketsSent != curntIpStat.broadcastPacketsSent))
682  {
683  *pChanged = true;
684  }
685  bCalledBroadcastPacketsSent = true;
686  backupBroadcastPacketsSent = curntIpStat.broadcastPacketsSent;
687  put_int(stMsgData->paramValue,curntIpStat.broadcastPacketsSent);
688  stMsgData->paramtype = hostIf_UnsignedLongType;
689  stMsgData->paramLen = sizeof(unsigned long);
690 
691  return OK;
692 }
693 
694 /**
695  * @brief This function gets the number of broadcast packets received on the IP interface.
696  * It provides the total number of received packets, delivered by this layer to a higher layer,
697  * which were addressed to a broadcast address at this layer.
698  *
699  * @note IPv6 does not define broadcast addresses, so IPv6 packets will never cause this counter
700  * to increment.
701  *
702  * @param[out] stMsgData TR-069 Host interface message request.
703  * @param[in] pChanged Status of the operation.
704  *
705  * @return Returns the status of the operation.
706  *
707  * @retval OK if it successfully fetch the data from the device.
708  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
709  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
710  */
712 {
713  curntIpStat.broadcastPacketsReceived = 0;
714  getSysClassNetStatistic ("rx_packets", &curntIpStat.broadcastPacketsReceived);
715 
716  if(bCalledBroadcastPacketsReceived && pChanged && (backupBroadcastPacketsReceived != curntIpStat.broadcastPacketsReceived))
717  {
718  *pChanged = true;
719  }
720  bCalledBroadcastPacketsReceived = true;
721  backupBroadcastPacketsReceived = curntIpStat.broadcastPacketsReceived;
722  put_int(stMsgData->paramValue,curntIpStat.broadcastPacketsReceived);
723  stMsgData->paramtype = hostIf_UnsignedIntType;
724  stMsgData->paramLen = 4;
725 
726  return OK;
727 }
728 
729 /**
730  * @brief This function gets the number of Packets of unidentified protocol received on
731  * the IP Interface. It provides the total number of packets received via the interface
732  * which were discarded because they were of an unknown or unsupported protocol.
733  *
734  * @param[out] stMsgData TR-069 Host interface message request.
735  * @param[in] pChanged Status of the operation.
736  *
737  * @return Returns the status of the operation.
738  *
739  * @retval OK if it successfully fetch the data from the device.
740  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
741  * @ingroup TR69_HOSTIF_DEVICE_IP_INTERFACE_STATS_API
742  */
744 {
745  curntIpStat.unknownProtoPacketsReceived = 0;
746  getSysClassNetStatistic ("rx_dropped", &curntIpStat.unknownProtoPacketsReceived);
747 
748  if(bCalledUnknownProtoPacketsReceived && pChanged && (backupUnknownProtoPacketsReceived != curntIpStat.unknownProtoPacketsReceived))
749  {
750  *pChanged = true;
751  }
752  bCalledUnknownProtoPacketsReceived = true;
753  backupUnknownProtoPacketsReceived = curntIpStat.unknownProtoPacketsReceived;
754  put_int(stMsgData->paramValue,curntIpStat.unknownProtoPacketsReceived);
755  stMsgData->paramtype = hostIf_UnsignedIntType;
756  stMsgData->paramLen = 4;
757 
758  return OK;
759 }
760 /* End of doxygen group */
761 /**
762  * @}
763  */
764 
765 /* End of file xxx_api.c. */
766 
767 
768 /** @} */
769 /** @} */
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_UnicastPacketsReceived
int get_Device_IP_Interface_Stats_UnicastPacketsReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of unicast packets received on the IP Interface. Provides the total num...
Definition: Device_IP_Interface_Stats.cpp:510
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_BroadcastPacketsReceived
int get_Device_IP_Interface_Stats_BroadcastPacketsReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of broadcast packets received on the IP interface. It provides the tota...
Definition: Device_IP_Interface_Stats.cpp:711
hostIf_IPInterfaceStats::hostIf_IPInterfaceStats
hostIf_IPInterfaceStats(int dev_id)
Class Constructor of the class hostIf_IPInterfaceStats.
Definition: Device_IP_Interface_Stats.cpp:146
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_UnicastPacketsSent
int get_Device_IP_Interface_Stats_UnicastPacketsSent(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of unicast packets for which a request to send on the IP Interface was ...
Definition: Device_IP_Interface_Stats.cpp:478
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_PacketsReceived
int get_Device_IP_Interface_Stats_PacketsReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the total number of packets received on the IP Interface.
Definition: Device_IP_Interface_Stats.cpp:379
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_DiscardPacketsReceived
int get_Device_IP_Interface_Stats_DiscardPacketsReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of discarded inbound packets on the IP Interface. It provides the total...
Definition: Device_IP_Interface_Stats.cpp:578
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_UnknownProtoPacketsReceived
int get_Device_IP_Interface_Stats_UnknownProtoPacketsReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of Packets of unidentified protocol received on the IP Interface....
Definition: Device_IP_Interface_Stats.cpp:743
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_BytesReceived
int get_Device_IP_Interface_Stats_BytesReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of bytes received on the IP Interface. It provides the total number of ...
Definition: Device_IP_Interface_Stats.cpp:318
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_BroadcastPacketsSent
int get_Device_IP_Interface_Stats_BroadcastPacketsSent(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of broadcast packets sent on the IP Interface. It provides the total nu...
Definition: Device_IP_Interface_Stats.cpp:676
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_PacketsSent
int get_Device_IP_Interface_Stats_PacketsSent(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
Get the number of packets sent on the IP Interface.
Definition: Device_IP_Interface_Stats.cpp:349
Device_IP_Interface_Stats.h
The header file provides TR069 device IP interface stats information APIs.
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
hostIf_IP::getInterfaceName
static char * getInterfaceName(int if_index, char *if_name)
Definition: Device_IP.cpp:183
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_DiscardPacketsSent
int get_Device_IP_Interface_Stats_DiscardPacketsSent(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of discarded outbound packets on the IP Interface. It provides the tota...
Definition: Device_IP_Interface_Stats.cpp:544
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_ErrorsReceived
int get_Device_IP_Interface_Stats_ErrorsReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of receive errors on the IP Interface. It provides the total number of ...
Definition: Device_IP_Interface_Stats.cpp:445
hostIf_IPInterfaceStats
This class provides the hostIf IP interface stats for getting IP interface stats information.
Definition: Device_IP_Interface_Stats.h:143
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_BytesSent
int get_Device_IP_Interface_Stats_BytesSent(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of bytes sent on the IP Interface. It provides the total number of byte...
Definition: Device_IP_Interface_Stats.cpp:287
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
Device_IP.h
The header file provides TR069 device IP information APIs.
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_MulticastPacketsReceived
int get_Device_IP_Interface_Stats_MulticastPacketsReceived(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of Multicast Packets received on the IP Interface. It provides the tota...
Definition: Device_IP_Interface_Stats.cpp:642
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_MulticastPacketsSent
int get_Device_IP_Interface_Stats_MulticastPacketsSent(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of Multicast Packets sent on the IP Interface. It provides the total nu...
Definition: Device_IP_Interface_Stats.cpp:610
hostIf_IPInterfaceStats::get_Device_IP_Interface_Stats_ErrorsSent
int get_Device_IP_Interface_Stats_ErrorsSent(HOSTIF_MsgData_t *stMsgData, bool *pChanged=NULL)
This function gets the number of send errors on the IP Interface. It provides the total number of out...
Definition: Device_IP_Interface_Stats.cpp:413
Device_IP_Interface_Stats
It contains the members variables of the Device_IP_Interface_stats structure.
Definition: Device_IP_Interface_Stats.h:78