summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-08-29 15:34:53 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-08-29 15:34:53 +0000
commitf5136eb1b1a24c5b307ce8123dfc4cc0c85facaf (patch)
tree357763a82d29edd1bf8f533cd294818ff3ce5a9d
parent81eaa5a9d5ebe1e61790069a2777178abd1b6a2c (diff)
downloadgnunet-f5136eb1b1a24c5b307ce8123dfc4cc0c85facaf.tar.gz
gnunet-f5136eb1b1a24c5b307ce8123dfc4cc0c85facaf.zip
implemented feedback API, but not yet calling solver
-rw-r--r--src/ats/Makefile.am11
-rw-r--r--src/ats/ats.h13
-rw-r--r--src/ats/ats_api_performance.c83
-rw-r--r--src/ats/gnunet-service-ats.c2
-rw-r--r--src/ats/gnunet-service-ats_addresses.c48
-rw-r--r--src/ats/gnunet-service-ats_addresses.h34
-rw-r--r--src/ats/gnunet-service-ats_performance.c52
-rw-r--r--src/ats/gnunet-service-ats_performance.h13
-rw-r--r--src/ats/perf_ats.c2
-rw-r--r--src/ats/test_ats_api_performance_feedback.c236
-rw-r--r--src/ats/test_ats_change_preference.c2
-rw-r--r--src/ats/test_ats_simplistic_change_preference.c8
-rw-r--r--src/ats/test_ats_simplistic_pref_aging.c2
13 files changed, 498 insertions, 8 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am
index 824e19f14..805076c09 100644
--- a/src/ats/Makefile.am
+++ b/src/ats/Makefile.am
@@ -79,6 +79,7 @@ TESTING_TESTS = \
79 test_ats_simplistic_change_preference \ 79 test_ats_simplistic_change_preference \
80 test_ats_api_performance_list_addresses \ 80 test_ats_api_performance_list_addresses \
81 test_ats_api_performance_address_info \ 81 test_ats_api_performance_address_info \
82 test_ats_api_performance_feedback \
82 perf_ats_proportional_bandwidth \ 83 perf_ats_proportional_bandwidth \
83 perf_ats_proportional_delay 84 perf_ats_proportional_delay
84endif 85endif
@@ -165,6 +166,16 @@ test_ats_api_scheduling_block_and_reset_LDADD = \
165 $(top_builddir)/src/testing/libgnunettesting.la \ 166 $(top_builddir)/src/testing/libgnunettesting.la \
166 $(top_builddir)/src/ats/libgnunetats.la 167 $(top_builddir)/src/ats/libgnunetats.la
167 168
169
170
171test_ats_api_performance_feedback_SOURCES = \
172 test_ats_api_performance_feedback.c
173test_ats_api_performance_feedback_LDADD = \
174 $(top_builddir)/src/util/libgnunetutil.la \
175 $(top_builddir)/src/testing/libgnunettesting.la \
176 $(top_builddir)/src/hello/libgnunethello.la \
177 $(top_builddir)/src/ats/libgnunetats.la
178
168test_ats_api_performance_list_addresses_SOURCES = \ 179test_ats_api_performance_list_addresses_SOURCES = \
169 test_ats_api_performance_list_addresses.c 180 test_ats_api_performance_list_addresses.c
170test_ats_api_performance_list_addresses_LDADD = \ 181test_ats_api_performance_list_addresses_LDADD = \
diff --git a/src/ats/ats.h b/src/ats/ats.h
index 6fae40632..d202ddc24 100644
--- a/src/ats/ats.h
+++ b/src/ats/ats.h
@@ -261,6 +261,19 @@ struct ChangePreferenceMessage
261 /* followed by 'num_preferences' 261 /* followed by 'num_preferences'
262 * struct PreferenceInformation values */ 262 * struct PreferenceInformation values */
263}; 263};
264
265struct FeedbackPreferenceMessage
266{
267 struct GNUNET_MessageHeader header;
268
269 uint32_t num_preferences GNUNET_PACKED;
270
271 struct GNUNET_PeerIdentity peer;
272
273 /* followed by 'num_preferences'
274 * struct PreferenceInformation values */
275};
276
264GNUNET_NETWORK_STRUCT_END 277GNUNET_NETWORK_STRUCT_END
265 278
266 279
diff --git a/src/ats/ats_api_performance.c b/src/ats/ats_api_performance.c
index 8acce225f..b7c24aa53 100644
--- a/src/ats/ats_api_performance.c
+++ b/src/ats/ats_api_performance.c
@@ -866,7 +866,7 @@ GNUNET_ATS_print_preference_type (uint32_t type)
866 * @param ... 0-terminated specification of the desired changes 866 * @param ... 0-terminated specification of the desired changes
867 */ 867 */
868void 868void
869GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph, 869GNUNET_ATS_performance_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
870 const struct GNUNET_PeerIdentity *peer, ...) 870 const struct GNUNET_PeerIdentity *peer, ...)
871{ 871{
872 struct PendingMessage *p; 872 struct PendingMessage *p;
@@ -938,4 +938,85 @@ GNUNET_ATS_change_preference (struct GNUNET_ATS_PerformanceHandle *ph,
938 do_transmit (ph); 938 do_transmit (ph);
939} 939}
940 940
941/**
942 * Send feedback to ATS on how good a the requirements for a peer and a
943 * preference is satisfied by ATS
944 *
945 * @param ph performance handle
946 * @param peer identifies the peer
947 * @param ... 0-terminated specification of the desired changes
948 */
949void
950GNUNET_ATS_performance_give_feedback (struct GNUNET_ATS_PerformanceHandle *ph,
951 const struct GNUNET_PeerIdentity *peer, ...)
952{
953 struct PendingMessage *p;
954 struct FeedbackPreferenceMessage *m;
955 size_t msize;
956 uint32_t count;
957 struct PreferenceInformation *pi;
958 va_list ap;
959 enum GNUNET_ATS_PreferenceKind kind;
960
961 count = 0;
962 va_start (ap, peer);
963 while (GNUNET_ATS_PREFERENCE_END !=
964 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
965 {
966 switch (kind)
967 {
968 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
969 count++;
970 (void) va_arg (ap, double);
971
972 break;
973 case GNUNET_ATS_PREFERENCE_LATENCY:
974 count++;
975 (void) va_arg (ap, double);
976
977 break;
978 default:
979 GNUNET_assert (0);
980 }
981 }
982 va_end (ap);
983 msize =
984 count * sizeof (struct PreferenceInformation) +
985 sizeof (struct FeedbackPreferenceMessage);
986 p = GNUNET_malloc (sizeof (struct PendingMessage) + msize);
987 p->size = msize;
988 p->is_init = GNUNET_NO;
989 m = (struct FeedbackPreferenceMessage *) &p[1];
990 m->header.type = htons (GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK);
991 m->header.size = htons (msize);
992 m->num_preferences = htonl (count);
993 m->peer = *peer;
994 pi = (struct PreferenceInformation *) &m[1];
995 count = 0;
996 va_start (ap, peer);
997 while (GNUNET_ATS_PREFERENCE_END !=
998 (kind = va_arg (ap, enum GNUNET_ATS_PreferenceKind)))
999 {
1000 pi[count].preference_kind = htonl (kind);
1001 switch (kind)
1002 {
1003 case GNUNET_ATS_PREFERENCE_BANDWIDTH:
1004 pi[count].preference_value = (float) va_arg (ap, double);
1005
1006 count++;
1007 break;
1008 case GNUNET_ATS_PREFERENCE_LATENCY:
1009 pi[count].preference_value = (float) va_arg (ap, double);
1010
1011 count++;
1012 break;
1013 default:
1014 GNUNET_assert (0);
1015 }
1016 }
1017 va_end (ap);
1018 GNUNET_CONTAINER_DLL_insert_tail (ph->pending_head, ph->pending_tail, p);
1019 do_transmit (ph);
1020}
1021
941/* end of ats_api_performance.c */ 1022/* end of ats_api_performance.c */
diff --git a/src/ats/gnunet-service-ats.c b/src/ats/gnunet-service-ats.c
index 3218769a6..68be19ba5 100644
--- a/src/ats/gnunet-service-ats.c
+++ b/src/ats/gnunet-service-ats.c
@@ -159,6 +159,8 @@ run (void *cls, struct GNUNET_SERVER_Handle *server,
159 sizeof (struct ReservationRequestMessage)}, 159 sizeof (struct ReservationRequestMessage)},
160 {&GAS_handle_preference_change, NULL, 160 {&GAS_handle_preference_change, NULL,
161 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0}, 161 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_CHANGE, 0},
162 {&GAS_handle_preference_feedback, NULL,
163 GNUNET_MESSAGE_TYPE_ATS_PREFERENCE_FEEDBACK, 0},
162 {&GAS_handle_reset_backoff, NULL, 164 {&GAS_handle_reset_backoff, NULL,
163 GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF, 165 GNUNET_MESSAGE_TYPE_ATS_RESET_BACKOFF,
164 sizeof (struct ResetBackoffMessage)}, 166 sizeof (struct ResetBackoffMessage)},
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c
index 6af0a1332..080fe89d0 100644
--- a/src/ats/gnunet-service-ats_addresses.c
+++ b/src/ats/gnunet-service-ats_addresses.c
@@ -368,6 +368,11 @@ struct GAS_Addresses_Handle
368 GAS_solver_address_change_preference s_pref; 368 GAS_solver_address_change_preference s_pref;
369 369
370 /** 370 /**
371 * Give feedback about the current assignment
372 */
373 GAS_solver_address_feedback_preference s_feedback;
374
375 /**
371 * Start a bulk operation 376 * Start a bulk operation
372 */ 377 */
373 GAS_solver_bulk_start s_bulk_start; 378 GAS_solver_bulk_start s_bulk_start;
@@ -1481,6 +1486,48 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
1481 handle->s_bulk_stop (handle->solver); 1486 handle->s_bulk_stop (handle->solver);
1482} 1487}
1483 1488
1489/**
1490 * Change the preference for a peer
1491 *
1492 * @param handle the address handle
1493 * @param application the client sending this request
1494 * @param peer the peer id
1495 * @param kind the preference kind to change
1496 * @param score_abs the new preference score
1497 */
1498void
1499GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
1500 void *application,
1501 const struct GNUNET_PeerIdentity *peer,
1502 enum GNUNET_ATS_PreferenceKind kind,
1503 float score_abs)
1504{
1505 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
1506 "Received `%s' for peer `%s' for client %p\n",
1507 "PREFERENCE FEEDBACK",
1508 GNUNET_i2s (peer), application);
1509
1510 if (GNUNET_NO == handle->running)
1511 return;
1512
1513 if (GNUNET_NO == GNUNET_CONTAINER_multihashmap_contains (handle->addresses,
1514 &peer->hashPubKey))
1515 {
1516 GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
1517 "Received `%s' for unknown peer `%s' from client %p\n",
1518 "PREFERENCE FEEDBACK",
1519 GNUNET_i2s (peer), application);
1520 return;
1521 }
1522
1523 GNUNET_break (0);
1524
1525 //handle->s_bulk_start (handle->solver);
1526 /* Tell normalization about change, normalization will call callback if preference changed */
1527 //GAS_normalization_normalize_preference (client, peer, kind, score_abs);
1528 //handle->s_bulk_stop (handle->solver);
1529}
1530
1484 1531
1485/** 1532/**
1486 * Load quotas for networks from configuration 1533 * Load quotas for networks from configuration
@@ -1733,6 +1780,7 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg,
1733 ah->s_get = &GAS_proportional_get_preferred_address; 1780 ah->s_get = &GAS_proportional_get_preferred_address;
1734 ah->s_get_stop = &GAS_proportional_stop_get_preferred_address; 1781 ah->s_get_stop = &GAS_proportional_stop_get_preferred_address;
1735 ah->s_pref = &GAS_proportional_address_change_preference; 1782 ah->s_pref = &GAS_proportional_address_change_preference;
1783 ah->s_pref = &GAS_proportional_address_change_preference;
1736 ah->s_del = &GAS_proportional_address_delete; 1784 ah->s_del = &GAS_proportional_address_delete;
1737 ah->s_bulk_start = &GAS_proportional_bulk_start; 1785 ah->s_bulk_start = &GAS_proportional_bulk_start;
1738 ah->s_bulk_stop = &GAS_proportional_bulk_stop; 1786 ah->s_bulk_stop = &GAS_proportional_bulk_stop;
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h
index 3c2e040f2..a50234361 100644
--- a/src/ats/gnunet-service-ats_addresses.h
+++ b/src/ats/gnunet-service-ats_addresses.h
@@ -448,6 +448,23 @@ typedef void
448 enum GNUNET_ATS_PreferenceKind kind, 448 enum GNUNET_ATS_PreferenceKind kind,
449 double pref_rel); 449 double pref_rel);
450 450
451
452/**
453 * Give feedback about the current assignment
454 *
455 * @param handle the solver handle
456 * @param application the application sending this request
457 * @param peer the peer id
458 * @param kind the preference kind for this feedback
459 * @param score the feedback score
460 */
461typedef void
462(*GAS_solver_address_feedback_preference) (void *solver,
463 void *application,
464 const struct GNUNET_PeerIdentity *peer,
465 enum GNUNET_ATS_PreferenceKind kind,
466 double score);
467
451/** 468/**
452 * Notify the solver about a bulk operation changing possibly a lot of values 469 * Notify the solver about a bulk operation changing possibly a lot of values
453 * Solver will not resolve until all bulk operations are marked as done 470 * Solver will not resolve until all bulk operations are marked as done
@@ -776,6 +793,23 @@ GAS_addresses_change_preference (struct GAS_Addresses_Handle *handle,
776 793
777 794
778/** 795/**
796 * Change the preference for a peer
797 *
798 * @param handle the address handle
799 * @param client the client sending this request
800 * @param peer the peer id
801 * @param kind the preference kind to change
802 * @param score_abs the new preference score
803 */
804void
805GAS_addresses_preference_feedback (struct GAS_Addresses_Handle *handle,
806 void *client,
807 const struct GNUNET_PeerIdentity *peer,
808 enum GNUNET_ATS_PreferenceKind kind,
809 float score_abs);
810
811
812/**
779 * Iterator for GAS_addresses_iterate_peers 813 * Iterator for GAS_addresses_iterate_peers
780 * 814 *
781 * @param p_it_cls closure 815 * @param p_it_cls closure
diff --git a/src/ats/gnunet-service-ats_performance.c b/src/ats/gnunet-service-ats_performance.c
index f0986959c..bb7ed7934 100644
--- a/src/ats/gnunet-service-ats_performance.c
+++ b/src/ats/gnunet-service-ats_performance.c
@@ -649,6 +649,58 @@ GAS_handle_preference_change (void *cls,
649 649
650 650
651/** 651/**
652 * Handle 'preference feedback' messages from clients.
653 *
654 * @param cls unused, NULL
655 * @param client client that sent the request
656 * @param message the request message
657 */
658void
659GAS_handle_preference_feedback (void *cls,
660 struct GNUNET_SERVER_Client *client,
661 const struct GNUNET_MessageHeader *message)
662{
663 const struct FeedbackPreferenceMessage *msg;
664 const struct PreferenceInformation *pi;
665 uint16_t msize;
666 uint32_t nump;
667 uint32_t i;
668
669 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Received `%s' message\n",
670 "PREFERENCE_FEEDBACK");
671 msize = ntohs (message->size);
672 if (msize < sizeof (struct FeedbackPreferenceMessage))
673 {
674 GNUNET_break (0);
675 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
676 return;
677 }
678 msg = (const struct FeedbackPreferenceMessage *) message;
679 nump = ntohl (msg->num_preferences);
680 if (msize !=
681 sizeof (struct FeedbackPreferenceMessage) +
682 nump * sizeof (struct PreferenceInformation))
683 {
684 GNUNET_break (0);
685 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
686 return;
687 }
688 GNUNET_STATISTICS_update (GSA_stats, "# preference feedbacks requests processed",
689 1, GNUNET_NO);
690 pi = (const struct PreferenceInformation *) &msg[1];
691 for (i = 0; i < nump; i++)
692 GAS_addresses_preference_feedback (GSA_addresses,
693 client,
694 &msg->peer,
695 (enum GNUNET_ATS_PreferenceKind)
696 ntohl (pi[i].preference_kind),
697 pi[i].preference_value);
698 GNUNET_SERVER_receive_done (client, GNUNET_OK);
699}
700
701
702
703/**
652 * Initialize performance subsystem. 704 * Initialize performance subsystem.
653 * 705 *
654 * @param server handle to our server 706 * @param server handle to our server
diff --git a/src/ats/gnunet-service-ats_performance.h b/src/ats/gnunet-service-ats_performance.h
index 790e1cc4a..1a96c8819 100644
--- a/src/ats/gnunet-service-ats_performance.h
+++ b/src/ats/gnunet-service-ats_performance.h
@@ -132,6 +132,19 @@ GAS_handle_preference_change (void *cls,
132 const struct GNUNET_MessageHeader *message); 132 const struct GNUNET_MessageHeader *message);
133 133
134 134
135/**
136 * Handle 'preference feedback' messages from clients.
137 *
138 * @param cls unused, NULL
139 * @param client client that sent the request
140 * @param message the request message
141 */
142void
143GAS_handle_preference_feedback (void *cls,
144 struct GNUNET_SERVER_Client *client,
145 const struct GNUNET_MessageHeader *message);
146
147
135void 148void
136GAS_handle_monitor (void *cls, 149GAS_handle_monitor (void *cls,
137 struct GNUNET_SERVER_Client *client, 150 struct GNUNET_SERVER_Client *client,
diff --git a/src/ats/perf_ats.c b/src/ats/perf_ats.c
index 726b78662..2cb6a0116 100644
--- a/src/ats/perf_ats.c
+++ b/src/ats/perf_ats.c
@@ -518,7 +518,7 @@ ats_pref_task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
518 518
519 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set preference for master %u: %f\n", 519 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Set preference for master %u: %f\n",
520 bp->no, last); 520 bp->no, last);
521 GNUNET_ATS_change_preference (bp->p_handle, &bp->destination->id, 521 GNUNET_ATS_performance_change_preference (bp->p_handle, &bp->destination->id,
522 GNUNET_ATS_PREFERENCE_BANDWIDTH, (double) last, 522 GNUNET_ATS_PREFERENCE_BANDWIDTH, (double) last,
523 GNUNET_ATS_PREFERENCE_END); 523 GNUNET_ATS_PREFERENCE_END);
524 last++; 524 last++;
diff --git a/src/ats/test_ats_api_performance_feedback.c b/src/ats/test_ats_api_performance_feedback.c
new file mode 100644
index 000000000..39cc5136f
--- /dev/null
+++ b/src/ats/test_ats_api_performance_feedback.c
@@ -0,0 +1,236 @@
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_feedback
22 * @brief Test performance API:
23 * Test for address feedback API
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_addrinfo_cb_p0;
56static int res_addrinfo_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
75end_now (int res)
76{
77 if (GNUNET_SCHEDULER_NO_TASK != stage_task)
78 {
79 GNUNET_SCHEDULER_cancel (stage_task);
80 stage_task = GNUNET_SCHEDULER_NO_TASK;
81 }
82 if (GNUNET_SCHEDULER_NO_TASK != die_task)
83 {
84 GNUNET_SCHEDULER_cancel (die_task);
85 die_task = GNUNET_SCHEDULER_NO_TASK;
86 }
87 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutdown\n");
88
89 cleanup_addresses ();
90
91 if (NULL != ph)
92 {
93 GNUNET_ATS_performance_done (ph);
94 ph = NULL;
95 }
96
97 if (NULL != sh)
98 {
99 GNUNET_ATS_scheduling_done (sh);
100 sh = NULL;
101 }
102 ret = res;
103}
104
105#if 0
106static void
107end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
108{
109 die_task = GNUNET_SCHEDULER_NO_TASK;
110 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Error!\n");
111 if (GNUNET_NO == res_addrinfo_cb_p0)
112 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not get address information for requested peer0!\n");
113 if (GNUNET_NO == res_addrinfo_cb_p1)
114 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not get address information for requested peer1!\n");
115 if (GNUNET_NO == res_suggest_cb_p0)
116 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Did not get suggestion for not peer!\n");
117 if (GNUNET_YES == res_suggest_cb_p1)
118 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Got suggestion for not requested peer!\n");
119 end_now (1);
120}
121#endif
122
123static void end (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
124{
125 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Success\n");
126 end_now (0);
127}
128
129static void
130addrinfo_cb (void *cls,
131 const struct GNUNET_HELLO_Address *address,
132 int address_active,
133 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
134 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
135 const struct GNUNET_ATS_Information *ats,
136 uint32_t ats_count)
137{
138 //static int shutdown = GNUNET_NO;
139 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
140 "ATS has information about address for peer `%s'\n", GNUNET_i2s (&address->peer));
141
142 if (0 == memcmp (&addr[0].peer, &address->peer, sizeof (address->peer)))
143 res_addrinfo_cb_p0 = GNUNET_YES;
144 if (0 == memcmp (&addr[1].peer, &address->peer, sizeof (address->peer)))
145 res_addrinfo_cb_p1 = GNUNET_YES;
146}
147
148void ats_suggest_cb (void *cls,
149 const struct GNUNET_HELLO_Address * address,
150 struct Session * session,
151 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out,
152 struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in,
153 const struct GNUNET_ATS_Information *ats,
154 uint32_t ats_count)
155{
156 static int feedbacks = 0;
157
158 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
159 "ATS is suggesting address for peer `%s'\n", GNUNET_i2s (&address->peer));
160
161 if (feedbacks >= 2)
162 return;
163 feedbacks++;
164
165 if (0 == memcmp (&addr[0].peer, &address->peer, sizeof (address->peer)))
166 {
167 res_suggest_cb_p0 = GNUNET_YES;
168 stage = 1;
169 GNUNET_ATS_address_update (sh, &addr[1], NULL, atsi, ATS_COUNT);
170 GNUNET_ATS_performance_give_feedback (ph, &addr[0].peer, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
171 }
172 if (0 == memcmp (&addr[1].peer, &address->peer, sizeof (address->peer)))
173 {
174 GNUNET_ATS_performance_give_feedback (ph, &addr[1].peer, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
175 res_suggest_cb_p1 = GNUNET_YES;
176 }
177}
178
179
180static void next (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc)
181{
182 memset (&addr[0].peer,'\0', sizeof (addr[0].peer));
183 addr[0].transport_name = "test0";
184 addr[0].address = "test_addr0";
185 addr[0].address_length = strlen ("test_addr0") + 1;
186
187 atsi[0].type = htonl(GNUNET_ATS_QUALITY_NET_DELAY);
188 atsi[0].value = htonl(100);
189
190 atsi[1].type = htonl(GNUNET_ATS_QUALITY_NET_DISTANCE);
191 atsi[1].value = htonl(5);
192
193 GNUNET_ATS_address_add (sh, &addr[0], NULL, atsi, ATS_COUNT);
194 GNUNET_ATS_suggest_address (sh, &addr[0].peer);
195
196 memset (&addr[1].peer,'\1', sizeof (addr[1].peer));
197 addr[1].transport_name = "test1";
198 addr[1].address = "test_addr1";
199 addr[1].address_length = strlen ("test_addr1") + 1;
200
201 GNUNET_ATS_address_add (sh, &addr[1], NULL, atsi, ATS_COUNT);
202 GNUNET_ATS_suggest_address (sh, &addr[1].peer);
203 GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &end, NULL);
204}
205
206static void
207run (void *cls,
208 const struct GNUNET_CONFIGURATION_Handle *mycfg,
209 struct GNUNET_TESTING_Peer *peer)
210{
211 ret = 1;
212 stage = 0;
213 cfg = (struct GNUNET_CONFIGURATION_Handle *) mycfg;
214// die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL);
215
216 ph = GNUNET_ATS_performance_init (cfg, &addrinfo_cb, NULL);
217 GNUNET_assert (NULL != ph);
218
219 sh = GNUNET_ATS_scheduling_init (cfg, &ats_suggest_cb, NULL);
220 GNUNET_assert (NULL != sh);
221
222 GNUNET_SCHEDULER_add_delayed (SHUTDOWN_CORRECT, &next, NULL);
223}
224
225
226int
227main (int argc, char *argv[])
228{
229 if (0 != GNUNET_TESTING_peer_run ("test_ats_api_performance_monitor",
230 "test_ats_api.conf",
231 &run, NULL))
232 return 1;
233 return ret;
234}
235
236/* end of file test_ats_api_performance_feedback.c */
diff --git a/src/ats/test_ats_change_preference.c b/src/ats/test_ats_change_preference.c
index 8fcd431cd..ff34d00d6 100644
--- a/src/ats/test_ats_change_preference.c
+++ b/src/ats/test_ats_change_preference.c
@@ -193,7 +193,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
193 { 193 {
194 /* Changing preference for peer 0 */ 194 /* Changing preference for peer 0 */
195 stage ++; 195 stage ++;
196 GNUNET_ATS_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END); 196 GNUNET_ATS_performance_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
197 sug_p0 = GNUNET_NO; 197 sug_p0 = GNUNET_NO;
198 sug_p1 = GNUNET_NO; 198 sug_p1 = GNUNET_NO;
199 return; 199 return;
diff --git a/src/ats/test_ats_simplistic_change_preference.c b/src/ats/test_ats_simplistic_change_preference.c
index 793d0cb4b..80759b874 100644
--- a/src/ats/test_ats_simplistic_change_preference.c
+++ b/src/ats/test_ats_simplistic_change_preference.c
@@ -384,20 +384,20 @@ run (void *cls,
384 384
385 385
386 /* Change bandwidth preference */ 386 /* Change bandwidth preference */
387 GNUNET_ATS_change_preference (perf_ats, 387 GNUNET_ATS_performance_change_preference (perf_ats,
388 &p[0].id, 388 &p[0].id,
389 GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END); 389 GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
390 GNUNET_ATS_change_preference (perf_ats, 390 GNUNET_ATS_performance_change_preference (perf_ats,
391 &p[1].id, 391 &p[1].id,
392 GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END); 392 GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
393 393
394 394
395 /* Change latency preference */ 395 /* Change latency preference */
396 396
397 GNUNET_ATS_change_preference (perf_ats, 397 GNUNET_ATS_performance_change_preference (perf_ats,
398 &p[0].id, 398 &p[0].id,
399 GNUNET_ATS_PREFERENCE_LATENCY,(double) 10, GNUNET_ATS_PREFERENCE_END); 399 GNUNET_ATS_PREFERENCE_LATENCY,(double) 10, GNUNET_ATS_PREFERENCE_END);
400 GNUNET_ATS_change_preference (perf_ats, 400 GNUNET_ATS_performance_change_preference (perf_ats,
401 &p[1].id, 401 &p[1].id,
402 GNUNET_ATS_PREFERENCE_LATENCY,(double) 100, GNUNET_ATS_PREFERENCE_END); 402 GNUNET_ATS_PREFERENCE_LATENCY,(double) 100, GNUNET_ATS_PREFERENCE_END);
403 GNUNET_SCHEDULER_add_delayed (SLEEP, &sleep_task, NULL); 403 GNUNET_SCHEDULER_add_delayed (SLEEP, &sleep_task, NULL);
diff --git a/src/ats/test_ats_simplistic_pref_aging.c b/src/ats/test_ats_simplistic_pref_aging.c
index 2681b87f5..305eda1a5 100644
--- a/src/ats/test_ats_simplistic_pref_aging.c
+++ b/src/ats/test_ats_simplistic_pref_aging.c
@@ -193,7 +193,7 @@ address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address,
193 { 193 {
194 /* Changing preference for peer 0 */ 194 /* Changing preference for peer 0 */
195 stage ++; 195 stage ++;
196 GNUNET_ATS_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END); 196 GNUNET_ATS_performance_change_preference (perf_ats, &p[0].id, GNUNET_ATS_PREFERENCE_BANDWIDTH,(double) 1000, GNUNET_ATS_PREFERENCE_END);
197 sug_p0 = GNUNET_NO; 197 sug_p0 = GNUNET_NO;
198 sug_p1 = GNUNET_NO; 198 sug_p1 = GNUNET_NO;
199 return; 199 return;