diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-24 15:06:45 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-24 15:06:45 +0000 |
commit | 7ba01a86dfa31c8e4b97e099437fbbfba32d191b (patch) | |
tree | 9cba59bb369223f840dbc55cd68f1095c10ad92f /src/ats | |
parent | 1e007a89197769e4e0f5ad36b583689a27f33cac (diff) | |
download | gnunet-7ba01a86dfa31c8e4b97e099437fbbfba32d191b.tar.gz gnunet-7ba01a86dfa31c8e4b97e099437fbbfba32d191b.zip |
implemented ats property normalization with callback to address
to do: recalculate min/max to prevent outdated max values have an impact on normalization
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/Makefile.am | 10 | ||||
-rw-r--r-- | src/ats/ats_api_scheduling.c | 15 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 39 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 1 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 125 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.h | 20 | ||||
-rw-r--r-- | src/ats/perf_ats_mlp.c | 12 | ||||
-rw-r--r-- | src/ats/test_ats_mlp.c | 11 | ||||
-rw-r--r-- | src/ats/test_ats_mlp_update.c | 12 | ||||
-rw-r--r-- | src/ats/test_ats_normalization_update_quality.c | 237 |
10 files changed, 438 insertions, 44 deletions
diff --git a/src/ats/Makefile.am b/src/ats/Makefile.am index 1b7b9d818..3f51e3cca 100644 --- a/src/ats/Makefile.am +++ b/src/ats/Makefile.am | |||
@@ -71,6 +71,7 @@ check_PROGRAMS = \ | |||
71 | test_ats_api_scheduling_destroy_session \ | 71 | test_ats_api_scheduling_destroy_session \ |
72 | test_ats_api_scheduling_destroy_inbound_connection \ | 72 | test_ats_api_scheduling_destroy_inbound_connection \ |
73 | test_ats_api_scheduling_block_and_reset \ | 73 | test_ats_api_scheduling_block_and_reset \ |
74 | test_ats_normalization_update_quality \ | ||
74 | test_ats_change_preference \ | 75 | test_ats_change_preference \ |
75 | test_ats_simplistic \ | 76 | test_ats_simplistic \ |
76 | test_ats_simplistic_switch_networks \ | 77 | test_ats_simplistic_switch_networks \ |
@@ -232,6 +233,15 @@ perf_ats_mlp_LDADD = \ | |||
232 | $(top_builddir)/src/ats/libgnunetats.la | 233 | $(top_builddir)/src/ats/libgnunetats.la |
233 | endif | 234 | endif |
234 | 235 | ||
236 | test_ats_normalization_update_quality_SOURCES = \ | ||
237 | test_ats_normalization_update_quality.c test_ats_api_common.c | ||
238 | test_ats_normalization_update_quality_LDADD = \ | ||
239 | $(GN_LIBGLPK) \ | ||
240 | $(top_builddir)/src/util/libgnunetutil.la \ | ||
241 | $(top_builddir)/src/statistics/libgnunetstatistics.la \ | ||
242 | $(top_builddir)/src/testing/libgnunettesting.la \ | ||
243 | $(top_builddir)/src/ats/libgnunetats.la | ||
244 | |||
235 | #test_ats_mlp_averaging_SOURCES = \ | 245 | #test_ats_mlp_averaging_SOURCES = \ |
236 | # $(GN_MLP_SRC) test_ats_mlp_averaging.c test_ats_api_common.c | 246 | # $(GN_MLP_SRC) test_ats_mlp_averaging.c test_ats_api_common.c |
237 | #test_ats_mlp_averaging_LDADD = \ | 247 | #test_ats_mlp_averaging_LDADD = \ |
diff --git a/src/ats/ats_api_scheduling.c b/src/ats/ats_api_scheduling.c index acd252245..bbbdc153c 100644 --- a/src/ats/ats_api_scheduling.c +++ b/src/ats/ats_api_scheduling.c | |||
@@ -846,6 +846,21 @@ GNUNET_ATS_print_network_type (uint32_t net) | |||
846 | return NULL; | 846 | return NULL; |
847 | } | 847 | } |
848 | 848 | ||
849 | /** | ||
850 | * Convert a ATS property to a string | ||
851 | * | ||
852 | * @param type the atsi type | ||
853 | * @return a string or NULL if invalid | ||
854 | */ | ||
855 | const char * | ||
856 | GNUNET_ATS_print_property_type (uint32_t type) | ||
857 | { | ||
858 | char *props[GNUNET_ATS_PropertyCount] = GNUNET_ATS_PropertyStrings; | ||
859 | if ((type > 0) && (type < GNUNET_ATS_PropertyCount)) | ||
860 | return props[type]; | ||
861 | return NULL; | ||
862 | } | ||
863 | |||
849 | 864 | ||
850 | /** | 865 | /** |
851 | * Returns where the address is located: LAN or WAN or ... | 866 | * Returns where the address is located: LAN or WAN or ... |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index d7c4100ea..03400136a 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -809,6 +809,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n", | 809 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' session id %u, %p\n", |
810 | GNUNET_i2s (peer), session_id, aa); | 810 | GNUNET_i2s (peer), session_id, aa); |
811 | /* Tell solver about new address */ | 811 | /* Tell solver about new address */ |
812 | GAS_normalization_normalize_property (aa, atsi, atsi_count); | ||
812 | handle->s_add (handle->solver, handle->addresses, aa, addr_net); | 813 | handle->s_add (handle->solver, handle->addresses, aa, addr_net); |
813 | /* Notify performance clients about new address */ | 814 | /* Notify performance clients about new address */ |
814 | GAS_performance_notify_all_clients (&aa->peer, | 815 | GAS_performance_notify_all_clients (&aa->peer, |
@@ -852,6 +853,7 @@ GAS_addresses_add (struct GAS_Addresses_Handle *handle, | |||
852 | } | 853 | } |
853 | 854 | ||
854 | /* Notify solver about update with atsi information and session */ | 855 | /* Notify solver about update with atsi information and session */ |
856 | GAS_normalization_normalize_property (ea, atsi, atsi_count); | ||
855 | handle->s_update (handle->solver, handle->addresses, ea, session_id, ea->used, atsi_delta, atsi_delta_count); | 857 | handle->s_update (handle->solver, handle->addresses, ea, session_id, ea->used, atsi_delta, atsi_delta_count); |
856 | GNUNET_free_non_null (atsi_delta); | 858 | GNUNET_free_non_null (atsi_delta); |
857 | 859 | ||
@@ -1308,6 +1310,15 @@ GAS_addresses_handle_backoff_reset (struct GAS_Addresses_Handle *handle, | |||
1308 | NULL)); | 1310 | NULL)); |
1309 | } | 1311 | } |
1310 | 1312 | ||
1313 | |||
1314 | /** | ||
1315 | * The preference changed for a peer | ||
1316 | * | ||
1317 | * @param cls the address handle | ||
1318 | * @param peer the peer | ||
1319 | * @param kind the ATS kind | ||
1320 | * @param double the new relative preference value | ||
1321 | */ | ||
1311 | static void | 1322 | static void |
1312 | normalized_preference_changed_cb (void *cls, | 1323 | normalized_preference_changed_cb (void *cls, |
1313 | const struct GNUNET_PeerIdentity *peer, | 1324 | const struct GNUNET_PeerIdentity *peer, |
@@ -1320,6 +1331,31 @@ normalized_preference_changed_cb (void *cls, | |||
1320 | handle->s_pref (handle->solver, handle->addresses, peer, kind, pref_rel); | 1331 | handle->s_pref (handle->solver, handle->addresses, peer, kind, pref_rel); |
1321 | } | 1332 | } |
1322 | 1333 | ||
1334 | |||
1335 | /** | ||
1336 | * The relative value for a property changed | ||
1337 | * | ||
1338 | * @param cls the address handle | ||
1339 | * @param peer the peer | ||
1340 | * @param kind the ATS kind | ||
1341 | * @param double the new relative preference value | ||
1342 | */ | ||
1343 | static void | ||
1344 | normalized_property_changed_cb (void *cls, | ||
1345 | const struct ATS_Address *peer, | ||
1346 | uint32_t type, | ||
1347 | double prop_rel) | ||
1348 | { | ||
1349 | GNUNET_assert (NULL != cls); | ||
1350 | //struct GAS_Addresses_Handle *handle = cls; | ||
1351 | /* Tell solver about update */ | ||
1352 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
1353 | "Normalized property %s for peer `%s' changed to %.3f \n", | ||
1354 | GNUNET_ATS_print_property_type (type), | ||
1355 | GNUNET_i2s (&peer->peer), | ||
1356 | prop_rel); | ||
1357 | } | ||
1358 | |||
1323 | const double * | 1359 | const double * |
1324 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | 1360 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) |
1325 | { | 1361 | { |
@@ -1626,7 +1662,8 @@ GAS_addresses_init (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
1626 | GNUNET_assert (NULL != ah->s_del); | 1662 | GNUNET_assert (NULL != ah->s_del); |
1627 | GNUNET_assert (NULL != ah->s_done); | 1663 | GNUNET_assert (NULL != ah->s_done); |
1628 | 1664 | ||
1629 | GAS_normalization_start (&normalized_preference_changed_cb, ah); | 1665 | GAS_normalization_start (&normalized_preference_changed_cb, ah, |
1666 | &normalized_property_changed_cb, ah); | ||
1630 | quota_count = load_quotas(cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount); | 1667 | quota_count = load_quotas(cfg, quotas_in, quotas_out, GNUNET_ATS_NetworkTypeCount); |
1631 | 1668 | ||
1632 | ah->solver = ah->s_init (cfg, stats, | 1669 | ah->solver = ah->s_init (cfg, stats, |
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index cfc54b2ea..8c462ed8c 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -237,6 +237,7 @@ struct GAS_Addresses_Handle; | |||
237 | struct GAS_NormalizationInfo | 237 | struct GAS_NormalizationInfo |
238 | { | 238 | { |
239 | unsigned int index; | 239 | unsigned int index; |
240 | uint32_t avg; | ||
240 | uint32_t atsi_abs[GAS_normalization_queue_length]; | 241 | uint32_t atsi_abs[GAS_normalization_queue_length]; |
241 | }; | 242 | }; |
242 | 243 | ||
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index f5dbf04c9..84a07b0d8 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -29,6 +29,7 @@ | |||
29 | #include "gnunet-service-ats_addresses.h" | 29 | #include "gnunet-service-ats_addresses.h" |
30 | #include "gnunet-service-ats_normalization.h" | 30 | #include "gnunet-service-ats_normalization.h" |
31 | 31 | ||
32 | #define LOG(kind,...) GNUNET_log_from (kind, "ats-normalization",__VA_ARGS__) | ||
32 | 33 | ||
33 | 34 | ||
34 | /** | 35 | /** |
@@ -144,6 +145,17 @@ static void *pref_changed_cb_cls; | |||
144 | 145 | ||
145 | 146 | ||
146 | /** | 147 | /** |
148 | * Callback to call on changing property values | ||
149 | */ | ||
150 | GAS_Normalization_property_changed_cb prop_ch_cb; | ||
151 | |||
152 | /** | ||
153 | * Closure for callback to call on changing property values | ||
154 | */ | ||
155 | void *prop_ch_cb_cls; | ||
156 | |||
157 | |||
158 | /** | ||
147 | * Hashmap to store peer information for preference normalization | 159 | * Hashmap to store peer information for preference normalization |
148 | */ | 160 | */ |
149 | static struct GNUNET_CONTAINER_MultiHashMap *preference_peers; | 161 | static struct GNUNET_CONTAINER_MultiHashMap *preference_peers; |
@@ -395,13 +407,12 @@ preference_aging (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
395 | * @param kind the kind to change the preference | 407 | * @param kind the kind to change the preference |
396 | * @param score_abs the normalized score | 408 | * @param score_abs the normalized score |
397 | */ | 409 | */ |
398 | float | 410 | void |
399 | GAS_normalization_normalize_preference (void *src, | 411 | GAS_normalization_normalize_preference (void *src, |
400 | const struct GNUNET_PeerIdentity *peer, | 412 | const struct GNUNET_PeerIdentity *peer, |
401 | enum GNUNET_ATS_PreferenceKind kind, | 413 | enum GNUNET_ATS_PreferenceKind kind, |
402 | float score_abs) | 414 | float score_abs) |
403 | { | 415 | { |
404 | float score_rel; | ||
405 | struct PreferenceClient *c_cur; | 416 | struct PreferenceClient *c_cur; |
406 | struct PreferencePeer *p_cur; | 417 | struct PreferencePeer *p_cur; |
407 | struct PeerRelative *r_cur; | 418 | struct PeerRelative *r_cur; |
@@ -421,7 +432,7 @@ GAS_normalization_normalize_preference (void *src, | |||
421 | if (kind >= GNUNET_ATS_PreferenceCount) | 432 | if (kind >= GNUNET_ATS_PreferenceCount) |
422 | { | 433 | { |
423 | GNUNET_break (0); | 434 | GNUNET_break (0); |
424 | return 0.0; | 435 | return; |
425 | } | 436 | } |
426 | 437 | ||
427 | /* Find preference client */ | 438 | /* Find preference client */ |
@@ -472,9 +483,7 @@ GAS_normalization_normalize_preference (void *src, | |||
472 | GNUNET_CONTAINER_multihashmap_put (preference_peers, &r_cur->id.hashPubKey, | 483 | GNUNET_CONTAINER_multihashmap_put (preference_peers, &r_cur->id.hashPubKey, |
473 | r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); | 484 | r_cur, GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY); |
474 | } | 485 | } |
475 | 486 | update_preference (c_cur, p_cur, kind, score_abs); | |
476 | score_rel = update_preference (c_cur, p_cur, kind, score_abs); | ||
477 | return score_rel; | ||
478 | } | 487 | } |
479 | 488 | ||
480 | 489 | ||
@@ -521,14 +530,15 @@ struct Property properties[GNUNET_ATS_QualityPropertiesCount]; | |||
521 | * @return the new average or GNUNET_ATS_VALUE_UNDEFINED | 530 | * @return the new average or GNUNET_ATS_VALUE_UNDEFINED |
522 | */ | 531 | */ |
523 | 532 | ||
524 | uint32_t property_average (struct ATS_Address *address, | 533 | uint32_t |
525 | const struct GNUNET_ATS_Information *atsi) | 534 | property_average (struct ATS_Address *address, |
535 | const struct GNUNET_ATS_Information *atsi) | ||
526 | { | 536 | { |
527 | struct GAS_NormalizationInfo *ni; | 537 | struct GAS_NormalizationInfo *ni; |
528 | uint32_t current_type; | 538 | uint32_t current_type; |
529 | uint32_t current_val; | 539 | uint32_t current_val; |
530 | 540 | uint32_t res; | |
531 | uint32_t sum; | 541 | uint64_t sum; |
532 | uint32_t count; | 542 | uint32_t count; |
533 | unsigned int c1; | 543 | unsigned int c1; |
534 | unsigned int index; | 544 | unsigned int index; |
@@ -557,6 +567,7 @@ uint32_t property_average (struct ATS_Address *address, | |||
557 | ni->index = 0; | 567 | ni->index = 0; |
558 | 568 | ||
559 | count = 0; | 569 | count = 0; |
570 | sum = 0; | ||
560 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) | 571 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) |
561 | { | 572 | { |
562 | if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1]) | 573 | if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1]) |
@@ -572,52 +583,84 @@ uint32_t property_average (struct ATS_Address *address, | |||
572 | } | 583 | } |
573 | } | 584 | } |
574 | GNUNET_assert (0 != count); | 585 | GNUNET_assert (0 != count); |
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New average from %u elements: %u\n", count, sum / count); | 586 | res = sum / count; |
576 | return 0; | 587 | LOG (GNUNET_ERROR_TYPE_DEBUG, "New average of `%s' created by adding %u from %u elements: %u\n", |
588 | GNUNET_ATS_print_property_type(current_type), | ||
589 | current_val, count, res , sum); | ||
590 | ni->avg = res; | ||
591 | return res; | ||
577 | } | 592 | } |
578 | 593 | ||
579 | double property_normalize (struct Property *p, | 594 | /** |
580 | struct ATS_Address *address, | 595 | * Normalize avg_value to a range of values between [1.0, 2.0] |
581 | uint32_t type, | 596 | * based on min max values currently known. |
582 | uint32_t avg_value) | 597 | * |
598 | * @param property p the property | ||
599 | * @param address the address | ||
600 | * @param type the atsi type | ||
601 | * @param avg_value the value to normalize | ||
602 | */ | ||
603 | |||
604 | static void | ||
605 | property_normalize (struct Property *p, | ||
606 | struct ATS_Address *address, | ||
607 | uint32_t type, | ||
608 | uint32_t avg_value) | ||
583 | { | 609 | { |
584 | double res; | 610 | double res; |
585 | double delta; | 611 | double delta; |
612 | uint32_t current_min; | ||
613 | |||
586 | /* Normalize the values of this property */ | 614 | /* Normalize the values of this property */ |
587 | if (p->max < avg_value) | 615 | if (avg_value > p->max) |
588 | { | 616 | { |
589 | p->max = avg_value; | 617 | p->max = avg_value; |
590 | if (GNUNET_NO == p->have_max) | 618 | if (GNUNET_NO == p->have_max) |
591 | p->have_max = GNUNET_YES; | 619 | p->have_max = GNUNET_YES; |
592 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 620 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
593 | "New maximum of %u for property %u\n", | 621 | "New maximum of %u for property %s\n", |
594 | p->max, avg_value); | 622 | p->max, GNUNET_ATS_print_property_type (type)); |
595 | } | 623 | } |
596 | if (p->min > avg_value) | 624 | |
625 | if ((avg_value < p->min) && (avg_value < p->max)) | ||
597 | { | 626 | { |
598 | p->min = avg_value; | 627 | p->min = avg_value; |
599 | if (GNUNET_NO == p->have_min) | 628 | if (GNUNET_NO == p->have_min) |
600 | p->have_min = GNUNET_YES; | 629 | p->have_min = GNUNET_YES; |
601 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 630 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
602 | "New minimum of %u for property %u\n", | 631 | "New minimum of %u for property %s\n", |
603 | p->min, avg_value); | 632 | p->min, GNUNET_ATS_print_property_type (type)); |
604 | } | 633 | } |
605 | 634 | ||
606 | if ((GNUNET_YES == p->have_max) && (GNUNET_YES == p->have_min)) | 635 | current_min = p->min; |
636 | if (UINT32_MAX == p->min) | ||
637 | current_min = 0; /* If we do not have a minimum we use 0.0 */ | ||
638 | |||
639 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Normalizing %u: new normalized property `%s' using min=%u max=%u\n", | ||
640 | avg_value, | ||
641 | GNUNET_ATS_print_property_type (type), | ||
642 | current_min, p->max); | ||
643 | |||
644 | if (GNUNET_YES == p->have_max) | ||
607 | { | 645 | { |
608 | delta = p->max - p->min; | 646 | delta = p->max - current_min; |
609 | res = (delta + avg_value) / (delta); | 647 | res = (delta + (avg_value - current_min)) / (delta); |
610 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 648 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
611 | "New normalized value of %f for property %u\n", | 649 | "Peer `%s': New normalized value of %f for property %s\n", |
612 | res, type); | 650 | GNUNET_i2s (&address->peer), res, GNUNET_ATS_print_property_type (type)); |
613 | return res; | 651 | if (NULL != prop_ch_cb) |
652 | prop_ch_cb (prop_ch_cb_cls, address, type, res); | ||
614 | } | 653 | } |
615 | |||
616 | return DEFAULT_REL_QUALITY; | ||
617 | } | 654 | } |
618 | 655 | ||
619 | 656 | ||
620 | 657 | /** | |
658 | * Update and normalize a atsi performance information | ||
659 | * | ||
660 | * @param address the address to update | ||
661 | * @param atsi the array of performance information | ||
662 | * @param atsi_count the number of atsi information in the array | ||
663 | */ | ||
621 | void | 664 | void |
622 | GAS_normalization_normalize_property (struct ATS_Address *address, | 665 | GAS_normalization_normalize_property (struct ATS_Address *address, |
623 | const struct GNUNET_ATS_Information *atsi, | 666 | const struct GNUNET_ATS_Information *atsi, |
@@ -633,6 +676,9 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
633 | GNUNET_assert (NULL != address); | 676 | GNUNET_assert (NULL != address); |
634 | GNUNET_assert (NULL != atsi); | 677 | GNUNET_assert (NULL != atsi); |
635 | 678 | ||
679 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Updating %u elements for peer `%s'\n", | ||
680 | atsi_count, GNUNET_i2s (&address->peer)); | ||
681 | |||
636 | for (c1 = 0; c1 < atsi_count; c1++) | 682 | for (c1 = 0; c1 < atsi_count; c1++) |
637 | { | 683 | { |
638 | current_type = ntohl (atsi[c1].type); | 684 | current_type = ntohl (atsi[c1].type); |
@@ -648,7 +694,6 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
648 | /* Invalid property, continue with next element */ | 694 | /* Invalid property, continue with next element */ |
649 | continue; | 695 | continue; |
650 | } | 696 | } |
651 | |||
652 | /* Averaging */ | 697 | /* Averaging */ |
653 | current_val = property_average (address, &atsi[c1]); | 698 | current_val = property_average (address, &atsi[c1]); |
654 | if (GNUNET_ATS_VALUE_UNDEFINED == current_val) | 699 | if (GNUNET_ATS_VALUE_UNDEFINED == current_val) |
@@ -662,7 +707,6 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
662 | cur_prop = &properties[c2]; | 707 | cur_prop = &properties[c2]; |
663 | property_normalize (cur_prop, address, ntohl(atsi[c1].type), current_val); | 708 | property_normalize (cur_prop, address, ntohl(atsi[c1].type), current_val); |
664 | } | 709 | } |
665 | |||
666 | } | 710 | } |
667 | 711 | ||
668 | 712 | ||
@@ -676,7 +720,9 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
676 | */ | 720 | */ |
677 | void | 721 | void |
678 | GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, | 722 | GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, |
679 | void *pref_ch_cb_cls) | 723 | void *pref_ch_cb_cls, |
724 | GAS_Normalization_property_changed_cb property_ch_cb, | ||
725 | void *property_ch_cb_cls) | ||
680 | { | 726 | { |
681 | int c1; | 727 | int c1; |
682 | int i; | 728 | int i; |
@@ -685,7 +731,7 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, | |||
685 | 731 | ||
686 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) | 732 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) |
687 | { | 733 | { |
688 | properties[c1].min = 0; | 734 | properties[c1].min = UINT32_MAX; |
689 | properties[c1].max = 0; | 735 | properties[c1].max = 0; |
690 | properties[c1].have_max = GNUNET_NO; | 736 | properties[c1].have_max = GNUNET_NO; |
691 | properties[c1].have_min = GNUNET_NO; | 737 | properties[c1].have_min = GNUNET_NO; |
@@ -693,6 +739,9 @@ GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, | |||
693 | 739 | ||
694 | pref_changed_cb = pref_ch_cb; | 740 | pref_changed_cb = pref_ch_cb; |
695 | pref_changed_cb_cls = pref_ch_cb_cls; | 741 | pref_changed_cb_cls = pref_ch_cb_cls; |
742 | prop_ch_cb = property_ch_cb; | ||
743 | prop_ch_cb_cls = pref_ch_cb_cls; | ||
744 | |||
696 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) | 745 | for (i = 0; i < GNUNET_ATS_PreferenceCount; i++) |
697 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; | 746 | defvalues.f_rel[i] = DEFAULT_REL_PREFERENCE; |
698 | return; | 747 | return; |
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index 24b6b5051..75158ac72 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h | |||
@@ -41,6 +41,12 @@ typedef void | |||
41 | enum GNUNET_ATS_PreferenceKind kind, | 41 | enum GNUNET_ATS_PreferenceKind kind, |
42 | double pref_rel); | 42 | double pref_rel); |
43 | 43 | ||
44 | typedef void | ||
45 | (*GAS_Normalization_property_changed_cb) (void *cls, | ||
46 | const struct ATS_Address *peer, | ||
47 | uint32_t type, | ||
48 | double prop_rel); | ||
49 | |||
44 | /** | 50 | /** |
45 | * Get the normalized preference values for a specific peer | 51 | * Get the normalized preference values for a specific peer |
46 | * | 52 | * |
@@ -59,12 +65,19 @@ GAS_normalization_get_preferences (const struct GNUNET_PeerIdentity *id); | |||
59 | * @param kind the kind to change the preference | 65 | * @param kind the kind to change the preference |
60 | * @param score_abs the normalized score | 66 | * @param score_abs the normalized score |
61 | */ | 67 | */ |
62 | float | 68 | void |
63 | GAS_normalization_normalize_preference (void *src, | 69 | GAS_normalization_normalize_preference (void *src, |
64 | const struct GNUNET_PeerIdentity *peer, | 70 | const struct GNUNET_PeerIdentity *peer, |
65 | enum GNUNET_ATS_PreferenceKind kind, | 71 | enum GNUNET_ATS_PreferenceKind kind, |
66 | float score_abs); | 72 | float score_abs); |
67 | 73 | ||
74 | /** | ||
75 | * Update and normalize a atsi performance information | ||
76 | * | ||
77 | * @param address the address to update | ||
78 | * @param atsi the array of performance information | ||
79 | * @param atsi_count the number of atsi information in the array | ||
80 | */ | ||
68 | void | 81 | void |
69 | GAS_normalization_normalize_property (struct ATS_Address *address, | 82 | GAS_normalization_normalize_property (struct ATS_Address *address, |
70 | const struct GNUNET_ATS_Information *atsi, | 83 | const struct GNUNET_ATS_Information *atsi, |
@@ -77,7 +90,10 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
77 | * @param pref_ch_cb_cls cls for the callback | 90 | * @param pref_ch_cb_cls cls for the callback |
78 | */ | 91 | */ |
79 | void | 92 | void |
80 | GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, void *pref_ch_cb_cls); | 93 | GAS_normalization_start (GAS_Normalization_preference_changed_cb pref_ch_cb, |
94 | void *pref_ch_cb_cls, | ||
95 | GAS_Normalization_property_changed_cb property_ch_ch_cls, | ||
96 | void *property_ch_cb_cls); | ||
81 | 97 | ||
82 | 98 | ||
83 | /** | 99 | /** |
diff --git a/src/ats/perf_ats_mlp.c b/src/ats/perf_ats_mlp.c index eb9e504a2..a9a142387 100644 --- a/src/ats/perf_ats_mlp.c +++ b/src/ats/perf_ats_mlp.c | |||
@@ -141,6 +141,16 @@ bandwidth_changed_cb (void *cls, struct ATS_Address *address) | |||
141 | 141 | ||
142 | } | 142 | } |
143 | 143 | ||
144 | static void | ||
145 | normalized_property_changed_cb (void *cls, | ||
146 | const struct ATS_Address *peer, | ||
147 | uint32_t type, | ||
148 | double prop_rel) | ||
149 | { | ||
150 | /* TODO */ | ||
151 | } | ||
152 | |||
153 | |||
144 | static const double * | 154 | static const double * |
145 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | 155 | get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) |
146 | { | 156 | { |
@@ -281,7 +291,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
281 | end_now (1); | 291 | end_now (1); |
282 | return; | 292 | return; |
283 | } | 293 | } |
284 | GAS_normalization_start (NULL, NULL); | 294 | GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL); |
285 | /* Load quotas */ | 295 | /* Load quotas */ |
286 | if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in, | 296 | if (GNUNET_ATS_NetworkTypeCount != load_quotas (cfg, quotas_out, quotas_in, |
287 | GNUNET_ATS_NetworkTypeCount)) | 297 | GNUNET_ATS_NetworkTypeCount)) |
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 3438606f4..abdc74bdb 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c | |||
@@ -133,6 +133,15 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | |||
133 | return GAS_normalization_get_preferences (id); | 133 | return GAS_normalization_get_preferences (id); |
134 | } | 134 | } |
135 | 135 | ||
136 | static void | ||
137 | normalized_property_changed_cb (void *cls, | ||
138 | const struct ATS_Address *peer, | ||
139 | uint32_t type, | ||
140 | double prop_rel) | ||
141 | { | ||
142 | /* TODO */ | ||
143 | } | ||
144 | |||
136 | 145 | ||
137 | static void | 146 | static void |
138 | bandwidth_changed_cb (void *cls, struct ATS_Address *address) | 147 | bandwidth_changed_cb (void *cls, struct ATS_Address *address) |
@@ -200,7 +209,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
200 | end_now (1); | 209 | end_now (1); |
201 | return; | 210 | return; |
202 | } | 211 | } |
203 | GAS_normalization_start (NULL, NULL); | 212 | GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL); |
204 | /* Setup address hashmap */ | 213 | /* Setup address hashmap */ |
205 | addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 214 | addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
206 | 215 | ||
diff --git a/src/ats/test_ats_mlp_update.c b/src/ats/test_ats_mlp_update.c index 8f89efc6a..e806bd85d 100644 --- a/src/ats/test_ats_mlp_update.c +++ b/src/ats/test_ats_mlp_update.c | |||
@@ -140,6 +140,16 @@ get_preferences_cb (void *cls, const struct GNUNET_PeerIdentity *id) | |||
140 | } | 140 | } |
141 | 141 | ||
142 | static void | 142 | static void |
143 | normalized_property_changed_cb (void *cls, | ||
144 | const struct ATS_Address *peer, | ||
145 | uint32_t type, | ||
146 | double prop_rel) | ||
147 | { | ||
148 | /* TODO */ | ||
149 | } | ||
150 | |||
151 | |||
152 | static void | ||
143 | bandwidth_changed_cb (void *cls, struct ATS_Address *address) | 153 | bandwidth_changed_cb (void *cls, struct ATS_Address *address) |
144 | { | 154 | { |
145 | static int cb_p0 = GNUNET_NO; | 155 | static int cb_p0 = GNUNET_NO; |
@@ -194,7 +204,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
194 | end_now (1); | 204 | end_now (1); |
195 | return; | 205 | return; |
196 | } | 206 | } |
197 | GAS_normalization_start (NULL, NULL); | 207 | GAS_normalization_start (NULL, NULL, &normalized_property_changed_cb, NULL); |
198 | 208 | ||
199 | /* Setup address hashmap */ | 209 | /* Setup address hashmap */ |
200 | addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); | 210 | addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); |
diff --git a/src/ats/test_ats_normalization_update_quality.c b/src/ats/test_ats_normalization_update_quality.c new file mode 100644 index 000000000..b6f378bc3 --- /dev/null +++ b/src/ats/test_ats_normalization_update_quality.c | |||
@@ -0,0 +1,237 @@ | |||
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_scheduling_update_address.c | ||
22 | * @brief test updating an address: add address, get and compare it, update it | ||
23 | * get it again and compre | ||
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 | #include "test_ats_api_common.h" | ||
32 | |||
33 | static GNUNET_SCHEDULER_TaskIdentifier die_task; | ||
34 | |||
35 | /** | ||
36 | * Scheduling handle | ||
37 | */ | ||
38 | static struct GNUNET_ATS_SchedulingHandle *sched_ats; | ||
39 | |||
40 | /** | ||
41 | * Return value | ||
42 | */ | ||
43 | static int ret; | ||
44 | |||
45 | /** | ||
46 | * Test address | ||
47 | */ | ||
48 | static struct Test_Address test_addr; | ||
49 | |||
50 | /** | ||
51 | * Test peer | ||
52 | */ | ||
53 | static struct PeerContext p[2]; | ||
54 | |||
55 | /** | ||
56 | * HELLO test address | ||
57 | */ | ||
58 | |||
59 | struct GNUNET_HELLO_Address test_hello_address[3]; | ||
60 | |||
61 | /** | ||
62 | * Test ats info | ||
63 | */ | ||
64 | struct GNUNET_ATS_Information test_ats_info[3]; | ||
65 | |||
66 | /** | ||
67 | * Test ats count | ||
68 | */ | ||
69 | uint32_t test_ats_count; | ||
70 | |||
71 | |||
72 | static void | ||
73 | end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | ||
74 | { | ||
75 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
76 | |||
77 | if (sched_ats != NULL) | ||
78 | GNUNET_ATS_scheduling_done (sched_ats); | ||
79 | free_test_address (&test_addr); | ||
80 | ret = 0; | ||
81 | } | ||
82 | |||
83 | |||
84 | static void | ||
85 | end () | ||
86 | { | ||
87 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Shutting down\n"); | ||
88 | if (die_task != GNUNET_SCHEDULER_NO_TASK) | ||
89 | { | ||
90 | GNUNET_SCHEDULER_cancel (die_task); | ||
91 | die_task = GNUNET_SCHEDULER_NO_TASK; | ||
92 | } | ||
93 | GNUNET_ATS_scheduling_done (sched_ats); | ||
94 | sched_ats = NULL; | ||
95 | free_test_address (&test_addr); | ||
96 | } | ||
97 | |||
98 | |||
99 | static void | ||
100 | address_suggest_cb (void *cls, const struct GNUNET_HELLO_Address *address, | ||
101 | struct Session *session, | ||
102 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, | ||
103 | struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, | ||
104 | const struct GNUNET_ATS_Information *atsi, | ||
105 | uint32_t ats_count) | ||
106 | { | ||
107 | static int stage = 0; | ||
108 | if (0 == stage) | ||
109 | { | ||
110 | GNUNET_ATS_suggest_address_cancel (sched_ats, &p[0].id); | ||
111 | |||
112 | /* Update address */ | ||
113 | /* Prepare ATS Information */ | ||
114 | |||
115 | test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
116 | test_ats_info[0].value = htonl(20); | ||
117 | test_ats_count = 1; | ||
118 | |||
119 | GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count); | ||
120 | |||
121 | test_ats_info[0].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
122 | test_ats_info[0].value = htonl(20); | ||
123 | test_ats_count = 1; | ||
124 | |||
125 | GNUNET_ATS_address_update (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count); | ||
126 | |||
127 | |||
128 | /* Request address */ | ||
129 | stage ++; | ||
130 | } | ||
131 | } | ||
132 | |||
133 | static void | ||
134 | run (void *cls, | ||
135 | const struct GNUNET_CONFIGURATION_Handle *cfg, | ||
136 | struct GNUNET_TESTING_Peer *peer) | ||
137 | { | ||
138 | die_task = GNUNET_SCHEDULER_add_delayed (TIMEOUT, &end_badly, NULL); | ||
139 | |||
140 | /* Connect to ATS scheduling */ | ||
141 | sched_ats = GNUNET_ATS_scheduling_init (cfg, &address_suggest_cb, NULL); | ||
142 | if (sched_ats == NULL) | ||
143 | { | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not connect to ATS scheduling!\n"); | ||
145 | ret = 1; | ||
146 | end (); | ||
147 | return; | ||
148 | } | ||
149 | |||
150 | /* Set up peer */ | ||
151 | if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].id.hashPubKey)) | ||
152 | { | ||
153 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
154 | ret = GNUNET_SYSERR; | ||
155 | end (); | ||
156 | return; | ||
157 | } | ||
158 | |||
159 | GNUNET_assert (0 == strcmp (PEERID0, GNUNET_i2s_full (&p[0].id))); | ||
160 | |||
161 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
162 | GNUNET_i2s_full(&p[0].id)); | ||
163 | |||
164 | /* Set up peer */ | ||
165 | if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID1, &p[1].id.hashPubKey)) | ||
166 | { | ||
167 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n"); | ||
168 | ret = GNUNET_SYSERR; | ||
169 | end (); | ||
170 | return; | ||
171 | } | ||
172 | |||
173 | GNUNET_assert (0 == strcmp (PEERID1, GNUNET_i2s_full (&p[1].id))); | ||
174 | |||
175 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Created peer `%s'\n", | ||
176 | GNUNET_i2s_full(&p[1].id)); | ||
177 | |||
178 | |||
179 | |||
180 | /* Adding address for peer 0 */ | ||
181 | create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1); | ||
182 | /* Prepare ATS Information */ | ||
183 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
184 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
185 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
186 | test_ats_info[1].value = htonl(30); | ||
187 | test_ats_count = 2; | ||
188 | |||
189 | test_hello_address[0].peer = p[0].id; | ||
190 | test_hello_address[0].transport_name = test_addr.plugin; | ||
191 | test_hello_address[0].address = test_addr.addr; | ||
192 | test_hello_address[0].address_length = test_addr.addr_len; | ||
193 | GNUNET_ATS_address_add (sched_ats, &test_hello_address[0], NULL, test_ats_info, test_ats_count); | ||
194 | |||
195 | /* Adding address for peer 1 */ | ||
196 | create_test_address (&test_addr, "test", &test_addr, "test", strlen ("test") + 1); | ||
197 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
198 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
199 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
200 | test_ats_info[1].value = htonl(10); | ||
201 | test_ats_count = 2; | ||
202 | |||
203 | test_hello_address[1].peer = p[1].id; | ||
204 | test_hello_address[1].transport_name = test_addr.plugin; | ||
205 | test_hello_address[1].address = test_addr.addr; | ||
206 | test_hello_address[1].address_length = test_addr.addr_len; | ||
207 | GNUNET_ATS_address_add (sched_ats, &test_hello_address[1], NULL, test_ats_info, test_ats_count); | ||
208 | |||
209 | /* Adding 2nd address for peer 1 */ | ||
210 | test_ats_info[0].type = htonl (GNUNET_ATS_NETWORK_TYPE); | ||
211 | test_ats_info[0].value = htonl(GNUNET_ATS_NET_WAN); | ||
212 | test_ats_info[1].type = htonl (GNUNET_ATS_QUALITY_NET_DELAY); | ||
213 | test_ats_info[1].value = htonl(20); | ||
214 | test_ats_count = 2; | ||
215 | |||
216 | test_hello_address[3].peer = p[1].id; | ||
217 | test_hello_address[3].transport_name = test_addr.plugin; | ||
218 | test_hello_address[3].address = test_addr.addr; | ||
219 | test_hello_address[3].address_length = test_addr.addr_len; | ||
220 | GNUNET_ATS_address_add (sched_ats, &test_hello_address[3], NULL, test_ats_info, test_ats_count); | ||
221 | |||
222 | /* Request address */ | ||
223 | GNUNET_ATS_suggest_address (sched_ats, &p[0].id); | ||
224 | } | ||
225 | |||
226 | |||
227 | int | ||
228 | main (int argc, char *argv[]) | ||
229 | { | ||
230 | if (0 != GNUNET_TESTING_peer_run ("test_ats_api_scheduling_update_address", | ||
231 | "test_ats_api.conf", | ||
232 | &run, NULL)) | ||
233 | return 1; | ||
234 | return ret; | ||
235 | } | ||
236 | |||
237 | /* end of file test_ats_api_scheduling_update_address.c */ | ||