statistics.h 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731
  1. /*
  2. * Class providing containers and access methods for statistical data collection.
  3. */
  4. #ifndef CPP_PCAPREADER_STATISTICS_H
  5. #define CPP_PCAPREADER_STATISTICS_H
  6. #include <vector>
  7. #include <unordered_map>
  8. #include <unordered_set>
  9. #include <list>
  10. #include <tuple>
  11. #include <tins/timestamp.h>
  12. #include <tins/ip_address.h>
  13. #include "utilities.h"
  14. using namespace Tins;
  15. #define COMM_INTERVAL_THRESHOLD 10e6 // in microseconds; i.e. here 10s
  16. /*
  17. * Definition of structs used in unordered_map fields
  18. */
  19. /*
  20. * Struct used as data structure for method get_stats_for_ip, represents:
  21. * - Incoming bandwidth in KBits
  22. * - Outgoing bandwidth in KBits
  23. * - Number of incoming packets per second
  24. * - Number of outgoing packets per second
  25. * - Average size of sent packets in kbytes
  26. * - Average size of received packets in kybtes
  27. * - Average value of TCP option Maximum Segment Size (MSS)
  28. */
  29. struct ip_stats {
  30. float bandwidthKBitsIn;
  31. float bandwidthKBitsOut;
  32. float packetPerSecondIn;
  33. float packetPerSecondOut;
  34. float AvgPacketSizeSent;
  35. float AvgPacketSizeRecv;
  36. };
  37. /*
  38. * Struct used to represent a conversation by:
  39. * - IP address A
  40. * - Port A
  41. * - IP address B
  42. * - Port B
  43. */
  44. struct conv{
  45. std::string ipAddressA;
  46. int portA;
  47. std::string ipAddressB;
  48. int portB;
  49. bool operator==(const conv &other) const {
  50. return ipAddressA == other.ipAddressA
  51. && portA == other.portA
  52. &&ipAddressB == other.ipAddressB
  53. && portB == other.portB;
  54. }
  55. };
  56. /*
  57. * Struct used to represent a conversation by:
  58. * - IP address A
  59. * - Port A
  60. * - IP address B
  61. * - Port B
  62. * - Protocol
  63. */
  64. struct convWithProt{
  65. std::string ipAddressA;
  66. int portA;
  67. std::string ipAddressB;
  68. int portB;
  69. std::string protocol;
  70. bool operator==(const convWithProt &other) const {
  71. return ipAddressA == other.ipAddressA
  72. && portA == other.portA
  73. &&ipAddressB == other.ipAddressB
  74. && portB == other.portB
  75. && protocol == other.protocol;
  76. }
  77. };
  78. /*
  79. * Struct used to represent:
  80. * - IP address (IPv4 or IPv6)
  81. * - MSS value
  82. */
  83. struct ipAddress_mss {
  84. std::string ipAddress;
  85. int mssValue;
  86. bool operator==(const ipAddress_mss &other) const {
  87. return ipAddress == other.ipAddress
  88. && mssValue == other.mssValue;
  89. }
  90. };
  91. /*
  92. * Struct used to represent:
  93. * - IP address (IPv4 or IPv6)
  94. * - ToS value
  95. */
  96. struct ipAddress_tos {
  97. std::string ipAddress;
  98. int tosValue;
  99. bool operator==(const ipAddress_tos &other) const {
  100. return ipAddress == other.ipAddress
  101. && tosValue == other.tosValue;
  102. }
  103. };
  104. /*
  105. * Struct used to represent:
  106. * - IP address (IPv4 or IPv6)
  107. * - Window size
  108. */
  109. struct ipAddress_win {
  110. std::string ipAddress;
  111. int winSize;
  112. bool operator==(const ipAddress_win &other) const {
  113. return ipAddress == other.ipAddress
  114. && winSize == other.winSize;
  115. }
  116. };
  117. /*
  118. * Struct used to represent:
  119. * - IP address (IPv4 or IPv6)
  120. * - TTL value
  121. */
  122. struct ipAddress_ttl {
  123. std::string ipAddress;
  124. int ttlValue;
  125. bool operator==(const ipAddress_ttl &other) const {
  126. return ipAddress == other.ipAddress
  127. && ttlValue == other.ttlValue;
  128. }
  129. };
  130. /*
  131. * Struct used to represent:
  132. * - IP address (IPv4 or IPv6)
  133. * - Protocol (e.g. TCP, UDP, IPv4, IPv6)
  134. */
  135. struct ipAddress_protocol {
  136. std::string ipAddress;
  137. std::string protocol;
  138. bool operator==(const ipAddress_protocol &other) const {
  139. return ipAddress == other.ipAddress
  140. && protocol == other.protocol;
  141. }
  142. };
  143. /*
  144. * Struct used to represent:
  145. * - Number of received packets
  146. * - Number of sent packets
  147. * - Data received in kbytes
  148. * - Data sent in kbytes
  149. */
  150. struct entry_ipStat {
  151. long pkts_received;
  152. long pkts_sent;
  153. float kbytes_received;
  154. float kbytes_sent;
  155. std::string ip_class;
  156. int in_degree;
  157. int out_degree;
  158. int overall_degree;
  159. // Collects statstics over time interval
  160. std::vector<float> interval_pkt_rate;
  161. float max_interval_pkt_rate;
  162. float min_interval_pkt_rate;
  163. std::vector<std::chrono::microseconds> pkts_sent_timestamp;
  164. std::vector<std::chrono::microseconds> pkts_received_timestamp;
  165. bool operator==(const entry_ipStat &other) const {
  166. return pkts_received == other.pkts_received
  167. && pkts_sent == other.pkts_sent
  168. && kbytes_sent == other.kbytes_sent
  169. && kbytes_received == other.kbytes_received
  170. && interval_pkt_rate == other.interval_pkt_rate
  171. && max_interval_pkt_rate == other.max_interval_pkt_rate
  172. && min_interval_pkt_rate == other.min_interval_pkt_rate
  173. && ip_class == other.ip_class
  174. && pkts_sent_timestamp == other.pkts_sent_timestamp
  175. && pkts_received_timestamp == other.pkts_received_timestamp;
  176. }
  177. };
  178. /*
  179. * Struct used to represent:
  180. * - Number of transmitted packets
  181. * - Number of transmitted bytes
  182. */
  183. struct entry_portStat {
  184. int count;
  185. float byteCount;
  186. };
  187. /*
  188. * Struct used to represent:
  189. * - Number of times the protocol is seen
  190. * - Amount of bytes transmitted with this protocol
  191. */
  192. struct entry_protocolStat {
  193. int count;
  194. float byteCount;
  195. };
  196. /*
  197. * Struct used to represent interval statistics:
  198. * - # packets
  199. * - # bytes
  200. * - IP source entropy
  201. * - IP destination entropy
  202. * - IP source cumulative entropy
  203. * - IP destination cumulative entropy
  204. * - # packets that have payload
  205. * - # incorrect TCP checksum
  206. * - # correct TCP checksum
  207. * - # novel IPs
  208. * - # novel TTL
  209. * - # novel Window Size
  210. * - # novel ToS
  211. * - # novel MSS
  212. */
  213. struct entry_intervalStat {
  214. std::string start;
  215. std::string end;
  216. int pkts_count;
  217. float pkt_rate;
  218. float kbytes;
  219. float kbyte_rate;
  220. float ip_src_entropy;
  221. float ip_dst_entropy;
  222. float ip_src_cum_entropy;
  223. float ip_dst_cum_entropy;
  224. int payload_count;
  225. int incorrect_tcp_checksum_count;
  226. int correct_tcp_checksum_count;
  227. int novel_ip_count;
  228. int novel_ttl_count;
  229. int novel_win_size_count;
  230. int novel_tos_count;
  231. int novel_mss_count;
  232. int novel_port_count;
  233. bool operator==(const entry_intervalStat &other) const {
  234. return start == other.start
  235. && end == other.end
  236. && pkts_count == other.pkts_count
  237. && pkt_rate == other.pkt_rate
  238. && kbytes == other.kbytes
  239. && kbyte_rate == other.kbyte_rate
  240. && ip_src_entropy == other.ip_src_entropy
  241. && ip_dst_entropy == other.ip_dst_entropy
  242. && ip_src_cum_entropy == other.ip_src_cum_entropy
  243. && ip_dst_cum_entropy == other.ip_dst_cum_entropy
  244. && payload_count == other.payload_count
  245. && incorrect_tcp_checksum_count == other.incorrect_tcp_checksum_count
  246. && novel_ip_count == other.novel_ip_count
  247. && novel_ttl_count == other.novel_ttl_count
  248. && novel_win_size_count == other.novel_win_size_count
  249. && novel_tos_count == other.novel_tos_count
  250. && novel_mss_count == other.novel_mss_count
  251. && novel_port_count == other.novel_port_count;
  252. }
  253. };
  254. /*
  255. * Struct used to represent converstaion statistics:
  256. * - # packets
  257. * - Average packet rate
  258. * - Timestamps of packets
  259. * - Inter-arrival time
  260. * - Average inter-arrival time
  261. */
  262. struct entry_convStat {
  263. long pkts_count;
  264. float avg_pkt_rate;
  265. std::vector<std::chrono::microseconds> pkts_timestamp;
  266. std::vector<std::chrono::microseconds> interarrival_time;
  267. std::chrono::microseconds avg_interarrival_time;
  268. bool operator==(const entry_convStat &other) const {
  269. return pkts_count == other.pkts_count
  270. && avg_pkt_rate == avg_pkt_rate
  271. && pkts_timestamp == other.pkts_timestamp
  272. && interarrival_time == other.interarrival_time
  273. && avg_interarrival_time == other.avg_interarrival_time;
  274. }
  275. };
  276. /*
  277. * Struct used to represent:
  278. * - IP address (IPv4 or IPv6)
  279. - Traffic direction (out: outgoing connection, in: incoming connection)
  280. * - Port number
  281. */
  282. struct ipAddress_inOut_port {
  283. std::string ipAddress;
  284. std::string trafficDirection;
  285. int portNumber;
  286. std::string protocol;
  287. bool operator==(const ipAddress_inOut_port &other) const {
  288. return ipAddress == other.ipAddress
  289. && trafficDirection == other.trafficDirection
  290. && portNumber == other.portNumber
  291. && protocol == other.protocol;
  292. }
  293. };
  294. /*
  295. * Struct used to represent a communication interval (for two hosts):
  296. * - Timestamp of the first packet in the interval
  297. * - Timestamp of the last packet in the interval
  298. * - The count of packets within the interval
  299. */
  300. struct commInterval{
  301. std::chrono::microseconds start;
  302. std::chrono::microseconds end;
  303. long pkts_count;
  304. bool operator==(const commInterval &other) const {
  305. return start == other.start
  306. && end == other.end
  307. && pkts_count == other.pkts_count;
  308. }
  309. };
  310. /*
  311. * Struct used to represent converstaion statistics:
  312. * - commnication intervals
  313. * - # packets
  314. * - Average packet rate
  315. * - average # packets per communication interval
  316. * - Average time between intervals
  317. * - Average duration of a communication interval
  318. * - Overall communication duration
  319. * - Timestamps of packets
  320. * - Inter-arrival time
  321. * - Average inter-arrival time
  322. */
  323. struct entry_convStatExt {
  324. std::vector<commInterval> comm_intervals;
  325. long pkts_count;
  326. float avg_pkt_rate;
  327. double avg_int_pkts_count;
  328. double avg_time_between_ints;
  329. double avg_interval_time;
  330. double total_comm_duration;
  331. std::chrono::duration<int, std::micro> timeInterval;
  332. std::vector<std::chrono::microseconds> pkts_timestamp;
  333. std::vector<std::chrono::microseconds> interarrival_time;
  334. std::chrono::microseconds avg_interarrival_time;
  335. bool operator==(const entry_convStatExt &other) const {
  336. return comm_intervals == other.comm_intervals
  337. && pkts_count == other.pkts_count
  338. && avg_pkt_rate == avg_pkt_rate
  339. && avg_int_pkts_count == other.avg_int_pkts_count
  340. && avg_time_between_ints == other.avg_time_between_ints
  341. && avg_interval_time == other.avg_interval_time
  342. && total_comm_duration == other.total_comm_duration
  343. && pkts_timestamp == other.pkts_timestamp
  344. && interarrival_time == other.interarrival_time
  345. && avg_interarrival_time == other.avg_interarrival_time;
  346. }
  347. };
  348. /*
  349. * Struct used to represent:
  350. * - Source MAC address
  351. * - Destination MAC address
  352. * - Payload type number
  353. */
  354. struct unrecognized_PDU {
  355. std::string srcMacAddress;
  356. std::string dstMacAddress;
  357. uint32_t typeNumber;
  358. bool operator==(const unrecognized_PDU &other) const {
  359. return srcMacAddress == other.srcMacAddress
  360. && dstMacAddress == other.dstMacAddress
  361. && typeNumber == other.typeNumber;
  362. }
  363. };
  364. /*
  365. * Struct used to represent:
  366. * - Number of occurrences
  367. * - Formatted timestamp of last occurrence
  368. */
  369. struct unrecognized_PDU_stat {
  370. int count;
  371. std::string timestamp_last_occurrence;
  372. };
  373. /*
  374. * Definition of hash functions for structs used as key in unordered_map
  375. */
  376. namespace std {
  377. template<>
  378. struct hash<ipAddress_ttl> {
  379. std::size_t operator()(const ipAddress_ttl &k) const {
  380. using std::size_t;
  381. using std::hash;
  382. using std::string;
  383. return ((hash<string>()(k.ipAddress)
  384. ^ (hash<int>()(k.ttlValue) << 1)) >> 1);
  385. }
  386. };
  387. template<>
  388. struct hash<ipAddress_mss> {
  389. std::size_t operator()(const ipAddress_mss &k) const {
  390. using std::size_t;
  391. using std::hash;
  392. using std::string;
  393. return ((hash<string>()(k.ipAddress)
  394. ^ (hash<int>()(k.mssValue) << 1)) >> 1);
  395. }
  396. };
  397. template<>
  398. struct hash<ipAddress_tos> {
  399. std::size_t operator()(const ipAddress_tos &k) const {
  400. using std::size_t;
  401. using std::hash;
  402. using std::string;
  403. return ((hash<string>()(k.ipAddress)
  404. ^ (hash<int>()(k.tosValue) << 1)) >> 1);
  405. }
  406. };
  407. template<>
  408. struct hash<ipAddress_win> {
  409. std::size_t operator()(const ipAddress_win &k) const {
  410. using std::size_t;
  411. using std::hash;
  412. using std::string;
  413. return ((hash<string>()(k.ipAddress)
  414. ^ (hash<int>()(k.winSize) << 1)) >> 1);
  415. }
  416. };
  417. template<>
  418. struct hash<conv> {
  419. std::size_t operator()(const conv &k) const {
  420. using std::size_t;
  421. using std::hash;
  422. using std::string;
  423. return ((hash<string>()(k.ipAddressA)
  424. ^ (hash<int>()(k.portA) << 1)) >> 1)
  425. ^ ((hash<string>()(k.ipAddressB)
  426. ^ (hash<int>()(k.portB) << 1)) >> 1);
  427. }
  428. };
  429. template<>
  430. struct hash<convWithProt> {
  431. std::size_t operator()(const convWithProt &c) const {
  432. using std::size_t;
  433. using std::hash;
  434. using std::string;
  435. return ((hash<string>()(c.ipAddressA)
  436. ^ (hash<int>()(c.portA) << 1)) >> 1)
  437. ^ ((hash<string>()(c.ipAddressB)
  438. ^ (hash<int>()(c.portB) << 1)) >> 1)
  439. ^ (hash<string>()(c.protocol));
  440. }
  441. };
  442. template<>
  443. struct hash<ipAddress_protocol> {
  444. std::size_t operator()(const ipAddress_protocol &k) const {
  445. using std::size_t;
  446. using std::hash;
  447. using std::string;
  448. return ((hash<string>()(k.ipAddress)
  449. ^ (hash<string>()(k.protocol) << 1)) >> 1);
  450. }
  451. };
  452. template<>
  453. struct hash<ipAddress_inOut_port> {
  454. std::size_t operator()(const ipAddress_inOut_port &k) const {
  455. using std::size_t;
  456. using std::hash;
  457. using std::string;
  458. return ((hash<string>()(k.ipAddress)
  459. ^ (hash<string>()(k.trafficDirection) << 1)) >> 1)
  460. ^ (hash<int>()(k.portNumber) << 1);
  461. }
  462. };
  463. template<>
  464. struct hash<unrecognized_PDU> {
  465. std::size_t operator()(const unrecognized_PDU &k) const {
  466. using std::size_t;
  467. using std::hash;
  468. using std::string;
  469. return ((hash<string>()(k.srcMacAddress)
  470. ^ (hash<string>()(k.dstMacAddress) << 1)) >> 1)
  471. ^ (hash<uint32_t>()(k.typeNumber) << 1);
  472. }
  473. };
  474. }
  475. class statistics {
  476. public:
  477. /*
  478. * Constructor
  479. */
  480. statistics(std::string resourcePath);
  481. /*
  482. * Methods
  483. */
  484. std::string getFormattedTimestamp(time_t seconds, suseconds_t microseconds) const;
  485. /*
  486. * Access methods for containers
  487. */
  488. void incrementPacketCount();
  489. void calculateIPIntervalPacketRate(std::chrono::duration<int, std::micro> interval, std::chrono::microseconds intervalStartTimestamp);
  490. void incrementMSScount(const std::string &ipAddress, int mssValue);
  491. void incrementWinCount(const std::string &ipAddress, int winSize);
  492. void addConvStat(const std::string &ipAddressSender,int sport, const std::string &ipAddressReceiver,int dport, std::chrono::microseconds timestamp);
  493. void addConvStatExt(const std::string &ipAddressSender,int sport, const std::string &ipAddressReceiver,int dport, const std::string &protocol, std::chrono::microseconds timestamp);
  494. void createCommIntervalStats();
  495. std::vector<float> calculateIPsCumEntropy();
  496. std::vector<float> calculateLastIntervalIPsEntropy(std::chrono::microseconds intervalStartTimestamp);
  497. void addIntervalStat(std::chrono::duration<int, std::micro> interval, std::chrono::microseconds intervalStartTimestamp, std::chrono::microseconds lastPktTimestamp);
  498. void checkPayload(const PDU *pdu_l4);
  499. void checkTCPChecksum(const std::string &ipAddressSender, const std::string &ipAddressReceiver, TCP tcpPkt);
  500. void checkToS(uint8_t ToS);
  501. void incrementToScount(const std::string &ipAddress, int tosValue);
  502. void incrementTTLcount(const std::string &ipAddress, int ttlValue);
  503. void incrementProtocolCount(const std::string &ipAddress, const std::string &protocol);
  504. void increaseProtocolByteCount(const std::string &ipAddress, const std::string &protocol, long bytesSent);
  505. void incrementUnrecognizedPDUCount(const std::string &srcMac, const std::string &dstMac, uint32_t typeNumber,
  506. const std::string &timestamp);
  507. void incrementPortCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
  508. int incomingPort, const std::string &protocol);
  509. void increasePortByteCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
  510. int incomingPort, long bytesSent, const std::string &protocol);
  511. int getProtocolCount(const std::string &ipAddress, const std::string &protocol);
  512. float getProtocolByteCount(const std::string &ipAddress, const std::string &protocol);
  513. void setTimestampFirstPacket(Tins::Timestamp ts);
  514. void setTimestampLastPacket(Tins::Timestamp ts);
  515. Tins::Timestamp getTimestampFirstPacket();
  516. Tins::Timestamp getTimestampLastPacket();
  517. void assignMacAddress(const std::string &ipAddress, const std::string &macAddress);
  518. void addIpStat_packetSent(const std::string &ipAddressSender, const std::string &ipAddressReceiver, long bytesSent, std::chrono::microseconds timestamp);
  519. int getPacketCount();
  520. int getSumPacketSize();
  521. void addMSS(const std::string &ipAddress, int MSSvalue);
  522. void writeToDatabase(std::string database_path, std::vector<std::chrono::duration<int, std::micro>> timeInterval, bool del);
  523. void writeIntervalsToDatabase(std::string database_path, std::vector<std::chrono::duration<int, std::micro>> timeIntervals, bool del);
  524. void addPacketSize(uint32_t packetSize);
  525. std::string getCaptureDurationTimestamp() const;
  526. float getCaptureDurationSeconds() const;
  527. float getAvgPacketSize() const;
  528. void printStats(const std::string &ipAddress);
  529. bool getDoExtraTests();
  530. void setDoExtraTests(bool var);
  531. int getDefaultInterval();
  532. void setDefaultInterval(int interval);
  533. /*
  534. * IP Address-specific statistics
  535. */
  536. ip_stats getStatsForIP(const std::string &ipAddress);
  537. private:
  538. /*
  539. * Data fields
  540. */
  541. Tins::Timestamp timestamp_firstPacket;
  542. Tins::Timestamp timestamp_lastPacket;
  543. float sumPacketSize = 0;
  544. int packetCount = 0;
  545. std::string resourcePath;
  546. /* Extra tests includes:
  547. * - calculate IPs entropies for intervals
  548. * - calculate IPs cumulative entropies interval-wise
  549. * - check payload availability
  550. * - chech TCP checksum correctness
  551. */
  552. bool doExtraTests = false;
  553. int payloadCount = 0;
  554. int incorrectTCPChecksumCount = 0;
  555. int correctTCPChecksumCount = 0;
  556. // Variables that are used for interval-wise statistics
  557. int intervalPayloadCount = 0;
  558. int intervalIncorrectTCPChecksumCount = 0;
  559. int intervalCorrectTCPChecksumCount = 0;
  560. int intervalCumPktCount = 0;
  561. float intervalCumSumPktSize = 0;
  562. int intervalCumNovelIPCount = 0;
  563. int intervalCumNovelTTLCount = 0;
  564. int intervalCumNovelWinSizeCount = 0;
  565. int intervalCumNovelToSCount = 0;
  566. int intervalCumNovelMSSCount = 0;
  567. int intervalCumNovelPortCount = 0;
  568. int default_interval = 0;
  569. /*
  570. * Data containers
  571. */
  572. // {IP Address, TTL value, count}
  573. std::unordered_map<ipAddress_ttl, int> ttl_distribution;
  574. // {IP Address, MSS value, count}
  575. std::unordered_map<ipAddress_mss, int> mss_distribution;
  576. // {IP Address, Win size, count}
  577. std::unordered_map<ipAddress_win, int> win_distribution;
  578. // {IP Address, ToS value, count}
  579. std::unordered_map<ipAddress_tos, int> tos_distribution;
  580. // {IP Address A, Port A, IP Address B, Port B, #packets, packets timestamps, inter-arrival times,
  581. // average of inter-arrival times}
  582. std::unordered_map<conv, entry_convStat> conv_statistics;
  583. // {IP Address A, Port A, IP Address B, Port B, comm_intervals, #packets, avg. pkt rate, avg. #packets per interval,
  584. // avg. time between intervals, avg. interval time, duration, packets timestamps, inter-arrivtal times, average of inter-arrival times}
  585. // Also stores conversation with only one exchanged message. In this case avgPktRate, minDelay, maxDelay and avgDelay are -1
  586. std::unordered_map<convWithProt, entry_convStatExt> conv_statistics_extended;
  587. // {Last timestamp in the interval, #packets, #bytes, source IP entropy, destination IP entropy,
  588. // source IP cumulative entropy, destination IP cumulative entropy, #payload, #incorrect TCP checksum,
  589. // #correct TCP checksum, #novel IP, #novel TTL, #novel Window Size, #novel ToS,#novel MSS}
  590. std::unordered_map<std::string, entry_intervalStat> interval_statistics;
  591. // {TTL value, count}
  592. std::unordered_map<int, int> ttl_values;
  593. // {Win size, count}
  594. std::unordered_map<int, int> win_values;
  595. // {ToS, count}
  596. std::unordered_map<int, int> tos_values;
  597. // {MSS, count}
  598. std::unordered_map<int, int> mss_values;
  599. // {Port, count}
  600. std::unordered_map<int, int> port_values;
  601. //{IP Address, contacted IP Addresses}
  602. std::unordered_map<std::string, std::unordered_set<std::string>> contacted_ips;
  603. // {IP Address, Protocol, #count, #Data transmitted in bytes}
  604. std::unordered_map<ipAddress_protocol, entry_protocolStat> protocol_distribution;
  605. // {IP Address, #received packets, #sent packets, Data received in kbytes, Data sent in kbytes}
  606. std::unordered_map<std::string, entry_ipStat> ip_statistics;
  607. // {IP Address, in_out, Port Number, #count, #Data transmitted in bytes}
  608. std::unordered_map<ipAddress_inOut_port, entry_portStat> ip_ports;
  609. // {IP Address, MAC Address}
  610. std::unordered_map<std::string, std::string> ip_mac_mapping;
  611. // {Source MAC, Destination MAC, typeNumber, #count, #timestamp of last occurrence}
  612. std::unordered_map<unrecognized_PDU, unrecognized_PDU_stat> unrecognized_PDUs;
  613. };
  614. #endif //CPP_PCAPREADER_STATISTICS_H