Added the option to manually specify which htb node/parent an identity should be...
[distributedratelimiting.git] / drl / config.h
1 /* See the DRL-LICENSE file for this file's software license. */
2
3 #ifndef _DRL_CONFIG_
4 #define _DRL_CONFIG_
5
6 struct drl_instance;
7
8 /** Enumeration of identity types. */
9 enum ident_types {
10
11     /** Type used by identities that will limit all slivers on the machine. */
12     IDENT_MACHINE = 1,
13
14     /** Type used by identities that will limit only a subset of slivers. */
15     IDENT_SET = 2
16 };
17
18 /** Enumeration of identity member types. */
19 enum member_types {
20
21     /** The member is an identifier (xid) of a single sliver. */
22     MEMBER_XID = 1,
23
24     /** The member is an identifier (guid) of another sliver-set identity. */
25     MEMBER_GUID = 2
26 };
27
28 /**
29  * Linked list node containing address information for one of the identity's
30  * peers.
31  */
32 typedef struct ident_peer {
33     /** The peer's IP address. */
34     in_addr_t ip;
35
36     /** Pointer to the next peer in the list or NULL if this is the last. */
37     struct ident_peer *next;
38 } ident_peer;
39
40 /**
41  * Linked list node containing hierarchy information.  For whole-machine
42  * identities, this is unnecessary.  For sliver-set identities, this specifies
43  * which slivers and other sliver-sets belong in the set.
44  */
45 typedef struct ident_member {
46     /** The numerical xid or guid of the member. */
47     int value;
48
49     /** Specifies whether the value is an xid or guid. */
50     enum member_types type;
51
52     /** Pointer to the next member in the list or NULL if this is the last. */
53     struct ident_member *next;
54 } ident_member;
55
56 /**
57  * Linked list node containing identity information.
58  */
59 typedef struct ident_config {
60     /** The guid of this identity. */
61     int id;
62
63     /** The global DRL limit for this identity. */
64     int limit;
65
66     /** The communication fabric (COMM_MESH or COMM_GOSSIP) for this identity.*/
67     enum commfabrics commfabric;
68
69     /** The gossip branch factor (when commfabric is COMM_GOSSIP). */
70     int branch;
71
72     /** The gossip group membership policy (SWIM, ZOOKEEPER). */
73     enum memberships membership;
74
75     /** The behavioral policy to use when one or more failures in group
76      * membership are detected. */
77     enum failure_behaviors failure_behavior;
78
79 #ifdef BUILD_ZOOKEEPER
80
81     /** The host string that should be passed to zookeeper_init when using
82      * zookeeper.  This consists of comma-separated ipaddr:port pairs. Example:
83      * "127.0.0.1:3000,127.0.0.1:3001,127.0.0.1:3002" */
84     char *zk_host;
85
86 #endif
87
88     /** The flow accounting mechanism to be used by this identity. */
89     enum accountings accounting;
90
91     /** The fixed (1-second) ewma weight value for this identity. */
92     double fixed_ewma_weight;
93
94     /** The number of limiter intervals to wait between calls to estimate,
95      * allocate and enforce. */
96     int mainloop_intervals;
97
98     /** The number of limiter intervals to wait between communication. */
99     int communication_intervals;
100
101     /** The type of this identity. */
102     enum ident_types type;
103
104     /** List of the identity's peers. */
105     ident_peer *peers;
106
107     /** The number of peers. */
108     int peer_count;
109
110     /** If this is set, the node goes under the root rather than machine nodes. */
111     int independent;
112
113     /** List of the identity's members (type IDENT_SET only). */
114     ident_member *members;
115
116     /** If NM is setting up the hierarchy for us, this is the htb node to use
117      * for this identity. */
118     int htb_node;
119
120     /** If NM is setting up the hierarchy for us, this is the htb parent node
121      * to use for this identity. */
122     int htb_parent;
123
124     /** Pointer to the next ident in the list or NULL if this is the last. */
125     struct ident_config *next;
126 } ident_config;
127
128 /**
129  * Structure used to pass two lists after parsing is complete.
130  */
131 typedef struct parsed_configs {
132     /** A list of IDENT_MACHINE type identities. */
133     ident_config *machines;
134
135     /** The number of machine identities. */
136     int machine_count;
137
138     /** A list of IDENT_SET type identities. */
139     ident_config *sets;
140
141     /** The number of set identities. */
142     int set_count;
143
144     /** Pointer to the tail of the machines list. */
145     ident_config *last_machine;
146
147     /** Pointer to the tail of the sets list. */
148     ident_config *last_set;
149 } parsed_configs;
150
151 /**
152  * Frees the specified ident and all of the memory associated with it and its
153  * fields.
154  *
155  * @param ident The ident to free.
156  */
157 void free_ident(ident_config *ident);
158
159 /**
160  * Frees the specified list of identities and all of the memory associated
161  * with them.
162  *
163  * @param list The ident_config list to free.
164  */
165 void free_ident_list(ident_config *list);
166
167 /**
168  * Uses libxml2 to parse a DRL configuration XML file and converts the
169  * information into a linked list of identities.
170  *
171  * @param configfile The path to the XML configuration file.
172  * @param configs A parsed_configs structure to be filled in with linked list
173  * of machine and set configs.
174  *
175  * @returns zero on success, non-zero on error.
176  */
177 int parse_drl_config(const char *configfile, parsed_configs *configs);
178
179 /**
180  * Reads /proc/virtual to get a list of viable xids.  It creates an array of
181  * leaf_t structures and a map that maps xid to the leaf_t in the array with
182  * the xid.
183  *
184  * @param instance The drl_instance_t to be filled in.  This function sets
185  * the instance's leaf_map, leaves, and leaf_count fields.
186  *
187  * @returns zero on success, non-zero on error. (Possibly ENOMEM if memory
188  * allocation fails, or 1 if the cause of the error is unclear. */
189 int get_eligible_leaves(struct drl_instance *instance);
190
191 #endif  /* _DRL_CONFIG_ */