Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
nicer API to the Netcard type
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 26 Feb 2016 22:21:48 +0000 (23:21 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 26 Feb 2016 22:21:48 +0000 (23:21 +0100)
src/simgrid/host.cpp
src/surf/surf_routing.hpp
src/surf/surf_routing_RoutedGraph.cpp
src/surf/surf_routing_cluster.cpp
src/surf/surf_routing_cluster_fat_tree.cpp
src/surf/surf_routing_cluster_torus.cpp
src/surf/surf_routing_vivaldi.cpp
teshsuite/simdag/platforms/basic_parsing_test.tesh
teshsuite/simdag/platforms/flatifier.cpp
teshsuite/simdag/platforms/is_router_test.cpp

index 99aa45e..98049d9 100644 (file)
@@ -68,7 +68,7 @@ xbt_dynar_t sg_hosts_as_dynar(void)
   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;
 }
index c3b614b..0ac0fa3 100644 (file)
@@ -47,12 +47,13 @@ public:
   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:
@@ -126,7 +127,11 @@ 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_;
index 6af5f56..9f2e501 100644 (file)
@@ -54,8 +54,7 @@ static const char *instr_node_name(xbt_node_t node)
   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)
@@ -66,11 +65,8 @@ xbt_node_t new_xbt_graph_node(xbt_graph_t graph, const char *name,
   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;
@@ -78,7 +74,7 @@ xbt_edge_t new_xbt_graph_edge(xbt_graph_t graph, xbt_node_t s, xbt_node_t d,
 
 
   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);
@@ -226,20 +222,16 @@ void AsRoutedGraph::addRouteCheckParams(sg_platf_route_cbarg_t route) {
     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());
index be5d606..81848c2 100644 (file)
@@ -24,7 +24,7 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
   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);
@@ -56,7 +56,7 @@ void AsCluster::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
       *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
@@ -96,7 +96,7 @@ void AsCluster::getGraph(xbt_graph_t graph, xbt_dict_t nodes, xbt_dict_t edges)
   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);
index 93ba4eb..5eecd34 100644 (file)
@@ -66,7 +66,8 @@ void AsClusterFatTree::getRouteAndLatency(NetCard *src,
 
   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());
index 8cd9b74..2d08077 100644 (file)
@@ -115,7 +115,7 @@ namespace simgrid {
       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_) {
index 377c13f..985af5b 100644 (file)
@@ -35,7 +35,7 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
   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);
@@ -48,7 +48,7 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
   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()) {
@@ -63,7 +63,7 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
     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);
   }
@@ -71,7 +71,7 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
     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()) {
@@ -88,7 +88,7 @@ void AsVivaldi::getRouteAndLatency(NetCard *src, NetCard *dst, sg_platf_route_cb
       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);
   }
index c6be629..b41132b 100644 (file)
@@ -58,26 +58,26 @@ $ rm -f ./bob0_availability_file.trace ./bob2_availability_file.trace ./bob0_sta
 
 $ ${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
 
index 6b347b7..690a21d 100644 (file)
@@ -131,7 +131,7 @@ int main(int argc, char **argv)
     // 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);
       }
     }
@@ -175,7 +175,7 @@ int main(int argc, char **argv)
       }
       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);
@@ -190,10 +190,10 @@ int main(int argc, char **argv)
 
     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);
index fbe96d0..1579d0c 100644 (file)
@@ -24,13 +24,17 @@ int main(int argc, char **argv)
 
   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;