Skip to content

Commit af2a354

Browse files
committed
fdsdump: add flowContext class for aggregator
1 parent 9d616ed commit af2a354

File tree

2 files changed

+102
-0
lines changed

2 files changed

+102
-0
lines changed
Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
/**
2+
* @file
3+
* @author Michal Sedlak <[email protected]>
4+
* @brief The flow context
5+
*
6+
* Copyright: (C) 2024 CESNET, z.s.p.o.
7+
* SPDX-License-Identifier: BSD-3-Clause
8+
*/
9+
10+
#include <aggregator/flowContext.hpp>
11+
12+
namespace fdsdump {
13+
namespace aggregator {
14+
15+
bool
16+
FlowContext::find_field(uint32_t pen, uint16_t id, fds_drec_field &field)
17+
{
18+
if (flow_dir == FlowDirection::None) {
19+
int ret = fds_drec_find(&drec, pen, id, &field);
20+
return ret != FDS_EOC;
21+
22+
} else {
23+
int flags = (flow_dir == FlowDirection::Forward
24+
? FDS_DREC_BIFLOW_FWD : FDS_DREC_BIFLOW_REV);
25+
fds_drec_iter iter;
26+
fds_drec_iter_init(&iter, &drec, flags);
27+
int ret = fds_drec_iter_find(&iter, pen, id);
28+
if (ret != FDS_EOC) {
29+
field = iter.field;
30+
return true;
31+
} else {
32+
return false;
33+
}
34+
}
35+
}
36+
37+
} // aggregator
38+
} // fdsdump
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
/**
2+
* @file
3+
* @author Michal Sedlak <[email protected]>
4+
* @brief The flow context
5+
*
6+
* Copyright: (C) 2024 CESNET, z.s.p.o.
7+
* SPDX-License-Identifier: BSD-3-Clause
8+
*/
9+
10+
#pragma once
11+
12+
#include <libfds.h>
13+
14+
#include <cstdint>
15+
16+
namespace fdsdump {
17+
namespace aggregator {
18+
19+
/**
20+
* @brief The view direction
21+
*/
22+
enum class ViewDirection {
23+
None,
24+
In,
25+
Out
26+
};
27+
28+
/**
29+
* @brief The flow direction
30+
*/
31+
enum class FlowDirection {
32+
None,
33+
Forward,
34+
Reverse
35+
};
36+
37+
/**
38+
* @brief The flow context
39+
*/
40+
struct FlowContext {
41+
fds_drec &drec;
42+
ViewDirection view_dir = ViewDirection::None;
43+
FlowDirection flow_dir = FlowDirection::None;
44+
45+
/**
46+
* @brief Create a flow context instance for the underlying flow data record
47+
*/
48+
FlowContext(fds_drec &drec) : drec(drec) {}
49+
50+
/**
51+
* @brief Find an IPFIX field in the underlying data record
52+
*
53+
* @param[in] pen The IPFIX PEN of the field
54+
* @param[in] id The IPFIX ID of the field
55+
* @param[out] field The field if found
56+
*
57+
* @return true if the field was found, else false
58+
*/
59+
bool
60+
find_field(uint32_t pen, uint16_t id, fds_drec_field &field);
61+
};
62+
63+
} // aggregator
64+
} // fdsdump

0 commit comments

Comments
 (0)