[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[GNUnet-SVN] r27545 - gnunet/src/ats
From: |
gnunet |
Subject: |
[GNUnet-SVN] r27545 - gnunet/src/ats |
Date: |
Mon, 24 Jun 2013 12:35:55 +0200 |
Author: wachs
Date: 2013-06-24 12:35:55 +0200 (Mon, 24 Jun 2013)
New Revision: 27545
Modified:
gnunet/src/ats/gnunet-service-ats.h
gnunet/src/ats/gnunet-service-ats_addresses.c
gnunet/src/ats/gnunet-service-ats_addresses.h
gnunet/src/ats/gnunet-service-ats_normalization.c
gnunet/src/ats/gnunet-service-ats_normalization.h
gnunet/src/ats/test_ats_api_common.c
Log:
- fixed info message in test
- added data structure for property normalization
- added property averaging
Modified: gnunet/src/ats/gnunet-service-ats.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats.h 2013-06-24 09:27:07 UTC (rev 27544)
+++ gnunet/src/ats/gnunet-service-ats.h 2013-06-24 10:35:55 UTC (rev 27545)
@@ -29,6 +29,8 @@
#include "gnunet_statistics_service.h"
+#define GAS_normalization_queue_length 3
+
/**
* Handle for statistics.
*/
Modified: gnunet/src/ats/gnunet-service-ats_addresses.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.c 2013-06-24 09:27:07 UTC
(rev 27544)
+++ gnunet/src/ats/gnunet-service-ats_addresses.c 2013-06-24 10:35:55 UTC
(rev 27545)
@@ -512,6 +512,8 @@
uint32_t session_id)
{
struct ATS_Address *aa = NULL;
+ int c1;
+ int c2;
aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len);
aa->peer = *peer;
@@ -527,6 +529,14 @@
aa->atsi_count = 0;
aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
+
+ for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1 ++)
+ {
+ aa->atsin[c1].index = 0;
+ for (c2 = 0; c2 < GAS_normalization_queue_length; c2++)
+ aa->atsin[c1].atsi_abs[c2] = GNUNET_ATS_VALUE_UNDEFINED;
+ }
+
return aa;
}
Modified: gnunet/src/ats/gnunet-service-ats_addresses.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_addresses.h 2013-06-24 09:27:07 UTC
(rev 27544)
+++ gnunet/src/ats/gnunet-service-ats_addresses.h 2013-06-24 10:35:55 UTC
(rev 27545)
@@ -29,6 +29,7 @@
#include "gnunet_util_lib.h"
#include "gnunet_ats_service.h"
+#include "gnunet-service-ats.h"
#include "gnunet_statistics_service.h"
#include "ats.h"
@@ -232,6 +233,13 @@
struct GAS_Addresses_Handle;
+
+struct GAS_NormalizationInfo
+{
+ unsigned int index;
+ uint32_t atsi_abs[GAS_normalization_queue_length];
+};
+
/**
* Address with additional information
*/
@@ -342,6 +350,12 @@
* Is this the address for this peer in use?
*/
int used;
+
+ /**
+ * Normalized ATS performance information for this address
+ * Each entry can be accessed using the GNUNET_ATS_QualityProperties index
+ */
+ struct GAS_NormalizationInfo atsin[GNUNET_ATS_QualityPropertiesCount];
};
Modified: gnunet/src/ats/gnunet-service-ats_normalization.c
===================================================================
--- gnunet/src/ats/gnunet-service-ats_normalization.c 2013-06-24 09:27:07 UTC
(rev 27544)
+++ gnunet/src/ats/gnunet-service-ats_normalization.c 2013-06-24 10:35:55 UTC
(rev 27545)
@@ -514,11 +514,66 @@
struct Property properties[GNUNET_ATS_QualityPropertiesCount];
+/**
+ * Normalize a specific ATS type with the values in queue
+ * @param address the address
+ * @param atsi the ats information
+ * @return the new average or GNUNET_ATS_VALUE_UNDEFINED
+ */
+
uint32_t property_average (struct ATS_Address *address,
const struct GNUNET_ATS_Information *atsi)
{
+ struct GAS_NormalizationInfo *ni;
+ uint32_t current_type;
+ uint32_t current_val;
+
+ uint32_t sum;
+ uint32_t count;
+ unsigned int c1;
+ unsigned int index;
+ unsigned int props[] = GNUNET_ATS_QualityProperties;
+
/* Average the values of this property */
- return ntohl(atsi->value);
+ current_type = ntohl (atsi->type);
+ current_val = ntohl (atsi->value);
+
+ for (c1 = 0; c1 < GNUNET_ATS_QualityPropertiesCount; c1++)
+ {
+ if (current_type == props[c1])
+ break;
+ }
+ if (c1 == GNUNET_ATS_QualityPropertiesCount)
+ {
+ GNUNET_break (0);
+ return GNUNET_ATS_VALUE_UNDEFINED;
+ }
+ index = c1;
+
+ ni = &address->atsin[index];
+ ni->atsi_abs[ni->index] = current_val;
+ ni->index ++;
+ if (GAS_normalization_queue_length == ni->index)
+ ni->index = 0;
+
+ count = 0;
+ for (c1 = 0; c1 < GAS_normalization_queue_length; c1++)
+ {
+ if (GNUNET_ATS_VALUE_UNDEFINED != ni->atsi_abs[c1])
+ {
+ count++;
+ if (GNUNET_ATS_VALUE_UNDEFINED > (sum +
ni->atsi_abs[c1]))
+ sum += ni->atsi_abs[c1];
+ else
+ {
+ sum = GNUNET_ATS_VALUE_UNDEFINED - 1;
+ GNUNET_break (0);
+ }
+ }
+ }
+ GNUNET_assert (0 != count);
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New average from %u elements:
%u\n", count, sum / count);
+ return 0;
}
void property_normalize (struct ATS_Address *address,
@@ -540,8 +595,10 @@
int c2;
uint32_t current_type;
uint32_t current_val;
+ unsigned int existing_properties[] = GNUNET_ATS_QualityProperties;
- int existing_properties[] = GNUNET_ATS_QualityProperties;
+ GNUNET_assert (NULL != address);
+ GNUNET_assert (NULL != atsi);
for (c1 = 0; c1 < atsi_count; c1++)
{
@@ -549,17 +606,23 @@
current_val = ntohl (atsi[c1].value);
for (c2 = 0; c2 < GNUNET_ATS_QualityPropertiesCount; c2++)
{
+ /* Check if type is valid */
if (current_type == existing_properties[c2])
break;
}
if (GNUNET_ATS_QualityPropertiesCount == c2)
{
- /* Invalid property */
+ /* Invalid property, continue with next element */
continue;
}
/* Averaging */
current_val = property_average (address, &atsi[c1]);
+ if (GNUNET_ATS_VALUE_UNDEFINED == current_val)
+ {
+ GNUNET_break (0);
+ continue;
+ }
/* Normalizing */
/* Check min, max */
@@ -579,8 +642,7 @@
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New minimum of %u
for property %u\n", cur_prop->min, current_type);
}
-
- property_normalize (address, ntohl(atsi[c1].type));
+ //property_normalize (address, ntohl(atsi[c1].type));
}
}
Modified: gnunet/src/ats/gnunet-service-ats_normalization.h
===================================================================
--- gnunet/src/ats/gnunet-service-ats_normalization.h 2013-06-24 09:27:07 UTC
(rev 27544)
+++ gnunet/src/ats/gnunet-service-ats_normalization.h 2013-06-24 10:35:55 UTC
(rev 27545)
@@ -33,7 +33,6 @@
#define DEFAULT_REL_PREFERENCE 1.0
#define DEFAULT_ABS_PREFERENCE 0.0
-
typedef void
(*GAS_Normalization_preference_changed_cb) (void *cls,
const struct GNUNET_PeerIdentity *peer,
Modified: gnunet/src/ats/test_ats_api_common.c
===================================================================
--- gnunet/src/ats/test_ats_api_common.c 2013-06-24 09:27:07 UTC (rev
27544)
+++ gnunet/src/ats/test_ats_api_common.c 2013-06-24 10:35:55 UTC (rev
27545)
@@ -69,13 +69,13 @@
}
if (address1->address_length != address2->address_length)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address
length'\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid address
length\n");
return GNUNET_SYSERR;
}
else if (0 != memcmp (address1->address, address2->address,
address2->address_length))
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid
address'\n");
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Suggestion with invalid
address\n");
return GNUNET_SYSERR;
}
if (session1 != session2)
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [GNUnet-SVN] r27545 - gnunet/src/ats,
gnunet <=