1 /* See the DRL-LICENSE file for this file's software license. */
5 * Defines the main types used by DRL.
14 #include "rate_accounting/common_accounting.h"
15 #include "rate_accounting/standard.h"
16 #include "rate_accounting/samplehold.h"
17 #include "rate_accounting/simple.h"
22 #include "drl_state.h"
23 #include "common_accounting.h"
25 #include "samplehold.h"
29 /** Represents a DRL entitiy/group. */
30 typedef struct identity {
32 /** A unique id for the identity. */
35 /** The global rate limit. */
38 /** The local rate limit. */
41 /** Pointer to the identity's parent in the HTB hierarchy. */
42 struct identity *parent;
44 /** Array of the leaves that are limited by this identity. Points into the
45 * leaves array for the identity's instance. */
48 /** The number of leaves for which this identity is responsible. */
51 /** The fixed (per second) EWMA weight. */
52 double fixed_ewma_weight;
54 /** The real EWMA weight, based on the fixed weight and estimate interval.*/
57 /** Used for average rate graph generation. */
62 /** Communication data for this identity. */
67 /** The node in the HTB hierarchy whose limits will be modified by this
68 * identity. (1:1<htb_node>)*/
71 /** The parent of this node in the HTB hierarchy. (tc requires that the
72 * parent be specified in all calls the modify a node.) */
75 /** FPS current weight value. */
78 /** FPS previous weight value. */
79 double last_localweight;
83 /** A flag to indicate whether or not the identity is in the flowstart
84 * state. During flowstart, the identity's limit is raised to allow for
85 * flows to grow before incurring losses. */
90 /** GRD drop probability information. */
93 /** GRD previous drop probability information. */
94 double last_drop_prob;
96 /* Flow accounting machinery. */
98 /** Flow information that is common to all types of tables.
99 * This includes aggregate rates, update times, etc. */
100 common_accounting_t common;
102 /** The actual table. Uses a void pointer because it could be one
103 * of several different types. (standard, sample&hold, etc. ) */
106 /** Protects the table, as it gets updated in two separate threads:
107 * 1) ulogd_DRL.c: the table is updated as new packet information arrives.
108 * 2) estimate.c: the table is used to determine rates, and it's also
109 * periodically cleaned.
111 pthread_mutex_t table_mutex;
113 /* Function pointers to functions to act on the table. */
115 /** Function to call for each packet. Updates the byte count for flows
116 * that are being tracked. */
117 int (*table_sample_function)(void *, const key_flow *);
119 /** Function to call on the table when it is periodically cleaned. */
120 int (*table_cleanup_function)(void *);
122 /** Function to call once per estimate interval to update the table's
123 * rate estimation. */
124 void (*table_update_function)(void *, struct timeval, double);
126 /** Function to call when the table should be destroyed. */
127 void (*table_destroy_function)(void *);
129 /* Scheduling bookkeeping. */
131 /* Pointers to other identities in the scheduling calendar. */
132 TAILQ_ENTRY(identity) calendar;
134 /* The number of limiter ticks at which this identity should be scheduled.
141 * Represents the bottom most entity in the HTB hierarchy. For PlanetLab,
142 * this corresponds to sliver (identified by Vserver context id, or xid).
144 typedef struct leaf {
145 /** The leaf identifier. */
148 /** The leaf's parent in the hierarchy. This is the identity to which this
152 /** GRD: The leaf's packet drop probability. */
157 * Contains all of the identity and sliver information associated with a
158 * runnable instance of a local DRL node.
160 typedef struct drl_instance {
161 /** An array of the node's viable leaves (slivers). */
164 /** The number of items in the leaf array. */
167 /** Maps sliver xid to the leaf_t in the leaves array. */
170 /** An array of the node's machine-type identities. */
171 identity_t **machines;
173 /** The number of items in the machines array. */
176 /** An array of the node's set-type identities. */
179 /** The number of items in the sets array. */
182 /** Maps identity guid to the identity_t in either the machines or sets
184 map_handle ident_map;
186 /** The lowest machine identity in the hierarchy. This acts as the root
187 * for the set-identity subtree. */
188 identity_t *last_machine;
190 /** Acts as a circular array of lists used to schedule identities at
191 * some number of intervals. */
192 struct ident_calendar *cal;
194 /** The slot for the "current" tick in the calendar. */
199 /** Represents the local node. */
200 typedef struct limiter {
201 /** The limiter's local address in dotted quad notation. */
204 /** The node's individual (administrative) limit. This node should set a
205 * limit above this value, even when DRL says it can do so. */
208 /** The DRL policy (GRD, FPS) this node is using. */
209 enum policies policy;
211 /** The estimate interval (in milliseconds). */
214 /** A lock to protect the state of identities so that they can be
215 * created/destroyed without harming any other, currently active idents.
217 * I made this an rwlock because it allows for much better parallelism.
218 * Creating/removing identities is uncommon, and most of the time this
219 * doesn't need to be held for writing. */
220 pthread_rwlock_t limiter_lock;
222 /** The currently running DRL instance. */
223 drl_instance_t stable_instance;
225 /** The next instance - if it validates. When the XML config file is
226 * re-read, the new structures will be incorporated into this instance. If
227 * everything checks out, the old (stable) instance will be freed, and this
228 * will be copied into stable_instance. */
229 drl_instance_t new_instance;
231 /* Communication fields. */
233 /** The limiter's local address as an integer (net byte order). */
236 /** The local port on which to listen (net byte order). */
239 /** Local UDP communication socket. */
243 /** Local TCP communication socket. */
247 /** Limiter-wide UDP receive thread. */
248 pthread_t udp_recv_thread;
251 /** Limiter-wide TCP thread for accepting incoming connections. */
252 pthread_t tcp_acpt_thread;