Logo AND Algorithmique Numérique Distribuée

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