Added a handler for SIGUSR1, which toggles off/on the enforcement calls to tc.
[distributedratelimiting.git] / drl / common_accounting.h
1 /* See the DRL-LICENSE file for this file's software license. */
2
3 /** Defines a structure that is common to all of the flow accounting
4  * mechanisms.  This includes the aggregate rate and the time it was last
5  * updated. */
6
7 #ifndef _COMMON_ACCOUNTING_H_
8 #define _COMMON_ACCOUNTING_H_
9
10 #include <inttypes.h>
11 #include <sys/time.h>
12 #include <time.h>
13
14 /** Representation of a flow that is to be used as a key into the table. */
15 typedef struct key_flow {
16
17     /* Identification information.  Some or all of this information is used
18      * by the accounting table hash functions to identify flows. */
19
20     /** The source IP address. */
21     uint32_t source_ip;
22
23     /** The destination IP address. */
24     uint32_t dest_ip;
25
26     /** The source TCP/UDP port. */
27     uint16_t source_port;
28
29     /** The destination TCP/UDP port. */
30     uint16_t dest_port;
31
32     /** The value of the IP header protocol field. */
33     uint8_t protocol;
34
35     /* 
36      * Packet information.  This is not used by the accounting tables for
37      * hashing, but is useful when sampling a new packet.
38      */
39
40     /** The size of the packet (in bytes). */
41     uint16_t packet_size;
42
43     /** The time at which the packet was sent. */
44     time_t packet_time;
45
46 } key_flow;
47
48 /** 
49  * This structure is used to store information common to all flow accounting
50  * mechanisms.  It includes the aggregate rate information that will be read
51  * by the estimation and allocation functions.
52  */
53 typedef struct {
54     /** The best estimate of the rate for the current estimate interval.  This
55      * includes EWMA smoothing. */
56     uint32_t rate;
57
58     /** The best estimate of the rate for the previous estimate inteval.  This
59      * includes EWMA smoothing. */
60     uint32_t last_rate;
61
62     /** The instantaneous rate for the current estimate interval.*/
63     uint32_t inst_rate;
64
65     /** The instantaneous rate for the previous estimate interval.*/
66     uint32_t last_inst_rate;
67
68     /** The rate of the largest flow being tracked by the table. */
69     uint32_t max_flow_rate;
70
71     /** The time at which this structure was last updated. */
72     struct timeval last_update;
73
74     /** The number of bytes sent since the last_update time. */
75     uint32_t bytes_since;
76
77     /* Statistics below. */
78
79     /** The current number of flows. */
80     uint32_t num_flows;
81
82     /** The number of flows sending above 5KB/s. */
83     uint32_t num_flows_5k;
84
85     /** The number of flows sending above 10KB/s. */
86     uint32_t num_flows_10k;
87
88     /** The number of flows sending above 20KB/s. */
89     uint32_t num_flows_20k;
90
91     /** The number of flows sending above 50KB/s. */
92     uint32_t num_flows_50k;
93
94     /** The average flow rate. */
95     uint32_t avg_rate;
96
97 } common_accounting_t;
98
99 /** Determines the difference between two timeval structs (in seconds, with
100  * fractions). */
101 #define timeval_subtract(big, small) ((double) (big.tv_sec - small.tv_sec) + (big.tv_usec - small.tv_usec) / 1000000.0)
102
103 #endif  /* _COMMON_ACCOUNTING_H_ */