Go to the documentation of this file.
41 static void FlowRateStoreFree(
void *ptr)
44 size_t total_free = 0;
48 for (
int i = 0; i < 2; i++) {
49 if (frs->
dir[i].
buf != NULL) {
51 total_free += (frs->
dir[i].
size *
sizeof(uint64_t));
56 total_free +=
sizeof(*frs);
66 bool track_flow =
false;
74 FatalError(
"No value for flow tracking bytes");
78 FatalError(
"Invalid value for flow tracking bytes");
84 FatalError(
"No value for flow tracking interval");
89 FatalError(
"Invalid value for flow tracking interval");
105 size_t total_memuse = 0;
116 total_memuse +=
sizeof(*frs);
117 for (
int i = 0; i < 2; i++) {
121 FlowRateStoreFree(frs);
126 total_memuse += (frs->
dir[i].
size *
sizeof(uint64_t));
139 static inline void FlowRateClearSumInRange(
140 FlowRateStore *frs, uint16_t start, uint16_t end,
int direction)
142 for (uint16_t i = start; i <= end; i++) {
143 uint64_t byte_count_at_i = frs->
dir[direction].
buf[i];
144 frs->
dir[direction].
buf[i] = 0;
146 frs->
dir[direction].
sum -= byte_count_at_i;
150 static inline void FlowRateStoreUpdateCurrentRing(
156 FlowRateClearSumInRange(frs, frs->
dir[direction].
last_idx + 1, idx, direction);
157 frs->
dir[direction].
buf[idx] += pkt_len;
159 frs->
dir[direction].
sum += pkt_len;
164 frs->
dir[direction].
buf[idx] += pkt_len;
166 frs->
dir[direction].
sum += pkt_len;
169 uint64_t prev_byte_count = frs->
dir[direction].
buf[idx];
171 frs->
dir[direction].
buf[idx] = pkt_len;
174 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);
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);
237 static int FlowRateTest01(
void)
244 for (
int i = 0; i < 2; i++) {
269 FlowRateStoreFree(frs);
274 static int FlowRateTest02(
void)
281 for (
int i = 0; i < 2; i++) {
316 FlowRateStoreFree(frs);
321 static int FlowRateTest03(
void)
328 for (
int i = 0; i < 2; i++) {
376 FlowRateStoreFree(frs);
381 static int FlowRateTest04(
void)
388 for (
int i = 0; i < 2; i++) {
409 FlowRateStoreFree(frs);
415 static int FlowRateTest05(
void)
422 for (
int i = 0; i < 2; i++) {
470 FlowRateStoreFree(frs);
475 static int FlowRateTest06(
void)
482 for (
int i = 0; i < 2; i++) {
542 FlowRateStoreFree(frs);
548 static int FlowRateTest07(
void)
555 for (
int i = 0; i < 2; i++) {
615 FlowRateStoreFree(frs);
FlowStorageId g_flowrate_storage_id
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)
FlowStorageId 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.
#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)
FlowStorageId FlowStorageRegister(const char *name, const unsigned int size, void *(*Alloc)(unsigned int), void(*Free)(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.
bool FlowRateStorageEnabled(void)
#define SCTIME_INITIALIZER
#define SCTIME_ADD_SECS(ts, s)
#define DEBUG_VALIDATE_BUG_ON(exp)