1 /* bandwidth - bandwidth test demo of GRAS features */
3 /* Copyright (c) 2005, 2006, 2007, 2008, 2009, 2010. The SimGrid Team.
4 * All rights reserved. */
6 /* This program is free software; you can redistribute it and/or modify it
7 * under the terms of the license (GNU LGPL) which comes with this package. */
11 #include "amok/bandwidth.h"
12 #include "amok/peermanagement.h"
14 XBT_LOG_NEW_DEFAULT_CATEGORY(Bandwidth,
15 "Messages specific to this example");
17 /* **********************************************************************
19 * **********************************************************************/
21 /* Function prototypes */
22 int sensor(int argc, char *argv[]);
24 int sensor(int argc, char *argv[])
27 gras_socket_t master = NULL;
28 int connection_try = 10;
31 gras_init(&argc, argv);
35 mysock = gras_socket_server_range(3000, 9999, 0, 0);
36 XBT_INFO("Sensor starting (on port %d)", gras_os_myport());
37 while (connection_try > 0 && master == NULL) {
40 master = gras_socket_client_from_string(argv[1]);
47 gras_os_sleep(0.5); /* let the master get ready */
51 amok_pm_group_join(master, "bandwidth");
54 gras_socket_close(mysock);
55 gras_socket_close(master);
60 /* **********************************************************************
62 * **********************************************************************/
64 /* Function prototypes */
65 int maestro(int argc, char *argv[]);
67 int maestro(int argc, char *argv[])
70 int buf_size = 32 * 1024;
71 int msg_size = 512 * 1024;
73 double min_duration = 1;
77 xbt_peer_t h1, h2, h_temp;
80 gras_init(&argc, argv);
84 XBT_INFO("Maestro starting");
86 XBT_ERROR("Usage: maestro port\n");
89 mysock = gras_socket_server(atoi(argv[1]));
90 group = amok_pm_group_new("bandwidth");
91 XBT_INFO("Wait for peers for 5 sec");
92 gras_msg_handleall(5); /* friends, we're ready. Come and play */
94 if (xbt_dynar_length(group) < 2) {
95 amok_pm_group_shutdown("bandwidth");
96 xbt_die("Not enough peers arrived. Expected 2 got %ld",
97 xbt_dynar_length(group));
99 h1 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 0);
100 h2 = *(xbt_peer_t *) xbt_dynar_get_ptr(group, 1);
101 /* sort peers in right order to keep output right */
102 if (strcmp(h1->name, h2->name) < 0 || h1->port > h2->port) {
108 XBT_INFO("Contact %s:%d", h1->name, h1->port);
109 peer = gras_socket_client(h1->name, h1->port);
111 XBT_INFO("Test the BW between me and one of the sensors");
112 amok_bw_test(peer, buf_size, msg_size, msg_amount, min_duration, &sec,
115 ("Experience between me and %s:%d (initially %d msgs of %d bytes, maybe modified to fill the pipe at least %.1fs) took %f sec, achieving %f kb/s",
116 h1->name, h1->port, msg_amount, msg_size, min_duration, sec,
117 ((double) bw) / 1024.0);
119 XBT_INFO("Test the BW between %s:%d and %s:%d", h1->name, h1->port,
121 amok_bw_request(h1->name, h1->port, h2->name, h2->port, buf_size,
122 msg_size, msg_amount, min_duration, &sec, &bw);
124 ("Experience between %s:%d and %s:%d took took %f sec, achieving %f kb/s",
125 h1->name, h1->port, h2->name, h2->port, sec,
126 ((double) bw) / 1024.0);
128 /* Game is over, friends */
129 amok_pm_group_shutdown("bandwidth");
131 gras_socket_close(mysock);