1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- /**
- * Class writing the statistics to the database.
- */
- #ifndef CPP_PCAPREADER_STATISTICSDB_H
- #define CPP_PCAPREADER_STATISTICSDB_H
- #include <iostream>
- #include <memory>
- #include <string>
- #include "statistics.h"
- #include <SQLiteCpp/SQLiteCpp.h>
- #include <unordered_map>
- class statistics_db {
- public:
- /*
- * Constructor: Creates new database / Opens existing database
- */
- statistics_db(std::string database_path);
- /*
- * Database version: Increment number on every change in the C++ code!
- */
- static const int DB_VERSION = 4;
- /*
- * Methods for writing values into database
- */
- void writeStatisticsIP(std::unordered_map<std::string, entry_ipStat> ipStatistics);
- void writeStatisticsTTL(std::unordered_map<ipAddress_ttl, int> ttlDistribution);
- void writeStatisticsMSS(std::unordered_map<ipAddress_mss, int> mssDistribution);
- void writeStatisticsToS(std::unordered_map<ipAddress_tos, int> tosDistribution);
- void writeStatisticsWin(std::unordered_map<ipAddress_win, int> winDistribution);
- void writeStatisticsProtocols(std::unordered_map<ipAddress_protocol, entry_protocolStat> protocolDistribution);
- void writeStatisticsPorts(std::unordered_map<ipAddress_inOut_port, entry_portStat> portsStatistics);
- void writeStatisticsIpMac(std::unordered_map<std::string, std::string> IpMacStatistics);
- void writeStatisticsFile(int packetCount, float captureDuration, std::string timestampFirstPkt,
- std::string timestampLastPkt, float avgPacketRate, float avgPacketSize,
- float avgPacketsSentPerHost, float avgBandwidthIn, float avgBandwidthOut);
- void writeStatisticsConv(std::unordered_map<conv, entry_convStat> convStatistics);
- void writeStatisticsInterval(std::unordered_map<std::string, entry_intervalStat> intervalStatistics);
- void writeDbVersion();
- void readPortServicesFromNmap();
- std::string getNmapPath();
- bool pathExists(std::string path);
- void writeStatisticsUnrecognizedPDUs(std::unordered_map<unrecognized_PDU, unrecognized_PDU_stat> unrecognized_PDUs);
- private:
- // Pointer to the SQLite database
- std::unique_ptr<SQLite::Database> db;
- // Vector which contains all ports and their corresponding services
- std::unordered_map<int, std::string> portServices;
- };
- #endif //CPP_PCAPREADER_STATISTICSDB_H
|