File tree Expand file tree Collapse file tree 2 files changed +70
-0
lines changed
Expand file tree Collapse file tree 2 files changed +70
-0
lines changed Original file line number Diff line number Diff line change 1+
2+ #include < cstring>
3+ #include < cstdint>
4+ #include < stdexcept>
5+
6+ #include " storageRecord.hpp"
7+
8+ StorageRecord::StorageRecord (
9+ const struct fds_drec &rec,
10+ enum Direction dir,
11+ const shared_tsnapshot &snapshot)
12+ : m_data{new uint8_t [rec.size ]}, m_snapshot{snapshot}
13+ {
14+ const uint16_t tmplt_id = rec.tmplt ->id ;
15+ const fds_template *tmplt = fds_tsnapshot_template_get (m_snapshot.get (), tmplt_id);
16+
17+ if (!tmplt) {
18+ throw std::runtime_error (" Snapshot doesn't contain required template" );;
19+ }
20+
21+ std::memcpy (m_data.get (), rec.data , rec.size );
22+
23+ m_flow.dir = dir;
24+ m_flow.rec .data = m_data.get ();
25+ m_flow.rec .size = rec.size ;
26+ m_flow.rec .tmplt = tmplt;
27+ m_flow.rec .snap = m_snapshot.get ();
28+ }
Original file line number Diff line number Diff line change 1+
2+ #pragma once
3+
4+ #include < libfds.h>
5+ #include < memory>
6+
7+ #include " common.hpp"
8+ #include " flow.hpp"
9+
10+ /* *
11+ * @brief Flow storage record.
12+ *
13+ * The flow record contains the whole IPFIX Data Record and a reference to
14+ * a template snapshot necessary for its interpretation.
15+ */
16+ class StorageRecord {
17+ public:
18+ /* *
19+ * @brief Create a storage record by creating a copy of IPFIX Data Record
20+ * extracted, for example, from FDS File.
21+ *
22+ * @param rec Flow data record to be stored
23+ * @param dir Direction of the record to be considered.
24+ * @param snapshot Template snapshot that should be used
25+ */
26+ StorageRecord (
27+ const struct fds_drec &rec,
28+ enum Direction dir,
29+ const shared_tsnapshot &snapshot);
30+ ~StorageRecord () = default ;
31+
32+ Flow &
33+ get_flow () { return m_flow; };
34+
35+ const Flow &
36+ get_flow_const () const { return m_flow; };
37+
38+ private:
39+ std::unique_ptr<uint8_t []> m_data;
40+ shared_tsnapshot m_snapshot;
41+ Flow m_flow;
42+ };
You can’t perform that action at this time.
0 commit comments