Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
e07585456cf12b0d1d6c61f0772b278bb19b28bb
[simgrid.git] / examples / bandwidth / bandwidth.c
1 /* $Id$ */
2
3 /* bandwidth - bandwidth test demo of GRAS features                         */
4
5 /* Authors: Martin Quinson                                                  */
6 /* Copyright (C) 2003,2004 da GRAS posse.                                   */
7
8 /* This program is free software; you can redistribute it and/or modify it
9    under the terms of the license (GNU LGPL) which comes with this package. */
10
11 #include "gras.h"
12 #include "amok/bandwidth.h"
13
14 GRAS_LOG_NEW_DEFAULT_CATEGORY(Bandwidth,"Messages specific to this example");
15
16 /* **********************************************************************
17  * Sensor code
18  * **********************************************************************/
19
20 /* Global private data */
21 typedef struct {
22   gras_socket_t sock;
23 } s_sensor_data_t,*sensor_data_t;
24
25 /* Function prototypes */
26 int sensor (int argc,char *argv[]);
27
28 int sensor (int argc,char *argv[]) {
29   gras_error_t errcode;
30   sensor_data_t g;
31
32   gras_init(&argc,argv);
33   g=gras_userdata_new(s_sensor_data_t);  
34
35   amok_bw_init();
36    
37   if ((errcode=gras_socket_server(atoi(argv[1]),&(g->sock)))) { 
38     ERROR1("Sensor: Error %s encountered while opening the server socket",gras_error_name(errcode));
39     return 1;
40   }
41
42   errcode=gras_msg_handle(60.0);
43   if (errcode != no_error) {
44      ERROR1("Sensor: Error '%s' while handling message",gras_error_name(errcode));
45      gras_socket_close(g->sock);
46      return errcode;
47   }
48
49   gras_socket_close(g->sock);
50   return 0;
51 }
52
53 /* **********************************************************************
54  * Maestro code
55  * **********************************************************************/
56
57 /* Global private data */
58 typedef struct {
59   gras_socket_t sock;
60 } s_maestro_data_t,*maestro_data_t;
61
62 /* Function prototypes */
63 int maestro (int argc,char *argv[]);
64
65 int maestro(int argc,char *argv[]) {
66   gras_error_t errcode;
67   maestro_data_t g;
68   double sec, bw;
69   int buf_size=32;
70   int exp_size=64;
71   int msg_size=64;
72   gras_socket_t peer;
73
74   gras_init(&argc,argv);
75   g=gras_userdata_new(s_maestro_data_t);
76   amok_bw_init();
77   gras_os_sleep(1,0);
78    
79   if ((errcode=gras_socket_server(6000,&(g->sock)))) { 
80     ERROR1("Maestro: Error %s encountered while opening the server socket",gras_error_name(errcode));
81     return 1;
82   }
83       
84    
85   if (argc != 5) {
86      ERROR0("Usage: maestro host port host port\n");
87      return 1;
88   }
89
90   if ((errcode=gras_socket_client(argv[1],atoi(argv[2]),&peer))) {
91      ERROR3("Client: Unable to connect to my peer on %s:%s. Got %s",
92             argv[1],argv[2],gras_error_name(errcode));
93      return 1;
94   }
95
96 /*  if ((errcode=amok_bw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
97                                buf_size,exp_size,msg_size,&sec,&bw))) {*/
98   
99   if ((errcode=amok_bw_test(peer,buf_size,exp_size,msg_size,&sec,&bw))) {
100     ERROR1("maestro: Error %s encountered while doing the test",gras_error_name(errcode));
101     return 1;
102   }
103    
104   INFO6("maestro: Experience between me and %s:%d (%d ko in msgs of %d ko) took %f sec, achieving %f Mb/s",
105         argv[1],atoi(argv[2]),
106         exp_size,msg_size,
107         sec,bw);
108
109   gras_socket_close(g->sock);
110   return 0;
111 }