pcap_processor.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  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, std::string database_path);
  25. /*
  26. * Attributes
  27. */
  28. statistics stats;
  29. std::string filePath;
  30. std::string databasePath;
  31. std::string resourcePath;
  32. bool hasUnrecognized;
  33. std::chrono::duration<int, std::micro> timeInterval;
  34. /*
  35. * Methods
  36. */
  37. inline bool file_exists(const std::string &filePath);
  38. void process_packets(const Packet &pkt);
  39. long double get_timestamp_mu_sec(const int after_packet_number);
  40. std::string merge_pcaps(const std::string pcap_path);
  41. bool read_pcap_info(const std::string &filePath, std::size_t &totalPakets);
  42. void collect_statistics(py::list& intervals);
  43. void write_to_database(std::string database_path, const py::list& intervals, bool del);
  44. void write_new_interval_statistics(std::string database_path, const py::list& intervals);
  45. static int get_db_version() { return statistics_db::DB_VERSION; }
  46. };
  47. #endif //CPP_PCAPREADER_MAIN_H