aboutsummaryrefslogtreecommitdiff
path: root/src/ats-tests
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2014-02-03 21:51:43 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2014-02-03 21:51:43 +0000
commit82668db981251a3b96760c289b459cad1bcece13 (patch)
tree9c8893c0bf2a10b552ccc723cb61a490a881c0f1 /src/ats-tests
parent8a3563b5c242b60aa4b7d2b9a3c3607ef8dcbadb (diff)
downloadgnunet-82668db981251a3b96760c289b459cad1bcece13.tar.gz
gnunet-82668db981251a3b96760c289b459cad1bcece13.zip
adding preference generation
Diffstat (limited to 'src/ats-tests')
-rw-r--r--src/ats-tests/Makefile.am2
-rw-r--r--src/ats-tests/ats-testing-preferences.c232
-rw-r--r--src/ats-tests/ats-testing-traffic.c2
-rw-r--r--src/ats-tests/ats-testing.h46
-rw-r--r--src/ats-tests/gnunet-ats-sim.c37
5 files changed, 311 insertions, 8 deletions
diff --git a/src/ats-tests/Makefile.am b/src/ats-tests/Makefile.am
index 532a738b9..aa303c870 100644
--- a/src/ats-tests/Makefile.am
+++ b/src/ats-tests/Makefile.am
@@ -54,7 +54,7 @@ noinst_PROGRAMS = \
54 54
55libgnunetatstesting_la_SOURCES = \ 55libgnunetatstesting_la_SOURCES = \
56 ats-testing.c ats-testing-log.c ats-testing-traffic.c \ 56 ats-testing.c ats-testing-log.c ats-testing-traffic.c \
57 ats-testing-experiment.c 57 ats-testing-experiment.c ats-testing-preferences.c
58libgnunetatstesting_la_LIBADD = \ 58libgnunetatstesting_la_LIBADD = \
59 $(top_builddir)/src/transport/libgnunettransport.la \ 59 $(top_builddir)/src/transport/libgnunettransport.la \
60 $(top_builddir)/src/hello/libgnunethello.la \ 60 $(top_builddir)/src/hello/libgnunethello.la \
diff --git a/src/ats-tests/ats-testing-preferences.c b/src/ats-tests/ats-testing-preferences.c
new file mode 100644
index 000000000..2e140ae9a
--- /dev/null
+++ b/src/ats-tests/ats-testing-preferences.c
@@ -0,0 +1,232 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010-2013 Christian Grothoff (and other contributing authors)
4
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
9
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
19 */
20/**
21 * @file ats-tests/ats-testing-preferences.c
22 * @brief ats benchmark: preference generator
23 * @author Christian Grothoff
24 * @author Matthias Wachs
25 */
26#include "platform.h"
27#include "gnunet_util_lib.h"
28#include "ats-testing.h"
29
30static struct PreferenceGenerator *pg_head;
31static struct PreferenceGenerator *pg_tail;
32
33extern struct GNUNET_ATS_TEST_Topology *top;
34
35static double
36get_preference (struct PreferenceGenerator *pg)
37{
38 struct GNUNET_TIME_Relative time_delta;
39 double delta_value;
40 double pref_value;
41
42 /* Calculate the current transmission rate based on the type of traffic */
43 switch (pg->type) {
44 case GNUNET_ATS_TEST_TG_CONSTANT:
45 pref_value = pg->base_value;
46 break;
47 case GNUNET_ATS_TEST_TG_LINEAR:
48 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
49 /* Calculate point of time in the current period */
50 time_delta.rel_value_us = time_delta.rel_value_us %
51 pg->duration_period.rel_value_us;
52 delta_value = ((double) time_delta.rel_value_us /
53 pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value);
54 if ((pg->max_value < pg->base_value) &&
55 ((pg->max_value - pg->base_value) > pg->base_value))
56 {
57 /* This will cause an underflow */
58 GNUNET_break (0);
59 }
60 pref_value = pg->base_value + delta_value;
61 break;
62 case GNUNET_ATS_TEST_TG_RANDOM:
63 delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK,
64 10000 * (pg->max_value - pg->base_value)) / 10000;
65 pref_value = pg->base_value + delta_value;
66 break;
67 case GNUNET_ATS_TEST_TG_SINUS:
68 time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start);
69 /* Calculate point of time in the current period */
70 time_delta.rel_value_us = time_delta.rel_value_us %
71 pg->duration_period.rel_value_us;
72 if ((pg->max_value - pg->base_value) > pg->base_value)
73 {
74 /* This will cause an underflow for second half of sinus period,
75 * will be detected in general when experiments are loaded */
76 GNUNET_break (0);
77 }
78 delta_value = (pg->max_value - pg->base_value) *
79 sin ( (2 * M_PI) / ((double) pg->duration_period.rel_value_us) *
80 time_delta.rel_value_us);
81 pref_value = pg->base_value + delta_value;
82 break;
83 default:
84 pref_value = 0.0;
85 break;
86 }
87 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n",
88 pref_value);
89 return pref_value;
90}
91
92
93static void
94set_pref_task (void *cls,
95 const struct GNUNET_SCHEDULER_TaskContext *tc)
96{
97 struct BenchmarkPartner *p = cls;
98 double pref_value;
99 p->pg->set_task = GNUNET_SCHEDULER_NO_TASK;
100
101 pref_value = get_preference (p->pg);
102
103 GNUNET_log(GNUNET_ERROR_TYPE_INFO,
104 "Setting preference for master [%u] and slave [%u] for %s to %f\n",
105 p->me->no, p->dest->no,
106 GNUNET_ATS_print_preference_type (p->pg->kind), pref_value);
107
108 GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle,
109 &p->dest->id, p->pg->kind, pref_value, GNUNET_ATS_PREFERENCE_END);
110
111 p->pg->set_task = GNUNET_SCHEDULER_add_delayed (p->pg->frequency,
112 set_pref_task, p);
113
114}
115
116
117/**
118 * Generate between the source master and the partner and set preferences with a
119 * value depending on the generator.
120 *
121 * @param src source
122 * @param dest partner
123 * @param type type of preferences to generate
124 * @param base_rate traffic base rate to send data with
125 * @param max_rate traffic maximum rate to send data with
126 * @param period duration of a period of traffic generation (~ 1/frequency)
127 * @param duration how long to generate traffic
128 * @return the traffic generator
129 */
130struct PreferenceGenerator *
131GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
132 struct BenchmarkPartner *dest,
133 enum GeneratorType type,
134 long int base_value,
135 long int value_rate,
136 struct GNUNET_TIME_Relative period,
137 struct GNUNET_TIME_Relative frequency,
138 enum GNUNET_ATS_PreferenceKind kind)
139{
140 struct PreferenceGenerator *pg;
141
142 if (NULL != dest->pg)
143 {
144 GNUNET_break (0);
145 return NULL;
146 }
147
148 pg = GNUNET_new (struct PreferenceGenerator);
149 GNUNET_CONTAINER_DLL_insert (pg_head, pg_tail, pg);
150 pg->type = type;
151 pg->src = src;
152 pg->dest = dest;
153 pg->kind = kind;
154 pg->base_value = base_value;
155 pg->max_value = value_rate;
156 pg->duration_period = period;
157 pg->frequency = frequency;
158 pg->time_start = GNUNET_TIME_absolute_get();
159
160 switch (type) {
161 case GNUNET_ATS_TEST_TG_CONSTANT:
162 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
163 "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n",
164 dest->me->no, GNUNET_i2s (&dest->me->id),
165 dest->dest->no, GNUNET_i2s (&dest->dest->id),
166 base_value);
167 break;
168 case GNUNET_ATS_TEST_TG_LINEAR:
169 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
170 "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n",
171 dest->me->no, GNUNET_i2s (&dest->me->id),
172 dest->dest->no, GNUNET_i2s (&dest->dest->id),
173 base_value, value_rate);
174 break;
175 case GNUNET_ATS_TEST_TG_SINUS:
176 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
177 "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n",
178 dest->me->no, GNUNET_i2s (&dest->me->id),
179 dest->dest->no, GNUNET_i2s (&dest->dest->id),
180 base_value, value_rate);
181 break;
182 case GNUNET_ATS_TEST_TG_RANDOM:
183 GNUNET_log (GNUNET_ERROR_TYPE_INFO,
184 "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n",
185 dest->me->no, GNUNET_i2s (&dest->me->id),
186 dest->dest->no, GNUNET_i2s (&dest->dest->id),
187 base_value, value_rate);
188 break;
189 default:
190 break;
191 }
192
193 dest->pg = pg;
194 pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, dest);
195 return pg;
196}
197
198
199void
200GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg)
201{
202 GNUNET_CONTAINER_DLL_remove (pg_head, pg_tail, pg);
203 pg->dest->pg = NULL;
204
205 if (GNUNET_SCHEDULER_NO_TASK != pg->set_task)
206 {
207 GNUNET_SCHEDULER_cancel (pg->set_task);
208 pg->set_task = GNUNET_SCHEDULER_NO_TASK;
209 }
210
211 GNUNET_free (pg);
212}
213
214
215/**
216 * Stop all preferences generators
217 */
218void
219GNUNET_ATS_TEST_generate_preferences_stop_all ()
220{
221 struct PreferenceGenerator *cur;
222 struct PreferenceGenerator *next;
223 next = pg_head;
224 for (cur = next; NULL != cur; cur = next)
225 {
226 next = cur->next;
227 GNUNET_ATS_TEST_generate_preferences_stop(cur);
228 }
229}
230
231/* end of file ats-testing-preferences.c */
232
diff --git a/src/ats-tests/ats-testing-traffic.c b/src/ats-tests/ats-testing-traffic.c
index 0c58bc1fa..fca65b900 100644
--- a/src/ats-tests/ats-testing-traffic.c
+++ b/src/ats-tests/ats-testing-traffic.c
@@ -310,7 +310,7 @@ GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p)
310struct TrafficGenerator * 310struct TrafficGenerator *
311GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src, 311GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
312 struct BenchmarkPartner *dest, 312 struct BenchmarkPartner *dest,
313 enum TrafficGeneratorType type, 313 enum GeneratorType type,
314 long int base_rate, 314 long int base_rate,
315 long int max_rate, 315 long int max_rate,
316 struct GNUNET_TIME_Relative period, 316 struct GNUNET_TIME_Relative period,
diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h
index be2d22583..e24f1dc53 100644
--- a/src/ats-tests/ats-testing.h
+++ b/src/ats-tests/ats-testing.h
@@ -56,7 +56,7 @@ struct TrafficGenerator;
56 56
57struct LoggingHandle; 57struct LoggingHandle;
58 58
59enum TrafficGeneratorType 59enum GeneratorType
60{ 60{
61 GNUNET_ATS_TEST_TG_LINEAR, 61 GNUNET_ATS_TEST_TG_LINEAR,
62 GNUNET_ATS_TEST_TG_CONSTANT, 62 GNUNET_ATS_TEST_TG_CONSTANT,
@@ -223,7 +223,7 @@ struct TrafficGenerator
223 struct TrafficGenerator *prev; 223 struct TrafficGenerator *prev;
224 struct TrafficGenerator *next; 224 struct TrafficGenerator *next;
225 225
226 enum TrafficGeneratorType type; 226 enum GeneratorType type;
227 227
228 struct BenchmarkPeer *src; 228 struct BenchmarkPeer *src;
229 struct BenchmarkPartner *dest; 229 struct BenchmarkPartner *dest;
@@ -238,6 +238,28 @@ struct TrafficGenerator
238}; 238};
239 239
240 240
241struct PreferenceGenerator
242{
243 struct PreferenceGenerator *prev;
244 struct PreferenceGenerator *next;
245
246 enum GeneratorType type;
247
248 struct BenchmarkPeer *src;
249 struct BenchmarkPartner *dest;
250
251 enum GNUNET_ATS_PreferenceKind kind;
252
253 long int base_value;
254 long int max_value;
255 struct GNUNET_TIME_Relative duration_period;
256 struct GNUNET_TIME_Relative frequency;
257
258 GNUNET_SCHEDULER_TaskIdentifier set_task;
259 struct GNUNET_TIME_Absolute next_ping_transmission;
260 struct GNUNET_TIME_Absolute time_start;
261};
262
241/** 263/**
242 * Information about a benchmarking partner 264 * Information about a benchmarking partner
243 */ 265 */
@@ -264,6 +286,7 @@ struct BenchmarkPartner
264 struct GNUNET_TRANSPORT_TransmitHandle *tth; 286 struct GNUNET_TRANSPORT_TransmitHandle *tth;
265 287
266 struct TrafficGenerator *tg; 288 struct TrafficGenerator *tg;
289 struct PreferenceGenerator *pg;
267 290
268 /** 291 /**
269 * Timestamp to calculate communication layer delay 292 * Timestamp to calculate communication layer delay
@@ -468,7 +491,7 @@ struct GNUNET_ATS_TEST_Operation
468 struct GNUNET_TIME_Relative period; 491 struct GNUNET_TIME_Relative period;
469 492
470 enum OperationType type; 493 enum OperationType type;
471 enum TrafficGeneratorType tg_type; 494 enum GeneratorType tg_type;
472}; 495};
473 496
474struct Episode 497struct Episode
@@ -565,7 +588,7 @@ GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p);
565struct TrafficGenerator * 588struct TrafficGenerator *
566GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src, 589GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src,
567 struct BenchmarkPartner *dest, 590 struct BenchmarkPartner *dest,
568 enum TrafficGeneratorType type, 591 enum GeneratorType type,
569 long int base_rate, 592 long int base_rate,
570 long int max_rate, 593 long int max_rate,
571 struct GNUNET_TIME_Relative period, 594 struct GNUNET_TIME_Relative period,
@@ -580,6 +603,21 @@ GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg);
580void 603void
581GNUNET_ATS_TEST_generate_traffic_stop_all (); 604GNUNET_ATS_TEST_generate_traffic_stop_all ();
582 605
606struct PreferenceGenerator *
607GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src,
608 struct BenchmarkPartner *dest,
609 enum GeneratorType type,
610 long int base_value,
611 long int value_rate,
612 struct GNUNET_TIME_Relative period,
613 struct GNUNET_TIME_Relative frequency,
614 enum GNUNET_ATS_PreferenceKind kind);
615
616void
617GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg);
618
619void
620GNUNET_ATS_TEST_generate_preferences_stop_all ();
583 621
584/* 622/*
585 * Logging related functions 623 * Logging related functions
diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c
index e891cb39b..567fd7e50 100644
--- a/src/ats-tests/gnunet-ats-sim.c
+++ b/src/ats-tests/gnunet-ats-sim.c
@@ -136,13 +136,18 @@ do_shutdown ()
136 GNUNET_ATS_TEST_logging_clean_up (l); 136 GNUNET_ATS_TEST_logging_clean_up (l);
137 l = NULL; 137 l = NULL;
138 } 138 }
139
140 /* Stop traffic generation */
141 GNUNET_ATS_TEST_generate_traffic_stop_all();
142
143 /* Stop all preference generations */
144 GNUNET_ATS_TEST_generate_preferences_stop_all ();
145
139 if (NULL != e) 146 if (NULL != e)
140 { 147 {
141 GNUNET_break (0);
142 GNUNET_ATS_TEST_experimentation_stop (e); 148 GNUNET_ATS_TEST_experimentation_stop (e);
143 e = NULL; 149 e = NULL;
144 } 150 }
145 GNUNET_break (0);
146 GNUNET_ATS_TEST_shutdown_topology (); 151 GNUNET_ATS_TEST_shutdown_topology ();
147} 152}
148 153
@@ -189,6 +194,9 @@ experiment_done_cb (struct Experiment *e, struct GNUNET_TIME_Relative duration,i
189 /* Stop traffic generation */ 194 /* Stop traffic generation */
190 GNUNET_ATS_TEST_generate_traffic_stop_all(); 195 GNUNET_ATS_TEST_generate_traffic_stop_all();
191 196
197 /* Stop all preference generations */
198 GNUNET_ATS_TEST_generate_preferences_stop_all ();
199
192 evaluate (duration); 200 evaluate (duration);
193 if (opt_log) 201 if (opt_log)
194 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot); 202 GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot);
@@ -229,6 +237,31 @@ static void topology_setup_done (void *cls,
229 e->num_masters, e->num_slaves, 237 e->num_masters, e->num_slaves,
230 opt_verbose); 238 opt_verbose);
231 GNUNET_ATS_TEST_experimentation_run (e, &episode_done_cb, &experiment_done_cb); 239 GNUNET_ATS_TEST_experimentation_run (e, &episode_done_cb, &experiment_done_cb);
240/*
241 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
242 GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS,
243 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
244 GNUNET_ATS_PREFERENCE_BANDWIDTH);
245*/
246/*
247 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
248 GNUNET_ATS_TEST_TG_LINEAR, 1, 50,
249 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
250 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
251 GNUNET_ATS_PREFERENCE_BANDWIDTH);
252*/
253/*
254 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
255 GNUNET_ATS_TEST_TG_RANDOM, 1, 50,
256 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 2),
257 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
258 GNUNET_ATS_PREFERENCE_BANDWIDTH);
259*/
260 GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0],
261 GNUNET_ATS_TEST_TG_SINUS, 10, 5,
262 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5),
263 GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 250),
264 GNUNET_ATS_PREFERENCE_BANDWIDTH);
232 265
233#if 0 266#if 0
234 int c_m; 267 int c_m;