X-Git-Url: http://info.iut-bm.univ-fcomte.fr/pub/gitweb/simgrid.git/blobdiff_plain/c32eeb962e9c6905fc069434aa0ee992fe40791d..fec43de0a32ebea77563d441cdf9b888667da722:/src/bindings/lua/lua_console.c diff --git a/src/bindings/lua/lua_console.c b/src/bindings/lua/lua_console.c index 7cb7a97d42..1e8880fff1 100644 --- a/src/bindings/lua/lua_console.c +++ b/src/bindings/lua/lua_console.c @@ -22,7 +22,7 @@ static xbt_dynar_t as_list_d; static void create_AS(const char *id, const char *mode) { - surf_AS_new(id, mode); + routing_AS_init(id, mode); } /** @@ -31,9 +31,8 @@ static void create_AS(const char *id, const char *mode) static void create_host(const char *id, double power_peak, double power_sc, const char *power_tr,int core,int state_init, - const char *state_tr) + const char *state_tr,xbt_dict_t properties) { - double power_scale = 1.0; int core_nb = 1; //default value tmgr_trace_t power_trace = NULL; @@ -55,11 +54,10 @@ static void create_host(const char *id, double power_peak, double power_sc, state_trace = tmgr_trace_new(state_tr); else state_trace = tmgr_trace_new(""); - current_property_set = xbt_dict_new(); + surf_host_create_resource(xbt_strdup(id), power_peak, power_scale, power_trace, core_nb, state_initial, state_trace, - current_property_set); - + properties); } /** @@ -101,7 +99,6 @@ static void create_link(const char *name, st_trace, policy_initial_link, xbt_dict_new()); } - /* *create host resource via workstation_ptask_L07 model [for SimDag] */ @@ -127,11 +124,11 @@ static void create_host_wsL07(const char *id, double power_peak, state_trace = tmgr_trace_new(state_tr); else state_trace = tmgr_trace_new(""); - current_property_set = xbt_dict_new(); + surf_wsL07_host_create_resource(xbt_strdup(id), power_peak, power_scale, power_trace, state_initial, state_trace, current_property_set); - + current_property_set = NULL; } /** @@ -177,7 +174,7 @@ static void create_link_wsL07(const char *name, /* - * init AS + * Append new AS to the Platform */ static int AS_new(lua_State * L) @@ -210,11 +207,57 @@ static int AS_new(lua_State * L) AS->host_list_d = xbt_dynar_new(sizeof(p_host_attr),&xbt_free_ref); AS->link_list_d = xbt_dynar_new(sizeof(p_link_attr),&xbt_free_ref); AS->route_list_d = xbt_dynar_new(sizeof(p_route_attr),&xbt_free_ref); + AS->router_list_d = xbt_dynar_new(sizeof(p_router_attr),&xbt_free_ref); + AS->sub_as_list_id = xbt_dynar_new(sizeof(p_AS_attr),&xbt_free_ref); xbt_dynar_push(as_list_d, &AS); return 0; } +/** + * add sub AS to the Parent AS + */ +static int AS_add(lua_State *L) +{ + unsigned int i; + p_AS_attr AS; + p_AS_attr super_as,p_as; + const char *super_AS_id; + const char *sub_AS_id = NULL; + const char *sub_AS_routing= NULL; + if(lua_istable(L, -1)) + { + lua_pushstring(L, "AS"); + lua_gettable(L, -2); + super_AS_id = lua_tostring(L, -1); + lua_pop(L,1); + + lua_pushstring(L, "id"); + lua_gettable(L, -2); + sub_AS_id = lua_tostring(L, -1); + lua_pop(L,1); + + } + + xbt_dynar_foreach(as_list_d, i, p_as){ + if (p_as->id == super_AS_id){ + super_as = p_as; + break; + } + } + AS = malloc(sizeof(AS_attr)); + AS->id = sub_AS_id; + AS->mode = sub_AS_routing; + AS->host_list_d = xbt_dynar_new(sizeof(p_host_attr),&xbt_free_ref); + AS->link_list_d = xbt_dynar_new(sizeof(p_link_attr),&xbt_free_ref); + AS->route_list_d = xbt_dynar_new(sizeof(p_route_attr),&xbt_free_ref); + AS->sub_as_list_id = xbt_dynar_new(sizeof(p_AS_attr),&xbt_free_ref); + xbt_dynar_push(super_as->sub_as_list_id, &AS); + + return 0; +} + + /* * add new host to platform hosts list */ @@ -305,13 +348,14 @@ static int Host_new(lua_State * L) host->state_initial = state_initial; host->state_trace = state_trace; host->function = NULL; + host->properties = xbt_dict_new(); xbt_dynar_push(current_as->host_list_d, &host); return 0; } /** - * add link to platform links list + * add link to AS links list */ static int Link_new(lua_State * L) // (id,bandwidth,latency) { @@ -416,7 +460,7 @@ static int Link_new(lua_State * L) // (id,bandwidth,latency) } /** - * add route to platform routes list + * add route to AS routes list */ static int Route_new(lua_State * L) // (src_id,dest_id,links_number,link_table) { @@ -428,7 +472,7 @@ static int Route_new(lua_State * L) // (src_id,dest_id,links_number,link_tab p_route_attr route = malloc(sizeof(route_attr)); - if (!lua_istable(L, 3)) { // if Route.new is declared as an indexed table (FIXME : we check the third arg if it's not a table) + 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"); @@ -476,18 +520,27 @@ static int Route_new(lua_State * L) // (src_id,dest_id,links_number,link_tab 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 - //const char* link_id; - route->src_id = luaL_checkstring(L, 1); - route->dest_id = luaL_checkstring(L, 2); + 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, 3) != 0) + while (lua_next(L, 4) != 0) { link_id = lua_tostring(L, -1); xbt_dynar_push(route->links_id, &link_id); @@ -495,15 +548,55 @@ static int Route_new(lua_State * L) // (src_id,dest_id,links_number,link_tab 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; + 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; + +} + /** * set function to process */ @@ -511,22 +604,22 @@ static int Host_set_function(lua_State * L) //(host,function,nb_args,list_ar { p_AS_attr p_as; p_host_attr p_host; - const char *host; - const char *function; + unsigned int i,j; + const char *host_id ; + const char *function_id; const char *args; char * tmp_arg; - unsigned int i,j; if (lua_istable(L, -1)) { // get Host id lua_pushstring(L, "host"); lua_gettable(L, -2); - host = lua_tostring(L, -1); + host_id = lua_tostring(L, -1); lua_pop(L, 1); // get Function Name lua_pushstring(L, "fct"); lua_gettable(L, -2); - function = lua_tostring(L, -1); + function_id = lua_tostring(L, -1); lua_pop(L, 1); //get args lua_pushstring(L,"args"); @@ -543,8 +636,8 @@ static int Host_set_function(lua_State * L) //(host,function,nb_args,list_ar xbt_dynar_foreach(as_list_d, i, p_as) { xbt_dynar_foreach(p_as->host_list_d, j, p_host) { - if (p_host->id == host) { - p_host->function = function; + if (p_host->id == host_id) { + p_host->function = function_id; p_host->args_list = xbt_dynar_new(sizeof(char *), &xbt_free_ref); // split & fill the args list tmp_arg = strtok((char*)args,","); @@ -556,9 +649,46 @@ static int Host_set_function(lua_State * L) //(host,function,nb_args,list_ar } } } - XBT_ERROR("Host : %s Not Found !!", host); + XBT_ERROR("Host : %s Not Found !!", host_id); return 1; +} + +static int Host_set_property(lua_State* L) +{ + p_AS_attr p_as; + p_host_attr p_host; + unsigned int i,j; + const char* host_id =""; + const char* prop_id = ""; + const char* prop_value = ""; + if (lua_istable(L, -1)) { + // get Host id + lua_pushstring(L, "host"); + lua_gettable(L, -2); + host_id = lua_tostring(L, -1); + lua_pop(L, 1); + // get Function Name + lua_pushstring(L, "prop_id"); + lua_gettable(L, -2); + prop_id = lua_tostring(L, -1); + lua_pop(L, 1); + //get args + lua_pushstring(L,"prop_value"); + lua_gettable(L, -2); + prop_value = lua_tostring(L,-1); + lua_pop(L, 1); + } + xbt_dynar_foreach(as_list_d, i, p_as) + { + xbt_dynar_foreach(p_as->host_list_d, j, p_host) { + if (p_host->id == host_id) { + xbt_dict_set(p_host->properties, prop_id, xbt_strdup(prop_value), free); + } + } + } + return 1; + } /* * surf parse bypass platform @@ -582,9 +712,11 @@ static int surf_parse_bypass_platform() xbt_dynar_foreach(p_as->host_list_d, j, p_host){ create_host(p_host->id, p_host->power_peak, p_host->power_scale, p_host->power_trace, p_host->core, p_host->state_initial, - p_host->state_trace); - //add to routing model host list - surf_route_add_host((char *) p_host->id); + p_host->state_trace, p_host->properties); + + + //add to routing model host list + surf_route_add_host((char *) p_host->id); } // add associated Links xbt_dynar_foreach(p_as->link_list_d, j, p_link){ @@ -600,7 +732,7 @@ static int surf_parse_bypass_platform() } // Finalize AS - surf_AS_finalize(p_as->id); + routing_AS_end(p_as->id); } // add traces @@ -619,9 +751,8 @@ static int surf_parse_bypass_platform() static int surf_wsL07_parse_bypass_platform() { - unsigned int i,j; - p_AS_attr p_as; + p_AS_attr p_as, p_sub_as; p_host_attr p_host; p_link_attr p_link; p_route_attr p_route; @@ -630,7 +761,13 @@ static int surf_wsL07_parse_bypass_platform() { // Init AS create_AS(p_as->id, p_as->mode); + + // add Sub AS + // Add Hosts + xbt_dynar_foreach(p_as->sub_as_list_id, j, p_sub_as) { + //... + } xbt_dynar_foreach(p_as->host_list_d, j, p_host) { create_host_wsL07(p_host->id, p_host->power_peak, p_host->power_scale, p_host->power_trace, p_host->state_initial, @@ -652,7 +789,7 @@ static int surf_wsL07_parse_bypass_platform() } /* */ // Finalize AS - surf_AS_finalize(p_as->id); + routing_AS_end(p_as->id); } // add traces surf_wsL07_add_traces(); @@ -705,6 +842,11 @@ int console_set_function(lua_State *L) return Host_set_function(L); } +int console_host_set_property(lua_State *L) +{ + return Host_set_property(L); +} + int console_parse_platform() { return surf_parse_bypass_platform();