2 This file is part of GNUnet.
3 (C) 2010,2011 Christian Grothoff (and other contributing authors)
5 GNUnet is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published
7 by the Free Software Foundation; either version 3, or (at your
8 option) any later version.
10 GNUnet is distributed in the hope that it will be useful, but
11 WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with GNUnet; see the file COPYING. If not, write to the
17 Free Software Foundation, Inc., 59 Temple Place - Suite 330,
18 Boston, MA 02111-1307, USA.
21 * @file ats/test_ats_mlp.c
22 * @brief test for the MLP solver
23 * @author Christian Grothoff
24 * @author Matthias Wachs
28 #include "gnunet_util_lib.h"
29 #include "gnunet_statistics_service.h"
30 #include "gnunet_ats_service.h"
31 #include "gnunet-service-ats_addresses_mlp.h"
33 #define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
34 #define MLP_MAX_ITERATIONS INT_MAX
39 struct GNUNET_STATISTICS_Handle * stats;
41 struct GNUNET_CONTAINER_MultiHashMap * addresses;
43 struct GAS_MLP_Handle *mlp;
47 create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats)
49 addr->mlp_information = NULL;
52 addr->plugin = GNUNET_strdup (plugin);
53 addr->ats_count = ats_count;
58 set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value)
65 check (void *cls, char *const *args, const char *cfgfile,
66 const struct GNUNET_CONFIGURATION_Handle *cfg)
69 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
73 struct ATS_Address addr[10];
74 struct ATS_PreferedAddress *res[10];
75 // struct MLP_information *mlpi;
76 struct GAS_MLP_SolutionContext ctx;
78 stats = GNUNET_STATISTICS_create("ats", cfg);
80 addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
82 mlp = GAS_mlp_init (cfg, NULL);
83 mlp->auto_solve = GNUNET_NO;
85 struct GNUNET_PeerIdentity p[10];
88 GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &p[0].hashPubKey);
90 /* Creating peer 1 address 1 */
91 addr[0].peer.hashPubKey = p[0].hashPubKey;
92 struct GNUNET_ATS_Information a1_ats[3];
93 set_ats (&a1_ats[0], GNUNET_ATS_QUALITY_NET_DISTANCE, 1);
94 set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 0);
95 set_ats (&a1_ats[2], GNUNET_ATS_ARRAY_TERMINATOR, 0);
96 create_address (&addr[0], "dummy", 3, &a1_ats[0]);
97 addr[0].atsp_network_type = GNUNET_ATS_NET_LAN;
99 GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
101 /* Add peer 1 address 1 */
102 GAS_mlp_address_update (mlp, addresses, &addr[0]);
103 // mlpi = addr[0].mlp_information;
105 GNUNET_assert (mlp != NULL);
106 GNUNET_assert (mlp->addr_in_problem == 1);
108 /* Update an peer 1 address 1 */
109 set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 20);
110 GAS_mlp_address_update (mlp, addresses, &addr[0]);
111 GNUNET_assert (mlp->addr_in_problem == 1);
114 /* Update an peer 1 address 1 */
115 set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 10);
116 GAS_mlp_address_update (mlp, addresses, &addr[0]);
117 GNUNET_assert (mlp->addr_in_problem == 1);
119 /* Update an peer 1 address 1 */
120 set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 10);
121 GAS_mlp_address_update (mlp, addresses, &addr[0]);
122 GNUNET_assert (mlp->addr_in_problem == 1);
124 /* Update an peer 1 address 1 */
125 set_ats (&a1_ats[1], GNUNET_ATS_QUALITY_NET_DELAY, 30);
126 GAS_mlp_address_update (mlp, addresses, &addr[0]);
127 GNUNET_assert (mlp->addr_in_problem == 1);
130 GNUNET_assert (GNUNET_OK == GAS_mlp_solve_problem(mlp, &ctx));
131 GNUNET_assert (GNUNET_OK == ctx.lp_result);
132 GNUNET_assert (GNUNET_OK == ctx.mlp_result);
134 res[0] = GAS_mlp_get_preferred_address(mlp, addresses, &p[0]);
135 GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Preferred address `%s' outbound bandwidth: %u Bps\n",res[0]->address->plugin, res[0]->bandwidth_out);
136 GNUNET_free (res[0]);
138 /* Delete an address */
139 GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]);
140 GAS_mlp_address_delete (mlp, addresses, &addr[0]);
142 GNUNET_assert (mlp->addr_in_problem == 0);
146 GNUNET_free (addr[0].plugin);
147 GNUNET_CONTAINER_multihashmap_destroy (addresses);
148 GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
156 main (int argc, char *argv[])
159 static char *const argv2[] = { "test_ats_mlp",
166 static struct GNUNET_GETOPT_CommandLineOption options[] = {
167 GNUNET_GETOPT_OPTION_END
170 GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
171 "test_ats_mlp", "nohelp", options,
178 /* end of file test_ats_api_bandwidth_consumption.c */