RDK Documentation (Open Sourced RDK Components)
Device_Ethernet_Interface_Stats.cpp
Go to the documentation of this file.
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_Ethernet_Interface_Stats.cpp
22  * @brief This source file contains the APIs of device ethernet 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>
45 
48 
49 EthernetInterfaceStats hostIf_EthernetInterfaceStats::stEthInterfaceStats = {0,};
50 
51 GMutex* hostIf_EthernetInterfaceStats::m_mutex = NULL;
52 
53 GHashTable* hostIf_EthernetInterfaceStats::ifHash = NULL;
54 
55 //Returns the number of ethernet interfaces.
56 extern int ethCount();
57 
58 static int read_Device_Ethernet_Interface_Stats_Fields(unsigned int ethInterfaceNum, EEthInterfaceStatsMembers ethInterfaceStatMem)
59 {
60  FILE *fp;
61  char resultBuff[BUFF_LENGTH] = {'\0'};
62  char cmd[BUFF_LENGTH] = {'\0'};
63  int temp;
64  char ethName[BUFF_LENGTH] = {'\0'};
65 
66  // Get Interface name from devId to read statistics
67  HOSTIF_MsgData_t stMsgData;
69  pIface->get_Device_Ethernet_Interface_Name(&stMsgData);
70  strncpy(ethName,stMsgData.paramValue,BUFF_LENGTH -1);
71 
72  switch(ethInterfaceStatMem)
73  {
74  case eBytesSent:
75  sprintf(cmd,"cat /sys/class/net/%s/statistics/tx_bytes",ethName);
76 
77  fp = popen(cmd,"r");
78 
79  if(fp == NULL)
80  {
81  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eBytesSent\n");
82 
83  return 0;
84  }
85 
86  if(fgets(resultBuff,1024,fp)!=NULL)
87  {
88  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.bytesSent);
89  }
90 
91  pclose(fp);
92  break;
93 
94  case eBytesReceived:
95  sprintf(cmd,"cat /sys/class/net/%s/statistics/rx_bytes",ethName);
96 
97  fp = popen(cmd,"r");
98 
99  if(fp == NULL)
100  {
101  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eBytesReceived\n");
102 
103  return 0;
104  }
105 
106  if(fgets(resultBuff,1024,fp)!=NULL)
107  {
108  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.bytesReceived);
109  }
110 
111  pclose(fp);
112  break;
113  case ePacketsSent:
114  case eUnicastPacketsSent:
115  case eMulticastPacketsSent:
116  case eBroadcastPacketsSent:
117  sprintf(cmd,"cat /sys/class/net/%s/statistics/tx_packets",ethName);
118 
119  fp = popen(cmd,"r");
120 
121  if(fp == NULL)
122  {
123  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen ePacketsSent\n");
124 
125  return 0;
126  }
127 
128  if(fgets(resultBuff,1024,fp)!=NULL)
129  {
130  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.packetsSent);
131  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.unicastPacketsSent);
132  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.multicastPacketsSent);
133  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.broadcastPacketsSent);
134  }
135 
136  pclose(fp);
137  break;
138 
139  case ePacketsReceived:
140  case eUnicastPacketsReceived:
141  case eMulticastPacketsReceived:
142  case eBroadcastPacketsReceived:
143  sprintf(cmd,"cat /sys/class/net/%s/statistics/rx_packets",ethName);
144 
145  fp = popen(cmd,"r");
146 
147  if(fp == NULL)
148  {
149  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen ePacketsReceived\n");
150 
151  return 0;
152  }
153 
154  if(fgets(resultBuff,1024,fp)!=NULL)
155  {
156  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.packetsReceived);
157  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.unicastPacketsReceived);
158  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.multicastPacketsReceived);
159  sscanf(resultBuff,"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.broadcastPacketsReceived);
160  }
161 
162  pclose(fp);
163  break;
164 
165  case eErrorsSent:
166  sprintf(cmd,"cat /sys/class/net/%s/statistics/tx_errors",ethName);
167 
168  fp = popen(cmd,"r");
169 
170  if(fp == NULL)
171  {
172  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eErrorsSent\n");
173 
174  return 0;
175  }
176 
177  if(fgets(resultBuff,1024,fp)!=NULL)
178  {
179  sscanf(resultBuff,"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.errorsSent);
180  }
181 
182  pclose(fp);
183  break;
184 
185  case eErrorsReceived:
186  sprintf(cmd,"cat /sys/class/net/%s/statistics/rx_errors",ethName);
187 
188  fp = popen(cmd,"r");
189 
190  if(fp == NULL)
191  {
192  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eErrorsReceived\n");
193 
194  return 0;
195  }
196 
197  if(fgets(resultBuff,1024,fp)!=NULL)
198  {
199  sscanf(resultBuff,"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.errorsReceived);
200  }
201 
202  pclose(fp);
203  break;
204 
205  case eDiscardPacketsSent:
206  sprintf(cmd,"cat /sys/class/net/%s/statistics/tx_dropped",ethName);
207 
208  fp = popen(cmd,"r");
209 
210  if(fp == NULL)
211  {
212  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eDiscardPacketsSent \n");
213 
214  return 0;
215  }
216 
217  if(fgets(resultBuff,1024,fp)!=NULL)
218  {
219  sscanf(resultBuff,"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.discardPacketsSent);
220  }
221 
222  pclose(fp);
223  break;
224 
225  case eDiscardPacketsReceived:
226  case eUnknownProtoPacketsReceived:
227  sprintf(cmd,"cat /sys/class/net/%s/statistics/rx_dropped",ethName);
228 
229  fp = popen(cmd,"r");
230 
231  if(fp == NULL)
232  {
233  RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eDiscardPacketsReceived \n");
234 
235  return 0;
236  }
237 
238  if(fgets(resultBuff,1024,fp)!=NULL)
239  {
240  sscanf(resultBuff,"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.discardPacketsReceived);
241  sscanf(resultBuff,"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.unknownProtoPacketsReceived);
242  }
243 
244  pclose(fp);
245  break;
246 
247  default:
248  break;
249  }
250 
251  return 0;
252 }
253 
254 
255 hostIf_EthernetInterfaceStats* hostIf_EthernetInterfaceStats::getInstance(int dev_id)
256 {
257  hostIf_EthernetInterfaceStats* pRet = NULL;
258 
259  if(ifHash)
260  {
261  pRet = (hostIf_EthernetInterfaceStats *)g_hash_table_lookup(ifHash,(gpointer) dev_id);
262  }
263  else
264  {
265  ifHash = g_hash_table_new(NULL,NULL);
266  }
267 
268  if(!pRet)
269  {
270  try {
271  pRet = new hostIf_EthernetInterfaceStats(dev_id);
272  } catch(int e)
273  {
274  RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,"Caught exception, not able create Ethernet Interface instance..\n");
275  }
276  g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
277  }
278  return pRet;
279 }
280 
281 GList* hostIf_EthernetInterfaceStats::getAllInstances()
282 {
283  if(ifHash)
284  return g_hash_table_get_keys(ifHash);
285  return NULL;
286 }
287 
288 void hostIf_EthernetInterfaceStats::closeInstance(hostIf_EthernetInterfaceStats *pDev)
289 {
290  if(pDev)
291  {
292  g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
293  delete pDev;
294  }
295 }
296 
297 void hostIf_EthernetInterfaceStats::closeAllInstances()
298 {
299  if(ifHash)
300  {
301  GList* tmp_list = g_hash_table_get_values (ifHash);
302 
303  while(tmp_list)
304  {
306  tmp_list = tmp_list->next;
307  closeInstance(pDev);
308  }
309  }
310 }
311 
312 void hostIf_EthernetInterfaceStats::getLock()
313 {
314 
315  if(!m_mutex)
316  {
317  m_mutex = g_mutex_new();
318  }
319  g_mutex_lock(m_mutex);
320 
321 }
322 
323 void hostIf_EthernetInterfaceStats::releaseLock()
324 {
325  g_mutex_unlock(m_mutex);
326 }
327 
328 /**
329  * @brief Class Constructor of the class hostIf_EthernetInterfaceStats.
330  *
331  * It will initialize the device id.
332  *
333  * @param[in] dev_id Device identification Number.
334  */
336  dev_id(dev_id),
337  backupBytesSent(0),
338  backupBytesReceived(0),
339  backupPacketsSent(0),
340  backupPacketsReceived(0),
341  backupUnicastPacketsSent(0),
342  backupUnicastPacketsReceived(0),
343  backupMulticastPacketsReceived(0),
344  backupBroadcastPacketsSent(0),
345  backupBroadcastPacketsReceived(0),
346  backupMulticastPacketsSent(0),
347  backupErrorSent(0),
348  backupErrorsReceived(0),
349  backupErrorsSent(0),
350  backupDiscardPacketsReceived(0),
351  bCalledBytesSent(false),
352  bCalledBytesReceived(false),
353  bCalledPacketsSent(false),
354  bCalledPacketsReceived(false),
355  bCalledErrorSent(false),
356  bCalledErrorsReceived(false),
357  bCalledErrorsSent(false),
358  bCalledUnicastPacketsSent(false),
359  bCalledDiscardPacketsReceived(false),
360  bCalledDiscardPacketsSent(false),
361  bCalledUnicastPacketsReceived(false),
362  bCalledMulticastPacketsReceived(false),
363  bCalledBroadcastPacketsSent(false),
364  bCalledBroadcastPacketsReceived(false),
365  bCalledMulticastPacketsSent(false),
366  bCalledUnknownProtoPacketsReceived(false)
367 
368 {
369 }
370 
371 /****************************************************************************************************************************************************/
372 // Device.Ethernet.Interface.Stats. Profile. Getters:
373 /****************************************************************************************************************************************************/
374 
375 /**
376  * @brief This function provides the total number of bytes transmitted out of this Ethernet
377  * interface, including framing characters.
378  *
379  * @param[out] stMsgData TR-069 Host interface message request.
380  * @param[in] pChanged Status of the operation.
381  *
382  * @return Returns the status of the operation.
383  *
384  * @retval OK if is successfully fetch the data from the device.
385  * @retval ERR_INTERNAL_ERROR if not able to fetch the data.
386  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
387  */
389 {
390 
391  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBytesSent);
392  if(bCalledBytesSent && pChanged && (backupBytesSent != stEthInterfaceStats.bytesSent))
393  {
394  *pChanged = true;
395  }
396  bCalledBytesSent = true;
397  backupBytesSent = stEthInterfaceStats.bytesSent;
398  put_int(stMsgData->paramValue,stEthInterfaceStats.bytesSent);
399  stMsgData->paramtype = hostIf_UnsignedLongType;
400  stMsgData->paramLen = 4;
401 
402  return OK;
403 }
404 
405 /**
406  * @brief This function provides the total number of bytes received on this Ethernet
407  * interface, including framing characters.
408  *
409  * @param[out] stMsgData TR-069 Host interface message request.
410  * @param[in] pChanged Status of the operation.
411  *
412  * @returns Return '0' if the method successfully received the total number of bytes
413  * via ethernet interface else returns '-1'.
414  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
415  */
417 {
418 
419  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBytesReceived);
420  if(bCalledBytesReceived && pChanged && (backupBytesReceived != stEthInterfaceStats.bytesReceived))
421  {
422  *pChanged = true;
423  }
424  bCalledBytesReceived = true;
425  backupBytesReceived = stEthInterfaceStats.bytesReceived;
426  put_int(stMsgData->paramValue,stEthInterfaceStats.bytesReceived);
427  stMsgData->paramtype = hostIf_UnsignedLongType;
428  stMsgData->paramLen = 4;
429 
430  return OK;
431 }
432 
433 /**
434  * @brief This function provides the total number of packets transmitted out of this Ethernet interface.
435  *
436  * @param[out] stMsgData TR-069 Host interface message request.
437  * @param[in] pChanged Status of the operation.
438  *
439  * @returns Returns '0' if the method successfully sent the packets via ethernet interface
440  * else returns '-1'.
441  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
442  */
444 {
445 
446  read_Device_Ethernet_Interface_Stats_Fields(dev_id,ePacketsSent);
447  if(bCalledPacketsSent && pChanged && (backupPacketsSent != stEthInterfaceStats.packetsSent))
448  {
449  *pChanged = true;
450  }
451  bCalledPacketsSent = true;
452  backupPacketsSent = stEthInterfaceStats.packetsSent;
453  put_int(stMsgData->paramValue,stEthInterfaceStats.packetsSent);
454  stMsgData->paramtype = hostIf_UnsignedLongType;
455  stMsgData->paramLen = 4;
456 
457  return OK;
458 }
459 
460 /**
461  * @brief This function provides the total number of packets received on this Ethernet interface.
462  *
463  * @param[out] stMsgData TR-069 Host interface message request.
464  * @param[in] pChanged Status of the operation.
465  *
466  * @returns Returns '0' if the method successfully receive the total number of packets via
467  * ethernet interface else returns '1'.
468  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
469  */
471 {
472 
473  read_Device_Ethernet_Interface_Stats_Fields(dev_id,ePacketsReceived);
474  if(bCalledPacketsReceived && pChanged && (backupPacketsReceived != stEthInterfaceStats.packetsReceived))
475  {
476  *pChanged = true;
477  }
478  bCalledPacketsReceived = true;
479  backupPacketsReceived = stEthInterfaceStats.packetsReceived;
480  put_int(stMsgData->paramValue,stEthInterfaceStats.packetsReceived);
481  stMsgData->paramtype = hostIf_UnsignedLongType;
482  stMsgData->paramLen = 4;
483 
484  return OK;
485 }
486 
487 /**
488  * @brief This function provides the total number of outbound packets that could not be
489  * transmitted because of errors.
490  *
491  * @param[out] stMsgData TR-069 Host interface message request.
492  * @param[in] pChanged Status of the operation.
493  *
494  * @returns Returns '0' if the method successfully sent the errors via ethernet
495  * interface else returns '-1'.
496  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
497  */
499 {
500 
501  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eErrorsSent);
502  if(bCalledErrorSent && pChanged && (backupErrorSent != stEthInterfaceStats.errorsSent))
503  {
504  *pChanged = true;
505  }
506  bCalledErrorSent = true;
507  backupErrorSent = stEthInterfaceStats.errorsSent;
508  put_int(stMsgData->paramValue,stEthInterfaceStats.errorsSent);
509  stMsgData->paramtype = hostIf_UnsignedIntType;
510  stMsgData->paramLen = 4;
511 
512  return OK;
513 }
514 
515 /**
516  * @brief This function provides the total number of inbound packets that contained errors
517  * preventing them from being delivered to a higher-layer protocol.
518  *
519  * @param[out] stMsgData TR-069 Host interface message request.
520  * @param[in] pChanged Status of the operation.
521  *
522  * @returns Returns '0' if the method successfully receive the errors via ethernet
523  * interface stats else returns '-1'.
524  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
525  */
527 {
528 
529  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eErrorsReceived);
530  if(bCalledErrorsReceived && pChanged && (backupErrorsReceived != stEthInterfaceStats.errorsReceived))
531  {
532  *pChanged = true;
533  }
534  bCalledErrorsReceived = true;
535  backupErrorsReceived = stEthInterfaceStats.errorsReceived;
536  put_int(stMsgData->paramValue,stEthInterfaceStats.errorsReceived);
537  stMsgData->paramtype = hostIf_UnsignedIntType;
538  stMsgData->paramLen = 4;
539 
540  return OK;
541 }
542 
543 /**
544  * @brief This function get the number of unicast packets for which a request is send on the IP
545  * Interface was received. This function provides the total number of packets requested for
546  * transmission which were not addressed to a multicast or broadcast address at this layer,
547  * including those that were discarded or not sent.
548  *
549  * @param[out] stMsgData TR-069 Host interface message request.
550  * @param[in] pChanged Status of the operation.
551  *
552  * @returns Returns '0' if the method successfully sent the unicast packets via
553  * ethernet interface else returns '-1'.
554  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
555  */
557 {
558 
559  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eUnicastPacketsSent);
560  if(bCalledErrorsSent && pChanged && (backupErrorsSent != stEthInterfaceStats.unicastPacketsSent))
561  {
562  *pChanged = true;
563  }
564  bCalledErrorsSent = true;
565  backupErrorsSent = stEthInterfaceStats.unicastPacketsSent;
566  put_int(stMsgData->paramValue,stEthInterfaceStats.unicastPacketsSent);
567  stMsgData->paramtype = hostIf_UnsignedLongType;
568  stMsgData->paramLen = 4;
569 
570  return OK;
571 }
572 
573 /**
574  * @brief This function get the number of unicast packets received on an Ethernet Interface.
575  * This function provides the total number of received packets, delivered by this layer to
576  * a higher layer, which were not addressed to a multicast or broadcast address at this layer.
577  *
578  * @param[out] stMsgData TR-069 Host interface message request.
579  * @param[in] pChanged Status of the operation.
580  *
581  * @returns Returns '0' if the method successfully receive the unicast packets via
582  * ethernet interface else returns '-1'.
583  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
584  */
586 {
587 
588  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eUnicastPacketsReceived);
589  if(bCalledUnicastPacketsReceived && pChanged && (backupUnicastPacketsReceived != stEthInterfaceStats.unicastPacketsReceived))
590  {
591  *pChanged = true;
592  }
593  bCalledUnicastPacketsReceived = true;
594  backupUnicastPacketsReceived = stEthInterfaceStats.unicastPacketsReceived;
595  put_int(stMsgData->paramValue,stEthInterfaceStats.unicastPacketsReceived);
596  stMsgData->paramtype = hostIf_UnsignedLongType;
597  stMsgData->paramLen = 4;
598 
599  return OK;
600 }
601 
602 /**
603  * @brief This function get the number of discarded outbound packets on an Ethernet Interface.
604  * This function provides the total number of outbound packets which were chosen to be
605  * discarded even though no errors had been detected to prevent their being transmitted.
606  *
607  * @note One possible reason for discarding such a packet could be to free up buffer
608  * space.
609  *
610  *
611  * @param[out] stMsgData TR-069 Host interface message request.
612  * @param[in] pChanged Status of the operation.
613  *
614  * @returns Returns '0' if the method successfully discard the unicast packets sent via
615  * ethernet interface else returns '-1'.
616  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
617  */
619 {
620  bCalledDiscardPacketsSent;
621  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eDiscardPacketsSent);
622  if(bCalledUnicastPacketsSent && pChanged && (backupUnicastPacketsSent != stEthInterfaceStats.discardPacketsSent))
623  {
624  *pChanged = true;
625  }
626  bCalledUnicastPacketsSent = true;
627  backupUnicastPacketsSent = stEthInterfaceStats.discardPacketsSent;
628  put_int(stMsgData->paramValue,stEthInterfaceStats.discardPacketsSent);
629  stMsgData->paramtype = hostIf_UnsignedIntType;
630  stMsgData->paramLen = 4;
631 
632  return OK;
633 }
634 
635 
636 /**
637  * @brief This function get the number of discarded inbound packets on an Ethernet Interface.
638  * This function provides the total number of inbound packets which were chosen to be
639  * discarded even though no errors had been detected to prevent their being delivered.
640  *
641  * @note One possible reason for discarding such a packet could be to free up buffer
642  * space.
643  *
644  * @param[out] stMsgData TR-069 Host interface message request.
645  * @param[in] pChanged Status of the operation.
646  *
647  * @returns Returns '0' if the method successfully discard the unicast packets received via
648  * ethernet interface else returns '-1'.
649  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
650  */
652 {
653 
654  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eDiscardPacketsReceived);
655  if(bCalledDiscardPacketsReceived && pChanged && (backupDiscardPacketsReceived != stEthInterfaceStats.discardPacketsReceived))
656  {
657  *pChanged = true;
658  }
659  bCalledDiscardPacketsReceived = true;
660  backupDiscardPacketsReceived = stEthInterfaceStats.discardPacketsReceived;
661  put_int(stMsgData->paramValue,stEthInterfaceStats.discardPacketsReceived);
662  stMsgData->paramtype = hostIf_UnsignedIntType;
663  stMsgData->paramLen = 4;
664 
665  return OK;
666 }
667 
668 
669 /**
670  * @brief This function get the number of Multicast Packets sent on an Ethernet Interface.
671  * This function provides the total number of packets that higher-level protocols
672  * requested for transmission and which were addressed to a multicast address at
673  * this layer, including those that were discarded or not sent.
674  *
675  * @param[out] stMsgData TR-069 Host interface message request.
676  * @param[in] pChanged Status of the operation.
677  *
678  * @returns Returns '0' if the method successfully sent the multicast packets via
679  * ethernet interface else returns '-1'.
680  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
681  */
683 {
684 
685  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eMulticastPacketsSent);
686  if(bCalledUnicastPacketsReceived && pChanged && (backupUnicastPacketsReceived != stEthInterfaceStats.multicastPacketsSent))
687  {
688  *pChanged = true;
689  }
690  bCalledUnicastPacketsReceived = true;
691  backupUnicastPacketsReceived = stEthInterfaceStats.multicastPacketsSent;
692  put_int(stMsgData->paramValue,stEthInterfaceStats.multicastPacketsSent);
693  stMsgData->paramtype = hostIf_UnsignedLongType;
694  stMsgData->paramLen = 4;
695 
696  return OK;
697 }
698 
699 
700 /**
701  * @brief This function get the number of Multicast Packets received on an Ethernet Interface.
702  * This function provides the total number of received packets, delivered by this layer
703  * to a higher layer, which were addressed to a multicast address at this layer.
704  *
705  * @param[out] stMsgData TR-069 Host interface message request.
706  * @param[in] pChanged Status of the operation.
707  *
708  * @returns Returns '0' if the method successfully received the multicast packets via
709  * ethernet interface else returns '-1'.
710  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
711  */
713 {
714 
715  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eMulticastPacketsReceived);
716  if(bCalledMulticastPacketsReceived && pChanged && (backupMulticastPacketsReceived != stEthInterfaceStats.multicastPacketsReceived))
717  {
718  *pChanged = true;
719  }
720  bCalledMulticastPacketsReceived = true;
721  backupMulticastPacketsReceived = stEthInterfaceStats.multicastPacketsReceived;
722  put_int(stMsgData->paramValue,stEthInterfaceStats.multicastPacketsReceived);
723  stMsgData->paramtype = hostIf_UnsignedLongType;
724  stMsgData->paramLen = 4;
725 
726  return OK;
727 }
728 
729 /**
730  * @brief This function get the number of Broadcast Packets sent on an Ethernet Interface.
731  * This function provides the total number of packets that higher-level protocols
732  * requested for transmission and which were addressed to a broadcast address at this
733  * layer, including those that were discarded or not sent.
734  *
735  * @note IPv6 does not define broadcast addresses, so IPv6 packets will never cause
736  * this counter to increment.
737  *
738  * @param[out] stMsgData TR-069 Host interface message request.
739  * @param[in] pChanged Status of the operation.
740  *
741  * @returns Returns '0' if the method successfully sent the broadcast packets via etherne
742  * interface else returns '-1'.
743  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
744  *
745  */
747 {
748 
749  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBroadcastPacketsSent);
750  if(bCalledBroadcastPacketsSent && pChanged && (backupBroadcastPacketsSent != stEthInterfaceStats.broadcastPacketsSent))
751  {
752  *pChanged = true;
753  }
754  bCalledBroadcastPacketsSent = true;
755  backupBroadcastPacketsSent = stEthInterfaceStats.broadcastPacketsSent;
756  put_int(stMsgData->paramValue,stEthInterfaceStats.broadcastPacketsSent);
757  stMsgData->paramtype = hostIf_UnsignedLongType;
758  stMsgData->paramLen = 4;
759 
760  return OK;
761 }
762 
763 /**
764  * @brief This function get the number of Broadcast Packets received on an Ethernet Interface.
765  * This function provides the total number of received packets, delivered by this layer
766  * to a higher layer, which were addressed to a broadcast address at this layer.
767  *
768  * @note IPv6 does not define broadcast addresses, so IPv6 packets will never cause
769  * this counter to increment.
770  *
771  * @param[out] stMsgData TR-069 Host interface message request.
772  * @param[in] pChanged Status of the operation.
773  *
774  * @returns Returns '0' if the method successfully received the broadcast packets via ethernet
775  * interface else returns '-1'.
776  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
777  */
779 {
780 
781  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBroadcastPacketsReceived);
782  if(bCalledBroadcastPacketsReceived && pChanged && (backupBroadcastPacketsReceived != stEthInterfaceStats.broadcastPacketsReceived))
783  {
784  *pChanged = true;
785  }
786  bCalledBroadcastPacketsReceived = true;
787  backupBroadcastPacketsReceived = stEthInterfaceStats.broadcastPacketsReceived;
788  put_int(stMsgData->paramValue,stEthInterfaceStats.broadcastPacketsReceived);
789  stMsgData->paramtype = hostIf_UnsignedLongType;
790  stMsgData->paramLen = 4;
791 
792  return OK;
793 }
794 
795 /**
796  * @brief This function get the number of Packets of unidentified protocol received on an Ethernet Interface.
797  * This function provides the total number of packets received via this Ethernet interface which
798  * were discarded because they were of an unknown or unsupported protocol.
799  *
800  * @param[out] stMsgData TR-069 Host interface message request.
801  * @param[in] pChanged Status of the operation.
802  *
803  * @returns Returns '0' if the method successfully received the unknown proto packets via ethernet
804  * interface else returns '-1'.
805  * @ingroup TR69_HOSTIF_ETHERNET_INTERFACE_DEVICE_STATS_API
806  */
808 {
809  bCalledUnknownProtoPacketsReceived;
810  read_Device_Ethernet_Interface_Stats_Fields(dev_id,eUnknownProtoPacketsReceived);
811  if(bCalledMulticastPacketsSent && pChanged && (backupMulticastPacketsSent != stEthInterfaceStats.unknownProtoPacketsReceived))
812  {
813  *pChanged = true;
814  }
815  bCalledMulticastPacketsSent = true;
816  backupMulticastPacketsSent = stEthInterfaceStats.unknownProtoPacketsReceived;
817  put_int(stMsgData->paramValue,stEthInterfaceStats.unknownProtoPacketsReceived);
818  stMsgData->paramtype = hostIf_UnsignedIntType;
819  stMsgData->paramLen = 4;
820 
821  return OK;
822 }
823 
824 
825 /** @} */
826 /** @} */
hostIf_EthernetInterface::getInstance
static hostIf_EthernetInterface * getInstance(int dev_id)
Definition: Device_Ethernet_Interface.cpp:66
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_UnicastPacketsReceived
int get_Device_Ethernet_Interface_Stats_UnicastPacketsReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the number of unicast packets received on an Ethernet Interface.
Definition: Device_Ethernet_Interface_Stats.cpp:585
EthernetInterfaceStats
It contains the members variables of the EthernetInterfaceStats structure.
Device_Ethernet_Interface_Stats.h
The header file provides TR069 device ethernet interface stats information APIs.
hostIf_EthernetInterface::get_Device_Ethernet_Interface_Name
int get_Device_Ethernet_Interface_Name(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the textual name of the 'Ethernet' interface.
Definition: Device_Ethernet_Interface.cpp:622
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_UnknownProtoPacketsReceived
int get_Device_Ethernet_Interface_Stats_UnknownProtoPacketsReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function get the number of Packets of unidentified protocol received on an Ethernet Interface....
Definition: Device_Ethernet_Interface_Stats.cpp:807
hostIf_EthernetInterfaceStats
This class provides the interface for getting Device ethernet interface status information.
Definition: Device_Ethernet_Interface_Stats.h:174
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_BytesReceived
int get_Device_Ethernet_Interface_Stats_BytesReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the total number of bytes received on this Ethernet interface,...
Definition: Device_Ethernet_Interface_Stats.cpp:416
_HostIf_MsgData_t
Definition: hostIf_tr69ReqHandler.h:170
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_MulticastPacketsReceived
int get_Device_Ethernet_Interface_Stats_MulticastPacketsReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the number of Multicast Packets received on an Ethernet Interface.
Definition: Device_Ethernet_Interface_Stats.cpp:712
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_ErrorsSent
int get_Device_Ethernet_Interface_Stats_ErrorsSent(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the total number of outbound packets that could not be transmitted because of ...
Definition: Device_Ethernet_Interface_Stats.cpp:498
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_ErrorsReceived
int get_Device_Ethernet_Interface_Stats_ErrorsReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the total number of inbound packets that contained errors preventing them from...
Definition: Device_Ethernet_Interface_Stats.cpp:526
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_BroadcastPacketsSent
int get_Device_Ethernet_Interface_Stats_BroadcastPacketsSent(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function get the number of Broadcast Packets sent on an Ethernet Interface. This function provid...
Definition: Device_Ethernet_Interface_Stats.cpp:746
_HostIf_MsgData_t::paramtype
HostIf_ParamType_t paramtype
Definition: hostIf_tr69ReqHandler.h:177
RDK_LOG
#define RDK_LOG
Definition: rdk_debug.h:258
hostIf_EthernetInterface
This class provides the interface for getting Device ethernet interface information.
Definition: Device_Ethernet_Interface.h:195
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_DiscardPacketsReceived
int get_Device_Ethernet_Interface_Stats_DiscardPacketsReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the number of discarded inbound packets on an Ethernet Interface.
Definition: Device_Ethernet_Interface_Stats.cpp:651
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_UnicastPacketsSent
int get_Device_Ethernet_Interface_Stats_UnicastPacketsSent(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function get the number of unicast packets for which a request is send on the IP Interface was r...
Definition: Device_Ethernet_Interface_Stats.cpp:556
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_BroadcastPacketsReceived
int get_Device_Ethernet_Interface_Stats_BroadcastPacketsReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function get the number of Broadcast Packets received on an Ethernet Interface....
Definition: Device_Ethernet_Interface_Stats.cpp:778
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_BytesSent
int get_Device_Ethernet_Interface_Stats_BytesSent(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the total number of bytes transmitted out of this Ethernet interface,...
Definition: Device_Ethernet_Interface_Stats.cpp:388
_HostIf_MsgData_t::paramValue
char paramValue[(4 *1024)]
Definition: hostIf_tr69ReqHandler.h:172
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_DiscardPacketsSent
int get_Device_Ethernet_Interface_Stats_DiscardPacketsSent(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function get the number of discarded outbound packets on an Ethernet Interface....
Definition: Device_Ethernet_Interface_Stats.cpp:618
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_MulticastPacketsSent
int get_Device_Ethernet_Interface_Stats_MulticastPacketsSent(HOSTIF_MsgData_t *, bool *pChanged=NULL)
Get the number of Multicast Packets sent on an Ethernet Interface.
Definition: Device_Ethernet_Interface_Stats.cpp:682
hostIf_EthernetInterfaceStats::hostIf_EthernetInterfaceStats
hostIf_EthernetInterfaceStats(int dev_id)
Class Constructor of the class hostIf_EthernetInterfaceStats.
Definition: Device_Ethernet_Interface_Stats.cpp:335
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_PacketsSent
int get_Device_Ethernet_Interface_Stats_PacketsSent(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the total number of packets transmitted out of this Ethernet interface.
Definition: Device_Ethernet_Interface_Stats.cpp:443
EEthInterfaceStatsMembers
EEthInterfaceStatsMembers
These values are the members of the EEthInterfaceStatsMembers enum.
Definition: Device_Ethernet_Interface_Stats.h:82
put_int
void put_int(char *ptr, int val)
This function converts the input data to integer type.
Definition: hostIf_utils.cpp:152
Device_Ethernet_Interface.h
The header file provides TR069 device ethernet interface information APIs.
_HostIf_MsgData_t::paramLen
short paramLen
Definition: hostIf_tr69ReqHandler.h:175
hostIf_EthernetInterfaceStats::get_Device_Ethernet_Interface_Stats_PacketsReceived
int get_Device_Ethernet_Interface_Stats_PacketsReceived(HOSTIF_MsgData_t *, bool *pChanged=NULL)
This function provides the total number of packets received on this Ethernet interface.
Definition: Device_Ethernet_Interface_Stats.cpp:470