Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
finish the transition from C structures to C++ objects
authorMartin Quinson <martin.quinson@loria.fr>
Fri, 24 Feb 2017 15:54:26 +0000 (16:54 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Fri, 24 Feb 2017 15:56:00 +0000 (16:56 +0100)
Actually, we should stop using sg_platf_new_link and use
NetZone::createLink() but this later function is not ready yet.

And I don't want to revert the work of Fred so I'd better fix it.

src/bindings/lua/lua_platf.cpp
src/kernel/routing/ClusterZone.cpp
src/kernel/routing/DragonflyZone.cpp
src/kernel/routing/FatTreeZone.cpp
src/kernel/routing/TorusZone.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp

index 41f408c..f9f80a9 100644 (file)
@@ -61,16 +61,14 @@ int console_close(lua_State *L) {
 }
 
 int console_add_backbone(lua_State *L) {
 }
 
 int console_add_backbone(lua_State *L) {
-  s_sg_platf_link_cbarg_t link;
-  memset(&link,0,sizeof(link));
-  int type;
+  LinkCreationArgs link;
 
   link.properties = nullptr;
 
   lua_ensure(lua_istable(L, -1),"Bad Arguments to create backbone in Lua. Should be a table with named arguments.");
 
   lua_pushstring(L, "id");
 
   link.properties = nullptr;
 
   lua_ensure(lua_istable(L, -1),"Bad Arguments to create backbone in Lua. Should be a table with named arguments.");
 
   lua_pushstring(L, "id");
-  type = lua_gettable(L, -2);
+  int type = lua_gettable(L, -2);
   lua_ensure(type == LUA_TSTRING, "Attribute 'id' must be specified for backbone and must be a string.");
   link.id = lua_tostring(L, -1);
   lua_pop(L, 1);
   lua_ensure(type == LUA_TSTRING, "Attribute 'id' must be specified for backbone and must be a string.");
   link.id = lua_tostring(L, -1);
   lua_pop(L, 1);
@@ -79,14 +77,14 @@ int console_add_backbone(lua_State *L) {
   type = lua_gettable(L, -2);
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "Attribute 'bandwidth' must be specified for backbone and must either be a string (in the right format; see docs) or a number.");
   type = lua_gettable(L, -2);
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "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),"bandwidth of backbone",link.id);
+  link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1), "bandwidth of backbone", link.id.c_str());
   lua_pop(L, 1);
 
   lua_pushstring(L, "lat");
   type = lua_gettable(L, -2);
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "Attribute 'lat' must be specified for backbone and must either be a string (in the right format; see docs) or a number.");
   lua_pop(L, 1);
 
   lua_pushstring(L, "lat");
   type = lua_gettable(L, -2);
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "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),"latency of backbone",link.id);
+  link.latency = surf_parse_get_time(lua_tostring(L, -1), "latency of backbone", link.id.c_str());
   lua_pop(L, 1);
 
   lua_pushstring(L, "sharing_policy");
   lua_pop(L, 1);
 
   lua_pushstring(L, "sharing_policy");
@@ -101,7 +99,7 @@ int console_add_backbone(lua_State *L) {
   }
 
   sg_platf_new_link(&link);
   }
 
   sg_platf_new_link(&link);
-  routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(link.id));
+  routing_cluster_add_backbone(simgrid::surf::LinkImpl::byName(link.id.c_str()));
 
   return 0;
 }
 
   return 0;
 }
@@ -201,17 +199,15 @@ int console_add_host(lua_State *L) {
 }
 
 int  console_add_link(lua_State *L) {
 }
 
 int  console_add_link(lua_State *L) {
-  s_sg_platf_link_cbarg_t link;
-  memset(&link,0,sizeof(link));
+  LinkCreationArgs link;
 
 
-  int type;
   const char* policy;
 
   lua_ensure(lua_istable(L, -1), "Bad Arguments to create link, Should be a table with named arguments");
 
   // get Id Value
   lua_pushstring(L, "id");
   const char* policy;
 
   lua_ensure(lua_istable(L, -1), "Bad Arguments to create link, Should be a table with named arguments");
 
   // get Id Value
   lua_pushstring(L, "id");
-  type = lua_gettable(L, -2);
+  int type = lua_gettable(L, -2);
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "Attribute 'id' must be specified for any link and must be a string.");
   link.id = lua_tostring(L, -1);
   lua_ensure(type == LUA_TSTRING || type == LUA_TNUMBER,
       "Attribute 'id' must be specified for any link and must be a string.");
   link.id = lua_tostring(L, -1);
@@ -225,7 +221,7 @@ int  console_add_link(lua_State *L) {
   if (type == LUA_TNUMBER)
     link.bandwidth = lua_tonumber(L, -1);
   else // LUA_TSTRING
   if (type == LUA_TNUMBER)
     link.bandwidth = lua_tonumber(L, -1);
   else // LUA_TSTRING
-    link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1),"bandwidth of link", link.id);
+    link.bandwidth = surf_parse_get_bandwidth(lua_tostring(L, -1), "bandwidth of link", link.id.c_str());
   lua_pop(L, 1);
 
   //get latency value
   lua_pop(L, 1);
 
   //get latency value
@@ -236,7 +232,7 @@ int  console_add_link(lua_State *L) {
   if (type == LUA_TNUMBER)
     link.latency = lua_tonumber(L, -1);
   else // LUA_TSTRING
   if (type == LUA_TNUMBER)
     link.latency = lua_tonumber(L, -1);
   else // LUA_TSTRING
-    link.latency = surf_parse_get_time(lua_tostring(L, -1),"latency of link", link.id);
+    link.latency = surf_parse_get_time(lua_tostring(L, -1), "latency of link", link.id.c_str());
   lua_pop(L, 1);
 
   /*Optional Arguments  */
   lua_pop(L, 1);
 
   /*Optional Arguments  */
index 19cd4e9..b3363f9 100644 (file)
@@ -123,8 +123,7 @@ void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id
 {
   char* link_id = bprintf("%s_link_%d", cluster->id, id);
 
 {
   char* link_id = bprintf("%s_link_%d", cluster->id, id);
 
-  s_sg_platf_link_cbarg_t link;
-  memset(&link, 0, sizeof(link));
+  LinkCreationArgs link;
   link.id        = link_id;
   link.bandwidth = cluster->bw;
   link.latency   = cluster->lat;
   link.id        = link_id;
   link.bandwidth = cluster->bw;
   link.latency   = cluster->lat;
@@ -145,7 +144,6 @@ void ClusterZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id
     linkDown = linkUp;
   }
   privateLinks_.insert({position, {linkUp, linkDown}});
     linkDown = linkUp;
   }
   privateLinks_.insert({position, {linkUp, linkDown}});
-  xbt_free(link_id);
 }
 }
 }
 }
 }
 }
index 3e68e8e..12dd63c 100644 (file)
@@ -138,8 +138,7 @@ void DragonflyZone::createLink(char* id, int numlinks, surf::LinkImpl** linkup,
 {
   *linkup   = nullptr;
   *linkdown = nullptr;
 {
   *linkup   = nullptr;
   *linkdown = nullptr;
-  s_sg_platf_link_cbarg_t linkTemplate;
-  memset(&linkTemplate, 0, sizeof(linkTemplate));
+  LinkCreationArgs linkTemplate;
   linkTemplate.bandwidth = this->cluster_->bw * numlinks;
   linkTemplate.latency   = this->cluster_->lat;
   linkTemplate.policy    = this->cluster_->sharing_policy; // sthg to do with that ?
   linkTemplate.bandwidth = this->cluster_->bw * numlinks;
   linkTemplate.latency   = this->cluster_->lat;
   linkTemplate.policy    = this->cluster_->sharing_policy; // sthg to do with that ?
index b74a6cb..702655b 100644 (file)
@@ -430,9 +430,8 @@ void FatTreeZone::generateDotFile(const std::string& filename) const
 FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, int position)
     : id(id), level(level), position(position)
 {
 FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, int position)
     : id(id), level(level), position(position)
 {
-  s_sg_platf_link_cbarg_t linkTemplate;
+  LinkCreationArgs linkTemplate;
   if (cluster->limiter_link) {
   if (cluster->limiter_link) {
-    memset(&linkTemplate, 0, sizeof(linkTemplate));
     linkTemplate.bandwidth = cluster->limiter_link;
     linkTemplate.latency   = 0;
     linkTemplate.policy    = SURF_LINK_SHARED;
     linkTemplate.bandwidth = cluster->limiter_link;
     linkTemplate.latency   = 0;
     linkTemplate.policy    = SURF_LINK_SHARED;
@@ -441,7 +440,6 @@ FatTreeNode::FatTreeNode(sg_platf_cluster_cbarg_t cluster, int id, int level, in
     this->limiterLink = surf::LinkImpl::byName(linkTemplate.id.c_str());
   }
   if (cluster->loopback_bw || cluster->loopback_lat) {
     this->limiterLink = surf::LinkImpl::byName(linkTemplate.id.c_str());
   }
   if (cluster->loopback_bw || cluster->loopback_lat) {
-    memset(&linkTemplate, 0, sizeof(linkTemplate));
     linkTemplate.bandwidth = cluster->loopback_bw;
     linkTemplate.latency   = cluster->loopback_lat;
     linkTemplate.policy    = SURF_LINK_FATPIPE;
     linkTemplate.bandwidth = cluster->loopback_bw;
     linkTemplate.latency   = cluster->loopback_lat;
     linkTemplate.policy    = SURF_LINK_FATPIPE;
@@ -455,13 +453,12 @@ FatTreeLink::FatTreeLink(sg_platf_cluster_cbarg_t cluster, FatTreeNode* downNode
     : upNode(upNode), downNode(downNode)
 {
   static int uniqueId = 0;
     : upNode(upNode), downNode(downNode)
 {
   static int uniqueId = 0;
-  s_sg_platf_link_cbarg_t linkTemplate;
-  memset(&linkTemplate, 0, sizeof(linkTemplate));
+  LinkCreationArgs linkTemplate;
   linkTemplate.bandwidth = cluster->bw;
   linkTemplate.latency   = cluster->lat;
   linkTemplate.policy    = cluster->sharing_policy; // sthg to do with that ?
   linkTemplate.bandwidth = cluster->bw;
   linkTemplate.latency   = cluster->lat;
   linkTemplate.policy    = cluster->sharing_policy; // sthg to do with that ?
-  linkTemplate.id        =
-      "link_from_" + std::to_string( downNode->id) + "_" + std::to_string(upNode->id) + "_" + std::to_string(uniqueId);
+  linkTemplate.id =
+      "link_from_" + std::to_string(downNode->id) + "_" + std::to_string(upNode->id) + "_" + std::to_string(uniqueId);
   sg_platf_new_link(&linkTemplate);
 
   if (cluster->sharing_policy == SURF_LINK_FULLDUPLEX) {
   sg_platf_new_link(&linkTemplate);
 
   if (cluster->sharing_policy == SURF_LINK_FULLDUPLEX) {
index f632e6e..f7c80c9 100644 (file)
@@ -48,8 +48,7 @@ void TorusZone::create_links_for_node(sg_platf_cluster_cbarg_t cluster, int id,
   int dim_product = 1; // Needed to calculate the next neighbor_id
   for (unsigned int j = 0; j < xbt_dynar_length(dimensions_); j++) {
 
   int dim_product = 1; // Needed to calculate the next neighbor_id
   for (unsigned int j = 0; j < xbt_dynar_length(dimensions_); j++) {
 
-    s_sg_platf_link_cbarg_t link;
-    memset(&link, 0, sizeof(link));
+    LinkCreationArgs link;
     current_dimension = xbt_dynar_get_as(dimensions_, j, int);
     neighbor_rank_id  = ((static_cast<int>(rank) / dim_product) % current_dimension == current_dimension - 1)
                            ? rank - (current_dimension - 1) * dim_product
     current_dimension = xbt_dynar_get_as(dimensions_, j, int);
     neighbor_rank_id  = ((static_cast<int>(rank) / dim_product) % current_dimension == current_dimension - 1)
                            ? rank - (current_dimension - 1) * dim_product
index 33d727a..bb4d2e8 100644 (file)
@@ -115,7 +115,8 @@ simgrid::kernel::routing::NetPoint* sg_platf_new_router(const char* name, const
   return netpoint;
 }
 
   return netpoint;
 }
 
-void sg_platf_new_link(sg_platf_link_cbarg_t link){
+void sg_platf_new_link(LinkCreationArgs* link)
+{
   std::vector<std::string> names;
 
   if (link->policy == SURF_LINK_FULLDUPLEX) {
   std::vector<std::string> names;
 
   if (link->policy == SURF_LINK_FULLDUPLEX) {
@@ -154,7 +155,6 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
 
   int rankId=0;
 
 
   int rankId=0;
 
-  s_sg_platf_link_cbarg_t link;
 
   // What an inventive way of initializing the AS that I have as ancestor :-(
   s_sg_platf_AS_cbarg_t AS;
 
   // What an inventive way of initializing the AS that I have as ancestor :-(
   s_sg_platf_AS_cbarg_t AS;
@@ -228,7 +228,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
       char *tmp_link = bprintf("%s_loopback", link_id);
       XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->loopback_bw);
 
       char *tmp_link = bprintf("%s_loopback", link_id);
       XBT_DEBUG("<loopback\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->loopback_bw);
 
-      memset(&link, 0, sizeof(link));
+      LinkCreationArgs link;
       link.id        = tmp_link;
       link.bandwidth = cluster->loopback_bw;
       link.latency   = cluster->loopback_lat;
       link.id        = tmp_link;
       link.bandwidth = cluster->loopback_bw;
       link.latency   = cluster->loopback_lat;
@@ -249,7 +249,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
       char *tmp_link = bprintf("%s_limiter", link_id);
       XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->limiter_link);
 
       char *tmp_link = bprintf("%s_limiter", link_id);
       XBT_DEBUG("<limiter\tid=\"%s\"\tbw=\"%f\"/>", tmp_link, cluster->limiter_link);
 
-      memset(&link, 0, sizeof(link));
+      LinkCreationArgs link;
       link.id = tmp_link;
       link.bandwidth = cluster->limiter_link;
       link.latency = 0;
       link.id = tmp_link;
       link.bandwidth = cluster->limiter_link;
       link.latency = 0;
@@ -288,7 +288,7 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
   //Make the backbone
   if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
 
   //Make the backbone
   if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
 
-    memset(&link, 0, sizeof(link));
+    LinkCreationArgs link;
     link.id        = std::string(cluster->id)+ "_backbone";
     link.bandwidth = cluster->bb_bw;
     link.latency   = cluster->bb_lat;
     link.id        = std::string(cluster->id)+ "_backbone";
     link.bandwidth = cluster->bb_bw;
     link.latency   = cluster->bb_lat;
@@ -331,8 +331,7 @@ void sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet)
     host.speed_per_pstate.push_back(cabinet->speed);
     sg_platf_new_host(&host);
 
     host.speed_per_pstate.push_back(cabinet->speed);
     sg_platf_new_host(&host);
 
-    s_sg_platf_link_cbarg_t link;
-    memset(&link, 0, sizeof(link));
+    LinkCreationArgs link;
     link.policy    = SURF_LINK_FULLDUPLEX;
     link.latency   = cabinet->lat;
     link.bandwidth = cabinet->bw;
     link.policy    = SURF_LINK_FULLDUPLEX;
     link.latency   = cabinet->lat;
     link.bandwidth = cabinet->bw;
index bd8a1b6..092e81c 100644 (file)
@@ -57,16 +57,17 @@ typedef struct {
   const char* link_down;
 } s_sg_platf_host_link_cbarg_t, *sg_platf_host_link_cbarg_t;
 
   const char* link_down;
 } s_sg_platf_host_link_cbarg_t, *sg_platf_host_link_cbarg_t;
 
-typedef struct {
+class LinkCreationArgs {
+public:
   std::string id;
   std::string id;
-  double bandwidth;
-  tmgr_trace_t bandwidth_trace;
-  double latency;
-  tmgr_trace_t latency_trace;
-  tmgr_trace_t state_trace;
-  e_surf_link_sharing_policy_t policy;
-  xbt_dict_t properties;
-} s_sg_platf_link_cbarg_t, *sg_platf_link_cbarg_t;
+  double bandwidth                    = 0;
+  tmgr_trace_t bandwidth_trace        = nullptr;
+  double latency                      = 0;
+  tmgr_trace_t latency_trace          = nullptr;
+  tmgr_trace_t state_trace            = nullptr;
+  e_surf_link_sharing_policy_t policy = SURF_LINK_FATPIPE;
+  xbt_dict_t properties               = nullptr;
+};
 
 typedef struct s_sg_platf_peer_cbarg *sg_platf_peer_cbarg_t;
 typedef struct s_sg_platf_peer_cbarg {
 
 typedef struct s_sg_platf_peer_cbarg *sg_platf_peer_cbarg_t;
 typedef struct s_sg_platf_peer_cbarg {
@@ -202,7 +203,7 @@ XBT_PUBLIC(void) sg_platf_new_host   (sg_platf_host_cbarg_t   host);   // Add an
 XBT_PUBLIC(void) sg_platf_new_hostlink(sg_platf_host_link_cbarg_t h); // Add an host_link to the currently described AS
 XBT_PUBLIC(simgrid::kernel::routing::NetPoint*)
 sg_platf_new_router(const char* name, const char* coords);             // Add a router  to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_hostlink(sg_platf_host_link_cbarg_t h); // Add an host_link to the currently described AS
 XBT_PUBLIC(simgrid::kernel::routing::NetPoint*)
 sg_platf_new_router(const char* name, const char* coords);             // Add a router  to the currently described AS
-XBT_PUBLIC(void) sg_platf_new_link   (sg_platf_link_cbarg_t link);     // Add a link    to the currently described AS
+XBT_PUBLIC(void) sg_platf_new_link(LinkCreationArgs* link);            // Add a link    to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_peer   (sg_platf_peer_cbarg_t peer);     // Add a peer    to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_cluster(sg_platf_cluster_cbarg_t clust); // Add a cluster to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet); // Add a cabinet to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_peer   (sg_platf_peer_cbarg_t peer);     // Add a peer    to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_cluster(sg_platf_cluster_cbarg_t clust); // Add a cluster to the currently described AS
 XBT_PUBLIC(void) sg_platf_new_cabinet(sg_platf_cabinet_cbarg_t cabinet); // Add a cabinet to the currently described AS
index 274a939..f855907 100644 (file)
@@ -652,8 +652,7 @@ void STag_surfxml_link(){
 }
 
 void ETag_surfxml_link(){
 }
 
 void ETag_surfxml_link(){
-  s_sg_platf_link_cbarg_t link;
-  memset(&link,0,sizeof(link));
+  LinkCreationArgs link;
 
   link.properties          = current_property_set;
   current_property_set     = nullptr;
 
   link.properties          = current_property_set;
   current_property_set     = nullptr;
@@ -711,8 +710,7 @@ void STag_surfxml_link___ctn(){
 }
 
 void ETag_surfxml_backbone(){
 }
 
 void ETag_surfxml_backbone(){
-  s_sg_platf_link_cbarg_t link;
-  memset(&link,0,sizeof(link));
+  LinkCreationArgs link;
 
   link.properties = nullptr;
   link.id = std::string(A_surfxml_backbone_id);
 
   link.properties = nullptr;
   link.id = std::string(A_surfxml_backbone_id);