From f2a58ae1caa79ddda66ea8c6a056e466394fba0d Mon Sep 17 00:00:00 2001 From: Matthias Wachs Date: Mon, 25 Feb 2013 15:38:01 +0000 Subject: [PATCH] changes --- src/ats/gnunet-service-ats_addresses_mlp.c | 11 +-- src/ats/test_ats_mlp.c | 100 +++++++++++++-------- 2 files changed, 68 insertions(+), 43 deletions(-) diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 5d92be3a6..3e03e6adc 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c @@ -1026,7 +1026,7 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value if ((GLP_YES == mlp_use) && (GNUNET_NO == address->active)) { /* Address switch: Activate address*/ - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); + LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : enabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); address->active = GNUNET_YES; address->assigned_bw_in.value__ = htonl (mlp_bw); address->assigned_bw_out.value__ = htonl (mlp_bw); @@ -1035,7 +1035,7 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value else if ((GLP_NO == mlp_use) && (GNUNET_YES == address->active)) { /* Address switch: Disable address*/ - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : disabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); + LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : disabling address\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); address->active = GNUNET_NO; /* Set bandwidth to 0 */ address->assigned_bw_in.value__ = htonl (0); @@ -1046,14 +1046,14 @@ mlp_propagate_results (void *cls, const struct GNUNET_HashCode *key, void *value (mlp_bw != ntohl(address->assigned_bw_in.value__))) { /* Bandwidth changed */ - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : bandwidth changed\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); + LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : bandwidth changed\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); address->assigned_bw_in.value__ = htonl (mlp_bw); address->assigned_bw_out.value__ = htonl (mlp_bw); mlp->bw_changed_cb (mlp->bw_changed_cb_cls, address); } else { - LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %f : no change\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); + LOG (GNUNET_ERROR_TYPE_DEBUG, "%s %.2f : no change\n", (1 == mlp_use) ? "[x]": "[ ]", mlp_bw); } return GNUNET_OK; @@ -1430,7 +1430,8 @@ GAS_mlp_get_preferred_address (void *solver, /* Added new peer, we have to rebuild problem before solving */ mlp->mlp_prob_changed = GNUNET_YES; } - GAS_mlp_solve_problem (mlp, addresses); + if (GNUNET_YES == mlp->mlp_auto_solve) + GAS_mlp_solve_problem (mlp, addresses); /* Get prefered address */ GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 918edef02..366a18298 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c @@ -121,24 +121,51 @@ end_now (int res) } static void -bandwidth_changed_cb (void *cls, struct ATS_Address *address) +end_correctly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "MLP suggests for peer `%s' address `%s':`%s' in %llu out %llu \n", - GNUNET_i2s(&address->peer), address->plugin, address->addr, - ntohl(address->assigned_bw_in.value__), - ntohl(address->assigned_bw_out.value__)); - //end_now (0); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with success\n")); + end_now (0); } static void end_badly (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) { timeout_task = GNUNET_SCHEDULER_NO_TASK; - GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test failed: timeout\n")); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, _("Test ending with timeout\n")); end_now (1); } +static void +bandwidth_changed_cb (void *cls, struct ATS_Address *address) +{ + static int cb_p0 = GNUNET_NO; + static int cb_p1 = GNUNET_NO; + + unsigned long long in = ntohl(address->assigned_bw_in.value__); + unsigned long long out = ntohl(address->assigned_bw_out.value__); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "MLP suggests for peer `%s' address `%s':`%s' in %llu out %llu \n", + GNUNET_i2s(&address->peer), + address->plugin, + address->addr, + in, out); + + if ((in > 0) && (out > 0) && + (0 == memcmp(&p[0], &address->peer, sizeof (address->peer)))) + cb_p0 ++; + + if ((in > 0) && (out > 0) && + (0 == memcmp(&p[1], &address->peer, sizeof (address->peer)))) + cb_p1 ++; + + if ((1 == cb_p0) && (1 == cb_p1)) + GNUNET_SCHEDULER_add_now (&end_correctly, NULL); + else if ((1 > cb_p0) || (1 > cb_p1)) + GNUNET_SCHEDULER_add_now (&end_badly, NULL); +} + + static void check (void *cls, char *const *args, const char *cfgfile, const struct GNUNET_CONFIGURATION_Handle *cfg) @@ -185,6 +212,7 @@ check (void *cls, char *const *args, const char *cfgfile, end_now (1); return; } + mlp->mlp_auto_solve = GNUNET_NO; /* Create peer 0 */ if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p[0].hashPubKey)) @@ -202,35 +230,46 @@ check (void *cls, char *const *args, const char *cfgfile, return; } - /* Create address 3 */ - address[2] = create_address (&p[1], "test_plugin2", "test_addr2", strlen("test_addr2")+1, 0); - if (NULL == address[2]) + /* Create address 0 */ + address[0] = create_address (&p[0], "test_plugin0", "test_addr0", strlen("test_addr0")+1, 0); + if (NULL == address[0]) { GNUNET_break (0); end_now (1); return; } - GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2], + GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + /* Adding address 0 */ + GAS_mlp_address_add (mlp, addresses, address[0]); - + /* Create address 1 */ + address[1] = create_address (&p[0], "test_plugin1", "test_addr1", strlen("test_addr1")+1, 0); + if (NULL == address[1]) + { + GNUNET_break (0); + end_now (1); + return; + } + GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1], + GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); /* Adding address 1*/ - GAS_mlp_address_add (mlp, addresses, address[2]); + GAS_mlp_address_add (mlp, addresses, address[1]); - /* Create address 0 */ - address[0] = create_address (&p[0], "test_plugin0", "test_addr0", strlen("test_addr0")+1, 0); - if (NULL == address[0]) + /* Create address 3 */ + address[2] = create_address (&p[1], "test_plugin2", "test_addr2", strlen("test_addr2")+1, 0); + if (NULL == address[2]) { GNUNET_break (0); end_now (1); return; } - GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[0], + GNUNET_CONTAINER_multihashmap_put (addresses, &p[1].hashPubKey, address[2], GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + /* Adding address 3*/ + GAS_mlp_address_add (mlp, addresses, address[2]); - /* Adding address 0 */ - GAS_mlp_address_add (mlp, addresses, address[0]); /* Updating address 0*/ ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); @@ -239,32 +278,17 @@ check (void *cls, char *const *args, const char *cfgfile, /* Retrieving preferred address for peer and wait for callback */ GAS_mlp_get_preferred_address (mlp, addresses, &p[0]); - - /* Create address 1 */ - address[1] = create_address (&p[0], "test_plugin1", "test_addr1", strlen("test_addr1")+1, 0); - if (NULL == address[1]) - { - GNUNET_break (0); - end_now (1); - return; - } - GNUNET_CONTAINER_multihashmap_put (addresses, &p[0].hashPubKey, address[1], - GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST); + GAS_mlp_get_preferred_address (mlp, addresses, &p[1]); - /* Adding address 1*/ - GAS_mlp_address_add (mlp, addresses, address[1]); - +#if 0 /* Updating address 1*/ ats.type = htonl (GNUNET_ATS_NETWORK_TYPE); ats.value = htonl (GNUNET_ATS_NET_WAN); GAS_mlp_address_update (mlp, addresses, address[1], 1, GNUNET_NO, &ats, 1); - GAS_mlp_address_delete (mlp, addresses, address[0], GNUNET_NO); - - end_now (0); - //struct GAS_MLP_SolutionContext ctx; - //GAS_mlp_solve_problem (mlp, &ctx); +#endif + GAS_mlp_solve_problem (mlp, addresses); } -- 2.25.1