- more working constraints
[oweals/gnunet.git] / src / ats / test_ats_mlp.c
1 /*
2      This file is part of GNUnet.
3      (C) 2010,2011 Christian Grothoff (and other contributing authors)
4
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.
9
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.
14
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.
19 */
20 /**
21  * @file ats/test_ats_mlp.c
22  * @brief test for the MLP solver
23  * @author Christian Grothoff
24  * @author Matthias Wachs
25
26  */
27 #include "platform.h"
28 #include "gnunet_util_lib.h"
29 #include "gnunet_statistics_service.h"
30 #include "gnunet-service-ats_addresses_mlp.h"
31
32 #define VERBOSE GNUNET_YES
33 #define VERBOSE_ARM GNUNET_EXTRA_LOGGING
34
35 #define MLP_MAX_EXEC_DURATION   GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
36 #define MLP_MAX_ITERATIONS      INT_MAX
37
38
39 static int ret;
40
41 struct GNUNET_STATISTICS_Handle * stats;
42
43 struct GNUNET_CONTAINER_MultiHashMap * addresses;
44
45 struct GAS_MLP_Handle *mlp;
46
47 static void
48 check (void *cls, char *const *args, const char *cfgfile,
49        const struct GNUNET_CONFIGURATION_Handle *cfg)
50 {
51 #if !HAVE_LIBGLPK
52   GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "GLPK not installed!");
53   ret = 1;
54   return;
55 #endif
56   struct ATS_Address addr[10];
57
58   stats = GNUNET_STATISTICS_create("ats", cfg);
59
60   addresses = GNUNET_CONTAINER_multihashmap_create (10);
61
62   GNUNET_CRYPTO_hash_create_random(GNUNET_CRYPTO_QUALITY_WEAK, &addr[0].peer.hashPubKey);
63   addr[0].mlp_information = NULL;
64   addr[0].next = NULL;
65   addr[0].prev = NULL;
66   addr[0].plugin = strdup ("dummy");
67
68   addr[1].peer = addr[0].peer;
69   addr[1].mlp_information = NULL;
70   addr[1].next = NULL;
71   addr[1].prev = NULL;
72   addr[1].plugin = strdup ("dummy2");
73
74   GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[0], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
75
76   mlp = GAS_mlp_init (cfg, NULL, MLP_MAX_EXEC_DURATION, MLP_MAX_ITERATIONS);
77
78   /* Add a new address */
79   GAS_mlp_address_update (mlp, addresses, &addr[0]);
80
81   GNUNET_assert (mlp != NULL);
82   GNUNET_assert (mlp->addr_in_problem == 1);
83
84   /* Update an new address */
85   GAS_mlp_address_update (mlp, addresses, &addr[0]);
86   GNUNET_assert (mlp->addr_in_problem == 1);
87
88   /* Add a second address for same peer */
89   GNUNET_CONTAINER_multihashmap_put(addresses, &addr[0].peer.hashPubKey, &addr[1], GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE);
90   GAS_mlp_address_update (mlp, addresses, &addr[1]);
91   GNUNET_assert (mlp->addr_in_problem == 2);
92
93   /* Delete an address */
94   GNUNET_CONTAINER_multihashmap_remove (addresses, &addr[0].peer.hashPubKey, &addr[0]);
95   GAS_mlp_address_delete (mlp, addresses, &addr[0]);
96   GAS_mlp_address_delete (mlp, addresses, &addr[1]);
97
98   GAS_mlp_done (mlp);
99
100   GNUNET_free (addr[0].plugin);
101   GNUNET_free (addr[1].plugin);
102   GNUNET_CONTAINER_multihashmap_destroy (addresses);
103   GNUNET_STATISTICS_destroy(stats, GNUNET_NO);
104
105   ret = 0;
106   return;
107 }
108
109
110 int
111 main (int argc, char *argv[])
112 {
113
114   static char *const argv2[] = { "test_ats_mlp",
115     "-c",
116     "test_ats_api.conf",
117 #if VERBOSE
118     "-L", "DEBUG",
119 #else
120     "-L", "WARNING",
121 #endif
122     NULL
123   };
124
125   static struct GNUNET_GETOPT_CommandLineOption options[] = {
126     GNUNET_GETOPT_OPTION_END
127   };
128
129   GNUNET_PROGRAM_run ((sizeof (argv2) / sizeof (char *)) - 1, argv2,
130                       "test_ats_mlp", "nohelp", options,
131                       &check, NULL);
132
133
134   return ret;
135 }
136
137 /* end of file test_ats_api_bandwidth_consumption.c */