statistics.cpp 20 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531
  1. // Aidmar
  2. #include <iostream>
  3. #include <fstream>
  4. #include <vector>
  5. #include <math.h>
  6. #include "statistics.h"
  7. #include <sstream>
  8. #include <SQLiteCpp/SQLiteCpp.h>
  9. #include "statistics_db.h"
  10. // Aidmar
  11. void statistics::addIPEntropy(){
  12. std::vector <std::string> IPs;
  13. std::vector <float> IPsSrcProb;
  14. std::vector <float> IPsDstProb;
  15. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  16. IPs.push_back(i->first);
  17. IPsSrcProb.push_back((float)i->second.pkts_sent/packetCount);
  18. IPsDstProb.push_back((float)i->second.pkts_received/packetCount);
  19. /*std::cout << i->first << ":" << i->second.pkts_sent << ":" << i->second.pkts_received << ":"
  20. << i->second.firstAppearAsSenderPktCount << ":" << i->second.firstAppearAsReceiverPktCount << ":"
  21. << packetCount << "\n";*/
  22. }
  23. // Calculate IP source entropy
  24. float IPsSrcEntropy = 0;
  25. for(unsigned i=0; i < IPsSrcProb.size();i++){
  26. if (IPsSrcProb[i] > 0)
  27. IPsSrcEntropy += - IPsSrcProb[i]*log2(IPsSrcProb[i]);
  28. }
  29. std::cout << packetCount << ": SrcEnt: " << IPsSrcEntropy << "\n";
  30. // Calculate IP destination entropy
  31. float IPsDstEntropy = 0;
  32. for(unsigned i=0; i < IPsDstProb.size();i++){
  33. if (IPsDstProb[i] > 0)
  34. IPsDstEntropy += - IPsDstProb[i]*log2(IPsDstProb[i]);
  35. }
  36. std::cout << packetCount << ": DstEnt: " << IPsDstEntropy << "\n";
  37. /*
  38. // Calculate IP source tn/r anomaly score
  39. float ipSrc_Mahoney_score = 0;
  40. // The number of IP sources (the different values)
  41. int s_r = 0;
  42. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  43. if (i->second.pkts_sent > 0)
  44. s_r++;
  45. }
  46. if(s_r > 0){
  47. // The number of the total instances
  48. int n = packetCount;
  49. // The packet count when the last novel IP was added as a sender
  50. int pktCntNvlSndr = 0;
  51. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  52. if (pktCntNvlSndr < i->second.firstAppearAsSenderPktCount)
  53. pktCntNvlSndr = i->second.firstAppearAsSenderPktCount;
  54. }
  55. // The "time" since last anomalous (novel) IP was appeared
  56. int s_t = packetCount - pktCntNvlSndr + 1;
  57. ipSrc_Mahoney_score = (float)s_t*n/s_r;
  58. std::cout << s_t << ":" << n << ":" << s_r << "\n";
  59. std::cout << packetCount << ": Mahoney score: " << ipSrc_Mahoney_score << "\n";
  60. }
  61. // Calculate IP destination tn/r anomaly score
  62. float ipDst_Mahoney_score = 0;
  63. // The number of IP sources (the different values)
  64. int d_r = 0;
  65. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  66. if (i->second.pkts_received > 0)
  67. d_r++;
  68. }
  69. if(d_r > 0){
  70. // The number of the total instances
  71. int n = packetCount;
  72. // The packet count when the last novel IP was added as a sender
  73. int pktCntNvlRcvr = 0;
  74. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  75. if (pktCntNvlRcvr < i->second.firstAppearAsReceiverPktCount)
  76. pktCntNvlRcvr = i->second.firstAppearAsReceiverPktCount;
  77. }
  78. // The "time" since last anomalous (novel) IP was appeared
  79. int d_t = packetCount - pktCntNvlRcvr + 1;
  80. ipDst_Mahoney_score = (float)d_t*n/d_r;
  81. std::cout << d_t << ":" << n << ":" << d_r << "\n";
  82. std::cout << packetCount << ": Anomaly score: " << ipDst_Mahoney_score << "\n";
  83. }
  84. */
  85. // Write stats to file
  86. std::ofstream file;
  87. file.open ("ip_entropy.csv",std::ios_base::app);
  88. file << packetCount << "," << IPsSrcEntropy << "," << IPsDstEntropy << "\n";
  89. file.close();
  90. }
  91. // Aidmar
  92. void statistics::addFlowStat(std::string ipAddressSender,int sport,std::string ipAddressReceiver,int dport){
  93. std::cout<<ipAddressSender<<":"<<sport<<","<<ipAddressReceiver<<":"<<dport<<"\n";
  94. // if already exist A(ipAddressReceiver, dport), B(ipAddressSender, sport)
  95. /*if (flow_statistics.count({ipAddressReceiver, dport, ipAddressSender, sport})>0){
  96. flow_statistics[{ipAddressReceiver, dport, ipAddressSender, sport}].pkts_B_A++;
  97. std::cout<<flow_statistics[{ipAddressReceiver, dport, ipAddressSender, sport}].pkts_A_B<<"\n";
  98. std::cout<<flow_statistics[{ipAddressReceiver, dport, ipAddressSender, sport}].pkts_B_A<<"\n";
  99. }
  100. else{*/
  101. std::cout<<flow_statistics[{ipAddressSender, sport, ipAddressReceiver, dport}].pkts_A_B<<"\n";
  102. flow_statistics[{ipAddressSender, sport, ipAddressReceiver, dport}].pkts_A_B++;
  103. std::cout<<flow_statistics[{ipAddressSender, sport, ipAddressReceiver, dport}].pkts_A_B<<"\n";
  104. std::cout<<flow_statistics[{ipAddressSender, sport, ipAddressReceiver, dport}].pkts_B_A<<"\n";
  105. //}
  106. }
  107. // Aidmar
  108. /**
  109. * Increments the packet counter for the given IP address and MSS value.
  110. * @param ipAddress The IP address whose MSS packet counter should be incremented.
  111. * @param mssValue The MSS value of the packet.
  112. */
  113. void statistics::incrementMSScount(std::string ipAddress, int mssValue) {
  114. mss_distribution[{ipAddress, mssValue}]++;
  115. }
  116. // Aidmar
  117. /**
  118. * Increments the packet counter for the given IP address and window size.
  119. * @param ipAddress The IP address whose window size packet counter should be incremented.
  120. * @param winSize The window size of the packet.
  121. */
  122. void statistics::incrementWinCount(std::string ipAddress, int winSize) {
  123. win_distribution[{ipAddress, winSize}]++;
  124. }
  125. /**
  126. * Increments the packet counter for the given IP address and TTL value.
  127. * @param ipAddress The IP address whose TTL packet counter should be incremented.
  128. * @param ttlValue The TTL value of the packet.
  129. */
  130. void statistics::incrementTTLcount(std::string ipAddress, int ttlValue) {
  131. ttl_distribution[{ipAddress, ttlValue}]++;
  132. }
  133. /**
  134. * Increments the protocol counter for the given IP address and protocol.
  135. * @param ipAddress The IP address whose protocol packet counter should be incremented.
  136. * @param protocol The protocol of the packet.
  137. */
  138. void statistics::incrementProtocolCount(std::string ipAddress, std::string protocol) {
  139. protocol_distribution[{ipAddress, protocol}]++;
  140. }
  141. /**
  142. * Returns the number of packets seen for the given IP address and protocol.
  143. * @param ipAddress The IP address whose packet count is wanted.
  144. * @param protocol The protocol whose packet count is wanted.
  145. * @return an integer: the number of packets
  146. */
  147. int statistics::getProtocolCount(std::string ipAddress, std::string protocol) {
  148. return protocol_distribution[{ipAddress, protocol}];
  149. }
  150. /**
  151. * Increments the packet counter for
  152. * - the given sender IP address with outgoing port and
  153. * - the given receiver IP address with incoming port.
  154. * @param ipAddressSender The IP address of the packet sender.
  155. * @param outgoingPort The port used by the sender.
  156. * @param ipAddressReceiver The IP address of the packet receiver.
  157. * @param incomingPort The port used by the receiver.
  158. */
  159. void statistics::incrementPortCount(std::string ipAddressSender, int outgoingPort, std::string ipAddressReceiver,
  160. int incomingPort) {
  161. ip_ports[{ipAddressSender, "out", outgoingPort}]++;
  162. ip_ports[{ipAddressReceiver, "in", incomingPort}]++;
  163. }
  164. /**
  165. * Creates a new statistics object.
  166. */
  167. statistics::statistics(void) {
  168. }
  169. /**
  170. * Stores the assignment IP address -> MAC address.
  171. * @param ipAddress The IP address belonging to the given MAC address.
  172. * @param macAddress The MAC address belonging to the given IP address.
  173. */
  174. void statistics::assignMacAddress(std::string ipAddress, std::string macAddress) {
  175. ip_mac_mapping[ipAddress] = macAddress;
  176. }
  177. /**
  178. * Registers statistical data for a sent packet. Increments the counter packets_sent for the sender and
  179. * packets_received for the receiver. Adds the bytes as kbytes_sent (sender) and kybtes_received (receiver).
  180. * @param ipAddressSender The IP address of the packet sender.
  181. * @param ipAddressReceiver The IP address of the packet receiver.
  182. * @param bytesSent The packet's size.
  183. */
  184. void statistics::addIpStat_packetSent(std::string ipAddressSender, std::string ipAddressReceiver, long bytesSent) {
  185. // Aidmar - Adding IP as a sender for first time
  186. if(ip_statistics[ipAddressSender].pkts_sent==0){
  187. // Caculate Mahoney anomaly score for ip.src
  188. float ipSrc_Mahoney_score = 0;
  189. // s_r: The number of IP sources (the different values)
  190. // n: The number of the total instances
  191. // s_t: The "time" since last anomalous (novel) IP was appeared
  192. int s_t = 0, n = 0, s_r = 0;
  193. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  194. if (i->second.pkts_sent > 0)
  195. s_r++;
  196. }
  197. if(s_r > 0){
  198. // The number of the total instances
  199. n = packetCount;
  200. // The packet count when the last novel IP was added as a sender
  201. int pktCntNvlSndr = 0;
  202. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  203. if (pktCntNvlSndr < i->second.firstAppearAsSenderPktCount)
  204. pktCntNvlSndr = i->second.firstAppearAsSenderPktCount;
  205. }
  206. // The "time" since last anomalous (novel) IP was appeared
  207. s_t = packetCount - pktCntNvlSndr + 1;
  208. ipSrc_Mahoney_score = (float)s_t*n/s_r;
  209. }
  210. // Write stats to file
  211. std::ofstream file;
  212. file.open ("ip_src_anomaly_score.csv",std::ios_base::app);
  213. file << ipAddressSender << ","<< s_t << "," << n << "," << s_r << "," << ipSrc_Mahoney_score << "\n";
  214. file.close();
  215. ip_statistics[ipAddressSender].firstAppearAsSenderPktCount = packetCount;
  216. ip_statistics[ipAddressSender].sourceAnomalyScore = ipSrc_Mahoney_score;
  217. }
  218. // Aidmar - Adding IP as a receiver for first time
  219. if(ip_statistics[ipAddressReceiver].pkts_received==0){
  220. // Caculate Mahoney anomaly score for ip.dst
  221. float ipDst_Mahoney_score = 0;
  222. // s_r: The number of IP sources (the different values)
  223. // n: The number of the total instances
  224. // s_t: The "time" since last anomalous (novel) IP was appeared
  225. int s_t = 0, n = 0, s_r = 0;
  226. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  227. if (i->second.pkts_received > 0)
  228. s_r++;
  229. }
  230. if(s_r > 0){
  231. // The number of the total instances
  232. n = packetCount;
  233. // The packet count when the last novel IP was added as a sender
  234. int pktCntNvlRcvr = 0;
  235. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  236. if (pktCntNvlRcvr < i->second.firstAppearAsReceiverPktCount)
  237. pktCntNvlRcvr = i->second.firstAppearAsReceiverPktCount;
  238. }
  239. // The "time" since last anomalous (novel) IP was appeared
  240. s_t = packetCount - pktCntNvlRcvr + 1;
  241. ipDst_Mahoney_score = (float)s_t*n/s_r;
  242. }
  243. // Write stats to file
  244. std::ofstream file;
  245. file.open ("ip_dst_anomaly_score.csv",std::ios_base::app);
  246. file << ipAddressReceiver << ","<< s_t << "," << n << "," << s_r << "," << ipDst_Mahoney_score << "\n";
  247. file.close();
  248. ip_statistics[ipAddressReceiver].firstAppearAsReceiverPktCount = packetCount;
  249. ip_statistics[ipAddressReceiver].destinationAnomalyScore = ipDst_Mahoney_score;
  250. }
  251. // Update stats for packet sender
  252. ip_statistics[ipAddressSender].kbytes_sent += (float(bytesSent) / 1024);
  253. ip_statistics[ipAddressSender].pkts_sent++;
  254. // Update stats for packet receiver
  255. ip_statistics[ipAddressReceiver].kbytes_received += (float(bytesSent) / 1024);
  256. ip_statistics[ipAddressReceiver].pkts_received++;
  257. }
  258. /**
  259. * Registers a value of the TCP option Maximum Segment Size (MSS).
  260. * @param ipAddress The IP address which sent the TCP packet.
  261. * @param MSSvalue The MSS value found.
  262. */
  263. void statistics::addMSS(std::string ipAddress, int MSSvalue) {
  264. ip_sumMss[ipAddress] += MSSvalue;
  265. }
  266. /**
  267. * Setter for the timestamp_firstPacket field.
  268. * @param ts The timestamp of the first packet in the PCAP file.
  269. */
  270. void statistics::setTimestampFirstPacket(Tins::Timestamp ts) {
  271. timestamp_firstPacket = ts;
  272. }
  273. /**
  274. * Setter for the timestamp_lastPacket field.
  275. * @param ts The timestamp of the last packet in the PCAP file.
  276. */
  277. void statistics::setTimestampLastPacket(Tins::Timestamp ts) {
  278. timestamp_lastPacket = ts;
  279. }
  280. /**
  281. * Calculates the capture duration.
  282. * @return a formatted string HH:MM:SS.mmmmmm with
  283. * HH: hour, MM: minute, SS: second, mmmmmm: microseconds
  284. */
  285. std::string statistics::getCaptureDurationTimestamp() const {
  286. // Calculate duration
  287. time_t t = (timestamp_lastPacket.seconds() - timestamp_firstPacket.seconds());
  288. time_t ms = (timestamp_lastPacket.microseconds() - timestamp_firstPacket.microseconds());
  289. long int hour = t / 3600;
  290. long int remainder = (t - hour * 3600);
  291. long int minute = remainder / 60;
  292. long int second = (remainder - minute * 60) % 60;
  293. long int microseconds = ms;
  294. // Build desired output format: YYYY-mm-dd hh:mm:ss
  295. char out[64];
  296. sprintf(out, "%02ld:%02ld:%02ld.%06ld ", hour, minute, second, microseconds);
  297. return std::string(out);
  298. }
  299. /**
  300. * Calculates the capture duration.
  301. * @return a formatted string SS.mmmmmm with
  302. * S: seconds (UNIX time), mmmmmm: microseconds
  303. */
  304. float statistics::getCaptureDurationSeconds() const {
  305. timeval d;
  306. d.tv_sec = timestamp_lastPacket.seconds() - timestamp_firstPacket.seconds();
  307. d.tv_usec = timestamp_lastPacket.microseconds() - timestamp_firstPacket.microseconds();
  308. char tmbuf[64], buf[64];
  309. auto nowtm = localtime(&(d.tv_sec));
  310. strftime(tmbuf, sizeof(tmbuf), "%S", nowtm);
  311. snprintf(buf, sizeof(buf), "%s.%06u", tmbuf, (uint) d.tv_usec);
  312. return std::stof(std::string(buf));
  313. }
  314. /**
  315. * Creates a timestamp based on a time_t seconds (UNIX time format) and microseconds.
  316. * @param seconds
  317. * @param microseconds
  318. * @return a formatted string Y-m-d H:M:S.m with
  319. * Y: year, m: month, d: day, H: hour, M: minute, S: second, m: microseconds
  320. */
  321. std::string statistics::getFormattedTimestamp(time_t seconds, suseconds_t microseconds) const {
  322. timeval tv;
  323. tv.tv_sec = seconds;
  324. tv.tv_usec = microseconds;
  325. char tmbuf[64], buf[64];
  326. auto nowtm = localtime(&(tv.tv_sec));
  327. strftime(tmbuf, sizeof(tmbuf), "%Y-%m-%d %H:%M:%S", nowtm);
  328. snprintf(buf, sizeof(buf), "%s.%06u", tmbuf, (uint) tv.tv_usec);
  329. return std::string(buf);
  330. }
  331. /**
  332. * Calculates the statistics for a given IP address.
  333. * @param ipAddress The IP address whose statistics should be calculated.
  334. * @return a ip_stats struct containing statistical data derived by the statistical data collected.
  335. */
  336. ip_stats statistics::getStatsForIP(std::string ipAddress) {
  337. float duration = getCaptureDurationSeconds();
  338. entry_ipStat ipStatEntry = ip_statistics[ipAddress];
  339. ip_stats s;
  340. s.bandwidthKBitsIn = (ipStatEntry.kbytes_received / duration) * 8;
  341. s.bandwidthKBitsOut = (ipStatEntry.kbytes_sent / duration) * 8;
  342. s.packetPerSecondIn = (ipStatEntry.pkts_received / duration);
  343. s.packetPerSecondOut = (ipStatEntry.pkts_sent / duration);
  344. s.AvgPacketSizeSent = (ipStatEntry.kbytes_sent / ipStatEntry.pkts_sent);
  345. s.AvgPacketSizeRecv = (ipStatEntry.kbytes_received / ipStatEntry.pkts_received);
  346. int sumMSS = ip_sumMss[ipAddress];
  347. int tcpPacketsSent = getProtocolCount(ipAddress, "TCP");
  348. s.AvgMaxSegmentSizeTCP = ((sumMSS > 0 && tcpPacketsSent > 0) ? (sumMSS / tcpPacketsSent) : 0);
  349. return s;
  350. }
  351. /**
  352. * Increments the packet counter.
  353. */
  354. void statistics::incrementPacketCount() {
  355. packetCount++;
  356. }
  357. /**
  358. * Prints the statistics of the PCAP and IP specific statistics for the given IP address.
  359. * @param ipAddress The IP address whose statistics should be printed. Can be empty "" to print only general file statistics.
  360. */
  361. void statistics::printStats(std::string ipAddress) {
  362. std::stringstream ss;
  363. ss << std::endl;
  364. ss << "Capture duration: " << getCaptureDurationSeconds() << " seconds" << std::endl;
  365. ss << "Capture duration (HH:MM:SS.mmmmmm): " << getCaptureDurationTimestamp() << std::endl;
  366. ss << "#Packets: " << packetCount << std::endl;
  367. ss << std::endl;
  368. // Print IP address specific statistics only if IP address was given
  369. if (ipAddress != "") {
  370. entry_ipStat e = ip_statistics[ipAddress];
  371. ss << "\n----- STATS FOR IP ADDRESS [" << ipAddress << "] -------" << std::endl;
  372. ss << std::endl << "KBytes sent: " << e.kbytes_sent << std::endl;
  373. ss << "KBytes received: " << e.kbytes_received << std::endl;
  374. ss << "Packets sent: " << e.pkts_sent << std::endl;
  375. ss << "Packets received: " << e.pkts_received << "\n\n";
  376. ip_stats is = getStatsForIP(ipAddress);
  377. ss << "Bandwidth IN: " << is.bandwidthKBitsIn << " kbit/s" << std::endl;
  378. ss << "Bandwidth OUT: " << is.bandwidthKBitsOut << " kbit/s" << std::endl;
  379. ss << "Packets per second IN: " << is.packetPerSecondIn << std::endl;
  380. ss << "Packets per second OUT: " << is.packetPerSecondOut << std::endl;
  381. ss << "Avg Packet Size Sent: " << is.AvgPacketSizeSent << " kbytes" << std::endl;
  382. ss << "Avg Packet Size Received: " << is.AvgPacketSizeRecv << " kbytes" << std::endl;
  383. ss << "Avg MSS: " << is.AvgMaxSegmentSizeTCP << " bytes" << std::endl;
  384. }
  385. std::cout << ss.str();
  386. }
  387. /**
  388. * Derives general PCAP file statistics from the collected statistical data and
  389. * writes all data into a SQLite database, located at database_path.
  390. * @param database_path The path of the SQLite database file ending with .sqlite3.
  391. */
  392. void statistics::writeToDatabase(std::string database_path) {
  393. // Generate general file statistics
  394. float duration = getCaptureDurationSeconds();
  395. long sumPacketsSent = 0, senderCountIP = 0;
  396. float sumBandwidthIn = 0.0, sumBandwidthOut = 0.0;
  397. for (auto i = ip_statistics.begin(); i != ip_statistics.end(); i++) {
  398. sumPacketsSent += i->second.pkts_sent;
  399. // Consumed bandwith (bytes) for sending packets
  400. sumBandwidthIn += (i->second.kbytes_received / duration);
  401. sumBandwidthOut += (i->second.kbytes_sent / duration);
  402. senderCountIP++;
  403. }
  404. float avgPacketRate = (packetCount / duration);
  405. long avgPacketSize = getAvgPacketSize();
  406. long avgPacketsSentPerHost = (sumPacketsSent / senderCountIP);
  407. float avgBandwidthInKBits = (sumBandwidthIn / senderCountIP) * 8;
  408. float avgBandwidthOutInKBits = (sumBandwidthOut / senderCountIP) * 8;
  409. // Create database and write information
  410. statistics_db db(database_path);
  411. db.writeStatisticsFile(packetCount, getCaptureDurationSeconds(),
  412. getFormattedTimestamp(timestamp_firstPacket.seconds(), timestamp_firstPacket.microseconds()),
  413. getFormattedTimestamp(timestamp_lastPacket.seconds(), timestamp_lastPacket.microseconds()),
  414. avgPacketRate, avgPacketSize, avgPacketsSentPerHost, avgBandwidthInKBits,
  415. avgBandwidthOutInKBits);
  416. db.writeStatisticsIP(ip_statistics);
  417. db.writeStatisticsTTL(ttl_distribution);
  418. db.writeStatisticsIpMac(ip_mac_mapping);
  419. db.writeStatisticsMss(ip_sumMss);
  420. db.writeStatisticsPorts(ip_ports);
  421. db.writeStatisticsProtocols(protocol_distribution);
  422. // Aidmar
  423. db.writeStatisticsMss_dist(mss_distribution);
  424. db.writeStatisticsWin(win_distribution);
  425. db.writeStatisticsFlow(flow_statistics);
  426. }
  427. /**
  428. * Returns the average packet size.
  429. * @return a float indicating the average packet size in kbytes.
  430. */
  431. float statistics::getAvgPacketSize() const {
  432. // AvgPktSize = (Sum of all packet sizes / #Packets)
  433. return (sumPacketSize / packetCount) / 1024;
  434. }
  435. /**
  436. * Adds the size of a packet (to be used to calculate the avg. packet size).
  437. * @param packetSize The size of the current packet in bytes.
  438. */
  439. void statistics::addPacketSize(uint32_t packetSize) {
  440. sumPacketSize += ((float) packetSize);
  441. }