X-Git-Url: http://git.onelab.eu/?a=blobdiff_plain;f=drl%2Fconfig.c;h=23ee36ee2c337c1f3fe594465c3ac2fe64a7fe29;hb=ef996ac4c4bd1aaaf5ccaba5012a799527a7a372;hp=42f4472aa99e1121d1ae97c2436463812c3973ca;hpb=17fba5cc2628df108d09ab4abbbd4b4a7437e7eb;p=distributedratelimiting.git diff --git a/drl/config.c b/drl/config.c index 42f4472..23ee36e 100644 --- a/drl/config.c +++ b/drl/config.c @@ -101,19 +101,74 @@ 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; xmlChar *commfabric; xmlChar *branch; + xmlChar *membership; + xmlChar *failure_behavior; xmlChar *accounting; xmlChar *ewma; xmlChar *mainloop_intervals; xmlChar *communication_intervals; xmlChar *independent; + xmlChar *htb_node; + xmlChar *htb_parent; xmlNodePtr fields = ident->children; ident_peer *current = NULL; + /* The struct has been memsetted to 0, this is just to be safe. */ +#ifdef BUILD_ZOOKEEPER + common->zk_host = NULL; +#endif + common->peers = NULL; + common->members = NULL; + common->next = NULL; + /* Make sure no required fields are missing. */ id = xmlGetProp(ident, (const xmlChar *) "id"); if (id == NULL) { @@ -150,7 +205,7 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { xmlFree(commfabric); } - /* Only care about branching factor if we're using gossip. */ + /* Only care about branching factor and failure detector if we're using gossip. */ if (common->commfabric == COMM_GOSSIP) { branch = xmlGetProp(ident, (const xmlChar *) "branch"); if (branch == NULL) { @@ -160,6 +215,46 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { common->branch = atoi((const char *) branch); xmlFree(branch); } + + membership = xmlGetProp(ident, (const xmlChar *) "membership"); + if (membership == NULL) { + printlog(LOG_CRITICAL, "Ident missing membership protocol selection.\n"); + return EINVAL; + } else { + if (!xmlStrcmp(membership, (const xmlChar *) "SWIM")) { + common->membership = SWIM; + } else if (!xmlStrcmp(membership, (const xmlChar *) "ZOOKEEPER")) { +#ifdef BUILD_ZOOKEEPER + common->membership = ZOOKEEPER; +#else + printlog(LOG_CRITICAL, "Zookeeper requested, but support not compiled into DRL at configure time.\n"); + xmlFree(membership); + return EINVAL; +#endif + } else { + printlog(LOG_CRITICAL, "Unknown/invalid gossip group membership protocol.\n"); + xmlFree(membership); + return EINVAL; + } + xmlFree(membership); + } + + failure_behavior = xmlGetProp(ident, (const xmlChar *) "failure_behavior"); + if (failure_behavior == NULL) { + printlog(LOG_CRITICAL, "Ident missing failure handling behavior.\n"); + return EINVAL; + } else { + if (!xmlStrcmp(failure_behavior, (const xmlChar *) "PANIC")) { + common->failure_behavior = PANIC; + } else if (!xmlStrcmp(failure_behavior, (const xmlChar *) "QUORUM")) { + common->failure_behavior = QUORUM; + } else { + printlog(LOG_CRITICAL, "Unknown/invalid gossip failure behavior policy.\n"); + xmlFree(failure_behavior); + return EINVAL; + } + xmlFree(failure_behavior); + } } accounting = xmlGetProp(ident, (const xmlChar *) "accounting"); @@ -218,6 +313,21 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { xmlFree(independent); } + htb_node = xmlGetProp(ident, (const xmlChar *) "htb_node"); + htb_parent = xmlGetProp(ident, (const xmlChar *) "htb_parent"); + if (htb_node == NULL) { + common->htb_node = -1; + } else { + sscanf((const char *)htb_node, "%x", &common->htb_node); + xmlFree(htb_node); + } + if (htb_parent == NULL) { + common->htb_parent = -1; + } else { + sscanf((const char *)htb_parent, "%x", &common->htb_parent); + xmlFree(htb_parent); + } + while (fields != NULL) { if((!xmlStrcmp(fields->name, (const xmlChar *) "peer"))) { xmlChar *ip = xmlNodeListGetString(doc, fields->children, 1); @@ -243,6 +353,16 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { current->next = NULL; } xmlFree(ip); + } else if ((!xmlStrcmp(fields->name, (const xmlChar *) "zkhost"))) { + xmlChar *host = xmlNodeListGetString(doc, fields->children, 1); + +#ifdef BUILD_ZOOKEEPER + common->zk_host = strdup((const char *) host); + if (common->zk_host == NULL) { + return ENOMEM; + } +#endif + xmlFree(host); } fields = fields->next; } @@ -252,6 +372,12 @@ static int parse_common(xmlDocPtr doc, xmlNodePtr ident, ident_config *common) { return EINVAL; } +#ifdef BUILD_ZOOKEEPER + if (common->membership == ZOOKEEPER && common->zk_host == NULL) { + printlog(LOG_CRITICAL, "Group membership protocol ZOOKEEPER requires a zkhost field.\n"); + return EINVAL; + } +#endif /* No errors. */ return 0; }