-/**
- * add route to AS routes list
- */
-static int Route_new(lua_State * L) // (src_id,dest_id,links_number,link_table)
-{
- const char* AS_id;
- unsigned int i;
- p_AS_attr p_as,current_as = NULL;
- const char *links;
- const char* link_id;
- p_route_attr route = malloc(sizeof(route_attr));
-
-
- if (!lua_istable(L, 4)) { // if Route.new is declared as an indexed table (FIXME : we check the third arg if it's not a table)
-
- //get AS_id
- lua_pushstring(L, "AS");
- lua_gettable(L, -2);
- AS_id = lua_tostring(L, -1);
- lua_pop(L, 1);
-
- xbt_dynar_foreach(as_list_d, i, p_as){
- if (p_as->id == AS_id){
- current_as = p_as;
- break;
- }
- }
-
- if (!current_as)
- {
- XBT_ERROR("addRoute: No AS_id :%s found",AS_id);
- return -2;
- }
- // get Source Value
- lua_pushstring(L, "src");
- lua_gettable(L, -2);
- route->src_id = lua_tostring(L, -1);
- lua_pop(L, 1);
-
- // get Destination Value
- lua_pushstring(L, "dest");
- lua_gettable(L, -2);
- route->dest_id = lua_tostring(L, -1);
- lua_pop(L, 1);
-
- // get Links Table (char* to be splited later)
- lua_pushstring(L, "links");
- lua_gettable(L, -2);
- links = lua_tostring(L, -1);
- lua_pop(L,1);
-
- route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
-
- char *tmp_links = xbt_strdup(links);
- link_id = strtok(tmp_links,","); //tmp_link = strtok((char*)links,",");
- while(link_id != NULL)
- {
- xbt_dynar_push(route->links_id, &link_id);
- link_id = strtok(NULL,","); //Alternatively, a null pointer may be specified, in which case the function continues scanning where a previous successful call to the function ended.
- }
- xbt_dynar_push(current_as->route_list_d, &route);
- return 0;
- }
- else { // Route.new is declared as a function
- AS_id = luaL_checkstring(L, 1);
- xbt_dynar_foreach(as_list_d, i, p_as){
- if (p_as->id == AS_id){
- current_as = p_as;
- break;
- }
- }
-
- if (!current_as)
- {
- XBT_ERROR("addRoute: No AS_id :%s found",AS_id);
- return -2;
- }
- route->src_id = luaL_checkstring(L, 2);
- route->dest_id = luaL_checkstring(L, 3);
- route->links_id = xbt_dynar_new(sizeof(char *), &xbt_free_ref);
- lua_pushnil(L);
- while (lua_next(L, 4) != 0)
- {
- link_id = lua_tostring(L, -1);
- xbt_dynar_push(route->links_id, &link_id);
- XBT_DEBUG("index = %f , Link_id = %s \n", lua_tonumber(L, -2),
- lua_tostring(L, -1));
- lua_pop(L, 1);
- }
- lua_pop(L, 1);
- //add route to platform's route list
- xbt_dynar_push(current_as->route_list_d, &route);
- return 0;
- }
-
- return -1;
-}
-/**
- * add Router to AS components
- */
-static int Router_new(lua_State* L)
-{
- p_router_attr router;
- const char* AS_id;
- unsigned int i;
- p_AS_attr p_as,current_as = NULL;
- const char* id;
- if (lua_istable(L, -1)) {
- // get AS id
- lua_pushstring(L, "AS");
- lua_gettable(L, -2);
- AS_id = lua_tostring(L, -1);
- lua_pop(L,1);
-
- lua_pushstring(L, "id");
- lua_gettable(L, -2);
- id = lua_tostring(L, -1);
- lua_pop(L,1);
- }
- xbt_dynar_foreach(as_list_d, i, p_as){
- if (p_as->id == AS_id){
- current_as = p_as;
- break;
- }
- }
-
- if (!current_as)
- {
- XBT_ERROR("No AS_id :%s found",AS_id);
- return -2;
- }
- router = malloc(sizeof(router_attr));
- router->id = id;
- xbt_dynar_push(current_as->router_list_d, &router);
- return 0;