Skip to content

Commit 081a30f

Browse files
Lukas HutakLukas955
authored andcommitted
fdsdump: storageRecord: define component
1 parent 8952aee commit 081a30f

File tree

2 files changed

+70
-0
lines changed

2 files changed

+70
-0
lines changed
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
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+
}
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
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+
};

0 commit comments

Comments
 (0)