Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Fix compilation with tracing and new network_element_t
[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   xbt_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     XBT_INFO("New sensor: %s:%d", host->name, host->port);
46     xbt_dynar_push(hosts, &host);
47   }
48   nb_hosts = xbt_dynar_length(hosts);
49
50   XBT_INFO(">>> 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     XBT_INFO
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   /* where are the sensors */
71   xbt_dynar_t hosts = xbt_dynar_new(sizeof(xbt_host_t), &free_host);
72   int nb_hosts;
73
74   /* getting the name of maestro for the saturation and the concurrent bandwidth measurements  */
75   char *host_test = argv[0];
76
77   /* results */
78   double sec, bw;
79
80   /* iterators */
81   int i, j;
82   xbt_host_t h1, h2;
83
84   /* socket to sensor */
85   xbt_socket_t peer;
86
87   /* wait to ensure that all server sockets are there before starting the experiment */
88   gras_os_sleep(0.5);
89
90   XBT_INFO(">>>>>< le maestro est: %s ", argv[0]);
91   /* Get the sensor location from argc/argv */
92   for (i = 1; i < argc - 1; i += 2) {
93     xbt_host_t host = xbt_new(s_xbt_host_t, 1);
94     host->name = strdup(argv[i]);
95     host->port = atoi(argv[i + 1]);
96     XBT_INFO("New sensor: %s:%d", host->name, host->port);
97     xbt_dynar_push(hosts, &host);
98   }
99   nb_hosts = xbt_dynar_length(hosts);
100
101   XBT_INFO(">>> start Test2: ENV pairwise host bandwidth mesurements");
102   xbt_dynar_foreach(hosts, i, h1) {
103
104     TRY {
105       amok_bw_saturate_start(h1->name, h1->port, host_test, h1->port,   //"Ginette"
106                              msg_size, 120);    // sturation of the link with msg_size to compute a concurent bandwidth MA //MB
107     }
108     CATCH_ANONYMOUS {
109       RETHROWF("Cannot ask hosts to saturate the link: %s");
110     }
111     // gras_os_sleep(1.0);
112
113     xbt_dynar_foreach(hosts, j, h2) {
114       if (i == j)
115         continue;
116
117       peer = gras_socket_client(h2->name, h2->port);
118       amok_bw_test(peer, buf_size, exp_size, msg_size, min_duration, &sec,
119                    &bw);
120       XBT_INFO
121           ("Bandwidth between me and %s // measurement between me and %s (%d bytes in msgs of %d bytes) took %f sec, achieving %.3f kb/s",
122            h2->name, h1->name, exp_size, msg_size, sec,
123            ((double) bw) / 1024.0);
124
125     }
126     amok_bw_saturate_stop(h1->name, h1->port, NULL, NULL);
127   }
128   xbt_dynar_map(hosts, kill_buddy_dynar);
129   xbt_dynar_free(&hosts);
130
131 }
132
133 int maestro(int argc, char *argv[])
134 {
135
136   gras_init(&argc, argv);
137   amok_bw_init();
138   amok_hm_init();
139
140   gras_socket_server(3333);     /* only so that messages from the transport layer in gras identify us */
141
142   //env_Pairwisehost_bw(argc,argv);
143   //env_hosttohost_bw(argc,argv);
144
145   gras_exit();
146   return 0;
147
148 }