int console_AS_open(lua_State *L) { const char *id; const char *mode; int type; XBT_DEBUG("Opening AS"); lua_ensure(lua_istable(L, 1), "Bad Arguments to AS_open, Should be a table with named arguments"); lua_pushstring(L, "id"); type = lua_gettable(L, -2); lua_ensure(type == LUA_TSTRING, "Attribute 'id' must be specified for any AS and must be a string."); 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); int mode_int = A_surfxml_AS_routing_None; if(!strcmp(mode,"Full")) mode_int = A_surfxml_AS_routing_Full; else if(!strcmp(mode,"Floyd")) mode_int = A_surfxml_AS_routing_Floyd; else if(!strcmp(mode,"Dijkstra")) mode_int = A_surfxml_AS_routing_Dijkstra; else if(!strcmp(mode,"DijkstraCache")) mode_int = A_surfxml_AS_routing_DijkstraCache; else if(!strcmp(mode,"Vivaldi")) mode_int = A_surfxml_AS_routing_Vivaldi; else if(!strcmp(mode,"Cluster")) mode_int = A_surfxml_AS_routing_Cluster; else if(!strcmp(mode,"none")) mode_int = A_surfxml_AS_routing_None; else xbt_die("Don't have the model name '%s'",mode); s_sg_platf_AS_cbarg_t AS; AS.id = id; AS.routing = mode_int; simgrid::s4u::NetZone* new_as = sg_platf_new_AS_begin(&AS); /* Build a Lua representation of the new AS on the stack */ lua_newtable(L); simgrid::s4u::NetZone** lua_as = (simgrid::s4u::NetZone**)lua_newuserdata(L, sizeof(simgrid::s4u::NetZone*)); /* table userdatum */ *lua_as = new_as; luaL_getmetatable(L, PLATF_MODULE_NAME); /* table userdatum metatable */ lua_setmetatable(L, -2); /* table userdatum */ lua_setfield(L, -2, AS_FIELDNAME); /* table -- put the userdata as field of the table */ return 1; }
static int surf_parse_bypass_platform(void) { sg_platf_begin(); s_sg_platf_AS_cbarg_t AS = SG_PLATF_AS_INITIALIZER; AS.id = "AS0"; AS.routing = A_surfxml_AS_routing_Full; sg_platf_new_AS_begin(&AS); s_sg_platf_host_cbarg_t bob = SG_PLATF_HOST_INITIALIZER; bob.id = "bob"; bob.power_peak = xbt_dynar_new(sizeof(double), NULL); xbt_dynar_push_as(bob.power_peak, double, 98095000.0); sg_platf_new_host(&bob); s_sg_platf_host_cbarg_t alice = SG_PLATF_HOST_INITIALIZER; alice.id = "alice"; alice.power_peak = xbt_dynar_new(sizeof(double), NULL); xbt_dynar_push_as(alice.power_peak, double, 98095000.0); sg_platf_new_host(&alice); s_sg_platf_link_cbarg_t link = SG_PLATF_LINK_INITIALIZER; link.id = "link1"; link.latency = 0.000278066; link.bandwidth = 27946250; sg_platf_new_link(&link); s_sg_platf_route_cbarg_t route= SG_PLATF_ROUTE_INITIALIZER; route.src = "bob"; route.dst = "alice"; sg_platf_route_begin(&route); sg_platf_route_add_link("link1", &route); sg_platf_route_end(&route); sg_platf_new_AS_end(); sg_platf_end(); sg_platf_exit(); return 0; }