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_IPInterfaceStats::m_mutex = NULL;
53 GHashTable *hostIf_IPInterfaceStats::ifHash = NULL;
56 void hostIf_IPInterfaceStats::refreshInterfaceName ()
58 nameOfInterface[0] = 0;
60 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"%s: error getting interface name for Device.IP.Interface.%d\n", __FUNCTION__, dev_id);
73 ifHash = g_hash_table_new(NULL,NULL);
82 RDK_LOG(RDK_LOG_WARN,LOG_TR69HOSTIF,
"Caught exception, not able create hostIf_IPInterfaceStats instance..\n");
84 g_hash_table_insert(ifHash, (gpointer)dev_id, pRet);
89 pRet->refreshInterfaceName ();
94 GList* hostIf_IPInterfaceStats::getAllInstances()
97 return g_hash_table_get_keys(ifHash);
105 g_hash_table_remove(ifHash, (gconstpointer)pDev->dev_id);
110 void hostIf_IPInterfaceStats::closeAllInstances()
114 GList* tmp_list = g_hash_table_get_values (ifHash);
119 tmp_list = tmp_list->next;
125 void hostIf_IPInterfaceStats::getLock()
129 m_mutex = g_mutex_new();
131 g_mutex_lock(m_mutex);
134 void hostIf_IPInterfaceStats::releaseLock()
136 g_mutex_unlock(m_mutex);
149 backupBytesReceived(0),
150 backupPacketsSent(0),
151 backupPacketsReceived(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)
181 int hostIf_IPInterfaceStats::handleGetMsg (
const char* pSetting,
HOSTIF_MsgData_t* stMsgData)
183 int ret = NOT_HANDLED;
185 if (!strcasecmp (pSetting,
"Stats.BytesSent"))
189 else if (!strcasecmp (pSetting,
"Stats.BytesReceived"))
193 else if (!strcasecmp (pSetting,
"Stats.PacketsSent"))
197 else if (!strcasecmp (pSetting,
"Stats.PacketsReceived"))
201 else if (!strcasecmp (pSetting,
"Stats.ErrorsSent"))
205 else if (!strcasecmp (pSetting,
"Stats.ErrorsReceived"))
209 else if (!strcasecmp (pSetting,
"Stats.UnicastPacketsSent"))
213 else if (!strcasecmp (pSetting,
"Stats.UnicastPacketsReceived"))
217 else if (!strcasecmp (pSetting,
"Stats.DiscardPacketsSent"))
221 else if (!strcasecmp (pSetting,
"Stats.DiscardPacketsReceived"))
225 else if (!strcasecmp (pSetting,
"Stats.MulticastPacketsSent"))
229 else if (!strcasecmp (pSetting,
"Stats.MulticastPacketsReceived"))
233 else if (!strcasecmp (pSetting,
"Stats.BroadcastPacketsSent"))
237 else if (!strcasecmp (pSetting,
"Stats.BroadcastPacketsReceived"))
241 else if (!strcasecmp (pSetting,
"Stats.UnknownProtoPacketsReceived"))
249 int hostIf_IPInterfaceStats::getSysClassNetStatistic (
char* statistic,
unsigned long* result)
252 char filename[BUFF_LENGTH_64];
253 sprintf (filename,
"/sys/class/net/%s/statistics/%s", nameOfInterface, statistic);
255 FILE* fp = fopen (filename,
"r");
258 RDK_LOG (RDK_LOG_ERROR, LOG_TR69HOSTIF,
"\n[%s(), %d] Error in fopen(%s)\n", __FUNCTION__, __LINE__, filename);
262 if (1 == fscanf (fp,
"%ld", result))
289 curntIpStat.bytesSent = 0;
290 getSysClassNetStatistic (
"tx_bytes", &curntIpStat.bytesSent);
292 if(bCalledBytesSent && pChanged && (backupBytesSent != curntIpStat.bytesSent))
296 bCalledBytesSent =
true;
297 backupBytesSent = curntIpStat.bytesSent;
299 stMsgData->
paramtype = hostIf_UnsignedLongType;
300 stMsgData->
paramLen =
sizeof(
unsigned long);
320 curntIpStat.bytesReceived = 0;
321 getSysClassNetStatistic (
"rx_bytes", &curntIpStat.bytesReceived);
323 if(bCalledBytesReceived && pChanged && (backupBytesReceived != curntIpStat.bytesReceived))
327 bCalledBytesReceived =
true;
328 backupBytesReceived = curntIpStat.bytesReceived;
330 stMsgData->
paramtype = hostIf_UnsignedLongType;
331 stMsgData->
paramLen =
sizeof(
unsigned long);
351 curntIpStat.packetsSent = 0;
352 getSysClassNetStatistic (
"tx_packets", &curntIpStat.packetsSent);
354 if(bCalledPacketsSent && pChanged && (backupPacketsSent != curntIpStat.packetsSent))
358 bCalledPacketsSent =
true;
359 backupPacketsSent = curntIpStat.packetsSent;
361 stMsgData->
paramtype = hostIf_UnsignedLongType;
362 stMsgData->
paramLen =
sizeof(
unsigned long);
381 curntIpStat.packetsReceived = 0;
382 getSysClassNetStatistic (
"rx_packets", &curntIpStat.packetsReceived);
387 if(bCalledPacketsReceived && pChanged && (backupPacketsReceived != curntIpStat.packetsReceived))
391 bCalledPacketsReceived =
true;
392 backupPacketsReceived = curntIpStat.packetsReceived;
394 stMsgData->
paramtype = hostIf_UnsignedLongType;
395 stMsgData->
paramLen =
sizeof(
unsigned long);
415 curntIpStat.errorsSent = 0;
416 getSysClassNetStatistic (
"tx_errors", &curntIpStat.errorsSent);
418 if(bCalledErrorsSent && pChanged && (backupErrorsSent != curntIpStat.errorsSent))
422 bCalledErrorsSent =
true;
423 backupErrorsSent = curntIpStat.errorsSent;
425 stMsgData->
paramtype = hostIf_UnsignedIntType;
447 curntIpStat.errorsReceived = 0;
448 getSysClassNetStatistic (
"rx_errors", &curntIpStat.errorsReceived);
450 if(bCalledErrorsReceived && pChanged && (backupErrorsReceived != curntIpStat.errorsReceived))
454 bCalledErrorsReceived =
true;
455 backupErrorsReceived = curntIpStat.errorsReceived;
457 stMsgData->
paramtype = hostIf_UnsignedIntType;
480 curntIpStat.unicastPacketsSent = 0;
481 getSysClassNetStatistic (
"tx_packets", &curntIpStat.unicastPacketsSent);
483 if(bCalledUnicastPacketsSent && pChanged && (backupUnicastPacketsSent != curntIpStat.unicastPacketsSent))
487 bCalledUnicastPacketsSent =
true;
488 backupUnicastPacketsSent = curntIpStat.unicastPacketsSent;
490 stMsgData->
paramtype = hostIf_UnsignedLongType;
491 stMsgData->
paramLen =
sizeof(
unsigned long);
512 curntIpStat.unicastPacketsReceived = 0;
513 getSysClassNetStatistic (
"rx_packets", &curntIpStat.unicastPacketsReceived);
515 if(bCalledUnicastPacketsReceived && pChanged && (backupUnicastPacketsReceived != curntIpStat.unicastPacketsReceived))
519 bCalledUnicastPacketsReceived =
true;
520 backupUnicastPacketsReceived = curntIpStat.unicastPacketsReceived;
522 stMsgData->
paramtype = hostIf_UnsignedLongType;
523 stMsgData->
paramLen =
sizeof(
unsigned long);
546 curntIpStat.discardPacketsSent = 0;
547 getSysClassNetStatistic (
"tx_dropped", &curntIpStat.discardPacketsSent);
549 if(bCalledDiscardPacketsSent && pChanged && (backupDiscardPacketsSent != curntIpStat.discardPacketsSent))
553 bCalledDiscardPacketsSent =
true;
554 backupDiscardPacketsSent = curntIpStat.discardPacketsSent;
556 stMsgData->
paramtype = hostIf_UnsignedIntType;
580 curntIpStat.discardPacketsReceived = 0;
581 getSysClassNetStatistic (
"rx_dropped", &curntIpStat.discardPacketsReceived);
583 if(bCalledDiscardPacketsReceived && pChanged && (backupDiscardPacketsReceived != curntIpStat.discardPacketsReceived))
587 bCalledDiscardPacketsReceived =
true;
588 backupDiscardPacketsReceived = curntIpStat.discardPacketsReceived;
590 stMsgData->
paramtype = hostIf_UnsignedIntType;
612 curntIpStat.multicastPacketsSent = 0;
613 getSysClassNetStatistic (
"tx_packets", &curntIpStat.multicastPacketsSent);
615 if(bCalledMulticastPacketsSent && pChanged && (backupMulticastPacketsSent != curntIpStat.multicastPacketsSent))
619 bCalledMulticastPacketsSent =
true;
620 backupMulticastPacketsSent = curntIpStat.multicastPacketsSent;
622 stMsgData->
paramtype = hostIf_UnsignedLongType;
623 stMsgData->
paramLen =
sizeof(
unsigned long);
644 curntIpStat.multicastPacketsReceived = 0;
645 getSysClassNetStatistic (
"multicast", &curntIpStat.multicastPacketsReceived);
647 if(bCalledMulticastPacketsReceived && pChanged && (backupMulticastPacketsReceived != curntIpStat.multicastPacketsReceived))
651 bCalledMulticastPacketsReceived =
true;
652 backupMulticastPacketsReceived = curntIpStat.multicastPacketsReceived;
654 stMsgData->
paramtype = hostIf_UnsignedLongType;
655 stMsgData->
paramLen =
sizeof(
unsigned long);
678 curntIpStat.broadcastPacketsSent = 0;
679 getSysClassNetStatistic (
"tx_packets", &curntIpStat.broadcastPacketsSent);
681 if(bCalledBroadcastPacketsSent && pChanged && (backupBroadcastPacketsSent != curntIpStat.broadcastPacketsSent))
685 bCalledBroadcastPacketsSent =
true;
686 backupBroadcastPacketsSent = curntIpStat.broadcastPacketsSent;
688 stMsgData->
paramtype = hostIf_UnsignedLongType;
689 stMsgData->
paramLen =
sizeof(
unsigned long);
713 curntIpStat.broadcastPacketsReceived = 0;
714 getSysClassNetStatistic (
"rx_packets", &curntIpStat.broadcastPacketsReceived);
716 if(bCalledBroadcastPacketsReceived && pChanged && (backupBroadcastPacketsReceived != curntIpStat.broadcastPacketsReceived))
720 bCalledBroadcastPacketsReceived =
true;
721 backupBroadcastPacketsReceived = curntIpStat.broadcastPacketsReceived;
723 stMsgData->
paramtype = hostIf_UnsignedIntType;
745 curntIpStat.unknownProtoPacketsReceived = 0;
746 getSysClassNetStatistic (
"rx_dropped", &curntIpStat.unknownProtoPacketsReceived);
748 if(bCalledUnknownProtoPacketsReceived && pChanged && (backupUnknownProtoPacketsReceived != curntIpStat.unknownProtoPacketsReceived))
752 bCalledUnknownProtoPacketsReceived =
true;
753 backupUnknownProtoPacketsReceived = curntIpStat.unknownProtoPacketsReceived;
755 stMsgData->
paramtype = hostIf_UnsignedIntType;