39 #include <sys/sysinfo.h>
40 #include <sys/ioctl.h>
41 #include <sys/socket.h>
42 #include <sys/types.h>
44 #include <arpa/inet.h>
51 GMutex* hostIf_EthernetInterfaceStats::m_mutex = NULL;
53 GHashTable* hostIf_EthernetInterfaceStats::ifHash = NULL;
56 extern int ethCount();
58 static int read_Device_Ethernet_Interface_Stats_Fields(
unsigned int ethInterfaceNum,
EEthInterfaceStatsMembers ethInterfaceStatMem)
61 char resultBuff[BUFF_LENGTH] = {
'\0'};
62 char cmd[BUFF_LENGTH] = {
'\0'};
64 char ethName[BUFF_LENGTH] = {
'\0'};
70 strncpy(ethName,stMsgData.
paramValue,BUFF_LENGTH -1);
72 switch(ethInterfaceStatMem)
75 sprintf(cmd,
"cat /sys/class/net/%s/statistics/tx_bytes",ethName);
81 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eBytesSent\n");
86 if(fgets(resultBuff,1024,fp)!=NULL)
88 sscanf(resultBuff,
"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.bytesSent);
95 sprintf(cmd,
"cat /sys/class/net/%s/statistics/rx_bytes",ethName);
101 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eBytesReceived\n");
106 if(fgets(resultBuff,1024,fp)!=NULL)
108 sscanf(resultBuff,
"%lu",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.bytesReceived);
114 case eUnicastPacketsSent:
115 case eMulticastPacketsSent:
116 case eBroadcastPacketsSent:
117 sprintf(cmd,
"cat /sys/class/net/%s/statistics/tx_packets",ethName);
123 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen ePacketsSent\n");
128 if(fgets(resultBuff,1024,fp)!=NULL)
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);
139 case ePacketsReceived:
140 case eUnicastPacketsReceived:
141 case eMulticastPacketsReceived:
142 case eBroadcastPacketsReceived:
143 sprintf(cmd,
"cat /sys/class/net/%s/statistics/rx_packets",ethName);
149 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen ePacketsReceived\n");
154 if(fgets(resultBuff,1024,fp)!=NULL)
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);
166 sprintf(cmd,
"cat /sys/class/net/%s/statistics/tx_errors",ethName);
172 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eErrorsSent\n");
177 if(fgets(resultBuff,1024,fp)!=NULL)
179 sscanf(resultBuff,
"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.errorsSent);
185 case eErrorsReceived:
186 sprintf(cmd,
"cat /sys/class/net/%s/statistics/rx_errors",ethName);
192 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eErrorsReceived\n");
197 if(fgets(resultBuff,1024,fp)!=NULL)
199 sscanf(resultBuff,
"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.errorsReceived);
205 case eDiscardPacketsSent:
206 sprintf(cmd,
"cat /sys/class/net/%s/statistics/tx_dropped",ethName);
212 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eDiscardPacketsSent \n");
217 if(fgets(resultBuff,1024,fp)!=NULL)
219 sscanf(resultBuff,
"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.discardPacketsSent);
225 case eDiscardPacketsReceived:
226 case eUnknownProtoPacketsReceived:
227 sprintf(cmd,
"cat /sys/class/net/%s/statistics/rx_dropped",ethName);
233 RDK_LOG(RDK_LOG_ERROR,LOG_TR69HOSTIF,
"\n read_Device_Ethernet_Interface_Stats_Fields(): Error in popen eDiscardPacketsReceived \n");
238 if(fgets(resultBuff,1024,fp)!=NULL)
240 sscanf(resultBuff,
"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.discardPacketsReceived);
241 sscanf(resultBuff,
"%u",&hostIf_EthernetInterfaceStats::stEthInterfaceStats.unknownProtoPacketsReceived);
265 ifHash = g_hash_table_new(NULL,NULL);
274 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create Ethernet Interface instance..\n");
276 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
281 GList* hostIf_EthernetInterfaceStats::getAllInstances()
284 return g_hash_table_get_keys(ifHash);
292 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
297 void hostIf_EthernetInterfaceStats::closeAllInstances()
301 GList* tmp_list = g_hash_table_get_values (ifHash);
306 tmp_list = tmp_list->next;
312 void hostIf_EthernetInterfaceStats::getLock()
317 m_mutex = g_mutex_new();
319 g_mutex_lock(m_mutex);
323 void hostIf_EthernetInterfaceStats::releaseLock()
325 g_mutex_unlock(m_mutex);
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),
348 backupErrorsReceived(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)
391 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBytesSent);
392 if(bCalledBytesSent && pChanged && (backupBytesSent != stEthInterfaceStats.bytesSent))
396 bCalledBytesSent =
true;
397 backupBytesSent = stEthInterfaceStats.bytesSent;
399 stMsgData->
paramtype = hostIf_UnsignedLongType;
419 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBytesReceived);
420 if(bCalledBytesReceived && pChanged && (backupBytesReceived != stEthInterfaceStats.bytesReceived))
424 bCalledBytesReceived =
true;
425 backupBytesReceived = stEthInterfaceStats.bytesReceived;
427 stMsgData->
paramtype = hostIf_UnsignedLongType;
446 read_Device_Ethernet_Interface_Stats_Fields(dev_id,ePacketsSent);
447 if(bCalledPacketsSent && pChanged && (backupPacketsSent != stEthInterfaceStats.packetsSent))
451 bCalledPacketsSent =
true;
452 backupPacketsSent = stEthInterfaceStats.packetsSent;
454 stMsgData->
paramtype = hostIf_UnsignedLongType;
473 read_Device_Ethernet_Interface_Stats_Fields(dev_id,ePacketsReceived);
474 if(bCalledPacketsReceived && pChanged && (backupPacketsReceived != stEthInterfaceStats.packetsReceived))
478 bCalledPacketsReceived =
true;
479 backupPacketsReceived = stEthInterfaceStats.packetsReceived;
481 stMsgData->
paramtype = hostIf_UnsignedLongType;
501 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eErrorsSent);
502 if(bCalledErrorSent && pChanged && (backupErrorSent != stEthInterfaceStats.errorsSent))
506 bCalledErrorSent =
true;
507 backupErrorSent = stEthInterfaceStats.errorsSent;
509 stMsgData->
paramtype = hostIf_UnsignedIntType;
529 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eErrorsReceived);
530 if(bCalledErrorsReceived && pChanged && (backupErrorsReceived != stEthInterfaceStats.errorsReceived))
534 bCalledErrorsReceived =
true;
535 backupErrorsReceived = stEthInterfaceStats.errorsReceived;
537 stMsgData->
paramtype = hostIf_UnsignedIntType;
559 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eUnicastPacketsSent);
560 if(bCalledErrorsSent && pChanged && (backupErrorsSent != stEthInterfaceStats.unicastPacketsSent))
564 bCalledErrorsSent =
true;
565 backupErrorsSent = stEthInterfaceStats.unicastPacketsSent;
567 stMsgData->
paramtype = hostIf_UnsignedLongType;
588 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eUnicastPacketsReceived);
589 if(bCalledUnicastPacketsReceived && pChanged && (backupUnicastPacketsReceived != stEthInterfaceStats.unicastPacketsReceived))
593 bCalledUnicastPacketsReceived =
true;
594 backupUnicastPacketsReceived = stEthInterfaceStats.unicastPacketsReceived;
596 stMsgData->
paramtype = hostIf_UnsignedLongType;
620 bCalledDiscardPacketsSent;
621 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eDiscardPacketsSent);
622 if(bCalledUnicastPacketsSent && pChanged && (backupUnicastPacketsSent != stEthInterfaceStats.discardPacketsSent))
626 bCalledUnicastPacketsSent =
true;
627 backupUnicastPacketsSent = stEthInterfaceStats.discardPacketsSent;
629 stMsgData->
paramtype = hostIf_UnsignedIntType;
654 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eDiscardPacketsReceived);
655 if(bCalledDiscardPacketsReceived && pChanged && (backupDiscardPacketsReceived != stEthInterfaceStats.discardPacketsReceived))
659 bCalledDiscardPacketsReceived =
true;
660 backupDiscardPacketsReceived = stEthInterfaceStats.discardPacketsReceived;
662 stMsgData->
paramtype = hostIf_UnsignedIntType;
685 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eMulticastPacketsSent);
686 if(bCalledUnicastPacketsReceived && pChanged && (backupUnicastPacketsReceived != stEthInterfaceStats.multicastPacketsSent))
690 bCalledUnicastPacketsReceived =
true;
691 backupUnicastPacketsReceived = stEthInterfaceStats.multicastPacketsSent;
693 stMsgData->
paramtype = hostIf_UnsignedLongType;
715 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eMulticastPacketsReceived);
716 if(bCalledMulticastPacketsReceived && pChanged && (backupMulticastPacketsReceived != stEthInterfaceStats.multicastPacketsReceived))
720 bCalledMulticastPacketsReceived =
true;
721 backupMulticastPacketsReceived = stEthInterfaceStats.multicastPacketsReceived;
723 stMsgData->
paramtype = hostIf_UnsignedLongType;
749 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBroadcastPacketsSent);
750 if(bCalledBroadcastPacketsSent && pChanged && (backupBroadcastPacketsSent != stEthInterfaceStats.broadcastPacketsSent))
754 bCalledBroadcastPacketsSent =
true;
755 backupBroadcastPacketsSent = stEthInterfaceStats.broadcastPacketsSent;
757 stMsgData->
paramtype = hostIf_UnsignedLongType;
781 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eBroadcastPacketsReceived);
782 if(bCalledBroadcastPacketsReceived && pChanged && (backupBroadcastPacketsReceived != stEthInterfaceStats.broadcastPacketsReceived))
786 bCalledBroadcastPacketsReceived =
true;
787 backupBroadcastPacketsReceived = stEthInterfaceStats.broadcastPacketsReceived;
789 stMsgData->
paramtype = hostIf_UnsignedLongType;
809 bCalledUnknownProtoPacketsReceived;
810 read_Device_Ethernet_Interface_Stats_Fields(dev_id,eUnknownProtoPacketsReceived);
811 if(bCalledMulticastPacketsSent && pChanged && (backupMulticastPacketsSent != stEthInterfaceStats.unknownProtoPacketsReceived))
815 bCalledMulticastPacketsSent =
true;
816 backupMulticastPacketsSent = stEthInterfaceStats.unknownProtoPacketsReceived;
818 stMsgData->
paramtype = hostIf_UnsignedIntType;