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/gnunet-service-ats_normalization.c | |
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/gnunet-service-ats_normalization.c')
-rw-r--r-- | src/ats/gnunet-service-ats_normalization.c | 72 |
1 files changed, 67 insertions, 5 deletions
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 | } |