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");
104 size_t total_memuse = 0;
115 total_memuse +=
sizeof(*frs);
116 for (
int i = 0; i < 2; i++) {
120 FlowRateStoreFree(frs);
125 total_memuse += (frs->
dir[i].
size *
sizeof(uint64_t));
138 static inline void FlowRateClearSumInRange(
141 for (uint16_t i =
start; i <=
end; i++) {
142 uint64_t byte_count_at_i = frs->
dir[direction].
buf[i];
143 frs->
dir[direction].
buf[i] = 0;
145 frs->
dir[direction].
sum -= byte_count_at_i;
149 static inline void FlowRateStoreUpdateCurrentRing(
155 FlowRateClearSumInRange(frs, frs->
dir[direction].
last_idx + 1, idx, direction);
156 frs->
dir[direction].
buf[idx] += pkt_len;
158 frs->
dir[direction].
sum += pkt_len;
162 frs->
dir[direction].
buf[idx] += pkt_len;
164 frs->
dir[direction].
sum += pkt_len;
167 uint64_t prev_byte_count = frs->
dir[direction].
buf[idx];
169 frs->
dir[direction].
buf[idx] = pkt_len;
172 frs->
dir[direction].
sum += pkt_len - prev_byte_count;
181 static inline void FlowRateStoreFlushRing(
184 memset(frs->
dir[direction].
buf, 0, frs->
dir[direction].
size);
187 frs->
dir[direction].
buf[0] = pkt_len;
189 frs->
dir[direction].
sum = pkt_len;
210 FlowRateClearSumInRange(frs, 0, idx, direction);
217 FlowRateStoreUpdateCurrentRing(frs, p_ts, pkt_len, idx, direction);
221 FlowRateStoreFlushRing(frs, p_ts, pkt_len, direction);
235 static int FlowRateTest01(
void)
242 for (
int i = 0; i < 2; i++) {
270 FlowRateStoreFree(frs);
275 static int FlowRateTest02(
void)
282 for (
int i = 0; i < 2; i++) {
321 FlowRateStoreFree(frs);
326 static int FlowRateTest03(
void)
333 for (
int i = 0; i < 2; i++) {
396 FlowRateStoreFree(frs);
401 static int FlowRateTest04(
void)
408 for (
int i = 0; i < 2; i++) {
431 FlowRateStoreFree(frs);
437 static int FlowRateTest05(
void)
444 for (
int i = 0; i < 2; i++) {
497 FlowRateStoreFree(frs);
502 static int FlowRateTest06(
void)
509 for (
int i = 0; i < 2; i++) {
575 FlowRateStoreFree(frs);
581 static int FlowRateTest07(
void)
588 for (
int i = 0; i < 2; i++) {
654 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)