+int console_add_backbone(lua_State *L) {
+ s_sg_platf_link_cbarg_t link;
+ memset(&link,0,sizeof(link));
+ int type;
+
+ link.properties = NULL;
+
+ if (!lua_istable(L, -1)) {
+ XBT_ERROR
+ ("Bad Arguments to create backbone in Lua. Should be a table with named arguments.");
+ return -1;
+ }
+
+ lua_pushstring(L, "id");
+ type = lua_gettable(L, -2);
+ if (type != LUA_TSTRING) {
+ XBT_ERROR("Attribute 'id' must be specified for backbone and must be a string.");
+ }
+ link.id = lua_tostring(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "bandwidth");
+ type = lua_gettable(L, -2);
+ if (type != LUA_TSTRING && type != LUA_TNUMBER) {
+ XBT_ERROR("Attribute 'bandwidth' must be specified for backbone and must either be a string (in the right format; see docs) or a number.");
+ }
+ link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1));
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "lat");
+ type = lua_gettable(L, -2);
+ if (type != LUA_TSTRING && type != LUA_TNUMBER) {
+ XBT_ERROR("Attribute 'lat' must be specified for backbone and must either be a string (in the right format; see docs) or a number.");
+ }
+ link.latency = surf_parse_get_time(lua_tostring(L, -1));
+ lua_pop(L, 1);
+
+ link.state = SURF_RESOURCE_ON;
+
+ lua_pushstring(L, "sharing_policy");
+ type = lua_gettable(L, -2);
+ const char* policy = lua_tostring(L, -1);
+ if (policy && !strcmp(policy,"FULLDUPLEX")) {
+ link.policy = SURF_LINK_FULLDUPLEX;
+ } else if (policy && !strcmp(policy,"FATPIPE")) {
+ link.policy = SURF_LINK_FATPIPE;
+ } else {
+ 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));
+ int type;
+
+ // we get values from the table passed as argument
+ if (!lua_istable(L, -1)) {
+ XBT_ERROR
+ ("Bad Arguments to create host_link in Lua. Should be a table with named arguments.");
+ return -1;
+ }
+
+ lua_pushstring(L, "id");
+ type = lua_gettable(L, -2);
+ if (type != LUA_TSTRING) {
+ XBT_ERROR("Attribute 'id' must be specified for any host_link and must be a string.");
+ }
+ host_link.id = lua_tostring(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "up");
+ type = lua_gettable(L, -2);
+ if (type != LUA_TSTRING && type != LUA_TNUMBER) {
+ XBT_ERROR("Attribute 'up' must be specified for host_link and must either be a string or a number.");
+ }
+ host_link.link_up = lua_tostring(L, -1);
+ lua_pop(L, 1);
+
+ lua_pushstring(L, "down");
+ type = lua_gettable(L, -2);
+ if (type != LUA_TSTRING && type != LUA_TNUMBER) {
+ XBT_ERROR("Attribute 'down' must be specified for host_link and must either be a string or a number.");
+ }
+ 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;
+}
+