+ surfxml_add_callback(ETag_surfxml_platform_cb_list, &instr_routing_parse_end_platform);
+}
+
+static long long int newContainedId ()
+{
+ static long long counter = 0;
+ return counter++;
+}
+
+static container_t newContainer (const char *name, e_container_types kind, container_t father)
+{
+ long long int counter = newContainedId();
+ char id_str[INSTR_DEFAULT_STR_SIZE];
+ snprintf (id_str, INSTR_DEFAULT_STR_SIZE, "%lld", counter);
+
+ container_t new = xbt_new0(s_container_t, 1);
+ new->name = xbt_strdup (name); // name of the container
+ new->id = xbt_strdup (id_str); // id (or alias) of the container
+ new->father = father;
+ // father of this container
+ if (new->father){
+ new->father = xbt_dynar_get_ptr(currentContainer, xbt_dynar_length(currentContainer)-1);
+ }else{
+ new->father = NULL;
+ }
+ // level depends on level of father
+ if (new->father){
+ new->level = new->father->level+1;
+ }else{
+ new->level = 0;
+ }
+ // type definition (method depends on kind of this new container)
+ new->kind = kind;
+ if (new->kind == INSTR_AS){
+ //if this container is of an AS, its type name depends on its level
+ char as_typename[INSTR_DEFAULT_STR_SIZE];
+ snprintf (as_typename, INSTR_DEFAULT_STR_SIZE, "L%d", new->level);
+ if (new->father){
+ new->type = getContainerType (as_typename, new->father->type);
+ }else{
+ new->type = getContainerType ("0", NULL);
+ }
+ }else{
+ //otherwise, the name is its kind
+ switch (new->kind){
+ case INSTR_HOST: new->type = getContainerType ("HOST", new->father->type); break;
+ case INSTR_LINK: new->type = getContainerType ("LINK", new->father->type); break;
+ case INSTR_ROUTER: new->type = getContainerType ("ROUTER", new->father->type); break;
+ default: xbt_die ("Congratulations, you have found a bug on newContainer function of instr_routing.c"); break;
+ }
+ }
+ new->children = xbt_dict_new();
+ if (new->father){
+ xbt_dict_set(new->father->children, new->name, new, NULL);
+ pajeCreateContainer (0, new->id, new->type->id, new->father->id, new->name);
+ }
+
+ //register hosts, routers, links containers
+ if (new->kind == INSTR_HOST || new->kind == INSTR_LINK || new->kind == INSTR_ROUTER) {
+ xbt_dict_set (allContainers, new->name, new, NULL);
+ }
+
+ //register the host container types
+ if (new->kind == INSTR_HOST){
+ xbt_dynar_push_as (allHostTypes, type_t, new->type);
+ }
+
+ //register the link container types
+ if (new->kind == INSTR_LINK){
+ xbt_dynar_push_as(allLinkTypes, type_t, new->type);
+ }
+ return new;
+}
+
+static container_t findChild (container_t root, container_t a1)
+{
+ 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 (const char *a1, const char *a2)
+{
+ //ignore loopback
+ if (strcmp (a1, "__loopback__") == 0 || strcmp (a2, "__loopback__") == 0)
+ return;
+
+ container_t a1_container = ((container_t)xbt_dict_get (allContainers, a1));
+ type_t a1_type = a1_container->type;
+
+ container_t a2_container = ((container_t)xbt_dict_get (allContainers, a2));
+ type_t a2_type = a2_container->type;
+
+ container_t container = findCommonFather (rootContainer, a1_container, a2_container);
+ xbt_assert0 (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);
+
+ //create the link
+ static long long counter = 0;
+ char key[INSTR_DEFAULT_STR_SIZE];
+ snprintf (key, INSTR_DEFAULT_STR_SIZE, "%lld", counter++);
+ pajeStartLink(SIMIX_get_clock(), link_type->id, container->id, "G", a1_container->id, key);
+ pajeEndLink(SIMIX_get_clock(), link_type->id, container->id, "G", a2_container->id, key);