- if((errcode=gras_sock_client_open(from_name,from_port,&sock))) {
- fprintf(stderr,"%s:%d:saturate_start(): Error %s encountered while contacting peer\n",
- __FILE__,__LINE__,xbt_error_name(errcode));
- return errcode;
+
+ gras_msg_rpccall(sock,60,gras_msgtype_by_name("amok_bw_sat start"),&request, NULL);
+
+ free(request);
+ gras_socket_close(sock);
+}
+
+/* Asked to begin a saturation */
+static int amok_bw_cb_sat_start(gras_msg_cb_ctx_t ctx, void *payload){
+ sat_request_t request = *(sat_request_t*)payload;
+ amok_bw_saturate_begin(request->host.name,request->host.port,
+ request->msg_size, request->duration,
+ NULL,NULL);
+ free(request->host.name);
+ free(request);
+ return 1;
+}
+
+/**
+ * @brief Start saturating between the current process and the designated peer
+ *
+ * Note that the only way to break this function before the end of the timeout
+ * is to have a remote host calling amok_bw_saturate_stop to this process.
+ */
+void amok_bw_saturate_begin(const char* to_name,unsigned int to_port,
+ unsigned int msg_size, unsigned int duration,
+ /*out*/ double *elapsed_res, double *bw_res) {
+
+ xbt_ex_t e;
+
+ gras_socket_t peer_cmd = gras_socket_client(to_name, to_port);
+ gras_socket_t measMaster=NULL,meas=NULL;
+ int port;
+
+ s_gras_msg_t msg_got;
+
+ unsigned int packet_sent=0;
+ double start,elapsed=-1; /* timer */
+ double bw;
+
+ volatile int saturate_further; /* boolean in the main loop */
+
+ /* 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));
+
+ for (port = 6000; port <= 10000 && measMaster == NULL; port++) {
+ TRY {
+ measMaster = gras_socket_server_ext(port,
+ 0 /*bufsize: auto*/,
+ 1 /*meas: true*/);
+ } CATCH(e) {
+ measMaster = NULL;
+ if (port < 10000)
+ xbt_ex_free(e);
+ else
+ RETHROW0("Error encountered while opening a measurement server socket: %s");
+ }