+ if (root == a1) return root;
+
+ xbt_dict_cursor_t cursor = NULL;
+ container_t child;
+ char *child_name;
+ xbt_dict_foreach(root->children, cursor, child_name, child) {
+ if (findChild (child, a1)) return child;
+ }
+ return NULL;
+}
+
+static container_t findCommonFather (container_t root, container_t a1, container_t a2)
+{
+ if (a1->father == a2->father) return a1->father;
+
+ xbt_dict_cursor_t cursor = NULL;
+ container_t child;
+ char *child_name;
+ container_t a1_try = NULL;
+ container_t a2_try = NULL;
+ xbt_dict_foreach(root->children, cursor, child_name, child) {
+ a1_try = findChild (child, a1);
+ a2_try = findChild (child, a2);
+ if (a1_try && a2_try) return child;
+ }
+ return NULL;
+}
+
+static void linkContainers (container_t father, container_t src, container_t dst, xbt_dict_t filter)
+{
+ //ignore loopback
+ if (strcmp (src->name, "__loopback__") == 0 || strcmp (dst->name, "__loopback__") == 0)
+ return;
+
+ if (filter != NULL){
+ //check if we already register this pair (we only need one direction)
+ char aux1[INSTR_DEFAULT_STR_SIZE], aux2[INSTR_DEFAULT_STR_SIZE];
+ snprintf (aux1, INSTR_DEFAULT_STR_SIZE, "%s%s", src->name, dst->name);
+ snprintf (aux2, INSTR_DEFAULT_STR_SIZE, "%s%s", dst->name, src->name);
+ if (xbt_dict_get_or_null (filter, aux1)) return;
+ if (xbt_dict_get_or_null (filter, aux2)) return;
+
+ //ok, not found, register it
+ xbt_dict_set (filter, aux1, xbt_strdup ("1"), xbt_free);
+ xbt_dict_set (filter, aux2, xbt_strdup ("1"), xbt_free);
+ }
+
+ //declare type
+ char link_typename[INSTR_DEFAULT_STR_SIZE];
+ snprintf (link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s", src->type->name, dst->type->name);
+ type_t link_type = getLinkType (link_typename, father->type, src->type, dst->type);
+
+ //register EDGE types for triva configuration
+ xbt_dict_set (trivaEdgeTypes, link_type->name, xbt_strdup("1"), xbt_free);
+
+ //create the link
+ static long long counter = 0;
+ char key[INSTR_DEFAULT_STR_SIZE];
+ snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
+ new_pajeStartLink(SIMIX_get_clock(), father, link_type, src, "G", key);
+ new_pajeEndLink(SIMIX_get_clock(), father, link_type, dst, "G", key);
+}
+
+static void recursiveGraphExtraction (routing_component_t rc, container_t container, xbt_dict_t filter)
+{
+ if (xbt_dict_length (rc->routing_sons)){
+ xbt_dict_cursor_t cursor = NULL;
+ routing_component_t rc_son;
+ char *child_name;
+ //bottom-up recursion
+ xbt_dict_foreach(rc->routing_sons, cursor, child_name, rc_son) {
+ container_t child_container = xbt_dict_get (container->children, rc_son->name);
+ recursiveGraphExtraction (rc_son, child_container, filter);
+ }
+ }
+
+ //let's get routes
+ xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
+ container_t child1, child2;
+ const char *child1_name, *child2_name;
+ xbt_dict_foreach(container->children, cursor1, child1_name, child1) {
+ if (child1->kind == INSTR_LINK) continue;
+ xbt_dict_foreach(container->children, cursor2, child2_name, child2) {
+ if (child2->kind == INSTR_LINK) continue;
+
+ if ((child1->kind == INSTR_HOST || child1->kind == INSTR_ROUTER) &&
+ (child2->kind == INSTR_HOST || child2->kind == INSTR_ROUTER) &&
+ strcmp (child1_name, child2_name) != 0){
+
+ xbt_dynar_t route = global_routing->get_route (child1_name, child2_name);
+ unsigned int cpt;
+ void *link;
+ container_t previous = child1;
+ xbt_dynar_foreach (route, cpt, link) {
+ char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
+ container_t current = getContainerByName(link_name);
+ linkContainers(container, previous, current, filter);
+ previous = current;
+ }
+ linkContainers(container, previous, child2, filter);
+
+ }else if (child1->kind == INSTR_AS &&
+ child2->kind == INSTR_AS &&
+ strcmp(child1_name, child2_name) != 0){
+
+ route_extended_t route = rc->get_route (rc, child1_name, child2_name);
+ unsigned int cpt;
+ void *link;
+ container_t previous = getContainerByName(route->src_gateway);
+ xbt_dynar_foreach (route->generic_route.link_list, cpt, link) {
+ char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
+ container_t current = getContainerByName(link_name);
+ linkContainers (container, previous, current, filter);
+ previous = current;
+ }
+ container_t last = getContainerByName(route->dst_gateway);
+ linkContainers (container, previous, last, filter);
+ }
+ }
+ }