- /* Handle the SAT_STOP which broke the previous while */
-
- if ((errcode=gras_msg_new_and_send(sock, GRASMSG_SAT_END,0))) {
- fprintf(stderr,"cbSatStart(): Cannot tell peer to stop saturation\n");
-
- grasRepportError(msg->sock,GRASMSG_SAT_STOPPED,1,
- "cbSatStart: Severe error: Cannot send error status to requester!!\n",
- errcode,"Sending SAT_END to peer failed.\n");
- gras_sock_close(sock);
- gras_rawsock_close(raw);
- return 1;
+ /* Negociate the saturation with the peer */
+ sat_request_t request = xbt_new(s_sat_request_t,1);
+
+ DEBUG2("Begin to saturate to %s:%d",to_name,to_port);
+ memset(&msg_got,0,sizeof(msg_got));
+
+ request->msg_size = msg_size;
+ request->duration = duration;
+ request->host.name = NULL;
+ request->host.port = 0;
+
+ ctx = gras_msg_rpc_async_call(peer_cmd, 60,
+ gras_msgtype_by_name("amok_bw_sat begin"),
+ &request);
+ free(request);
+ gras_msg_rpc_async_wait(ctx,&request);
+ meas=gras_socket_client_ext( to_name, request->host.port,
+ 0 /*bufsize: auto*/,
+ 1 /*meas: true*/);
+ free(request);
+
+ gras_socket_close(peer_cmd);
+ INFO2("Saturation from %s to %s started",gras_os_myname(),to_name);
+
+ /* Start experiment */
+ start=gras_os_time();
+
+ do {
+ /* do send it */
+ gras_socket_meas_send(meas,120,msg_size,msg_size);
+ 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"),
+ NULL /* accept any sender */,
+ NULL, NULL, /* No specific filter */
+ &msg_got);
+ } CATCH(e) {
+ if (e.category == timeout_error) {
+ saturate_further=1;
+ memset(&msg_got,0,sizeof(msg_got)); /* may be overprotectiv here */
+ }
+ xbt_ex_free(e);
+ }
+
+ /* Check whether the experiment has to be terminated by now */
+ elapsed=gras_os_time()-start;
+ VERB2("elapsed %f duration %f",elapsed, duration);
+
+ } while (duration==0 || (saturate_further && elapsed < duration));
+
+ bw = ((double)(packet_sent*msg_size)) / elapsed;
+
+ if (elapsed_res)
+ *elapsed_res = elapsed;
+ if (bw_res)
+ *bw_res = bw;
+
+ /* If someone stopped us, inform him about the achieved bandwidth */
+ if (msg_got.expe) {
+ 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));
+ answer->timestamp=gras_os_time();
+ answer->sec=elapsed;
+ answer->bw=bw;
+
+ ctx.expeditor = msg_got.expe;
+ ctx.ID = msg_got.ID;
+ ctx.msgtype = msg_got.type;
+
+ 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);