diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-24 10:35:55 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2013-06-24 10:35:55 +0000 |
commit | 5752e1aa99cae87bda55a05e098e8f8113142f36 (patch) | |
tree | c637459e70cd9c0fd503a3c7a51c741d550b1978 /src/ats | |
parent | d42e0431346cfa1da13c9ac3156dcf1c96a97393 (diff) | |
download | gnunet-5752e1aa99cae87bda55a05e098e8f8113142f36.tar.gz gnunet-5752e1aa99cae87bda55a05e098e8f8113142f36.zip |
- fixed info message in test
- added data structure for property normalization
- added property averaging
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats.h | 2 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 10 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.h | 14 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 72 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.h | 1 | ||||
-rw-r--r-- | src/ats/test_ats_api_common.c | 4 |
6 files changed, 95 insertions, 8 deletions
diff --git a/src/ats/gnunet-service-ats.h b/src/ats/gnunet-service-ats.h index b60332d20..4335c5226 100644 --- a/src/ats/gnunet-service-ats.h +++ b/src/ats/gnunet-service-ats.h | |||
@@ -29,6 +29,8 @@ | |||
29 | 29 | ||
30 | #include "gnunet_statistics_service.h" | 30 | #include "gnunet_statistics_service.h" |
31 | 31 | ||
32 | #define GAS_normalization_queue_length 3 | ||
33 | |||
32 | /** | 34 | /** |
33 | * Handle for statistics. | 35 | * Handle for statistics. |
34 | */ | 36 | */ |
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 8083ba914..d7c4100ea 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -512,6 +512,8 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
512 | uint32_t session_id) | 512 | uint32_t session_id) |
513 | { | 513 | { |
514 | struct ATS_Address *aa = NULL; | 514 | struct ATS_Address *aa = NULL; |
515 | int c1; | ||
516 | int c2; | ||
515 | 517 | ||
516 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); | 518 | aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len); |
517 | aa->peer = *peer; | 519 | aa->peer = *peer; |
@@ -527,6 +529,14 @@ create_address (const struct GNUNET_PeerIdentity *peer, | |||
527 | aa->atsi_count = 0; | 529 | aa->atsi_count = 0; |
528 | aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0); | 530 | aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0); |
529 | aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0); | 531 | aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0); |
532 | |||
533 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1 ++) | ||
534 | { | ||
535 | aa->atsin[c1].index = 0; | ||
536 | for (c2 = 0; c2 < GAS_normalization_queue_length; c2++) | ||
537 | aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED; | ||
538 | } | ||
539 | |||
530 | return aa; | 540 | return aa; |
531 | } | 541 | } |
532 | 542 | ||
diff --git a/src/ats/gnunet-service-ats_addresses.h b/src/ats/gnunet-service-ats_addresses.h index 0da559d20..cfc54b2ea 100644 --- a/src/ats/gnunet-service-ats_addresses.h +++ b/src/ats/gnunet-service-ats_addresses.h | |||
@@ -29,6 +29,7 @@ | |||
29 | 29 | ||
30 | #include "gnunet_util_lib.h" | 30 | #include "gnunet_util_lib.h" |
31 | #include "gnunet_ats_service.h" | 31 | #include "gnunet_ats_service.h" |
32 | #include "gnunet-service-ats.h" | ||
32 | #include "gnunet_statistics_service.h" | 33 | #include "gnunet_statistics_service.h" |
33 | #include "ats.h" | 34 | #include "ats.h" |
34 | 35 | ||
@@ -232,6 +233,13 @@ | |||
232 | 233 | ||
233 | struct GAS_Addresses_Handle; | 234 | struct GAS_Addresses_Handle; |
234 | 235 | ||
236 | |||
237 | struct GAS_NormalizationInfo | ||
238 | { | ||
239 | unsigned int index; | ||
240 | uint32_t atsi_abs[GAS_normalization_queue_length]; | ||
241 | }; | ||
242 | |||
235 | /** | 243 | /** |
236 | * Address with additional information | 244 | * Address with additional information |
237 | */ | 245 | */ |
@@ -342,6 +350,12 @@ struct ATS_Address | |||
342 | * Is this the address for this peer in use? | 350 | * Is this the address for this peer in use? |
343 | */ | 351 | */ |
344 | int used; | 352 | int used; |
353 | |||
354 | /** | ||
355 | * Normalized ATS performance information for this address | ||
356 | * Each entry can be accessed using the GNUNET_ATS_QualityProperties index | ||
357 | */ | ||
358 | struct GAS_NormalizationInfo atsin[GNUNET_ATS_QualityPropertiesCount]; | ||
345 | }; | 359 | }; |
346 | 360 | ||
347 | 361 | ||
diff --git a/src/ats/gnunet-service-ats_normalization.c b/src/ats/gnunet-service-ats_normalization.c index 2b0efa912..c290b697c 100644 --- a/src/ats/gnunet-service-ats_normalization.c +++ b/src/ats/gnunet-service-ats_normalization.c | |||
@@ -514,11 +514,66 @@ struct Property | |||
514 | 514 | ||
515 | struct Property properties[GNUNET_ATS_QualityPropertiesCount]; | 515 | struct Property properties[GNUNET_ATS_QualityPropertiesCount]; |
516 | 516 | ||
517 | /** | ||
518 | * Normalize a specific ATS type with the values in queue | ||
519 | * @param address the address | ||
520 | * @param atsi the ats information | ||
521 | * @return the new average or GNUNET_ATS_VALUE_UNDEFINED | ||
522 | */ | ||
523 | |||
517 | uint32_t property_average (struct ATS_Address *address, | 524 | uint32_t property_average (struct ATS_Address *address, |
518 | const struct GNUNET_ATS_Information *atsi) | 525 | const struct GNUNET_ATS_Information *atsi) |
519 | { | 526 | { |
527 | struct GAS_NormalizationInfo *ni; | ||
528 | uint32_t current_type; | ||
529 | uint32_t current_val; | ||
530 | |||
531 | uint32_t sum; | ||
532 | uint32_t count; | ||
533 | unsigned int c1; | ||
534 | unsigned int index; | ||
535 | unsigned int props[] = GNUNET_ATS_QualityProperties; | ||
536 | |||
520 | /* Average the values of this property */ | 537 | /* Average the values of this property */ |
521 | return ntohl(atsi->value); | 538 | current_type = ntohl (atsi->type); |
539 | current_val = ntohl (atsi->value); | ||
540 | |||
541 | for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++) | ||
542 | { | ||
543 | if (current_type == props[c1]) | ||
544 | break; | ||
545 | } | ||
546 | if (c1 == GNUNET_ATS_QualityPropertiesCount) | ||
547 | { | ||
548 | GNUNET_break (0); | ||
549 | return GNUNET_ATS_VALUE_UNDEFINED; | ||
550 | } | ||
551 | index = c1; | ||
552 | |||
553 | ni = &address->atsin[index]; | ||
554 | ni->atsi_abs[ni->index] = current_val; | ||
555 | ni->index ++; | ||
556 | if (GAS_normalization_queue_length == ni->index) | ||
557 | ni->index = 0; | ||
558 | |||
559 | count = 0; | ||
560 | for (c1 = 0; c1 < GAS_normalization_queue_length; c1++) | ||
561 | { | ||
562 | if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1]) | ||
563 | { | ||
564 | count++; | ||
565 | if (GNUNET_ATS_VALUE_UNDEFINED > (sum + ni->atsi_abs[c1])) | ||
566 | sum += ni->atsi_abs[c1]; | ||
567 | else | ||
568 | { | ||
569 | sum = GNUNET_ATS_VALUE_UNDEFINED - 1; | ||
570 | GNUNET_break (0); | ||
571 | } | ||
572 | } | ||
573 | } | ||
574 | GNUNET_assert (0 != count); | ||
575 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New average from %u elements: %u\n", count, sum / count); | ||
576 | return 0; | ||
522 | } | 577 | } |
523 | 578 | ||
524 | void property_normalize (struct ATS_Address *address, | 579 | void property_normalize (struct ATS_Address *address, |
@@ -540,8 +595,10 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
540 | int c2; | 595 | int c2; |
541 | uint32_t current_type; | 596 | uint32_t current_type; |
542 | uint32_t current_val; | 597 | uint32_t current_val; |
598 | unsigned int existing_properties[] = GNUNET_ATS_QualityProperties; | ||
543 | 599 | ||
544 | int existing_properties[] = GNUNET_ATS_QualityProperties; | 600 | GNUNET_assert (NULL != address); |
601 | GNUNET_assert (NULL != atsi); | ||
545 | 602 | ||
546 | for (c1 = 0; c1 < atsi_count; c1++) | 603 | for (c1 = 0; c1 < atsi_count; c1++) |
547 | { | 604 | { |
@@ -549,17 +606,23 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
549 | current_val = ntohl (atsi[c1].value); | 606 | current_val = ntohl (atsi[c1].value); |
550 | for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++) | 607 | for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++) |
551 | { | 608 | { |
609 | /* Check if type is valid */ | ||
552 | if (current_type == existing_properties[c2]) | 610 | if (current_type == existing_properties[c2]) |
553 | break; | 611 | break; |
554 | } | 612 | } |
555 | if (GNUNET_ATS_QualityPropertiesCount == c2) | 613 | if (GNUNET_ATS_QualityPropertiesCount == c2) |
556 | { | 614 | { |
557 | /* Invalid property */ | 615 | /* Invalid property, continue with next element */ |
558 | continue; | 616 | continue; |
559 | } | 617 | } |
560 | 618 | ||
561 | /* Averaging */ | 619 | /* Averaging */ |
562 | current_val = property_average (address, &atsi[c1]); | 620 | current_val = property_average (address, &atsi[c1]); |
621 | if (GNUNET_ATS_VALUE_UNDEFINED == current_val) | ||
622 | { | ||
623 | GNUNET_break (0); | ||
624 | continue; | ||
625 | } | ||
563 | 626 | ||
564 | /* Normalizing */ | 627 | /* Normalizing */ |
565 | /* Check min, max */ | 628 | /* Check min, max */ |
@@ -579,8 +642,7 @@ GAS_normalization_normalize_property (struct ATS_Address *address, | |||
579 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New minimum of %u for property %u\n", cur_prop->min, current_type); | 642 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New minimum of %u for property %u\n", cur_prop->min, current_type); |
580 | } | 643 | } |
581 | 644 | ||
582 | 645 | //property_normalize (address, ntohl(atsi[c1].type)); | |
583 | property_normalize (address, ntohl(atsi[c1].type)); | ||
584 | } | 646 | } |
585 | 647 | ||
586 | } | 648 | } |
diff --git a/src/ats/gnunet-service-ats_normalization.h b/src/ats/gnunet-service-ats_normalization.h index c90d4d8c6..967702bae 100644 --- a/src/ats/gnunet-service-ats_normalization.h +++ b/src/ats/gnunet-service-ats_normalization.h | |||
@@ -33,7 +33,6 @@ | |||
33 | #define DEFAULT_REL_PREFERENCE 1.0 | 33 | #define DEFAULT_REL_PREFERENCE 1.0 |
34 | #define DEFAULT_ABS_PREFERENCE 0.0 | 34 | #define DEFAULT_ABS_PREFERENCE 0.0 |
35 | 35 | ||
36 | |||
37 | typedef void | 36 | typedef void |
38 | (*GAS_Normalization_preference_changed_cb) (void *cls, | 37 | (*GAS_Normalization_preference_changed_cb) (void *cls, |
39 | const struct GNUNET_PeerIdentity *peer, | 38 | const struct GNUNET_PeerIdentity *peer, |
diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c index 79005d8d3..44d627424 100644 --- a/src/ats/test_ats_api_common.c +++ b/src/ats/test_ats_api_common.c | |||
@@ -69,13 +69,13 @@ compare_addresses (const struct GNUNET_HELLO_Address *address1, void *session1, | |||
69 | } | 69 | } |
70 | if (address1->address_length != address2->address_length) | 70 | if (address1->address_length != address2->address_length) |
71 | { | 71 | { |
72 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length'\n"); | 72 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address length\n"); |
73 | return GNUNET_SYSERR; | 73 | return GNUNET_SYSERR; |
74 | 74 | ||
75 | } | 75 | } |
76 | else if (0 != memcmp (address1->address, address2->address, address2->address_length)) | 76 | else if (0 != memcmp (address1->address, address2->address, address2->address_length)) |
77 | { | 77 | { |
78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address'\n"); | 78 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address\n"); |
79 | return GNUNET_SYSERR; | 79 | return GNUNET_SYSERR; |
80 | } | 80 | } |
81 | if (session1 != session2) | 81 | if (session1 != session2) |