From 550e2982f1b4cd634914e5a30ea82bf191f511bd Mon Sep 17 00:00:00 2001 From: Christian Heinrich Date: Tue, 24 Feb 2015 09:45:34 +0100 Subject: [PATCH] LUA: Added support for backbone, host_link and ASroute - This code almost duplicates code in the surf_parsexml files. In the future, it might be nice to move this to different layer. - This changeset also makes the notion of 'power=1Gf' available to hosts (and links for the bandwidth attrib). --- src/bindings/lua/factories/host.lua | 9 ++ src/bindings/lua/lua_platf.c | 133 +++++++++++++++++++++++++++- src/bindings/lua/simgrid_lua.c | 7 +- src/bindings/lua/simgrid_lua.h | 3 + 4 files changed, 147 insertions(+), 5 deletions(-) create mode 100644 src/bindings/lua/factories/host.lua diff --git a/src/bindings/lua/factories/host.lua b/src/bindings/lua/factories/host.lua new file mode 100644 index 0000000000..f8f07cd427 --- /dev/null +++ b/src/bindings/lua/factories/host.lua @@ -0,0 +1,9 @@ + +hostFactory = function(host_args) + if type(host_args.power) ~= "number" then + error("FUCK") + end + return function(more_args) + end +end + diff --git a/src/bindings/lua/lua_platf.c b/src/bindings/lua/lua_platf.c index e21b30e8ef..ac6a80aab2 100644 --- a/src/bindings/lua/lua_platf.c +++ b/src/bindings/lua/lua_platf.c @@ -31,10 +31,13 @@ static const luaL_reg platf_functions[] = { {"close", console_close}, {"AS_open", console_AS_open}, {"AS_close", console_AS_close}, + {"backbone_new", console_add_backbone}, + {"host_link_new", console_add_host___link}, {"host_new", console_add_host}, {"link_new", console_add_link}, {"router_new", console_add_router}, {"route_new", console_add_route}, + {"ASroute_new", console_add_ASroute}, {NULL, NULL} }; @@ -73,6 +76,68 @@ int console_close(lua_State *L) { return 0; } +int console_add_backbone(lua_State *L) { + s_sg_platf_link_cbarg_t link; + memset(&link,0,sizeof(link)); + + link.properties = NULL; + + lua_pushstring(L, "id"); + lua_gettable(L, -2); + link.id = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "bandwidth"); + lua_gettable(L, -2); + link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1)); + lua_pop(L, 1); + + lua_pushstring(L, "latency"); + lua_gettable(L, -2); + link.latency = surf_parse_get_time(lua_tostring(L, -1)); + lua_pop(L, 1); + + link.state = SURF_RESOURCE_ON; + link.policy = SURF_LINK_SHARED; + + sg_platf_new_link(&link); + routing_cluster_add_backbone(xbt_lib_get_or_null(link_lib, link.id, SURF_LINK_LEVEL)); + + return 0; +} + +int console_add_host___link(lua_State *L) { + s_sg_platf_host_link_cbarg_t host_link; + memset(&host_link,0,sizeof(host_link)); + + // 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; + } + + lua_pushstring(L, "id"); + lua_gettable(L, -2); + host_link.id = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "up"); + lua_gettable(L, -2); + host_link.link_up = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "down"); + lua_gettable(L, -2); + host_link.link_down = lua_tostring(L, -1); + lua_pop(L, 1); + + XBT_DEBUG("Create a host_link for host %s", host_link.id); + sg_platf_new_host_link(&host_link); + + return 0; +} + int console_add_host(lua_State *L) { s_sg_platf_host_cbarg_t host; memset(&host,0,sizeof(host)); @@ -95,7 +160,7 @@ int console_add_host(lua_State *L) { lua_pushstring(L, "power"); lua_gettable(L, -2); host.power_peak = xbt_dynar_new(sizeof(double), NULL); - xbt_dynar_push_as(host.power_peak, double, lua_tonumber(L, -1)); + xbt_dynar_push_as(host.power_peak, double, get_cpu_power(lua_tostring(L, -1))); lua_pop(L, 1); // get core @@ -163,13 +228,13 @@ int console_add_link(lua_State *L) { // get bandwidth value lua_pushstring(L, "bandwidth"); lua_gettable(L, -2); - link.bandwidth = lua_tonumber(L, -1); + link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1)); lua_pop(L, 1); //get latency value lua_pushstring(L, "latency"); lua_gettable(L, -2); - link.latency = lua_tonumber(L, -1); + link.latency = surf_parse_get_time(lua_tostring(L, -1)); lua_pop(L, 1); /*Optional Arguments */ @@ -279,6 +344,9 @@ int console_add_route(lua_State *L) { /* 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. + * + * (Note that above this function, there is a #include statement. Is this + * comment related to that statement?) */ lua_pushstring(L,"symmetrical"); lua_gettable(L,-2); @@ -303,6 +371,64 @@ int console_add_route(lua_State *L) { return 0; } +int console_add_ASroute(lua_State *L) { + s_sg_platf_route_cbarg_t ASroute; + memset(&ASroute,0,sizeof(ASroute)); + + lua_pushstring(L, "src"); + lua_gettable(L, -2); + ASroute.src = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "dst"); + lua_gettable(L, -2); + ASroute.dst = lua_tostring(L, -1); + lua_pop(L, 1); + + lua_pushstring(L, "gw_src"); + lua_gettable(L, -2); + ASroute.gw_src = sg_routing_edge_by_name_or_null(lua_tostring(L, -1)); + lua_pop(L, 1); + + lua_pushstring(L, "gw_dst"); + lua_gettable(L, -2); + ASroute.gw_dst = sg_routing_edge_by_name_or_null(lua_tostring(L, -1)); + lua_pop(L, 1); + + /*if (A_surfxml_ASroute_gw___src && !ASroute.gw_src)*/ + /*surf_parse_error("gw_src=\"%s\" not found for ASroute from \"%s\" to \"%s\"",*/ + /*A_surfxml_ASroute_gw___src, ASroute.src, ASroute.dst);*/ + /*if (A_surfxml_ASroute_gw___dst && !ASroute.gw_dst)*/ + /*surf_parse_error("gw_dst=\"%s\" not found for ASroute from \"%s\" to \"%s\"",*/ + /*A_surfxml_ASroute_gw___dst, ASroute.src, ASroute.dst);*/ + + lua_pushstring(L,"links"); + lua_gettable(L,-2); + ASroute.link_list = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); + if (xbt_dynar_is_empty(ASroute.link_list)) + xbt_dynar_push_as(ASroute.link_list,char*,xbt_strdup(lua_tostring(L, -1))); + lua_pop(L,1); + + lua_pushstring(L,"symmetrical"); + lua_gettable(L,-2); + if (lua_isstring(L, -1)) { + const char* value = lua_tostring(L, -1); + if (strcmp("YES", value) == 0) { + ASroute.symmetrical = TRUE; + } + else + ASroute.symmetrical = FALSE; + } + else { + ASroute.symmetrical = TRUE; + } + lua_pop(L,1); + + sg_platf_new_ASroute(&ASroute); + + return 0; +} + int console_AS_open(lua_State *L) { const char *id; const char *mode; @@ -337,6 +463,7 @@ int console_AS_open(lua_State *L) { s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER; AS.id = id; AS.routing = mode_int; + sg_platf_new_AS_begin(&AS); return 0; diff --git a/src/bindings/lua/simgrid_lua.c b/src/bindings/lua/simgrid_lua.c index f15d6915b6..69de34e473 100644 --- a/src/bindings/lua/simgrid_lua.c +++ b/src/bindings/lua/simgrid_lua.c @@ -15,6 +15,7 @@ #include "surf/surfxml_parse.h" #include + XBT_LOG_NEW_DEFAULT_SUBCATEGORY(lua, bindings, "Lua Bindings"); static lua_State* sglua_maestro_state; @@ -42,6 +43,7 @@ static int launch_application(lua_State* L) { return 0; } + /** * \brief Creates the platform. * \param L a Lua state @@ -197,6 +199,7 @@ static const luaL_Reg simgrid_functions[] = { * * \param L the Lua state */ + int luaopen_simgrid(lua_State *L) { XBT_DEBUG("luaopen_simgrid *****"); @@ -232,10 +235,10 @@ int luaopen_simgrid(lua_State *L) argv[argc--] = NULL; /* Initialize the MSG core */ - MSG_init(&argc, argv); - MSG_process_set_data_cleanup((void_f_pvoid_t) lua_close); XBT_DEBUG("Still %d arguments on command line", argc); // FIXME: update the lua's arg table to reflect the changes from SimGrid } + MSG_init(&argc, argv); + MSG_process_set_data_cleanup((void_f_pvoid_t) lua_close); /* Keep the context mechanism informed of our lua world today */ sglua_maestro_state = L; diff --git a/src/bindings/lua/simgrid_lua.h b/src/bindings/lua/simgrid_lua.h index 958440d2b3..dea4da47ff 100644 --- a/src/bindings/lua/simgrid_lua.h +++ b/src/bindings/lua/simgrid_lua.h @@ -16,10 +16,13 @@ int console_open(lua_State *L); int console_close(lua_State *L); +int console_add_backbone(lua_State*); +int console_add_host___link(lua_State*); 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_ASroute(lua_State*); int console_AS_open(lua_State*); int console_AS_close(lua_State *L); int console_set_function(lua_State*); -- 2.20.1