Go to the documentation of this file.
40 static void FlowRateStoreFree(
void *ptr)
43 size_t total_free = 0;
47 for (
int i = 0; i < 2; i++) {
48 if (frs->
dir[i].
buf != NULL) {
50 total_free += (frs->
dir[i].
size *
sizeof(uint64_t));
55 total_free +=
sizeof(*frs);
65 bool track_flow =
false;
73 FatalError(
"No value for flow tracking bytes");
77 FatalError(
"Invalid value for flow tracking bytes");
83 FatalError(
"No value for flow tracking interval");
88 FatalError(
"Invalid value for flow tracking interval");
103 size_t total_memuse = 0;
114 total_memuse +=
sizeof(*frs);
115 for (
int i = 0; i < 2; i++) {
119 FlowRateStoreFree(frs);
124 total_memuse += (frs->
dir[i].
size *
sizeof(uint64_t));
137 static inline void FlowRateClearSumInRange(
140 for (uint16_t i =
start; i <=
end; i++) {
141 uint64_t byte_count_at_i = frs->
dir[direction].
buf[i];
142 frs->
dir[direction].
buf[i] = 0;
144 frs->
dir[direction].
sum -= byte_count_at_i;
148 static inline void FlowRateStoreUpdateCurrentRing(
154 FlowRateClearSumInRange(frs, frs->
dir[direction].
last_idx + 1, idx, direction);
155 frs->
dir[direction].
buf[idx] += pkt_len;
157 frs->
dir[direction].
sum += pkt_len;
161 frs->
dir[direction].
buf[idx] += pkt_len;
163 frs->
dir[direction].
sum += pkt_len;
166 uint64_t prev_byte_count = frs->
dir[direction].
buf[idx];
168 frs->
dir[direction].
buf[idx] = pkt_len;
171 frs->
dir[direction].
sum += pkt_len - prev_byte_count;
180 static inline void FlowRateStoreFlushRing(
183 memset(frs->
dir[direction].
buf, 0, frs->
dir[direction].
size *
sizeof(*frs->
dir[direction].
buf));
186 frs->
dir[direction].
buf[0] = pkt_len;
188 frs->
dir[direction].
sum = pkt_len;
209 FlowRateClearSumInRange(frs, 0, idx, direction);
216 FlowRateStoreUpdateCurrentRing(frs, p_ts, pkt_len, idx, direction);
220 FlowRateStoreFlushRing(frs, p_ts, pkt_len, direction);
234 static int FlowRateTest01(
void)
241 for (
int i = 0; i < 2; i++) {
269 FlowRateStoreFree(frs);
274 static int FlowRateTest02(
void)
281 for (
int i = 0; i < 2; i++) {
320 FlowRateStoreFree(frs);
325 static int FlowRateTest03(
void)
332 for (
int i = 0; i < 2; i++) {
395 FlowRateStoreFree(frs);
401 static int FlowRateTest04(
void)
408 for (
int i = 0; i < 2; i++) {
474 FlowRateStoreFree(frs);
480 static int FlowRateTest05(
void)
487 for (
int i = 0; i < 2; i++) {
540 FlowRateStoreFree(frs);
545 static int FlowRateTest06(
void)
552 for (
int i = 0; i < 2; i++) {
618 FlowRateStoreFree(frs);
624 static int FlowRateTest07(
void)
631 for (
int i = 0; i < 2; i++) {
697 FlowRateStoreFree(frs);
void FlowRateRegisterTests(void)
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
#define SC_ATOMIC_SET(name, val)
Set the value for the atomic variable.
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
int ParseSizeStringU64(const char *size, uint64_t *res)
#define SC_ATOMIC_ADD(name, val)
add a value to our atomic variable
int StringParseUint16(uint16_t *res, int base, size_t len, const char *str)
SCFlowStorageId FlowRateGetStorageID(void)
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
const char * SCConfNodeLookupChildValue(const SCConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
SCFlowStorageId g_flowrate_storage_id
SCFlowStorageId SCFlowStorageRegister(const char *name, void(*Free)(void *))
#define FLOW_CHECK_MEMCAP(size)
check if a memory alloc would fit in the memcap
void FlowRateStoreUpdate(FlowRateStore *frs, SCTime_t p_ts, uint32_t pkt_len, int direction)
#define PASS
Pass the test.
void FlowRateRegisterFlowStorage(void)
#define SC_ATOMIC_SUB(name, val)
sub a value from our atomic variable
FlowRateConfig flow_rate_config
SCConfNode * SCConfNodeLookupChild(const SCConfNode *node, const char *name)
Lookup a child configuration node by name.
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
FlowRateStore * FlowRateStoreInit(void)
bool FlowRateIsExceeding(FlowRateStore *frs, int direction)
SCConfNode * SCConfGetNode(const char *name)
Get a SCConfNode by name.
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
bool FlowRateStorageEnabled(void)
#define SCTIME_INITIALIZER
#define SCTIME_ADD_SECS(ts, s)
#define DEBUG_VALIDATE_BUG_ON(exp)