/* 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 #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 "bsd_queue.h" #include "config.h" #include "drl_state.h" #include "common_accounting.h" #include "standard.h" #include "samplehold.h" #include "simple.h" #include "multipleinterval.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 effective global rate limit. Can be lower than the nominal global * rate limit due to the failure of one or more peers. */ uint32_t effective_limit; /** The local rate limit. */ uint32_t locallimit; /** Pointer to the identity's parent in the HTB hierarchy. */ struct identity *parent; /** For sets, indicates the parent should be 0x10. Meaningless for machines. */ int independent; /** Array of the leaves that are limited by this identity. Points into the * leaves array for the identity's instance. */ struct leaf **leaves; /** The number of leaves for which this identity is responsible. */ int leaf_count; /** 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)*/ 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; double total_weight; /** 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; /** Keeps track of the state of FPS dampening for this identity. */ enum dampenings dampen_state; /* GRD */ /** GRD drop probability information. */ double drop_prob; /** GRD previous drop probability information. */ double last_drop_prob; /* 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 *); #ifdef SHADOW_ACCTING common_accounting_t shadow_common; void *shadow_table; double localweight_copy; double last_localweight_copy; enum dampenings dampen_state_copy; #endif /* Scheduling bookkeeping. */ /** Scheduling unit that tells the limiter when to execute the main loop.*/ struct ident_action *loop_action; /** Scheduling unit that tells the limiter when to communicate.*/ struct ident_action *comm_action; /** The number of limiter ticks that should pass before this identity should * be scheduled to execute its main estimate/allocate/enforce loop. */ uint32_t mainloop_intervals; /** The number of limiter ticks that should pass before this identity should * be scheduled for communication. */ uint32_t communication_intervals; } identity_t; enum identity_actions { ACTION_MAINLOOP = 1, ACTION_COMMUNICATE = 2 }; typedef struct ident_action { struct identity *ident; enum identity_actions action; int valid; TAILQ_ENTRY(ident_action) calendar; } identity_action; /** * 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; /** GRD: The leaf's packet drop probability. */ double drop_prob; /** Only used for experimentation. */ int delay; } 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 policy; /** 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