pcap_processor.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. /**
  2. * Class for processing PCAPs to collect statistical data.
  3. */
  4. #ifndef CPP_PCAPREADER_MAIN_H
  5. #define CPP_PCAPREADER_MAIN_H
  6. #include <algorithm>
  7. #include <iomanip>
  8. #include <tins/tins.h>
  9. #include <iostream>
  10. #include <pybind11/pybind11.h>
  11. #include <time.h>
  12. #include <stdio.h>
  13. #include <sys/stat.h>
  14. #include <unordered_map>
  15. #include "statistics.h"
  16. #include "statistics_db.h"
  17. namespace py = pybind11;
  18. using namespace Tins;
  19. class pcap_processor {
  20. public:
  21. /*
  22. * Class constructor
  23. */
  24. pcap_processor(std::string path, std::string extraTests, std::string resource_path);
  25. /*
  26. * Attributes
  27. */
  28. statistics stats;
  29. std::string filePath;
  30. bool hasUnrecognized;
  31. std::chrono::duration<int, std::micro> timeInterval;
  32. /*
  33. * Methods
  34. */
  35. inline bool file_exists(const std::string &filePath);
  36. void process_packets(const Packet &pkt);
  37. long double get_timestamp_mu_sec(const int after_packet_number);
  38. std::string merge_pcaps(const std::string pcap_path);
  39. bool read_pcap_info(const std::string &filePath, std::size_t &totalPakets);
  40. void collect_statistics(const py::list& intervals);
  41. void write_to_database(std::string database_path, const py::list& intervals, bool del);
  42. void write_new_interval_statistics(std::string database_path, const py::list& intervals);
  43. static int get_db_version() { return statistics_db::DB_VERSION; }
  44. };
  45. #endif //CPP_PCAPREADER_MAIN_H