aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-03-26 15:02:37 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-03-26 15:02:37 +0000
commitfec18deaff1382f2fc7598cb4a5c87865447ddda (patch)
tree7f3319f352f1b53efde2c4f66eb09297237f9339 /src/ats
parent916a78761f48b4fabf4fd7d3d93f12cb679f4bd6 (diff)
downloadgnunet-fec18deaff1382f2fc7598cb4a5c87865447ddda.tar.gz
gnunet-fec18deaff1382f2fc7598cb4a5c87865447ddda.zip
api change
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/Makefile.am10
-rw-r--r--src/ats/ats_api_performance.c28
-rw-r--r--src/ats/gnunet-service-ats_addresses.c80
-rw-r--r--src/ats/gnunet-service-ats_performance.c1
-rw-r--r--src/ats/test_ats_api_performance_address_info.c5
-rw-r--r--src/ats/test_ats_api_performance_list_addresses.c10
-rw-r--r--src/ats/test_ats_api_performance_monitor.c358
-rw-r--r--src/ats/test_ats_simplistic_change_preference.c2
-rw-r--r--src/ats/test_ats_simplistic_pref_aging.c2
9 files changed, 66 insertions, 430 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 109a752dc..3b31d85cf 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -75,7 +75,6 @@ check_PROGRAMS = \
75 test_ats_simplistic_change_preference \ 75 test_ats_simplistic_change_preference \
76 test_ats_simplistic_pref_aging \ 76 test_ats_simplistic_pref_aging \
77 test_ats_api_performance_list_addresses \ 77 test_ats_api_performance_list_addresses \
78 test_ats_api_performance_monitor \
79 test_ats_api_performance_address_info \ 78 test_ats_api_performance_address_info \
80 $(GN_MLP_TEST) $(GN_MLP_PERF) $(GN_MLP_TEST_UPDATE) 79 $(GN_MLP_TEST) $(GN_MLP_PERF) $(GN_MLP_TEST_UPDATE)
81# $(GN_MLP_TEST_AVG) 80# $(GN_MLP_TEST_AVG)
@@ -166,15 +165,6 @@ test_ats_api_performance_list_addresses_LDADD = \
166 $(top_builddir)/src/testing/libgnunettesting.la \ 165 $(top_builddir)/src/testing/libgnunettesting.la \
167 $(top_builddir)/src/hello/libgnunethello.la \ 166 $(top_builddir)/src/hello/libgnunethello.la \
168 $(top_builddir)/src/ats/libgnunetats.la 167 $(top_builddir)/src/ats/libgnunetats.la
169
170test_ats_api_performance_monitor_SOURCES = \
171 test_ats_api_performance_monitor.c
172test_ats_api_performance_monitor_LDADD = \
173 $(top_builddir)/src/util/libgnunetutil.la \
174 $(top_builddir)/src/testing/libgnunettesting.la \
175 $(top_builddir)/src/hello/libgnunethello.la \
176 $(top_builddir)/src/ats/libgnunetats.la
177
178 168
179test_ats_api_performance_address_info_SOURCES = \ 169test_ats_api_performance_address_info_SOURCES = \
180 test_ats_api_performance_address_info.c 170 test_ats_api_performance_address_info.c
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index 16495b604..8acce225f 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -181,16 +181,6 @@ struct GNUNET_ATS_PerformanceHandle
181 void *addr_info_cb_cls; 181 void *addr_info_cb_cls;
182 182
183 /** 183 /**
184 * Callback to invoke when a peer has performance changes.
185 */
186 GNUNET_ATS_PerformanceMonitorCb perf_monitor_cb;
187
188 /**
189 * Closure for 'perf_monitor_cb'.
190 */
191 void *perf_monitor_cb_cls;
192
193 /**
194 * Connection to ATS service. 184 * Connection to ATS service.
195 */ 185 */
196 struct GNUNET_CLIENT_Connection *client; 186 struct GNUNET_CLIENT_Connection *client;
@@ -396,15 +386,6 @@ process_pi_message (struct GNUNET_ATS_PerformanceHandle *ph,
396 ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, pi->bandwidth_out, pi->bandwidth_in, 386 ph->addr_info_cb (ph->addr_info_cb_cls, &address, addr_active, pi->bandwidth_out, pi->bandwidth_in,
397 atsi, ats_count); 387 atsi, ats_count);
398 } 388 }
399 if ((NULL != ph->perf_monitor_cb) &&
400 (GNUNET_YES == addr_active))
401 {
402 ph->perf_monitor_cb (ph->perf_monitor_cb_cls,
403 &pi->peer,
404 pi->bandwidth_out,
405 pi->bandwidth_in,
406 atsi, ats_count);
407 }
408 return GNUNET_OK; 389 return GNUNET_OK;
409} 390}
410 391
@@ -640,7 +621,7 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
640 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START); 621 init->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_START);
641 init->header.size = htons (sizeof (struct ClientStartMessage)); 622 init->header.size = htons (sizeof (struct ClientStartMessage));
642 init->start_flag = 623 init->start_flag =
643 htonl (((NULL ==ph->addr_info_cb) && (NULL == ph->perf_monitor_cb)) ? 624 htonl ((NULL ==ph->addr_info_cb) ?
644 START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC); 625 START_FLAG_PERFORMANCE_NO_PIC : START_FLAG_PERFORMANCE_WITH_PIC);
645 GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p); 626 GNUNET_CONTAINER_DLL_insert (ph->pending_head, ph->pending_tail, p);
646 } 627 }
@@ -653,9 +634,6 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
653 * Get handle to access performance API of the ATS subsystem. 634 * Get handle to access performance API of the ATS subsystem.
654 * 635 *
655 * @param cfg configuration to use 636 * @param cfg configuration to use
656 * @param perf_monitor_cb callback called when performance characteristics for
657 * a peer change
658 * @param perf_monitor_cb closure for the perf_monitor_cb
659 * @param addr_info_cb callback called when performance characteristics for 637 * @param addr_info_cb callback called when performance characteristics for
660 * an address change 638 * an address change
661 * @param addr_info_cb_cls closure for infocb 639 * @param addr_info_cb_cls closure for infocb
@@ -663,8 +641,6 @@ reconnect (struct GNUNET_ATS_PerformanceHandle *ph)
663 */ 641 */
664struct GNUNET_ATS_PerformanceHandle * 642struct GNUNET_ATS_PerformanceHandle *
665GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg, 643GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
666 GNUNET_ATS_PerformanceMonitorCb perf_monitor_cb,
667 void *perf_monitor_cb_cls,
668 GNUNET_ATS_AddressInformationCallback addr_info_cb, 644 GNUNET_ATS_AddressInformationCallback addr_info_cb,
669 void *addr_info_cb_cls) 645 void *addr_info_cb_cls)
670{ 646{
@@ -674,8 +650,6 @@ GNUNET_ATS_performance_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
674 ph->cfg = cfg; 650 ph->cfg = cfg;
675 ph->addr_info_cb = addr_info_cb; 651 ph->addr_info_cb = addr_info_cb;
676 ph->addr_info_cb_cls = addr_info_cb_cls; 652 ph->addr_info_cb_cls = addr_info_cb_cls;
677 ph->perf_monitor_cb = perf_monitor_cb;
678 ph->perf_monitor_cb_cls = perf_monitor_cb_cls;
679 ph->id = 0; 653 ph->id = 0;
680 reconnect (ph); 654 reconnect (ph);
681 return ph; 655 return ph;
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 1af07a53e..5ba0fb50a 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -367,6 +367,13 @@ struct GAS_Addresses_Handle
367}; 367};
368 368
369 369
370/**
371 * Assemble ATS information from address
372 *
373 * @param src source address
374 * @param dest destination
375 * @return number of elements
376 */
370static unsigned int 377static unsigned int
371assemble_ats_information (const struct ATS_Address *aa, struct GNUNET_ATS_Information **dest) 378assemble_ats_information (const struct ATS_Address *aa, struct GNUNET_ATS_Information **dest)
372{ 379{
@@ -393,6 +400,14 @@ assemble_ats_information (const struct ATS_Address *aa, struct GNUNET_ATS_Infor
393 return ats_count; 400 return ats_count;
394} 401}
395 402
403/**
404 * Disassemble ATS information and update address
405 *
406 * @param src source ATS information
407 * @param ats_count number of ATS information
408 * @param dest destination address
409 * @return GNUNET_YES if address was address updated, GNUNET_NO otherwise
410 */
396static unsigned int 411static unsigned int
397disassemble_ats_information (const struct GNUNET_ATS_Information *src, 412disassemble_ats_information (const struct GNUNET_ATS_Information *src,
398 uint32_t ats_count, 413 uint32_t ats_count,
@@ -460,17 +475,7 @@ disassemble_ats_information (const struct GNUNET_ATS_Information *src,
460 GNUNET_break (0); 475 GNUNET_break (0);
461 break; 476 break;
462 } 477 }
463 if (GNUNET_YES == change) 478 return change;
464 {
465 struct GNUNET_ATS_Information *destats;
466 int ats_count;
467 ats_count = assemble_ats_information (dest, &destats);
468 GAS_handle_performance_update (&dest->peer, dest->plugin,
469 dest->addr, dest->addr_len, dest->active,
470 destats, ats_count, dest->assigned_bw_out, dest->assigned_bw_in);
471 GNUNET_free (destats);
472 }
473 return res;
474} 479}
475 480
476/** 481/**
@@ -688,6 +693,8 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
688{ 693{
689 struct ATS_Address *aa; 694 struct ATS_Address *aa;
690 struct ATS_Address *ea; 695 struct ATS_Address *ea;
696 struct GNUNET_ATS_Information *ats_new;
697 uint32_t ats_count_new;
691 unsigned int ats_res; 698 unsigned int ats_res;
692 699
693 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 700 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -702,6 +709,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
702 709
703 aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len, 710 aa = create_address (peer, plugin_name, plugin_addr, plugin_addr_len,
704 session_id); 711 session_id);
712
705 if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, aa))) 713 if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, aa)))
706 { 714 {
707 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 715 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
@@ -722,6 +730,16 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
722 GNUNET_i2s (peer), session_id, aa); 730 GNUNET_i2s (peer), session_id, aa);
723 /* Tell solver about new address */ 731 /* Tell solver about new address */
724 handle->s_add (handle->solver, handle->addresses, aa); 732 handle->s_add (handle->solver, handle->addresses, aa);
733 /* Notify performance clients about new address */
734 ats_count_new = assemble_ats_information (aa, &ats_new);
735 GAS_performance_notify_all_clients (&aa->peer,
736 aa->plugin,
737 aa->addr, aa->addr_len,
738 aa->session_id,
739 ats_new, ats_count_new,
740 aa->assigned_bw_out,
741 aa->assigned_bw_in);
742 GNUNET_free (ats_new);
725 return; 743 return;
726 } 744 }
727 GNUNET_free (aa->plugin); 745 GNUNET_free (aa->plugin);
@@ -745,11 +763,17 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle,
745 763
746 /* Do the update */ 764 /* Do the update */
747 ea->session_id = session_id; 765 ea->session_id = session_id;
748 if (atsi_count != (ats_res = disassemble_ats_information(atsi, atsi_count, ea))) 766 if (GNUNET_YES == disassemble_ats_information(atsi, atsi_count, ea))
749 { 767 {
750 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 768 ats_count_new = assemble_ats_information (aa, &ats_new);
751 "While updating address: had %u ATS elements to add, could only add %u\n", 769 GAS_performance_notify_all_clients (&aa->peer,
752 atsi_count, ats_res); 770 aa->plugin,
771 aa->addr, aa->addr_len,
772 aa->session_id,
773 ats_new, ats_count_new,
774 aa->assigned_bw_out,
775 aa->assigned_bw_in);
776 GNUNET_free (ats_new);
753 } 777 }
754 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 778 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
755 "Updated existing address for peer `%s' %p with new session %u\n", 779 "Updated existing address for peer `%s' %p with new session %u\n",
@@ -766,7 +790,8 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
766 uint32_t atsi_count) 790 uint32_t atsi_count)
767{ 791{
768 struct ATS_Address *aa; 792 struct ATS_Address *aa;
769 uint32_t ats_res; 793 struct GNUNET_ATS_Information *ats_new;
794 uint32_t ats_count_new;
770 795
771 if (GNUNET_NO == handle->running) 796 if (GNUNET_NO == handle->running)
772 return; 797 return;
@@ -793,15 +818,19 @@ GAS_addresses_update (struct GAS_Addresses_Handle *handle,
793 handle->s_update (handle->solver, handle->addresses, aa, session_id, aa->used, atsi, atsi_count); 818 handle->s_update (handle->solver, handle->addresses, aa, session_id, aa->used, atsi, atsi_count);
794 819
795 /* Update address */ 820 /* Update address */
796 if (atsi_count != (ats_res = disassemble_ats_information (atsi, atsi_count, aa))) 821 if (GNUNET_YES == disassemble_ats_information (atsi, atsi_count, aa))
797 { 822 {
798 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 823 ats_count_new = assemble_ats_information (aa, &ats_new);
799 "While adding address: had %u ATS elements to add, could only add %u\n", 824 /* Notify performance clients about updated address */
800 atsi_count, ats_res); 825 GAS_performance_notify_all_clients (&aa->peer,
826 aa->plugin,
827 aa->addr, aa->addr_len,
828 aa->session_id,
829 ats_new, ats_count_new,
830 aa->assigned_bw_out,
831 aa->assigned_bw_in);
832 GNUNET_free (ats_new);
801 } 833 }
802 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
803 "Updated %u ATS elements for address %p\n",
804 ats_res, aa);
805} 834}
806 835
807 836
@@ -1274,6 +1303,8 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1274 1303
1275 1304
1276 ats_count = assemble_ats_information (address, &ats); 1305 ats_count = assemble_ats_information (address, &ats);
1306
1307 /* Notify performance clients about changes to address */
1277 GAS_performance_notify_all_clients (&address->peer, 1308 GAS_performance_notify_all_clients (&address->peer,
1278 address->plugin, 1309 address->plugin,
1279 address->addr, address->addr_len, 1310 address->addr, address->addr_len,
@@ -1281,7 +1312,6 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1281 ats, ats_count, 1312 ats, ats_count,
1282 address->assigned_bw_out, 1313 address->assigned_bw_out,
1283 address->assigned_bw_in); 1314 address->assigned_bw_in);
1284
1285 cur = handle->r_head; 1315 cur = handle->r_head;
1286 while (NULL != cur) 1316 while (NULL != cur)
1287 { 1317 {
@@ -1300,7 +1330,7 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address)
1300 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, 1330 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1301 "Sending bandwidth update for peer `%s'\n",GNUNET_i2s (&address->peer)); 1331 "Sending bandwidth update for peer `%s'\n",GNUNET_i2s (&address->peer));
1302 1332
1303 1333 /* *Notify scheduling clients about suggestion */
1304 GAS_scheduling_transmit_address_suggestion (&address->peer, 1334 GAS_scheduling_transmit_address_suggestion (&address->peer,
1305 address->plugin, 1335 address->plugin,
1306 address->addr, address->addr_len, 1336 address->addr, address->addr_len,
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index 3739ad638..2e74680e8 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -225,7 +225,6 @@ GAS_performance_notify_all_clients (const struct GNUNET_PeerIdentity *peer,
225 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in) 225 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in)
226{ 226{
227 struct PerformanceClient *pc; 227 struct PerformanceClient *pc;
228
229 for (pc = pc_head; pc != NULL; pc = pc->next) 228 for (pc = pc_head; pc != NULL; pc = pc->next)
230 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC) 229 if (pc->flag == START_FLAG_PERFORMANCE_WITH_PIC)
231 { 230 {
diff --git a/src/ats/test_ats_api_performance_address_info.c b/src/ats/test_ats_api_performance_address_info.c
index d321a2219..3120c98b8 100644
--- a/src/ats/test_ats_api_performance_address_info.c
+++ b/src/ats/test_ats_api_performance_address_info.c
@@ -152,7 +152,7 @@ static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
152static void 152static void
153addrinfo_cb (void *cls, 153addrinfo_cb (void *cls,
154 const struct GNUNET_HELLO_Address *address, 154 const struct GNUNET_HELLO_Address *address,
155 unsigned int address_active, 155 int address_active,
156 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 156 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
157 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 157 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
158 const struct GNUNET_ATS_Information *ats, 158 const struct GNUNET_ATS_Information *ats,
@@ -213,6 +213,7 @@ static void next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
213 setup_addresses (); 213 setup_addresses ();
214 214
215 /* Get an active address for peer0 and expect callback */ 215 /* Get an active address for peer0 and expect callback */
216 return;
216 GNUNET_ATS_suggest_address (sh, &addr[0].peer); 217 GNUNET_ATS_suggest_address (sh, &addr[0].peer);
217 218
218 atsi[0].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY); 219 atsi[0].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY);
@@ -235,7 +236,7 @@ run (void *cls,
235 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg; 236 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
236 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); 237 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
237 238
238 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL, addrinfo_cb, NULL); 239 ph = GNUNET_ATS_performance_init (cfg, addrinfo_cb, NULL);
239 GNUNET_assert (NULL != ph); 240 GNUNET_assert (NULL != ph);
240 241
241 sh = GNUNET_ATS_scheduling_init (cfg, &ats_suggest_cb, NULL); 242 sh = GNUNET_ATS_scheduling_init (cfg, &ats_suggest_cb, NULL);
diff --git a/src/ats/test_ats_api_performance_list_addresses.c b/src/ats/test_ats_api_performance_list_addresses.c
index 422dbfcf5..4d101662d 100644
--- a/src/ats/test_ats_api_performance_list_addresses.c
+++ b/src/ats/test_ats_api_performance_list_addresses.c
@@ -130,7 +130,7 @@ test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
130 130
131void all_active_addresses_peer_cb (void *cls, 131void all_active_addresses_peer_cb (void *cls,
132 const struct GNUNET_HELLO_Address *address, 132 const struct GNUNET_HELLO_Address *address,
133 unsigned int active, 133 int active,
134 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 134 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
135 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 135 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
136 const struct GNUNET_ATS_Information *ats, 136 const struct GNUNET_ATS_Information *ats,
@@ -193,7 +193,7 @@ void all_active_addresses_peer_cb (void *cls,
193 193
194void all_active_addresses_cb (void *cls, 194void all_active_addresses_cb (void *cls,
195 const struct GNUNET_HELLO_Address *address, 195 const struct GNUNET_HELLO_Address *address,
196 unsigned int active, 196 int active,
197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 197 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
198 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 198 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
199 const struct GNUNET_ATS_Information *ats, 199 const struct GNUNET_ATS_Information *ats,
@@ -268,7 +268,7 @@ void all_active_addresses_cb (void *cls,
268 268
269void all_addresses_peer_cb (void *cls, 269void all_addresses_peer_cb (void *cls,
270 const struct GNUNET_HELLO_Address *address, 270 const struct GNUNET_HELLO_Address *address,
271 unsigned int active, 271 int active,
272 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 272 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
273 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 273 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
274 const struct GNUNET_ATS_Information *ats, 274 const struct GNUNET_ATS_Information *ats,
@@ -317,7 +317,7 @@ void all_addresses_peer_cb (void *cls,
317 317
318void all_addresses_cb (void *cls, 318void all_addresses_cb (void *cls,
319 const struct GNUNET_HELLO_Address *address, 319 const struct GNUNET_HELLO_Address *address,
320 unsigned int active, 320 int active,
321 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, 321 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
322 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, 322 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
323 const struct GNUNET_ATS_Information *ats, 323 const struct GNUNET_ATS_Information *ats,
@@ -380,7 +380,7 @@ static void
380test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) 380test_performance_api (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
381{ 381{
382 if (NULL == ph) 382 if (NULL == ph)
383 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL, NULL, NULL); 383 ph = GNUNET_ATS_performance_init (cfg, NULL, NULL);
384 if (NULL == ph) 384 if (NULL == ph)
385 { 385 {
386 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize performance handle\n"); 386 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Failed to initialize performance handle\n");
diff --git a/src/ats/test_ats_api_performance_monitor.c b/src/ats/test_ats_api_performance_monitor.c
deleted file mode 100644
index 5ba6cd6bd..000000000
--- a/src/ats/test_ats_api_performance_monitor.c
+++ /dev/null
@@ -1,358 +0,0 @@
1/*
2 This file is part of GNUnet.
3 (C) 2010,2011 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/test_ats_api_performance_monitor.c
22 * @brief Test performance API:
23 * Add an address for a peer and request it. We expect an monitor callback
24 * @author Christian Grothoff
25 * @author Matthias Wachs
26 */
27#include "platform.h"
28#include "gnunet_ats_service.h"
29#include "gnunet_testing_lib.h"
30#include "ats.h"
31
32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 20)
33#define SHUTDOWN_CORRECT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5)
34
35#define ATS_COUNT 2
36
37static GNUNET_SCHEDULER_TaskIdentifier die_task;
38static GNUNET_SCHEDULER_TaskIdentifier stage_task;
39
40struct GNUNET_CONFIGURATION_Handle *cfg;
41
42static struct GNUNET_ATS_SchedulingHandle *sh;
43
44static struct GNUNET_ATS_PerformanceHandle *ph;
45
46static struct GNUNET_HELLO_Address addr[2];
47
48static struct GNUNET_ATS_Information atsi[ATS_COUNT];
49
50static int ret;
51
52static int res_suggest_cb_p0;
53static int res_suggest_cb_p1;
54
55static int res_perf_cb_p0;
56static int res_perf_cb_p1;
57
58/**
59 * Stage 0: Init, request address and wait for peer0 suggest cb
60 * Stage 1: Got peer0 suggest cb, expect monitoring cb
61 * Stage 2: Got peer0 monitoring cb, update address and expect monitor cb
62 * Stage 3: Got 2nd peer0 monitoring cb, shutdown
63 */
64
65static int stage;
66
67
68static void cleanup_addresses ()
69{
70 GNUNET_ATS_address_destroyed (sh, &addr[0], NULL);
71 GNUNET_ATS_address_destroyed (sh, &addr[1], NULL);
72}
73
74static void setup_addresses ()
75{
76 memset (&addr[0].peer,'\0', sizeof (addr[0].peer));
77 addr[0].transport_name = "test0";
78 addr[0].address = "test_addr0";
79 addr[0].address_length = strlen ("test_addr0") + 1;
80
81 atsi[0].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY);
82 atsi[0].value = htonl(100);
83
84 atsi[1].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE);
85 atsi[1].value = htonl(5);
86
87 GNUNET_ATS_address_add (sh, &addr[0], NULL, atsi, ATS_COUNT);
88
89 memset (&addr[1].peer,'\1', sizeof (addr[1].peer));
90 addr[1].transport_name = "test1";
91 addr[1].address = "test_addr1";
92 addr[1].address_length = strlen ("test_addr1") + 1;
93
94 GNUNET_ATS_address_add (sh, &addr[1], NULL, atsi, ATS_COUNT);
95}
96
97
98static void
99end_now (int res)
100{
101 if (GNUNET_SCHEDULER_NO_TASK != stage_task)
102 {
103 GNUNET_SCHEDULER_cancel (stage_task);
104 stage_task = GNUNET_SCHEDULER_NO_TASK;
105 }
106 if (GNUNET_SCHEDULER_NO_TASK != die_task)
107 {
108 GNUNET_SCHEDULER_cancel (die_task);
109 die_task = GNUNET_SCHEDULER_NO_TASK;
110 }
111 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
112
113 cleanup_addresses ();
114
115 if (NULL != ph)
116 {
117 GNUNET_ATS_performance_done (ph);
118 ph = NULL;
119 }
120
121 if (NULL != sh)
122 {
123 GNUNET_ATS_scheduling_done (sh);
124 sh = NULL;
125 }
126 ret = res;
127}
128
129static void
130end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
131{
132 die_task = GNUNET_SCHEDULER_NO_TASK;
133 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error!\n");
134 if (GNUNET_NO == res_perf_cb_p0)
135 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not get performance information for requested peer!\n");
136 if (GNUNET_YES == res_perf_cb_p1)
137 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got suggestion for not requested peer!\n");
138 if (GNUNET_NO == res_suggest_cb_p0)
139 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not get suggestion for not peer!\n");
140 if (GNUNET_YES == res_suggest_cb_p1)
141 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got suggestion for not requested peer!\n");
142 end_now (1);
143}
144
145static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
146{
147 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Success\n");
148 end_now (0);
149}
150
151
152static void
153perf_mon_cb (void *cls,
154 const struct GNUNET_PeerIdentity *peer,
155 const struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
156 const struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
157 const struct GNUNET_ATS_Information *ats,
158 uint32_t ats_count)
159{
160 int c1;
161 int c2;
162 int c3;
163
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
165 "ATS notifies about perfomance change for peer `%s'\n", GNUNET_i2s (peer));
166
167 if ((1 != stage) && (2 != stage))
168 {
169 GNUNET_break (0);
170 end_now(1);
171 return;
172 }
173
174 if (1 == stage)
175 {
176 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received 1st callback for peer `%s' with %u information\n",
177 GNUNET_i2s (&addr[0].peer), ats_count);
178 if (0 != memcmp (peer, &addr[0].peer, sizeof (addr[0].peer)))
179 {
180 res_perf_cb_p1 = GNUNET_YES;
181 GNUNET_break (0);
182 if (GNUNET_SCHEDULER_NO_TASK != die_task)
183 GNUNET_SCHEDULER_cancel (die_task);
184 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
185 return;
186 }
187
188 if (ats_count < ATS_COUNT)
189 {
190 GNUNET_break (0);
191 if (GNUNET_SCHEDULER_NO_TASK != die_task)
192 GNUNET_SCHEDULER_cancel (die_task);
193 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
194 return;
195 }
196
197 c3 = 0;
198 for (c1 = 0; c1 < ats_count; c1++)
199 {
200 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS information [%u] %u : %u \n",
201 c1, ntohl (ats[c1].type), ntohl (ats[c1].value));
202 for (c2 = 0; c2 < ATS_COUNT; c2++)
203 {
204 if (ats[c1].type == atsi[c2].type)
205 {
206 if (ats[c1].value == atsi[c2].value)
207 c3++;
208 else
209 GNUNET_break (0);
210 }
211 }
212 }
213 if (ATS_COUNT != c3)
214 {
215 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received only %u correct ATS information \n", c3);
216 if (GNUNET_SCHEDULER_NO_TASK != die_task)
217 GNUNET_SCHEDULER_cancel (die_task);
218 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
219 return;
220 }
221
222 /* Everything OK */
223 stage ++;
224 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %u correct ATS information \n", c3);
225
226 atsi[0].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY);
227 atsi[0].value = htonl(1000);
228
229 atsi[1].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE);
230 atsi[1].value = htonl(50);
231
232 GNUNET_ATS_address_update (sh, &addr[0], NULL, atsi, ATS_COUNT);
233 return;
234 }
235 if (2 == stage)
236 {
237 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received 2nd callback for peer `%s' with %u information\n",
238 GNUNET_i2s (&addr[0].peer), ats_count);
239 if (0 != memcmp (peer, &addr[0].peer, sizeof (addr[0].peer)))
240 {
241 res_perf_cb_p1 = GNUNET_YES;
242 GNUNET_break (0);
243 if (GNUNET_SCHEDULER_NO_TASK != die_task)
244 GNUNET_SCHEDULER_cancel (die_task);
245 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
246 return;
247 }
248
249 if (ats_count < ATS_COUNT)
250 {
251 GNUNET_break (0);
252 if (GNUNET_SCHEDULER_NO_TASK != die_task)
253 GNUNET_SCHEDULER_cancel (die_task);
254 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
255 return;
256 }
257
258
259 c3 = 0;
260 for (c1 = 0; c1 < ats_count; c1++)
261 {
262 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS information [%u] %u : %u \n",
263 c1, ntohl (ats[c1].type), ntohl (ats[c1].value));
264 for (c2 = 0; c2 < ATS_COUNT; c2++)
265 {
266 if (ats[c1].type == atsi[c2].type)
267 {
268 if (ats[c1].value == atsi[c2].value)
269 c3++;
270 else
271 {
272 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "ATS information [%u] should be %u, but is %u \n",
273 ntohl (ats[c1].type), ntohl(atsi[c2].value), ntohl (ats[c1].value));
274 GNUNET_break (0);
275 }
276 }
277 }
278 }
279 if (ATS_COUNT != c3)
280 {
281 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received only %u correct ATS information \n", c3);
282 if (GNUNET_SCHEDULER_NO_TASK != die_task)
283 GNUNET_SCHEDULER_cancel (die_task);
284 die_task = GNUNET_SCHEDULER_add_now (&end_badly, NULL);
285 return;
286 }
287
288 /* Everything OK */
289 stage ++;
290 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received %u correct ATS information \n", c3);
291 GNUNET_SCHEDULER_add_now (&end, NULL);
292 return;
293 }
294}
295
296void ats_suggest_cb (void *cls,
297 const struct GNUNET_HELLO_Address * address,
298 struct Session * session,
299 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
300 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
301 const struct GNUNET_ATS_Information *ats,
302 uint32_t ats_count)
303{
304 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
305 "ATS is suggesting address for peer `%s'\n", GNUNET_i2s (&address->peer));
306
307 if (0 != stage)
308 {
309 GNUNET_break (0);
310 end_now(1);
311 return;
312 }
313
314 if (0 == memcmp (&addr[0].peer, &address->peer, sizeof (address->peer)))
315 {
316 res_suggest_cb_p0 = GNUNET_YES;
317 stage = 1;
318 }
319 if (0 == memcmp (&addr[1].peer, &address->peer, sizeof (address->peer)))
320 res_suggest_cb_p1 = GNUNET_YES;
321}
322
323
324static void
325run (void *cls,
326 const struct GNUNET_CONFIGURATION_Handle *mycfg,
327 struct GNUNET_TESTING_Peer *peer)
328{
329 ret = 1;
330 stage = 0;
331 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
332 die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
333
334 sh = GNUNET_ATS_scheduling_init (cfg, &ats_suggest_cb, NULL);
335 GNUNET_assert (NULL != sh);
336
337 ph = GNUNET_ATS_performance_init (cfg, &perf_mon_cb, &ret, NULL, NULL);
338 GNUNET_assert (NULL != ph);
339
340 /* Add addresses */
341 setup_addresses ();
342
343 /* Get an active address for peer0 and expect callback */
344 GNUNET_ATS_suggest_address (sh, &addr[0].peer);
345}
346
347
348int
349main (int argc, char *argv[])
350{
351 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_performance_monitor",
352 "test_ats_api.conf",
353 &run, NULL))
354 return 1;
355 return ret;
356}
357
358/* end of file test_ats_api_performance_monitor.c */
diff --git a/src/ats/test_ats_simplistic_change_preference.c b/src/ats/test_ats_simplistic_change_preference.c
index 0cf22fb3c..793d0cb4b 100644
--- a/src/ats/test_ats_simplistic_change_preference.c
+++ b/src/ats/test_ats_simplistic_change_preference.c
@@ -318,7 +318,7 @@ run (void *cls,
318 return; 318 return;
319 } 319 }
320 320
321 perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL, NULL, NULL); 321 perf_ats = GNUNET_ATS_performance_init (cfg, NULL, NULL);
322 if (perf_ats == NULL) 322 if (perf_ats == NULL)
323 { 323 {
324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS performance!\n"); 324 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS performance!\n");
diff --git a/src/ats/test_ats_simplistic_pref_aging.c b/src/ats/test_ats_simplistic_pref_aging.c
index 14b45f91c..2681b87f5 100644
--- a/src/ats/test_ats_simplistic_pref_aging.c
+++ b/src/ats/test_ats_simplistic_pref_aging.c
@@ -368,7 +368,7 @@ run (void *cls,
368 } 368 }
369 369
370 /* Connect to ATS performance */ 370 /* Connect to ATS performance */
371 perf_ats = GNUNET_ATS_performance_init(cfg, NULL, NULL, NULL, NULL); 371 perf_ats = GNUNET_ATS_performance_init(cfg, NULL, NULL);
372 if (sched_ats == NULL) 372 if (sched_ats == NULL)
373 { 373 {
374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); 374 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n");