#include "gnunet-service-ats_addresses_mlp.h"
#endif
+#define VERBOSE GNUNET_NO
+
enum ATS_Mode
{
- /**
+ /*
* Assign each peer an equal amount of bandwidth (bw)
*
* bw_per_peer = bw_total / #active addresses
*/
SIMPLE,
- /**
+ /*
* Use MLP solver to assign bandwidth
*/
MLP
static struct GNUNET_CONTAINER_MultiHashMap *addresses;
+#if HAVE_LIBGLPK
+static struct GAS_MLP_Handle *mlp;
+#endif
+
static unsigned long long wan_quota_in;
static unsigned long long wan_quota_out;
static int ats_mode;
+static void
+send_bw_notification (struct ATS_Address *aa)
+{
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
+ GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
+ ntohl (aa->assigned_bw_out.value__));
+ GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr,
+ aa->addr_len, aa->session_id,
+ aa->ats, aa->ats_count,
+ aa->assigned_bw_out,
+ aa->assigned_bw_in);
+ GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
+ GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len,
+ aa->ats, aa->ats_count, aa->assigned_bw_out,
+ aa->assigned_bw_in);
+}
+
/**
* Update a bandwidth assignment for a peer. This trivial method currently
* simply assigns the same share to all active connections.
* @return GNUNET_OK (continue to iterate)
*/
static int
-update_bw_it (void *cls, const GNUNET_HashCode * key, void *value)
+update_bw_simple_it (void *cls, const GNUNET_HashCode * key, void *value)
{
struct ATS_Address *aa = value;
-
- /* Simple method */
if (GNUNET_YES != aa->active)
return GNUNET_OK;
GNUNET_assert (active_addr_count > 0);
+
+
+ /* Simple method */
aa->assigned_bw_in.value__ = htonl (wan_quota_in / active_addr_count);
aa->assigned_bw_out.value__ = htonl (wan_quota_out / active_addr_count);
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n",
- GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__),
- ntohl (aa->assigned_bw_out.value__));
- GAS_scheduling_transmit_address_suggestion (&aa->peer, aa->plugin, aa->addr,
- aa->addr_len, aa->session_id,
- aa->ats, aa->ats_count,
- aa->assigned_bw_out,
- aa->assigned_bw_in);
- GAS_reservations_set_bandwidth (&aa->peer, aa->assigned_bw_in);
- GAS_performance_notify_clients (&aa->peer, aa->plugin, aa->addr, aa->addr_len,
- aa->ats, aa->ats_count, aa->assigned_bw_out,
- aa->assigned_bw_in);
+
+ send_bw_notification (aa);
+
return GNUNET_OK;
}
1, GNUNET_NO);
GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count,
GNUNET_NO);
- GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL);
+
+ GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_simple_it, NULL);
}
/**
memcpy (&aa[1], plugin_addr, plugin_addr_len);
aa->plugin = GNUNET_strdup (plugin_name);
aa->session_id = session_id;
-
+ aa->mlp_information = NULL;
+ aa->next = NULL;
+ aa->prev = NULL;
return aa;
}
#if HAVE_LIBGLPK
if (ats_mode == MLP)
- GAS_mlp_address_delete (addresses, addr);
+ GAS_mlp_address_delete (mlp, addresses, addr);
#endif
if (GNUNET_YES == addr->active)
struct CompareAddressContext
{
const struct ATS_Address *search;
- struct ATS_Address *result;
+
+ /* exact_address != NULL if address and session is equal */
+ struct ATS_Address *exact_address;
+ /* exact_address != NULL if address and session is 0 */
+ struct ATS_Address *base_address;
};
{
struct CompareAddressContext *cac = cls;
struct ATS_Address *aa = value;
+/*
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "Comparing to: %s %s %u session %u\n",
+ GNUNET_i2s (&aa->peer), aa->plugin, aa->addr_len, aa->session_id);
+
+*/
+ /* find an exact matching address: aa->addr == cac->search->addr && aa->session == cac->search->session */
+ if ((aa->addr_len == cac->search->addr_len) && (0 == strcmp (aa->plugin, cac->search->plugin)))
+ {
+ if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == cac->search->session_id))
+ {
+ cac->exact_address = aa;
+ }
+ }
- if (((aa->addr_len != cac->search->addr_len) ||
- (0 != strcmp (aa->plugin, cac->search->plugin)) ||
- (0 != memcmp (aa->addr, cac->search->addr, aa->addr_len))) &&
- ((aa->session_id != cac->search->session_id) ||
- (cac->search->session_id == 0)))
+ /* find an matching address: aa->addr == cac->search->addr && aa->session == 0 */
+ /* this address can be used to be updated */
+ if ((aa->addr_len == cac->search->addr_len) && (0 == strcmp (aa->plugin, cac->search->plugin)))
+ {
+ if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == 0))
+ {
+ cac->base_address = aa;
+ }
+ }
+
+ if (cac->exact_address == NULL)
return GNUNET_YES;
- cac->result = aa;
- return GNUNET_NO;
+ else
+ return GNUNET_NO;
}
{
struct CompareAddressContext cac;
- cac.result = NULL;
+ cac.exact_address = NULL;
+ cac.base_address = NULL;
cac.search = addr;
GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
&compare_address_it, &cac);
- return cac.result;
+
+/*
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ "exact address: %s base address: %s\n",
+ (cac.exact_address != NULL) ? "YES" : "NO",
+ (cac.base_address != NULL) ? "YES" : "NO");
+*/
+ if (cac.exact_address == NULL)
+ return cac.base_address;
+ return cac.exact_address;
+}
+
+
+static int
+compare_address_session_it (void *cls, const GNUNET_HashCode * key, void *value)
+{
+ struct CompareAddressContext *cac = cls;
+ struct ATS_Address *aa = value;
+
+ if ((aa->addr_len == cac->search->addr_len) && (0 == strcmp (aa->plugin, cac->search->plugin)))
+ {
+ if ((0 == memcmp (aa->addr, cac->search->addr, aa->addr_len)) && (aa->session_id == cac->search->session_id))
+ {
+ cac->exact_address = aa;
+ return GNUNET_NO;
+ }
+ }
+ return GNUNET_YES;
+}
+
+
+/**
+ * Find an existing equivalent address record.
+ * Compares by peer identity and network address AND by session ID
+ * (one of the two must match).
+ *
+ * @param peer peer to lookup addresses for
+ * @param addr existing address record
+ * @return existing address record, NULL for none
+ */
+struct ATS_Address *
+find_exact_address (const struct GNUNET_PeerIdentity *peer,
+ const struct ATS_Address *addr)
+{
+ struct CompareAddressContext cac;
+
+ cac.exact_address = NULL;
+ cac.search = addr;
+ GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
+ &compare_address_session_it, &cac);
+ return cac.exact_address;
}
aa->ats_count = atsi_count;
memcpy (aa->ats, atsi, atsi_count * sizeof (struct GNUNET_ATS_Information));
+#if DEBUG_ATS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Updating address for peer `%s' %u\n",
+ GNUNET_i2s (peer),
+ session_id);
+#endif
+ /* Get existing address or address with session == 0 */
old = find_address (peer, aa);
if (old == NULL)
{
GNUNET_CONTAINER_multihashmap_put (addresses,
&peer->hashPubKey, aa,
GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE));
+#if DEBUG_ATS
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Added new address for peer `%s' %X\n",
GNUNET_i2s (peer), aa);
+#endif
old = aa;
}
else
{
- GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Updated existing address for peer `%s' %X \n",
- GNUNET_i2s (peer), old);
+#if DEBUG_ATS
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Updated existing address for peer `%s' %p old session %u new session %u\n",
+ GNUNET_i2s (peer), old,
+ old->session_id, session_id);
+#endif
GNUNET_free_non_null (old->ats);
old->session_id = session_id;
old->ats = NULL;
}
#if HAVE_LIBGLPK
if (ats_mode == MLP)
- GAS_mlp_address_update (addresses, old);
+ GAS_mlp_address_update (mlp, addresses, old);
#endif
}
(aa->addr_len == info->addr_len) &&
(0 == memcmp (info->addr, aa->addr, aa->addr_len)))
{
+#if VERBOSE
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Deleting address for peer `%s': `%s'\n",
- GNUNET_i2s (&aa->peer), aa->plugin);
+ "Deleting address for peer `%s': `%s' %u\n",
+ GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
+#endif
if (GNUNET_YES == destroy_address (aa))
recalculate_assigned_bw ();
return GNUNET_OK;
if (aa->session_id != 0)
GNUNET_break (0 == strcmp (info->plugin, aa->plugin));
/* session died */
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting session for peer `%s': `%s' %u\n",
+ GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
+#endif
aa->session_id = 0;
if (GNUNET_YES == aa->active)
/* session == 0 and addrlen == 0 : destroy address */
if (aa->addr_len == 0)
{
+#if VERBOSE
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Deleting session and address for peer `%s': `%s' %u\n",
+ GNUNET_i2s (&aa->peer), aa->plugin, aa->session_id);
+#endif
(void) destroy_address (aa);
}
else
/* session was set to 0, update address */
#if HAVE_LIBGLPK
if (ats_mode == MLP)
- GAS_mlp_address_update (addresses, aa);
+ GAS_mlp_address_update (mlp, addresses, aa);
#endif
}
struct ATS_Address *aa;
struct ATS_Address *old;
+
aa = create_address(peer, plugin_name, plugin_addr, plugin_addr_len, session_id);
- old = find_address (peer, aa);
+ old = find_exact_address (peer, aa);
free_address (aa);
GNUNET_assert (old != NULL);
- GNUNET_assert (in_use != old->used);
+ GNUNET_assert (old->used != in_use);
old->used = in_use;
#if HAVE_LIBGLPK
if (ats_mode == MLP)
- GAS_mlp_address_update (addresses, old);
+ GAS_mlp_address_update (mlp, addresses, old);
#endif
}
-void
-GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
+
+void request_address_mlp (const struct GNUNET_PeerIdentity *peer)
{
struct ATS_Address *aa;
+ aa = NULL;
+
+#if HAVE_GLPK
+ /* Get preferred address from MLP */
+ struct ATS_PreferedAddress * paddr = NULL;
+ paddr = GAS_mlp_get_preferred_address (mlp, addresses, peer);
+ aa = paddr->address;
+ aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(paddr->bandwidth_out);
+ /* FIXME use bw in value */
+ paddr->bandwidth_in = paddr->bandwidth_out;
+ aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init (paddr->bandwidth_in);
+ GNUNET_free (paddr);
+#endif
+
+ if (aa == NULL)
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
+ "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
+ return;
+ }
+ if (aa->active == GNUNET_NO)
+ {
+ aa->active = GNUNET_YES;
+ active_addr_count++;
+ send_bw_notification (aa);
+ }
+ else
+ {
+ /* just to be sure... */
+ GAS_scheduling_transmit_address_suggestion (peer, aa->plugin, aa->addr,
+ aa->addr_len, aa->session_id,
+ aa->ats, aa->ats_count,
+ aa->assigned_bw_out,
+ aa->assigned_bw_in);
+ }
+
+}
+
+void request_address_simple (const struct GNUNET_PeerIdentity *peer)
+{
+ struct ATS_Address *aa;
aa = NULL;
+
+ /* Get address with: stick to current address, lower distance, lower latency */
GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey,
&find_address_it, &aa);
if (aa == NULL)
"Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer));
return;
}
+
if (aa->active == GNUNET_NO)
{
aa->active = GNUNET_YES;
active_addr_count++;
- recalculate_assigned_bw ();
+ if (ats_mode == SIMPLE)
+ {
+ recalculate_assigned_bw ();
+ }
}
else
{
}
+void
+GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer)
+{
+ if (ats_mode == SIMPLE)
+ {
+ request_address_simple (peer);
+ }
+ if (ats_mode == MLP)
+ {
+ request_address_mlp(peer);
+ }
+}
+
+
// FIXME: this function should likely end up in the LP-subsystem and
// not with 'addresses' in the future...
void
enum GNUNET_ATS_PreferenceKind kind,
float score)
{
- // do nothing for now...
+#if HAVE_LIBGLPK
+ if (ats_mode == MLP)
+ GAS_mlp_address_change_preference (mlp, peer, kind, score);
+#endif
}
"WAN_QUOTA_OUT",
&wan_quota_out));
-
-
switch (GNUNET_CONFIGURATION_get_value_yesno (cfg, "ats", "MLP"))
{
/* MLP = YES */
#if HAVE_LIBGLPK
ats_mode = MLP;
/* Init the MLP solver with default values */
- GAS_mlp_init (stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
+ mlp = GAS_mlp_init (cfg, stats, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
break;
#else
GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP mode was configured, but libglpk is not installed, switching to simple mode");
#if HAVE_LIBGLPK
if (ats_mode == MLP)
{
- GAS_mlp_done ();
+ GAS_mlp_done (mlp);
}
#endif