Logo AND Algorithmique Numérique Distribuée

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