+static void linkContainers (const char *a1, const char *a2, xbt_dict_t filter)
+{
+ //ignore loopback
+ if (strcmp (a1, "__loopback__") == 0 || strcmp (a2, "__loopback__") == 0)
+ return;
+
+ //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", a1, a2);
+ snprintf (aux2, INSTR_DEFAULT_STR_SIZE, "%s%s", a2, a1);
+ 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);
+
+ container_t a1_container = getContainerByName (a1);
+ type_t a1_type = a1_container->type;
+
+ container_t a2_container = getContainerByName (a2);
+ type_t a2_type = a2_container->type;
+
+ container_t container = findCommonFather (getRootContainer(), a1_container, a2_container);
+ xbt_assert (container != NULL, "common father not found");
+
+ //declare type
+ char link_typename[INSTR_DEFAULT_STR_SIZE];
+ snprintf (link_typename, INSTR_DEFAULT_STR_SIZE, "%s-%s", a1_type->name, a2_type->name);
+ type_t link_type = getLinkType (link_typename, container->type, a1_type, a2_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(), container, link_type, a1_container, "G", key);
+ new_pajeEndLink(SIMIX_get_clock(), container, link_type, a2_container, "G", key);
+}
+
+static void recursiveGraphExtraction (container_t container, xbt_dict_t filter)
+{
+ if (xbt_dict_length(container->children)){
+ xbt_dict_cursor_t cursor = NULL;
+ container_t child;
+ char *child_name;
+ //bottom-up recursion
+ xbt_dict_foreach(container->children, cursor, child_name, child) {
+ recursiveGraphExtraction (child, filter);
+ }
+
+ //let's get routes
+ xbt_dict_cursor_t cursor1 = NULL, cursor2 = NULL;
+ container_t child1, child2;
+ const char *child_name1, *child_name2;
+
+ xbt_dict_foreach(container->children, cursor1, child_name1, child1) {
+ xbt_dict_foreach(container->children, cursor2, child_name2, child2) {
+ if ((child1->kind == INSTR_HOST || child1->kind == INSTR_ROUTER) &&
+ (child2->kind == INSTR_HOST || child2->kind == INSTR_ROUTER)){
+
+ //getting route
+ xbt_dynar_t route = NULL;
+ xbt_ex_t exception;
+ TRY {
+ route = global_routing->get_route (child_name1, child_name2);
+ }CATCH(exception) {
+ //no route between them, that's possible
+ continue;
+ }
+
+ //link the route members
+ unsigned int cpt;
+ void *link;
+ char *previous_entity_name = (char*)child_name1;
+ xbt_dynar_foreach (route, cpt, link) {
+ char *link_name = ((link_CM02_t)link)->lmm_resource.generic_resource.name;
+ linkContainers (previous_entity_name, link_name, filter);
+ previous_entity_name = link_name;
+ }
+ linkContainers (previous_entity_name, child_name2, filter);
+ }else if (child1->kind == INSTR_AS &&
+ child2->kind == INSTR_AS &&
+ strcmp(child_name1, child_name2) != 0){
+
+ //getting route
+ routing_component_t root = global_routing->root;
+ route_extended_t route = NULL;
+ xbt_ex_t exception;
+ TRY {
+ route = root->get_route (root, child_name1, child_name2);
+ }CATCH(exception) {
+ //no route between them, that's possible
+ continue;
+ }
+ xbt_assert(route!=NULL,
+ "there is no ASroute between %s and %s", child_name1, child_name2);
+ unsigned int cpt;
+ void *link;
+ char *previous_entity_name = 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;
+ linkContainers (previous_entity_name, link_name, filter);
+ previous_entity_name = link_name;
+ }
+ linkContainers (previous_entity_name, route->dst_gateway, filter);
+ }
+ }
+ }
+ }
+}
+
+/*
+ * Callbacks
+ */