From d12ab8f1cd4ff135d692f7841360af70f0beb57b Mon Sep 17 00:00:00 2001 From: Kevin Webb Date: Tue, 14 Apr 2009 19:22:23 +0000 Subject: [PATCH] Added an 'independent' option for set identites that will put them under the root rather than the last machine node. Few small comment cleanups. --- drl/config.c | 9 +++++++++ drl/config.h | 3 +++ drl/ratetypes.h | 3 +++ drl/samplehold.c | 4 ++++ drl/samplehold.h | 8 +++++--- drl/ulogd_DRL.c | 39 ++++++++++++++------------------------- 6 files changed, 38 insertions(+), 28 deletions(-) diff --git a/drl/config.c b/drl/config.c index 65d8eb9..8b15cd2 100644 --- a/drl/config.c +++ b/drl/config.c @@ -107,6 +107,7 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { xmlChar *ewma; xmlChar *mainloop_intervals; xmlChar *communication_intervals; + xmlChar *independent; xmlNodePtr fields = ident->children; ident_peer *current = NULL; @@ -206,6 +207,14 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { xmlFree(communication_intervals); } + independent = xmlGetProp(ident, (const xmlChar *) "independent"); + if (independent == NULL) { + common->independent = 0; + } else { + common->independent = atoi((const char *) independent); + xmlFree(independent); + } + while (fields != NULL) { if((!xmlStrcmp(fields->name, (const xmlChar *) "peer"))) { xmlChar *ip = xmlNodeListGetString(doc, fields->children, 1); diff --git a/drl/config.h b/drl/config.h index 82e6e1f..0b202c7 100644 --- a/drl/config.h +++ b/drl/config.h @@ -91,6 +91,9 @@ typedef struct ident_config { /** The number of peers. */ int peer_count; + /** If this is set, the node goes under the root rather than machine nodes. */ + int independent; + /** List of the identity's members (type IDENT_SET only). */ ident_member *members; diff --git a/drl/ratetypes.h b/drl/ratetypes.h index 319d071..dc7f6c9 100644 --- a/drl/ratetypes.h +++ b/drl/ratetypes.h @@ -42,6 +42,9 @@ typedef struct identity { /** 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; diff --git a/drl/samplehold.c b/drl/samplehold.c index f98e5df..9a30995 100644 --- a/drl/samplehold.c +++ b/drl/samplehold.c @@ -379,6 +379,10 @@ void sampled_table_update_flows(sampled_flow_table table, struct timeval now, do } } + if (table->common->num_flows > 0) { + table->common->avg_rate = table->common->rate / table->common->num_flows; + } + table->common->max_flow_rate = largest_rate; } diff --git a/drl/samplehold.h b/drl/samplehold.h index 6c992fd..7e51623 100644 --- a/drl/samplehold.h +++ b/drl/samplehold.h @@ -30,9 +30,11 @@ #define RANDOM_GRANULARITY (1000) -// FIXME: In reality, you probably don't want this higher than 5 -//#define SAMPLEHOLD_PERCENTAGE (5) -#define SAMPLEHOLD_PERCENTAGE (10) +/* For simple S&H testing. */ +//#define SAMPLEHOLD_PERCENTAGE (20) +//#define SAMPLEHOLD_OVERFACTOR (5) + +#define SAMPLEHOLD_PERCENTAGE (5) #define SAMPLEHOLD_OVERFACTOR (10) #define SAMPLEHOLD_BONUS_FACTOR (1.05) diff --git a/drl/ulogd_DRL.c b/drl/ulogd_DRL.c index f785d30..79cb4ef 100644 --- a/drl/ulogd_DRL.c +++ b/drl/ulogd_DRL.c @@ -586,6 +586,7 @@ static identity_t *new_identity(ident_config *config) { ident->ewma_weight = pow(ident->fixed_ewma_weight, (limiter.estintms/1000.0) * config->mainloop_intervals); ident->parent = NULL; + ident->independent = config->independent; pthread_mutex_init(&ident->table_mutex, NULL); switch (config->accounting) { @@ -763,11 +764,17 @@ static int validate_configs(parsed_configs configs, drl_instance_t *instance) { return EINVAL; } + if (mlist->independent) { + printlog(LOG_CRITICAL, "Makes no sense to have independent machine node - setting independent to false.\n"); + mlist->independent = 0; + } + mlist = mlist->next; } instance->sets = malloc(configs.set_count * sizeof(identity_t *)); if (instance->sets == NULL) { + printlog(LOG_CRITICAL, "Not enough memory to allocate set identity collection.\n"); return ENOMEM; } @@ -801,6 +808,7 @@ static int validate_configs(parsed_configs configs, drl_instance_t *instance) { instance->sets[i] = new_identity(slist); if (instance->sets[i] == NULL) { + printlog(LOG_CRITICAL, "Not enough memory to allocate set identity.\n"); return ENOMEM; } @@ -817,10 +825,12 @@ static int validate_configs(parsed_configs configs, drl_instance_t *instance) { child_leaf = map_search(instance->leaf_map, &members->value, sizeof(members->value)); if (child_leaf == NULL) { + printlog(LOG_CRITICAL, "xid: child leaf not found.\n"); return EINVAL; } if (child_leaf->parent != NULL) { /* Error - This leaf already has a parent. */ + printlog(LOG_CRITICAL, "xid: child already has a parent.\n"); return EINVAL; } child_leaf->parent = instance->sets[i]; @@ -829,10 +839,12 @@ static int validate_configs(parsed_configs configs, drl_instance_t *instance) { child_ident = map_search(instance->ident_map, &members->value, sizeof(members->value)); if (child_ident == NULL) { + printlog(LOG_CRITICAL, "guid: child identity not found.\n"); return EINVAL; } if (child_ident->parent != NULL) { /* Error - This identity already has a parent. */ + printlog(LOG_CRITICAL, "guid: child identity already has a parent.\n"); return EINVAL; } child_ident->parent = instance->sets[i]; @@ -987,7 +999,7 @@ static int init_identities(parsed_configs configs, drl_instance_t *instance) { identity_action *loop_action; identity_action *comm_action; - if (instance->sets[i]->parent == NULL) { + if (instance->sets[i]->parent == NULL && instance->sets[i]->independent == 0) { instance->sets[i]->parent = instance->last_machine; } @@ -1073,6 +1085,7 @@ static int assign_htb_hierarchy(drl_instance_t *instance) { * already there. */ for (j = (instance->set_count - 1); j >= 0; --j) { if (instance->sets[j]->parent == NULL) { + /* Independent node - goes under 0x10 away from machine nodes. */ instance->sets[j]->htb_parent = 0x10; } else { instance->sets[j]->htb_parent = instance->sets[j]->parent->htb_node; @@ -1252,28 +1265,6 @@ static int create_htb_hierarchy(drl_instance_t *instance) { } } -#if 0 -#ifdef DELAY40MS - /* Only for artificial delay testing. */ - sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:1000 handle 1000 pfifo"); - execute_cmd(cmd); - - sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:1000 handle 1000 netem loss 0 delay 40ms"); - execute_cmd(cmd); - sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:11f9 handle 11f9 pfifo"); - execute_cmd(cmd); - - sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:11f9 handle 11f9 netem loss 0 delay 40ms"); - execute_cmd(cmd); - sprintf(cmd, "/sbin/tc qdisc del dev eth0 parent 1:11fa handle 11fa pfifo"); - execute_cmd(cmd); - - sprintf(cmd, "/sbin/tc qdisc replace dev eth0 parent 1:11fa handle 11fa netem loss 0 delay 40ms"); - execute_cmd(cmd); - /* End delay testing */ -#endif -#endif - return 0; } @@ -1457,7 +1448,6 @@ static int init_drl(void) { free_ident_list(configs.machines); free_ident_list(configs.sets); - /* Debugging - FIXME: remove this? */ print_instance(&limiter.stable_instance); switch (limiter.policy) { @@ -1545,7 +1535,6 @@ static void reconfig() { free_ident_list(configs.machines); free_ident_list(configs.sets); - /* Debugging - FIXME: remove this? */ print_instance(&limiter.new_instance); /* Lock */ -- 2.43.0