X-Git-Url: http://git.onelab.eu/?p=distributedratelimiting.git;a=blobdiff_plain;f=drl%2Fconfig.c;fp=drl%2Fconfig.c;h=23ee36ee2c337c1f3fe594465c3ac2fe64a7fe29;hp=86d1ec4e023baa74a2bd68f989aa5ec4f336772b;hb=77e70ca3ac61f5a17ba5f0222ce205ff58c9a314;hpb=1e5f447c9fe1b7c9cdf675b3c595dcc57a12bc38 diff --git a/drl/config.c b/drl/config.c index 86d1ec4..23ee36e 100644 --- a/drl/config.c +++ b/drl/config.c @@ -101,6 +101,49 @@ int get_eligible_leaves(drl_instance_t *instance) { return 0; } +int parse_leaves(drl_instance_t *instance, char *leafstring) { + int count = 1; + int i; + char *comma = leafstring; + leaf_t *leaves = NULL; + map_handle leaf_map; + + while ((comma = strchr(comma, ',')) != NULL) { + count += 1; + comma++; + } + + leaf_map = allocate_map(); + if (leaf_map == NULL) { + return ENOMEM; + } + + leaves = malloc(count * sizeof(leaf_t)); + if (leaves == NULL) { + return ENOMEM; + } + memset(leaves, 0, count * sizeof(leaf_t)); + + comma = leafstring; + for (i = 0; i < count; ++i) { + leaves[i].xid = (uint32_t) strtol(comma, NULL, 16); + leaves[i].parent = NULL; + leaves[i].drop_prob = 0.0; + leaves[i].delay = 0; + + printlog(LOG_DEBUG, "Read leaf - hex: %x, dec: %d\n", leaves[i].xid, leaves[i].xid); + + comma = strchr(comma, ','); + comma++; + } + + instance->leaf_map = leaf_map; + instance->leaves = leaves; + instance->leaf_count = count; + + return 0; +} + static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { xmlChar *id; xmlChar *limit;