aboutsummaryrefslogtreecommitdiff
path: root/src/ats/test_ats_api_bandwidth_consumption.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ats/test_ats_api_bandwidth_consumption.c')
-rw-r--r--src/ats/test_ats_api_bandwidth_consumption.c131
1 files changed, 55 insertions, 76 deletions
diff --git a/src/ats/test_ats_api_bandwidth_consumption.c b/src/ats/test_ats_api_bandwidth_consumption.c
index d2a7b53dc..1eb57fcc8 100644
--- a/src/ats/test_ats_api_bandwidth_consumption.c
+++ b/src/ats/test_ats_api_bandwidth_consumption.c
@@ -44,9 +44,9 @@ static struct GNUNET_ATS_PerformanceHandle *atp;
44 44
45struct GNUNET_ATS_ReservationContext *sh; 45struct GNUNET_ATS_ReservationContext *sh;
46 46
47static struct GNUNET_OS_Process * arm_proc; 47static struct GNUNET_OS_Process *arm_proc;
48 48
49static struct PeerContext * p; 49static struct PeerContext *p;
50 50
51static uint32_t bw_in; 51static uint32_t bw_in;
52 52
@@ -56,23 +56,23 @@ static int ret;
56 56
57struct Address 57struct Address
58{ 58{
59 char * plugin; 59 char *plugin;
60 size_t plugin_len; 60 size_t plugin_len;
61 61
62 void * addr; 62 void *addr;
63 size_t addr_len; 63 size_t addr_len;
64 64
65 struct GNUNET_ATS_Information * ats; 65 struct GNUNET_ATS_Information *ats;
66 int ats_count; 66 int ats_count;
67 67
68 void *session; 68 void *session;
69}; 69};
70 70
71struct PeerContext 71struct PeerContext
72{ 72{
73 struct GNUNET_PeerIdentity id; 73 struct GNUNET_PeerIdentity id;
74 74
75 struct Address * addr; 75 struct Address *addr;
76}; 76};
77 77
78 78
@@ -94,12 +94,12 @@ end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
94 94
95 if (consume_task != GNUNET_SCHEDULER_NO_TASK) 95 if (consume_task != GNUNET_SCHEDULER_NO_TASK)
96 { 96 {
97 GNUNET_SCHEDULER_cancel(consume_task); 97 GNUNET_SCHEDULER_cancel (consume_task);
98 consume_task = GNUNET_SCHEDULER_NO_TASK; 98 consume_task = GNUNET_SCHEDULER_NO_TASK;
99 } 99 }
100 100
101 if (sh != NULL) 101 if (sh != NULL)
102 GNUNET_ATS_reserve_bandwidth_cancel(sh); 102 GNUNET_ATS_reserve_bandwidth_cancel (sh);
103 103
104 if (ats != NULL) 104 if (ats != NULL)
105 GNUNET_ATS_scheduling_done (ats); 105 GNUNET_ATS_scheduling_done (ats);
@@ -120,13 +120,13 @@ end ()
120{ 120{
121 if (die_task != GNUNET_SCHEDULER_NO_TASK) 121 if (die_task != GNUNET_SCHEDULER_NO_TASK)
122 { 122 {
123 GNUNET_SCHEDULER_cancel(die_task); 123 GNUNET_SCHEDULER_cancel (die_task);
124 die_task = GNUNET_SCHEDULER_NO_TASK; 124 die_task = GNUNET_SCHEDULER_NO_TASK;
125 } 125 }
126 126
127 if (consume_task != GNUNET_SCHEDULER_NO_TASK) 127 if (consume_task != GNUNET_SCHEDULER_NO_TASK)
128 { 128 {
129 GNUNET_SCHEDULER_cancel(consume_task); 129 GNUNET_SCHEDULER_cancel (consume_task);
130 consume_task = GNUNET_SCHEDULER_NO_TASK; 130 consume_task = GNUNET_SCHEDULER_NO_TASK;
131 } 131 }
132 132
@@ -142,41 +142,25 @@ end ()
142 stop_arm (); 142 stop_arm ();
143} 143}
144 144
145void performance_cb (void *cls, 145void
146 const struct 146performance_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
147 GNUNET_PeerIdentity * 147 const char *plugin_name, const void *plugin_addr,
148 peer, 148 size_t plugin_addr_len,
149 const char *plugin_name, 149 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
150 const void *plugin_addr, 150 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
151 size_t plugin_addr_len, 151 const struct GNUNET_ATS_Information *ats, uint32_t ats_count)
152 struct
153 GNUNET_BANDWIDTH_Value32NBO
154 bandwidth_out,
155 struct
156 GNUNET_BANDWIDTH_Value32NBO
157 bandwidth_in,
158 const struct
159 GNUNET_ATS_Information
160 * ats,
161 uint32_t ats_count)
162{ 152{
163 153
164} 154}
165 155
166void reservation_cb (void *cls, 156void
167 const struct 157reservation_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
168 GNUNET_PeerIdentity * 158 int32_t amount, struct GNUNET_TIME_Relative res_delay)
169 peer,
170 int32_t amount,
171 struct
172 GNUNET_TIME_Relative
173 res_delay)
174{ 159{
175 sh = NULL; 160 sh = NULL;
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", 161 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
177 amount, 162 "ATS reserved bandwidth of %i to peer `%s' in %llu ms\n", amount,
178 GNUNET_i2s (peer), 163 GNUNET_i2s (peer), res_delay.rel_value);
179 res_delay.rel_value);
180} 164}
181 165
182static void 166static void
@@ -184,51 +168,43 @@ consume_bandwidth (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
184{ 168{
185 consume_task = GNUNET_SCHEDULER_NO_TASK; 169 consume_task = GNUNET_SCHEDULER_NO_TASK;
186 int32_t to_reserve = 500; 170 int32_t to_reserve = 500;
187 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
188 to_reserve,
189 GNUNET_i2s (&p->id));
190 171
191 sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb, NULL); 172 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
173 "Trying to reserver bandwidth of %i to peer `%s' in %llu ms\n",
174 to_reserve, GNUNET_i2s (&p->id));
175
176 sh = GNUNET_ATS_reserve_bandwidth (atp, &p->id, to_reserve, &reservation_cb,
177 NULL);
192} 178}
193 179
194static void 180static void
195address_suggest_cb (void *cls, 181address_suggest_cb (void *cls, const struct GNUNET_PeerIdentity *peer,
196 const struct 182 const char *plugin_name, const void *plugin_addr,
197 GNUNET_PeerIdentity * 183 size_t plugin_addr_len, struct Session *session,
198 peer, 184 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
199 const char *plugin_name, 185 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
200 const void *plugin_addr, 186 const struct GNUNET_ATS_Information *ats,
201 size_t plugin_addr_len,
202 struct Session * session,
203 struct
204 GNUNET_BANDWIDTH_Value32NBO
205 bandwidth_out,
206 struct
207 GNUNET_BANDWIDTH_Value32NBO
208 bandwidth_in,
209 const struct
210 GNUNET_ATS_Information
211 * ats,
212 uint32_t ats_count) 187 uint32_t ats_count)
213
214{ 188{
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n", GNUNET_i2s (peer)); 189 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS suggested address for peer `%s'\n",
190 GNUNET_i2s (peer));
216 191
217 bw_in = ntohl (bandwidth_in.value__); 192 bw_in = ntohl (bandwidth_in.value__);
218 bw_out = ntohl (bandwidth_out.value__); 193 bw_out = ntohl (bandwidth_out.value__);
219 194
220 consume_task = GNUNET_SCHEDULER_add_now(&consume_bandwidth, NULL); 195 consume_task = GNUNET_SCHEDULER_add_now (&consume_bandwidth, NULL);
221} 196}
222 197
223void 198void
224start_arm (const char *cfgname) 199start_arm (const char *cfgname)
225{ 200{
226 arm_proc = GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm", 201 arm_proc =
227 "gnunet-service-arm", 202 GNUNET_OS_start_process (NULL, NULL, "gnunet-service-arm",
203 "gnunet-service-arm",
228#if VERBOSE_ARM 204#if VERBOSE_ARM
229 "-L", "DEBUG", 205 "-L", "DEBUG",
230#endif 206#endif
231 "-c", cfgname, NULL); 207 "-c", cfgname, NULL);
232} 208}
233 209
234static void 210static void
@@ -238,7 +214,7 @@ check (void *cls, char *const *args, const char *cfgfile,
238 ret = GNUNET_SYSERR; 214 ret = GNUNET_SYSERR;
239 struct Address *addr; 215 struct Address *addr;
240 216
241 die_task = GNUNET_SCHEDULER_add_delayed(TIMEOUT, &end_badly, NULL); 217 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
242 start_arm (cfgfile); 218 start_arm (cfgfile);
243 219
244 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); 220 ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL);
@@ -257,25 +233,28 @@ check (void *cls, char *const *args, const char *cfgfile,
257 { 233 {
258 ret = GNUNET_SYSERR; 234 ret = GNUNET_SYSERR;
259 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n"); 235 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to init ATS performance\n");
260 end_badly(NULL, NULL); 236 end_badly (NULL, NULL);
261 GNUNET_free (p); 237 GNUNET_free (p);
262 GNUNET_free (addr); 238 GNUNET_free (addr);
263 return; 239 return;
264 } 240 }
265 241
266 /* set up peer */ 242 /* set up peer */
267 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p->id.hashPubKey); 243 GNUNET_CRYPTO_hash_create_random (GNUNET_CRYPTO_QUALITY_WEAK,
244 &p->id.hashPubKey);
268 245
269 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", GNUNET_i2s (&p->id)); 246 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n",
247 GNUNET_i2s (&p->id));
270 p->addr = addr; 248 p->addr = addr;
271 addr->plugin = "test"; 249 addr->plugin = "test";
272 addr->session = NULL; 250 addr->session = NULL;
273 addr->addr = NULL; 251 addr->addr = NULL;
274 addr->addr_len = 0; 252 addr->addr_len = 0;
275 253
276 GNUNET_ATS_address_update(ats, &p->id, addr->plugin, addr->addr, addr->addr_len, addr->session, NULL, 0); 254 GNUNET_ATS_address_update (ats, &p->id, addr->plugin, addr->addr,
255 addr->addr_len, addr->session, NULL, 0);
277 256
278 GNUNET_ATS_suggest_address(ats, &p->id); 257 GNUNET_ATS_suggest_address (ats, &p->id);
279} 258}
280 259
281int 260int
@@ -297,8 +276,8 @@ main (int argc, char *argv[])
297 }; 276 };
298 277
299 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2, 278 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
300 "test_ats_api_bandwidth_consumption", "nohelp", options, &check, 279 "test_ats_api_bandwidth_consumption", "nohelp", options,
301 NULL); 280 &check, NULL);
302 281
303 282
304 return ret; 283 return ret;