Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
adapt to lastest changes in GRAS API
[simgrid.git] / src / amok / Bandwidth / saturate.c
index 78b4464..fe15223 100644 (file)
@@ -36,16 +36,12 @@ void amok_bw_sat_init(void) {
 
 }
 void amok_bw_sat_join(void) {
-  gras_cb_register(gras_msgtype_by_name("amok_bw_sat start"),
-                  &amok_bw_cb_sat_start);
-  gras_cb_register(gras_msgtype_by_name("amok_bw_sat begin"),
-                  &amok_bw_cb_sat_begin);
+  gras_cb_register("amok_bw_sat start", &amok_bw_cb_sat_start);
+  gras_cb_register("amok_bw_sat begin", &amok_bw_cb_sat_begin);
 }
 void amok_bw_sat_leave(void) {
-  gras_cb_unregister(gras_msgtype_by_name("amok_bw_sat start"),
-                    &amok_bw_cb_sat_start);
-  gras_cb_unregister(gras_msgtype_by_name("amok_bw_sat begin"),
-                    &amok_bw_cb_sat_begin);
+  gras_cb_unregister("amok_bw_sat start", &amok_bw_cb_sat_start);
+  gras_cb_unregister("amok_bw_sat begin", &amok_bw_cb_sat_begin);
 }
 
 /* ***************************************************************************
@@ -71,10 +67,10 @@ void amok_bw_saturate_start(const char* from_name,unsigned int from_port,
                            const char* to_name,unsigned int to_port,
                            unsigned int msg_size, double duration) {
   gras_socket_t sock;
-  xbt_ex_t e;
   sat_request_t request = xbt_new(s_sat_request_t,1);
 
-  INFO2("from_name %s // to_name %s \n",from_name,to_name); 
+  VERB4("Start from_name %s:%d -> to_name %s:%d",
+       from_name, from_port, to_name, to_port);
   sock = gras_socket_client(from_name,from_port);
 
   request->peer.name = (char*)to_name;
@@ -83,14 +79,8 @@ void amok_bw_saturate_start(const char* from_name,unsigned int from_port,
   request->duration=duration;
   request->msg_size=msg_size;
 
- TRY{
-  gras_msg_rpccall(sock,60,gras_msgtype_by_name("amok_bw_sat start"),&request, NULL);
+  gras_msg_rpccall(sock,60,"amok_bw_sat start",&request, NULL);
 
-  }CATCH(e){
-    if (e.value==1)
-      THROW1(0,1,"%s",to_name);
-    THROW1(0,0,"%s",from_name);
-  }
   free(request);
   gras_socket_close(sock);
 }
@@ -100,28 +90,21 @@ static int amok_bw_cb_sat_start(gras_msg_cb_ctx_t ctx, void *payload){
   sat_request_t request = *(sat_request_t*)payload;
   gras_socket_t expeditor = gras_msg_cb_ctx_from(ctx);
  
-  xbt_ex_t e;
-
   VERB4("Asked by %s:%d to start a saturation to %s:%d",
        gras_socket_peer_name(expeditor),gras_socket_peer_port(expeditor),
        request->peer.name,request->peer.port);
        
   gras_msg_rpcreturn(60,ctx, NULL);
 
-TRY{
   amok_bw_saturate_begin(request->peer.name,request->peer.port,
 
                         request->msg_size, request->duration,
                         NULL,NULL);
-
-  }CATCH(e){
-     THROW1(0,1," can not connect %s ",((request)->peer.name));
-  }
  
   free(request->peer.name);
 
   free(request);
-  return 1;
+  return 0;
 }
 
 /**
@@ -142,7 +125,7 @@ void amok_bw_saturate_begin(const char* to_name,unsigned int to_port,
  
   xbt_ex_t e;
 
-  gras_socket_t peer_cmd; //= gras_socket_client(to_name, to_port);
+  gras_socket_t peer_cmd = gras_socket_client(to_name, to_port);
   gras_msg_cb_ctx_t ctx;
 
   gras_socket_t meas;
@@ -172,7 +155,9 @@ void amok_bw_saturate_begin(const char* to_name,unsigned int to_port,
     double bw;
     double sec;
     amok_bw_test(peer_cmd,
-                0,512*1024, 512*1024, /* 512k as first guess */
+                0, /* check buffsize yourself */
+                512*1024,  /* 512k as first guess */
+                1, /* One packet only */
                 1, /* at least one sec */
                 &sec, &bw);
     msg_size = request->msg_size = (int)bw;
@@ -181,9 +166,7 @@ void amok_bw_saturate_begin(const char* to_name,unsigned int to_port,
    
   /* Launch the saturation */
 
-  ctx = gras_msg_rpc_async_call(peer_cmd, 60, 
-                               gras_msgtype_by_name("amok_bw_sat begin"),
-                                                 &request);
+  ctx = gras_msg_rpc_async_call(peer_cmd, 60, "amok_bw_sat begin", &request);
   free(request);
   gras_msg_rpc_async_wait(ctx,&request);
   meas=gras_socket_client_ext( to_name, request->peer.port,
@@ -193,20 +176,20 @@ void amok_bw_saturate_begin(const char* to_name,unsigned int to_port,
   free(request);
 
   gras_socket_close(peer_cmd);
-  INFO2("Saturation(%s->%s) started",gras_os_myname(),to_name);
+  INFO4("Saturation(%s:%d->%s:%d) started",gras_os_myname(),gras_os_myport(),to_name,to_port);
 
   /* Start experiment */
   start=gras_os_time();
 
   do {
     /* do send it */
-    gras_socket_meas_send(meas,120,msg_size,msg_size);
+    gras_socket_meas_send(meas, 120, msg_size, 1);
     packet_sent++;
 
     /* Check whether someone asked us to stop saturation */
     saturate_further = 0;
     TRY {
-      gras_msg_wait_ext(0/*no wait*/,gras_msgtype_by_name("amok_bw_sat stop"),
+      gras_msg_wait_ext(0/*no wait*/,"amok_bw_sat stop",
                        NULL /* accept any sender */,
                        NULL, NULL, /* No specific filter */
                        &msg_got);
@@ -236,8 +219,8 @@ void amok_bw_saturate_begin(const char* to_name,unsigned int to_port,
     bw_res_t answer = xbt_new(s_bw_res_t,1);
     s_gras_msg_cb_ctx_t ctx;
 
-    INFO3("Saturation from %s to %s stopped by %s",
-         gras_os_myname(),to_name, gras_socket_peer_name(msg_got.expe));
+    INFO6("Saturation from %s:%d to %s:%d stopped by %s:%d",
+         gras_os_myname(),gras_os_myport(),to_name,to_port, gras_socket_peer_name(msg_got.expe),gras_socket_peer_port(msg_got.expe));
     answer->timestamp=gras_os_time();
     answer->sec=elapsed;
     answer->bw=bw;
@@ -249,8 +232,8 @@ void amok_bw_saturate_begin(const char* to_name,unsigned int to_port,
     gras_msg_rpcreturn(60,&ctx,&answer);
     free(answer);
   } else {
-    INFO4("Saturation from %s to %s elapsed after %f sec (achieving %f kb/s)",
-         gras_os_myname(),to_name,elapsed,bw/1024.0);
+    INFO6("Saturation from %s:%d to %s:%d elapsed after %f sec (achieving %f kb/s)",
+         gras_os_myname(),gras_os_myport(),to_name,to_port,elapsed,bw/1024.0);
   }
   
   gras_socket_close(meas);
@@ -298,21 +281,21 @@ static int amok_bw_cb_sat_begin(gras_msg_cb_ctx_t ctx, void *payload){
 
   while (saturate_further) {
     TRY {
-      gras_socket_meas_recv(meas,5,request->msg_size,request->msg_size);
+      gras_socket_meas_recv(meas, 5, request->msg_size, 1);
     } CATCH(e) {
       saturate_further = 0;
       xbt_ex_free(e);
     }
   }
-  INFO3("Saturation comming from %s:%d stopped on %s",
+  INFO4("Saturation comming from %s:%d stopped on %s:%d",
        gras_socket_peer_name(from),gras_socket_peer_port(from),
-       gras_os_myname());
+       gras_os_myname(),gras_os_myport());
 
   gras_socket_close(meas);
   if (gras_if_RL()) /* On SG, accepted=master */
     gras_socket_close(measMaster); 
   free(request);
-  return 1;
+  return 0;
 }
 
 /**
@@ -331,7 +314,7 @@ void amok_bw_saturate_stop(const char* from_name,unsigned int from_port,
   bw_res_t answer;
   VERB2("Ask %s:%d to stop the saturation",from_name,from_port);
   TRY {        
-     gras_msg_rpccall(sock,60,gras_msgtype_by_name("amok_bw_sat stop"),NULL,&answer);
+     gras_msg_rpccall(sock,60,"amok_bw_sat stop",NULL,&answer);
   } CATCH(e) {
      RETHROW2("Cannot ask %s:%d to stop saturation: %s",from_name, from_port);
   }