Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Indent the rest of the code (examples, buildtools, doc...) except for examples/SMPI...
[simgrid.git] / examples / amok / saturate / env.c
1 /* saturate - link saturation demo of AMOK features                         */
2
3 /* Copyright (c) 2006, 2010. The SimGrid Team.
4  * All rights reserved.                                                     */
5
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. */
8
9 #include <stdio.h>
10 #include <stdlib.h>
11 #include <signal.h>
12 #include <time.h>
13
14 #include "gras.h"
15 #include "amok/bandwidth.h"
16 #include "amok/hostmanagement.h"
17
18 XBT_LOG_NEW_DEFAULT_CATEGORY(saturate,
19                              "Messages specific to this example");
20
21 static void env_hosttohost_bw(int argc, char *argv[])
22 {
23
24   /* where are the sensors */
25   xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t), &free_host);
26   int nb_hosts;
27
28   /* results */
29   double sec, bw;
30
31   /* iterators */
32   int i;
33   xbt_host_t h1;
34
35   gras_socket_t peer;           /* socket to sensor */
36
37   /* wait to ensure that all server sockets are there before starting the experiment */
38   gras_os_sleep(0.5);
39
40   /* Get the sensor location from argc/argv */
41   for (i = 1; i < argc - 1; i += 2) {
42     xbt_host_t host = xbt_new(s_xbt_host_t, 1);
43     host->name = strdup(argv[i]);
44     host->port = atoi(argv[i + 1]);
45     INFO2("New sensor: %s:%d", host->name, host->port);
46     xbt_dynar_push(hosts, &host);
47   }
48   nb_hosts = xbt_dynar_length(hosts);
49
50   INFO0(">>> start Test1: ENV end to end mesurements");
51
52   xbt_dynar_foreach(hosts, i, h1) {
53     peer = gras_socket_client(h1->name, h1->port);
54     amok_bw_test(peer, buf_size, exp_size, msg_size, min_duration, &sec,
55                  &bw);
56     INFO6
57         ("Bandwidth between me and %s:%d (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
58          h1->name, h1->port, exp_size, msg_size, sec,
59          ((double) bw) / 1024.0);
60   }
61
62   xbt_dynar_map(hosts, kill_buddy_dynar);
63   xbt_dynar_free(&hosts);
64
65 }
66
67 /********************************************************************************************/
68 static void env_Pairwisehost_bw(int argc, char *argv[])
69 {
70   xbt_ex_t e;
71
72   /* where are the sensors */
73   xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t), &free_host);
74   int nb_hosts;
75
76   /* getting the name of maestro for the saturation and the concurrent bandwidth measurements  */
77   char *host_test = argv[0];
78
79   /* results */
80   double sec, bw;
81
82   /* iterators */
83   int i, j;
84   xbt_host_t h1, h2;
85
86   /* socket to sensor */
87   gras_socket_t peer;
88
89   /* wait to ensure that all server sockets are there before starting the experiment */
90   gras_os_sleep(0.5);
91
92   INFO1(">>>>>< le maestro est: %s ", argv[0]);
93   /* Get the sensor location from argc/argv */
94   for (i = 1; i < argc - 1; i += 2) {
95     xbt_host_t host = xbt_new(s_xbt_host_t, 1);
96     host->name = strdup(argv[i]);
97     host->port = atoi(argv[i + 1]);
98     INFO2("New sensor: %s:%d", host->name, host->port);
99     xbt_dynar_push(hosts, &host);
100   }
101   nb_hosts = xbt_dynar_length(hosts);
102
103   INFO0(">>> start Test2: ENV pairwise host bandwidth mesurements");
104   xbt_dynar_foreach(hosts, i, h1) {
105
106     TRY {
107       amok_bw_saturate_start(h1->name, h1->port, host_test, h1->port,   //"Ginette"
108                              msg_size, 120);    // sturation of the link with msg_size to compute a concurent bandwidth MA //MB
109     }
110     CATCH(e) {
111       RETHROW0("Cannot ask hosts to saturate the link: %s");
112     }
113     // gras_os_sleep(1.0);
114
115     xbt_dynar_foreach(hosts, j, h2) {
116       if (i == j)
117         continue;
118
119       peer = gras_socket_client(h2->name, h2->port);
120       amok_bw_test(peer, buf_size, exp_size, msg_size, min_duration, &sec,
121                    &bw);
122       INFO6
123           ("Bandwidth between me and %s // measurement between me and %s (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
124            h2->name, h1->name, exp_size, msg_size, sec,
125            ((double) bw) / 1024.0);
126
127     }
128     amok_bw_saturate_stop(h1->name, h1->port, NULL, NULL);
129   }
130   xbt_dynar_map(hosts, kill_buddy_dynar);
131   xbt_dynar_free(&hosts);
132
133 }
134
135 int maestro(int argc, char *argv[])
136 {
137
138   gras_init(&argc, argv);
139   amok_bw_init();
140   amok_hm_init();
141
142   gras_socket_server(3333);     /* only so that messages from the transport layer in gras identify us */
143
144   //env_Pairwisehost_bw(argc,argv);
145   //env_hosttohost_bw(argc,argv);
146
147   gras_exit();
148   return 0;
149
150 }