void AsFull::addRoute(sg_platf_route_cbarg_t route) { const char *src = route->src; const char *dst = route->dst; NetCard *src_net_elm = sg_netcard_by_name_or_null(src); NetCard *dst_net_elm = sg_netcard_by_name_or_null(dst); addRouteCheckParams(route); size_t table_size = xbt_dynar_length(vertices_); if (!routingTable_) routingTable_ = xbt_new0(sg_platf_route_cbarg_t, table_size * table_size); /* Check that the route does not already exist */ if (route->gw_dst) // AS route (to adapt the error message, if any) xbt_assert(nullptr == TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()), "The route between %s@%s and %s@%s already exists (Rq: routes are symmetrical by default).", src,route->gw_src->name(),dst,route->gw_dst->name()); else xbt_assert(nullptr == TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()), "The route between %s and %s already exists (Rq: routes are symmetrical by default).", src,dst); /* Add the route to the base */ TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id()) = newExtendedRoute(hierarchy_, route, 1); TO_ROUTE_FULL(src_net_elm->id(), dst_net_elm->id())->link_list->shrink_to_fit(); if (route->symmetrical == true && src_net_elm != dst_net_elm) { if (route->gw_dst && route->gw_src) { NetCard* gw_tmp = route->gw_src; route->gw_src = route->gw_dst; route->gw_dst = gw_tmp; } if (route->gw_dst) // AS route (to adapt the error message, if any) xbt_assert(nullptr == TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()), "The route between %s@%s and %s@%s already exists. You should not declare the reverse path as symmetrical.", dst,route->gw_dst->name(),src,route->gw_src->name()); else xbt_assert(nullptr == TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()), "The route between %s and %s already exists. You should not declare the reverse path as symmetrical.", dst,src); TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id()) = newExtendedRoute(hierarchy_, route, 0); TO_ROUTE_FULL(dst_net_elm->id(), src_net_elm->id())->link_list->shrink_to_fit(); } }
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); const char *srcName = lua_tostring(L, -1); ASroute.src = sg_netcard_by_name_or_null(srcName); lua_ensure(ASroute.src != nullptr, "Attribute 'src=%s' of AS route does not name a node.", srcName); lua_pop(L, 1); lua_pushstring(L, "dst"); lua_gettable(L, -2); const char *dstName = lua_tostring(L, -1); ASroute.dst = sg_netcard_by_name_or_null(dstName); lua_ensure(ASroute.dst != nullptr, "Attribute 'dst=%s' of AS route does not name a node.", dstName); lua_pop(L, 1); lua_pushstring(L, "gw_src"); lua_gettable(L, -2); const char *name = lua_tostring(L, -1); ASroute.gw_src = sg_netcard_by_name_or_null(name); lua_ensure(ASroute.gw_src, "Attribute 'gw_src=%s' of AS route does not name a valid node", name); lua_pop(L, 1); lua_pushstring(L, "gw_dst"); lua_gettable(L, -2); name = lua_tostring(L, -1); ASroute.gw_dst = sg_netcard_by_name_or_null(name); lua_ensure(ASroute.gw_dst, "Attribute 'gw_dst=%s' of AS route does not name a valid node", name); lua_pop(L, 1); lua_pushstring(L,"links"); lua_gettable(L,-2); ASroute.link_list = new std::vector<Link*>(); xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); if (xbt_dynar_is_empty(names)) { /* unique name with no comma */ ASroute.link_list->push_back(Link::byName(lua_tostring(L, -1))); } else { // Several names separated by , \t\r\n unsigned int cpt; char *name; xbt_dynar_foreach(names, cpt, name) { if (strlen(name)>0) { Link *link = Link::byName(name); ASroute.link_list->push_back(link); } } } 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_route(&ASroute); return 0; }
int console_add_route(lua_State *L) { XBT_DEBUG("Adding route"); s_sg_platf_route_cbarg_t route; memset(&route,0,sizeof(route)); int type; /* allocating memory for the buffer, I think 2kB should be enough */ surfxml_bufferstack = xbt_new0(char, surfxml_bufferstack_size); lua_ensure(lua_istable(L, -1), "Bad Arguments to add a route. Should be a table with named arguments"); lua_pushstring(L,"src"); type = lua_gettable(L,-2); lua_ensure(type == LUA_TSTRING, "Attribute 'src' must be specified for any route and must be a string."); const char *srcName = lua_tostring(L, -1); route.src = sg_netcard_by_name_or_null(srcName); lua_ensure(route.src != nullptr, "Attribute 'src=%s' of route does not name a node.", srcName); lua_pop(L,1); lua_pushstring(L,"dest"); type = lua_gettable(L,-2); lua_ensure(type == LUA_TSTRING, "Attribute 'dest' must be specified for any route and must be a string."); const char *dstName = lua_tostring(L, -1); route.dst = sg_netcard_by_name_or_null(dstName); lua_ensure(route.dst != nullptr, "Attribute 'dst=%s' of route does not name a node.", dstName); lua_pop(L,1); lua_pushstring(L,"links"); type = lua_gettable(L,-2); lua_ensure(type == LUA_TSTRING, "Attribute 'links' must be specified for any route and must be a string (different links separated by commas or single spaces."); route.link_list = new std::vector<Link*>(); xbt_dynar_t names = xbt_str_split(lua_tostring(L, -1), ", \t\r\n"); if (xbt_dynar_is_empty(names)) { /* unique name */ route.link_list->push_back(Link::byName(lua_tostring(L, -1))); } else { // Several names separated by , \t\r\n unsigned int cpt; char *name; xbt_dynar_foreach(names, cpt, name) { if (strlen(name)>0) { Link *link = Link::byName(name); route.link_list->push_back(link); } } } 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. * * (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); if (lua_isstring(L, -1)) { const char* value = lua_tostring(L, -1); if (strcmp("YES", value) == 0) route.symmetrical = true; else route.symmetrical = false; } else { route.symmetrical = true; } lua_pop(L,1); route.gw_src = nullptr; route.gw_dst = nullptr; sg_platf_new_route(&route); return 0; }