Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
remove the s_sg_platf_router_cbarg_t structure
authorMartin Quinson <martin.quinson@loria.fr>
Mon, 2 Jan 2017 13:49:16 +0000 (14:49 +0100)
committerMartin Quinson <martin.quinson@loria.fr>
Mon, 2 Jan 2017 13:49:20 +0000 (14:49 +0100)
This is one of the many structures provided by the sg_platf interface,
that I want to replace with the s4u interface.

src/bindings/lua/lua_platf.cpp
src/surf/instr_routing.cpp
src/surf/sg_platf.cpp
src/surf/xml/platf_private.hpp
src/surf/xml/surfxml_sax_cb.cpp

index 7398ed7..c662f75 100644 (file)
@@ -286,25 +286,21 @@ int  console_add_link(lua_State *L) {
  * add Router to AS components
  */
 int console_add_router(lua_State* L) {
-  s_sg_platf_router_cbarg_t router;
-  memset(&router,0,sizeof(router));
-  int type;
-
   lua_ensure(lua_istable(L, -1),
       "Bad Arguments to create router, 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 any link and must be a string.");
-  router.id = lua_tostring(L, -1);
+  const char* name = lua_tostring(L, -1);
   lua_pop(L,1);
 
   lua_pushstring(L,"coord");
   lua_gettable(L,-2);
-  router.coord = lua_tostring(L, -1);
+  const char* coords = lua_tostring(L, -1);
   lua_pop(L,1);
 
-  sg_platf_new_router(&router);
+  sg_platf_new_router(name, coords);
 
   return 0;
 }
index 2eb79f7..43bfc41 100644 (file)
@@ -297,10 +297,10 @@ void sg_instr_new_host(simgrid::s4u::Host& host)
 
 }
 
-void sg_instr_new_router(sg_platf_router_cbarg_t router)
+void sg_instr_new_router(const char* name, const char* coords)
 {
   container_t father = currentContainer.back();
-  PJ_container_new (router->id, INSTR_ROUTER, father);
+  PJ_container_new(name, INSTR_ROUTER, father);
 }
 
 static void instr_routing_parse_end_platform ()
index 8742488..fa37309 100644 (file)
@@ -96,24 +96,26 @@ void sg_platf_new_host(sg_platf_host_cbarg_t args)
 }
 
 /** @brief Add a "router" to the network element list */
-void sg_platf_new_router(sg_platf_router_cbarg_t router)
+simgrid::kernel::routing::NetCard* sg_platf_new_router(const char* name, const char* coords)
 {
   simgrid::kernel::routing::NetZoneImpl* current_routing = routing_get_current();
 
   if (current_routing->hierarchy_ == simgrid::kernel::routing::NetZoneImpl::RoutingMode::unset)
     current_routing->hierarchy_ = simgrid::kernel::routing::NetZoneImpl::RoutingMode::base;
-  xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(router->id),
-             "Refusing to create a router named '%s': this name already describes a node.", router->id);
+  xbt_assert(nullptr == simgrid::s4u::Engine::instance()->netcardByNameOrNull(name),
+             "Refusing to create a router named '%s': this name already describes a node.", name);
 
   simgrid::kernel::routing::NetCard* netcard =
-    new simgrid::kernel::routing::NetCard(router->id, simgrid::kernel::routing::NetCard::Type::Router, current_routing);
-  XBT_DEBUG("Router '%s' has the id %d", router->id, netcard->id());
+      new simgrid::kernel::routing::NetCard(name, simgrid::kernel::routing::NetCard::Type::Router, current_routing);
+  XBT_DEBUG("Router '%s' has the id %d", name, netcard->id());
 
-  if (router->coord && strcmp(router->coord, ""))
-    new simgrid::kernel::routing::vivaldi::Coords(netcard, router->coord);
+  if (coords && strcmp(coords, ""))
+    new simgrid::kernel::routing::vivaldi::Coords(netcard, coords);
 
   if (TRACE_is_enabled() && TRACE_needs_platform())
-    sg_instr_new_router(router);
+    sg_instr_new_router(name, coords);
+
+  return netcard;
 }
 
 void sg_platf_new_link(sg_platf_link_cbarg_t link){
@@ -279,15 +281,13 @@ void sg_platf_new_cluster(sg_platf_cluster_cbarg_t cluster)
   // Add a router.
   XBT_DEBUG(" ");
   XBT_DEBUG("<router id=\"%s\"/>", cluster->router_id);
-  char *newid = nullptr;
-  s_sg_platf_router_cbarg_t router;
-  memset(&router, 0, sizeof(router));
-  router.id = cluster->router_id;
-  if (!router.id || !strcmp(router.id, ""))
-    router.id = newid = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix);
-  sg_platf_new_router(&router);
-  current_as->router_ = simgrid::s4u::Engine::instance()->netcardByNameOrNull(router.id);
-  free(newid);
+  if (!cluster->router_id || !strcmp(cluster->router_id, "")) {
+    char* newid         = bprintf("%s%s_router%s", cluster->prefix, cluster->id, cluster->suffix);
+    current_as->router_ = sg_platf_new_router(newid, NULL);
+    free(newid);
+  } else {
+    current_as->router_ = sg_platf_new_router(cluster->router_id, NULL);
+  }
 
   //Make the backbone
   if ((cluster->bb_bw != 0) || (cluster->bb_lat != 0)) {
index e604e46..dbbe39b 100644 (file)
@@ -56,11 +56,6 @@ typedef struct {
   const char* link_down;
 } s_sg_platf_host_link_cbarg_t, *sg_platf_host_link_cbarg_t;
 
-typedef struct {
-  const char* id;
-  const char* coord;
-} s_sg_platf_router_cbarg_t, *sg_platf_router_cbarg_t;
-
 typedef struct {
   const char* id;
   double bandwidth;
@@ -204,7 +199,8 @@ XBT_PUBLIC(void) sg_platf_new_AS_seal();                     // That AS is fully
 
 XBT_PUBLIC(void) sg_platf_new_host   (sg_platf_host_cbarg_t   host);   // Add an host   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(void) sg_platf_new_router (sg_platf_router_cbarg_t router); // Add a router  to the currently described AS
+XBT_PUBLIC(simgrid::kernel::routing::NetCard*)
+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_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
@@ -244,7 +240,7 @@ XBT_PUBLIC_DATA(int) surfxml_bufferstack_size;
 XBT_PUBLIC(void) routing_route_free(sg_platf_route_cbarg_t route);
 /********** Instr. **********/
 XBT_PRIVATE void sg_instr_AS_begin(sg_platf_AS_cbarg_t AS);
-XBT_PRIVATE void sg_instr_new_router(sg_platf_router_cbarg_t router);
+XBT_PRIVATE void sg_instr_new_router(const char* name, const char* coords);
 XBT_PRIVATE void sg_instr_new_host(simgrid::s4u::Host& host);
 XBT_PRIVATE void sg_instr_AS_end();
 
index d9a4c52..8e5a7cd 100644 (file)
@@ -523,13 +523,7 @@ void STag_surfxml_host___link(){
 }
 
 void STag_surfxml_router(){
-  s_sg_platf_router_cbarg_t router;
-  memset(&router, 0, sizeof(router));
-
-  router.id    = A_surfxml_router_id;
-  router.coord = A_surfxml_router_coordinates;
-
-  sg_platf_new_router(&router);
+  sg_platf_new_router(A_surfxml_router_id, A_surfxml_router_coordinates);
 }
 
 void ETag_surfxml_cluster(){