statistics_db.h 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /**
  2. * Class writing the statistics to the database.
  3. */
  4. #ifndef CPP_PCAPREADER_STATISTICSDB_H
  5. #define CPP_PCAPREADER_STATISTICSDB_H
  6. #include <iostream>
  7. #include <memory>
  8. #include <string>
  9. #include "statistics.h"
  10. #include <SQLiteCpp/SQLiteCpp.h>
  11. #include <unordered_map>
  12. class statistics_db {
  13. public:
  14. /*
  15. * Constructor: Creates new database / Opens existing database
  16. */
  17. statistics_db(std::string database_path);
  18. /*
  19. * Database version: Increment number on every change in the C++ code!
  20. */
  21. static const int DB_VERSION = 9;
  22. /*
  23. * Methods for writing values into database
  24. */
  25. void writeStatisticsIP(const std::unordered_map<std::string, entry_ipStat> &ipStatistics);
  26. void writeStatisticsDegree(const std::unordered_map<std::string, entry_ipStat> &ipStatistics);
  27. void writeStatisticsTTL(const std::unordered_map<ipAddress_ttl, int> &ttlDistribution);
  28. void writeStatisticsMSS(const std::unordered_map<ipAddress_mss, int> &mssDistribution);
  29. void writeStatisticsToS(const std::unordered_map<ipAddress_tos, int> &tosDistribution);
  30. void writeStatisticsWin(const std::unordered_map<ipAddress_win, int> &winDistribution);
  31. void writeStatisticsProtocols(const std::unordered_map<ipAddress_protocol, entry_protocolStat> &protocolDistribution);
  32. void writeStatisticsPorts(const std::unordered_map<ipAddress_inOut_port, entry_portStat> &portsStatistics);
  33. void writeStatisticsIpMac(const std::unordered_map<std::string, std::string> &IpMacStatistics);
  34. void writeStatisticsFile(int packetCount, float captureDuration, std::string timestampFirstPkt,
  35. std::string timestampLastPkt, float avgPacketRate, float avgPacketSize,
  36. float avgPacketsSentPerHost, float avgBandwidthIn, float avgBandwidthOut,
  37. bool doExtraTests);
  38. void writeStatisticsConv(std::unordered_map<conv, entry_convStat> &convStatistics);
  39. void writeStatisticsConvExt(std::unordered_map<convWithProt, entry_convStatExt> &conv_statistics_extended);
  40. void writeStatisticsInterval(const std::unordered_map<std::string, entry_intervalStat> &intervalStatistics);
  41. void writeDbVersion();
  42. void readPortServicesFromNmap();
  43. std::string getNmapPath();
  44. bool pathExists(std::string path);
  45. void writeStatisticsUnrecognizedPDUs(const std::unordered_map<unrecognized_PDU, unrecognized_PDU_stat> &unrecognized_PDUs);
  46. private:
  47. // Pointer to the SQLite database
  48. std::unique_ptr<SQLite::Database> db;
  49. // Vector which contains all ports and their corresponding services
  50. std::unordered_map<int, std::string> portServices;
  51. };
  52. #endif //CPP_PCAPREADER_STATISTICSDB_H