From 22b3e706eb926a52a50f895b3313e587a92ca0e5 Mon Sep 17 00:00:00 2001 From: Martin Quinson Date: Tue, 8 Nov 2011 11:27:02 +0100 Subject: [PATCH 1/1] Reimplement the lua console on top of sg_platf I admit it was too early to do that change since sg_platf is not quite fully separated from the XML parsing yet, but the cruft accumulates from everywhere, so I have to break stuff a bit to fix the overall picture. Yeah, the lua tests are not fixed yet. --- examples/lua/console/platform.lua | 76 +-- include/simgrid/platf.h | 6 +- src/bindings/lua/lua_console.c | 933 +++++++++--------------------- src/bindings/lua/simgrid_lua.c | 85 +-- src/bindings/lua/simgrid_lua.h | 65 +-- src/msg/environment.c | 4 +- src/surf/surf_routing.c | 2 +- 7 files changed, 350 insertions(+), 821 deletions(-) diff --git a/examples/lua/console/platform.lua b/examples/lua/console/platform.lua index 19ebf50e6c..60e66b9df0 100644 --- a/examples/lua/console/platform.lua +++ b/examples/lua/console/platform.lua @@ -1,45 +1,45 @@ - --create new routing model - --simgrid.AS.new(AS_id,AS_mode) - simgrid.AS.new{id="AS0",mode="Full"}; - --simgrid.Host.new(host_id,power) - simgrid.AS.addHost{AS="AS0",id="Tremblay",power=98095000}; - simgrid.AS.addHost{AS="AS0",id="Jupiter",power=76296000}; - simgrid.AS.addHost{AS="AS0",id="Fafard",power=76296000}; - simgrid.AS.addHost{AS="AS0",id="Ginette",power=48492000}; - simgrid.AS.addHost{AS="AS0",id="Bourassa",power=48492000}; - -- create Links - for i=10,0,-1 do - simgrid.AS.addLink{AS="AS0",id=i,bandwidth=252750+ i*768,latency=0.000270544+i*0.087}; - end - -- simgrid.Route.new(src_id,des_id,links_nb,links_list) - simgrid.AS.addRoute{AS="AS0",src="Tremblay",dest="Jupiter",links="1"}; - simgrid.AS.addRoute{AS="AS0",src="Tremblay",dest="Fafard",links="0,1,2,3,4,8"}; - simgrid.AS.addRoute{AS="AS0",src="Tremblay",dest="Ginette",links="3,4,5"}; - simgrid.AS.addRoute{AS="AS0",src="Tremblay",dest="Bourassa",links="0,1,3,2,4,6,7"}; +simgrid.platf.open(); - simgrid.AS.addRoute{AS="AS0",src="Jupiter",dest="Tremblay",links="1"}; - simgrid.AS.addRoute{AS="AS0",src="Jupiter",dest="Fafard",links="0,1,2,3,4,8,9"}; - simgrid.AS.addRoute{AS="AS0",src="Jupiter",dest="Ginette",links="3,4,5,9"}; - simgrid.AS.addRoute{AS="AS0",src="Jupiter",dest="Bourassa",links="0,1,2,3,4,6,7,9"}; +simgrid.platf.AS_open{id="AS0",mode="Full"}; + +simgrid.platf.host_new{id="Tremblay",power=98095000}; +simgrid.platf.host_new{id="Jupiter",power=76296000}; +simgrid.platf.host_new{id="Fafard",power=76296000}; +simgrid.platf.host_new{id="Ginette",power=48492000}; +simgrid.platf.host_new{id="Bourassa",power=48492000}; + +-- create Links +for i=10,0,-1 do + simgrid.platf.link_new{id=i,bandwidth=252750+ i*768,latency=0.000270544+i*0.087}; +end + +simgrid.platf.route_new{src="Tremblay",dest="Jupiter",links="1",symmetrical=0}; +simgrid.platf.route_new{src="Tremblay",dest="Fafard",links="0,1,2,3,4,8",symmetrical=0}; +simgrid.platf.route_new{src="Tremblay",dest="Ginette",links="3,4,5",symmetrical=0}; +simgrid.platf.route_new{src="Tremblay",dest="Bourassa",links="0,1,3,2,4,6,7",symmetrical=0}; + +simgrid.platf.route_new{src="Jupiter",dest="Tremblay",links="1",symmetrical=0}; +simgrid.platf.route_new{src="Jupiter",dest="Fafard",links="0,1,2,3,4,8,9",symmetrical=0}; +simgrid.platf.route_new{src="Jupiter",dest="Ginette",links="3,4,5,9",symmetrical=0}; +simgrid.platf.route_new{src="Jupiter",dest="Bourassa",links="0,1,2,3,4,6,7,9",symmetrical=0}; - simgrid.AS.addRoute{AS="AS0",src="Fafard",dest="Tremblay",links="0,1,2,3,4,8"}; - simgrid.AS.addRoute{AS="AS0",src="Fafard",dest="Jupiter",links="0,1,2,3,4,8,9"}; - simgrid.AS.addRoute{AS="AS0",src="Fafard",dest="Ginette",links="0,1,2,5,8"}; - simgrid.AS.addRoute{AS="AS0",src="Fafard",dest="Bourassa",links="6,7,8"}; +simgrid.platf.route_new{src="Fafard",dest="Tremblay",links="0,1,2,3,4,8",symmetrical=0}; +simgrid.platf.route_new{src="Fafard",dest="Jupiter",links="0,1,2,3,4,8,9",symmetrical=0}; +simgrid.platf.route_new{src="Fafard",dest="Ginette",links="0,1,2,5,8",symmetrical=0}; +simgrid.platf.route_new{src="Fafard",dest="Bourassa",links="6,7,8",symmetrical=0}; - simgrid.AS.addRoute{AS="AS0",src="Ginette",dest="Tremblay",links="3,4,5"}; - simgrid.AS.addRoute{AS="AS0",src="Ginette",dest="Jupiter",links="3,4,5,9"}; - simgrid.AS.addRoute{AS="AS0",src="Ginette",dest="Fafard",links="0,1,2,5,8"}; - simgrid.AS.addRoute{AS="AS0",src="Ginette",dest="Bourassa",links="0,1,2,5,6,7"}; +simgrid.platf.route_new{src="Ginette",dest="Tremblay",links="3,4,5",symmetrical=0}; +simgrid.platf.route_new{src="Ginette",dest="Jupiter",links="3,4,5,9",symmetrical=0}; +simgrid.platf.route_new{src="Ginette",dest="Fafard",links="0,1,2,5,8",symmetrical=0}; +simgrid.platf.route_new{src="Ginette",dest="Bourassa",links="0,1,2,5,6,7",symmetrical=0}; - simgrid.AS.addRoute{AS="AS0",src="Bourassa",dest="Tremblay",links="0,1,3,2,4,6,7"}; - simgrid.AS.addRoute{AS="AS0",src="Bourassa",dest="Jupiter",links="0,1,2,3,4,6,7,9"}; - simgrid.AS.addRoute{AS="AS0",src="Bourassa",dest="Fafard",links="6,7,8"}; - simgrid.AS.addRoute{AS="AS0",src="Bourassa",dest="Ginette",links="0,1,2,5,6,7"}; +simgrid.platf.route_new{src="Bourassa",dest="Tremblay",links="0,1,3,2,4,6,7",symmetrical=0}; +simgrid.platf.route_new{src="Bourassa",dest="Jupiter",links="0,1,2,3,4,6,7,9",symmetrical=0}; +simgrid.platf.route_new{src="Bourassa",dest="Fafard",links="6,7,8",symmetrical=0}; +simgrid.platf.route_new{src="Bourassa",dest="Ginette",links="0,1,2,5,6,7",symmetrical=0}; +simgrid.platf.AS_close(); + +simgrid.platf.close(); - --Save Platform - --simgrid.info("start registering platform"); - simgrid.msg_register_platform(); - --simgrid.info("platform registered"); diff --git a/include/simgrid/platf.h b/include/simgrid/platf.h index 69f1f66e63..e67f56d1f4 100644 --- a/include/simgrid/platf.h +++ b/include/simgrid/platf.h @@ -31,7 +31,7 @@ typedef enum { */ typedef struct { - char* V_host_id; //id + const char* V_host_id; //id double V_host_power_peak; //power int V_host_core; //core double V_host_power_scale; //availability @@ -48,7 +48,7 @@ typedef struct { } s_sg_platf_router_cbarg_t, *sg_platf_router_cbarg_t; typedef struct { - char* V_link_id; + const char* V_link_id; double V_link_bandwidth; tmgr_trace_t V_link_bandwidth_file; double V_link_latency; @@ -69,7 +69,7 @@ XBT_PUBLIC(void) sg_platf_new_AS_close(void); // That XBT_PUBLIC(void) sg_platf_new_host (sg_platf_host_cbarg_t host); // Add an host to the currently described AS XBT_PUBLIC(void) sg_platf_new_router(sg_platf_router_cbarg_t router); // Add a router to the currently described AS -XBT_PUBLIC(void) sg_platf_new_link(sg_platf_link_cbarg_t link); // Add a link to the currently described AS +XBT_PUBLIC(void) sg_platf_new_link (sg_platf_link_cbarg_t link); // Add a link to the currently described AS #endif /* SG_PLATF_H */ diff --git a/src/bindings/lua/lua_console.c b/src/bindings/lua/lua_console.c index b086e4bbbf..afa8a94f45 100644 --- a/src/bindings/lua/lua_console.c +++ b/src/bindings/lua/lua_console.c @@ -13,368 +13,155 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua_console, bindings, "Lua Bindings"); - -//AS List -static xbt_dynar_t as_list_d; - -/** - * create host resource via CPU model [for MSG] - */ - -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,xbt_dict_t properties) -{ - double power_scale = 1.0; - int core_nb = 1; //default value - tmgr_trace_t power_trace = NULL; - e_surf_resource_state_t state_initial; - tmgr_trace_t state_trace; - if (power_sc) // !=0 - power_scale = power_sc; - if (core) - core_nb = core; //default value - if (state_init == -1) - state_initial = SURF_RESOURCE_OFF; - else - state_initial = SURF_RESOURCE_ON; - if (power_tr) - power_trace = tmgr_trace_new(power_tr); - else - power_trace = tmgr_trace_new(""); - if (state_tr) - state_trace = tmgr_trace_new(state_tr); - else - state_trace = tmgr_trace_new(""); - - surf_host_create_resource(xbt_strdup(id), power_peak, power_scale, - power_trace, core_nb, state_initial, state_trace, - properties); +int console_open(lua_State *L) { + sg_platf_init(); + sg_platf_open(); + surf_parse_init_callbacks(); + return 0; } -/** - * create link resource via network model - */ -static void create_link(const char *name, - double bw_initial, const char *trace, - double lat_initial, const char *latency_trace, - int state_init, const char *state_trace, - int policy) -{ - tmgr_trace_t bw_trace; - tmgr_trace_t lat_trace; - e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON; - e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED; - tmgr_trace_t st_trace; - if (trace) - bw_trace = tmgr_trace_new(trace); - else - bw_trace = tmgr_trace_new(""); - - if (latency_trace) - lat_trace = tmgr_trace_new(latency_trace); - else - lat_trace = tmgr_trace_new(""); - - if (state_trace) - st_trace = tmgr_trace_new(state_trace); - else - st_trace = tmgr_trace_new(""); +int console_close(lua_State *L) { + sg_platf_close(); + sg_platf_exit(); + return 0; +} - if (state_init == -1) - state_initial_link = SURF_RESOURCE_OFF; - if (policy == -1) - policy_initial_link = SURF_LINK_FATPIPE; +int console_add_host(lua_State *L) { + s_sg_platf_host_cbarg_t host; + memset(&host,0,sizeof(host)); + int state; - surf_link_create_resource(xbt_strdup(name), bw_initial, bw_trace, - lat_initial, lat_trace, state_initial_link, - st_trace, policy_initial_link, xbt_dict_new()); -} + // we get values from the table passed as argument + if (!lua_istable(L, -1)) { + XBT_ERROR + ("Bad Arguments to create host, Should be a table with named arguments"); + return -1; + } -/* - *create host resource via workstation_ptask_L07 model [for SimDag] - */ -static void create_host_wsL07(const char *id, double power_peak, - double power_sc, const char *power_tr, - int state_init, const char *state_tr) -{ - double power_scale = 1.0; - tmgr_trace_t power_trace = NULL; - e_surf_resource_state_t state_initial; - tmgr_trace_t state_trace; - if (power_sc) // !=0 - power_scale = power_sc; - if (state_init == -1) - state_initial = SURF_RESOURCE_OFF; - else - state_initial = SURF_RESOURCE_ON; - if (power_tr) - power_trace = tmgr_trace_new(power_tr); - else - power_trace = tmgr_trace_new(""); - if (state_tr) - state_trace = tmgr_trace_new(state_tr); - else - state_trace = tmgr_trace_new(""); + // get Id Value + lua_pushstring(L, "id"); + lua_gettable(L, -2); + host.V_host_id = lua_tostring(L, -1); + lua_pop(L, 1); - 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; -} + // get power value + lua_pushstring(L, "power"); + lua_gettable(L, -2); + host.V_host_power_peak = lua_tonumber(L, -1); + lua_pop(L, 1); -/** - * create link resource via workstation_ptask_L07 model [for SimDag] - */ + //get power_scale + lua_pushstring(L, "power_scale"); + lua_gettable(L, -2); + host.V_host_power_scale = lua_tonumber(L, -1); + lua_pop(L, 1); -static void create_link_wsL07(const char *name, - double bw_initial, const char *trace, - double lat_initial, - const char *latency_trace, int state_init, - const char *state_trace, int policy) -{ - tmgr_trace_t bw_trace; - tmgr_trace_t lat_trace; - e_surf_resource_state_t state_initial_link = SURF_RESOURCE_ON; - e_surf_link_sharing_policy_t policy_initial_link = SURF_LINK_SHARED; - tmgr_trace_t st_trace; - if (trace) - bw_trace = tmgr_trace_new(trace); - else - bw_trace = tmgr_trace_new(""); + //get power_trace + lua_pushstring(L, "power_trace"); + lua_gettable(L, -2); + host.V_host_power_trace = tmgr_trace_new(lua_tostring(L, -1)); + lua_pop(L, 1); - if (latency_trace) - lat_trace = tmgr_trace_new(latency_trace); - else - lat_trace = tmgr_trace_new(""); + lua_pushstring(L, "core"); + lua_gettable(L, -2); + host.V_host_core = lua_tonumber(L, -1); + if (host.V_host_core == 0) + host.V_host_core = 1; + lua_pop(L, 1); - if (state_trace) - st_trace = tmgr_trace_new(state_trace); + //get state initial + lua_pushstring(L, "state_initial"); + lua_gettable(L, -2); + state = lua_tonumber(L, -1); + lua_pop(L, 1); + if (state) + host.V_host_state_initial = SURF_RESOURCE_ON; else - st_trace = tmgr_trace_new(""); + host.V_host_state_initial = SURF_RESOURCE_OFF; - if (state_init == -1) - state_initial_link = SURF_RESOURCE_OFF; - if (policy == -1) - policy_initial_link = SURF_LINK_FATPIPE; + //get trace state + lua_pushstring(L, "state_trace"); + lua_gettable(L, -2); + host.V_host_state_trace = tmgr_trace_new(lua_tostring(L, -1)); + lua_pop(L, 1); - surf_wsL07_link_create_resource(xbt_strdup(name), bw_initial, bw_trace, - lat_initial, lat_trace, - state_initial_link, st_trace, - policy_initial_link, xbt_dict_new()); -} + sg_platf_new_host(&host); -/* - * surf parse bypass application for MSG Module - */ -static int surf_parse_bypass_application() -{ - unsigned int i,j; - p_AS_attr p_as; - p_host_attr p_host; - xbt_dynar_foreach(as_list_d, i, p_as) - { - xbt_dynar_foreach(p_as->host_list_d, j, p_host) { - if (p_host->function) - MSG_set_function(p_host->id, p_host->function, p_host->args_list); - } - } return 0; } -/* - * Public Methods - */ -int console_add_host(lua_State *L) -{ - p_host_attr host; - unsigned int i; - p_AS_attr p_as,current_as = NULL; - const char *AS_id; - const char *id; - const char *power_trace; - const char *state_trace; - double power, power_scale; - int state_initial,core; - //get values from the table passed as argument - 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); +int console_add_link(lua_State *L) { + s_sg_platf_link_cbarg_t link; + memset(&link,0,sizeof(link)); - // get Id Value - lua_pushstring(L, "id"); - lua_gettable(L, -2); - id = lua_tostring(L, -1); - lua_pop(L, 1); - - // get power value - lua_pushstring(L, "power"); - lua_gettable(L, -2); - power = lua_tonumber(L, -1); - lua_pop(L, 1); - - //get power_scale - lua_pushstring(L, "power_scale"); - lua_gettable(L, -2); - power_scale = lua_tonumber(L, -1); - lua_pop(L, 1); - - //get power_trace - lua_pushstring(L, "power_trace"); - lua_gettable(L, -2); - power_trace = lua_tostring(L, -1); - lua_pop(L, 1); - - lua_pushstring(L, "core"); - lua_gettable(L, -2); - core = lua_tonumber(L, -1); - lua_pop(L, 1); - - //get state initial - lua_pushstring(L, "state_initial"); - lua_gettable(L, -2); - state_initial = lua_tonumber(L, -1); - lua_pop(L, 1); - - //get trace state - lua_pushstring(L, "state_trace"); - lua_gettable(L, -2); - state_trace = lua_tostring(L, -1); - lua_pop(L, 1); + const char* policy; - } else { - XBT_ERROR - ("Bad Arguments to create host, Should be a table with named arguments"); + if (! lua_istable(L, -1)) { + XBT_ERROR("Bad Arguments to create link, Should be a table with named arguments"); return -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; - } + // get Id Value + lua_pushstring(L, "id"); + lua_gettable(L, -2); + link.V_link_id = lua_tostring(L, -1); + lua_pop(L, 1); - host = malloc(sizeof(host_attr)); - host->id = id; - host->power_peak = power; - host->power_scale = power_scale; - host->power_trace = power_trace; - host->core = core; - 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); + // get bandwidth value + lua_pushstring(L, "bandwidth"); + lua_gettable(L, -2); + link.V_link_bandwidth = lua_tonumber(L, -1); + lua_pop(L, 1); - return 0; -} + //get latency value + lua_pushstring(L, "latency"); + lua_gettable(L, -2); + link.V_link_latency = lua_tonumber(L, -1); + lua_pop(L, 1); -int console_add_link(lua_State *L) { - const char *AS_id; - unsigned int i; - p_AS_attr p_as,current_as = NULL; - const char* id; - double bandwidth, latency; - const char *bandwidth_trace; - const char *latency_trace; - const char *state_trace; - int state_initial, policy; - - //get values from the table passed as argument - if (lua_istable(L, -1)) { - - //get AS id - lua_pushstring(L, "AS"); + /*Optional Arguments */ + + //get bandwidth_trace value + lua_pushstring(L, "bandwidth_trace"); lua_gettable(L, -2); - AS_id = lua_tostring(L, -1); + link.V_link_bandwidth_file = tmgr_trace_new(lua_tostring(L, -1)); lua_pop(L, 1); - // get Id Value - lua_pushstring(L, "id"); - lua_gettable(L, -2); - id = lua_tostring(L, -1); - lua_pop(L, 1); - - // get bandwidth value - lua_pushstring(L, "bandwidth"); - lua_gettable(L, -2); - bandwidth = lua_tonumber(L, -1); - lua_pop(L, 1); - - //get latency value - lua_pushstring(L, "latency"); - lua_gettable(L, -2); - latency = lua_tonumber(L, -1); - lua_pop(L, 1); - - /*Optional Arguments */ - - //get bandwidth_trace value - lua_pushstring(L, "bandwidth_trace"); - lua_gettable(L, -2); - bandwidth_trace = lua_tostring(L, -1); - lua_pop(L, 1); - - //get latency_trace value - lua_pushstring(L, "latency_trace"); - lua_gettable(L, -2); - latency_trace = lua_tostring(L, -1); - lua_pop(L, 1); - - //get state_trace value - lua_pushstring(L, "state_trace"); - lua_gettable(L, -2); - state_trace = lua_tostring(L, -1); - lua_pop(L, 1); - - //get state_initial value - lua_pushstring(L, "state_initial"); - lua_gettable(L, -2); - state_initial = lua_tonumber(L, -1); - lua_pop(L, 1); - - //get policy value - lua_pushstring(L, "policy"); - lua_gettable(L, -2); - policy = lua_tonumber(L, -1); - lua_pop(L, 1); + //get latency_trace value + lua_pushstring(L, "latency_trace"); + lua_gettable(L, -2); + link.V_link_latency_file = tmgr_trace_new(lua_tostring(L, -1)); + lua_pop(L, 1); + + //get state_trace value + lua_pushstring(L, "state_trace"); + lua_gettable(L, -2); + link.V_link_state_file = tmgr_trace_new(lua_tostring(L, -1)); + lua_pop(L, 1); + + //get state_initial value + lua_pushstring(L, "state_initial"); + lua_gettable(L, -2); + if (lua_tonumber(L, -1)) + link.V_link_state = SURF_RESOURCE_ON; + else + link.V_link_state = SURF_RESOURCE_OFF; + lua_pop(L, 1); + //get policy value + lua_pushstring(L, "policy"); + lua_gettable(L, -2); + policy = lua_tostring(L, -1); + lua_pop(L, 1); + if (policy && !strcmp(policy,"FULLDUPLEX")) { + link.V_link_sharing_policy = SURF_LINK_FULLDUPLEX; + } else if (policy && !strcmp(policy,"FATPIPE")) { + link.V_link_sharing_policy = SURF_LINK_FATPIPE; } else { - XBT_ERROR - ("Bad Arguments to create link, Should be a table with named arguments"); - return -1; - } - xbt_dynar_foreach(as_list_d, i, p_as){ - if (p_as->id == AS_id){ - current_as = p_as; - break; - } + link.V_link_sharing_policy = SURF_LINK_SHARED; } - if (!current_as) - { - XBT_ERROR("No AS_id :%s found",AS_id); - return -2; - } - p_link_attr link = malloc(sizeof(link_attr)); - link->id = id; - link->bandwidth = bandwidth; - link->latency = latency; - link->bandwidth_trace = bandwidth_trace; - link->latency_trace = latency_trace; - link->state_trace = state_trace; - link->state_initial = state_initial; - link->policy = policy; - xbt_dynar_push(current_as->link_list_d, &link); + sg_platf_new_link(&link); return 0; } @@ -382,352 +169,202 @@ int console_add_link(lua_State *L) { * add Router to AS components */ int console_add_router(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); + s_sg_platf_router_cbarg_t router; + memset(&router,0,sizeof(router)); + + if (! lua_istable(L, -1)) { + XBT_ERROR("Bad Arguments to create router, Should be a table with named arguments"); + return -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; -} + lua_pushstring(L, "id"); + lua_gettable(L, -2); + router.V_router_id = lua_tostring(L, -1); + lua_pop(L,1); + + lua_pushstring(L,"coord"); + lua_gettable(L,-2); + router.V_router_coord = lua_tostring(L, -1); + lua_pop(L,1); + sg_platf_new_router(&router); -int console_add_route(lua_State *L) -{ - 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; + return 0; } -int console_add_AS(lua_State *L) -{ - if (xbt_dynar_is_empty(as_list_d)) - as_list_d = xbt_dynar_new(sizeof(p_AS_attr), &xbt_free_ref); +#include "surf/surfxml_parse.h" /* to override surf_parse and bypass the parser */ + +int console_add_route(lua_State *L) { + static int AX_ptr = 0; + static int surfxml_bufferstack_size = 2048; + + /* allocating memory for the buffer, I think 2kB should be enough */ + surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size); - p_AS_attr AS; + const char*src; + const char*dst; + int is_symmetrical; + xbt_dynar_t links; + unsigned int cursor; + char *link_id; + + if (! lua_istable(L, -1)) { + XBT_ERROR("Bad Arguments to create a route, Should be a table with named arguments"); + return -1; + } + + lua_pushstring(L,"src"); + lua_gettable(L,-2); + src = lua_tostring(L, -1); + lua_pop(L,1); + + lua_pushstring(L,"dest"); + lua_gettable(L,-2); + dst = lua_tostring(L, -1); + lua_pop(L,1); + + lua_pushstring(L,"links"); + lua_gettable(L,-2); + links = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); + if (xbt_dynar_length(links)==0) + xbt_dynar_push_as(links,char*,xbt_strdup(lua_tostring(L, -1))); + lua_pop(L,1); + + lua_pushstring(L,"symmetrical"); + lua_gettable(L,-2); + is_symmetrical = lua_tointeger(L, -1); + lua_pop(L,1); + + /* We are relying on the XML bypassing mechanism since the corresponding sg_platf does not exist yet. + * Et ouais mon pote. That's the way it goes. F34R. + */ + SURFXML_BUFFER_SET(route_src, src); + SURFXML_BUFFER_SET(route_dst, dst); + if (is_symmetrical) + A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_YES; + else + A_surfxml_route_symmetrical = A_surfxml_route_symmetrical_NO; + SURFXML_START_TAG(route); + + xbt_dynar_foreach(links,cursor,link_id) { + SURFXML_BUFFER_SET(link_ctn_id, link_id); + A_surfxml_link_ctn_direction = A_surfxml_link_ctn_direction_NONE; + SURFXML_START_TAG(link_ctn); + SURFXML_END_TAG(link_ctn); + } + SURFXML_END_TAG(route); + + xbt_dynar_free(&links); + free(surfxml_bufferstack); + + return 0; +} + +int console_AS_open(lua_State *L) { const char *id; const char *mode; - if (lua_istable(L, 1)) { - lua_pushstring(L, "id"); - lua_gettable(L, -2); - id = lua_tostring(L, -1); - lua_pop(L, 1); - - lua_pushstring(L, "mode"); - lua_gettable(L, -2); - mode = lua_tostring(L, -1); - lua_pop(L, 1); - } else { - XBT_ERROR - ("Bad Arguments to AS.new, Should be a table with named arguments"); + + if (! lua_istable(L, 1)) { + XBT_ERROR("Bad Arguments to AS_open, Should be a table with named arguments"); return -1; } - AS = malloc(sizeof(AS_attr)); - AS->id = id; - AS->mode = mode; - 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); + + lua_pushstring(L, "id"); + lua_gettable(L, -2); + id = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "mode"); + lua_gettable(L, -2); + mode = lua_tostring(L, -1); + lua_pop(L, 1); + + sg_platf_new_AS_open(id,mode); return 0; } +int console_AS_close(lua_State *L) { + sg_platf_new_AS_close(); + return 0; +} int console_set_function(lua_State *L) { - p_AS_attr p_as; - p_host_attr p_host; - unsigned int i,j; + const char *host_id ; const char *function_id; - const char *args; - char * tmp_arg; - - 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, "fct"); - lua_gettable(L, -2); - function_id = lua_tostring(L, -1); - lua_pop(L, 1); - //get args - lua_pushstring(L,"args"); - lua_gettable(L, -2); - args = lua_tostring(L,-1); - lua_pop(L, 1); - } - else { - XBT_ERROR("Bad Arguments to create link, Should be a table with named arguments"); - return -1; - } - - // look for the index of host in host_list for each AS - 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) { - 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,","); - while (tmp_arg != NULL) { - xbt_dynar_push(p_host->args_list, &tmp_arg); - tmp_arg = strtok(NULL,","); - } - return 0; - } - } - } - XBT_ERROR("Host : %s Not Found !!", host_id); - return 1; + xbt_dynar_t args; + + if (! lua_istable(L, 1)) { + XBT_ERROR("Bad Arguments to AS.new, Should be a table with named arguments"); + return -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, "fct"); + lua_gettable(L, -2); + function_id = lua_tostring(L, -1); + lua_pop(L, 1); + + //get args + lua_pushstring(L,"args"); + lua_gettable(L, -2); + args = xbt_str_split_quoted( lua_tostring(L,-1) ); + lua_pop(L, 1); + + // FIXME: hackish to go under MSG that way + m_host_t host = xbt_lib_get_or_null(host_lib,host_id,MSG_HOST_LEVEL); + if (!host) { + XBT_ERROR("no host '%s' found",host_id); + return -1; + } + + MSG_set_function(host_id, function_id, args); + + return 0; } int console_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* name =""; 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; -} - -int console_parse_platform() { - unsigned int i,j; - p_AS_attr p_as; - p_host_attr p_host; - p_link_attr p_link; - p_route_attr p_route; - - - // Add AS - xbt_dynar_foreach(as_list_d, i,p_as) - { - sg_platf_new_AS_open(p_as->id,p_as->mode); - // add associated Hosts - 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, p_host->properties); - - - //FIXME: should use sg_platf instead. That would add to routing model host list, amongst other benefits - } - // add associated Links - xbt_dynar_foreach(p_as->link_list_d, j, p_link){ - create_link(p_link->id, p_link->bandwidth, p_link->bandwidth_trace, - p_link->latency, p_link->latency_trace, - p_link->state_initial, p_link->state_trace, - p_link->policy); - } - // add associated Routes - xbt_dynar_foreach(p_as->route_list_d, j, p_route){ - surf_routing_add_route((char *) p_route->src_id, - (char *) p_route->dest_id, p_route->links_id); - } - - // Finalize AS - sg_platf_new_AS_close(); + if (!lua_istable(L, -1)) { + XBT_ERROR("Bad Arguments to create link, Should be a table with named arguments"); + return -1; } - // add traces - surf_add_host_traces(); - surf_add_link_traces(); - return 0; // must return 0 ?!! -} + // get Host id + lua_pushstring(L, "host"); + lua_gettable(L, -2); + name = lua_tostring(L, -1); + lua_pop(L, 1); -int console_parse_application() -{ - return surf_parse_bypass_application(); -} + // get prop Name + lua_pushstring(L, "prop"); + lua_gettable(L, -2); + prop_id = lua_tostring(L, -1); + lua_pop(L, 1); + //get args + lua_pushstring(L,"value"); + lua_gettable(L, -2); + prop_value = lua_tostring(L,-1); + lua_pop(L, 1); -int console_parse_platform_wsL07() -{ - unsigned int i,j; - p_AS_attr p_as, p_sub_as; - p_host_attr p_host; - p_link_attr p_link; - p_route_attr p_route; - - xbt_dynar_foreach(as_list_d, i, p_as) - { - // Init AS - sg_platf_new_AS_open(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, - p_host->state_trace); - //add to routing model host list - } - //add Links - xbt_dynar_foreach(p_as->link_list_d, j, p_link) { - create_link_wsL07(p_link->id, p_link->bandwidth, - p_link->bandwidth_trace, p_link->latency, - p_link->latency_trace, p_link->state_initial, - p_link->state_trace, p_link->policy); - } - // add route - xbt_dynar_foreach(p_as->route_list_d, j, p_route) { - surf_routing_add_route((char *) p_route->src_id, - (char *) p_route->dest_id, p_route->links_id); - } - /* */ - // Finalize AS - sg_platf_new_AS_close(); + // FIXME: hackish to go under MSG that way + m_host_t host = xbt_lib_get_or_null(host_lib,name,MSG_HOST_LEVEL); + if (!host) { + XBT_ERROR("no host '%s' found",name); + return -1; } - // add traces - surf_wsL07_add_traces(); + xbt_dict_t props = MSG_host_get_properties(host); + xbt_dict_set(props,prop_id,xbt_strdup(prop_value),free); + return 0; } + diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index db3d75dbb2..3b60dc6080 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -17,8 +17,7 @@ XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua, bindings, "Lua Bindings"); // Surf (bypass XML) #define LINK_MODULE_NAME "simgrid.Link" #define ROUTE_MODULE_NAME "simgrid.Route" -#define AS_MODULE_NAME "simgrid.AS" -#define TRACE_MODULE_NAME "simgrid.Trace" +#define PLATF_MODULE_NAME "simgrid.platf" static lua_State* sglua_maestro_state; @@ -435,40 +434,6 @@ static int gras_generate(lua_State * L) return 0; } -/*********************************** - * Tracing - **********************************/ -static int trace_start(lua_State *L) -{ -#ifdef HAVE_TRACING - TRACE_start(); -#endif - return 1; -} - -static int trace_category(lua_State * L) -{ -#ifdef HAVE_TRACING - TRACE_category(luaL_checkstring(L, 1)); -#endif - return 1; -} - -static int trace_set_task_category(lua_State *L) -{ -#ifdef HAVE_TRACING - TRACE_msg_set_task_category(checkTask(L, -2), luaL_checkstring(L, -1)); -#endif - return 1; -} - -static int trace_end(lua_State *L) -{ -#ifdef HAVE_TRACING - TRACE_end(); -#endif - return 1; -} // *********** Register Methods ******************************************* // @@ -513,24 +478,16 @@ static const luaL_reg Host_meta[] = { /* * AS Methods */ -static const luaL_reg AS_methods[] = { - {"new", console_add_AS}, - {"addHost", console_add_host}, - {"addLink", console_add_link}, - {"addRouter", console_add_router}, - {"addRoute", console_add_route}, - {NULL, NULL} -}; - -/** - * Tracing Functions - */ -static const luaL_reg Trace_methods[] = { - {"start", trace_start}, - {"category", trace_category}, - {"setTaskCategory", trace_set_task_category}, - {"finish", trace_end}, - {NULL, NULL} +static const luaL_reg platf_methods[] = { + {"open", console_open}, + {"close", console_close}, + {"AS_open", console_AS_open}, + {"AS_close", console_AS_close}, + {"host_new", console_add_host}, + {"link_new", console_add_link}, + {"router_new", console_add_router}, + {"route_new", console_add_route}, + {NULL, NULL} }; /* @@ -629,7 +586,7 @@ static int clean(lua_State * L) static int msg_register_platform(lua_State * L) { /* Tell Simgrid we dont wanna use its parser */ - surf_parse = console_parse_platform; + //surf_parse = console_parse_platform; surf_parse_reset_callbacks(); MSG_create_environment(NULL); return 0; @@ -641,7 +598,7 @@ static int msg_register_platform(lua_State * L) static int sd_register_platform(lua_State * L) { - surf_parse = console_parse_platform_wsL07; + //surf_parse = console_parse_platform_wsL07; surf_parse_reset_callbacks(); SD_create_environment(NULL); return 0; @@ -652,8 +609,7 @@ static int sd_register_platform(lua_State * L) */ static int gras_register_platform(lua_State * L) { - /* Tell Simgrid we dont wanna use surf parser */ - surf_parse = console_parse_platform; + //surf_parse = console_parse_platform; surf_parse_reset_callbacks(); gras_create_environment(NULL); return 0; @@ -665,7 +621,7 @@ static int gras_register_platform(lua_State * L) static int msg_register_application(lua_State * L) { MSG_function_register_default(run_lua_code); - surf_parse = console_parse_application; + //surf_parse = console_parse_application; MSG_launch_application(NULL); return 0; } @@ -676,7 +632,7 @@ static int msg_register_application(lua_State * L) static int gras_register_application(lua_State * L) { gras_function_register_default(run_lua_code); - surf_parse = console_parse_application; + //surf_parse = console_parse_application; gras_launch_application(NULL); return 0; } @@ -818,12 +774,7 @@ void register_c_functions(lua_State *L) { lua_pop(L, 1); /* register the links methods to lua */ - luaL_openlib(L, AS_MODULE_NAME, AS_methods, 0); - luaL_newmetatable(L, AS_MODULE_NAME); - lua_pop(L, 1); - - /* register the Tracing functions to lua */ - luaL_openlib(L, TRACE_MODULE_NAME, Trace_methods, 0); - luaL_newmetatable(L, TRACE_MODULE_NAME); + luaL_openlib(L, PLATF_MODULE_NAME, platf_methods, 0); + luaL_newmetatable(L, PLATF_MODULE_NAME); lua_pop(L, 1); } diff --git a/src/bindings/lua/simgrid_lua.h b/src/bindings/lua/simgrid_lua.h index 50034bba9c..06a9aefeb5 100644 --- a/src/bindings/lua/simgrid_lua.h +++ b/src/bindings/lua/simgrid_lua.h @@ -17,9 +17,7 @@ #include "xbt/function_types.h" #include "xbt/log.h" #include "surf/surfxml_parse.h" -#include "surf/surf_private.h" #include "surf/surf.h" -#include "portable.h" /* Needed for the time of the SIMIX convertion */ #include extern xbt_dict_t process_function_set; @@ -43,72 +41,17 @@ void generate_makefile_local(const char *project); /* ********************************************************************************* */ /* Console functions */ /* ********************************************************************************* */ - -typedef struct t_AS_attr { - const char *id; - const char *mode; - xbt_dynar_t host_list_d; - xbt_dynar_t link_list_d; - xbt_dynar_t route_list_d; - xbt_dynar_t router_list_d; - xbt_dynar_t sub_as_list_id; -} AS_attr, *p_AS_attr; - -typedef struct t_host_attr { - //platform attribute - // Mandatory attributes - const char *id; - double power_peak; - // Optional attributes - double power_scale; - const char *power_trace; - int state_initial; - const char *state_trace; - int core; - //deployment attribute - const char *function; - xbt_dynar_t args_list; - xbt_dict_t properties; -} host_attr, *p_host_attr; - - -typedef struct t_link_attr { - //mandatory attributes - const char *id; - double bandwidth; - double latency; - // Optional attributes - const char *bandwidth_trace; - const char *latency_trace; - const char *state_trace; - int state_initial; - int policy; -} link_attr, *p_link_attr; - - -typedef struct t_route_attr { - const char *src_id; - const char *dest_id; - xbt_dynar_t links_id; - -} route_attr, *p_route_attr; - -typedef struct t_router_attr { - const char *id; -} router_attr, *p_router_attr; - // Public Functions +int console_open(lua_State *L); +int console_close(lua_State *L); int console_add_host(lua_State*); int console_add_link(lua_State*); int console_add_router(lua_State* L); int console_add_route(lua_State*); -int console_add_AS(lua_State*); +int console_AS_open(lua_State*); +int console_AS_close(lua_State *L); int console_set_function(lua_State*); int console_host_set_property(lua_State*); -int console_parse_platform(void); -int console_parse_application(void); -int console_parse_platform_wsL07(void); - #endif /* SIMGRID_LUA_H */ diff --git a/src/msg/environment.c b/src/msg/environment.c index fca4a9f412..fac131f01b 100644 --- a/src/msg/environment.c +++ b/src/msg/environment.c @@ -70,10 +70,9 @@ void MSG_create_environment(const char *file) /* Initialize MSG hosts */ xbt_lib_foreach(host_lib, cursor, name, data) { - if(data[SIMIX_HOST_LEVEL]) + if(data[SIMIX_HOST_LEVEL]) __MSG_host_create((smx_host_t)data[SIMIX_HOST_LEVEL], NULL); } - return; } /** @@ -97,5 +96,4 @@ void MSG_load_platform_script(const char *script_file) xbt_die ("Lua is not available!! to call MSG_load_platform_script, lua should be available..."); #endif - return; } diff --git a/src/surf/surf_routing.c b/src/surf/surf_routing.c index 349f5e4d63..cfd09c54e2 100644 --- a/src/surf/surf_routing.c +++ b/src/surf/surf_routing.c @@ -116,7 +116,7 @@ static void parse_S_host(sg_platf_host_cbarg_t host) { info->rc_component = current_routing; info->rc_type = SURF_NETWORK_ELEMENT_HOST; xbt_lib_set(host_lib,host->V_host_id,ROUTING_HOST_LEVEL,(void *) info); - if (strcmp(host->V_host_coord,"")) { + if (host->V_host_coord && strcmp(host->V_host_coord,"")) { if(!COORD_HOST_LEVEL) xbt_die("To use coordinates, you must set configuration 'coordinates' to 'yes'"); xbt_dynar_t ctn = xbt_str_split_str(host->V_host_coord, " "); xbt_dynar_shrink(ctn, 0); -- 2.20.1