diff options
author | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-17 15:32:23 +0000 |
---|---|---|
committer | Matthias Wachs <wachs@net.in.tum.de> | 2012-02-17 15:32:23 +0000 |
commit | 847f1b045f087dac3ed2b8989a0512610b58b00d (patch) | |
tree | f6bb4b5770545082c59d1cb369b77154fd76299c /src/ats | |
parent | dde12b107415d22cf0dbe44e2a0b88a974b59ae0 (diff) | |
download | gnunet-847f1b045f087dac3ed2b8989a0512610b58b00d.tar.gz gnunet-847f1b045f087dac3ed2b8989a0512610b58b00d.zip |
- changes to ats
Diffstat (limited to 'src/ats')
-rw-r--r-- | src/ats/gnunet-service-ats_addresses.c | 33 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.c | 48 | ||||
-rw-r--r-- | src/ats/gnunet-service-ats_addresses_mlp.h | 16 | ||||
-rw-r--r-- | src/ats/test_ats_mlp.c | 7 |
4 files changed, 89 insertions, 15 deletions
diff --git a/src/ats/gnunet-service-ats_addresses.c b/src/ats/gnunet-service-ats_addresses.c index 04cc07c8b..12eaef113 100644 --- a/src/ats/gnunet-service-ats_addresses.c +++ b/src/ats/gnunet-service-ats_addresses.c | |||
@@ -77,17 +77,19 @@ static int ats_mode; | |||
77 | * @return GNUNET_OK (continue to iterate) | 77 | * @return GNUNET_OK (continue to iterate) |
78 | */ | 78 | */ |
79 | static int | 79 | static int |
80 | update_bw_it (void *cls, const GNUNET_HashCode * key, void *value) | 80 | update_bw_simple_it (void *cls, const GNUNET_HashCode * key, void *value) |
81 | { | 81 | { |
82 | struct ATS_Address *aa = value; | 82 | struct ATS_Address *aa = value; |
83 | 83 | ||
84 | |||
85 | /* Simple method */ | ||
86 | if (GNUNET_YES != aa->active) | 84 | if (GNUNET_YES != aa->active) |
87 | return GNUNET_OK; | 85 | return GNUNET_OK; |
88 | GNUNET_assert (active_addr_count > 0); | 86 | GNUNET_assert (active_addr_count > 0); |
87 | |||
88 | |||
89 | /* Simple method */ | ||
89 | aa->assigned_bw_in.value__ = htonl (wan_quota_in / active_addr_count); | 90 | aa->assigned_bw_in.value__ = htonl (wan_quota_in / active_addr_count); |
90 | aa->assigned_bw_out.value__ = htonl (wan_quota_out / active_addr_count); | 91 | aa->assigned_bw_out.value__ = htonl (wan_quota_out / active_addr_count); |
92 | |||
91 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n", | 93 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "New bandwidth for peer %s is %u/%u\n", |
92 | GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__), | 94 | GNUNET_i2s (&aa->peer), ntohl (aa->assigned_bw_in.value__), |
93 | ntohl (aa->assigned_bw_out.value__)); | 95 | ntohl (aa->assigned_bw_out.value__)); |
@@ -117,7 +119,8 @@ recalculate_assigned_bw () | |||
117 | 1, GNUNET_NO); | 119 | 1, GNUNET_NO); |
118 | GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count, | 120 | GNUNET_STATISTICS_set (GSA_stats, "# active addresses", active_addr_count, |
119 | GNUNET_NO); | 121 | GNUNET_NO); |
120 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_it, NULL); | 122 | |
123 | GNUNET_CONTAINER_multihashmap_iterate (addresses, &update_bw_simple_it, NULL); | ||
121 | } | 124 | } |
122 | 125 | ||
123 | /** | 126 | /** |
@@ -591,14 +594,24 @@ GAS_addresses_request_address (const struct GNUNET_PeerIdentity *peer) | |||
591 | struct ATS_Address *aa; | 594 | struct ATS_Address *aa; |
592 | 595 | ||
593 | aa = NULL; | 596 | aa = NULL; |
594 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, | 597 | |
595 | &find_address_it, &aa); | 598 | if (ats_mode == SIMPLE) |
596 | if (aa == NULL) | ||
597 | { | 599 | { |
598 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 600 | /* Get address with: stick to current address, lower distance, lower latency */ |
599 | "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); | 601 | GNUNET_CONTAINER_multihashmap_get_multiple (addresses, &peer->hashPubKey, |
600 | return; | 602 | &find_address_it, &aa); |
603 | if (aa == NULL) | ||
604 | { | ||
605 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | ||
606 | "Cannot suggest address for peer `%s'\n", GNUNET_i2s (peer)); | ||
607 | return; | ||
608 | } | ||
601 | } | 609 | } |
610 | if (ats_mode == MLP) | ||
611 | { | ||
612 | /* Get preferred address from MLP */ | ||
613 | } | ||
614 | |||
602 | if (aa->active == GNUNET_NO) | 615 | if (aa->active == GNUNET_NO) |
603 | { | 616 | { |
604 | aa->active = GNUNET_YES; | 617 | aa->active = GNUNET_YES; |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.c b/src/ats/gnunet-service-ats_addresses_mlp.c index 50d1e42a2..0c9e0b328 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.c +++ b/src/ats/gnunet-service-ats_addresses_mlp.c | |||
@@ -1026,17 +1026,20 @@ GAS_mlp_solve_problem (struct GAS_MLP_Handle *mlp) | |||
1026 | mlpi = a->mlp_information; | 1026 | mlpi = a->mlp_information; |
1027 | 1027 | ||
1028 | b = glp_mip_col_val(mlp->prob, mlpi->c_b); | 1028 | b = glp_mip_col_val(mlp->prob, mlpi->c_b); |
1029 | n = glp_mip_col_val(mlp->prob, mlpi->c_n); | 1029 | mlpi->b = b; |
1030 | 1030 | ||
1031 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tAddress %f %f\n", n, b); | 1031 | n = glp_mip_col_val(mlp->prob, mlpi->c_n); |
1032 | if (n == 1.0) | ||
1033 | mlpi->n = GNUNET_YES; | ||
1034 | else | ||
1035 | mlpi->n = GNUNET_NO; | ||
1032 | 1036 | ||
1037 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "\tAddress %s %f\n", | ||
1038 | (n == 1.0) ? "[x]" : "[ ]", b); | ||
1033 | } | 1039 | } |
1034 | 1040 | ||
1035 | } | 1041 | } |
1036 | 1042 | ||
1037 | |||
1038 | |||
1039 | |||
1040 | if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) | 1043 | if (mlp->mlp_task != GNUNET_SCHEDULER_NO_TASK) |
1041 | { | 1044 | { |
1042 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); | 1045 | GNUNET_SCHEDULER_cancel(mlp->mlp_task); |
@@ -1416,6 +1419,41 @@ GAS_mlp_address_delete (struct GAS_MLP_Handle *mlp, struct GNUNET_CONTAINER_Mult | |||
1416 | } | 1419 | } |
1417 | } | 1420 | } |
1418 | 1421 | ||
1422 | static int | ||
1423 | mlp_get_preferred_address_it (void *cls, const GNUNET_HashCode * key, void *value) | ||
1424 | { | ||
1425 | |||
1426 | struct ATS_Address **aa = (struct ATS_Address **)cls; | ||
1427 | struct ATS_Address *addr = value; | ||
1428 | struct MLP_information *mlpi = addr->mlp_information; | ||
1429 | if (mlpi->n == GNUNET_YES) | ||
1430 | { | ||
1431 | *aa = addr; | ||
1432 | return GNUNET_NO; | ||
1433 | } | ||
1434 | return GNUNET_YES; | ||
1435 | } | ||
1436 | |||
1437 | |||
1438 | /** | ||
1439 | * Get the preferred address for a specific peer | ||
1440 | * | ||
1441 | * @param mlp the MLP Handle | ||
1442 | * @param peer the peer | ||
1443 | * @return suggested address | ||
1444 | */ | ||
1445 | struct ATS_Address * | ||
1446 | GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp, | ||
1447 | struct GNUNET_CONTAINER_MultiHashMap * addresses, | ||
1448 | const struct GNUNET_PeerIdentity *peer) | ||
1449 | { | ||
1450 | struct ATS_Address * aa = NULL; | ||
1451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Getting preferred address for `%s'\n", GNUNET_i2s (peer)); | ||
1452 | GNUNET_CONTAINER_multihashmap_get_multiple(addresses, &peer->hashPubKey, mlp_get_preferred_address_it, &aa); | ||
1453 | return aa; | ||
1454 | } | ||
1455 | |||
1456 | |||
1419 | /** | 1457 | /** |
1420 | * Changes the preferences for a peer in the MLP problem | 1458 | * Changes the preferences for a peer in the MLP problem |
1421 | * | 1459 | * |
diff --git a/src/ats/gnunet-service-ats_addresses_mlp.h b/src/ats/gnunet-service-ats_addresses_mlp.h index 52631eb3c..a2e665f4b 100644 --- a/src/ats/gnunet-service-ats_addresses_mlp.h +++ b/src/ats/gnunet-service-ats_addresses_mlp.h | |||
@@ -251,6 +251,10 @@ struct GAS_MLP_Handle | |||
251 | */ | 251 | */ |
252 | struct MLP_information | 252 | struct MLP_information |
253 | { | 253 | { |
254 | double b; | ||
255 | |||
256 | int n; | ||
257 | |||
254 | /* bandwidth column index */ | 258 | /* bandwidth column index */ |
255 | signed int c_b; | 259 | signed int c_b; |
256 | 260 | ||
@@ -349,6 +353,18 @@ GAS_mlp_address_change_preference (struct GAS_MLP_Handle *mlp, | |||
349 | 353 | ||
350 | 354 | ||
351 | /** | 355 | /** |
356 | * Get the preferred address for a specific peer | ||
357 | * | ||
358 | * @param mlp the MLP Handle | ||
359 | * @param peer the peer | ||
360 | * @return suggested address | ||
361 | */ | ||
362 | struct ATS_Address * | ||
363 | GAS_mlp_get_preferred_address (struct GAS_MLP_Handle *mlp, | ||
364 | struct GNUNET_CONTAINER_MultiHashMap * addresses, | ||
365 | const struct GNUNET_PeerIdentity *peer); | ||
366 | |||
367 | /** | ||
352 | * Shutdown the MLP problem solving component | 368 | * Shutdown the MLP problem solving component |
353 | */ | 369 | */ |
354 | void | 370 | void |
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c index 23ab71f7a..ddcd41237 100644 --- a/src/ats/test_ats_mlp.c +++ b/src/ats/test_ats_mlp.c | |||
@@ -45,6 +45,7 @@ struct GNUNET_CONTAINER_MultiHashMap * addresses; | |||
45 | 45 | ||
46 | struct GAS_MLP_Handle *mlp; | 46 | struct GAS_MLP_Handle *mlp; |
47 | 47 | ||
48 | |||
48 | static void | 49 | static void |
49 | create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats) | 50 | create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats) |
50 | { | 51 | { |
@@ -73,6 +74,7 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
73 | return; | 74 | return; |
74 | #endif | 75 | #endif |
75 | struct ATS_Address addr[10]; | 76 | struct ATS_Address addr[10]; |
77 | struct ATS_Address *res[10]; | ||
76 | 78 | ||
77 | stats = GNUNET_STATISTICS_create("ats", cfg); | 79 | stats = GNUNET_STATISTICS_create("ats", cfg); |
78 | 80 | ||
@@ -138,6 +140,11 @@ check (void *cls, char *const *args, const char *cfgfile, | |||
138 | 140 | ||
139 | GNUNET_assert (GNUNET_OK == GAS_mlp_solve_problem(mlp)); | 141 | GNUNET_assert (GNUNET_OK == GAS_mlp_solve_problem(mlp)); |
140 | 142 | ||
143 | res[0] = GAS_mlp_get_preferred_address(mlp, addresses, &p[0]); | ||
144 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' \n",res[0]->plugin); | ||
145 | res[1] = GAS_mlp_get_preferred_address(mlp, addresses, &p[1]); | ||
146 | GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' \n",res[1]->plugin); | ||
147 | |||
141 | /* Delete an address */ | 148 | /* Delete an address */ |
142 | GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]); | 149 | GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]); |
143 | GAS_mlp_address_delete (mlp, addresses, &addr[0]); | 150 | GAS_mlp_address_delete (mlp, addresses, &addr[0]); |