const char* name = nullptr;
simgrid::s4u::Host* host = nullptr;
xbt_dict_foreach(host_list, cursor, name, host)
- if (host && host->pimpl_netcard && host->pimpl_netcard->getRcType() == SURF_NETWORK_ELEMENT_HOST)
+ if (host && host->pimpl_netcard && host->pimpl_netcard->isHost())
xbt_dynar_push(res, &host);
return res;
}
virtual void setId(int id)=0;
virtual char *name()=0;
virtual As *containingAS()=0; // This is the AS in which I am
- virtual e_surf_network_element_type_t getRcType()=0;
+ virtual bool isAS()=0;
+ virtual bool isHost()=0;
+ virtual bool isRouter()=0;
};
/** @ingroup SURF_routing_interface
* @brief Network Autonomous System (AS)
- * @details [TODO]
*/
class As {
public:
void setId(int id) override {id_ = id;}
char *name() override {return name_;}
As *containingAS() override {return containingAS_;}
- e_surf_network_element_type_t getRcType() override {return componentType_;}
+
+ bool isAS() override {return componentType_ == SURF_NETWORK_ELEMENT_AS;}
+ bool isHost() override {return componentType_ == SURF_NETWORK_ELEMENT_HOST;}
+ bool isRouter() override {return componentType_ == SURF_NETWORK_ELEMENT_ROUTER;}
+
private:
int id_ = -1;
char *name_;
return str;
}
-xbt_node_t new_xbt_graph_node(xbt_graph_t graph, const char *name,
- xbt_dict_t nodes)
+xbt_node_t new_xbt_graph_node(xbt_graph_t graph, const char *name, xbt_dict_t nodes)
{
xbt_node_t ret = (xbt_node_t) xbt_dict_get_or_null(nodes, name);
if (ret)
return ret;
}
-xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d,
- xbt_dict_t edges)
+xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d, xbt_dict_t edges)
{
- xbt_edge_t ret;
-
const char *sn = instr_node_name(s);
const char *dn = instr_node_name(d);
int len = strlen(sn) + strlen(dn) + 1;
snprintf(name, len, "%s%s", sn, dn);
- ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
+ xbt_edge_t ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
if (ret == NULL) {
snprintf(name, len, "%s%s", dn, sn);
ret = (xbt_edge_t) xbt_dict_get_or_null(edges, name);
xbt_assert(src, "Cannot add a route from %s to %s: %s does not exist.", srcName, dstName, srcName);
xbt_assert(dst, "Cannot add a route from %s to %s: %s does not exist.", srcName, dstName, dstName);
xbt_assert(!xbt_dynar_is_empty(route->link_list), "Empty route (between %s and %s) forbidden.", srcName, dstName);
- xbt_assert(src->getRcType()==SURF_NETWORK_ELEMENT_HOST || src->getRcType()==SURF_NETWORK_ELEMENT_ROUTER,
- "When defining a route, src must be an host or a router but '%s' is not. Did you meant to have an ASroute?", srcName);
- xbt_assert(dst->getRcType()==SURF_NETWORK_ELEMENT_HOST || dst->getRcType()==SURF_NETWORK_ELEMENT_ROUTER,
- "When defining a route, dst must be an host or a router but '%s' is not. Did you meant to have an ASroute?", dstName);
+ xbt_assert(! src->isAS(), "When defining a route, src cannot be an AS such as '%s'. Did you meant to have an ASroute?", srcName);
+ xbt_assert(! dst->isAS(), "When defining a route, dst cannot be an AS such as '%s'. Did you meant to have an ASroute?", dstName);
} else {
XBT_DEBUG("Load ASroute from %s@%s to %s@%s", srcName, route->gw_src->name(), dstName, route->gw_dst->name());
- xbt_assert(src->getRcType()==SURF_NETWORK_ELEMENT_AS,
- "When defining an ASroute, src must be an AS but '%s' is not", srcName);
- xbt_assert(dst->getRcType()==SURF_NETWORK_ELEMENT_AS,
- "When defining an ASroute, dst must be an AS but '%s' is not", dstName);
+ xbt_assert(src->isAS(), "When defining an ASroute, src must be an AS but '%s' is not", srcName);
+ xbt_assert(dst->isAS(), "When defining an ASroute, dst must be an AS but '%s' is not", dstName);
- xbt_assert(route->gw_src->getRcType()==SURF_NETWORK_ELEMENT_HOST || route->gw_src->getRcType()==SURF_NETWORK_ELEMENT_ROUTER,
+ xbt_assert(route->gw_src->isHost() || route->gw_src->isRouter(),
"When defining an ASroute, gw_src must be an host or a router but '%s' is not.", srcName);
- xbt_assert(route->gw_dst->getRcType()==SURF_NETWORK_ELEMENT_HOST || route->gw_dst->getRcType()==SURF_NETWORK_ELEMENT_ROUTER,
+ xbt_assert(route->gw_dst->isHost() || route->gw_dst->isRouter(),
"When defining an ASroute, gw_dst must be an host or a router but '%s' is not.", dstName);
xbt_assert(route->gw_src != route->gw_dst, "Cannot define an ASroute from '%s' to itself", route->gw_src->name());
XBT_VERB("cluster_get_route_and_latency from '%s'[%d] to '%s'[%d]",
src->name(), src->id(), dst->name(), dst->id());
- if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
+ if (! src->isRouter()) { // No specific link for router
if((src->id() == dst->id()) && has_loopback_ ){
info = xbt_dynar_get_as(upDownLinks, src->id() * nb_links_per_node_, s_surf_parsing_link_up_down_t);
*lat += backbone_->getLatency();
}
- if (dst->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) { // No specific link for router
+ if (! dst->isRouter()) { // No specific link for router
info = xbt_dynar_get_as(upDownLinks, dst->id() * nb_links_per_node_ + has_loopback_ + has_limiter_, s_surf_parsing_link_up_down_t);
if (info.link_down) { // link down
for (isrc = 0; isrc < table_size; isrc++) {
src = xbt_dynar_get_as(vertices_, isrc, NetCard*);
- if (src->getRcType() != SURF_NETWORK_ELEMENT_ROUTER) {
+ if (! src->isRouter()) {
previous = new_xbt_graph_node(graph, src->name(), nodes);
info = xbt_dynar_get_as(upDownLinks, src->id(), s_surf_parsing_link_up_down_t);
std::map<int, FatTreeNode*>::const_iterator tempIter;
-if (dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER) return;
+ if (dst->isRouter() || src->isRouter())
+ return;
/* Let's find the source and the destination in our internal structure */
tempIter = this->computeNodes_.find(src->id());
XBT_VERB("torus_get_route_and_latency from '%s'[%d] to '%s'[%d]",
src->name(), src->id(), dst->name(), dst->id());
- if (dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER)
+ if (dst->isRouter() || src->isRouter())
return;
if ((src->id() == dst->id()) && has_loopback_) {
XBT_DEBUG("vivaldi_get_route_and_latency from '%s'[%d] '%s'[%d]",
src->name(), src->id(), dst->name(), dst->id());
- if(src->getRcType() == SURF_NETWORK_ELEMENT_AS) {
+ if(src->isAS()) {
char *src_name = ROUTER_PEER(src->name());
char *dst_name = ROUTER_PEER(dst->name());
route->gw_src = (sg_netcard_t) xbt_lib_get_or_null(as_router_lib, src_name, ROUTING_ASR_LEVEL);
xbt_dynar_t src_ctn, dst_ctn;
char *tmp_src_name, *tmp_dst_name;
- if(src->getRcType() == SURF_NETWORK_ELEMENT_HOST){
+ if(src->isHost()){
tmp_src_name = HOST_PEER(src->name());
if ((int)xbt_dynar_length(upDownLinks)>src->id()) {
if (src_ctn == nullptr)
src_ctn = (xbt_dynar_t) simgrid::s4u::Host::by_name_or_create(src->name())->extension(COORD_HOST_LEVEL);
}
- else if(src->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || src->getRcType() == SURF_NETWORK_ELEMENT_AS){
+ else if(src->isRouter() || src->isAS()){
tmp_src_name = ROUTER_PEER(src->name());
src_ctn = (xbt_dynar_t) xbt_lib_get_or_null(as_router_lib, tmp_src_name, COORD_ASR_LEVEL);
}
THROW_IMPOSSIBLE;
}
- if(dst->getRcType() == SURF_NETWORK_ELEMENT_HOST){
+ if(dst->isHost()){
tmp_dst_name = HOST_PEER(dst->name());
if ((int)xbt_dynar_length(upDownLinks)>dst->id()) {
dst_ctn = (xbt_dynar_t) simgrid::s4u::Host::by_name_or_create(dst->name())
->extension(COORD_HOST_LEVEL);
}
- else if(dst->getRcType() == SURF_NETWORK_ELEMENT_ROUTER || dst->getRcType() == SURF_NETWORK_ELEMENT_AS){
+ else if(dst->isRouter() || dst->isAS()){
tmp_dst_name = ROUTER_PEER(dst->name());
dst_ctn = (xbt_dynar_t) xbt_lib_get_or_null(as_router_lib, tmp_dst_name, COORD_ASR_LEVEL);
}
$ ${bindir:=.}/is_router_test ./test_of_is_router.xml
> [0.000000] [xbt_cfg/INFO] Switching to the L07 model to handle parallel tasks.
-> Workstation number: 10, link number: 1, elmts number: 21
-> - Seen: "host01" is type : 1
-> - Seen: "host02" is type : 1
-> - Seen: "host03" is type : 1
-> - Seen: "host04" is type : 1
-> - Seen: "host05" is type : 1
-> - Seen: "host06" is type : 1
-> - Seen: "host07" is type : 1
-> - Seen: "host08" is type : 1
-> - Seen: "host09" is type : 1
-> - Seen: "host10" is type : 1
-> - Seen: "router1" is type : 2
-> - Seen: "router2" is type : 2
-> - Seen: "router3" is type : 2
-> - Seen: "router4" is type : 2
-> - Seen: "router5" is type : 2
-> - Seen: "AS0" is type : 3
-> - Seen: "AS1" is type : 3
-> - Seen: "AS2" is type : 3
-> - Seen: "AS3" is type : 3
-> - Seen: "AS4" is type : 3
-> - Seen: "AS" is type : 3
+> Host number: 10, link number: 1, elmts number: 21
+> - Seen: "host01". Type: host
+> - Seen: "host02". Type: host
+> - Seen: "host03". Type: host
+> - Seen: "host04". Type: host
+> - Seen: "host05". Type: host
+> - Seen: "host06". Type: host
+> - Seen: "host07". Type: host
+> - Seen: "host08". Type: host
+> - Seen: "host09". Type: host
+> - Seen: "host10". Type: host
+> - Seen: "router1". Type: router
+> - Seen: "router2". Type: router
+> - Seen: "router3". Type: router
+> - Seen: "router4". Type: router
+> - Seen: "router5". Type: router
+> - Seen: "AS0". Type: AS
+> - Seen: "AS1". Type: AS
+> - Seen: "AS2". Type: AS
+> - Seen: "AS3". Type: AS
+> - Seen: "AS4". Type: AS
+> - Seen: "AS". Type: AS
// Routers
xbt_lib_foreach(as_router_lib, cursor_src, key, value1) {
value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib, key, ROUTING_ASR_LEVEL);
- if(value1->getRcType() == SURF_NETWORK_ELEMENT_ROUTER) {
+ if(value1->isRouter()) {
printf(" <router id=\"%s\"/>\n",key);
}
}
}
xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
- if(value2->getRcType() == SURF_NETWORK_ELEMENT_ROUTER){
+ if(value2->isRouter()){
printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
xbt_dynar_t route=NULL;
routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
xbt_lib_foreach(as_router_lib, cursor_src, src, value1){ // Routes from router
value1 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,src,ROUTING_ASR_LEVEL);
- if (value1->getRcType() == SURF_NETWORK_ELEMENT_ROUTER){
+ if (value1->isRouter()){
xbt_lib_foreach(as_router_lib, cursor_dst, dst, value2){ //to router
value2 = (sg_netcard_t)xbt_lib_get_or_null(as_router_lib,dst,ROUTING_ASR_LEVEL);
- if(value2->getRcType() == SURF_NETWORK_ELEMENT_ROUTER){
+ if(value2->isRouter()){
printf(" <route src=\"%s\" dst=\"%s\">\n ", src, dst);
xbt_dynar_t route=NULL;
routing_platf->getRouteAndLatency((sg_netcard_t)value1,(sg_netcard_t)value2,&route,NULL);
size = xbt_dict_length(host_list) + xbt_lib_length(as_router_lib);
- printf("Workstation number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size);
+ printf("Host number: %zu, link number: %d, elmts number: %d\n", sg_host_count(), sg_link_count(), size);
- xbt_dict_foreach(host_list, cursor, key, data)
- printf(" - Seen: \"%s\" is type : %d\n", key, (int) sg_netcard_by_name_or_null(key)->getRcType());
+ xbt_dict_foreach(host_list, cursor, key, data) {
+ simgrid::surf::NetCard * nc = sg_netcard_by_name_or_null(key);
+ printf(" - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));
+ }
- xbt_lib_foreach(as_router_lib, cursor, key, data)
- printf(" - Seen: \"%s\" is type : %d\n", key, (int) sg_netcard_by_name_or_null(key)->getRcType());
+ xbt_lib_foreach(as_router_lib, cursor, key, data) {
+ simgrid::surf::NetCard * nc = sg_netcard_by_name_or_null(key);
+ printf(" - Seen: \"%s\". Type: %s\n", key, nc->isRouter() ? "router" : (nc->isAS()?"AS":"host"));
+ }
SD_exit();
return 0;