- if ((errcode=gras_msg_new_and_send(sock,GRASMSG_BW_REQUEST, 2,
- target,1,
- request,1))) {
- fprintf(stderr,"grasbw_request(): Error %s encountered while sending the request.\n",
- xbt_error_name(errcode));
- gras_sock_close(sock);
- return errcode;
- }
- if ((errcode=gras_msg_wait(240,GRASMSG_BW_RESULT,&answer))) {
- fprintf(stderr,"grasbw_request(): Error %s encountered while waiting for the answer.\n",
- xbt_error_name(errcode));
- gras_sock_close(sock);
- return errcode;
- }
-
- if((errcode=gras_msg_ctn(answer,0,0,msgError_t).errcode)) {
- fprintf(stderr,"grasbw_request(): Peer reported error %s (%s).\n",
- xbt_error_name(errcode),gras_msg_ctn(answer,0,0,msgError_t).errmsg);
- gras_msg_free(answer);
- gras_sock_close(sock);
- return errcode;
- }
-
- /* fprintf(stderr,"sec=%p",gras_msg_ctn(answer,1,0,msgResult_t)); */
- *sec=gras_msg_ctn(answer,1,0,msgResult_t).value;
- *bw=gras_msg_ctn(answer,1,1,msgResult_t).value;
-
- gras_msg_free(answer);
- gras_sock_close(sock);
- return no_error;
-}
-
-int grasbw_cbBWRequest(gras_msg_t *msg) {
- /* specification of the test to run */
- char* to_name=gras_msg_ctn(msg,0,0,msgHost_t).host;
- unsigned int to_port=gras_msg_ctn(msg,0,0,msgHost_t).port;
-
- unsigned int bufSize=gras_msg_ctn(msg,1,0,BwExp_t).bufSize;
- unsigned int expSize=gras_msg_ctn(msg,1,0,BwExp_t).expSize;
- unsigned int msgSize=gras_msg_ctn(msg,1,0,BwExp_t).msgSize;
- /* our answer */
- msgError_t *error;
- msgResult_t *res;
-
- if (!(error=(msgError_t *)malloc(sizeof(msgError_t))) ||
- !(res=(msgResult_t *)malloc(sizeof(msgResult_t) * 2))) {
- fprintf(stderr,"%s:%d:grasbw_cbRequest: Malloc error\n",__FILE__,__LINE__);
- return malloc_error;
- }
-
- if ((error->errcode=grasbw_test(to_name,to_port,bufSize,expSize,msgSize,
- &(res[0].value),&(res[1].value) ))) {
- fprintf(stderr,
- "%s:%d:grasbw_cbRequest: Error %s encountered while doing the test\n",
- __FILE__,__LINE__,xbt_error_name(error->errcode));
- strncpy(error->errmsg,"Error within grasbw_test",ERRMSG_LEN);
- gras_msg_new_and_send(msg->sock,GRASMSG_BW_RESULT,2,
- error,1,
- res,2);
- return 1;
- }
- res[0].timestamp = (unsigned int) gras_time();
- res[1].timestamp = (unsigned int) gras_time();
- gras_msg_new_and_send(msg->sock,GRASMSG_BW_RESULT,2,
- error,1,
- res,2);
- gras_msg_free(msg);
- return 1;
-}
-
-/* ***************************************************************************
- * Link saturation
- * ***************************************************************************/
-
-xbt_error_t grasbw_saturate_start(const char* from_name,unsigned int from_port,
- const char* to_name,unsigned int to_port,
- unsigned int msgSize, unsigned int timeout) {
- gras_sock_t *sock;
- xbt_error_t errcode;
- /* The request */
- SatExp_t *request;
- msgHost_t *target;
- /* answer */
- gras_msg_t *answer;
-
- 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;
- }
- if (!(request=(SatExp_t *)malloc(sizeof(SatExp_t))) ||
- !(target=(msgHost_t*)malloc(sizeof(msgHost_t)))) {
- fprintf(stderr,"%s:%d:saturate_start(): Malloc error\n",__FILE__,__LINE__);
- gras_sock_close(sock);
- return malloc_error;
- }
-
- request->timeout=timeout;
- request->msgSize=msgSize;
-
- strcpy(target->host,to_name);
- target->port=to_port;
-
- if ((errcode=gras_msg_new_and_send(sock,GRASMSG_SAT_START, 2,
- target,1,
- request,1))) {
- fprintf(stderr,"%s:%d:saturate_start(): Error %s encountered while sending the request.\n",
- __FILE__,__LINE__,xbt_error_name(errcode));
- gras_sock_close(sock);
- return errcode;
- }
- if ((errcode=gras_msg_wait(120,GRASMSG_SAT_STARTED,&answer))) {
- fprintf(stderr,"%s:%d:saturate_start(): Error %s encountered while waiting for the ACK.\n",
- __FILE__,__LINE__,xbt_error_name(errcode));
- gras_sock_close(sock);
- return errcode;
- }
-
- if((errcode=gras_msg_ctn(answer,0,0,msgError_t).errcode)) {
- fprintf(stderr,"%s:%d:saturate_start(): Peer reported error %s (%s).\n",
- __FILE__,__LINE__,xbt_error_name(errcode),gras_msg_ctn(answer,0,0,msgError_t).errmsg);
- gras_msg_free(answer);
- gras_sock_close(sock);
- return errcode;
- }
-
- gras_msg_free(answer);
- gras_sock_close(sock);
- return no_error;
-}
-
-int grasbw_cbSatStart(gras_msg_t *msg) {
- gras_rawsock_t *raw;
- gras_sock_t *sock;
- xbt_error_t errcode;
- double start; /* time to timeout */
-
- /* specification of the test to run */
- char* to_name=gras_msg_ctn(msg,0,0,msgHost_t).host;
- unsigned int to_port=gras_msg_ctn(msg,0,0,msgHost_t).port;
-
- unsigned int msgSize=gras_msg_ctn(msg,1,0,SatExp_t).msgSize;
- unsigned int timeout=gras_msg_ctn(msg,1,0,SatExp_t).timeout;
- unsigned int raw_port;
-