X-Git-Url: http://git.onelab.eu/?p=distributedratelimiting.git;a=blobdiff_plain;f=drl%2Fulogd_DRL.c;h=170ab4375ea7e122ce901ec224882f9ebcd51332;hp=e24b41cc1b3d43f3c2bd9c3bed5685a131442981;hb=3cc87c8471668009b3426013fded8c6ec5a382da;hpb=c9d6255f0c06ee41eb2c06a5f74a957ec7be3223 diff --git a/drl/ulogd_DRL.c b/drl/ulogd_DRL.c index e24b41c..170ab43 100644 --- a/drl/ulogd_DRL.c +++ b/drl/ulogd_DRL.c @@ -124,8 +124,16 @@ * Add the config options for DRL. */ -static config_entry_t enforce_on = { +static config_entry_t create_htb = { .next = NULL, + .key = "create_htb", + .type = CONFIG_TYPE_INT, + .options = CONFIG_OPT_NONE, + .u = { .value = 1 }, +}; + +static config_entry_t enforce_on = { + .next = &create_htb, .key = "enforce_on", .type = CONFIG_TYPE_INT, .options = CONFIG_OPT_NONE, @@ -697,6 +705,11 @@ static identity_t *new_identity(ident_config *config) { ident->comm.remote_nodes = comm_nodes; + if (!create_htb.u.value) { + ident->htb_node = config->htb_node; + ident->htb_parent = config->htb_parent; + } + return ident; } @@ -736,6 +749,17 @@ static int validate_config(ident_config *config) { return 1; } + if (!create_htb.u.value) { + if (config->htb_node < 0 || config->htb_parent < 0) { + printlog(LOG_CRITICAL, "When create_htb is disabled in ulogd.conf, an identity must specify the htb_node and htb_parent propertities in its configuration.\n"); + return 1; + } + } else { + if (config->htb_node > -1 || config->htb_parent > -1) { + printlog(LOG_WARN, "htb_node or htb_parent are configured but ignored because we're configured to create our own htb hierarchy.\n"); + } + } + /* Note: Parsing stage requires that each ident has at least one peer. */ return 0; } @@ -1080,6 +1104,14 @@ static int assign_htb_hierarchy(drl_instance_t *instance) { int i, j; int next_node = 0x100; + /* If we're not going to create our own htb hierarchy (for instance, + * if we're going to let PL's node manager do it for us), then we don't + * want this function to do anything. */ + if (!create_htb.u.value) { + printlog(LOG_DEBUG, "Skipping assign_htb_hierarchy becase ulogd.conf's create_htb set to 0.\n"); + return 0; + } + /* Chain machine nodes under 1:10. */ for (i = 0; i < instance->machine_count; ++i) { if (instance->machines[i]->parent == NULL) { @@ -1171,6 +1203,14 @@ static int create_htb_hierarchy(drl_instance_t *instance) { int i, j, k; uint64_t gigabit = 1024 * 1024 * 1024; + /* If we're not going to create our own htb hierarchy (for instance, + * if we're going to let PL's node manager do it for us), then we don't + * want this function to do anything. */ + if (!create_htb.u.value) { + printlog(LOG_DEBUG, "Skipping create_htb_hierarchy becase ulogd.conf's create_htb set to 0.\n"); + return 0; + } + /* Nuke the hierarchy. */ sprintf(cmd, "tc qdisc del dev eth0 root handle 1: htb"); execute_cmd(cmd); @@ -1695,32 +1735,6 @@ static void reconfig() { pthread_rwlock_unlock(&limiter.limiter_lock); } -static ulog_output_t drl_op = { - .name = "drl", - .output = &_output_drl, - .signal = NULL, /* This appears to be broken. Using my own handler. */ - .init = NULL, - .fini = NULL, -}; - -/* Tests the amount of time it takes to call reconfig(). */ -static void time_reconfig(int iterations) { - struct timeval start, end; - int i; - - gettimeofday(&start, NULL); - for (i = 0; i < iterations; ++i) { - reconfig(); - } - gettimeofday(&end, NULL); - - printf("%d reconfigs() took %d seconds and %d microseconds.\n", - iterations, end.tv_sec - start.tv_sec, end.tv_usec - start.tv_usec); - exit(0); - - // Seems to take about 85ms / iteration -} - static int stop_enforcement(drl_instance_t *instance) { char cmd[300]; int i; @@ -1799,13 +1813,9 @@ static void *signal_thread_func(void *args) { break; } } - } -/* register output plugin with ulogd */ -static void _drl_reg_op(void) -{ - ulog_output_t *op = &drl_op; +static int drl_plugin_init() { sigset_t signal_mask; sigemptyset(&signal_mask); @@ -1828,8 +1838,6 @@ static void _drl_reg_op(void) exit(EXIT_FAILURE); } - register_output(op); - /* start up the thread that will periodically estimate the * local rate and set the local limits * see estimate.c @@ -1846,6 +1854,43 @@ static void _drl_reg_op(void) printlog(LOG_CRITICAL, "--Switching enforcement on.--\n"); pthread_rwlock_unlock(&limiter.limiter_lock); } + + return 0; +} + +static ulog_output_t drl_op = { + .name = "drl", + .output = &_output_drl, + .signal = NULL, /* This appears to be broken. Using my own handler. */ + .init = &drl_plugin_init, + .fini = NULL, +}; + +#if 0 +/* Tests the amount of time it takes to call reconfig(). */ +static void time_reconfig(int iterations) { + struct timeval start, end; + int i; + + gettimeofday(&start, NULL); + for (i = 0; i < iterations; ++i) { + reconfig(); + } + gettimeofday(&end, NULL); + + printf("%d reconfigs() took %d seconds and %d microseconds.\n", + iterations, end.tv_sec - start.tv_sec, end.tv_usec - start.tv_usec); + exit(0); + + // Seems to take about 85ms / iteration +} +#endif + +/* register output plugin with ulogd */ +static void _drl_reg_op(void) +{ + ulog_output_t *op = &drl_op; + register_output(op); } void _init(void)