3 /* bandwidth - bandwidth test demo of GRAS features */
5 /* Copyright (c) 2003, 2004 Martin Quinson. All rights reserved. */
7 /* This program is free software; you can redistribute it and/or modify it
8 * under the terms of the license (GNU LGPL) which comes with this package. */
12 #include "amok/bandwidth.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(Bandwidth,"Messages specific to this example");
16 /* **********************************************************************
18 * **********************************************************************/
20 /* Global private data */
24 } s_sensor_data_t,*sensor_data_t;
26 static int sensor_cb_quit(gras_socket_t expeditor,
28 sensor_data_t globals=(sensor_data_t)gras_userdata_get();
34 /* Function prototypes */
35 int sensor (int argc,char *argv[]);
37 int sensor (int argc,char *argv[]) {
40 gras_init(&argc, argv);
41 g=gras_userdata_new(s_sensor_data_t);
44 g->sock=gras_socket_server(atoi(argv[1]));
47 gras_msgtype_declare("quit",NULL);
48 gras_cb_register(gras_msgtype_by_name("quit"),&sensor_cb_quit);
51 gras_msg_handle(60.0);
53 gras_socket_close(g->sock);
57 /* **********************************************************************
59 * **********************************************************************/
61 /* Global private data */
64 } s_maestro_data_t,*maestro_data_t;
66 /* Function prototypes */
67 int maestro (int argc,char *argv[]);
69 int maestro(int argc,char *argv[]) {
77 gras_init(&argc, argv);
78 g=gras_userdata_new(s_maestro_data_t);
82 ERROR0("Usage: maestro host port host port\n");
86 /* wait to ensure that all server sockets are there before starting the experiment */
89 peer = gras_socket_client(argv[1],atoi(argv[2]));
91 INFO0("Test the BW between me and one of the sensors");
92 amok_bw_test(peer,buf_size,exp_size,msg_size,&sec,&bw);
93 INFO6("Experience between me and %s:%d (%d kb in msgs of %d kb) took %f sec, achieving %f kb/s",
94 argv[1],atoi(argv[2]),
98 INFO0("Test the BW between the two sensors");
99 amok_bw_request(argv[1],atoi(argv[2]),argv[3],atoi(argv[4]),
100 buf_size,exp_size,msg_size,&sec,&bw);
101 INFO2("Experience took took %f sec, achieving %f kb/s",
104 /* ask sensors to quit */
105 gras_msgtype_declare("quit",NULL);
106 gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL);
107 gras_socket_close(peer);
109 peer = gras_socket_client(argv[3],atoi(argv[4]));
110 gras_msg_send(peer,gras_msgtype_by_name("quit"), NULL);
111 gras_socket_close(peer);
113 gras_socket_close(g->sock);