aboutsummaryrefslogtreecommitdiff
path: root/src/ats
diff options
context:
space:
mode:
authorMatthias Wachs <wachs@net.in.tum.de>2013-02-14 13:28:13 +0000
committerMatthias Wachs <wachs@net.in.tum.de>2013-02-14 13:28:13 +0000
commitf4af5b0b23a2efe6b5f25dbd87f79f788bfd5aba (patch)
treee98fc252aebd04845e74a8d726f837af75fca81d /src/ats
parent52d8ab51ff822968e9d0c7690391005977b18f4e (diff)
downloadgnunet-f4af5b0b23a2efe6b5f25dbd87f79f788bfd5aba.tar.gz
gnunet-f4af5b0b23a2efe6b5f25dbd87f79f788bfd5aba.zip
mod
Diffstat (limited to 'src/ats')
-rw-r--r--src/ats/test_ats_api_common.c33
-rw-r--r--src/ats/test_ats_api_common.h7
-rw-r--r--src/ats/test_ats_mlp.c139
3 files changed, 75 insertions, 104 deletions
diff --git a/src/ats/test_ats_api_common.c b/src/ats/test_ats_api_common.c
index dcd043e71..f8d106a7f 100644
--- a/src/ats/test_ats_api_common.c
+++ b/src/ats/test_ats_api_common.c
@@ -242,4 +242,37 @@ load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg,
242 return GNUNET_ATS_NetworkTypeCount; 242 return GNUNET_ATS_NetworkTypeCount;
243} 243}
244 244
245/**
246 * Create a ATS_address with the given information
247 * @param peer peer
248 * @param plugin_name plugin
249 * @param plugin_addr address
250 * @param plugin_addr_len address length
251 * @param session_id session
252 * @return the ATS_Address
253 */
254struct ATS_Address *
255create_address (const struct GNUNET_PeerIdentity *peer,
256 const char *plugin_name,
257 const void *plugin_addr, size_t plugin_addr_len,
258 uint32_t session_id)
259{
260 struct ATS_Address *aa = NULL;
261
262 aa = GNUNET_malloc (sizeof (struct ATS_Address) + plugin_addr_len + strlen (plugin_name) + 1);
263 aa->peer = *peer;
264 aa->addr_len = plugin_addr_len;
265 aa->addr = &aa[1];
266 aa->plugin = (char *) &aa[1] + plugin_addr_len;
267 memcpy (&aa[1], plugin_addr, plugin_addr_len);
268 memcpy (aa->plugin, plugin_name, strlen (plugin_name) + 1);
269 aa->session_id = session_id;
270 aa->active = GNUNET_NO;
271 aa->used = GNUNET_NO;
272 aa->solver_information = NULL;
273 aa->assigned_bw_in = GNUNET_BANDWIDTH_value_init(0);
274 aa->assigned_bw_out = GNUNET_BANDWIDTH_value_init(0);
275 return aa;
276}
277
245/* end of file test_ats_api_common.c */ 278/* end of file test_ats_api_common.c */
diff --git a/src/ats/test_ats_api_common.h b/src/ats/test_ats_api_common.h
index 3fbd0691b..1f9bd10c1 100644
--- a/src/ats/test_ats_api_common.h
+++ b/src/ats/test_ats_api_common.h
@@ -27,6 +27,7 @@
27#include "platform.h" 27#include "platform.h"
28#include "gnunet_common.h" 28#include "gnunet_common.h"
29#include "gnunet_ats_service.h" 29#include "gnunet_ats_service.h"
30#include "gnunet-service-ats_addresses.h"
30 31
31#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30) 32#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 30)
32 33
@@ -72,6 +73,12 @@ int
72compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is, 73compare_ats (const struct GNUNET_ATS_Information *ats_is, uint32_t ats_count_is,
73 const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should); 74 const struct GNUNET_ATS_Information *ats_should, uint32_t ats_count_should);
74 75
76struct ATS_Address *
77create_address (const struct GNUNET_PeerIdentity *peer,
78 const char *plugin_name,
79 const void *plugin_addr, size_t plugin_addr_len,
80 uint32_t session_id);
81
75/** 82/**
76 * Load quotas for networks from configuration 83 * Load quotas for networks from configuration
77 * 84 *
diff --git a/src/ats/test_ats_mlp.c b/src/ats/test_ats_mlp.c
index 594957a25..7945ab3a9 100644
--- a/src/ats/test_ats_mlp.c
+++ b/src/ats/test_ats_mlp.c
@@ -52,32 +52,21 @@ struct GNUNET_STATISTICS_Handle * stats;
52 */ 52 */
53struct GNUNET_CONTAINER_MultiHashMap * addresses; 53struct GNUNET_CONTAINER_MultiHashMap * addresses;
54 54
55/**
56 * Peer
57 */
58struct GNUNET_PeerIdentity p;
59
60/**
61 * ATS Address
62 */
63struct ATS_Address *address;
64
55#if 0 65#if 0
56 66
57#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3) 67#define MLP_MAX_EXEC_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 3)
58#define MLP_MAX_ITERATIONS INT_MAX 68#define MLP_MAX_ITERATIONS INT_MAX
59 69
60
61
62
63
64
65
66
67
68
69
70static void
71create_address (struct ATS_Address *addr, char * plugin, int ats_count, struct GNUNET_ATS_Information *ats)
72{
73 addr->solver_information = NULL;
74 addr->next = NULL;
75 addr->prev = NULL;
76 addr->plugin = GNUNET_strdup (plugin);
77 addr->ats_count = ats_count;
78 addr->ats = ats;
79}
80
81static void 70static void
82set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value) 71set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value)
83{ 72{
@@ -85,87 +74,6 @@ set_ats (struct GNUNET_ATS_Information *ats, uint32_t type, uint32_t value)
85 ats->value = value; 74 ats->value = value;
86} 75}
87 76
88
89unsigned int
90load_quotas (const struct GNUNET_CONFIGURATION_Handle *cfg, unsigned long long *out_dest, unsigned long long *in_dest, int dest_length)
91{
92 int quotas[GNUNET_ATS_NetworkTypeCount] = GNUNET_ATS_NetworkType;
93 char * entry_in = NULL;
94 char * entry_out = NULL;
95 char * quota_out_str;
96 char * quota_in_str;
97 int c;
98
99 for (c = 0; (c < GNUNET_ATS_NetworkTypeCount) && (c < dest_length); c++)
100 {
101 in_dest[c] = 0;
102 out_dest[c] = 0;
103 switch (quotas[c]) {
104 case GNUNET_ATS_NET_UNSPECIFIED:
105 entry_out = "UNSPECIFIED_QUOTA_OUT";
106 entry_in = "UNSPECIFIED_QUOTA_IN";
107 break;
108 case GNUNET_ATS_NET_LOOPBACK:
109 entry_out = "LOOPBACK_QUOTA_OUT";
110 entry_in = "LOOPBACK_QUOTA_IN";
111 break;
112 case GNUNET_ATS_NET_LAN:
113 entry_out = "LAN_QUOTA_OUT";
114 entry_in = "LAN_QUOTA_IN";
115 break;
116 case GNUNET_ATS_NET_WAN:
117 entry_out = "WAN_QUOTA_OUT";
118 entry_in = "WAN_QUOTA_IN";
119 break;
120 case GNUNET_ATS_NET_WLAN:
121 entry_out = "WLAN_QUOTA_OUT";
122 entry_in = "WLAN_QUOTA_IN";
123 break;
124 default:
125 break;
126 }
127
128 if ((entry_in == NULL) || (entry_out == NULL))
129 continue;
130
131 /* quota out */
132 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_out, &quota_out_str))
133 {
134 if (0 == strcmp(quota_out_str, BIG_M_STRING) ||
135 (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_out_str, &out_dest[c])))
136 out_dest[c] = UINT32_MAX;
137
138 GNUNET_free (quota_out_str);
139 quota_out_str = NULL;
140 }
141 else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
142 out_dest[c] = UINT32_MAX;
143 else
144 out_dest[c] = UINT32_MAX;
145
146 /* quota in */
147 if (GNUNET_OK == GNUNET_CONFIGURATION_get_value_string(cfg, "ats", entry_in, &quota_in_str))
148 {
149 if (0 == strcmp(quota_in_str, BIG_M_STRING) ||
150 (GNUNET_SYSERR == GNUNET_STRINGS_fancy_size_to_bytes (quota_in_str, &in_dest[c])))
151 in_dest[c] = UINT32_MAX;
152
153 GNUNET_free (quota_in_str);
154 quota_in_str = NULL;
155 }
156 else if (GNUNET_ATS_NET_UNSPECIFIED == quotas[c])
157 {
158 in_dest[c] = UINT32_MAX;
159 }
160 else
161 {
162 in_dest[c] = UINT32_MAX;
163 }
164 GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, "Loaded quota: %s %u, %s %u\n", entry_in, in_dest[c], entry_out, out_dest[c]);
165
166 }
167 return GNUNET_ATS_NetworkTypeCount;
168}
169#endif 77#endif
170 78
171int addr_it (void *cls, 79int addr_it (void *cls,
@@ -196,7 +104,11 @@ end_now (int res)
196 GNUNET_CONTAINER_multihashmap_destroy (addresses); 104 GNUNET_CONTAINER_multihashmap_destroy (addresses);
197 addresses = NULL ; 105 addresses = NULL ;
198 } 106 }
199 107 if (NULL != address)
108 {
109 GNUNET_free (address);
110 address = NULL;
111 }
200 ret = res; 112 ret = res;
201} 113}
202 114
@@ -238,7 +150,6 @@ check (void *cls, char *const *args, const char *cfgfile,
238 } 150 }
239 151
240 addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO); 152 addresses = GNUNET_CONTAINER_multihashmap_create (10, GNUNET_NO);
241
242 mlp = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in, 153 mlp = GAS_mlp_init (cfg, stats, quotas, quotas_out, quotas_in,
243 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL); 154 GNUNET_ATS_NetworkTypeCount, &bandwidth_changed_cb, NULL);
244 if (NULL == mlp) 155 if (NULL == mlp)
@@ -248,6 +159,26 @@ check (void *cls, char *const *args, const char *cfgfile,
248 return; 159 return;
249 } 160 }
250 161
162 /* Create peer */
163 if (GNUNET_SYSERR == GNUNET_CRYPTO_hash_from_string(PEERID0, &p.hashPubKey))
164 {
165 GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Could not setup peer!\n");
166 end_now (1);
167 return;
168 }
169
170 /* Create address */
171 address = create_address (&p, "test_plugin", "test_addr", strlen("test_addr")+1, 0);
172 if (NULL == address)
173 {
174 GNUNET_break (0);
175 end_now (1);
176 return;
177 }
178 GNUNET_CONTAINER_multihashmap_put (addresses, &p.hashPubKey, address,
179 GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_FAST);
180
181 GAS_mlp_address_add (mlp, addresses, address);
251 182
252 183
253 end_now (0); 184 end_now (0);