--- /dev/null
+/* See the DRL-LICENSE file for this file's software license. */
+
+/* ratetypes.h
+ *
+ * Defines the main types used by DRL.
+ */
+
+#ifndef _RATETYPES_H_
+#define _RATETYPES_H_
+
+#include <inttypes.h>
+
+#if 0
+#include "rate_accounting/common_accounting.h"
+#include "rate_accounting/standard.h"
+#include "rate_accounting/samplehold.h"
+#include "rate_accounting/simple.h"
+#endif
+
+#include "calendar.h"
+#include "config.h"
+#include "drl_state.h"
+#include "common_accounting.h"
+#include "standard.h"
+#include "samplehold.h"
+#include "simple.h"
+
+
+/** Represents a DRL entitiy/group. */
+typedef struct identity {
+
+ /** A unique id for the identity. */
+ uint32_t id;
+
+ /** The global rate limit. */
+ uint32_t limit;
+
+ /** The local rate limit. */
+ uint32_t locallimit;
+
+ /** Pointer to the identity's parent in the HTB hierarchy. */
+ struct identity *parent;
+
+ /** The fixed (per second) EWMA weight. */
+ double fixed_ewma_weight;
+
+ /** The real EWMA weight, based on the fixed weight and estimate interval.*/
+ double ewma_weight;
+
+ /** Used for average rate graph generation. */
+ double avg_bytes;
+
+ /* Communication */
+
+ /** Communication data for this identity. */
+ comm_t comm;
+
+ /* FPS */
+
+ /** The node in the HTB hierarchy whose limits will be modified by this
+ * identity. (1:1<htb_node>)*/
+ uint32_t htb_node;
+
+ /** The parent of this node in the HTB hierarchy. (tc requires that the
+ * parent be specified in all calls the modify a node.) */
+ uint32_t htb_parent;
+
+ /** FPS current weight value. */
+ double localweight;
+
+ /** FPS previous weight value. */
+ double last_localweight;
+
+ /** A flag to indicate whether or not the identity is in the flowstart
+ * state. During flowstart, the identity's limit is raised to allow for
+ * flows to grow before incurring losses. */
+ int flowstart;
+
+ /* GRD */
+
+ /** GRD drop probability information. */
+ double localdropprob;
+
+ /** GRD previous drop probability information. */
+ double last_localdropprob;
+
+ /* Flow accounting machinery. */
+
+ /** Flow information that is common to all types of tables.
+ * This includes aggregate rates, update times, etc. */
+ common_accounting_t common;
+
+ /** The actual table. Uses a void pointer because it could be one
+ * of several different types. (standard, sample&hold, etc. ) */
+ void *table;
+
+ /** Protects the table, as it gets updated in two separate threads:
+ * 1) ulogd_DRL.c: the table is updated as new packet information arrives.
+ * 2) estimate.c: the table is used to determine rates, and it's also
+ * periodically cleaned.
+ */
+ pthread_mutex_t table_mutex;
+
+ /* Function pointers to functions to act on the table. */
+
+ /** Function to call for each packet. Updates the byte count for flows
+ * that are being tracked. */
+ int (*table_sample_function)(void *, const key_flow *);
+
+ /** Function to call on the table when it is periodically cleaned. */
+ int (*table_cleanup_function)(void *);
+
+ /** Function to call once per estimate interval to update the table's
+ * rate estimation. */
+ void (*table_update_function)(void *, struct timeval, double);
+
+ /** Function to call when the table should be destroyed. */
+ void (*table_destroy_function)(void *);
+
+ /* Scheduling bookkeeping. */
+
+ /* Pointers to other identities in the scheduling calendar. */
+ TAILQ_ENTRY(identity) calendar;
+
+ /* The number of limiter ticks at which this identity should be scheduled.
+ */
+ uint32_t intervals;
+
+} identity_t;
+
+/**
+ * Represents the bottom most entity in the HTB hierarchy. For PlanetLab,
+ * this corresponds to sliver (identified by Vserver context id, or xid).
+ */
+typedef struct leaf {
+ /** The leaf identifier. */
+ uint32_t xid;
+
+ /** The leaf's parent in the hierarchy. This is the identity to which this
+ * leaf belongs. */
+ identity_t *parent;
+} leaf_t;
+
+/**
+ * Contains all of the identity and sliver information associated with a
+ * runnable instance of a local DRL node.
+ */
+typedef struct drl_instance {
+ /** An array of the node's viable leaves (slivers). */
+ leaf_t *leaves;
+
+ /** The number of items in the leaf array. */
+ int leaf_count;
+
+ /** Maps sliver xid to the leaf_t in the leaves array. */
+ map_handle leaf_map;
+
+ /** An array of the node's machine-type identities. */
+ identity_t **machines;
+
+ /** The number of items in the machines array. */
+ int machine_count;
+
+ /** An array of the node's set-type identities. */
+ identity_t **sets;
+
+ /** The number of items in the sets array. */
+ int set_count;
+
+ /** Maps identity guid to the identity_t in either the machines or sets
+ * arrays. */
+ map_handle ident_map;
+
+ /** The lowest machine identity in the hierarchy. This acts as the root
+ * for the set-identity subtree. */
+ identity_t *last_machine;
+
+ /** Acts as a circular array of lists used to schedule identities at
+ * some number of intervals. */
+ struct ident_calendar *cal;
+
+ /** The slot for the "current" tick in the calendar. */
+ uint32_t cal_slot;
+
+} drl_instance_t;
+
+/** Represents the local node. */
+typedef struct limiter {
+ /** The limiter's local address in dotted quad notation. */
+ char *ip;
+
+ /** The node's individual (administrative) limit. This node should set a
+ * limit above this value, even when DRL says it can do so. */
+ uint32_t nodelimit;
+
+ /** The DRL policy (GRD, FPS) this node is using. */
+ enum policies policynum;
+
+ /** The estimate interval (in milliseconds). */
+ int estintms;
+
+ /** A lock to protect the state of identities so that they can be
+ * created/destroyed without harming any other, currently active idents.
+ *
+ * I made this an rwlock because it allows for much better parallelism.
+ * Creating/removing identities is uncommon, and most of the time this
+ * doesn't need to be held for writing. */
+ pthread_rwlock_t limiter_lock;
+
+ /** The currently running DRL instance. */
+ drl_instance_t stable_instance;
+
+ /** The next instance - if it validates. When the XML config file is
+ * re-read, the new structures will be incorporated into this instance. If
+ * everything checks out, the old (stable) instance will be freed, and this
+ * will be copied into stable_instance. */
+ drl_instance_t new_instance;
+
+ /* Communication fields. */
+
+ /** The limiter's local address as an integer (net byte order). */
+ in_addr_t localaddr;
+
+ /** The local port on which to listen (net byte order). */
+ in_port_t port;
+
+ /** Local UDP communication socket. */
+ int udp_socket;
+
+#if 0
+ /** Local TCP communication socket. */
+ int tcp_socket;
+#endif
+
+ /** Limiter-wide UDP receive thread. */
+ pthread_t udp_recv_thread;
+
+#if 0
+ /** Limiter-wide TCP thread for accepting incoming connections. */
+ pthread_t tcp_acpt_thread;
+#endif
+
+} limiter_t;
+
+#endif