statistics.h 23 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753
  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. std::vector<double> ip_entropies;
  221. std::vector<double> ip_cum_entropies;
  222. std::vector<double> ttl_entropies;
  223. std::vector<double> win_size_entropies;
  224. std::vector<double> tos_entropies;
  225. std::vector<double> mss_entropies;
  226. std::vector<double> port_entropies;
  227. int payload_count;
  228. int incorrect_tcp_checksum_count;
  229. int correct_tcp_checksum_count;
  230. size_t novel_ip_src_count;
  231. size_t novel_ip_dst_count;
  232. int novel_ttl_count;
  233. int novel_win_size_count;
  234. int novel_tos_count;
  235. int novel_mss_count;
  236. int novel_port_count;
  237. // FIXME: add new attributes to operator==
  238. bool operator==(const entry_intervalStat &other) const {
  239. return start == other.start
  240. && end == other.end
  241. && pkts_count == other.pkts_count
  242. && pkt_rate == other.pkt_rate
  243. && kbytes == other.kbytes
  244. && kbyte_rate == other.kbyte_rate
  245. && ip_entropies == other.ip_entropies
  246. && ip_cum_entropies == other.ip_cum_entropies
  247. && payload_count == other.payload_count
  248. && incorrect_tcp_checksum_count == other.incorrect_tcp_checksum_count
  249. && correct_tcp_checksum_count == other.correct_tcp_checksum_count
  250. && novel_ip_src_count == other.novel_ip_src_count
  251. && novel_ip_dst_count == other.novel_ip_dst_count
  252. && novel_ttl_count == other.novel_ttl_count
  253. && novel_win_size_count == other.novel_win_size_count
  254. && novel_tos_count == other.novel_tos_count
  255. && novel_mss_count == other.novel_mss_count
  256. && novel_port_count == other.novel_port_count
  257. && ttl_entropies == other.ttl_entropies
  258. && win_size_entropies == other.win_size_entropies
  259. && tos_entropies == other.tos_entropies
  260. && mss_entropies == other.mss_entropies
  261. && port_entropies == other.port_entropies;
  262. }
  263. };
  264. /*
  265. * Struct used to represent converstaion statistics:
  266. * - # packets
  267. * - Average packet rate
  268. * - Timestamps of packets
  269. * - Inter-arrival time
  270. * - Average inter-arrival time
  271. */
  272. struct entry_convStat {
  273. long pkts_count;
  274. float avg_pkt_rate;
  275. std::vector<std::chrono::microseconds> pkts_timestamp;
  276. std::vector<std::chrono::microseconds> interarrival_time;
  277. std::chrono::microseconds avg_interarrival_time;
  278. std::vector<small_uint<12>> tcp_types;
  279. bool operator==(const entry_convStat &other) const {
  280. return pkts_count == other.pkts_count
  281. && avg_pkt_rate == avg_pkt_rate
  282. && pkts_timestamp == other.pkts_timestamp
  283. && interarrival_time == other.interarrival_time
  284. && avg_interarrival_time == other.avg_interarrival_time
  285. && tcp_types == other.tcp_types;
  286. }
  287. };
  288. /*
  289. * Struct used to represent:
  290. * - IP address (IPv4 or IPv6)
  291. - Traffic direction (out: outgoing connection, in: incoming connection)
  292. * - Port number
  293. */
  294. struct ipAddress_inOut_port {
  295. std::string ipAddress;
  296. std::string trafficDirection;
  297. int portNumber;
  298. std::string protocol;
  299. bool operator==(const ipAddress_inOut_port &other) const {
  300. return ipAddress == other.ipAddress
  301. && trafficDirection == other.trafficDirection
  302. && portNumber == other.portNumber
  303. && protocol == other.protocol;
  304. }
  305. };
  306. /*
  307. * Struct used to represent a communication interval (for two hosts):
  308. * - Timestamp of the first packet in the interval
  309. * - Timestamp of the last packet in the interval
  310. * - The count of packets within the interval
  311. */
  312. struct commInterval{
  313. std::chrono::microseconds start;
  314. std::chrono::microseconds end;
  315. long pkts_count;
  316. bool operator==(const commInterval &other) const {
  317. return start == other.start
  318. && end == other.end
  319. && pkts_count == other.pkts_count;
  320. }
  321. };
  322. /*
  323. * Struct used to represent converstaion statistics:
  324. * - commnication intervals
  325. * - # packets
  326. * - Average packet rate
  327. * - average # packets per communication interval
  328. * - Average time between intervals
  329. * - Average duration of a communication interval
  330. * - Overall communication duration
  331. * - Timestamps of packets
  332. * - Inter-arrival time
  333. * - Average inter-arrival time
  334. */
  335. struct entry_convStatExt {
  336. std::vector<commInterval> comm_intervals;
  337. long pkts_count;
  338. float avg_pkt_rate;
  339. double avg_int_pkts_count;
  340. double avg_time_between_ints;
  341. double avg_interval_time;
  342. double total_comm_duration;
  343. std::chrono::duration<int, std::micro> timeInterval;
  344. std::vector<std::chrono::microseconds> pkts_timestamp;
  345. std::vector<std::chrono::microseconds> interarrival_time;
  346. std::chrono::microseconds avg_interarrival_time;
  347. bool operator==(const entry_convStatExt &other) const {
  348. return comm_intervals == other.comm_intervals
  349. && pkts_count == other.pkts_count
  350. && avg_pkt_rate == avg_pkt_rate
  351. && avg_int_pkts_count == other.avg_int_pkts_count
  352. && avg_time_between_ints == other.avg_time_between_ints
  353. && avg_interval_time == other.avg_interval_time
  354. && total_comm_duration == other.total_comm_duration
  355. && pkts_timestamp == other.pkts_timestamp
  356. && interarrival_time == other.interarrival_time
  357. && avg_interarrival_time == other.avg_interarrival_time;
  358. }
  359. };
  360. /*
  361. * Struct used to represent:
  362. * - Source MAC address
  363. * - Destination MAC address
  364. * - Payload type number
  365. */
  366. struct unrecognized_PDU {
  367. std::string srcMacAddress;
  368. std::string dstMacAddress;
  369. uint32_t typeNumber;
  370. bool operator==(const unrecognized_PDU &other) const {
  371. return srcMacAddress == other.srcMacAddress
  372. && dstMacAddress == other.dstMacAddress
  373. && typeNumber == other.typeNumber;
  374. }
  375. };
  376. /*
  377. * Struct used to represent:
  378. * - Number of occurrences
  379. * - Formatted timestamp of last occurrence
  380. */
  381. struct unrecognized_PDU_stat {
  382. int count;
  383. std::string timestamp_last_occurrence;
  384. };
  385. /*
  386. * Definition of hash functions for structs used as key in unordered_map
  387. */
  388. namespace std {
  389. template<>
  390. struct hash<ipAddress_ttl> {
  391. std::size_t operator()(const ipAddress_ttl &k) const {
  392. using std::size_t;
  393. using std::hash;
  394. using std::string;
  395. return ((hash<string>()(k.ipAddress)
  396. ^ (hash<int>()(k.ttlValue) << 1)) >> 1);
  397. }
  398. };
  399. template<>
  400. struct hash<ipAddress_mss> {
  401. std::size_t operator()(const ipAddress_mss &k) const {
  402. using std::size_t;
  403. using std::hash;
  404. using std::string;
  405. return ((hash<string>()(k.ipAddress)
  406. ^ (hash<int>()(k.mssValue) << 1)) >> 1);
  407. }
  408. };
  409. template<>
  410. struct hash<ipAddress_tos> {
  411. std::size_t operator()(const ipAddress_tos &k) const {
  412. using std::size_t;
  413. using std::hash;
  414. using std::string;
  415. return ((hash<string>()(k.ipAddress)
  416. ^ (hash<int>()(k.tosValue) << 1)) >> 1);
  417. }
  418. };
  419. template<>
  420. struct hash<ipAddress_win> {
  421. std::size_t operator()(const ipAddress_win &k) const {
  422. using std::size_t;
  423. using std::hash;
  424. using std::string;
  425. return ((hash<string>()(k.ipAddress)
  426. ^ (hash<int>()(k.winSize) << 1)) >> 1);
  427. }
  428. };
  429. template<>
  430. struct hash<conv> {
  431. std::size_t operator()(const conv &k) const {
  432. using std::size_t;
  433. using std::hash;
  434. using std::string;
  435. return ((hash<string>()(k.ipAddressA)
  436. ^ (hash<int>()(k.portA) << 1)) >> 1)
  437. ^ ((hash<string>()(k.ipAddressB)
  438. ^ (hash<int>()(k.portB) << 1)) >> 1);
  439. }
  440. };
  441. template<>
  442. struct hash<convWithProt> {
  443. std::size_t operator()(const convWithProt &c) const {
  444. using std::size_t;
  445. using std::hash;
  446. using std::string;
  447. return ((hash<string>()(c.ipAddressA)
  448. ^ (hash<int>()(c.portA) << 1)) >> 1)
  449. ^ ((hash<string>()(c.ipAddressB)
  450. ^ (hash<int>()(c.portB) << 1)) >> 1)
  451. ^ (hash<string>()(c.protocol));
  452. }
  453. };
  454. template<>
  455. struct hash<ipAddress_protocol> {
  456. std::size_t operator()(const ipAddress_protocol &k) const {
  457. using std::size_t;
  458. using std::hash;
  459. using std::string;
  460. return ((hash<string>()(k.ipAddress)
  461. ^ (hash<string>()(k.protocol) << 1)) >> 1);
  462. }
  463. };
  464. template<>
  465. struct hash<ipAddress_inOut_port> {
  466. std::size_t operator()(const ipAddress_inOut_port &k) const {
  467. using std::size_t;
  468. using std::hash;
  469. using std::string;
  470. return ((hash<string>()(k.ipAddress)
  471. ^ (hash<string>()(k.trafficDirection) << 1)) >> 1)
  472. ^ (hash<int>()(k.portNumber) << 1);
  473. }
  474. };
  475. template<>
  476. struct hash<unrecognized_PDU> {
  477. std::size_t operator()(const unrecognized_PDU &k) const {
  478. using std::size_t;
  479. using std::hash;
  480. using std::string;
  481. return ((hash<string>()(k.srcMacAddress)
  482. ^ (hash<string>()(k.dstMacAddress) << 1)) >> 1)
  483. ^ (hash<uint32_t>()(k.typeNumber) << 1);
  484. }
  485. };
  486. }
  487. class statistics {
  488. public:
  489. /*
  490. * Constructor
  491. */
  492. statistics(std::string resourcePath);
  493. /*
  494. * Methods
  495. */
  496. std::string getFormattedTimestamp(time_t seconds, suseconds_t microseconds) const;
  497. /*
  498. * Access methods for containers
  499. */
  500. void incrementPacketCount();
  501. void calculateIPIntervalPacketRate(std::chrono::duration<int, std::micro> interval, std::chrono::microseconds intervalStartTimestamp);
  502. void incrementMSScount(const std::string &ipAddress, int mssValue);
  503. void incrementWinCount(const std::string &ipAddress, int winSize);
  504. void addConvStat(const std::string &ipAddressSender,int sport, const std::string &ipAddressReceiver,int dport, std::chrono::microseconds timestamp, small_uint<12> flags);
  505. void addConvStatExt(const std::string &ipAddressSender,int sport, const std::string &ipAddressReceiver,int dport, const std::string &protocol, std::chrono::microseconds timestamp);
  506. void createCommIntervalStats();
  507. std::vector<double> calculateIPsCumEntropy();
  508. std::vector<double> calculateLastIntervalIPsEntropy(std::chrono::microseconds intervalStartTimestamp);
  509. std::vector<double> calculateEntropies(std::unordered_map<int, int> &map, std::unordered_map<int, int> &old);
  510. void addIntervalStat(std::chrono::duration<int, std::micro> interval, std::chrono::microseconds intervalStartTimestamp, std::chrono::microseconds lastPktTimestamp);
  511. void checkPayload(const PDU *pdu_l4);
  512. void checkTCPChecksum(const std::string &ipAddressSender, const std::string &ipAddressReceiver, TCP tcpPkt);
  513. void checkToS(uint8_t ToS);
  514. void incrementToScount(const std::string &ipAddress, int tosValue);
  515. void incrementTTLcount(const std::string &ipAddress, int ttlValue);
  516. void incrementProtocolCount(const std::string &ipAddress, const std::string &protocol);
  517. void increaseProtocolByteCount(const std::string &ipAddress, const std::string &protocol, long bytesSent);
  518. void incrementUnrecognizedPDUCount(const std::string &srcMac, const std::string &dstMac, uint32_t typeNumber,
  519. const std::string &timestamp);
  520. void incrementPortCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
  521. int incomingPort, const std::string &protocol);
  522. void increasePortByteCount(const std::string &ipAddressSender, int outgoingPort, const std::string &ipAddressReceiver,
  523. int incomingPort, long bytesSent, const std::string &protocol);
  524. int getProtocolCount(const std::string &ipAddress, const std::string &protocol);
  525. float getProtocolByteCount(const std::string &ipAddress, const std::string &protocol);
  526. void setTimestampFirstPacket(Tins::Timestamp ts);
  527. void setTimestampLastPacket(Tins::Timestamp ts);
  528. Tins::Timestamp getTimestampFirstPacket();
  529. Tins::Timestamp getTimestampLastPacket();
  530. void assignMacAddress(const std::string &ipAddress, const std::string &macAddress);
  531. void addIpStat_packetSent(const std::string &ipAddressSender, const std::string &ipAddressReceiver, long bytesSent, std::chrono::microseconds timestamp);
  532. int getPacketCount();
  533. int getSumPacketSize();
  534. void addMSS(const std::string &ipAddress, int MSSvalue);
  535. void writeToDatabase(std::string database_path, std::vector<std::chrono::duration<int, std::micro>> timeInterval, bool del);
  536. void writeIntervalsToDatabase(std::string database_path, std::vector<std::chrono::duration<int, std::micro>> timeIntervals, bool del);
  537. void addPacketSize(uint32_t packetSize);
  538. std::string getCaptureDurationTimestamp() const;
  539. float getCaptureDurationSeconds() const;
  540. float getAvgPacketSize() const;
  541. void printStats(const std::string &ipAddress);
  542. bool getDoExtraTests();
  543. void setDoExtraTests(bool var);
  544. int getDefaultInterval();
  545. void setDefaultInterval(int interval);
  546. /*
  547. * IP Address-specific statistics
  548. */
  549. ip_stats getStatsForIP(const std::string &ipAddress);
  550. private:
  551. /*
  552. * Data fields
  553. */
  554. Tins::Timestamp timestamp_firstPacket;
  555. Tins::Timestamp timestamp_lastPacket;
  556. float sumPacketSize = 0;
  557. int packetCount = 0;
  558. std::string resourcePath;
  559. /* Extra tests includes:
  560. * - calculate IPs entropies for intervals
  561. * - calculate IPs cumulative entropies interval-wise
  562. * - check payload availability
  563. * - chech TCP checksum correctness
  564. */
  565. bool doExtraTests = false;
  566. int payloadCount = 0;
  567. int incorrectTCPChecksumCount = 0;
  568. int correctTCPChecksumCount = 0;
  569. // Variables that are used for interval-wise statistics
  570. int intervalPayloadCount = 0;
  571. int intervalIncorrectTCPChecksumCount = 0;
  572. int intervalCorrectTCPChecksumCount = 0;
  573. int intervalCumPktCount = 0;
  574. float intervalCumSumPktSize = 0;
  575. size_t ip_src_novel_count = 0;
  576. size_t ip_dst_novel_count = 0;
  577. int intervalCumNovelIPCount = 0;
  578. int intervalCumNovelTTLCount = 0;
  579. int intervalCumNovelWinSizeCount = 0;
  580. int intervalCumNovelToSCount = 0;
  581. int intervalCumNovelMSSCount = 0;
  582. int intervalCumNovelPortCount = 0;
  583. std::unordered_map<std::string, entry_ipStat> intervalCumIPStats;
  584. std::unordered_map<int,int> intervalCumTTLValues;
  585. std::unordered_map<int,int> intervalCumWinSizeValues;
  586. std::unordered_map<int,int> intervalCumTosValues;
  587. std::unordered_map<int,int> intervalCumMSSValues;
  588. std::unordered_map<int,int> intervalCumPortValues;
  589. int default_interval = 0;
  590. /*
  591. * Data containers
  592. */
  593. // {IP Address, TTL value, count}
  594. std::unordered_map<ipAddress_ttl, int> ttl_distribution;
  595. // {IP Address, MSS value, count}
  596. std::unordered_map<ipAddress_mss, int> mss_distribution;
  597. // {IP Address, Win size, count}
  598. std::unordered_map<ipAddress_win, int> win_distribution;
  599. // {IP Address, ToS value, count}
  600. std::unordered_map<ipAddress_tos, int> tos_distribution;
  601. // {IP Address A, Port A, IP Address B, Port B, #packets, packets timestamps, inter-arrival times,
  602. // average of inter-arrival times}
  603. std::unordered_map<conv, entry_convStat> conv_statistics;
  604. // {IP Address A, Port A, IP Address B, Port B, comm_intervals, #packets, avg. pkt rate, avg. #packets per interval,
  605. // avg. time between intervals, avg. interval time, duration, packets timestamps, inter-arrivtal times, average of inter-arrival times}
  606. // Also stores conversation with only one exchanged message. In this case avgPktRate, minDelay, maxDelay and avgDelay are -1
  607. std::unordered_map<convWithProt, entry_convStatExt> conv_statistics_extended;
  608. // {Last timestamp in the interval, #packets, #bytes, source IP entropy, destination IP entropy,
  609. // source IP cumulative entropy, destination IP cumulative entropy, #payload, #incorrect TCP checksum,
  610. // #correct TCP checksum, #novel IP, #novel TTL, #novel Window Size, #novel ToS,#novel MSS}
  611. std::unordered_map<std::string, entry_intervalStat> interval_statistics;
  612. // {TTL value, count}
  613. std::unordered_map<int, int> ttl_values;
  614. // {Win size, count}
  615. std::unordered_map<int, int> win_values;
  616. // {ToS, count}
  617. std::unordered_map<int, int> tos_values;
  618. // {MSS, count}
  619. std::unordered_map<int, int> mss_values;
  620. // {Port, count}
  621. std::unordered_map<int, int> port_values;
  622. //{IP Address, contacted IP Addresses}
  623. std::unordered_map<std::string, std::unordered_set<std::string>> contacted_ips;
  624. // {IP Address, Protocol, #count, #Data transmitted in bytes}
  625. std::unordered_map<ipAddress_protocol, entry_protocolStat> protocol_distribution;
  626. // {IP Address, #received packets, #sent packets, Data received in kbytes, Data sent in kbytes}
  627. std::unordered_map<std::string, entry_ipStat> ip_statistics;
  628. // {IP Address, in_out, Port Number, #count, #Data transmitted in bytes}
  629. std::unordered_map<ipAddress_inOut_port, entry_portStat> ip_ports;
  630. // {IP Address, MAC Address}
  631. std::unordered_map<std::string, std::string> ip_mac_mapping;
  632. // {Source MAC, Destination MAC, typeNumber, #count, #timestamp of last occurrence}
  633. std::unordered_map<unrecognized_PDU, unrecognized_PDU_stat> unrecognized_PDUs;
  634. };
  635. #endif //CPP_PCAPREADER_STATISTICS_H