diff options
author | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2019-10-05 15:09:28 +0200 |
commit | c4e9ba925ffd758aaa3feee2ccfc0b76f26fe207 (patch) | |
tree | cac3ce030d77b4cbe7c7dc62ed58cfe6d24f73e1 /src | |
parent | fbb71d527c7d6babf269a8fefce1db291b9f7068 (diff) |
global reindent, now with uncrustify hook enabled
Diffstat (limited to 'src')
1007 files changed, 210320 insertions, 205092 deletions
diff --git a/src/abe/abe.c b/src/abe/abe.c index 31c6e04e0..bba6e5c45 100644 --- a/src/abe/abe.c +++ b/src/abe/abe.c @@ -33,63 +33,65 @@ #include "gnunet_crypto_lib.h" #include "gnunet_abe_lib.h" -struct GNUNET_ABE_AbeMasterKey { - gabe_pub_t* pub; - gabe_msk_t* msk; +struct GNUNET_ABE_AbeMasterKey +{ + gabe_pub_t*pub; + gabe_msk_t*msk; }; -struct GNUNET_ABE_AbeKey { - gabe_pub_t* pub; - gabe_prv_t* prv; +struct GNUNET_ABE_AbeKey +{ + gabe_pub_t*pub; + gabe_prv_t*prv; }; static int -init_aes(element_t k, int enc, - gcry_cipher_hd_t* handle, - struct GNUNET_CRYPTO_SymmetricSessionKey *key, - unsigned char* iv) +init_aes (element_t k, int enc, + gcry_cipher_hd_t*handle, + struct GNUNET_CRYPTO_SymmetricSessionKey *key, + unsigned char*iv) { int rc; int key_len; - unsigned char* key_buf; - - key_len = element_length_in_bytes(k) < 33 ? 3 : element_length_in_bytes(k); - key_buf = (unsigned char*)malloc(key_len); - element_to_bytes(key_buf, k); - - GNUNET_memcpy(key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); - GNUNET_assert(0 == - gcry_cipher_open(handle, GCRY_CIPHER_AES256, - GCRY_CIPHER_MODE_CFB, 0)); - rc = gcry_cipher_setkey(*handle, - key->aes_key, - sizeof(key->aes_key)); - GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY)); - memset(iv, 0, 16); //TODO make reasonable - rc = gcry_cipher_setiv(*handle, - iv, - 16); - GNUNET_assert((0 == rc) || ((char)rc == GPG_ERR_WEAK_KEY)); - - free(key_buf); + unsigned char*key_buf; + + key_len = element_length_in_bytes (k) < 33 ? 3 : element_length_in_bytes (k); + key_buf = (unsigned char*) malloc (key_len); + element_to_bytes (key_buf, k); + + GNUNET_memcpy (key->aes_key, key_buf, GNUNET_CRYPTO_AES_KEY_LENGTH); + GNUNET_assert (0 == + gcry_cipher_open (handle, GCRY_CIPHER_AES256, + GCRY_CIPHER_MODE_CFB, 0)); + rc = gcry_cipher_setkey (*handle, + key->aes_key, + sizeof(key->aes_key)); + GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); + memset (iv, 0, 16); // TODO make reasonable + rc = gcry_cipher_setiv (*handle, + iv, + 16); + GNUNET_assert ((0 == rc) || ((char) rc == GPG_ERR_WEAK_KEY)); + + free (key_buf); return rc; } static int -aes_128_cbc_encrypt(char* pt, - int size, - element_t k, - char **ct) +aes_128_cbc_encrypt (char*pt, + int size, + element_t k, + char **ct) { gcry_cipher_hd_t handle; struct GNUNET_CRYPTO_SymmetricSessionKey skey; unsigned char iv[16]; - char* buf; + char*buf; int padding; int buf_size; uint8_t len[4]; - init_aes(k, 1, &handle, &skey, iv); + init_aes (k, 1, &handle, &skey, iv); /* TODO make less crufty */ @@ -100,37 +102,38 @@ aes_128_cbc_encrypt(char* pt, len[3] = (size & 0xff) >> 0; padding = 16 - ((4 + size) % 16); buf_size = 4 + size + padding; - buf = GNUNET_malloc(buf_size); - GNUNET_memcpy(buf, len, 4); - GNUNET_memcpy(buf + 4, pt, size); - *ct = GNUNET_malloc(buf_size); - - GNUNET_assert(0 == gcry_cipher_encrypt(handle, *ct, buf_size, buf, buf_size)); - gcry_cipher_close(handle); - //AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT); - GNUNET_free(buf); + buf = GNUNET_malloc (buf_size); + GNUNET_memcpy (buf, len, 4); + GNUNET_memcpy (buf + 4, pt, size); + *ct = GNUNET_malloc (buf_size); + + GNUNET_assert (0 == gcry_cipher_encrypt (handle, *ct, buf_size, buf, + buf_size)); + gcry_cipher_close (handle); + // AES_cbc_encrypt(pt->data, ct->data, pt->len, &key, iv, AES_ENCRYPT); + GNUNET_free (buf); return buf_size; } static int -aes_128_cbc_decrypt(char* ct, - int size, - element_t k, - char **pt) +aes_128_cbc_decrypt (char*ct, + int size, + element_t k, + char **pt) { struct GNUNET_CRYPTO_SymmetricSessionKey skey; gcry_cipher_hd_t handle; unsigned char iv[16]; - char* tmp; + char*tmp; uint32_t len; - init_aes(k, 1, &handle, &skey, iv); + init_aes (k, 1, &handle, &skey, iv); - tmp = GNUNET_malloc(size); + tmp = GNUNET_malloc (size); - //AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); - GNUNET_assert(0 == gcry_cipher_decrypt(handle, tmp, size, ct, size)); - gcry_cipher_close(handle); + // AES_cbc_encrypt(ct->data, pt->data, ct->len, &key, iv, AES_DECRYPT); + GNUNET_assert (0 == gcry_cipher_decrypt (handle, tmp, size, ct, size)); + gcry_cipher_close (handle); /* TODO make less crufty */ /* get real length */ @@ -139,9 +142,9 @@ aes_128_cbc_decrypt(char* ct, | ((tmp[0]) << 24) | ((tmp[1]) << 16) | ((tmp[2]) << 8) | ((tmp[3]) << 0); /* truncate any garbage from the padding */ - *pt = GNUNET_malloc(len); - GNUNET_memcpy(*pt, tmp + 4, len); - GNUNET_free(tmp); + *pt = GNUNET_malloc (len); + GNUNET_memcpy (*pt, tmp + 4, len); + GNUNET_free (tmp); return len; } @@ -152,14 +155,14 @@ aes_128_cbc_decrypt(char* ct, * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_master_key */ struct GNUNET_ABE_AbeMasterKey* -GNUNET_ABE_cpabe_create_master_key(void) +GNUNET_ABE_cpabe_create_master_key (void) { - struct GNUNET_ABE_AbeMasterKey* key; + struct GNUNET_ABE_AbeMasterKey*key; - key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey); - gabe_setup(&key->pub, &key->msk); - GNUNET_assert(NULL != key->pub); - GNUNET_assert(NULL != key->msk); + key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey); + gabe_setup (&key->pub, &key->msk); + GNUNET_assert (NULL != key->pub); + GNUNET_assert (NULL != key->msk); return key; } @@ -171,13 +174,13 @@ GNUNET_ABE_cpabe_create_master_key(void) * @return fresh private key; free using #GNUNET_free */ void -GNUNET_ABE_cpabe_delete_master_key(struct GNUNET_ABE_AbeMasterKey *key) +GNUNET_ABE_cpabe_delete_master_key (struct GNUNET_ABE_AbeMasterKey *key) { - gabe_msk_free(key->msk); - gabe_pub_free(key->pub); - //GNUNET_free (key->msk); - //gabe_msk_free (key->msk); //For some reason free of pub implicit? - GNUNET_free(key); + gabe_msk_free (key->msk); + gabe_pub_free (key->pub); + // GNUNET_free (key->msk); + // gabe_msk_free (key->msk); //For some reason free of pub implicit? + GNUNET_free (key); } /** @@ -189,19 +192,19 @@ GNUNET_ABE_cpabe_delete_master_key(struct GNUNET_ABE_AbeMasterKey *key) * @return fresh private key; free using #GNUNET_ABE_cpabe_delete_key */ struct GNUNET_ABE_AbeKey* -GNUNET_ABE_cpabe_create_key(struct GNUNET_ABE_AbeMasterKey *key, - char **attrs) +GNUNET_ABE_cpabe_create_key (struct GNUNET_ABE_AbeMasterKey *key, + char **attrs) { struct GNUNET_ABE_AbeKey *prv_key; int size; char *tmp; - prv_key = GNUNET_new(struct GNUNET_ABE_AbeKey); - prv_key->prv = gabe_keygen(key->pub, key->msk, attrs); - size = gabe_pub_serialize(key->pub, &tmp); - prv_key->pub = gabe_pub_unserialize(tmp, size); - GNUNET_free(tmp); - GNUNET_assert(NULL != prv_key->prv); + prv_key = GNUNET_new (struct GNUNET_ABE_AbeKey); + prv_key->prv = gabe_keygen (key->pub, key->msk, attrs); + size = gabe_pub_serialize (key->pub, &tmp); + prv_key->pub = gabe_pub_unserialize (tmp, size); + GNUNET_free (tmp); + GNUNET_assert (NULL != prv_key->prv); return prv_key; } @@ -214,70 +217,70 @@ GNUNET_ABE_cpabe_create_key(struct GNUNET_ABE_AbeMasterKey *key, * @return fresh private key; free using #GNUNET_free */ void -GNUNET_ABE_cpabe_delete_key(struct GNUNET_ABE_AbeKey *key, - int delete_pub) +GNUNET_ABE_cpabe_delete_key (struct GNUNET_ABE_AbeKey *key, + int delete_pub) { - //Memory management in gabe is buggy - gabe_prv_free(key->prv); + // Memory management in gabe is buggy + gabe_prv_free (key->prv); if (GNUNET_YES == delete_pub) - gabe_pub_free(key->pub); - GNUNET_free(key); + gabe_pub_free (key->pub); + GNUNET_free (key); } static ssize_t -write_cpabe(void **result, - uint32_t file_len, - char* cph_buf, - int cph_buf_len, - char* aes_buf, - int aes_buf_len) +write_cpabe (void **result, + uint32_t file_len, + char*cph_buf, + int cph_buf_len, + char*aes_buf, + int aes_buf_len) { char *ptr; uint32_t *len; - *result = GNUNET_malloc(12 + cph_buf_len + aes_buf_len); + *result = GNUNET_malloc (12 + cph_buf_len + aes_buf_len); ptr = *result; - len = (uint32_t*)ptr; - *len = htonl(file_len); + len = (uint32_t*) ptr; + *len = htonl (file_len); ptr += 4; - len = (uint32_t*)ptr; - *len = htonl(aes_buf_len); + len = (uint32_t*) ptr; + *len = htonl (aes_buf_len); ptr += 4; - GNUNET_memcpy(ptr, aes_buf, aes_buf_len); + GNUNET_memcpy (ptr, aes_buf, aes_buf_len); ptr += aes_buf_len; - len = (uint32_t*)ptr; - *len = htonl(cph_buf_len); + len = (uint32_t*) ptr; + *len = htonl (cph_buf_len); ptr += 4; - GNUNET_memcpy(ptr, cph_buf, cph_buf_len); + GNUNET_memcpy (ptr, cph_buf, cph_buf_len); return 12 + cph_buf_len + aes_buf_len; } static ssize_t -read_cpabe(const void *data, - char** cph_buf, - int *cph_buf_len, - char** aes_buf, - int *aes_buf_len) +read_cpabe (const void *data, + char**cph_buf, + int *cph_buf_len, + char**aes_buf, + int *aes_buf_len) { int buf_len; char *ptr; uint32_t *len; - ptr = (char*)data; - len = (uint32_t*)ptr; - buf_len = ntohl(*len); + ptr = (char*) data; + len = (uint32_t*) ptr; + buf_len = ntohl (*len); ptr += 4; - len = (uint32_t*)ptr; - *aes_buf_len = ntohl(*len); + len = (uint32_t*) ptr; + *aes_buf_len = ntohl (*len); ptr += 4; - *aes_buf = GNUNET_malloc(*aes_buf_len); - GNUNET_memcpy(*aes_buf, ptr, *aes_buf_len); + *aes_buf = GNUNET_malloc (*aes_buf_len); + GNUNET_memcpy (*aes_buf, ptr, *aes_buf_len); ptr += *aes_buf_len; - len = (uint32_t*)ptr; - *cph_buf_len = ntohl(*len); + len = (uint32_t*) ptr; + *cph_buf_len = ntohl (*len); ptr += 4; - *cph_buf = GNUNET_malloc(*cph_buf_len); - GNUNET_memcpy(*cph_buf, ptr, *cph_buf_len); + *cph_buf = GNUNET_malloc (*cph_buf_len); + GNUNET_memcpy (*cph_buf, ptr, *cph_buf_len); return buf_len; } @@ -294,34 +297,35 @@ read_cpabe(const void *data, * @return the size of the encrypted block, -1 for errors */ ssize_t -GNUNET_ABE_cpabe_encrypt(const void *block, - size_t size, - const char *policy, - const struct GNUNET_ABE_AbeMasterKey *key, - void **result) +GNUNET_ABE_cpabe_encrypt (const void *block, + size_t size, + const char *policy, + const struct GNUNET_ABE_AbeMasterKey *key, + void **result) { - gabe_cph_t* cph; - char* plt; - char* cph_buf; - char* aes_buf; + gabe_cph_t*cph; + char*plt; + char*cph_buf; + char*aes_buf; element_t m; int cph_buf_len; int aes_buf_len; ssize_t result_len; - if (!(cph = gabe_enc(key->pub, m, (char*)policy))) + if (! (cph = gabe_enc (key->pub, m, (char*) policy))) return GNUNET_SYSERR; - cph_buf_len = gabe_cph_serialize(cph, - &cph_buf); - gabe_cph_free(cph); - GNUNET_free(cph); - plt = GNUNET_memdup(block, size); - aes_buf_len = aes_128_cbc_encrypt(plt, size, m, &aes_buf); - GNUNET_free(plt); - element_clear(m); - result_len = write_cpabe(result, size, cph_buf, cph_buf_len, aes_buf, aes_buf_len); - GNUNET_free(cph_buf); - GNUNET_free(aes_buf); + cph_buf_len = gabe_cph_serialize (cph, + &cph_buf); + gabe_cph_free (cph); + GNUNET_free (cph); + plt = GNUNET_memdup (block, size); + aes_buf_len = aes_128_cbc_encrypt (plt, size, m, &aes_buf); + GNUNET_free (plt); + element_clear (m); + result_len = write_cpabe (result, size, cph_buf, cph_buf_len, aes_buf, + aes_buf_len); + GNUNET_free (cph_buf); + GNUNET_free (aes_buf); return result_len; } @@ -336,41 +340,41 @@ GNUNET_ABE_cpabe_encrypt(const void *block, * @return the size of the encrypted block, -1 for errors */ ssize_t -GNUNET_ABE_cpabe_decrypt(const void *block, - size_t size, - const struct GNUNET_ABE_AbeKey *key, - void **result) +GNUNET_ABE_cpabe_decrypt (const void *block, + size_t size, + const struct GNUNET_ABE_AbeKey *key, + void **result) { - char* aes_buf; - char* cph_buf; - gabe_cph_t* cph; + char*aes_buf; + char*cph_buf; + gabe_cph_t*cph; element_t m; int cph_buf_size; int aes_buf_size; int plt_len; - read_cpabe(block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size); - cph = gabe_cph_unserialize(key->pub, cph_buf, cph_buf_size); - if (!gabe_dec(key->pub, key->prv, cph, m)) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%s\n", gabe_error()); - GNUNET_free(aes_buf); - GNUNET_free(cph_buf); - gabe_cph_free(cph); - GNUNET_free(cph); - element_clear(m); - return GNUNET_SYSERR; - } - gabe_cph_free(cph); - GNUNET_free(cph); - plt_len = aes_128_cbc_decrypt(aes_buf, aes_buf_size, m, (char**)result); - GNUNET_free(cph_buf); - GNUNET_free(aes_buf); - element_clear(m); - //freeing is buggy in gabe - //gabe_prv_free (prv); - //gabe_pub_free (pub); + read_cpabe (block, &cph_buf, &cph_buf_size, &aes_buf, &aes_buf_size); + cph = gabe_cph_unserialize (key->pub, cph_buf, cph_buf_size); + if (! gabe_dec (key->pub, key->prv, cph, m)) + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s\n", gabe_error ()); + GNUNET_free (aes_buf); + GNUNET_free (cph_buf); + gabe_cph_free (cph); + GNUNET_free (cph); + element_clear (m); + return GNUNET_SYSERR; + } + gabe_cph_free (cph); + GNUNET_free (cph); + plt_len = aes_128_cbc_decrypt (aes_buf, aes_buf_size, m, (char**) result); + GNUNET_free (cph_buf); + GNUNET_free (aes_buf); + element_clear (m); + // freeing is buggy in gabe + // gabe_prv_free (prv); + // gabe_pub_free (pub); return plt_len; } @@ -383,8 +387,8 @@ GNUNET_ABE_cpabe_decrypt(const void *block, * @return the size of the encrypted block, -1 for errors */ ssize_t -GNUNET_ABE_cpabe_serialize_key(const struct GNUNET_ABE_AbeKey *key, - void **result) +GNUNET_ABE_cpabe_serialize_key (const struct GNUNET_ABE_AbeKey *key, + void **result) { ssize_t len; char *pub; @@ -392,14 +396,14 @@ GNUNET_ABE_cpabe_serialize_key(const struct GNUNET_ABE_AbeKey *key, int pub_len; int prv_len; - pub_len = gabe_pub_serialize(key->pub, &pub); - prv_len = gabe_prv_serialize(key->prv, &prv); + pub_len = gabe_pub_serialize (key->pub, &pub); + prv_len = gabe_prv_serialize (key->prv, &prv); len = pub_len + prv_len + 12; - write_cpabe(result, len, pub, pub_len, prv, prv_len); + write_cpabe (result, len, pub, pub_len, prv, prv_len); - GNUNET_free(pub); - GNUNET_free(prv); + GNUNET_free (pub); + GNUNET_free (prv); return len; } @@ -413,8 +417,8 @@ GNUNET_ABE_cpabe_serialize_key(const struct GNUNET_ABE_AbeKey *key, * @return the ABE key. NULL of unsuccessful */ struct GNUNET_ABE_AbeKey* -GNUNET_ABE_cpabe_deserialize_key(const void *data, - size_t len) +GNUNET_ABE_cpabe_deserialize_key (const void *data, + size_t len) { struct GNUNET_ABE_AbeKey *key; char *pub; @@ -422,17 +426,17 @@ GNUNET_ABE_cpabe_deserialize_key(const void *data, int prv_len; int pub_len; - key = GNUNET_new(struct GNUNET_ABE_AbeKey); - read_cpabe(data, - &pub, - &pub_len, - &prv, - &prv_len); - key->pub = gabe_pub_unserialize(pub, pub_len); - key->prv = gabe_prv_unserialize(key->pub, prv, prv_len); - - GNUNET_free(pub); - GNUNET_free(prv); + key = GNUNET_new (struct GNUNET_ABE_AbeKey); + read_cpabe (data, + &pub, + &pub_len, + &prv, + &prv_len); + key->pub = gabe_pub_unserialize (pub, pub_len); + key->prv = gabe_prv_unserialize (key->pub, prv, prv_len); + + GNUNET_free (pub); + GNUNET_free (prv); return key; } @@ -445,8 +449,9 @@ GNUNET_ABE_cpabe_deserialize_key(const void *data, * @return the size of the encrypted block, -1 for errors */ ssize_t -GNUNET_ABE_cpabe_serialize_master_key(const struct GNUNET_ABE_AbeMasterKey *key, - void **result) +GNUNET_ABE_cpabe_serialize_master_key (const struct + GNUNET_ABE_AbeMasterKey *key, + void **result) { ssize_t len; char *pub; @@ -454,14 +459,14 @@ GNUNET_ABE_cpabe_serialize_master_key(const struct GNUNET_ABE_AbeMasterKey *key, int pub_len; int msk_len; - pub_len = gabe_pub_serialize(key->pub, &pub); - msk_len = gabe_msk_serialize(key->msk, &msk); + pub_len = gabe_pub_serialize (key->pub, &pub); + msk_len = gabe_msk_serialize (key->msk, &msk); len = pub_len + msk_len + 12; - write_cpabe(result, len, pub, pub_len, msk, msk_len); + write_cpabe (result, len, pub, pub_len, msk, msk_len); - GNUNET_free(pub); - GNUNET_free(msk); + GNUNET_free (pub); + GNUNET_free (msk); return len; } @@ -475,8 +480,8 @@ GNUNET_ABE_cpabe_serialize_master_key(const struct GNUNET_ABE_AbeMasterKey *key, * @return the ABE key. NULL of unsuccessful */ struct GNUNET_ABE_AbeMasterKey* -GNUNET_ABE_cpabe_deserialize_master_key(const void *data, - size_t len) +GNUNET_ABE_cpabe_deserialize_master_key (const void *data, + size_t len) { struct GNUNET_ABE_AbeMasterKey *key; char *msk; @@ -484,17 +489,17 @@ GNUNET_ABE_cpabe_deserialize_master_key(const void *data, int msk_len; int pub_len; - key = GNUNET_new(struct GNUNET_ABE_AbeMasterKey); - read_cpabe(data, - &pub, - &pub_len, - &msk, - &msk_len); - key->pub = gabe_pub_unserialize(pub, pub_len); - key->msk = gabe_msk_unserialize(key->pub, msk, msk_len); - - GNUNET_free(pub); - GNUNET_free(msk); + key = GNUNET_new (struct GNUNET_ABE_AbeMasterKey); + read_cpabe (data, + &pub, + &pub_len, + &msk, + &msk_len); + key->pub = gabe_pub_unserialize (pub, pub_len); + key->msk = gabe_msk_unserialize (key->pub, msk, msk_len); + + GNUNET_free (pub); + GNUNET_free (msk); return key; } diff --git a/src/abe/test_cpabe.c b/src/abe/test_cpabe.c index 84b45fc8a..c1db72f96 100644 --- a/src/abe/test_cpabe.c +++ b/src/abe/test_cpabe.c @@ -30,7 +30,7 @@ #define TESTSTRING "Hello World!" static int -testAbecipher() +testAbecipher () { struct GNUNET_ABE_AbeMasterKey *msk; struct GNUNET_ABE_AbeKey *key; @@ -39,49 +39,49 @@ testAbecipher() int size; char *res; - msk = GNUNET_ABE_cpabe_create_master_key(); - size = GNUNET_ABE_cpabe_encrypt(TESTSTRING, strlen(TESTSTRING) + 1, - "testattr", //Policy - msk, - (void*)&result); - GNUNET_assert(-1 != size); - attrs = GNUNET_malloc(2 * sizeof(char*)); + msk = GNUNET_ABE_cpabe_create_master_key (); + size = GNUNET_ABE_cpabe_encrypt (TESTSTRING, strlen (TESTSTRING) + 1, + "testattr", // Policy + msk, + (void*) &result); + GNUNET_assert (-1 != size); + attrs = GNUNET_malloc (2 * sizeof(char*)); attrs[0] = "testattr"; attrs[1] = NULL; - key = GNUNET_ABE_cpabe_create_key(msk, - attrs); + key = GNUNET_ABE_cpabe_create_key (msk, + attrs); - size = GNUNET_ABE_cpabe_decrypt(result, size, - key, - (void*)&res); - if (strlen(TESTSTRING) + 1 != size) - { - printf("abeciphertest failed: decryptBlock returned %d\n", size); - return 1; - } - if (0 != strcmp(res, TESTSTRING)) - { - printf("abeciphertest failed: %s != %s\n", res, TESTSTRING); - return 1; - } + size = GNUNET_ABE_cpabe_decrypt (result, size, + key, + (void*) &res); + if (strlen (TESTSTRING) + 1 != size) + { + printf ("abeciphertest failed: decryptBlock returned %d\n", size); + return 1; + } + if (0 != strcmp (res, TESTSTRING)) + { + printf ("abeciphertest failed: %s != %s\n", res, TESTSTRING); + return 1; + } else return 0; } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { int failureCount = 0; - GNUNET_log_setup("test-crypto-abe", "WARNING", NULL); - failureCount += testAbecipher(); + GNUNET_log_setup ("test-crypto-abe", "WARNING", NULL); + failureCount += testAbecipher (); if (failureCount != 0) - { - printf("%d TESTS FAILED!\n", failureCount); - return -1; - } + { + printf ("%d TESTS FAILED!\n", failureCount); + return -1; + } return 0; } diff --git a/src/arm/arm.h b/src/arm/arm.h index bddcd7cf3..15f24b3f6 100644 --- a/src/arm/arm.h +++ b/src/arm/arm.h @@ -38,7 +38,8 @@ GNUNET_NETWORK_STRUCT_BEGIN /** * Status update from ARM to client. */ -struct GNUNET_ARM_StatusMessage { +struct GNUNET_ARM_StatusMessage +{ /** * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_STATUS. */ @@ -52,7 +53,8 @@ struct GNUNET_ARM_StatusMessage { /* followed by a 0-terminated service name */ }; -struct GNUNET_ARM_Message { +struct GNUNET_ARM_Message +{ /** * Reply to client, type is #GNUNET_MESSAGE_TYPE_ARM_RESULT or * #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT. @@ -81,7 +83,8 @@ struct GNUNET_ARM_Message { /** * Reply from ARM to client. */ -struct GNUNET_ARM_ResultMessage { +struct GNUNET_ARM_ResultMessage +{ /** * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_RESULT, with an ID. */ @@ -93,7 +96,8 @@ struct GNUNET_ARM_ResultMessage { uint32_t result; }; -struct GNUNET_ARM_ServiceInfoMessage { +struct GNUNET_ARM_ServiceInfoMessage +{ /** * String pool index for the service's name. */ @@ -137,7 +141,8 @@ struct GNUNET_ARM_ServiceInfoMessage { * '\0' terminated strings. header->size contains the * total size (including all strings). */ -struct GNUNET_ARM_ListResultMessage { +struct GNUNET_ARM_ListResultMessage +{ /** * Reply to client, of type is #GNUNET_MESSAGE_TYPE_ARM_LIST_RESULT, * with an ID. diff --git a/src/arm/arm_monitor_api.c b/src/arm/arm_monitor_api.c index 00faaaef1..2c418d0ce 100644 --- a/src/arm/arm_monitor_api.c +++ b/src/arm/arm_monitor_api.c @@ -30,14 +30,15 @@ #include "gnunet_protocols.h" #include "arm.h" -#define INIT_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 5) +#define INIT_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 5) -#define LOG(kind, ...) GNUNET_log_from(kind, "arm-monitor-api", __VA_ARGS__) +#define LOG(kind, ...) GNUNET_log_from (kind, "arm-monitor-api", __VA_ARGS__) /** * Handle for interacting with ARM. */ -struct GNUNET_ARM_MonitorHandle { +struct GNUNET_ARM_MonitorHandle +{ /** * Our control connection to the ARM service. */ @@ -77,7 +78,7 @@ struct GNUNET_ARM_MonitorHandle { * @return #GNUNET_OK on success */ static int -reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h); +reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h); /** @@ -86,14 +87,14 @@ reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h); * @param cls the `struct GNUNET_ARM_MonitorHandle` */ static void -reconnect_arm_monitor_task(void *cls) +reconnect_arm_monitor_task (void *cls) { struct GNUNET_ARM_MonitorHandle *h = cls; h->reconnect_task = NULL; - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Connecting to ARM service for monitoring after delay\n"); - GNUNET_break(GNUNET_OK == reconnect_arm_monitor(h)); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Connecting to ARM service for monitoring after delay\n"); + GNUNET_break (GNUNET_OK == reconnect_arm_monitor (h)); } @@ -104,18 +105,18 @@ reconnect_arm_monitor_task(void *cls) * @param h our handle */ static void -reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h) +reconnect_arm_monitor_later (struct GNUNET_ARM_MonitorHandle *h) { if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } - GNUNET_assert(NULL == h->reconnect_task); - h->reconnect_task = GNUNET_SCHEDULER_add_delayed(h->retry_backoff, - &reconnect_arm_monitor_task, - h); - h->retry_backoff = GNUNET_TIME_STD_BACKOFF(h->retry_backoff); + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } + GNUNET_assert (NULL == h->reconnect_task); + h->reconnect_task = GNUNET_SCHEDULER_add_delayed (h->retry_backoff, + &reconnect_arm_monitor_task, + h); + h->retry_backoff = GNUNET_TIME_STD_BACKOFF (h->retry_backoff); } @@ -127,18 +128,18 @@ reconnect_arm_monitor_later(struct GNUNET_ARM_MonitorHandle *h) * @return #GNUNET_OK if the message is well-formed */ static int -check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg) +check_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *msg) { size_t sl = - ntohs(msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage); - const char *name = (const char *)&msg[1]; + ntohs (msg->header.size) - sizeof(struct GNUNET_ARM_StatusMessage); + const char *name = (const char *) &msg[1]; - (void)cls; + (void) cls; if ((0 == sl) || ('\0' != name[sl - 1])) - { - GNUNET_break(0); - return GNUNET_SYSERR; - } + { + GNUNET_break (0); + return GNUNET_SYSERR; + } return GNUNET_OK; } @@ -150,18 +151,18 @@ check_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *msg) * @param res the message received from the arm service */ static void -handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res) +handle_monitor_notify (void *cls, const struct GNUNET_ARM_StatusMessage *res) { struct GNUNET_ARM_MonitorHandle *h = cls; enum GNUNET_ARM_ServiceMonitorStatus status; - status = (enum GNUNET_ARM_ServiceMonitorStatus)ntohl(res->status); - LOG(GNUNET_ERROR_TYPE_DEBUG, - "Received notification from ARM for service `%s' with status %d\n", - (const char *)&res[1], - (int)status); + status = (enum GNUNET_ARM_ServiceMonitorStatus) ntohl (res->status); + LOG (GNUNET_ERROR_TYPE_DEBUG, + "Received notification from ARM for service `%s' with status %d\n", + (const char *) &res[1], + (int) status); if (NULL != h->service_status) - h->service_status(h->service_status_cls, (const char *)&res[1], status); + h->service_status (h->service_status_cls, (const char *) &res[1], status); } @@ -174,12 +175,12 @@ handle_monitor_notify(void *cls, const struct GNUNET_ARM_StatusMessage *res) * @param error error code */ static void -mq_error_handler(void *cls, enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, enum GNUNET_MQ_Error error) { struct GNUNET_ARM_MonitorHandle *h = cls; - (void)error; - reconnect_arm_monitor_later(h); + (void) error; + reconnect_arm_monitor_later (h); } @@ -190,29 +191,29 @@ mq_error_handler(void *cls, enum GNUNET_MQ_Error error) * @return #GNUNET_OK on success */ static int -reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h) +reconnect_arm_monitor (struct GNUNET_ARM_MonitorHandle *h) { struct GNUNET_MQ_MessageHandler handlers[] = - { GNUNET_MQ_hd_var_size(monitor_notify, - GNUNET_MESSAGE_TYPE_ARM_STATUS, - struct GNUNET_ARM_StatusMessage, - h), - GNUNET_MQ_handler_end() }; + { GNUNET_MQ_hd_var_size (monitor_notify, + GNUNET_MESSAGE_TYPE_ARM_STATUS, + struct GNUNET_ARM_StatusMessage, + h), + GNUNET_MQ_handler_end () }; struct GNUNET_MessageHeader *msg; struct GNUNET_MQ_Envelope *env; - GNUNET_assert(NULL == h->mq); - h->mq = GNUNET_CLIENT_connect(h->cfg, "arm", handlers, &mq_error_handler, h); + GNUNET_assert (NULL == h->mq); + h->mq = GNUNET_CLIENT_connect (h->cfg, "arm", handlers, &mq_error_handler, h); if (NULL == h->mq) - { - if (NULL != h->service_status) - h->service_status(h->service_status_cls, - NULL, - GNUNET_ARM_SERVICE_STOPPED); - return GNUNET_SYSERR; - } - env = GNUNET_MQ_msg(msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); - GNUNET_MQ_send(h->mq, env); + { + if (NULL != h->service_status) + h->service_status (h->service_status_cls, + NULL, + GNUNET_ARM_SERVICE_STOPPED); + return GNUNET_SYSERR; + } + env = GNUNET_MQ_msg (msg, GNUNET_MESSAGE_TYPE_ARM_MONITOR); + GNUNET_MQ_send (h->mq, env); return GNUNET_OK; } @@ -229,21 +230,21 @@ reconnect_arm_monitor(struct GNUNET_ARM_MonitorHandle *h) * @return context to use for further ARM monitor operations, NULL on error. */ struct GNUNET_ARM_MonitorHandle * -GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, - GNUNET_ARM_ServiceMonitorCallback cont, - void *cont_cls) +GNUNET_ARM_monitor_start (const struct GNUNET_CONFIGURATION_Handle *cfg, + GNUNET_ARM_ServiceMonitorCallback cont, + void *cont_cls) { struct GNUNET_ARM_MonitorHandle *h; - h = GNUNET_new(struct GNUNET_ARM_MonitorHandle); + h = GNUNET_new (struct GNUNET_ARM_MonitorHandle); h->cfg = cfg; h->service_status = cont; h->service_status_cls = cont_cls; - if (GNUNET_OK != reconnect_arm_monitor(h)) - { - GNUNET_free(h); - return NULL; - } + if (GNUNET_OK != reconnect_arm_monitor (h)) + { + GNUNET_free (h); + return NULL; + } return h; } @@ -254,19 +255,19 @@ GNUNET_ARM_monitor_start(const struct GNUNET_CONFIGURATION_Handle *cfg, * @param h the handle that was being used */ void -GNUNET_ARM_monitor_stop(struct GNUNET_ARM_MonitorHandle *h) +GNUNET_ARM_monitor_stop (struct GNUNET_ARM_MonitorHandle *h) { if (NULL != h->mq) - { - GNUNET_MQ_destroy(h->mq); - h->mq = NULL; - } + { + GNUNET_MQ_destroy (h->mq); + h->mq = NULL; + } if (NULL != h->reconnect_task) - { - GNUNET_SCHEDULER_cancel(h->reconnect_task); - h->reconnect_task = NULL; - } - GNUNET_free(h); + { + GNUNET_SCHEDULER_cancel (h->reconnect_task); + h->reconnect_task = NULL; + } + GNUNET_free (h); } diff --git a/src/arm/mockup-service.c b/src/arm/mockup-service.c index 6134f17b3..9870afea1 100644 --- a/src/arm/mockup-service.c +++ b/src/arm/mockup-service.c @@ -33,15 +33,15 @@ static int special_ret = 0; * @param message the actual message */ static void -handle_stop(void *cls, const struct GNUNET_MessageHeader *message) +handle_stop (void *cls, const struct GNUNET_MessageHeader *message) { struct GNUNET_SERVICE_Client *client = cls; - (void)message; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Initiating shutdown as requested by client.\n")); - GNUNET_SERVICE_client_persist(client); - GNUNET_SCHEDULER_shutdown(); + (void) message; + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Initiating shutdown as requested by client.\n")); + GNUNET_SERVICE_client_persist (client); + GNUNET_SCHEDULER_shutdown (); /* ARM won't exponentially increase restart delay if we * terminate normally. This changes the return code. */ @@ -58,12 +58,12 @@ handle_stop(void *cls, const struct GNUNET_MessageHeader *message) * @return @a c */ static void * -client_connect_cb(void *cls, - struct GNUNET_SERVICE_Client *c, - struct GNUNET_MQ_Handle *mq) +client_connect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + struct GNUNET_MQ_Handle *mq) { - (void)cls; - (void)mq; + (void) cls; + (void) mq; return c; } @@ -76,23 +76,23 @@ client_connect_cb(void *cls, * @param internal_cls should be equal to @a c */ static void -client_disconnect_cb(void *cls, - struct GNUNET_SERVICE_Client *c, - void *internal_cls) +client_disconnect_cb (void *cls, + struct GNUNET_SERVICE_Client *c, + void *internal_cls) { - (void)cls; - GNUNET_assert(c == internal_cls); + (void) cls; + GNUNET_assert (c == internal_cls); } static void -run(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg, - struct GNUNET_SERVICE_Handle *service) +run (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg, + struct GNUNET_SERVICE_Handle *service) { - (void)cls; - (void)cfg; - (void)service; + (void) cls; + (void) cfg; + (void) service; /* nothing to do */ } @@ -100,23 +100,23 @@ run(void *cls, /** * Define "main" method using service macro. */ -GNUNET_SERVICE_MAIN("do-nothing", - GNUNET_SERVICE_OPTION_NONE, - &run, - &client_connect_cb, - &client_disconnect_cb, - NULL, - GNUNET_MQ_hd_fixed_size(stop, - GNUNET_MESSAGE_TYPE_ARM_STOP, - struct GNUNET_MessageHeader, - NULL), - GNUNET_MQ_handler_end()); +GNUNET_SERVICE_MAIN ("do-nothing", + GNUNET_SERVICE_OPTION_NONE, + &run, + &client_connect_cb, + &client_disconnect_cb, + NULL, + GNUNET_MQ_hd_fixed_size (stop, + GNUNET_MESSAGE_TYPE_ARM_STOP, + struct GNUNET_MessageHeader, + NULL), + GNUNET_MQ_handler_end ()); /** * MINIMIZE heap size (way below 128k) since this process doesn't need much. */ -void __attribute__ ((destructor)) GNUNET_mockup_done() +void __attribute__ ((destructor)) GNUNET_mockup_done () { - _exit(special_ret); + _exit (special_ret); } diff --git a/src/arm/test_arm_api.c b/src/arm/test_arm_api.c index 84d6f1bfd..5a06c823c 100644 --- a/src/arm/test_arm_api.c +++ b/src/arm/test_arm_api.c @@ -26,9 +26,9 @@ #include "gnunet_arm_service.h" #include "gnunet_resolver_service.h" -#define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) +#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 15) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 15) static const struct GNUNET_CONFIGURATION_Handle *cfg; @@ -42,139 +42,142 @@ static int phase = 0; static void -arm_stop_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +arm_stop_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { op = NULL; /* (6), a stop request should be sent to ARM successfully */ /* ARM should report that it is stopping */ - GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); - GNUNET_break(phase == 6); + GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); + GNUNET_break (phase == 6); phase++; - LOG("Sent 'STOP' request for arm to ARM %s\n", - (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); - GNUNET_SCHEDULER_shutdown(); + LOG ("Sent 'STOP' request for arm to ARM %s\n", + (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : + "unsuccessfully"); + GNUNET_SCHEDULER_shutdown (); } static void -resolver_stop_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +resolver_stop_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { op = NULL; /* (5), a stop request should be sent to ARM successfully. * ARM should report that resolver is stopped. */ - GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); - GNUNET_break(phase == 5); - LOG("Sent 'STOP' request for resolver to ARM %s\n", - (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); + GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); + GNUNET_break (phase == 5); + LOG ("Sent 'STOP' request for resolver to ARM %s\n", + (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : + "unsuccessfully"); phase++; - GNUNET_assert(NULL == op); - op = GNUNET_ARM_request_service_stop(arm, - "arm", - &arm_stop_cb, - NULL); + GNUNET_assert (NULL == op); + op = GNUNET_ARM_request_service_stop (arm, + "arm", + &arm_stop_cb, + NULL); } static void -dns_notify(void *cls, - const struct sockaddr *addr, - socklen_t addrlen) +dns_notify (void *cls, + const struct sockaddr *addr, + socklen_t addrlen) { if (addr == NULL) - { - /* (4), resolver should finish resolving localhost */ - GNUNET_break(phase == 4); - phase++; - LOG("Finished resolving localhost\n"); - if (ok != 0) - ok = 2; - GNUNET_assert(NULL == op); - op = GNUNET_ARM_request_service_stop(arm, - "resolver", - &resolver_stop_cb, - NULL); - return; - } + { + /* (4), resolver should finish resolving localhost */ + GNUNET_break (phase == 4); + phase++; + LOG ("Finished resolving localhost\n"); + if (ok != 0) + ok = 2; + GNUNET_assert (NULL == op); + op = GNUNET_ARM_request_service_stop (arm, + "resolver", + &resolver_stop_cb, + NULL); + return; + } /* (3), resolver should resolve localhost */ - GNUNET_break(phase == 3); - LOG("Resolved localhost\n"); + GNUNET_break (phase == 3); + LOG ("Resolved localhost\n"); phase++; - GNUNET_break(addr != NULL); + GNUNET_break (addr != NULL); ok = 0; } static void -resolver_start_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +resolver_start_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { op = NULL; /* (2), the start request for resolver should be sent successfully * ARM should report that resolver service is starting. */ - GNUNET_assert(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(phase == 2); - GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); - LOG("Sent 'START' request for resolver to ARM %s\n", - (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); + GNUNET_assert (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (phase == 2); + GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); + LOG ("Sent 'START' request for resolver to ARM %s\n", + (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : + "unsuccessfully"); phase++; - GNUNET_RESOLVER_ip_get("localhost", - AF_INET, - TIMEOUT, - &dns_notify, NULL); + GNUNET_RESOLVER_ip_get ("localhost", + AF_INET, + TIMEOUT, + &dns_notify, NULL); } static void -arm_conn(void *cls, - int connected) +arm_conn (void *cls, + int connected) { if (GNUNET_SYSERR == connected) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Fatal error initializing ARM API.\n")); - GNUNET_SCHEDULER_shutdown(); - GNUNET_assert(0); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Fatal error initializing ARM API.\n")); + GNUNET_SCHEDULER_shutdown (); + GNUNET_assert (0); + return; + } if (GNUNET_YES == connected) - { - /* (1), arm connection should be established */ - LOG("Connected to ARM\n"); - GNUNET_break(phase == 1); - phase++; - GNUNET_assert(NULL == op); - op = GNUNET_ARM_request_service_start(arm, - "resolver", - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - &resolver_start_cb, - NULL); - } + { + /* (1), arm connection should be established */ + LOG ("Connected to ARM\n"); + GNUNET_break (phase == 1); + phase++; + GNUNET_assert (NULL == op); + op = GNUNET_ARM_request_service_start (arm, + "resolver", + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + &resolver_start_cb, + NULL); + } else - { - /* (7), ARM should stop (we disconnect from it) */ - LOG("Disconnected from ARM\n"); - GNUNET_break(phase == 7); - if (phase != 7) - ok = 3; - else if (ok == 1) - ok = 0; - } + { + /* (7), ARM should stop (we disconnect from it) */ + LOG ("Disconnected from ARM\n"); + GNUNET_break (phase == 7); + if (phase != 7) + ok = 3; + else if (ok == 1) + ok = 0; + } } static void -arm_start_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +arm_start_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { op = NULL; /* (0) The request should be "sent" successfully @@ -182,55 +185,56 @@ arm_start_cb(void *cls, * by itself). * ARM API should report that ARM service is starting. */ - GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(phase == 0); - LOG("Sent 'START' request for arm to ARM %s\n", - (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); - GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); + GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (phase == 0); + LOG ("Sent 'START' request for arm to ARM %s\n", + (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : + "unsuccessfully"); + GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); phase++; } static void -do_shutdown(void *cls) +do_shutdown (void *cls) { if (NULL != op) - { - GNUNET_ARM_operation_cancel(op); - op = NULL; - } + { + GNUNET_ARM_operation_cancel (op); + op = NULL; + } if (NULL != arm) - { - GNUNET_ARM_disconnect(arm); - arm = NULL; - } + { + GNUNET_ARM_disconnect (arm); + arm = NULL; + } } static void -task(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +task (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { cfg = c; - arm = GNUNET_ARM_connect(cfg, - &arm_conn, - NULL); + arm = GNUNET_ARM_connect (cfg, + &arm_conn, + NULL); if (NULL == arm) return; - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, - NULL); - op = GNUNET_ARM_request_service_start(arm, - "arm", - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - &arm_start_cb, - NULL); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + NULL); + op = GNUNET_ARM_request_service_start (arm, + "arm", + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + &arm_start_cb, + NULL); } int -main(int argc, char *argvx[]) +main (int argc, char *argvx[]) { char *const argv[] = { "test-arm-api", @@ -241,13 +245,13 @@ main(int argc, char *argvx[]) GNUNET_GETOPT_OPTION_END }; - GNUNET_log_setup("test-arm-api", - "WARNING", - NULL); - GNUNET_assert(GNUNET_OK == - GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, - argv, "test-arm-api", "nohelp", options, - &task, NULL)); + GNUNET_log_setup ("test-arm-api", + "WARNING", + NULL); + GNUNET_assert (GNUNET_OK == + GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, + argv, "test-arm-api", "nohelp", options, + &task, NULL)); return ok; } diff --git a/src/arm/test_exponential_backoff.c b/src/arm/test_exponential_backoff.c index b13ab1cb8..5d1863f37 100644 --- a/src/arm/test_exponential_backoff.c +++ b/src/arm/test_exponential_backoff.c @@ -27,15 +27,16 @@ #include "gnunet_util_lib.h" #include "gnunet_protocols.h" -#define LOG(...) GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) +#define LOG(...) GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, __VA_ARGS__) #define LOG_BACKOFF GNUNET_NO -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) #define SERVICE_TEST_TIMEOUT GNUNET_TIME_UNIT_FOREVER_REL -#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 5) +#define FIVE_MILLISECONDS GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MILLISECONDS, 5) #define SERVICE "do-nothing" @@ -74,7 +75,8 @@ static char *killLogFileName; /** * Context for handling the shutdown of a service. */ -struct ShutdownContext { +struct ShutdownContext +{ /** * Connection to the service that is being shutdown. */ @@ -88,7 +90,7 @@ struct ShutdownContext { static void -kill_task(void *cbData); +kill_task (void *cbData); /** @@ -97,9 +99,9 @@ kill_task(void *cbData); * @param cls closure */ static void -service_shutdown_timeout(void *cls) +service_shutdown_timeout (void *cls) { - GNUNET_assert(0); + GNUNET_assert (0); } @@ -112,196 +114,197 @@ service_shutdown_timeout(void *cls) * @param error error code */ static void -mq_error_handler(void *cls, - enum GNUNET_MQ_Error error) +mq_error_handler (void *cls, + enum GNUNET_MQ_Error error) { struct ShutdownContext *shutdown_ctx = cls; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Service shutdown complete (MQ error).\n"); - GNUNET_SCHEDULER_cancel(shutdown_ctx->cancel_task); - GNUNET_MQ_destroy(shutdown_ctx->mq); - GNUNET_free(shutdown_ctx); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Service shutdown complete (MQ error).\n"); + GNUNET_SCHEDULER_cancel (shutdown_ctx->cancel_task); + GNUNET_MQ_destroy (shutdown_ctx->mq); + GNUNET_free (shutdown_ctx); } static void -kill_task(void *cbData) +kill_task (void *cbData) { struct ShutdownContext *shutdown_ctx - = GNUNET_new(struct ShutdownContext); + = GNUNET_new (struct ShutdownContext); struct GNUNET_MQ_Envelope *env; struct GNUNET_MessageHeader *msg; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_handler_end() + GNUNET_MQ_handler_end () }; kt = NULL; if (trialCount == 13) - { - LOG("Saw enough kills, asking ARM to stop mock service for good\n"); - GNUNET_ARM_request_service_stop(arm, - SERVICE, - NULL, - NULL); - ok = 0; - trialCount++; - GNUNET_free(shutdown_ctx); - return; - } - shutdown_ctx->mq = GNUNET_CLIENT_connect(cfg, - SERVICE, - handlers, - &mq_error_handler, - shutdown_ctx); - GNUNET_assert(NULL != shutdown_ctx->mq); + { + LOG ("Saw enough kills, asking ARM to stop mock service for good\n"); + GNUNET_ARM_request_service_stop (arm, + SERVICE, + NULL, + NULL); + ok = 0; + trialCount++; + GNUNET_free (shutdown_ctx); + return; + } + shutdown_ctx->mq = GNUNET_CLIENT_connect (cfg, + SERVICE, + handlers, + &mq_error_handler, + shutdown_ctx); + GNUNET_assert (NULL != shutdown_ctx->mq); trialCount++; - LOG("Sending a shutdown request to the mock service\n"); - env = GNUNET_MQ_msg(msg, - GNUNET_MESSAGE_TYPE_ARM_STOP); /* FIXME: abuse of message type */ - GNUNET_MQ_send(shutdown_ctx->mq, - env); + LOG ("Sending a shutdown request to the mock service\n"); + env = GNUNET_MQ_msg (msg, + GNUNET_MESSAGE_TYPE_ARM_STOP); /* FIXME: abuse of message type */ + GNUNET_MQ_send (shutdown_ctx->mq, + env); shutdown_ctx->cancel_task - = GNUNET_SCHEDULER_add_delayed(TIMEOUT, - &service_shutdown_timeout, - shutdown_ctx); + = GNUNET_SCHEDULER_add_delayed (TIMEOUT, + &service_shutdown_timeout, + shutdown_ctx); } static void -trigger_disconnect(void *cls) +trigger_disconnect (void *cls) { - GNUNET_ARM_disconnect(arm); - GNUNET_ARM_monitor_stop(mon); + GNUNET_ARM_disconnect (arm); + GNUNET_ARM_monitor_stop (mon); if (NULL != kt) - { - GNUNET_SCHEDULER_cancel(kt); - kt = NULL; - } + { + GNUNET_SCHEDULER_cancel (kt); + kt = NULL; + } } static void -arm_stop_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +arm_stop_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { - GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); - LOG("ARM service stopped\n"); - GNUNET_SCHEDULER_shutdown(); + GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); + LOG ("ARM service stopped\n"); + GNUNET_SCHEDULER_shutdown (); } static void -srv_status(void *cls, - const char *service, - enum GNUNET_ARM_ServiceMonitorStatus status) +srv_status (void *cls, + const char *service, + enum GNUNET_ARM_ServiceMonitorStatus status) { if (status == GNUNET_ARM_SERVICE_MONITORING_STARTED) - { - LOG("ARM monitor started, starting mock service\n"); - phase++; - GNUNET_ARM_request_service_start(arm, - SERVICE, - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - NULL, - NULL); - return; - } - if (0 != strcasecmp(service, SERVICE)) + { + LOG ("ARM monitor started, starting mock service\n"); + phase++; + GNUNET_ARM_request_service_start (arm, + SERVICE, + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + NULL, + NULL); + return; + } + if (0 != strcasecmp (service, SERVICE)) return; /* not what we care about */ if (phase == 1) + { + GNUNET_break (status == GNUNET_ARM_SERVICE_STARTING); + GNUNET_break (phase == 1); + LOG ("do-nothing is starting\n"); + phase++; + ok = 1; + GNUNET_assert (NULL == kt); + startedWaitingAt = GNUNET_TIME_absolute_get (); + kt = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &kill_task, + NULL); + } + else if (phase == 2) + { + /* We passively monitor ARM for status updates. ARM should tell us + * when do-nothing dies (no need to run a service upness test ourselves). + */ + if (status == GNUNET_ARM_SERVICE_STARTING) { - GNUNET_break(status == GNUNET_ARM_SERVICE_STARTING); - GNUNET_break(phase == 1); - LOG("do-nothing is starting\n"); - phase++; - ok = 1; - GNUNET_assert(NULL == kt); - startedWaitingAt = GNUNET_TIME_absolute_get(); - kt = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &kill_task, - NULL); + waitedFor = GNUNET_TIME_absolute_get_duration (startedWaitingAt); + LOG ("Waited for: %s\n", + GNUNET_STRINGS_relative_time_to_string (waitedFor, + GNUNET_YES)); + + LOG ("do-nothing is starting, killing it...\n"); + GNUNET_assert (NULL == kt); + kt = GNUNET_SCHEDULER_add_now (&kill_task, &ok); } - else if (phase == 2) + else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) { - /* We passively monitor ARM for status updates. ARM should tell us - * when do-nothing dies (no need to run a service upness test ourselves). - */ - if (status == GNUNET_ARM_SERVICE_STARTING) - { - waitedFor = GNUNET_TIME_absolute_get_duration(startedWaitingAt); - LOG("Waited for: %s\n", - GNUNET_STRINGS_relative_time_to_string(waitedFor, - GNUNET_YES)); - - LOG("do-nothing is starting, killing it...\n"); - GNUNET_assert(NULL == kt); - kt = GNUNET_SCHEDULER_add_now(&kill_task, &ok); - } - else if ((status == GNUNET_ARM_SERVICE_STOPPED) && (trialCount == 14)) - { - phase++; - LOG("do-nothing stopped working %u times, we are done here\n", - (unsigned int)trialCount); - GNUNET_ARM_request_service_stop(arm, - "arm", - &arm_stop_cb, - NULL); - } + phase++; + LOG ("do-nothing stopped working %u times, we are done here\n", + (unsigned int) trialCount); + GNUNET_ARM_request_service_stop (arm, + "arm", + &arm_stop_cb, + NULL); } + } } static void -arm_start_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +arm_start_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { - GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); - GNUNET_break(phase == 0); - LOG("Sent 'START' request for arm to ARM %s\n", - (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : "unsuccessfully"); + GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); + GNUNET_break (phase == 0); + LOG ("Sent 'START' request for arm to ARM %s\n", + (status == GNUNET_ARM_REQUEST_SENT_OK) ? "successfully" : + "unsuccessfully"); } static void -task(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +task (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { cfg = c; - arm = GNUNET_ARM_connect(cfg, NULL, NULL); + arm = GNUNET_ARM_connect (cfg, NULL, NULL); if (NULL == arm) - { - GNUNET_break(0); - return; - } - mon = GNUNET_ARM_monitor_start(cfg, - &srv_status, - NULL); + { + GNUNET_break (0); + return; + } + mon = GNUNET_ARM_monitor_start (cfg, + &srv_status, + NULL); if (NULL == mon) - { - GNUNET_break(0); - GNUNET_ARM_disconnect(arm); - arm = NULL; - return; - } - GNUNET_ARM_request_service_start(arm, - "arm", - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - &arm_start_cb, - NULL); - GNUNET_SCHEDULER_add_shutdown(&trigger_disconnect, - NULL); + { + GNUNET_break (0); + GNUNET_ARM_disconnect (arm); + arm = NULL; + return; + } + GNUNET_ARM_request_service_start (arm, + "arm", + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + &arm_start_cb, + NULL); + GNUNET_SCHEDULER_add_shutdown (&trigger_disconnect, + NULL); } static int -check() +check () { char *const argv[] = { "test-exponential-backoff", @@ -313,14 +316,14 @@ check() }; /* Running ARM and running the do_nothing task */ - GNUNET_assert(GNUNET_OK == - GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, - argv, - "test-exponential-backoff", - "nohelp", - options, - &task, - NULL)); + GNUNET_assert (GNUNET_OK == + GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, + argv, + "test-exponential-backoff", + "nohelp", + options, + &task, + NULL)); return ok; } @@ -334,78 +337,78 @@ check() static int -init() +init () { struct GNUNET_CONFIGURATION_Handle *cfg; char pwd[PATH_MAX]; char *binary; - cfg = GNUNET_CONFIGURATION_create(); - if (GNUNET_OK != GNUNET_CONFIGURATION_parse(cfg, - "test_arm_api_data.conf")) - { - GNUNET_CONFIGURATION_destroy(cfg); - return GNUNET_SYSERR; - } - if (NULL == getcwd(pwd, PATH_MAX)) + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_OK != GNUNET_CONFIGURATION_parse (cfg, + "test_arm_api_data.conf")) + { + GNUNET_CONFIGURATION_destroy (cfg); return GNUNET_SYSERR; - GNUNET_assert(0 < GNUNET_asprintf(&binary, - "%s/%s", - pwd, - BINARY)); - GNUNET_CONFIGURATION_set_value_string(cfg, - SERVICE, - "BINARY", - binary); - GNUNET_free(binary); - if (GNUNET_OK != GNUNET_CONFIGURATION_write(cfg, - CFGFILENAME)) - { - GNUNET_CONFIGURATION_destroy(cfg); - return GNUNET_SYSERR; - } - GNUNET_CONFIGURATION_destroy(cfg); + } + if (NULL == getcwd (pwd, PATH_MAX)) + return GNUNET_SYSERR; + GNUNET_assert (0 < GNUNET_asprintf (&binary, + "%s/%s", + pwd, + BINARY)); + GNUNET_CONFIGURATION_set_value_string (cfg, + SERVICE, + "BINARY", + binary); + GNUNET_free (binary); + if (GNUNET_OK != GNUNET_CONFIGURATION_write (cfg, + CFGFILENAME)) + { + GNUNET_CONFIGURATION_destroy (cfg); + return GNUNET_SYSERR; + } + GNUNET_CONFIGURATION_destroy (cfg); #if LOG_BACKOFF - killLogFileName = GNUNET_DISK_mktemp("exponential-backoff-waiting.log"); - if (NULL == (killLogFilePtr = fopen(killLogFileName, - "w"))) - { - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_WARNING, - "fopen", - killLogFileName); - GNUNET_free(killLogFileName); - return GNUNET_SYSERR; - } + killLogFileName = GNUNET_DISK_mktemp ("exponential-backoff-waiting.log"); + if (NULL == (killLogFilePtr = fopen (killLogFileName, + "w"))) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING, + "fopen", + killLogFileName); + GNUNET_free (killLogFileName); + return GNUNET_SYSERR; + } #endif return GNUNET_OK; } static void -houseKeep() +houseKeep () { #if LOG_BACKOFF - GNUNET_assert(0 == fclose(killLogFilePtr)); - GNUNET_free(killLogFileName); + GNUNET_assert (0 == fclose (killLogFilePtr)); + GNUNET_free (killLogFileName); #endif - (void)unlink(CFGFILENAME); + (void) unlink (CFGFILENAME); } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { int ret; - GNUNET_log_setup("test-exponential-backoff", - "WARNING", - NULL); + GNUNET_log_setup ("test-exponential-backoff", + "WARNING", + NULL); - if (GNUNET_OK != init()) + if (GNUNET_OK != init ()) return 1; - ret = check(); - houseKeep(); + ret = check (); + houseKeep (); return ret; } diff --git a/src/arm/test_gnunet_service_arm.c b/src/arm/test_gnunet_service_arm.c index cb2c14438..45053a41d 100644 --- a/src/arm/test_gnunet_service_arm.c +++ b/src/arm/test_gnunet_service_arm.c @@ -34,9 +34,10 @@ * (by checking if running before starting, so really this time is always waited on * startup (annoying)). */ -#define START_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 50) +#define START_TIMEOUT GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MILLISECONDS, 50) -#define TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, 10) static int ret = 1; @@ -51,141 +52,141 @@ static const char hostname[] = "www.gnu.org"; /* any domain should do */ static void -trigger_disconnect(void *cls) +trigger_disconnect (void *cls) { - GNUNET_ARM_disconnect(arm); + GNUNET_ARM_disconnect (arm); arm = NULL; } static void -arm_stop_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +arm_stop_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { - GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(result == GNUNET_ARM_RESULT_STOPPED); + GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (result == GNUNET_ARM_RESULT_STOPPED); if (result != GNUNET_ARM_RESULT_STOPPED) - { - GNUNET_break(0); - ret = 4; - } - GNUNET_SCHEDULER_add_now(&trigger_disconnect, NULL); + { + GNUNET_break (0); + ret = 4; + } + GNUNET_SCHEDULER_add_now (&trigger_disconnect, NULL); } static void -service_list(void *cls, - enum GNUNET_ARM_RequestStatus rs, - unsigned int count, - const struct GNUNET_ARM_ServiceInfo *list) +service_list (void *cls, + enum GNUNET_ARM_RequestStatus rs, + unsigned int count, + const struct GNUNET_ARM_ServiceInfo *list) { unsigned int i; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%u services are are currently running\n", - count); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%u services are are currently running\n", + count); if (GNUNET_ARM_REQUEST_SENT_OK != rs) goto stop_arm; for (i = 0; i < count; i++) + { + if ((0 == strcasecmp (list[i].name, "resolver")) && + (0 == strcasecmp (list[i].binary, "gnunet-service-resolver"))) { - if ((0 == strcasecmp(list[i].name, "resolver")) && - (0 == strcasecmp(list[i].binary, "gnunet-service-resolver"))) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Got service list, now stopping arm\n"); - ret = 0; - } + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Got service list, now stopping arm\n"); + ret = 0; } + } stop_arm: - GNUNET_ARM_request_service_stop(arm, - "arm", - &arm_stop_cb, - NULL); + GNUNET_ARM_request_service_stop (arm, + "arm", + &arm_stop_cb, + NULL); } static void -hostname_resolve_cb(void *cls, - const struct sockaddr *addr, - socklen_t addrlen) +hostname_resolve_cb (void *cls, + const struct sockaddr *addr, + socklen_t addrlen) { if ((0 == ret) || (4 == ret) || (1 == resolved_ok)) return; if (NULL == addr) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to resolve hostname!\n"); - GNUNET_break(0); - ret = 3; - GNUNET_ARM_request_service_stop(arm, - "arm", - &arm_stop_cb, - NULL); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to resolve hostname!\n"); + GNUNET_break (0); + ret = 3; + GNUNET_ARM_request_service_stop (arm, + "arm", + &arm_stop_cb, + NULL); + return; + } if (0 == asked_for_a_list) - { - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Resolved hostname, now checking the service list\n"); - GNUNET_ARM_request_service_list(arm, - &service_list, - NULL); - asked_for_a_list = 1; - resolved_ok = 1; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Resolved hostname, now checking the service list\n"); + GNUNET_ARM_request_service_list (arm, + &service_list, + NULL); + asked_for_a_list = 1; + resolved_ok = 1; + } } static void -arm_start_cb(void *cls, - enum GNUNET_ARM_RequestStatus status, - enum GNUNET_ARM_Result result) +arm_start_cb (void *cls, + enum GNUNET_ARM_RequestStatus status, + enum GNUNET_ARM_Result result) { - GNUNET_break(status == GNUNET_ARM_REQUEST_SENT_OK); - GNUNET_break(result == GNUNET_ARM_RESULT_STARTING); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Trying to resolve a hostname via the resolver service!\n"); + GNUNET_break (status == GNUNET_ARM_REQUEST_SENT_OK); + GNUNET_break (result == GNUNET_ARM_RESULT_STARTING); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Trying to resolve a hostname via the resolver service!\n"); /* connect to the resolver service */ if (NULL == - GNUNET_RESOLVER_ip_get(hostname, - AF_UNSPEC, - TIMEOUT, - &hostname_resolve_cb, - NULL)) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Unable initiate connection to resolver service\n"); - GNUNET_break(0); - ret = 2; - GNUNET_ARM_request_service_stop(arm, - "arm", - &arm_stop_cb, - NULL); - } + GNUNET_RESOLVER_ip_get (hostname, + AF_UNSPEC, + TIMEOUT, + &hostname_resolve_cb, + NULL)) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Unable initiate connection to resolver service\n"); + GNUNET_break (0); + ret = 2; + GNUNET_ARM_request_service_stop (arm, + "arm", + &arm_stop_cb, + NULL); + } } static void -run(void *cls, - char *const *args, - const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *c) +run (void *cls, + char *const *args, + const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *c) { - arm = GNUNET_ARM_connect(c, - NULL, - NULL); - GNUNET_ARM_request_service_start(arm, - "arm", - GNUNET_OS_INHERIT_STD_OUT_AND_ERR, - &arm_start_cb, - NULL); + arm = GNUNET_ARM_connect (c, + NULL, + NULL); + GNUNET_ARM_request_service_start (arm, + "arm", + GNUNET_OS_INHERIT_STD_OUT_AND_ERR, + &arm_start_cb, + NULL); } int -main(int argc, char *av[]) +main (int argc, char *av[]) { static char *const argv[] = { "test-gnunet-service-arm", @@ -203,62 +204,62 @@ main(int argc, char *av[]) struct addrinfo *ai; int ret; - if (0 != (ret = getaddrinfo(hostname, NULL, NULL, &ai))) - { - fprintf(stderr, - "Failed to resolve `%s', testcase not run.\n", - hostname); - return 77; - } - freeaddrinfo(ai); + if (0 != (ret = getaddrinfo (hostname, NULL, NULL, &ai))) + { + fprintf (stderr, + "Failed to resolve `%s', testcase not run.\n", + hostname); + return 77; + } + freeaddrinfo (ai); } #elif HAVE_GETHOSTBYNAME2 { struct hostent *host; - host = gethostbyname2(hostname, AF_INET); + host = gethostbyname2 (hostname, AF_INET); if (NULL == host) - host = gethostbyname2(hostname, AF_INET6); + host = gethostbyname2 (hostname, AF_INET6); if (NULL == host) - { - fprintf(stderr, - "Failed to resolve `%s', testcase not run.\n", - hostname); - return 77; - } + { + fprintf (stderr, + "Failed to resolve `%s', testcase not run.\n", + hostname); + return 77; + } } #elif HAVE_GETHOSTBYNAME { struct hostent *host; - host = gethostbyname(hostname); + host = gethostbyname (hostname); if (NULL == host) - { - fprintf(stderr, - "Failed to resolve `%s', testcase not run.\n", - hostname); - return 77; - } + { + fprintf (stderr, + "Failed to resolve `%s', testcase not run.\n", + hostname); + return 77; + } } #else - fprintf(stderr, - "libc fails to have resolver function, testcase not run.\n"); + fprintf (stderr, + "libc fails to have resolver function, testcase not run.\n"); return 77; #endif - GNUNET_log_setup("test-gnunet-service-arm", - "WARNING", - NULL); - GNUNET_break(GNUNET_OK == - GNUNET_PROGRAM_run((sizeof(argv) / sizeof(char *)) - 1, - argv, "test-gnunet-service-arm", - "nohelp", options, - &run, NULL)); + GNUNET_log_setup ("test-gnunet-service-arm", + "WARNING", + NULL); + GNUNET_break (GNUNET_OK == + GNUNET_PROGRAM_run ((sizeof(argv) / sizeof(char *)) - 1, + argv, "test-gnunet-service-arm", + "nohelp", options, + &run, NULL)); if (0 != ret) - { - fprintf(stderr, - "Test failed with error code %d\n", - ret); - } + { + fprintf (stderr, + "Test failed with error code %d\n", + ret); + } return ret; } diff --git a/src/ats-tests/ats-testing-experiment.c b/src/ats-tests/ats-testing-experiment.c index db5f411dd..676021926 100644 --- a/src/ats-tests/ats-testing-experiment.c +++ b/src/ats-tests/ats-testing-experiment.c @@ -28,35 +28,35 @@ #include "ats-testing.h" const char * -print_op(enum OperationType op) +print_op (enum OperationType op) { switch (op) - { - case START_SEND: - return "START_SEND"; + { + case START_SEND: + return "START_SEND"; - case STOP_SEND: - return "STOP_SEND"; + case STOP_SEND: + return "STOP_SEND"; - case START_PREFERENCE: - return "START_PREFERENCE"; + case START_PREFERENCE: + return "START_PREFERENCE"; - case STOP_PREFERENCE: - return "STOP_PREFERENCE"; + case STOP_PREFERENCE: + return "STOP_PREFERENCE"; - default: - break; - } + default: + break; + } return ""; } static struct Experiment * -create_experiment() +create_experiment () { struct Experiment *e; - e = GNUNET_new(struct Experiment); + e = GNUNET_new (struct Experiment); e->name = NULL; e->num_masters = 0; e->num_slaves = 0; @@ -66,7 +66,7 @@ create_experiment() } static void -free_experiment(struct Experiment *e) +free_experiment (struct Experiment *e) { struct Episode *cur; struct Episode *next; @@ -75,28 +75,28 @@ free_experiment(struct Experiment *e) next = e->start; for (cur = next; NULL != cur; cur = next) - { - next = cur->next; + { + next = cur->next; - next_o = cur->head; - for (cur_o = next_o; NULL != cur_o; cur_o = next_o) - { - next_o = cur_o->next; - GNUNET_free(cur_o); - } - GNUNET_free(cur); + next_o = cur->head; + for (cur_o = next_o; NULL != cur_o; cur_o = next_o) + { + next_o = cur_o->next; + GNUNET_free (cur_o); } + GNUNET_free (cur); + } - GNUNET_free_non_null(e->name); - GNUNET_free_non_null(e->cfg_file); - GNUNET_free(e); + GNUNET_free_non_null (e->name); + GNUNET_free_non_null (e->cfg_file); + GNUNET_free (e); } static int -load_episode(struct Experiment *e, - struct Episode *cur, - struct GNUNET_CONFIGURATION_Handle *cfg) +load_episode (struct Experiment *e, + struct Episode *cur, + struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_ATS_TEST_Operation *o; char *sec_name; @@ -106,272 +106,297 @@ load_episode(struct Experiment *e, char *pref; int op_counter = 0; - fprintf(stderr, "Parsing episode %u\n", cur->id); - GNUNET_asprintf(&sec_name, "episode-%u", cur->id); + fprintf (stderr, "Parsing episode %u\n", cur->id); + GNUNET_asprintf (&sec_name, "episode-%u", cur->id); while (1) + { + /* Load operation */ + GNUNET_asprintf (&op_name, "op-%u-operation", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + sec_name, + op_name, &op)) { - /* Load operation */ - GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, - sec_name, op_name, &op)) - { - GNUNET_free(op_name); - break; - } - o = GNUNET_new(struct GNUNET_ATS_TEST_Operation); - /* operations = set_rate, start_send, stop_send, set_preference */ - if (0 == strcmp(op, "start_send")) - { - o->type = START_SEND; - } - else if (0 == strcmp(op, "stop_send")) - { - o->type = STOP_SEND; - } - else if (0 == strcmp(op, "start_preference")) - { - o->type = START_PREFERENCE; - } - else if (0 == strcmp(op, "stop_preference")) - { - o->type = STOP_PREFERENCE; - } + GNUNET_free (op_name); + break; + } + o = GNUNET_new (struct GNUNET_ATS_TEST_Operation); + /* operations = set_rate, start_send, stop_send, set_preference */ + if (0 == strcmp (op, "start_send")) + { + o->type = START_SEND; + } + else if (0 == strcmp (op, "stop_send")) + { + o->type = STOP_SEND; + } + else if (0 == strcmp (op, "start_preference")) + { + o->type = START_PREFERENCE; + } + else if (0 == strcmp (op, "stop_preference")) + { + o->type = STOP_PREFERENCE; + } + else + { + fprintf (stderr, "Invalid operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (o); + GNUNET_free (sec_name); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get source */ + GNUNET_asprintf (&op_name, "op-%u-src", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->src_id)) + { + fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (o); + GNUNET_free (sec_name); + return GNUNET_SYSERR; + } + if (o->src_id > (e->num_masters - 1)) + { + fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", + o->src_id, op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (o); + GNUNET_free (sec_name); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get destination */ + GNUNET_asprintf (&op_name, "op-%u-dest", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->dest_id)) + { + fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (o); + GNUNET_free (sec_name); + return GNUNET_SYSERR; + } + if (o->dest_id > (e->num_slaves - 1)) + { + fprintf (stderr, + "Invalid destination %llu in operation %u `%s' in episode %u\n", + o->dest_id, op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (o); + GNUNET_free (sec_name); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + GNUNET_asprintf (&op_name, "op-%u-type", op_counter); + if ((GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string (cfg, + sec_name, + op_name, + &type)) && + (STOP_SEND != o->type) && + (STOP_PREFERENCE != o->type)) + { + /* Load arguments for set_rate, start_send, set_preference */ + if (0 == strcmp (type, "constant")) + { + o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; + } + else if (0 == strcmp (type, "linear")) + { + o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; + } + else if (0 == strcmp (type, "sinus")) + { + o->gen_type = GNUNET_ATS_TEST_TG_SINUS; + } + else if (0 == strcmp (type, "random")) + { + o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; + } else + { + fprintf (stderr, "Invalid type %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get base rate */ + GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->base_rate)) + { + fprintf (stderr, + "Missing base rate in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get max rate */ + GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->max_rate)) + { + if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || + (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || + (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) { - fprintf(stderr, "Invalid operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(o); - GNUNET_free(sec_name); + fprintf (stderr, + "Missing max rate in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free (o); + GNUNET_free (sec_name); return GNUNET_SYSERR; } - GNUNET_free(op_name); - - /* Get source */ - GNUNET_asprintf(&op_name, "op-%u-src", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, op_name, &o->src_id)) + } + GNUNET_free (op_name); + + /* Get period */ + GNUNET_asprintf (&op_name, "op-%u-period", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, + sec_name, + op_name, + &o->period)) + { + o->period = cur->duration; + } + GNUNET_free (op_name); + + if (START_PREFERENCE == o->type) + { + /* Get frequency */ + GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, + sec_name, + op_name, + &o->frequency)) { - fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(o); - GNUNET_free(sec_name); + fprintf (stderr, + "Missing frequency in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free (o); + GNUNET_free (sec_name); return GNUNET_SYSERR; } - if (o->src_id > (e->num_masters - 1)) + GNUNET_free (op_name); + + /* Get preference */ + GNUNET_asprintf (&op_name, "op-%u-pref", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + sec_name, + op_name, + &pref)) { - fprintf(stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", - o->src_id, op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(o); - GNUNET_free(sec_name); + fprintf (stderr, + "Missing preference in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free_non_null (pref); + GNUNET_free (o); + GNUNET_free (sec_name); return GNUNET_SYSERR; } - GNUNET_free(op_name); - /* Get destination */ - GNUNET_asprintf(&op_name, "op-%u-dest", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, op_name, &o->dest_id)) + if (0 == strcmp (pref, "bandwidth")) + o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH; + else if (0 == strcmp (pref, "latency")) + o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY; + else { - fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(o); - GNUNET_free(sec_name); + fprintf (stderr, + "Invalid preference in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free_non_null (pref); + GNUNET_free (o); + GNUNET_free (sec_name); return GNUNET_SYSERR; } - if (o->dest_id > (e->num_slaves - 1)) - { - fprintf(stderr, "Invalid destination %llu in operation %u `%s' in episode %u\n", - o->dest_id, op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(o); - GNUNET_free(sec_name); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - GNUNET_asprintf(&op_name, "op-%u-type", op_counter); - if ((GNUNET_SYSERR != GNUNET_CONFIGURATION_get_value_string(cfg, - sec_name, op_name, &type)) && - (STOP_SEND != o->type) && - (STOP_PREFERENCE != o->type)) - { - /* Load arguments for set_rate, start_send, set_preference */ - if (0 == strcmp(type, "constant")) - { - o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; - } - else if (0 == strcmp(type, "linear")) - { - o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; - } - else if (0 == strcmp(type, "sinus")) - { - o->gen_type = GNUNET_ATS_TEST_TG_SINUS; - } - else if (0 == strcmp(type, "random")) - { - o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; - } - else - { - fprintf(stderr, "Invalid type %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - /* Get base rate */ - GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, op_name, &o->base_rate)) - { - fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - /* Get max rate */ - GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, op_name, &o->max_rate)) - { - if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || - (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || - (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) - { - fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free(o); - GNUNET_free(sec_name); - return GNUNET_SYSERR; - } - } - GNUNET_free(op_name); - - /* Get period */ - GNUNET_asprintf(&op_name, "op-%u-period", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, - sec_name, op_name, &o->period)) - { - o->period = cur->duration; - } - GNUNET_free(op_name); - - if (START_PREFERENCE == o->type) - { - /* Get frequency */ - GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, - sec_name, op_name, &o->frequency)) - { - fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free(o); - GNUNET_free(sec_name); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - /* Get preference */ - GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, - sec_name, op_name, &pref)) - { - fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free_non_null(pref); - GNUNET_free(o); - GNUNET_free(sec_name); - return GNUNET_SYSERR; - } - - if (0 == strcmp(pref, "bandwidth")) - o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH; - else if (0 == strcmp(pref, "latency")) - o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY; - else - { - fprintf(stderr, "Invalid preference in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free_non_null(pref); - GNUNET_free(o); - GNUNET_free(sec_name); - return GNUNET_SYSERR; - } - GNUNET_free(pref); - GNUNET_free(op_name); - } - } - - /* Safety checks */ - if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || - (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) - { - if ((o->max_rate - o->base_rate) > o->base_rate) - { - /* This will cause an underflow */ - GNUNET_break(0); - } - fprintf(stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n"); - } - - if ((START_SEND == o->type) || (START_PREFERENCE == o->type)) - fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n", - op_counter, cur->id, print_op(o->type), o->src_id, - o->dest_id, (NULL != type) ? type : "", - o->base_rate, o->max_rate, - GNUNET_STRINGS_relative_time_to_string(o->period, GNUNET_YES)); - else - fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n", - op_counter, cur->id, print_op(o->type), o->src_id, o->dest_id); - - GNUNET_free_non_null(type); - GNUNET_free(op); + GNUNET_free (pref); + GNUNET_free (op_name); + } + } - GNUNET_CONTAINER_DLL_insert(cur->head, cur->tail, o); - op_counter++; + /* Safety checks */ + if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || + (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) + { + if ((o->max_rate - o->base_rate) > o->base_rate) + { + /* This will cause an underflow */ + GNUNET_break (0); + } + fprintf (stderr, + "Selected max rate and base rate cannot be used for desired traffic form!\n"); } - GNUNET_free(sec_name); + + if ((START_SEND == o->type) || (START_PREFERENCE == o->type)) + fprintf (stderr, + "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n", + op_counter, cur->id, print_op (o->type), o->src_id, + o->dest_id, (NULL != type) ? type : "", + o->base_rate, o->max_rate, + GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES)); + else + fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n", + op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id); + + GNUNET_free_non_null (type); + GNUNET_free (op); + + GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, o); + op_counter++; + } + GNUNET_free (sec_name); return GNUNET_OK; } static int -load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) +load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) { int e_counter = 0; char *sec_name; @@ -382,380 +407,407 @@ load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) e_counter = 0; last = NULL; while (1) + { + GNUNET_asprintf (&sec_name, "episode-%u", e_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, + sec_name, + "duration", + &e_duration)) { - GNUNET_asprintf(&sec_name, "episode-%u", e_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, - sec_name, "duration", &e_duration)) - { - GNUNET_free(sec_name); - break; - } - - cur = GNUNET_new(struct Episode); - cur->duration = e_duration; - cur->id = e_counter; - - if (GNUNET_OK != load_episode(e, cur, cfg)) - { - GNUNET_free(sec_name); - GNUNET_free(cur); - return GNUNET_SYSERR; - } - - fprintf(stderr, "Found episode %u with duration %s \n", - e_counter, - GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES)); + GNUNET_free (sec_name); + break; + } - /* Update experiment */ - e->num_episodes++; - e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); - /* Put in linked list */ - if (NULL == last) - e->start = cur; - else - last->next = cur; + cur = GNUNET_new (struct Episode); + cur->duration = e_duration; + cur->id = e_counter; - GNUNET_free(sec_name); - e_counter++; - last = cur; + if (GNUNET_OK != load_episode (e, cur, cfg)) + { + GNUNET_free (sec_name); + GNUNET_free (cur); + return GNUNET_SYSERR; } + + fprintf (stderr, "Found episode %u with duration %s \n", + e_counter, + GNUNET_STRINGS_relative_time_to_string (cur->duration, + GNUNET_YES)); + + /* Update experiment */ + e->num_episodes++; + e->total_duration = GNUNET_TIME_relative_add (e->total_duration, + cur->duration); + /* Put in linked list */ + if (NULL == last) + e->start = cur; + else + last->next = cur; + + GNUNET_free (sec_name); + e_counter++; + last = cur; + } return e_counter; } static void -timeout_experiment(void *cls) +timeout_experiment (void *cls) { struct Experiment *e = cls; e->experiment_timeout_task = NULL; - fprintf(stderr, "Experiment timeout!\n"); + fprintf (stderr, "Experiment timeout!\n"); if (NULL != e->episode_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->episode_timeout_task); - e->episode_timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (e->episode_timeout_task); + e->episode_timeout_task = NULL; + } - e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), - GNUNET_SYSERR); + e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time), + GNUNET_SYSERR); } static void -enforce_start_send(struct GNUNET_ATS_TEST_Operation *op) +enforce_start_send (struct GNUNET_ATS_TEST_Operation *op) { struct BenchmarkPeer *peer; struct BenchmarkPartner *partner; - peer = GNUNET_ATS_TEST_get_peer(op->src_id); + peer = GNUNET_ATS_TEST_get_peer (op->src_id); if (NULL == peer) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } - partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); + partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); if (NULL == partner) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } - fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); + fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); if (NULL != partner->tg) - { - fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", op->src_id, op->dest_id); - GNUNET_ATS_TEST_generate_traffic_stop(partner->tg); - partner->tg = NULL; - } - - partner->tg = GNUNET_ATS_TEST_generate_traffic_start(peer, partner, - op->gen_type, op->base_rate, op->max_rate, op->period, - GNUNET_TIME_UNIT_FOREVER_REL); + { + fprintf (stderr, "Stopping traffic between master %llu slave %llu\n", + op->src_id, op->dest_id); + GNUNET_ATS_TEST_generate_traffic_stop (partner->tg); + partner->tg = NULL; + } + + partner->tg = GNUNET_ATS_TEST_generate_traffic_start (peer, partner, + op->gen_type, + op->base_rate, + op->max_rate, + op->period, + GNUNET_TIME_UNIT_FOREVER_REL); } static void -enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op) +enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op) { struct BenchmarkPartner *p; - p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); + p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); if (NULL == p) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } - fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); + fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); if (NULL != p->tg) - { - fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", - op->src_id, op->dest_id); - GNUNET_ATS_TEST_generate_traffic_stop(p->tg); - p->tg = NULL; - } + { + fprintf (stderr, "Stopping traffic between master %llu slave %llu\n", + op->src_id, op->dest_id); + GNUNET_ATS_TEST_generate_traffic_stop (p->tg); + p->tg = NULL; + } } static void -enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) +enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op) { struct BenchmarkPeer *peer; struct BenchmarkPartner *partner; - peer = GNUNET_ATS_TEST_get_peer(op->src_id); + peer = GNUNET_ATS_TEST_get_peer (op->src_id); if (NULL == peer) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } - partner = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); + partner = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); if (NULL == partner) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } - fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); + fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); if (NULL != partner->pg) - { - fprintf(stderr, "Stopping traffic between master %llu slave %llu\n", - op->src_id, op->dest_id); - GNUNET_ATS_TEST_generate_preferences_stop(partner->pg); - partner->pg = NULL; - } - - partner->pg = GNUNET_ATS_TEST_generate_preferences_start(peer, partner, - op->gen_type, op->base_rate, op->max_rate, op->period, op->frequency, - op->pref_type); + { + fprintf (stderr, "Stopping traffic between master %llu slave %llu\n", + op->src_id, op->dest_id); + GNUNET_ATS_TEST_generate_preferences_stop (partner->pg); + partner->pg = NULL; + } + + partner->pg = GNUNET_ATS_TEST_generate_preferences_start (peer, partner, + op->gen_type, + op->base_rate, + op->max_rate, + op->period, + op->frequency, + op->pref_type); } static void -enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) +enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op) { struct BenchmarkPartner *p; - p = GNUNET_ATS_TEST_get_partner(op->src_id, op->dest_id); + p = GNUNET_ATS_TEST_get_partner (op->src_id, op->dest_id); if (NULL == p) - { - GNUNET_break(0); - return; - } + { + GNUNET_break (0); + return; + } - fprintf(stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); + fprintf (stderr, "Found master %llu slave %llu\n", op->src_id, op->dest_id); if (NULL != p->pg) - { - fprintf(stderr, "Stopping preference between master %llu slave %llu\n", - op->src_id, op->dest_id); - GNUNET_ATS_TEST_generate_preferences_stop(p->pg); - p->pg = NULL; - } + { + fprintf (stderr, "Stopping preference between master %llu slave %llu\n", + op->src_id, op->dest_id); + GNUNET_ATS_TEST_generate_preferences_stop (p->pg); + p->pg = NULL; + } } -static void enforce_episode(struct Episode *ep) +static void enforce_episode (struct Episode *ep) { struct GNUNET_ATS_TEST_Operation *cur; for (cur = ep->head; NULL != cur; cur = cur->next) + { + fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", + print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate); + switch (cur->type) { - fprintf(stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", - print_op(cur->type), cur->src_id, cur->dest_id, cur->base_rate); - switch (cur->type) - { - case START_SEND: - enforce_start_send(cur); - break; + case START_SEND: + enforce_start_send (cur); + break; - case STOP_SEND: - enforce_stop_send(cur); - break; + case STOP_SEND: + enforce_stop_send (cur); + break; - case START_PREFERENCE: - enforce_start_preference(cur); - break; + case START_PREFERENCE: + enforce_start_preference (cur); + break; - case STOP_PREFERENCE: - enforce_stop_preference(cur); - break; + case STOP_PREFERENCE: + enforce_stop_preference (cur); + break; - default: - break; - } + default: + break; } + } } static void -timeout_episode(void *cls) +timeout_episode (void *cls) { struct Experiment *e = cls; e->episode_timeout_task = NULL; if (NULL != e->ep_done_cb) - e->ep_done_cb(e->cur); + e->ep_done_cb (e->cur); /* Scheduling next */ e->cur = e->cur->next; if (NULL == e->cur) + { + /* done */ + fprintf (stderr, "Last episode done!\n"); + if (NULL != e->experiment_timeout_task) { - /* done */ - fprintf(stderr, "Last episode done!\n"); - if (NULL != e->experiment_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); - e->experiment_timeout_task = NULL; - } - e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK); - return; + GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); + e->experiment_timeout_task = NULL; } - - fprintf(stderr, "Running episode %u with timeout %s\n", - e->cur->id, - GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); - enforce_episode(e->cur); - - e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, - &timeout_episode, e); + e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time), + GNUNET_OK); + return; + } + + fprintf (stderr, "Running episode %u with timeout %s\n", + e->cur->id, + GNUNET_STRINGS_relative_time_to_string (e->cur->duration, + GNUNET_YES)); + enforce_episode (e->cur); + + e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, + &timeout_episode, e); } void -GNUNET_ATS_TEST_experimentation_run(struct Experiment *e, - GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, - GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) +GNUNET_ATS_TEST_experimentation_run (struct Experiment *e, + GNUNET_ATS_TESTING_EpisodeDoneCallback + ep_done_cb, + GNUNET_ATS_TESTING_ExperimentDoneCallback + e_done_cb) { - fprintf(stderr, "Running experiment `%s' with timeout %s\n", e->name, - GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); + fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name, + GNUNET_STRINGS_relative_time_to_string (e->max_duration, + GNUNET_YES)); e->e_done_cb = e_done_cb; e->ep_done_cb = ep_done_cb; - e->start_time = GNUNET_TIME_absolute_get(); + e->start_time = GNUNET_TIME_absolute_get (); /* Start total time out */ - e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration, - &timeout_experiment, e); + e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration, + &timeout_experiment, + e); /* Start */ e->cur = e->start; - fprintf(stderr, "Running episode %u with timeout %s\n", - e->cur->id, - GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); - enforce_episode(e->cur); - e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, - &timeout_episode, e); + fprintf (stderr, "Running episode %u with timeout %s\n", + e->cur->id, + GNUNET_STRINGS_relative_time_to_string (e->cur->duration, + GNUNET_YES)); + enforce_episode (e->cur); + e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, + &timeout_episode, e); } struct Experiment * -GNUNET_ATS_TEST_experimentation_load(const char *filename) +GNUNET_ATS_TEST_experimentation_load (const char *filename) { struct Experiment *e; struct GNUNET_CONFIGURATION_Handle *cfg; e = NULL; - cfg = GNUNET_CONFIGURATION_create(); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename)) - { - fprintf(stderr, "Failed to load `%s'\n", filename); - GNUNET_CONFIGURATION_destroy(cfg); - return NULL; - } - - e = create_experiment(); - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", - "name", &e->name)) - { - fprintf(stderr, "Invalid %s", "name"); - free_experiment(e); - return NULL; - } + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename)) + { + fprintf (stderr, "Failed to load `%s'\n", filename); + GNUNET_CONFIGURATION_destroy (cfg); + return NULL; + } + + e = create_experiment (); + + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment", + "name", &e->name)) + { + fprintf (stderr, "Invalid %s", "name"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment name: `%s'\n", e->name); - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", - "cfg_file", &e->cfg_file)) - { - fprintf(stderr, "Invalid %s", "cfg_file"); - free_experiment(e); - return NULL; - } + fprintf (stderr, "Experiment name: `%s'\n", e->name); + + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, + "experiment", + "cfg_file", + &e->cfg_file)) + { + fprintf (stderr, "Invalid %s", "cfg_file"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment name: `%s'\n", e->cfg_file); - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", - "masters", &e->num_masters)) - { - fprintf(stderr, "Invalid %s", "masters"); - free_experiment(e); - return NULL; - } + fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file); + + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment", + "masters", + &e->num_masters)) + { + fprintf (stderr, "Invalid %s", "masters"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment masters: `%llu'\n", - e->num_masters); - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", - "slaves", &e->num_slaves)) - { - fprintf(stderr, "Invalid %s", "slaves"); - free_experiment(e); - return NULL; - } + fprintf (stderr, "Experiment masters: `%llu'\n", + e->num_masters); + + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment", + "slaves", + &e->num_slaves)) + { + fprintf (stderr, "Invalid %s", "slaves"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment slaves: `%llu'\n", - e->num_slaves); - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", - "log_freq", &e->log_freq)) - { - fprintf(stderr, "Invalid %s", "log_freq"); - free_experiment(e); - return NULL; - } + fprintf (stderr, "Experiment slaves: `%llu'\n", + e->num_slaves); + + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment", + "log_freq", + &e->log_freq)) + { + fprintf (stderr, "Invalid %s", "log_freq"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment logging frequency: `%s'\n", - GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES)); - - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", - "max_duration", &e->max_duration)) - { - fprintf(stderr, "Invalid %s", "max_duration"); - free_experiment(e); - return NULL; - } + fprintf (stderr, "Experiment logging frequency: `%s'\n", + GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES)); + + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment", + "max_duration", + &e->max_duration)) + { + fprintf (stderr, "Invalid %s", "max_duration"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment duration: `%s'\n", - GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); + fprintf (stderr, "Experiment duration: `%s'\n", + GNUNET_STRINGS_relative_time_to_string (e->max_duration, + GNUNET_YES)); - load_episodes(e, cfg); - fprintf(stderr, "Loaded %u episodes with total duration %s\n", - e->num_episodes, - GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES)); + load_episodes (e, cfg); + fprintf (stderr, "Loaded %u episodes with total duration %s\n", + e->num_episodes, + GNUNET_STRINGS_relative_time_to_string (e->total_duration, + GNUNET_YES)); - GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_CONFIGURATION_destroy (cfg); return e; } void -GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e) +GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e) { if (NULL != e->experiment_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); - e->experiment_timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); + e->experiment_timeout_task = NULL; + } if (NULL != e->episode_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->episode_timeout_task); - e->episode_timeout_task = NULL; - } - free_experiment(e); + { + GNUNET_SCHEDULER_cancel (e->episode_timeout_task); + e->episode_timeout_task = NULL; + } + free_experiment (e); } /* end of file ats-testing-experiment.c*/ diff --git a/src/ats-tests/ats-testing-log.c b/src/ats-tests/ats-testing-log.c index a362955d2..12a08ffda 100644 --- a/src/ats-tests/ats-testing-log.c +++ b/src/ats-tests/ats-testing-log.c @@ -72,7 +72,8 @@ /** * A single logging time step for a partner */ -struct PartnerLoggingTimestep { +struct PartnerLoggingTimestep +{ /** * Peer */ @@ -142,7 +143,8 @@ struct PartnerLoggingTimestep { /** * A single logging time step for a peer */ -struct PeerLoggingTimestep { +struct PeerLoggingTimestep +{ /** * Next in DLL */ @@ -197,7 +199,8 @@ struct PeerLoggingTimestep { /** * Entry for a benchmark peer */ -struct LoggingPeer { +struct LoggingPeer +{ /** * Peer */ @@ -219,7 +222,8 @@ struct LoggingPeer { struct PeerLoggingTimestep *tail; }; -struct LoggingHandle { +struct LoggingHandle +{ /** * Logging task */ @@ -244,179 +248,205 @@ struct LoggingHandle { static void -write_throughput_gnuplot_script(char * fn, struct LoggingPeer *lp, char **fs, int slaves) +write_throughput_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, + int slaves) { struct GNUNET_DISK_FileHandle *f; - char * gfn; + char *gfn; char *data; int c_s; - GNUNET_asprintf(&gfn, "gnuplot_throughput_%s", fn); - fprintf(stderr, "Writing throughput plot for master %u and %u slaves to `%s'\n", - lp->peer->no, slaves, gfn); + GNUNET_asprintf (&gfn, "gnuplot_throughput_%s", fn); + fprintf (stderr, + "Writing throughput plot for master %u and %u slaves to `%s'\n", + lp->peer->no, slaves, gfn); - f = GNUNET_DISK_file_open(gfn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + f = GNUNET_DISK_file_open (gfn, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_EXEC + | GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (NULL == f) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); - GNUNET_free(gfn); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", + gfn); + GNUNET_free (gfn); + return; + } /* Write header */ - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE, - strlen(THROUGHPUT_TEMPLATE))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot write data to plot file `%s'\n", gfn); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, THROUGHPUT_TEMPLATE, + strlen (THROUGHPUT_TEMPLATE))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); /* Write master data */ - GNUNET_asprintf(&data, - "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \ - "'%s' using 2:%u with lines title 'Master %u receive total', \\\n", - fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, - fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); - GNUNET_free(data); + GNUNET_asprintf (&data, + "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \ + "'%s' using 2:%u with lines title 'Master %u receive total', \\\n", + fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, + fn, LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); + GNUNET_free (data); for (c_s = 0; c_s < slaves; c_s++) - { - GNUNET_asprintf(&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \ - "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n", - fs[c_s], - LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, - lp->peer->no, - lp->peer->partners[c_s].dest->no, - fs[c_s], - LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, - lp->peer->no, - lp->peer->partners[c_s].dest->no, - (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); - GNUNET_free(data); - } - - if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot close gnuplot file `%s'\n", gfn); + { + GNUNET_asprintf (&data, + "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \ + "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n", + fs[c_s], + LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_SENT, + lp->peer->no, + lp->peer->partners[c_s].dest->no, + fs[c_s], + LOG_ITEMS_TIME + LOG_ITEM_THROUGHPUT_RECV, + lp->peer->no, + lp->peer->partners[c_s].dest->no, + (c_s < lp->peer->num_partners - 1) ? ", \\" : + "\n pause -1"); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); + GNUNET_free (data); + } + + if (GNUNET_SYSERR == GNUNET_DISK_file_close (f)) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot close gnuplot file `%s'\n", gfn); else - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Data successfully written to plot file `%s'\n", gfn); - GNUNET_free(gfn); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Data successfully written to plot file `%s'\n", gfn); + GNUNET_free (gfn); } static void -write_rtt_gnuplot_script(char * fn, struct LoggingPeer *lp, char **fs, int slaves) +write_rtt_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int + slaves) { struct GNUNET_DISK_FileHandle *f; - char * gfn; + char *gfn; char *data; int c_s; - GNUNET_asprintf(&gfn, "gnuplot_rtt_%s", fn); - fprintf(stderr, "Writing rtt plot for master %u to `%s'\n", - lp->peer->no, gfn); + GNUNET_asprintf (&gfn, "gnuplot_rtt_%s", fn); + fprintf (stderr, "Writing rtt plot for master %u to `%s'\n", + lp->peer->no, gfn); - f = GNUNET_DISK_file_open(gfn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + f = GNUNET_DISK_file_open (gfn, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_EXEC + | GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (NULL == f) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); - GNUNET_free(gfn); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", + gfn); + GNUNET_free (gfn); + return; + } /* Write header */ - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, RTT_TEMPLATE, strlen ( + RTT_TEMPLATE))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); for (c_s = 0; c_s < slaves; c_s++) - { - GNUNET_asprintf(&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n", - (0 == c_s) ? "plot " : "", - fs[c_s], - LOG_ITEMS_TIME + LOG_ITEM_APP_RTT, - lp->peer->no, - lp->peer->partners[c_s].dest->no, - (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); - GNUNET_free(data); - } - - if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); + { + GNUNET_asprintf (&data, + "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n", + (0 == c_s) ? "plot " : "", + fs[c_s], + LOG_ITEMS_TIME + LOG_ITEM_APP_RTT, + lp->peer->no, + lp->peer->partners[c_s].dest->no, + (c_s < lp->peer->num_partners - 1) ? ", \\" : + "\n pause -1"); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); + GNUNET_free (data); + } + + if (GNUNET_SYSERR == GNUNET_DISK_file_close (f)) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", + gfn); else - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); - GNUNET_free(gfn); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Data successfully written to plot file `%s'\n", gfn); + GNUNET_free (gfn); } static void -write_bw_gnuplot_script(char * fn, struct LoggingPeer *lp, char **fs, int slaves) +write_bw_gnuplot_script (char *fn, struct LoggingPeer *lp, char **fs, int + slaves) { struct GNUNET_DISK_FileHandle *f; - char * gfn; + char *gfn; char *data; int c_s; - GNUNET_asprintf(&gfn, "gnuplot_bw_%s", fn); - fprintf(stderr, "Writing bandwidth plot for master %u to `%s'\n", - lp->peer->no, gfn); + GNUNET_asprintf (&gfn, "gnuplot_bw_%s", fn); + fprintf (stderr, "Writing bandwidth plot for master %u to `%s'\n", + lp->peer->no, gfn); - f = GNUNET_DISK_file_open(gfn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | - GNUNET_DISK_PERM_USER_WRITE); + f = GNUNET_DISK_file_open (gfn, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_EXEC + | GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (NULL == f) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); - GNUNET_free(gfn); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", + gfn); + GNUNET_free (gfn); + return; + } /* Write header */ - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot write data to plot file `%s'\n", gfn); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, BW_TEMPLATE, strlen ( + BW_TEMPLATE))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); for (c_s = 0; c_s < slaves; c_s++) - { - GNUNET_asprintf(&data, "%s" \ - "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \ - "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \ - "%s\n", - (0 == c_s) ? "plot " : "", - fs[c_s], - LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT, - lp->peer->no, c_s, - fs[c_s], - LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN, - lp->peer->no, c_s, - (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); - GNUNET_free(data); - } - - if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); + { + GNUNET_asprintf (&data, "%s" \ + "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \ + "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \ + "%s\n", + (0 == c_s) ? "plot " : "", + fs[c_s], + LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_OUT, + lp->peer->no, c_s, + fs[c_s], + LOG_ITEMS_TIME + LOG_ITEM_ATS_BW_IN, + lp->peer->no, c_s, + (c_s < lp->peer->num_partners - 1) ? ", \\" : + "\n pause -1"); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); + GNUNET_free (data); + } + + if (GNUNET_SYSERR == GNUNET_DISK_file_close (f)) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", + gfn); else - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); - GNUNET_free(gfn); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Data successfully written to plot file `%s'\n", gfn); + GNUNET_free (gfn); } void -GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l, - const char *experiment_name, - int plots) +GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l, + const char *experiment_name, + int plots) { struct GNUNET_DISK_FileHandle *f[l->num_slaves]; struct GNUNET_DISK_FileHandle *f_m; @@ -431,182 +461,207 @@ GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l, int c_s; - timestamp = GNUNET_TIME_absolute_get(); + timestamp = GNUNET_TIME_absolute_get (); tmp_exp_name = experiment_name; for (c_m = 0; c_m < l->num_masters; c_m++) + { + GNUNET_asprintf (&filename_master, "%s_%llu_master%u_%s", + experiment_name, timestamp.abs_value_us, c_m, l->name); + fprintf (stderr, "Writing data for master %u to file `%s'\n", + c_m, filename_master); + + f_m = GNUNET_DISK_file_open (filename_master, + GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); + if (NULL == f_m) { - GNUNET_asprintf(&filename_master, "%s_%llu_master%u_%s", - experiment_name, timestamp.abs_value_us, c_m, l->name); - fprintf(stderr, "Writing data for master %u to file `%s'\n", - c_m, filename_master); - - f_m = GNUNET_DISK_file_open(filename_master, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); - if (NULL == f_m) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_master); - GNUNET_free(filename_master); - return; - } + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", + filename_master); + GNUNET_free (filename_master); + return; + } - GNUNET_asprintf(&data, "# master %u; experiment : %s\n" - "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n", - c_m, experiment_name); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot write data to log file `%s'\n", filename_master); - GNUNET_free(data); + GNUNET_asprintf (&data, "# master %u; experiment : %s\n" + "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; \n", + c_m, experiment_name); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to log file `%s'\n", filename_master); + GNUNET_free (data); - for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++) - { - GNUNET_asprintf(&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s", - tmp_exp_name, timestamp.abs_value_us, c_m, c_s, l->name); - - fprintf(stderr, "Writing data for master %u slave %u to file `%s'\n", - c_m, c_s, filename_slaves[c_s]); - - f[c_s] = GNUNET_DISK_file_open(filename_slaves[c_s], - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); - if (NULL == f[c_s]) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", filename_slaves[c_s]); - GNUNET_free(filename_slaves[c_s]); - GNUNET_break(GNUNET_OK == GNUNET_DISK_file_close(f_m)); - GNUNET_free(filename_master); - return; - } - - /* Header */ - GNUNET_asprintf(&data, "# master %u; slave %u ; experiment : %s\n" - "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \ - "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \ - "pref bandwidth; pref delay\n", - c_m, c_s, experiment_name); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot write data to log file `%s'\n", filename_slaves[c_s]); - GNUNET_free(data); - } + for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++) + { + GNUNET_asprintf (&filename_slaves[c_s], "%s_%llu_master%u_slave_%u_%s", + tmp_exp_name, timestamp.abs_value_us, c_m, c_s, l->name); + + fprintf (stderr, "Writing data for master %u slave %u to file `%s'\n", + c_m, c_s, filename_slaves[c_s]); + + f[c_s] = GNUNET_DISK_file_open (filename_slaves[c_s], + GNUNET_DISK_OPEN_WRITE + | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); + if (NULL == f[c_s]) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open log file `%s'\n", + filename_slaves[c_s]); + GNUNET_free (filename_slaves[c_s]); + GNUNET_break (GNUNET_OK == GNUNET_DISK_file_close (f_m)); + GNUNET_free (filename_master); + return; + } + + /* Header */ + GNUNET_asprintf (&data, "# master %u; slave %u ; experiment : %s\n" + "timestamp; timestamp delta; #messages sent; #bytes sent; #throughput sent; #messages received; #bytes received; #throughput received; " \ + "rtt; bw in; bw out; ats_cost_lan; ats_cost_wlan; ats_delay; ats_distance; ats_network_type; ats_utilization_up ;ats_utilization_down;" \ + "pref bandwidth; pref delay\n", + c_m, c_s, experiment_name); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to log file `%s'\n", + filename_slaves[c_s]); + GNUNET_free (data); + } + + for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next) + { + if (l->verbose) + fprintf (stderr, + "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n", + l->lp[c_m].peer->no, + (long long unsigned int) cur_lt->timestamp.abs_value_us, + (long long unsigned int) GNUNET_TIME_absolute_get_difference ( + l->lp[c_m].start, + cur_lt + ->timestamp).rel_value_us / 1000, + cur_lt->total_messages_sent, + cur_lt->total_bytes_sent, + cur_lt->total_throughput_send, + cur_lt->total_messages_received, + cur_lt->total_bytes_received, + cur_lt->total_throughput_recv); + + /* Assembling master string */ + GNUNET_asprintf (&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n", + (long long unsigned int) cur_lt->timestamp.abs_value_us, + (long long unsigned + int) GNUNET_TIME_absolute_get_difference ( + l->lp[c_m].start, + cur_lt + ->timestamp). + rel_value_us / 1000, + cur_lt->total_messages_sent, + cur_lt->total_bytes_sent, + cur_lt->total_throughput_send, + cur_lt->total_messages_received, + cur_lt->total_bytes_received, + cur_lt->total_throughput_recv); + + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f_m, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to master file %u\n", c_m); + GNUNET_free (data); - for (cur_lt = l->lp[c_m].head; NULL != cur_lt; cur_lt = cur_lt->next) - { - if (l->verbose) - fprintf(stderr, - "Master [%u]: timestamp %llu %llu ; %u %u %u ; %u %u %u\n", - l->lp[c_m].peer->no, - (long long unsigned int)cur_lt->timestamp.abs_value_us, - (long long unsigned int)GNUNET_TIME_absolute_get_difference(l->lp[c_m].start, - cur_lt->timestamp).rel_value_us / 1000, - cur_lt->total_messages_sent, - cur_lt->total_bytes_sent, - cur_lt->total_throughput_send, - cur_lt->total_messages_received, - cur_lt->total_bytes_received, - cur_lt->total_throughput_recv); - - /* Assembling master string */ - GNUNET_asprintf(&data, "%llu;%llu;%u;%u;%u;%u;%u;%u;\n", - (long long unsigned int)cur_lt->timestamp.abs_value_us, - (long long unsigned int)GNUNET_TIME_absolute_get_difference(l->lp[c_m].start, - cur_lt->timestamp).rel_value_us / 1000, - cur_lt->total_messages_sent, - cur_lt->total_bytes_sent, - cur_lt->total_throughput_send, - cur_lt->total_messages_received, - cur_lt->total_bytes_received, - cur_lt->total_throughput_recv); - - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f_m, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot write data to master file %u\n", c_m); - GNUNET_free(data); - - - for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++) - { - plt = &cur_lt->slaves_log[c_s]; - /* Log partners */ - - /* Assembling slave string */ - GNUNET_asprintf(&data, - "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n", - (long long unsigned int)cur_lt->timestamp.abs_value_us, - (long long unsigned int)GNUNET_TIME_absolute_get_difference(l->lp[c_m].start, - cur_lt->timestamp).rel_value_us / 1000, - plt->total_messages_sent, - plt->total_bytes_sent, - plt->throughput_sent, - plt->total_messages_received, - plt->total_bytes_received, - plt->throughput_recv, - (double)plt->app_rtt / 1000, - plt->bandwidth_in, - plt->bandwidth_out, - plt->ats_delay, - plt->ats_distance, - plt->ats_network_type, - plt->ats_utilization_out, - plt->ats_utilization_in, - plt->pref_bandwidth, - plt->pref_delay); - - if (l->verbose) - fprintf(stderr, - "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %llu bw_in %u bw_out %u \n", - plt->slave->no, - plt->total_messages_sent, - plt->total_bytes_sent, - plt->throughput_sent, - plt->total_messages_received, - plt->total_bytes_received, - plt->throughput_recv, - plt->app_rtt, - (long long unsigned int)plt->ats_delay.rel_value_us, - plt->bandwidth_in, - plt->bandwidth_out); - - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f[c_s], data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot write data to log file `%s'\n", filename_slaves[c_s]); - GNUNET_free(data); - } - } for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++) - { - if (GNUNET_SYSERR == GNUNET_DISK_file_close(f[c_s])) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Cannot close log file for master[%u] slave[%u]\n", c_m, c_s); - continue; - } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Data file successfully written to log file for `%s'\n", - filename_slaves[c_s]); - } + { + plt = &cur_lt->slaves_log[c_s]; + /* Log partners */ + + /* Assembling slave string */ + GNUNET_asprintf (&data, + "%llu;%llu;%u;%u;%u;%u;%u;%u;%.3f;%u;%u;%u;%u;%u;%u;%u;%.3f;%.3f\n", + (long long unsigned + int) cur_lt->timestamp.abs_value_us, + (long long unsigned + int) GNUNET_TIME_absolute_get_difference ( + l->lp[c_m].start, + cur_lt + ->timestamp) + .rel_value_us / 1000, + plt->total_messages_sent, + plt->total_bytes_sent, + plt->throughput_sent, + plt->total_messages_received, + plt->total_bytes_received, + plt->throughput_recv, + (double) plt->app_rtt / 1000, + plt->bandwidth_in, + plt->bandwidth_out, + plt->ats_delay, + plt->ats_distance, + plt->ats_network_type, + plt->ats_utilization_out, + plt->ats_utilization_in, + plt->pref_bandwidth, + plt->pref_delay); + + if (l->verbose) + fprintf (stderr, + "\t Slave [%u]: %u %u %u ; %u %u %u rtt %u delay %llu bw_in %u bw_out %u \n", + plt->slave->no, + plt->total_messages_sent, + plt->total_bytes_sent, + plt->throughput_sent, + plt->total_messages_received, + plt->total_bytes_received, + plt->throughput_recv, + plt->app_rtt, + (long long unsigned int) plt->ats_delay.rel_value_us, + plt->bandwidth_in, + plt->bandwidth_out); + + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f[c_s], data, strlen ( + data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to log file `%s'\n", + filename_slaves[c_s]); + GNUNET_free (data); + } + } - if (GNUNET_SYSERR == GNUNET_DISK_file_close(f_m)) - { - GNUNET_log_strerror_file(GNUNET_ERROR_TYPE_ERROR, - "close", - filename_master); - GNUNET_free(filename_master); - return; - } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Data file successfully written to log file for master `%s'\n", filename_master); + for (c_s = 0; c_s < l->lp[c_m].peer->num_partners; c_s++) + { + if (GNUNET_SYSERR == GNUNET_DISK_file_close (f[c_s])) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot close log file for master[%u] slave[%u]\n", c_m, + c_s); + continue; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Data file successfully written to log file for `%s'\n", + filename_slaves[c_s]); + } - if (GNUNET_YES == plots) - { - write_throughput_gnuplot_script(filename_master, &l->lp[c_m], filename_slaves, l->num_slaves); - write_rtt_gnuplot_script(filename_master, &l->lp[c_m], filename_slaves, l->num_slaves); - write_bw_gnuplot_script(filename_master, &l->lp[c_m], filename_slaves, l->num_slaves); - } + if (GNUNET_SYSERR == GNUNET_DISK_file_close (f_m)) + { + GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, + "close", + filename_master); + GNUNET_free (filename_master); + return; } - GNUNET_free(filename_master); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Data file successfully written to log file for master `%s'\n", + filename_master); + + if (GNUNET_YES == plots) + { + write_throughput_gnuplot_script (filename_master, &l->lp[c_m], + filename_slaves, l->num_slaves); + write_rtt_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, + l->num_slaves); + write_bw_gnuplot_script (filename_master, &l->lp[c_m], filename_slaves, + l->num_slaves); + } + } + GNUNET_free (filename_master); } /** @@ -615,7 +670,7 @@ GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l, * @param l logging handle to use */ void -GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l) +GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l) { struct LoggingPeer *bp; struct PeerLoggingTimestep *mlt; @@ -633,180 +688,188 @@ GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l) return; for (c_m = 0; c_m < l->num_masters; c_m++) + { + bp = &l->lp[c_m]; + mlt = GNUNET_new (struct PeerLoggingTimestep); + GNUNET_CONTAINER_DLL_insert_tail (l->lp[c_m].head, l->lp[c_m].tail, mlt); + prev_log_mlt = mlt->prev; + + /* Collect data */ + /* Current master state */ + mlt->timestamp = GNUNET_TIME_absolute_get (); + mlt->total_bytes_sent = bp->peer->total_bytes_sent; + mlt->total_messages_sent = bp->peer->total_messages_sent; + mlt->total_bytes_received = bp->peer->total_bytes_received; + mlt->total_messages_received = bp->peer->total_messages_received; + + /* Throughput */ + if (NULL == prev_log_mlt) + { + /* Get difference to start */ + delta = GNUNET_TIME_absolute_get_difference (l->lp[c_m].start, + mlt->timestamp); + } + else + { + /* Get difference to last timestep */ + delta = GNUNET_TIME_absolute_get_difference (mlt->prev->timestamp, + mlt->timestamp); + } + + /* Multiplication factor for throughput calculation */ + mult = (double) GNUNET_TIME_UNIT_SECONDS.rel_value_us + / (delta.rel_value_us); + + /* Total throughput */ + if (NULL != prev_log_mlt) + { + if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0) + { + mlt->total_throughput_send = mult * (mlt->total_bytes_sent + - mlt->prev->total_bytes_sent); + } + else + { + mlt->total_throughput_send = 0; + // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */ + } + + if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0) + { + mlt->total_throughput_recv = mult * (mlt->total_bytes_received + - mlt->prev->total_bytes_received); + } + else + { + mlt->total_throughput_recv = 0; + // mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */ + } + } + else + { + mlt->total_throughput_send = mult * mlt->total_bytes_sent; + mlt->total_throughput_recv = mult * mlt->total_bytes_received; + } + + if (GNUNET_YES == l->verbose) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n", + c_m, + (unsigned long long) delta.rel_value_us, + mlt->total_bytes_sent, + mlt->total_bytes_received, + mlt->total_throughput_send, + mlt->total_throughput_recv); + } + + mlt->slaves_log = GNUNET_malloc (bp->peer->num_partners + * sizeof(struct PartnerLoggingTimestep)); + + for (c_s = 0; c_s < bp->peer->num_partners; c_s++) { - bp = &l->lp[c_m]; - mlt = GNUNET_new(struct PeerLoggingTimestep); - GNUNET_CONTAINER_DLL_insert_tail(l->lp[c_m].head, l->lp[c_m].tail, mlt); - prev_log_mlt = mlt->prev; - - /* Collect data */ - /* Current master state */ - mlt->timestamp = GNUNET_TIME_absolute_get(); - mlt->total_bytes_sent = bp->peer->total_bytes_sent; - mlt->total_messages_sent = bp->peer->total_messages_sent; - mlt->total_bytes_received = bp->peer->total_bytes_received; - mlt->total_messages_received = bp->peer->total_messages_received; - - /* Throughput */ + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Collect logging data master[%u] slave [%u]\n", c_m, c_s); + + p = &bp->peer->partners[c_s]; + slt = &mlt->slaves_log[c_s]; + + slt->slave = p->dest; + /* Bytes sent from master to this slave */ + slt->total_bytes_sent = p->bytes_sent; + /* Messages sent from master to this slave */ + slt->total_messages_sent = p->messages_sent; + /* Bytes master received from this slave */ + slt->total_bytes_received = p->bytes_received; + /* Messages master received from this slave */ + slt->total_messages_received = p->messages_received; + slt->total_app_rtt = p->total_app_rtt; + /* ats performance information */ + slt->ats_delay = p->props.delay; + slt->ats_distance = p->props.distance; + slt->ats_network_type = p->props.scope; + slt->ats_utilization_in = p->props.utilization_out; + slt->ats_utilization_out = p->props.utilization_out; + slt->bandwidth_in = p->bandwidth_in; + slt->bandwidth_out = p->bandwidth_out; + slt->pref_bandwidth = p->pref_bandwidth; + slt->pref_delay = p->pref_delay; + + /* Total application level rtt */ if (NULL == prev_log_mlt) - { - /* Get difference to start */ - delta = GNUNET_TIME_absolute_get_difference(l->lp[c_m].start, mlt->timestamp); - } + { + if (0 != slt->total_messages_sent) + app_rtt = slt->total_app_rtt / slt->total_messages_sent; + else + app_rtt = 0; + } else + { + prev_log_slt = &prev_log_mlt->slaves_log[c_s]; + if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0) + app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) + / (slt->total_messages_sent + - prev_log_slt->total_messages_sent); + else { - /* Get difference to last timestep */ - delta = GNUNET_TIME_absolute_get_difference(mlt->prev->timestamp, mlt->timestamp); + app_rtt = prev_log_slt->app_rtt; /* No messages were */ } + } + slt->app_rtt = app_rtt; - /* Multiplication factor for throughput calculation */ - mult = (double)GNUNET_TIME_UNIT_SECONDS.rel_value_us / (delta.rel_value_us); - - /* Total throughput */ + /* Partner throughput */ if (NULL != prev_log_mlt) - { - if (mlt->total_bytes_sent - mlt->prev->total_bytes_sent > 0) - { - mlt->total_throughput_send = mult * (mlt->total_bytes_sent - mlt->prev->total_bytes_sent); - } - else - { - mlt->total_throughput_send = 0; - // mlt->total_throughput_send = prev_log_mlt->total_throughput_send; /* no msgs send */ - } - - if (mlt->total_bytes_received - mlt->prev->total_bytes_received > 0) - { - mlt->total_throughput_recv = mult * (mlt->total_bytes_received - mlt->prev->total_bytes_received); - } - else - { - mlt->total_throughput_recv = 0; - //mlt->total_throughput_recv = prev_log_mlt->total_throughput_recv; /* no msgs received */ - } - } + { + prev_log_slt = &prev_log_mlt->slaves_log[c_s]; + if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent) + slt->throughput_sent = mult * (slt->total_bytes_sent + - prev_log_slt->total_bytes_sent); + else + slt->throughput_sent = 0; + + if (slt->total_bytes_received > prev_log_slt->total_bytes_received) + slt->throughput_recv = mult + * (slt->total_bytes_received + - prev_log_slt->total_bytes_received); + else + slt->throughput_recv = 0; + } else - { - mlt->total_throughput_send = mult * mlt->total_bytes_sent; - mlt->total_throughput_recv = mult * mlt->total_bytes_received; - } + { + slt->throughput_sent = mult * slt->total_bytes_sent; + slt->throughput_recv = mult * slt->total_bytes_received; + } if (GNUNET_YES == l->verbose) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Master[%u] delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n", - c_m, - (unsigned long long)delta.rel_value_us, - mlt->total_bytes_sent, - mlt->total_bytes_received, - mlt->total_throughput_send, - mlt->total_throughput_recv); - } - - mlt->slaves_log = GNUNET_malloc(bp->peer->num_partners * - sizeof(struct PartnerLoggingTimestep)); - - for (c_s = 0; c_s < bp->peer->num_partners; c_s++) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Collect logging data master[%u] slave [%u]\n", c_m, c_s); - - p = &bp->peer->partners[c_s]; - slt = &mlt->slaves_log[c_s]; - - slt->slave = p->dest; - /* Bytes sent from master to this slave */ - slt->total_bytes_sent = p->bytes_sent; - /* Messages sent from master to this slave */ - slt->total_messages_sent = p->messages_sent; - /* Bytes master received from this slave */ - slt->total_bytes_received = p->bytes_received; - /* Messages master received from this slave */ - slt->total_messages_received = p->messages_received; - slt->total_app_rtt = p->total_app_rtt; - /* ats performance information */ - slt->ats_delay = p->props.delay; - slt->ats_distance = p->props.distance; - slt->ats_network_type = p->props.scope; - slt->ats_utilization_in = p->props.utilization_out; - slt->ats_utilization_out = p->props.utilization_out; - slt->bandwidth_in = p->bandwidth_in; - slt->bandwidth_out = p->bandwidth_out; - slt->pref_bandwidth = p->pref_bandwidth; - slt->pref_delay = p->pref_delay; - - /* Total application level rtt */ - if (NULL == prev_log_mlt) - { - if (0 != slt->total_messages_sent) - app_rtt = slt->total_app_rtt / slt->total_messages_sent; - else - app_rtt = 0; - } - else - { - prev_log_slt = &prev_log_mlt->slaves_log[c_s]; - if ((slt->total_messages_sent - prev_log_slt->total_messages_sent) > 0) - app_rtt = (slt->total_app_rtt - prev_log_slt->total_app_rtt) / - (slt->total_messages_sent - prev_log_slt->total_messages_sent); - else - { - app_rtt = prev_log_slt->app_rtt; /* No messages were */ - } - } - slt->app_rtt = app_rtt; - - /* Partner throughput */ - if (NULL != prev_log_mlt) - { - prev_log_slt = &prev_log_mlt->slaves_log[c_s]; - if (slt->total_bytes_sent > prev_log_slt->total_bytes_sent) - slt->throughput_sent = mult * (slt->total_bytes_sent - prev_log_slt->total_bytes_sent); - else - slt->throughput_sent = 0; - - if (slt->total_bytes_received > prev_log_slt->total_bytes_received) - slt->throughput_recv = mult * - (slt->total_bytes_received - prev_log_slt->total_bytes_received); - else - slt->throughput_recv = 0; - } - else - { - slt->throughput_sent = mult * slt->total_bytes_sent; - slt->throughput_recv = mult * slt->total_bytes_received; - } - - if (GNUNET_YES == l->verbose) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n", - c_m, c_s, - (unsigned long long)delta.rel_value_us, - mlt->total_bytes_sent, - mlt->total_bytes_received, - slt->throughput_sent, - slt->throughput_recv); - } - else - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Master [%u]: slave [%u]\n", - bp->peer->no, p->dest->no); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Master [%u] -> Slave [%u]: delta: %llu us, bytes (sent/received): %u / %u; throughput send/recv: %u / %u\n", + c_m, c_s, + (unsigned long long) delta.rel_value_us, + mlt->total_bytes_sent, + mlt->total_bytes_received, + slt->throughput_sent, + slt->throughput_recv); + } + else + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Master [%u]: slave [%u]\n", + bp->peer->no, p->dest->no); } + } } static void -collect_log_task(void *cls) +collect_log_task (void *cls) { struct LoggingHandle *l = cls; l->log_task = NULL; - GNUNET_ATS_TEST_logging_now(l); - l->log_task = GNUNET_SCHEDULER_add_delayed(l->frequency, - &collect_log_task, - l); + GNUNET_ATS_TEST_logging_now (l); + l->log_task = GNUNET_SCHEDULER_add_delayed (l->frequency, + &collect_log_task, + l); } @@ -816,20 +879,20 @@ collect_log_task(void *cls) * @param l the logging handle */ void -GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l) +GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l) { if (GNUNET_YES != l->running) return; if (NULL != l->log_task) - { - GNUNET_SCHEDULER_cancel(l->log_task); - l->log_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (l->log_task); + l->log_task = NULL; + } l->running = GNUNET_NO; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Stop logging\n")); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Stop logging\n")); } /** @@ -838,26 +901,26 @@ GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l) * @param l the logging handle */ void -GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l) +GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l) { int c_m; struct PeerLoggingTimestep *cur; if (GNUNET_YES == l->running) - GNUNET_ATS_TEST_logging_stop(l); + GNUNET_ATS_TEST_logging_stop (l); for (c_m = 0; c_m < l->num_masters; c_m++) + { + while (NULL != (cur = l->lp[c_m].head)) { - while (NULL != (cur = l->lp[c_m].head)) - { - GNUNET_CONTAINER_DLL_remove(l->lp[c_m].head, l->lp[c_m].tail, cur); - GNUNET_free(cur->slaves_log); - GNUNET_free(cur); - } + GNUNET_CONTAINER_DLL_remove (l->lp[c_m].head, l->lp[c_m].tail, cur); + GNUNET_free (cur->slaves_log); + GNUNET_free (cur); } + } - GNUNET_free(l->lp); - GNUNET_free(l); + GNUNET_free (l->lp); + GNUNET_free (l); } @@ -873,35 +936,35 @@ GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l) * @return the logging handle or NULL on error */ struct LoggingHandle * -GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency, - const char *testname, - struct BenchmarkPeer *masters, - int num_masters, - int num_slaves, - int verbose) +GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency, + const char *testname, + struct BenchmarkPeer *masters, + int num_masters, + int num_slaves, + int verbose) { struct LoggingHandle *l; int c_m; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Start logging `%s'\n"), testname); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Start logging `%s'\n"), testname); - l = GNUNET_new(struct LoggingHandle); + l = GNUNET_new (struct LoggingHandle); l->num_masters = num_masters; l->num_slaves = num_slaves; l->name = testname; l->frequency = log_frequency; l->verbose = verbose; - l->lp = GNUNET_malloc(num_masters * sizeof(struct LoggingPeer)); + l->lp = GNUNET_malloc (num_masters * sizeof(struct LoggingPeer)); for (c_m = 0; c_m < num_masters; c_m++) - { - l->lp[c_m].peer = &masters[c_m]; - l->lp[c_m].start = GNUNET_TIME_absolute_get(); - } + { + l->lp[c_m].peer = &masters[c_m]; + l->lp[c_m].start = GNUNET_TIME_absolute_get (); + } /* Schedule logging task */ - l->log_task = GNUNET_SCHEDULER_add_now(&collect_log_task, l); + l->log_task = GNUNET_SCHEDULER_add_now (&collect_log_task, l); l->running = GNUNET_YES; return l; diff --git a/src/ats-tests/ats-testing-preferences.c b/src/ats-tests/ats-testing-preferences.c index a14e66736..8138b18bb 100644 --- a/src/ats-tests/ats-testing-preferences.c +++ b/src/ats-tests/ats-testing-preferences.c @@ -33,7 +33,7 @@ static struct PreferenceGenerator *pg_tail; extern struct GNUNET_ATS_TEST_Topology *top; static double -get_preference(struct PreferenceGenerator *pg) +get_preference (struct PreferenceGenerator *pg) { struct GNUNET_TIME_Relative time_delta; double delta_value; @@ -41,97 +41,101 @@ get_preference(struct PreferenceGenerator *pg) /* Calculate the current preference value */ switch (pg->type) + { + case GNUNET_ATS_TEST_TG_CONSTANT: + pref_value = pg->base_value; + break; + + case GNUNET_ATS_TEST_TG_LINEAR: + time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start); + /* Calculate point of time in the current period */ + time_delta.rel_value_us = time_delta.rel_value_us + % pg->duration_period.rel_value_us; + delta_value = ((double) time_delta.rel_value_us + / pg->duration_period.rel_value_us) * (pg->max_value + - pg->base_value); + if ((pg->max_value < pg->base_value) && + ((pg->max_value - pg->base_value) > pg->base_value)) { - case GNUNET_ATS_TEST_TG_CONSTANT: - pref_value = pg->base_value; - break; - - case GNUNET_ATS_TEST_TG_LINEAR: - time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); - /* Calculate point of time in the current period */ - time_delta.rel_value_us = time_delta.rel_value_us % - pg->duration_period.rel_value_us; - delta_value = ((double)time_delta.rel_value_us / - pg->duration_period.rel_value_us) * (pg->max_value - pg->base_value); - if ((pg->max_value < pg->base_value) && - ((pg->max_value - pg->base_value) > pg->base_value)) - { - /* This will cause an underflow */ - GNUNET_break(0); - } - pref_value = pg->base_value + delta_value; - break; - - case GNUNET_ATS_TEST_TG_RANDOM: - delta_value = (double)GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, - 10000 * (pg->max_value - pg->base_value)) / 10000; - pref_value = pg->base_value + delta_value; - break; - - case GNUNET_ATS_TEST_TG_SINUS: - time_delta = GNUNET_TIME_absolute_get_duration(pg->time_start); - /* Calculate point of time in the current period */ - time_delta.rel_value_us = time_delta.rel_value_us % - pg->duration_period.rel_value_us; - if ((pg->max_value - pg->base_value) > pg->base_value) - { - /* This will cause an underflow for second half of sinus period, - * will be detected in general when experiments are loaded */ - GNUNET_break(0); - } - delta_value = (pg->max_value - pg->base_value) * - sin((2 * M_PI) / ((double)pg->duration_period.rel_value_us) * - time_delta.rel_value_us); - pref_value = pg->base_value + delta_value; - break; - - default: - pref_value = 0.0; - break; + /* This will cause an underflow */ + GNUNET_break (0); } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n", - pref_value); + pref_value = pg->base_value + delta_value; + break; + + case GNUNET_ATS_TEST_TG_RANDOM: + delta_value = (double) GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_WEAK, + 10000 * (pg->max_value + - pg->base_value)) + / 10000; + pref_value = pg->base_value + delta_value; + break; + + case GNUNET_ATS_TEST_TG_SINUS: + time_delta = GNUNET_TIME_absolute_get_duration (pg->time_start); + /* Calculate point of time in the current period */ + time_delta.rel_value_us = time_delta.rel_value_us + % pg->duration_period.rel_value_us; + if ((pg->max_value - pg->base_value) > pg->base_value) + { + /* This will cause an underflow for second half of sinus period, + * will be detected in general when experiments are loaded */ + GNUNET_break (0); + } + delta_value = (pg->max_value - pg->base_value) + * sin ((2 * M_PI) + / ((double) pg->duration_period.rel_value_us) + * time_delta.rel_value_us); + pref_value = pg->base_value + delta_value; + break; + + default: + pref_value = 0.0; + break; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Current preference value is %f\n", + pref_value); return pref_value; } static void -set_pref_task(void *cls) +set_pref_task (void *cls) { struct BenchmarkPartner *p = cls; double pref_value; p->pg->set_task = NULL; - pref_value = get_preference(p->pg); + pref_value = get_preference (p->pg); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting preference for master [%u] and slave [%u] for %s to %f\n", - p->me->no, p->dest->no, - GNUNET_ATS_print_preference_type(p->pg->kind), pref_value); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting preference for master [%u] and slave [%u] for %s to %f\n", + p->me->no, p->dest->no, + GNUNET_ATS_print_preference_type (p->pg->kind), pref_value); - GNUNET_ATS_performance_change_preference(p->me->ats_perf_handle, - &p->dest->id, - p->pg->kind, - pref_value, - GNUNET_ATS_PREFERENCE_END); + GNUNET_ATS_performance_change_preference (p->me->ats_perf_handle, + &p->dest->id, + p->pg->kind, + pref_value, + GNUNET_ATS_PREFERENCE_END); switch (p->pg->kind) - { - case GNUNET_ATS_PREFERENCE_BANDWIDTH: - p->pref_bandwidth = pref_value; - break; + { + case GNUNET_ATS_PREFERENCE_BANDWIDTH: + p->pref_bandwidth = pref_value; + break; - case GNUNET_ATS_PREFERENCE_LATENCY: - p->pref_delay = pref_value; - break; + case GNUNET_ATS_PREFERENCE_LATENCY: + p->pref_delay = pref_value; + break; - default: - break; - } + default: + break; + } - p->pg->set_task = GNUNET_SCHEDULER_add_delayed(p->pg->frequency, - set_pref_task, p); + p->pg->set_task = GNUNET_SCHEDULER_add_delayed (p->pg->frequency, + set_pref_task, p); } @@ -150,25 +154,26 @@ set_pref_task(void *cls) * @return the preference generator */ struct PreferenceGenerator * -GNUNET_ATS_TEST_generate_preferences_start(struct BenchmarkPeer *src, - struct BenchmarkPartner *dest, - enum GeneratorType type, - unsigned int base_value, - unsigned int value_rate, - struct GNUNET_TIME_Relative period, - struct GNUNET_TIME_Relative frequency, - enum GNUNET_ATS_PreferenceKind kind) +GNUNET_ATS_TEST_generate_preferences_start (struct BenchmarkPeer *src, + struct BenchmarkPartner *dest, + enum GeneratorType type, + unsigned int base_value, + unsigned int value_rate, + struct GNUNET_TIME_Relative period, + struct GNUNET_TIME_Relative + frequency, + enum GNUNET_ATS_PreferenceKind kind) { struct PreferenceGenerator *pg; if (NULL != dest->pg) - { - GNUNET_break(0); - return NULL; - } + { + GNUNET_break (0); + return NULL; + } - pg = GNUNET_new(struct PreferenceGenerator); - GNUNET_CONTAINER_DLL_insert(pg_head, pg_tail, pg); + pg = GNUNET_new (struct PreferenceGenerator); + GNUNET_CONTAINER_DLL_insert (pg_head, pg_tail, pg); pg->type = type; pg->src = src; pg->dest = dest; @@ -177,65 +182,65 @@ GNUNET_ATS_TEST_generate_preferences_start(struct BenchmarkPeer *src, pg->max_value = value_rate; pg->duration_period = period; pg->frequency = frequency; - pg->time_start = GNUNET_TIME_absolute_get(); + pg->time_start = GNUNET_TIME_absolute_get (); switch (type) - { - case GNUNET_ATS_TEST_TG_CONSTANT: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", - dest->me->no, GNUNET_i2s(&dest->me->id), - dest->dest->no, GNUNET_i2s(&dest->dest->id), - base_value); - break; - - case GNUNET_ATS_TEST_TG_LINEAR: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", - dest->me->no, GNUNET_i2s(&dest->me->id), - dest->dest->no, GNUNET_i2s(&dest->dest->id), - base_value, value_rate); - break; - - case GNUNET_ATS_TEST_TG_SINUS: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", - dest->me->no, GNUNET_i2s(&dest->me->id), - dest->dest->no, GNUNET_i2s(&dest->dest->id), - base_value, value_rate); - break; - - case GNUNET_ATS_TEST_TG_RANDOM: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", - dest->me->no, GNUNET_i2s(&dest->me->id), - dest->dest->no, GNUNET_i2s(&dest->dest->id), - base_value, value_rate); - break; - - default: - break; - } + { + case GNUNET_ATS_TEST_TG_CONSTANT: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up constant preference generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", + dest->me->no, GNUNET_i2s (&dest->me->id), + dest->dest->no, GNUNET_i2s (&dest->dest->id), + base_value); + break; + + case GNUNET_ATS_TEST_TG_LINEAR: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up linear preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", + dest->me->no, GNUNET_i2s (&dest->me->id), + dest->dest->no, GNUNET_i2s (&dest->dest->id), + base_value, value_rate); + break; + + case GNUNET_ATS_TEST_TG_SINUS: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up sinus preference generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", + dest->me->no, GNUNET_i2s (&dest->me->id), + dest->dest->no, GNUNET_i2s (&dest->dest->id), + base_value, value_rate); + break; + + case GNUNET_ATS_TEST_TG_RANDOM: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up random preference generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", + dest->me->no, GNUNET_i2s (&dest->me->id), + dest->dest->no, GNUNET_i2s (&dest->dest->id), + base_value, value_rate); + break; + + default: + break; + } dest->pg = pg; - pg->set_task = GNUNET_SCHEDULER_add_now(&set_pref_task, dest); + pg->set_task = GNUNET_SCHEDULER_add_now (&set_pref_task, dest); return pg; } void -GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg) +GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg) { - GNUNET_CONTAINER_DLL_remove(pg_head, pg_tail, pg); + GNUNET_CONTAINER_DLL_remove (pg_head, pg_tail, pg); pg->dest->pg = NULL; if (NULL != pg->set_task) - { - GNUNET_SCHEDULER_cancel(pg->set_task); - pg->set_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (pg->set_task); + pg->set_task = NULL; + } - GNUNET_free(pg); + GNUNET_free (pg); } @@ -243,17 +248,17 @@ GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg) * Stop all preferences generators */ void -GNUNET_ATS_TEST_generate_preferences_stop_all() +GNUNET_ATS_TEST_generate_preferences_stop_all () { struct PreferenceGenerator *cur; struct PreferenceGenerator *next; next = pg_head; for (cur = next; NULL != cur; cur = next) - { - next = cur->next; - GNUNET_ATS_TEST_generate_preferences_stop(cur); - } + { + next = cur->next; + GNUNET_ATS_TEST_generate_preferences_stop (cur); + } } /* end of file ats-testing-preferences.c */ diff --git a/src/ats-tests/ats-testing-traffic.c b/src/ats-tests/ats-testing-traffic.c index 01462980c..14a8fe327 100644 --- a/src/ats-tests/ats-testing-traffic.c +++ b/src/ats-tests/ats-testing-traffic.c @@ -33,7 +33,7 @@ static struct TrafficGenerator *tg_tail; extern struct GNUNET_ATS_TEST_Topology *top; static struct GNUNET_TIME_Relative -get_delay(struct TrafficGenerator *tg) +get_delay (struct TrafficGenerator *tg) { struct GNUNET_TIME_Relative delay; struct GNUNET_TIME_Relative time_delta; @@ -44,69 +44,78 @@ get_delay(struct TrafficGenerator *tg) /* Calculate the current transmission rate based on the type of traffic */ switch (tg->type) + { + case GNUNET_ATS_TEST_TG_CONSTANT: + if (UINT32_MAX == tg->base_rate) + return GNUNET_TIME_UNIT_ZERO; + cur_rate = tg->base_rate; + break; + + case GNUNET_ATS_TEST_TG_LINEAR: + time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start); + /* Calculate point of time in the current period */ + time_delta.rel_value_us = time_delta.rel_value_us + % tg->duration_period.rel_value_us; + delta_rate = ((double) time_delta.rel_value_us + / tg->duration_period.rel_value_us) + * (tg->max_rate - tg->base_rate); + if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) > + tg->base_rate)) { - case GNUNET_ATS_TEST_TG_CONSTANT: - if (UINT32_MAX == tg->base_rate) - return GNUNET_TIME_UNIT_ZERO; - cur_rate = tg->base_rate; - break; - - case GNUNET_ATS_TEST_TG_LINEAR: - time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start); - /* Calculate point of time in the current period */ - time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us; - delta_rate = ((double)time_delta.rel_value_us / tg->duration_period.rel_value_us) * - (tg->max_rate - tg->base_rate); - if ((tg->max_rate < tg->base_rate) && ((tg->max_rate - tg->base_rate) > tg->base_rate)) - { - /* This will cause an underflow */ - GNUNET_break(0); - } - cur_rate = tg->base_rate + delta_rate; - break; - - case GNUNET_ATS_TEST_TG_RANDOM: - cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32(GNUNET_CRYPTO_QUALITY_WEAK, - tg->max_rate - tg->base_rate); - break; - - case GNUNET_ATS_TEST_TG_SINUS: - time_delta = GNUNET_TIME_absolute_get_duration(tg->time_start); - /* Calculate point of time in the current period */ - time_delta.rel_value_us = time_delta.rel_value_us % tg->duration_period.rel_value_us; - if ((tg->max_rate - tg->base_rate) > tg->base_rate) - { - /* This will cause an underflow for second half of sinus period, - * will be detected in general when experiments are loaded */ - GNUNET_break(0); - } - delta_rate = (tg->max_rate - tg->base_rate) * - sin((2 * M_PI) / ((double)tg->duration_period.rel_value_us) * time_delta.rel_value_us); - cur_rate = tg->base_rate + delta_rate; - break; - - default: - return delay; - break; + /* This will cause an underflow */ + GNUNET_break (0); } - - if (cur_rate < 0) + cur_rate = tg->base_rate + delta_rate; + break; + + case GNUNET_ATS_TEST_TG_RANDOM: + cur_rate = tg->base_rate + GNUNET_CRYPTO_random_u32 ( + GNUNET_CRYPTO_QUALITY_WEAK, + tg->max_rate + - tg->base_rate); + break; + + case GNUNET_ATS_TEST_TG_SINUS: + time_delta = GNUNET_TIME_absolute_get_duration (tg->time_start); + /* Calculate point of time in the current period */ + time_delta.rel_value_us = time_delta.rel_value_us + % tg->duration_period.rel_value_us; + if ((tg->max_rate - tg->base_rate) > tg->base_rate) { - cur_rate = 1; + /* This will cause an underflow for second half of sinus period, + * will be detected in general when experiments are loaded */ + GNUNET_break (0); } + delta_rate = (tg->max_rate - tg->base_rate) + * sin ((2 * M_PI) + / ((double) tg->duration_period.rel_value_us) + * time_delta.rel_value_us); + cur_rate = tg->base_rate + delta_rate; + break; + + default: + return delay; + break; + } + + if (cur_rate < 0) + { + cur_rate = 1; + } /* Calculate the delay for the next message based on the current delay */ - delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us * TEST_MESSAGE_SIZE / cur_rate; + delay.rel_value_us = GNUNET_TIME_UNIT_SECONDS.rel_value_us + * TEST_MESSAGE_SIZE / cur_rate; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Current rate is %lld, calculated delay is %llu\n", - cur_rate, - (unsigned long long)delay.rel_value_us); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Current rate is %lld, calculated delay is %llu\n", + cur_rate, + (unsigned long long) delay.rel_value_us); return delay; } static void -update_ping_data(void *cls) +update_ping_data (void *cls) { struct BenchmarkPartner *p = cls; struct GNUNET_TIME_Relative delay; @@ -117,49 +126,49 @@ update_ping_data(void *cls) p->me->total_bytes_sent += TEST_MESSAGE_SIZE; if (NULL == p->tg) - { - GNUNET_break(0); - return; - } - delay = get_delay(p->tg); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Delay for next transmission %s\n", - GNUNET_STRINGS_relative_time_to_string(delay, - GNUNET_YES)); + { + GNUNET_break (0); + return; + } + delay = get_delay (p->tg); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Delay for next transmission %s\n", + GNUNET_STRINGS_relative_time_to_string (delay, + GNUNET_YES)); p->tg->next_ping_transmission - = GNUNET_TIME_absolute_add(GNUNET_TIME_absolute_get(), - delay); + = GNUNET_TIME_absolute_add (GNUNET_TIME_absolute_get (), + delay); } static void -comm_schedule_send(void *cls) +comm_schedule_send (void *cls) { struct BenchmarkPartner *p = cls; struct TestMessage *msg; struct GNUNET_MQ_Envelope *env; p->tg->send_task = NULL; - p->last_message_sent = GNUNET_TIME_absolute_get(); - env = GNUNET_MQ_msg(msg, - TEST_MESSAGE_TYPE_PING); - memset(msg->padding, - 'a', - sizeof(msg->padding)); - GNUNET_MQ_notify_sent(env, - &update_ping_data, - p); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Master [%u]: Sending PING to [%u]\n", - p->me->no, - p->dest->no); - GNUNET_MQ_send(p->mq, - env); + p->last_message_sent = GNUNET_TIME_absolute_get (); + env = GNUNET_MQ_msg (msg, + TEST_MESSAGE_TYPE_PING); + memset (msg->padding, + 'a', + sizeof(msg->padding)); + GNUNET_MQ_notify_sent (env, + &update_ping_data, + p); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Master [%u]: Sending PING to [%u]\n", + p->me->no, + p->dest->no); + GNUNET_MQ_send (p->mq, + env); } static void -update_pong_data(void *cls) +update_pong_data (void *cls) { struct BenchmarkPartner *p = cls; @@ -171,74 +180,79 @@ update_pong_data(void *cls) void -GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p) +GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p) { struct TestMessage *msg; struct GNUNET_MQ_Envelope *env; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Slave [%u]: Received PING from [%u], sending PONG\n", - p->me->no, - p->dest->no); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Slave [%u]: Received PING from [%u], sending PONG\n", + p->me->no, + p->dest->no); p->messages_received++; p->bytes_received += TEST_MESSAGE_SIZE; p->me->total_messages_received++; p->me->total_bytes_received += TEST_MESSAGE_SIZE; - env = GNUNET_MQ_msg(msg, - TEST_MESSAGE_TYPE_PING); - memset(msg->padding, - 'a', - sizeof(msg->padding)); - GNUNET_MQ_notify_sent(env, - &update_pong_data, - p); - GNUNET_MQ_send(p->mq, - env); + env = GNUNET_MQ_msg (msg, + TEST_MESSAGE_TYPE_PING); + memset (msg->padding, + 'a', + sizeof(msg->padding)); + GNUNET_MQ_notify_sent (env, + &update_pong_data, + p); + GNUNET_MQ_send (p->mq, + env); } void -GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p) +GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p) { struct GNUNET_TIME_Relative left; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "Master [%u]: Received PONG from [%u], next message\n", - p->me->no, - p->dest->no); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "Master [%u]: Received PONG from [%u], next message\n", + p->me->no, + p->dest->no); p->messages_received++; p->bytes_received += TEST_MESSAGE_SIZE; p->me->total_messages_received++; p->me->total_bytes_received += TEST_MESSAGE_SIZE; - p->total_app_rtt += GNUNET_TIME_absolute_get_difference(p->last_message_sent, - GNUNET_TIME_absolute_get()).rel_value_us; + p->total_app_rtt += GNUNET_TIME_absolute_get_difference (p->last_message_sent, + GNUNET_TIME_absolute_get ()) + .rel_value_us; /* Schedule next send event */ if (NULL == p->tg) return; - left = GNUNET_TIME_absolute_get_remaining(p->tg->next_ping_transmission); + left = GNUNET_TIME_absolute_get_remaining (p->tg->next_ping_transmission); if (UINT32_MAX == p->tg->base_rate) - { - p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p); - } + { + p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p); + } else if (0 == left.rel_value_us) - { - p->tg->send_task = GNUNET_SCHEDULER_add_now(&comm_schedule_send, p); - } + { + p->tg->send_task = GNUNET_SCHEDULER_add_now (&comm_schedule_send, p); + } else - { - /* Enforce minimum transmission rate 1 msg / sec */ - if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left = GNUNET_TIME_relative_min(left, GNUNET_TIME_UNIT_SECONDS)).rel_value_us) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Enforcing minimum send rate between master [%u] and slave [%u]\n", - p->me->no, p->dest->no); - p->tg->send_task = GNUNET_SCHEDULER_add_delayed(left, - &comm_schedule_send, p); - } + { + /* Enforce minimum transmission rate 1 msg / sec */ + if (GNUNET_TIME_UNIT_SECONDS.rel_value_us == (left = + GNUNET_TIME_relative_min ( + left, + GNUNET_TIME_UNIT_SECONDS)) + .rel_value_us) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Enforcing minimum send rate between master [%u] and slave [%u]\n", + p->me->no, p->dest->no); + p->tg->send_task = GNUNET_SCHEDULER_add_delayed (left, + &comm_schedule_send, p); + } } @@ -256,105 +270,105 @@ GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p) * @return the traffic generator */ struct TrafficGenerator * -GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src, - struct BenchmarkPartner *dest, - enum GeneratorType type, - unsigned int base_rate, - unsigned int max_rate, - struct GNUNET_TIME_Relative period, - struct GNUNET_TIME_Relative duration) +GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src, + struct BenchmarkPartner *dest, + enum GeneratorType type, + unsigned int base_rate, + unsigned int max_rate, + struct GNUNET_TIME_Relative period, + struct GNUNET_TIME_Relative duration) { struct TrafficGenerator *tg; if (NULL != dest->tg) - { - GNUNET_break(0); - return NULL; - } - - tg = GNUNET_new(struct TrafficGenerator); - GNUNET_CONTAINER_DLL_insert(tg_head, - tg_tail, - tg); + { + GNUNET_break (0); + return NULL; + } + + tg = GNUNET_new (struct TrafficGenerator); + GNUNET_CONTAINER_DLL_insert (tg_head, + tg_tail, + tg); tg->type = type; tg->src = src; tg->dest = dest; tg->base_rate = base_rate; tg->max_rate = max_rate; tg->duration_period = period; - tg->time_start = GNUNET_TIME_absolute_get(); + tg->time_start = GNUNET_TIME_absolute_get (); tg->next_ping_transmission = GNUNET_TIME_UNIT_FOREVER_ABS; switch (type) - { - case GNUNET_ATS_TEST_TG_CONSTANT: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", - dest->me->no, - GNUNET_i2s(&dest->me->id), - dest->dest->no, - GNUNET_i2s(&dest->dest->id), - base_rate); - break; - - case GNUNET_ATS_TEST_TG_LINEAR: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", - dest->me->no, - GNUNET_i2s(&dest->me->id), - dest->dest->no, - GNUNET_i2s(&dest->dest->id), - base_rate, - max_rate); - break; - - case GNUNET_ATS_TEST_TG_SINUS: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", - dest->me->no, - GNUNET_i2s(&dest->me->id), - dest->dest->no, - GNUNET_i2s(&dest->dest->id), - base_rate, - max_rate); - break; - - case GNUNET_ATS_TEST_TG_RANDOM: - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", - dest->me->no, - GNUNET_i2s(&dest->me->id), - dest->dest->no, - GNUNET_i2s(&dest->dest->id), - base_rate, - max_rate); - break; - - default: - break; - } + { + case GNUNET_ATS_TEST_TG_CONSTANT: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up constant traffic generator master[%u] `%s' and slave [%u] `%s' max %u Bips\n", + dest->me->no, + GNUNET_i2s (&dest->me->id), + dest->dest->no, + GNUNET_i2s (&dest->dest->id), + base_rate); + break; + + case GNUNET_ATS_TEST_TG_LINEAR: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up linear traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bips\n", + dest->me->no, + GNUNET_i2s (&dest->me->id), + dest->dest->no, + GNUNET_i2s (&dest->dest->id), + base_rate, + max_rate); + break; + + case GNUNET_ATS_TEST_TG_SINUS: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up sinus traffic generator master[%u] `%s' and slave [%u] `%s' baserate %u Bips, amplitude %u Bps\n", + dest->me->no, + GNUNET_i2s (&dest->me->id), + dest->dest->no, + GNUNET_i2s (&dest->dest->id), + base_rate, + max_rate); + break; + + case GNUNET_ATS_TEST_TG_RANDOM: + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up random traffic generator master[%u] `%s' and slave [%u] `%s' min %u Bips max %u Bps\n", + dest->me->no, + GNUNET_i2s (&dest->me->id), + dest->dest->no, + GNUNET_i2s (&dest->dest->id), + base_rate, + max_rate); + break; + + default: + break; + } dest->tg = tg; tg->send_task - = GNUNET_SCHEDULER_add_now(&comm_schedule_send, - dest); + = GNUNET_SCHEDULER_add_now (&comm_schedule_send, + dest); return tg; } void -GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg) +GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg) { - GNUNET_CONTAINER_DLL_remove(tg_head, - tg_tail, - tg); + GNUNET_CONTAINER_DLL_remove (tg_head, + tg_tail, + tg); tg->dest->tg = NULL; if (NULL != tg->send_task) - { - GNUNET_SCHEDULER_cancel(tg->send_task); - tg->send_task = NULL; - } - GNUNET_free(tg); + { + GNUNET_SCHEDULER_cancel (tg->send_task); + tg->send_task = NULL; + } + GNUNET_free (tg); } @@ -362,17 +376,17 @@ GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg) * Stop all traffic generators */ void -GNUNET_ATS_TEST_generate_traffic_stop_all() +GNUNET_ATS_TEST_generate_traffic_stop_all () { struct TrafficGenerator *cur; struct TrafficGenerator *next; next = tg_head; for (cur = next; NULL != cur; cur = next) - { - next = cur->next; - GNUNET_ATS_TEST_generate_traffic_stop(cur); - } + { + next = cur->next; + GNUNET_ATS_TEST_generate_traffic_stop (cur); + } } /* end of file ats-testing-traffic.c */ diff --git a/src/ats-tests/ats-testing.c b/src/ats-tests/ats-testing.c index 696deb4bd..88c1729a6 100644 --- a/src/ats-tests/ats-testing.c +++ b/src/ats-tests/ats-testing.c @@ -30,7 +30,8 @@ /** * Connect peers with testbed */ -struct TestbedConnectOperation { +struct TestbedConnectOperation +{ /** * The benchmarking master initiating this connection */ @@ -58,7 +59,7 @@ struct GNUNET_ATS_TEST_Topology *top; * @param cls NULL */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { int c_m; int c_s; @@ -67,118 +68,118 @@ do_shutdown(void *cls) top->state.benchmarking = GNUNET_NO; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Benchmarking done\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Benchmarking done\n"); - GNUNET_ATS_TEST_generate_traffic_stop_all(); + GNUNET_ATS_TEST_generate_traffic_stop_all (); for (c_m = 0; c_m < top->num_masters; c_m++) + { + p = &top->mps[c_m]; + if (NULL != top->mps[c_m].peer_id_op) + { + GNUNET_TESTBED_operation_done (p->peer_id_op); + p->peer_id_op = NULL; + } + + if (NULL != p->ats_task) + GNUNET_SCHEDULER_cancel (p->ats_task); + p->ats_task = NULL; + + for (c_op = 0; c_op < p->num_partners; c_op++) + { + if ((NULL != p->core_connect_ops) && + (NULL != p->core_connect_ops[c_op].connect_op)) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Failed to connect peer 0 and %u\n", + c_op); + GNUNET_TESTBED_operation_done (p->core_connect_ops[c_op].connect_op); + p->core_connect_ops[c_op].connect_op = NULL; + } + } + + if (NULL != p->ats_perf_op) + { + GNUNET_TESTBED_operation_done (p->ats_perf_op); + p->ats_perf_op = NULL; + } + + if (NULL != p->comm_op) { - p = &top->mps[c_m]; - if (NULL != top->mps[c_m].peer_id_op) - { - GNUNET_TESTBED_operation_done(p->peer_id_op); - p->peer_id_op = NULL; - } - - if (NULL != p->ats_task) - GNUNET_SCHEDULER_cancel(p->ats_task); - p->ats_task = NULL; - - for (c_op = 0; c_op < p->num_partners; c_op++) - { - if ((NULL != p->core_connect_ops) && - (NULL != p->core_connect_ops[c_op].connect_op)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Failed to connect peer 0 and %u\n", - c_op); - GNUNET_TESTBED_operation_done(p->core_connect_ops[c_op].connect_op); - p->core_connect_ops[c_op].connect_op = NULL; - } - } - - if (NULL != p->ats_perf_op) - { - GNUNET_TESTBED_operation_done(p->ats_perf_op); - p->ats_perf_op = NULL; - } - - if (NULL != p->comm_op) - { - GNUNET_TESTBED_operation_done(p->comm_op); - p->comm_op = NULL; - } - GNUNET_free_non_null(p->core_connect_ops); - GNUNET_free(p->partners); - p->partners = NULL; + GNUNET_TESTBED_operation_done (p->comm_op); + p->comm_op = NULL; } + GNUNET_free_non_null (p->core_connect_ops); + GNUNET_free (p->partners); + p->partners = NULL; + } for (c_s = 0; c_s < top->num_slaves; c_s++) + { + p = &top->sps[c_s]; + if (NULL != p->peer_id_op) { - p = &top->sps[c_s]; - if (NULL != p->peer_id_op) - { - GNUNET_TESTBED_operation_done(p->peer_id_op); - p->peer_id_op = NULL; - } - if (NULL != p->ats_perf_op) - { - GNUNET_TESTBED_operation_done(p->ats_perf_op); - p->ats_perf_op = NULL; - } - if (NULL != p->comm_op) - { - GNUNET_TESTBED_operation_done(p->comm_op); - p->comm_op = NULL; - } - GNUNET_free(p->partners); - p->partners = NULL; + GNUNET_TESTBED_operation_done (p->peer_id_op); + p->peer_id_op = NULL; } - GNUNET_SCHEDULER_shutdown(); - GNUNET_free(top); + if (NULL != p->ats_perf_op) + { + GNUNET_TESTBED_operation_done (p->ats_perf_op); + p->ats_perf_op = NULL; + } + if (NULL != p->comm_op) + { + GNUNET_TESTBED_operation_done (p->comm_op); + p->comm_op = NULL; + } + GNUNET_free (p->partners); + p->partners = NULL; + } + GNUNET_SCHEDULER_shutdown (); + GNUNET_free (top); top = NULL; } static struct BenchmarkPartner * -find_partner(struct BenchmarkPeer *me, - const struct GNUNET_PeerIdentity *peer) +find_partner (struct BenchmarkPeer *me, + const struct GNUNET_PeerIdentity *peer) { int c_m; for (c_m = 0; c_m < me->num_partners; c_m++) + { + /* Find a partner with other as destination */ + if (0 == GNUNET_memcmp (peer, + &me->partners[c_m].dest->id)) { - /* Find a partner with other as destination */ - if (0 == GNUNET_memcmp(peer, - &me->partners[c_m].dest->id)) - { - return &me->partners[c_m]; - } + return &me->partners[c_m]; } + } return NULL; } static struct BenchmarkPeer * -find_peer(const struct GNUNET_PeerIdentity * peer) +find_peer (const struct GNUNET_PeerIdentity *peer) { int c_p; for (c_p = 0; c_p < top->num_masters; c_p++) - { - if (0 == GNUNET_memcmp(&top->mps[c_p].id, - peer)) - return &top->mps[c_p]; - } + { + if (0 == GNUNET_memcmp (&top->mps[c_p].id, + peer)) + return &top->mps[c_p]; + } for (c_p = 0; c_p < top->num_slaves; c_p++) - { - if (0 == GNUNET_memcmp(&top->sps[c_p].id, - peer)) - return &top->sps[c_p]; - } + { + if (0 == GNUNET_memcmp (&top->sps[c_p].id, + peer)) + return &top->sps[c_p]; + } return NULL; } @@ -192,9 +193,9 @@ find_peer(const struct GNUNET_PeerIdentity * peer) * @return the `struct BenchmarkPartner` of @a peer */ static void * -comm_connect_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - struct GNUNET_MQ_Handle *mq) +comm_connect_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + struct GNUNET_MQ_Handle *mq) { struct BenchmarkPeer *me = cls; struct BenchmarkPeer *remote; @@ -203,60 +204,60 @@ comm_connect_cb(void *cls, int c; int completed; - remote = find_peer(peer); + remote = find_peer (peer); if (NULL == remote) - { - GNUNET_log(GNUNET_ERROR_TYPE_WARNING, - "Unknown peer connected: `%s'\n", - GNUNET_i2s(peer)); - GNUNET_break(0); - return NULL; - } - - id = GNUNET_strdup(GNUNET_i2s(&me->id)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%s [%u] `%s' connected to %s [%u] %s\n", - (me->master == GNUNET_YES) ? "Master" : "Slave", - me->no, - id, - (remote->master == GNUNET_YES) ? "Master" : "Slave", - remote->no, - GNUNET_i2s(peer)); + { + GNUNET_log (GNUNET_ERROR_TYPE_WARNING, + "Unknown peer connected: `%s'\n", + GNUNET_i2s (peer)); + GNUNET_break (0); + return NULL; + } + + id = GNUNET_strdup (GNUNET_i2s (&me->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s [%u] `%s' connected to %s [%u] %s\n", + (me->master == GNUNET_YES) ? "Master" : "Slave", + me->no, + id, + (remote->master == GNUNET_YES) ? "Master" : "Slave", + remote->no, + GNUNET_i2s (peer)); me->core_connections++; if ((GNUNET_YES == me->master) && (GNUNET_NO == remote->master) && (GNUNET_NO == top->state.connected_CORE)) + { + me->core_slave_connections++; + + if (me->core_slave_connections == top->num_slaves) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Master [%u] connected all slaves\n", + me->no); + } + completed = GNUNET_YES; + for (c = 0; c < top->num_masters; c++) { - me->core_slave_connections++; - - if (me->core_slave_connections == top->num_slaves) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Master [%u] connected all slaves\n", - me->no); - } - completed = GNUNET_YES; - for (c = 0; c < top->num_masters; c++) - { - if (top->mps[c].core_slave_connections != top->num_slaves) - completed = GNUNET_NO; - } - if (GNUNET_YES == completed) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "All master peers connected all slave peers\n"); - top->state.connected_CORE = GNUNET_YES; - /* Notify about setup done */ - if (NULL != top->done_cb) - top->done_cb(top->done_cb_cls, - top->mps, - top->sps); - } + if (top->mps[c].core_slave_connections != top->num_slaves) + completed = GNUNET_NO; } - GNUNET_free(id); - p = find_partner(me, - peer); + if (GNUNET_YES == completed) + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "All master peers connected all slave peers\n"); + top->state.connected_CORE = GNUNET_YES; + /* Notify about setup done */ + if (NULL != top->done_cb) + top->done_cb (top->done_cb_cls, + top->mps, + top->sps); + } + } + GNUNET_free (id); + p = find_partner (me, + peer); if (NULL != p) p->mq = mq; return p; @@ -269,9 +270,9 @@ comm_connect_cb(void *cls, * @param internal_cls the `struct BenchmarkPartner` of @a peer */ static void -comm_disconnect_cb(void *cls, - const struct GNUNET_PeerIdentity *peer, - void *internal_cls) +comm_disconnect_cb (void *cls, + const struct GNUNET_PeerIdentity *peer, + void *internal_cls) { struct BenchmarkPeer *me = cls; struct BenchmarkPartner *p = internal_cls; @@ -280,170 +281,170 @@ comm_disconnect_cb(void *cls, if (NULL == p) return; - id = GNUNET_strdup(GNUNET_i2s(&me->id)); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%s disconnected from %s\n", - id, - GNUNET_i2s(peer)); - GNUNET_assert(me->core_connections > 0); + id = GNUNET_strdup (GNUNET_i2s (&me->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s disconnected from %s\n", + id, + GNUNET_i2s (peer)); + GNUNET_assert (me->core_connections > 0); me->core_connections--; if ((GNUNET_YES == top->state.benchmarking) && ((GNUNET_YES == me->master) || (GNUNET_YES == p->dest->master))) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "%s disconnected from %s while benchmarking\n", - id, - GNUNET_i2s(peer)); - } - GNUNET_free(id); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "%s disconnected from %s while benchmarking\n", + id, + GNUNET_i2s (peer)); + } + GNUNET_free (id); } static void -handle_pong(void *cls, - const struct TestMessage *message) +handle_pong (void *cls, + const struct TestMessage *message) { struct BenchmarkPartner *p = cls; - GNUNET_ATS_TEST_traffic_handle_pong(p); + GNUNET_ATS_TEST_traffic_handle_pong (p); } static void -handle_ping(void *cls, - const struct TestMessage *message) +handle_ping (void *cls, + const struct TestMessage *message) { struct BenchmarkPartner *p = cls; - GNUNET_ATS_TEST_traffic_handle_ping(p); + GNUNET_ATS_TEST_traffic_handle_ping (p); } static void * -transport_connect_adapter(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +transport_connect_adapter (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct BenchmarkPeer *me = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size(ping, - TEST_MESSAGE_TYPE_PING, - struct TestMessage, - me), - GNUNET_MQ_hd_fixed_size(pong, - TEST_MESSAGE_TYPE_PONG, - struct TestMessage, - me), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_fixed_size (ping, + TEST_MESSAGE_TYPE_PING, + struct TestMessage, + me), + GNUNET_MQ_hd_fixed_size (pong, + TEST_MESSAGE_TYPE_PONG, + struct TestMessage, + me), + GNUNET_MQ_handler_end () }; - me->th = GNUNET_TRANSPORT_core_connect(cfg, - &me->id, - handlers, - me, - &comm_connect_cb, - &comm_disconnect_cb, - NULL); + me->th = GNUNET_TRANSPORT_core_connect (cfg, + &me->id, + handlers, + me, + &comm_connect_cb, + &comm_disconnect_cb, + NULL); if (NULL == me->th) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to create transport connection \n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create transport connection \n"); return me->th; } static void -transport_disconnect_adapter(void *cls, - void *op_result) +transport_disconnect_adapter (void *cls, + void *op_result) { struct BenchmarkPeer *me = cls; - GNUNET_TRANSPORT_core_disconnect(me->th); + GNUNET_TRANSPORT_core_disconnect (me->th); me->th = NULL; } static void * -core_connect_adapter(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +core_connect_adapter (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct BenchmarkPeer *me = cls; struct GNUNET_MQ_MessageHandler handlers[] = { - GNUNET_MQ_hd_fixed_size(ping, - TEST_MESSAGE_TYPE_PING, - struct TestMessage, - me), - GNUNET_MQ_hd_fixed_size(pong, - TEST_MESSAGE_TYPE_PONG, - struct TestMessage, - me), - GNUNET_MQ_handler_end() + GNUNET_MQ_hd_fixed_size (ping, + TEST_MESSAGE_TYPE_PING, + struct TestMessage, + me), + GNUNET_MQ_hd_fixed_size (pong, + TEST_MESSAGE_TYPE_PONG, + struct TestMessage, + me), + GNUNET_MQ_handler_end () }; - me->ch = GNUNET_CORE_connect(cfg, - me, - NULL, - &comm_connect_cb, - &comm_disconnect_cb, - handlers); + me->ch = GNUNET_CORE_connect (cfg, + me, + NULL, + &comm_connect_cb, + &comm_disconnect_cb, + handlers); if (NULL == me->ch) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to create core connection \n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create core connection \n"); return me->ch; } static void -core_disconnect_adapter(void *cls, - void *op_result) +core_disconnect_adapter (void *cls, + void *op_result) { struct BenchmarkPeer *me = cls; - GNUNET_CORE_disconnect(me->ch); + GNUNET_CORE_disconnect (me->ch); me->ch = NULL; } static void -connect_completion_callback(void *cls, - struct GNUNET_TESTBED_Operation *op, - const char *emsg) +connect_completion_callback (void *cls, + struct GNUNET_TESTBED_Operation *op, + const char *emsg) { struct TestbedConnectOperation *cop = cls; static int ops = 0; int c; if (NULL == emsg) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - _("Connected master [%u] with slave [%u]\n"), - cop->master->no, - cop->slave->no); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + _ ("Connected master [%u] with slave [%u]\n"), + cop->master->no, + cop->slave->no); + } else - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - _("Failed to connect master peer [%u] with slave [%u]\n"), - cop->master->no, cop->slave->no); - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - } - GNUNET_TESTBED_operation_done(op); + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + _ ("Failed to connect master peer [%u] with slave [%u]\n"), + cop->master->no, cop->slave->no); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + } + GNUNET_TESTBED_operation_done (op); ops++; for (c = 0; c < top->num_slaves; c++) - { - if (cop == &cop->master->core_connect_ops[c]) - cop->master->core_connect_ops[c].connect_op = NULL; - } + { + if (cop == &cop->master->core_connect_ops[c]) + cop->master->core_connect_ops[c].connect_op = NULL; + } if (ops == top->num_masters * top->num_slaves) - { - top->state.connected_PEERS = GNUNET_YES; - } + { + top->state.connected_PEERS = GNUNET_YES; + } } static void -do_connect_peers(void *cls) +do_connect_peers (void *cls) { int c_m; int c_s; @@ -453,143 +454,144 @@ do_connect_peers(void *cls) (top->state.connected_COMM_service == GNUNET_NO)) return; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connecting peers on CORE level\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connecting peers on CORE level\n"); for (c_m = 0; c_m < top->num_masters; c_m++) + { + p = &top->mps[c_m]; + p->core_connect_ops = GNUNET_malloc (top->num_slaves + * sizeof(struct + TestbedConnectOperation)); + + for (c_s = 0; c_s < top->num_slaves; c_s++) { - p = &top->mps[c_m]; - p->core_connect_ops = GNUNET_malloc(top->num_slaves * - sizeof(struct TestbedConnectOperation)); - - for (c_s = 0; c_s < top->num_slaves; c_s++) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connecting master [%u] with slave [%u]\n", - p->no, - top->sps[c_s].no); - p->core_connect_ops[c_s].master = p; - p->core_connect_ops[c_s].slave = &top->sps[c_s]; - p->core_connect_ops[c_s].connect_op - = GNUNET_TESTBED_overlay_connect(NULL, - &connect_completion_callback, - &p->core_connect_ops[c_s], - top->sps[c_s].peer, - p->peer); - if (NULL == p->core_connect_ops[c_s].connect_op) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Could not connect master [%u] and slave [%u]\n", - p->no, - top->sps[c_s].no); - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } - } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connecting master [%u] with slave [%u]\n", + p->no, + top->sps[c_s].no); + p->core_connect_ops[c_s].master = p; + p->core_connect_ops[c_s].slave = &top->sps[c_s]; + p->core_connect_ops[c_s].connect_op + = GNUNET_TESTBED_overlay_connect (NULL, + &connect_completion_callback, + &p->core_connect_ops[c_s], + top->sps[c_s].peer, + p->peer); + if (NULL == p->core_connect_ops[c_s].connect_op) + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Could not connect master [%u] and slave [%u]\n", + p->no, + top->sps[c_s].no); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } } + } } static void -comm_connect_completion_cb(void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +comm_connect_completion_cb (void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { static int comm_done = 0; if ((NULL != emsg) || (NULL == ca_result)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Initialization failed, shutdown\n"); - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Initialization failed, shutdown\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } comm_done++; if (comm_done == top->num_slaves + top->num_masters) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connected to all %s services\n", - (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); - top->state.connected_COMM_service = GNUNET_YES; - GNUNET_SCHEDULER_add_now(&do_connect_peers, - NULL); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connected to all %s services\n", + (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); + top->state.connected_COMM_service = GNUNET_YES; + GNUNET_SCHEDULER_add_now (&do_connect_peers, + NULL); + } } static void -do_comm_connect(void *cls) +do_comm_connect (void *cls) { int c_s; int c_m; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connecting to all %s services\n", - (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connecting to all %s services\n", + (GNUNET_YES == top->test_core) ? "CORE" : "TRANSPORT"); for (c_m = 0; c_m < top->num_masters; c_m++) + { + if (GNUNET_YES == top->test_core) + top->mps[c_m].comm_op + = GNUNET_TESTBED_service_connect (NULL, + top->mps[c_m].peer, + "core", + &comm_connect_completion_cb, + NULL, + &core_connect_adapter, + &core_disconnect_adapter, + &top->mps[c_m]); + else { - if (GNUNET_YES == top->test_core) - top->mps[c_m].comm_op - = GNUNET_TESTBED_service_connect(NULL, - top->mps[c_m].peer, - "core", - &comm_connect_completion_cb, - NULL, - &core_connect_adapter, - &core_disconnect_adapter, - &top->mps[c_m]); - else - { - top->mps[c_m].comm_op - = GNUNET_TESTBED_service_connect(NULL, - top->mps[c_m].peer, - "transport", - &comm_connect_completion_cb, - NULL, - &transport_connect_adapter, - &transport_disconnect_adapter, - &top->mps[c_m]); - } + top->mps[c_m].comm_op + = GNUNET_TESTBED_service_connect (NULL, + top->mps[c_m].peer, + "transport", + &comm_connect_completion_cb, + NULL, + &transport_connect_adapter, + &transport_disconnect_adapter, + &top->mps[c_m]); } + } for (c_s = 0; c_s < top->num_slaves; c_s++) + { + if (GNUNET_YES == top->test_core) + top->sps[c_s].comm_op + = GNUNET_TESTBED_service_connect (NULL, + top->sps[c_s].peer, + "core", + &comm_connect_completion_cb, + NULL, + &core_connect_adapter, + &core_disconnect_adapter, + &top->sps[c_s]); + else { - if (GNUNET_YES == top->test_core) - top->sps[c_s].comm_op - = GNUNET_TESTBED_service_connect(NULL, - top->sps[c_s].peer, - "core", - &comm_connect_completion_cb, - NULL, - &core_connect_adapter, - &core_disconnect_adapter, - &top->sps[c_s]); - else - { - top->sps[c_s].comm_op - = GNUNET_TESTBED_service_connect(NULL, - top->sps[c_s].peer, - "transport", - &comm_connect_completion_cb, - NULL, - &transport_connect_adapter, - &transport_disconnect_adapter, - &top->sps[c_s]); - } + top->sps[c_s].comm_op + = GNUNET_TESTBED_service_connect (NULL, + top->sps[c_s].peer, + "transport", + &comm_connect_completion_cb, + NULL, + &transport_connect_adapter, + &transport_disconnect_adapter, + &top->sps[c_s]); } + } } static void -ats_performance_info_cb(void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Properties *ats_prop) +ats_performance_info_cb (void *cls, + const struct GNUNET_HELLO_Address *address, + int address_active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Properties *ats_prop) { struct BenchmarkPeer *me = cls; struct BenchmarkPartner *p; @@ -597,36 +599,36 @@ ats_performance_info_cb(void *cls, char *peer_id; if (NULL == address) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Peer %u: ATS Service disconnected!\n", - me->no); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Peer %u: ATS Service disconnected!\n", + me->no); + return; + } - p = find_partner(me, - &address->peer); + p = find_partner (me, + &address->peer); if (NULL == p) - { - /* This is not one of my partners - * Will happen since the peers will connect to each other due to gossiping - */ - return; - } - peer_id = GNUNET_strdup(GNUNET_i2s(&me->id)); + { + /* This is not one of my partners + * Will happen since the peers will connect to each other due to gossiping + */ + return; + } + peer_id = GNUNET_strdup (GNUNET_i2s (&me->id)); log = GNUNET_NO; - if ((p->bandwidth_in != ntohl(bandwidth_in.value__)) || - (p->bandwidth_out != ntohl(bandwidth_out.value__))) + if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) || + (p->bandwidth_out != ntohl (bandwidth_out.value__))) log = GNUNET_YES; - p->bandwidth_in = ntohl(bandwidth_in.value__); - p->bandwidth_out = ntohl(bandwidth_out.value__); + p->bandwidth_in = ntohl (bandwidth_in.value__); + p->bandwidth_out = ntohl (bandwidth_out.value__); - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%s [%u] received ATS information: %s\n", - (GNUNET_YES == p->me->master) ? "Master" : "Slave", - p->me->no, - GNUNET_i2s(&p->dest->id)); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s [%u] received ATS information: %s\n", + (GNUNET_YES == p->me->master) ? "Master" : "Slave", + p->me->no, + GNUNET_i2s (&p->dest->id)); p->props.utilization_out = ats_prop->utilization_out; p->props.utilization_in = ats_prop->utilization_in; @@ -635,137 +637,137 @@ ats_performance_info_cb(void *cls, p->props.distance = ats_prop->distance; if (GNUNET_YES == log) - top->ats_perf_cb(cls, address, - address_active, - bandwidth_out, - bandwidth_in, - ats_prop); - GNUNET_free(peer_id); + top->ats_perf_cb (cls, address, + address_active, + bandwidth_out, + bandwidth_in, + ats_prop); + GNUNET_free (peer_id); } static void * -ats_perf_connect_adapter(void *cls, - const struct GNUNET_CONFIGURATION_Handle *cfg) +ats_perf_connect_adapter (void *cls, + const struct GNUNET_CONFIGURATION_Handle *cfg) { struct BenchmarkPeer *me = cls; me->ats_perf_handle - = GNUNET_ATS_performance_init(cfg, - &ats_performance_info_cb, - me); + = GNUNET_ATS_performance_init (cfg, + &ats_performance_info_cb, + me); if (NULL == me->ats_perf_handle) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, - "Failed to create ATS performance handle \n"); + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Failed to create ATS performance handle \n"); return me->ats_perf_handle; } static void -ats_perf_disconnect_adapter(void *cls, - void *op_result) +ats_perf_disconnect_adapter (void *cls, + void *op_result) { struct BenchmarkPeer *me = cls; - GNUNET_ATS_performance_done(me->ats_perf_handle); + GNUNET_ATS_performance_done (me->ats_perf_handle); me->ats_perf_handle = NULL; } static void -ats_connect_completion_cb(void *cls, - struct GNUNET_TESTBED_Operation *op, - void *ca_result, - const char *emsg) +ats_connect_completion_cb (void *cls, + struct GNUNET_TESTBED_Operation *op, + void *ca_result, + const char *emsg) { static int op_done = 0; if ((NULL != emsg) || (NULL == ca_result)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Initialization failed, shutdown\n"); - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Initialization failed, shutdown\n"); + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + return; + } op_done++; if (op_done == (top->num_masters + top->num_slaves)) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connected to all ATS services\n"); - top->state.connected_ATS_service = GNUNET_YES; - GNUNET_SCHEDULER_add_now(&do_comm_connect, - NULL); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connected to all ATS services\n"); + top->state.connected_ATS_service = GNUNET_YES; + GNUNET_SCHEDULER_add_now (&do_comm_connect, + NULL); + } } static void -do_connect_ats(void *cls) +do_connect_ats (void *cls) { int c_m; int c_s; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Connecting to all ATS services\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Connecting to all ATS services\n"); for (c_m = 0; c_m < top->num_masters; c_m++) - { - top->mps[c_m].ats_perf_op - = GNUNET_TESTBED_service_connect(NULL, - top->mps[c_m].peer, - "ats", - &ats_connect_completion_cb, - NULL, - &ats_perf_connect_adapter, - &ats_perf_disconnect_adapter, - &top->mps[c_m]); - } + { + top->mps[c_m].ats_perf_op + = GNUNET_TESTBED_service_connect (NULL, + top->mps[c_m].peer, + "ats", + &ats_connect_completion_cb, + NULL, + &ats_perf_connect_adapter, + &ats_perf_disconnect_adapter, + &top->mps[c_m]); + } for (c_s = 0; c_s < top->num_slaves; c_s++) - { - top->sps[c_s].ats_perf_op - = GNUNET_TESTBED_service_connect(NULL, - top->sps[c_s].peer, - "ats", - &ats_connect_completion_cb, - NULL, - &ats_perf_connect_adapter, - &ats_perf_disconnect_adapter, - &top->sps[c_s]); - } + { + top->sps[c_s].ats_perf_op + = GNUNET_TESTBED_service_connect (NULL, + top->sps[c_s].peer, + "ats", + &ats_connect_completion_cb, + NULL, + &ats_perf_connect_adapter, + &ats_perf_disconnect_adapter, + &top->sps[c_s]); + } } static void -peerinformation_cb(void *cb_cls, - struct GNUNET_TESTBED_Operation *op, - const struct GNUNET_TESTBED_PeerInformation *pinfo, - const char *emsg) +peerinformation_cb (void *cb_cls, + struct GNUNET_TESTBED_Operation *op, + const struct GNUNET_TESTBED_PeerInformation *pinfo, + const char *emsg) { struct BenchmarkPeer *p = cb_cls; static int done = 0; - GNUNET_assert(pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY); + GNUNET_assert (pinfo->pit == GNUNET_TESTBED_PIT_IDENTITY); p->id = *pinfo->result.id; - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "%s [%u] has peer id `%s'\n", - (p->master == GNUNET_YES) ? "Master" : "Slave", - p->no, - GNUNET_i2s(&p->id)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "%s [%u] has peer id `%s'\n", + (p->master == GNUNET_YES) ? "Master" : "Slave", + p->no, + GNUNET_i2s (&p->id)); - GNUNET_TESTBED_operation_done(op); + GNUNET_TESTBED_operation_done (op); p->peer_id_op = NULL; done++; if (done == top->num_slaves + top->num_masters) - { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Retrieved all peer ID, connect to ATS\n"); - GNUNET_SCHEDULER_add_now(&do_connect_ats, - NULL); - } + { + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Retrieved all peer ID, connect to ATS\n"); + GNUNET_SCHEDULER_add_now (&do_connect_ats, + NULL); + } } @@ -782,85 +784,85 @@ peerinformation_cb(void *cb_cls, * failed */ static void -main_run(void *cls, - struct GNUNET_TESTBED_RunHandle *h, - unsigned int num_peers, - struct GNUNET_TESTBED_Peer **peers_, - unsigned int links_succeeded, - unsigned int links_failed) +main_run (void *cls, + struct GNUNET_TESTBED_RunHandle *h, + unsigned int num_peers, + struct GNUNET_TESTBED_Peer **peers_, + unsigned int links_succeeded, + unsigned int links_failed) { int c_m; int c_s; - GNUNET_assert(NULL == cls); - GNUNET_assert(top->num_masters + top->num_slaves == num_peers); - GNUNET_assert(NULL != peers_); + GNUNET_assert (NULL == cls); + GNUNET_assert (top->num_masters + top->num_slaves == num_peers); + GNUNET_assert (NULL != peers_); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, - top); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + top); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Setting up %u masters and %u slaves\n", - top->num_masters, - top->num_slaves); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Setting up %u masters and %u slaves\n", + top->num_masters, + top->num_slaves); /* Setup master peers */ for (c_m = 0; c_m < top->num_masters; c_m++) + { + GNUNET_assert (NULL != peers_[c_m]); + top->mps[c_m].peer = peers_[c_m]; + top->mps[c_m].no = c_m; + top->mps[c_m].master = GNUNET_YES; + top->mps[c_m].pref_partner = &top->sps[c_m]; + top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT; + top->mps[c_m].partners = + GNUNET_malloc (top->num_slaves * sizeof(struct BenchmarkPartner)); + top->mps[c_m].num_partners = top->num_slaves; + /* Initialize partners */ + for (c_s = 0; c_s < top->num_slaves; c_s++) { - GNUNET_assert(NULL != peers_[c_m]); - top->mps[c_m].peer = peers_[c_m]; - top->mps[c_m].no = c_m; - top->mps[c_m].master = GNUNET_YES; - top->mps[c_m].pref_partner = &top->sps[c_m]; - top->mps[c_m].pref_value = TEST_ATS_PREFERENCE_DEFAULT; - top->mps[c_m].partners = - GNUNET_malloc(top->num_slaves * sizeof(struct BenchmarkPartner)); - top->mps[c_m].num_partners = top->num_slaves; - /* Initialize partners */ - for (c_s = 0; c_s < top->num_slaves; c_s++) - { - top->mps[c_m].partners[c_s].me = &top->mps[c_m]; - top->mps[c_m].partners[c_s].dest = &top->sps[c_s]; - } - /* Get configuration */ - top->mps[c_m].peer_id_op - = GNUNET_TESTBED_peer_get_information(top->mps[c_m].peer, - GNUNET_TESTBED_PIT_IDENTITY, - &peerinformation_cb, - &top->mps[c_m]); + top->mps[c_m].partners[c_s].me = &top->mps[c_m]; + top->mps[c_m].partners[c_s].dest = &top->sps[c_s]; } + /* Get configuration */ + top->mps[c_m].peer_id_op + = GNUNET_TESTBED_peer_get_information (top->mps[c_m].peer, + GNUNET_TESTBED_PIT_IDENTITY, + &peerinformation_cb, + &top->mps[c_m]); + } /* Setup slave peers */ for (c_s = 0; c_s < top->num_slaves; c_s++) + { + GNUNET_assert (NULL != peers_[c_s + top->num_masters]); + top->sps[c_s].peer = peers_[c_s + top->num_masters]; + top->sps[c_s].no = c_s + top->num_masters; + top->sps[c_s].master = GNUNET_NO; + top->sps[c_s].partners = + GNUNET_new_array (top->num_masters, + struct BenchmarkPartner); + top->sps[c_s].num_partners = top->num_masters; + /* Initialize partners */ + for (c_m = 0; c_m < top->num_masters; c_m++) { - GNUNET_assert(NULL != peers_[c_s + top->num_masters]); - top->sps[c_s].peer = peers_[c_s + top->num_masters]; - top->sps[c_s].no = c_s + top->num_masters; - top->sps[c_s].master = GNUNET_NO; - top->sps[c_s].partners = - GNUNET_new_array(top->num_masters, - struct BenchmarkPartner); - top->sps[c_s].num_partners = top->num_masters; - /* Initialize partners */ - for (c_m = 0; c_m < top->num_masters; c_m++) - { - top->sps[c_s].partners[c_m].me = &top->sps[c_s]; - top->sps[c_s].partners[c_m].dest = &top->mps[c_m]; - - /* Initialize properties */ - top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO; - top->sps[c_s].partners[c_m].props.distance = 0; - top->sps[c_s].partners[c_m].props.scope = GNUNET_NT_UNSPECIFIED; - top->sps[c_s].partners[c_m].props.utilization_in = 0; - top->sps[c_s].partners[c_m].props.utilization_out = 0; - } - /* Get configuration */ - top->sps[c_s].peer_id_op - = GNUNET_TESTBED_peer_get_information(top->sps[c_s].peer, - GNUNET_TESTBED_PIT_IDENTITY, - &peerinformation_cb, - &top->sps[c_s]); + top->sps[c_s].partners[c_m].me = &top->sps[c_s]; + top->sps[c_s].partners[c_m].dest = &top->mps[c_m]; + + /* Initialize properties */ + top->sps[c_s].partners[c_m].props.delay = GNUNET_TIME_UNIT_ZERO; + top->sps[c_s].partners[c_m].props.distance = 0; + top->sps[c_s].partners[c_m].props.scope = GNUNET_NT_UNSPECIFIED; + top->sps[c_s].partners[c_m].props.utilization_in = 0; + top->sps[c_s].partners[c_m].props.utilization_out = 0; } + /* Get configuration */ + top->sps[c_s].peer_id_op + = GNUNET_TESTBED_peer_get_information (top->sps[c_s].peer, + GNUNET_TESTBED_PIT_IDENTITY, + &peerinformation_cb, + &top->sps[c_s]); + } } @@ -871,26 +873,26 @@ main_run(void *cls, * @param event the controller event */ static void -controller_event_cb(void *cls, - const struct GNUNET_TESTBED_EventInformation *event) +controller_event_cb (void *cls, + const struct GNUNET_TESTBED_EventInformation *event) { switch (event->type) - { - case GNUNET_TESTBED_ET_CONNECT: - break; + { + case GNUNET_TESTBED_ET_CONNECT: + break; - case GNUNET_TESTBED_ET_OPERATION_FINISHED: - break; + case GNUNET_TESTBED_ET_OPERATION_FINISHED: + break; - default: - GNUNET_break(0); - GNUNET_SCHEDULER_shutdown(); - } + default: + GNUNET_break (0); + GNUNET_SCHEDULER_shutdown (); + } } struct BenchmarkPeer * -GNUNET_ATS_TEST_get_peer(int src) +GNUNET_ATS_TEST_get_peer (int src) { if (src > top->num_masters) return NULL; @@ -899,8 +901,8 @@ GNUNET_ATS_TEST_get_peer(int src) struct BenchmarkPartner * -GNUNET_ATS_TEST_get_partner(int src, - int dest) +GNUNET_ATS_TEST_get_partner (int src, + int dest) { if (src > top->num_masters) return NULL; @@ -923,37 +925,39 @@ GNUNET_ATS_TEST_get_partner(int src, * @param log_request_cb callback to call when logging is required */ void -GNUNET_ATS_TEST_create_topology(char *name, char *cfg_file, - unsigned int num_slaves, - unsigned int num_masters, - int test_core, - GNUNET_ATS_TEST_TopologySetupDoneCallback done_cb, - void *done_cb_cls, - GNUNET_ATS_AddressInformationCallback log_request_cb) +GNUNET_ATS_TEST_create_topology (char *name, char *cfg_file, + unsigned int num_slaves, + unsigned int num_masters, + int test_core, + GNUNET_ATS_TEST_TopologySetupDoneCallback + done_cb, + void *done_cb_cls, + GNUNET_ATS_AddressInformationCallback + log_request_cb) { - top = GNUNET_new(struct GNUNET_ATS_TEST_Topology); + top = GNUNET_new (struct GNUNET_ATS_TEST_Topology); top->num_masters = num_masters; top->num_slaves = num_slaves; top->done_cb = done_cb; top->done_cb_cls = done_cb_cls; top->test_core = test_core; top->ats_perf_cb = log_request_cb; - top->mps = GNUNET_new_array(num_masters, - struct BenchmarkPeer); - top->sps = GNUNET_new_array(num_slaves, - struct BenchmarkPeer); + top->mps = GNUNET_new_array (num_masters, + struct BenchmarkPeer); + top->sps = GNUNET_new_array (num_slaves, + struct BenchmarkPeer); /* Start topology */ uint64_t event_mask; event_mask = 0; event_mask |= (1LL << GNUNET_TESTBED_ET_CONNECT); event_mask |= (1LL << GNUNET_TESTBED_ET_OPERATION_FINISHED); - (void)GNUNET_TESTBED_test_run(name, - cfg_file, - num_slaves + num_masters, - event_mask, - &controller_event_cb, NULL, - &main_run, NULL); + (void) GNUNET_TESTBED_test_run (name, + cfg_file, + num_slaves + num_masters, + event_mask, + &controller_event_cb, NULL, + &main_run, NULL); } @@ -961,11 +965,11 @@ GNUNET_ATS_TEST_create_topology(char *name, char *cfg_file, * Shutdown topology */ void -GNUNET_ATS_TEST_shutdown_topology(void) +GNUNET_ATS_TEST_shutdown_topology (void) { if (NULL == top) return; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); } diff --git a/src/ats-tests/ats-testing.h b/src/ats-tests/ats-testing.h index ff3a40837..017ffef4f 100644 --- a/src/ats-tests/ats-testing.h +++ b/src/ats-tests/ats-testing.h @@ -48,7 +48,8 @@ #define TEST_MESSAGE_SIZE 100 -struct TestMessage { +struct TestMessage +{ struct GNUNET_MessageHeader header; uint8_t padding[TEST_MESSAGE_SIZE - sizeof(struct GNUNET_MessageHeader)]; @@ -65,7 +66,8 @@ struct TrafficGenerator; struct LoggingHandle; -enum GeneratorType { +enum GeneratorType +{ GNUNET_ATS_TEST_TG_LINEAR, GNUNET_ATS_TEST_TG_CONSTANT, GNUNET_ATS_TEST_TG_RANDOM, @@ -106,7 +108,8 @@ typedef void (*GNUNET_ATS_TEST_LogRequest) ( /** * Information we track for a peer in the testbed. */ -struct BenchmarkPeer { +struct BenchmarkPeer +{ /** * Handle with testbed. */ @@ -224,7 +227,8 @@ struct BenchmarkPeer { unsigned int total_bytes_received; }; -struct TrafficGenerator { +struct TrafficGenerator +{ struct TrafficGenerator *prev; struct TrafficGenerator *next; @@ -243,7 +247,8 @@ struct TrafficGenerator { }; -struct PreferenceGenerator { +struct PreferenceGenerator +{ struct PreferenceGenerator *prev; struct PreferenceGenerator *next; @@ -267,7 +272,8 @@ struct PreferenceGenerator { /** * Information about a benchmarking partner */ -struct BenchmarkPartner { +struct BenchmarkPartner +{ /** * The peer itself this partner belongs to */ @@ -353,7 +359,8 @@ struct BenchmarkPartner { /** * Overall state of the performance benchmark */ -struct BenchmarkState { +struct BenchmarkState +{ /** * Are we connected to ATS service of all peers: GNUNET_YES/NO */ @@ -381,7 +388,8 @@ struct BenchmarkState { }; -struct GNUNET_ATS_TEST_Topology { +struct GNUNET_ATS_TEST_Topology +{ /** * Progress task */ @@ -459,7 +467,8 @@ struct GNUNET_ATS_TEST_Topology { void *done_cb_cls; }; -enum OperationType { +enum OperationType +{ START_SEND, STOP_SEND, START_PREFERENCE, @@ -480,7 +489,8 @@ typedef void (*GNUNET_ATS_TESTING_ExperimentDoneCallback) ( /** * An operation in an experiment */ -struct GNUNET_ATS_TEST_Operation { +struct GNUNET_ATS_TEST_Operation +{ struct GNUNET_ATS_TEST_Operation *next; struct GNUNET_ATS_TEST_Operation *prev; @@ -497,7 +507,8 @@ struct GNUNET_ATS_TEST_Operation { enum GNUNET_ATS_PreferenceKind pref_type; }; -struct Episode { +struct Episode +{ int id; struct Episode *next; struct GNUNET_TIME_Relative duration; @@ -507,7 +518,8 @@ struct Episode { }; -struct Experiment { +struct Experiment +{ char *name; char *cfg_file; unsigned long long int num_masters; @@ -538,7 +550,7 @@ extern struct GNUNET_CONFIGURATION_Handle *cfg; * @param e_done_cb the experiment is completed */ void -GNUNET_ATS_TEST_experimentation_run( +GNUNET_ATS_TEST_experimentation_run ( struct Experiment *e, GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb); @@ -551,7 +563,7 @@ GNUNET_ATS_TEST_experimentation_run( * @return the Experiment or NULL on failure */ struct Experiment * -GNUNET_ATS_TEST_experimentation_load(const char *filename); +GNUNET_ATS_TEST_experimentation_load (const char *filename); /** @@ -560,15 +572,15 @@ GNUNET_ATS_TEST_experimentation_load(const char *filename); * @param e the experiment */ void -GNUNET_ATS_TEST_experimentation_stop(struct Experiment *e); +GNUNET_ATS_TEST_experimentation_stop (struct Experiment *e); void -GNUNET_ATS_TEST_traffic_handle_ping(struct BenchmarkPartner *p); +GNUNET_ATS_TEST_traffic_handle_ping (struct BenchmarkPartner *p); void -GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p); +GNUNET_ATS_TEST_traffic_handle_pong (struct BenchmarkPartner *p); /** @@ -585,24 +597,24 @@ GNUNET_ATS_TEST_traffic_handle_pong(struct BenchmarkPartner *p); * @return the traffic generator */ struct TrafficGenerator * -GNUNET_ATS_TEST_generate_traffic_start(struct BenchmarkPeer *src, - struct BenchmarkPartner *dest, - enum GeneratorType type, - unsigned int base_rate, - unsigned int max_rate, - struct GNUNET_TIME_Relative period, - struct GNUNET_TIME_Relative duration); +GNUNET_ATS_TEST_generate_traffic_start (struct BenchmarkPeer *src, + struct BenchmarkPartner *dest, + enum GeneratorType type, + unsigned int base_rate, + unsigned int max_rate, + struct GNUNET_TIME_Relative period, + struct GNUNET_TIME_Relative duration); void -GNUNET_ATS_TEST_generate_traffic_stop(struct TrafficGenerator *tg); +GNUNET_ATS_TEST_generate_traffic_stop (struct TrafficGenerator *tg); /** * Stop all traffic generators */ void -GNUNET_ATS_TEST_generate_traffic_stop_all(void); +GNUNET_ATS_TEST_generate_traffic_stop_all (void); /** @@ -620,7 +632,7 @@ GNUNET_ATS_TEST_generate_traffic_stop_all(void); * @return the traffic generator */ struct PreferenceGenerator * -GNUNET_ATS_TEST_generate_preferences_start( +GNUNET_ATS_TEST_generate_preferences_start ( struct BenchmarkPeer *src, struct BenchmarkPartner *dest, enum GeneratorType type, @@ -632,11 +644,11 @@ GNUNET_ATS_TEST_generate_preferences_start( void -GNUNET_ATS_TEST_generate_preferences_stop(struct PreferenceGenerator *pg); +GNUNET_ATS_TEST_generate_preferences_stop (struct PreferenceGenerator *pg); void -GNUNET_ATS_TEST_generate_preferences_stop_all(void); +GNUNET_ATS_TEST_generate_preferences_stop_all (void); /** @@ -651,12 +663,12 @@ GNUNET_ATS_TEST_generate_preferences_stop_all(void); * @return the logging handle or NULL on error */ struct LoggingHandle * -GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency, - const char *testname, - struct BenchmarkPeer *masters, - int num_masters, - int num_slaves, - int verbose); +GNUNET_ATS_TEST_logging_start (struct GNUNET_TIME_Relative log_frequency, + const char *testname, + struct BenchmarkPeer *masters, + int num_masters, + int num_slaves, + int verbose); /** @@ -665,7 +677,7 @@ GNUNET_ATS_TEST_logging_start(struct GNUNET_TIME_Relative log_frequency, * @param l the logging handle */ void -GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l); +GNUNET_ATS_TEST_logging_clean_up (struct LoggingHandle *l); /** @@ -674,7 +686,7 @@ GNUNET_ATS_TEST_logging_clean_up(struct LoggingHandle *l); * @param l the logging handle */ void -GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l); +GNUNET_ATS_TEST_logging_stop (struct LoggingHandle *l); /** @@ -683,7 +695,7 @@ GNUNET_ATS_TEST_logging_stop(struct LoggingHandle *l); * @param l logging handle to use */ void -GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l); +GNUNET_ATS_TEST_logging_now (struct LoggingHandle *l); /** @@ -694,20 +706,20 @@ GNUNET_ATS_TEST_logging_now(struct LoggingHandle *l); * @param plots create gnuplots: #GNUNET_YES or #GNUNET_NO */ void -GNUNET_ATS_TEST_logging_write_to_file(struct LoggingHandle *l, - const char *test_name, - int plots); +GNUNET_ATS_TEST_logging_write_to_file (struct LoggingHandle *l, + const char *test_name, + int plots); /** * Topology related functions */ struct BenchmarkPeer * -GNUNET_ATS_TEST_get_peer(int src); +GNUNET_ATS_TEST_get_peer (int src); struct BenchmarkPartner * -GNUNET_ATS_TEST_get_partner(int src, int dest); +GNUNET_ATS_TEST_get_partner (int src, int dest); /** @@ -724,7 +736,7 @@ GNUNET_ATS_TEST_get_partner(int src, int dest); * @param log_request_cb callback to call when logging is required */ void -GNUNET_ATS_TEST_create_topology( +GNUNET_ATS_TEST_create_topology ( char *name, char *cfg_file, unsigned int num_slaves, @@ -739,7 +751,7 @@ GNUNET_ATS_TEST_create_topology( * Shutdown topology */ void -GNUNET_ATS_TEST_shutdown_topology(void); +GNUNET_ATS_TEST_shutdown_topology (void); /* end of file ats-testing.h */ diff --git a/src/ats-tests/gnunet-ats-sim.c b/src/ats-tests/gnunet-ats-sim.c index d6168d388..c9e7a6d9f 100644 --- a/src/ats-tests/gnunet-ats-sim.c +++ b/src/ats-tests/gnunet-ats-sim.c @@ -32,7 +32,8 @@ #include "gnunet_core_service.h" #include "ats-testing.h" -#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) +#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + 10) static struct BenchmarkPeer *masters_p; static struct BenchmarkPeer *slaves_p; @@ -65,7 +66,7 @@ static struct LoggingHandle *l; static void -evaluate(struct GNUNET_TIME_Relative duration_total) +evaluate (struct GNUNET_TIME_Relative duration_total) { int c_m; int c_s; @@ -84,166 +85,168 @@ evaluate(struct GNUNET_TIME_Relative duration_total) if (0 == duration) duration = 1; for (c_m = 0; c_m < e->num_masters; c_m++) + { + mp = &masters_p[c_m]; + fprintf (stderr, + _ ( + "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"), + mp->no, mp->total_bytes_sent / 1024, + duration, + (mp->total_bytes_sent / 1024) / duration, + mp->total_bytes_received / 1024, + duration, + (mp->total_bytes_received / 1024) / duration); + + for (c_s = 0; c_s < e->num_slaves; c_s++) { - mp = &masters_p[c_m]; - fprintf(stderr, - _("Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n"), - mp->no, mp->total_bytes_sent / 1024, - duration, - (mp->total_bytes_sent / 1024) / duration, - mp->total_bytes_received / 1024, - duration, - (mp->total_bytes_received / 1024) / duration); - - for (c_s = 0; c_s < e->num_slaves; c_s++) - { - p = &mp->partners[c_s]; - - b_sent_sec = 0; - b_recv_sec = 0; - kb_sent_percent = 0.0; - kb_recv_percent = 0.0; - rtt = 0; - - if (duration > 0) - { - b_sent_sec = p->bytes_sent / duration; - b_recv_sec = p->bytes_received / duration; - } - - if (mp->total_bytes_sent > 0) - kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent; - if (mp->total_bytes_received > 0) - kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received; - if (1000 * p->messages_sent > 0) - rtt = p->total_app_rtt / (1000 * p->messages_sent); - fprintf(stderr, - "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n", - (mp->pref_partner == p->dest) ? '*' : ' ', - mp->no, p->dest->no, - b_sent_sec, kb_sent_percent, - b_recv_sec, kb_recv_percent); - fprintf(stderr, - "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", - (mp->pref_partner == p->dest) ? '*' : ' ', - mp->no, p->dest->no, rtt); - } + p = &mp->partners[c_s]; + + b_sent_sec = 0; + b_recv_sec = 0; + kb_sent_percent = 0.0; + kb_recv_percent = 0.0; + rtt = 0; + + if (duration > 0) + { + b_sent_sec = p->bytes_sent / duration; + b_recv_sec = p->bytes_received / duration; + } + + if (mp->total_bytes_sent > 0) + kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent; + if (mp->total_bytes_received > 0) + kb_recv_percent = ((double) p->bytes_received * 100) + / mp->total_bytes_received; + if (1000 * p->messages_sent > 0) + rtt = p->total_app_rtt / (1000 * p->messages_sent); + fprintf (stderr, + "%c Master [%u] -> Slave [%u]: sent %u Bips (%.2f %%), received %u Bips (%.2f %%)\n", + (mp->pref_partner == p->dest) ? '*' : ' ', + mp->no, p->dest->no, + b_sent_sec, kb_sent_percent, + b_recv_sec, kb_recv_percent); + fprintf (stderr, + "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", + (mp->pref_partner == p->dest) ? '*' : ' ', + mp->no, p->dest->no, rtt); } + } } static void -do_shutdown(void *cls) +do_shutdown (void *cls) { - fprintf(stderr, "Shutdown\n"); + fprintf (stderr, "Shutdown\n"); if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = NULL; + } if (NULL != l) - { - GNUNET_ATS_TEST_logging_stop(l); - GNUNET_ATS_TEST_logging_clean_up(l); - l = NULL; - } + { + GNUNET_ATS_TEST_logging_stop (l); + GNUNET_ATS_TEST_logging_clean_up (l); + l = NULL; + } /* Stop traffic generation */ - GNUNET_ATS_TEST_generate_traffic_stop_all(); + GNUNET_ATS_TEST_generate_traffic_stop_all (); /* Stop all preference generations */ - GNUNET_ATS_TEST_generate_preferences_stop_all(); + GNUNET_ATS_TEST_generate_preferences_stop_all (); if (NULL != e) - { - GNUNET_ATS_TEST_experimentation_stop(e); - e = NULL; - } - GNUNET_ATS_TEST_shutdown_topology(); + { + GNUNET_ATS_TEST_experimentation_stop (e); + e = NULL; + } + GNUNET_ATS_TEST_shutdown_topology (); } static void -do_timeout(void *cls) +do_timeout (void *cls) { timeout_task = NULL; - GNUNET_SCHEDULER_shutdown(); + GNUNET_SCHEDULER_shutdown (); } static void -log_request__cb(void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Properties *ats) +log_request__cb (void *cls, + const struct GNUNET_HELLO_Address *address, + int address_active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Properties *ats) { if (NULL != l) - { - //GNUNET_break (0); - //GNUNET_ATS_TEST_logging_now (l); - } + { + // GNUNET_break (0); + // GNUNET_ATS_TEST_logging_now (l); + } } static void -experiment_done_cb(struct Experiment *e, - struct GNUNET_TIME_Relative duration, - int success) +experiment_done_cb (struct Experiment *e, + struct GNUNET_TIME_Relative duration, + int success) { if (GNUNET_OK == success) - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Experiment done successful in %s\n", - GNUNET_STRINGS_relative_time_to_string(duration, - GNUNET_YES)); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Experiment done successful in %s\n", + GNUNET_STRINGS_relative_time_to_string (duration, + GNUNET_YES)); else - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, "Experiment failed \n"); /* Stop logging */ - GNUNET_ATS_TEST_logging_stop(l); + GNUNET_ATS_TEST_logging_stop (l); /* Stop traffic generation */ - GNUNET_ATS_TEST_generate_traffic_stop_all(); + GNUNET_ATS_TEST_generate_traffic_stop_all (); /* Stop all preference generations */ - GNUNET_ATS_TEST_generate_preferences_stop_all(); + GNUNET_ATS_TEST_generate_preferences_stop_all (); - evaluate(duration); + evaluate (duration); if (opt_log) - GNUNET_ATS_TEST_logging_write_to_file(l, opt_exp_file, opt_plot); - GNUNET_SCHEDULER_shutdown(); + GNUNET_ATS_TEST_logging_write_to_file (l, opt_exp_file, opt_plot); + GNUNET_SCHEDULER_shutdown (); } static void -episode_done_cb(struct Episode *ep) +episode_done_cb (struct Episode *ep) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Episode %u done\n", - ep->id); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Episode %u done\n", + ep->id); } static void -topology_setup_done(void *cls, - struct BenchmarkPeer *masters, - struct BenchmarkPeer *slaves) +topology_setup_done (void *cls, + struct BenchmarkPeer *masters, + struct BenchmarkPeer *slaves) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Topology setup complete!\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Topology setup complete!\n"); masters_p = masters; slaves_p = slaves; - l = GNUNET_ATS_TEST_logging_start(e->log_freq, - e->name, - masters_p, - e->num_masters, e->num_slaves, - opt_verbose); - GNUNET_ATS_TEST_experimentation_run(e, - &episode_done_cb, - &experiment_done_cb); + l = GNUNET_ATS_TEST_logging_start (e->log_freq, + e->name, + masters_p, + e->num_masters, e->num_slaves, + opt_verbose); + GNUNET_ATS_TEST_experimentation_run (e, + &episode_done_cb, + &experiment_done_cb); /* GNUNET_ATS_TEST_generate_preferences_start(&masters[0],&masters[0].partners[0], GNUNET_ATS_TEST_TG_CONSTANT, 1, 1, GNUNET_TIME_UNIT_SECONDS, @@ -275,58 +278,59 @@ topology_setup_done(void *cls, int c_m; int c_s; for (c_m = 0; c_m < e->num_masters; c_m++) + { + for (c_s = 0; c_s < e->num_slaves; c_s++) { - for (c_s = 0; c_s < e->num_slaves; c_s++) - { - /* Generate maximum traffic to all peers */ - /* Example: Generate traffic with constant 10,000 Bytes/s */ - GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], - &masters[c_m].partners[c_s], - GNUNET_ATS_TEST_TG_CONSTANT, - 10000, - GNUNET_TIME_UNIT_FOREVER_REL); - /* Example: Generate traffic with an increasing rate from 1000 to 2000 - * Bytes/s with in a minute */ - GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], - &masters[c_m].partners[c_s], - GNUNET_ATS_TEST_TG_LINEAR, - 1000, - 2000, - GNUNET_TIME_UNIT_MINUTES, - GNUNET_TIME_UNIT_FOREVER_REL); - /* Example: Generate traffic with a random rate between 1000 to 2000 - * Bytes/s */ - GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], - &masters[c_m].partners[c_s], - GNUNET_ATS_TEST_TG_RANDOM, - 1000, - 2000, - GNUNET_TIME_UNIT_FOREVER_REL, - GNUNET_TIME_UNIT_FOREVER_REL); - /* Example: Generate traffic with a sinus form, a base rate of - * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */ - GNUNET_ATS_TEST_generate_traffic_start(&masters[c_m], - &masters[c_m].partners[c_s], - GNUNET_ATS_TEST_TG_SINUS, - 1000, - 2000, - GNUNET_TIME_UNIT_MINUTES, - GNUNET_TIME_UNIT_FOREVER_REL); - } + /* Generate maximum traffic to all peers */ + /* Example: Generate traffic with constant 10,000 Bytes/s */ + GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m], + &masters[c_m].partners[c_s], + GNUNET_ATS_TEST_TG_CONSTANT, + 10000, + GNUNET_TIME_UNIT_FOREVER_REL); + /* Example: Generate traffic with an increasing rate from 1000 to 2000 + * Bytes/s with in a minute */ + GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m], + &masters[c_m].partners[c_s], + GNUNET_ATS_TEST_TG_LINEAR, + 1000, + 2000, + GNUNET_TIME_UNIT_MINUTES, + GNUNET_TIME_UNIT_FOREVER_REL); + /* Example: Generate traffic with a random rate between 1000 to 2000 + * Bytes/s */ + GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m], + &masters[c_m].partners[c_s], + GNUNET_ATS_TEST_TG_RANDOM, + 1000, + 2000, + GNUNET_TIME_UNIT_FOREVER_REL, + GNUNET_TIME_UNIT_FOREVER_REL); + /* Example: Generate traffic with a sinus form, a base rate of + * 1000 Bytes/s, an amplitude of (max-base), and a period of 1 minute */ + GNUNET_ATS_TEST_generate_traffic_start (&masters[c_m], + &masters[c_m].partners[c_s], + GNUNET_ATS_TEST_TG_SINUS, + 1000, + 2000, + GNUNET_TIME_UNIT_MINUTES, + GNUNET_TIME_UNIT_FOREVER_REL); } + } #endif timeout_task - = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_relative_add(GNUNET_TIME_UNIT_MINUTES, - e->max_duration), - &do_timeout, - NULL); - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, NULL); + = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_relative_add ( + GNUNET_TIME_UNIT_MINUTES, + e->max_duration), + &do_timeout, + NULL); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, NULL); } static void -parse_args(int argc, char *argv[]) +parse_args (int argc, char *argv[]) { int c; @@ -335,62 +339,62 @@ parse_args(int argc, char *argv[]) opt_plot = GNUNET_NO; for (c = 0; c < argc; c++) + { + if ((c < (argc - 1)) && (0 == strcmp (argv[c], "-e"))) + { + GNUNET_free_non_null (opt_exp_file); + opt_exp_file = GNUNET_strdup (argv[c + 1]); + } + if (0 == strcmp (argv[c], "-l")) { - if ((c < (argc - 1)) && (0 == strcmp(argv[c], "-e"))) - { - GNUNET_free_non_null(opt_exp_file); - opt_exp_file = GNUNET_strdup(argv[c + 1]); - } - if (0 == strcmp(argv[c], "-l")) - { - opt_log = GNUNET_YES; - } - if (0 == strcmp(argv[c], "-p")) - { - opt_plot = GNUNET_YES; - } - if (0 == strcmp(argv[c], "-v")) - { - opt_verbose = GNUNET_YES; - } + opt_log = GNUNET_YES; } + if (0 == strcmp (argv[c], "-p")) + { + opt_plot = GNUNET_YES; + } + if (0 == strcmp (argv[c], "-v")) + { + opt_verbose = GNUNET_YES; + } + } } int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { - GNUNET_log_setup("gnunet-ats-sim", "INFO", NULL); + GNUNET_log_setup ("gnunet-ats-sim", "INFO", NULL); - parse_args(argc, argv); + parse_args (argc, argv); if (NULL == opt_exp_file) - { - fprintf(stderr, "No experiment given...\n"); - return 1; - } + { + fprintf (stderr, "No experiment given...\n"); + return 1; + } - fprintf(stderr, "Loading experiment `%s' \n", opt_exp_file); - e = GNUNET_ATS_TEST_experimentation_load(opt_exp_file); + fprintf (stderr, "Loading experiment `%s' \n", opt_exp_file); + e = GNUNET_ATS_TEST_experimentation_load (opt_exp_file); if (NULL == e) - { - fprintf(stderr, "Invalid experiment\n"); - return 1; - } + { + fprintf (stderr, "Invalid experiment\n"); + return 1; + } if (0 == e->num_episodes) - { - fprintf(stderr, "No episodes included\n"); - return 1; - } + { + fprintf (stderr, "No episodes included\n"); + return 1; + } /* Setup a topology with */ - GNUNET_ATS_TEST_create_topology("gnunet-ats-sim", e->cfg_file, - e->num_slaves, - e->num_masters, - GNUNET_NO, - &topology_setup_done, - NULL, - &log_request__cb); - GNUNET_free(opt_exp_file); + GNUNET_ATS_TEST_create_topology ("gnunet-ats-sim", e->cfg_file, + e->num_slaves, + e->num_masters, + GNUNET_NO, + &topology_setup_done, + NULL, + &log_request__cb); + GNUNET_free (opt_exp_file); return 0; } /* end of file gnunet-ats-sim.c */ diff --git a/src/ats-tests/gnunet-solver-eval.c b/src/ats-tests/gnunet-solver-eval.c index b5e00bd6f..bc6a3c435 100644 --- a/src/ats-tests/gnunet-solver-eval.c +++ b/src/ats-tests/gnunet-solver-eval.c @@ -34,35 +34,35 @@ * Experiments */ const char * -print_op(enum OperationType op) +print_op (enum OperationType op) { switch (op) - { - case START_SEND: - return "START_SEND"; + { + case START_SEND: + return "START_SEND"; - case STOP_SEND: - return "STOP_SEND"; + case STOP_SEND: + return "STOP_SEND"; - case START_PREFERENCE: - return "START_PREFERENCE"; + case START_PREFERENCE: + return "START_PREFERENCE"; - case STOP_PREFERENCE: - return "STOP_PREFERENCE"; + case STOP_PREFERENCE: + return "STOP_PREFERENCE"; - default: - break; - } + default: + break; + } return ""; } static struct Experiment * -create_experiment() +create_experiment () { struct Experiment *e; - e = GNUNET_new(struct Experiment); + e = GNUNET_new (struct Experiment); e->name = NULL; e->num_masters = 0; e->num_slaves = 0; @@ -73,7 +73,7 @@ create_experiment() static void -free_experiment(struct Experiment *e) +free_experiment (struct Experiment *e) { struct Episode *cur; struct Episode *next; @@ -82,28 +82,28 @@ free_experiment(struct Experiment *e) next = e->start; for (cur = next; NULL != cur; cur = next) - { - next = cur->next; + { + next = cur->next; - next_o = cur->head; - for (cur_o = next_o; NULL != cur_o; cur_o = next_o) - { - next_o = cur_o->next; - GNUNET_free(cur_o); - } - GNUNET_free(cur); + next_o = cur->head; + for (cur_o = next_o; NULL != cur_o; cur_o = next_o) + { + next_o = cur_o->next; + GNUNET_free (cur_o); } + GNUNET_free (cur); + } - GNUNET_free_non_null(e->name); - GNUNET_free_non_null(e->cfg_file); - GNUNET_free(e); + GNUNET_free_non_null (e->name); + GNUNET_free_non_null (e->cfg_file); + GNUNET_free (e); } static int -load_episode(struct Experiment *e, - struct Episode *cur, - struct GNUNET_CONFIGURATION_Handle *cfg) +load_episode (struct Experiment *e, + struct Episode *cur, + struct GNUNET_CONFIGURATION_Handle *cfg) { struct GNUNET_ATS_TEST_Operation *o; char *sec_name; @@ -113,284 +113,303 @@ load_episode(struct Experiment *e, char *pref; int op_counter = 0; - fprintf(stderr, "Parsing episode %u\n", cur->id); - GNUNET_asprintf(&sec_name, "episode-%u", cur->id); + fprintf (stderr, "Parsing episode %u\n", cur->id); + GNUNET_asprintf (&sec_name, "episode-%u", cur->id); while (1) + { + /* Load operation */ + GNUNET_asprintf (&op_name, "op-%u-operation", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + sec_name, + op_name, &op)) { - /* Load operation */ - GNUNET_asprintf(&op_name, "op-%u-operation", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, - sec_name, op_name, &op)) - { - GNUNET_free(op_name); - break; - } - o = GNUNET_new(struct GNUNET_ATS_TEST_Operation); - /* operations = set_rate, start_send, stop_send, set_preference */ - if (0 == strcmp(op, "start_send")) - { - o->type = START_SEND; - } - else if (0 == strcmp(op, "stop_send")) - { - o->type = STOP_SEND; - } - else if (0 == strcmp(op, "start_preference")) - { - o->type = START_PREFERENCE; - } - else if (0 == strcmp(op, "stop_preference")) - { - o->type = STOP_PREFERENCE; - } + GNUNET_free (op_name); + break; + } + o = GNUNET_new (struct GNUNET_ATS_TEST_Operation); + /* operations = set_rate, start_send, stop_send, set_preference */ + if (0 == strcmp (op, "start_send")) + { + o->type = START_SEND; + } + else if (0 == strcmp (op, "stop_send")) + { + o->type = STOP_SEND; + } + else if (0 == strcmp (op, "start_preference")) + { + o->type = START_PREFERENCE; + } + else if (0 == strcmp (op, "stop_preference")) + { + o->type = STOP_PREFERENCE; + } + else + { + fprintf (stderr, "Invalid operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get source */ + GNUNET_asprintf (&op_name, "op-%u-src", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->src_id)) + { + fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + if (o->src_id > (e->num_masters - 1)) + { + fprintf (stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", + o->src_id, op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get destination */ + GNUNET_asprintf (&op_name, "op-%u-dest", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->dest_id)) + { + fprintf (stderr, "Missing src in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + if (o->dest_id > (e->num_slaves - 1)) + { + fprintf (stderr, + "Invalid destination %llu in operation %u `%s' in episode %u\n", + o->dest_id, + op_counter, + op, + cur->id); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + GNUNET_asprintf (&op_name, "op-%u-type", op_counter); + if ((GNUNET_SYSERR != + GNUNET_CONFIGURATION_get_value_string (cfg, + sec_name, + op_name, + &type)) && + (STOP_SEND != o->type) && + (STOP_PREFERENCE != o->type)) + { + /* Load arguments for set_rate, start_send, set_preference */ + if (0 == strcmp (type, "constant")) + { + o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; + } + else if (0 == strcmp (type, "linear")) + { + o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; + } + else if (0 == strcmp (type, "sinus")) + { + o->gen_type = GNUNET_ATS_TEST_TG_SINUS; + } + else if (0 == strcmp (type, "random")) + { + o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; + } else + { + fprintf (stderr, "Invalid type %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get base rate */ + GNUNET_asprintf (&op_name, "op-%u-base-rate", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->base_rate)) + { + fprintf (stderr, + "Missing base rate in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op); + GNUNET_free (op_name); + GNUNET_free (sec_name); + GNUNET_free (o); + return GNUNET_SYSERR; + } + GNUNET_free (op_name); + + /* Get max rate */ + GNUNET_asprintf (&op_name, "op-%u-max-rate", op_counter); + if (GNUNET_SYSERR == + GNUNET_CONFIGURATION_get_value_number (cfg, + sec_name, + op_name, + &o->max_rate)) + { + if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || + (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || + (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) { - fprintf(stderr, "Invalid operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); + fprintf (stderr, + "Missing max rate in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free (sec_name); + GNUNET_free (o); return GNUNET_SYSERR; } - GNUNET_free(op_name); - - /* Get source */ - GNUNET_asprintf(&op_name, "op-%u-src", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, op_name, &o->src_id)) + } + GNUNET_free (op_name); + + /* Get period */ + GNUNET_asprintf (&op_name, "op-%u-period", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, + sec_name, + op_name, + &o->period)) + { + o->period = cur->duration; + } + GNUNET_free (op_name); + + if (START_PREFERENCE == o->type) + { + /* Get frequency */ + GNUNET_asprintf (&op_name, "op-%u-frequency", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, + sec_name, + op_name, + &o->frequency)) { - fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); + fprintf (stderr, + "Missing frequency in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free (sec_name); + GNUNET_free (o); return GNUNET_SYSERR; } - if (o->src_id > (e->num_masters - 1)) + GNUNET_free (op_name); + + /* Get preference */ + GNUNET_asprintf (&op_name, "op-%u-pref", op_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, + sec_name, + op_name, + &pref)) { - fprintf(stderr, "Invalid src %llu in operation %u `%s' in episode %u\n", - o->src_id, op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); + fprintf (stderr, + "Missing preference in operation %u `%s' in episode %u\n", + op_counter, op, cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free (sec_name); + GNUNET_free_non_null (pref); + GNUNET_free (o); return GNUNET_SYSERR; } - GNUNET_free(op_name); - /* Get destination */ - GNUNET_asprintf(&op_name, "op-%u-dest", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, op_name, &o->dest_id)) + if (0 == strcmp (pref, "bandwidth")) + o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH; + else if (0 == strcmp (pref, "latency")) + o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY; + else { - fprintf(stderr, "Missing src in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); + fprintf (stderr, + "Invalid preference in operation %u `%s' in episode %u\n", + op_counter, + op, + cur->id); + GNUNET_free (type); + GNUNET_free (op_name); + GNUNET_free (op); + GNUNET_free (sec_name); + GNUNET_free_non_null (pref); + GNUNET_free (o); return GNUNET_SYSERR; } - if (o->dest_id > (e->num_slaves - 1)) - { - fprintf(stderr, - "Invalid destination %llu in operation %u `%s' in episode %u\n", - o->dest_id, - op_counter, - op, - cur->id); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - GNUNET_asprintf(&op_name, "op-%u-type", op_counter); - if ((GNUNET_SYSERR != - GNUNET_CONFIGURATION_get_value_string(cfg, - sec_name, - op_name, - &type)) && - (STOP_SEND != o->type) && - (STOP_PREFERENCE != o->type)) - { - /* Load arguments for set_rate, start_send, set_preference */ - if (0 == strcmp(type, "constant")) - { - o->gen_type = GNUNET_ATS_TEST_TG_CONSTANT; - } - else if (0 == strcmp(type, "linear")) - { - o->gen_type = GNUNET_ATS_TEST_TG_LINEAR; - } - else if (0 == strcmp(type, "sinus")) - { - o->gen_type = GNUNET_ATS_TEST_TG_SINUS; - } - else if (0 == strcmp(type, "random")) - { - o->gen_type = GNUNET_ATS_TEST_TG_RANDOM; - } - else - { - fprintf(stderr, "Invalid type %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - /* Get base rate */ - GNUNET_asprintf(&op_name, "op-%u-base-rate", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, op_name, &o->base_rate)) - { - fprintf(stderr, "Missing base rate in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op); - GNUNET_free(op_name); - GNUNET_free(sec_name); - GNUNET_free(o); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - /* Get max rate */ - GNUNET_asprintf(&op_name, "op-%u-max-rate", op_counter); - if (GNUNET_SYSERR == - GNUNET_CONFIGURATION_get_value_number(cfg, - sec_name, - op_name, - &o->max_rate)) - { - if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || - (GNUNET_ATS_TEST_TG_RANDOM == o->gen_type) || - (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) - { - fprintf(stderr, "Missing max rate in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free(sec_name); - GNUNET_free(o); - return GNUNET_SYSERR; - } - } - GNUNET_free(op_name); - - /* Get period */ - GNUNET_asprintf(&op_name, "op-%u-period", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, - sec_name, op_name, &o->period)) - { - o->period = cur->duration; - } - GNUNET_free(op_name); - - if (START_PREFERENCE == o->type) - { - /* Get frequency */ - GNUNET_asprintf(&op_name, "op-%u-frequency", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, - sec_name, op_name, &o->frequency)) - { - fprintf(stderr, "Missing frequency in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free(sec_name); - GNUNET_free(o); - return GNUNET_SYSERR; - } - GNUNET_free(op_name); - - /* Get preference */ - GNUNET_asprintf(&op_name, "op-%u-pref", op_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, - sec_name, op_name, &pref)) - { - fprintf(stderr, "Missing preference in operation %u `%s' in episode %u\n", - op_counter, op, cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free(sec_name); - GNUNET_free_non_null(pref); - GNUNET_free(o); - return GNUNET_SYSERR; - } - - if (0 == strcmp(pref, "bandwidth")) - o->pref_type = GNUNET_ATS_PREFERENCE_BANDWIDTH; - else if (0 == strcmp(pref, "latency")) - o->pref_type = GNUNET_ATS_PREFERENCE_LATENCY; - else - { - fprintf(stderr, - "Invalid preference in operation %u `%s' in episode %u\n", - op_counter, - op, - cur->id); - GNUNET_free(type); - GNUNET_free(op_name); - GNUNET_free(op); - GNUNET_free(sec_name); - GNUNET_free_non_null(pref); - GNUNET_free(o); - return GNUNET_SYSERR; - } - GNUNET_free(pref); - GNUNET_free(op_name); - } - } - - /* Safety checks */ - if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || - (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) - { - if ((o->max_rate - o->base_rate) > o->base_rate) - { - /* This will cause an underflow */ - GNUNET_break(0); - } - fprintf(stderr, "Selected max rate and base rate cannot be used for desired traffic form!\n"); - } - - if ((START_SEND == o->type) || (START_PREFERENCE == o->type)) - fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n", - op_counter, cur->id, print_op(o->type), o->src_id, - o->dest_id, (NULL != type) ? type : "", - o->base_rate, o->max_rate, - GNUNET_STRINGS_relative_time_to_string(o->period, GNUNET_YES)); - else - fprintf(stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n", - op_counter, cur->id, print_op(o->type), o->src_id, o->dest_id); - - GNUNET_free_non_null(type); - GNUNET_free(op); + GNUNET_free (pref); + GNUNET_free (op_name); + } + } - GNUNET_CONTAINER_DLL_insert(cur->head, cur->tail, o); - op_counter++; + /* Safety checks */ + if ((GNUNET_ATS_TEST_TG_LINEAR == o->gen_type) || + (GNUNET_ATS_TEST_TG_SINUS == o->gen_type)) + { + if ((o->max_rate - o->base_rate) > o->base_rate) + { + /* This will cause an underflow */ + GNUNET_break (0); + } + fprintf (stderr, + "Selected max rate and base rate cannot be used for desired traffic form!\n"); } - GNUNET_free(sec_name); + + if ((START_SEND == o->type) || (START_PREFERENCE == o->type)) + fprintf (stderr, + "Found operation %u in episode %u: %s [%llu]->[%llu] == %s, %llu -> %llu in %s\n", + op_counter, cur->id, print_op (o->type), o->src_id, + o->dest_id, (NULL != type) ? type : "", + o->base_rate, o->max_rate, + GNUNET_STRINGS_relative_time_to_string (o->period, GNUNET_YES)); + else + fprintf (stderr, "Found operation %u in episode %u: %s [%llu]->[%llu]\n", + op_counter, cur->id, print_op (o->type), o->src_id, o->dest_id); + + GNUNET_free_non_null (type); + GNUNET_free (op); + + GNUNET_CONTAINER_DLL_insert (cur->head, cur->tail, o); + op_counter++; + } + GNUNET_free (sec_name); return GNUNET_OK; } static int -load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) +load_episodes (struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) { int e_counter = 0; char *sec_name; @@ -401,68 +420,72 @@ load_episodes(struct Experiment *e, struct GNUNET_CONFIGURATION_Handle *cfg) e_counter = 0; last = NULL; while (1) + { + GNUNET_asprintf (&sec_name, "episode-%u", e_counter); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, + sec_name, + "duration", + &e_duration)) { - GNUNET_asprintf(&sec_name, "episode-%u", e_counter); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, - sec_name, "duration", &e_duration)) - { - GNUNET_free(sec_name); - break; - } - - cur = GNUNET_new(struct Episode); - cur->duration = e_duration; - cur->id = e_counter; - - if (GNUNET_OK != load_episode(e, cur, cfg)) - { - GNUNET_free(sec_name); - GNUNET_free(cur); - return GNUNET_SYSERR; - } - - fprintf(stderr, "Found episode %u with duration %s \n", - e_counter, - GNUNET_STRINGS_relative_time_to_string(cur->duration, GNUNET_YES)); + GNUNET_free (sec_name); + break; + } - /* Update experiment */ - e->num_episodes++; - e->total_duration = GNUNET_TIME_relative_add(e->total_duration, cur->duration); - /* Put in linked list */ - if (NULL == last) - e->start = cur; - else - last->next = cur; + cur = GNUNET_new (struct Episode); + cur->duration = e_duration; + cur->id = e_counter; - GNUNET_free(sec_name); - e_counter++; - last = cur; + if (GNUNET_OK != load_episode (e, cur, cfg)) + { + GNUNET_free (sec_name); + GNUNET_free (cur); + return GNUNET_SYSERR; } + + fprintf (stderr, "Found episode %u with duration %s \n", + e_counter, + GNUNET_STRINGS_relative_time_to_string (cur->duration, + GNUNET_YES)); + + /* Update experiment */ + e->num_episodes++; + e->total_duration = GNUNET_TIME_relative_add (e->total_duration, + cur->duration); + /* Put in linked list */ + if (NULL == last) + e->start = cur; + else + last->next = cur; + + GNUNET_free (sec_name); + e_counter++; + last = cur; + } return e_counter; } static void -timeout_experiment(void *cls) +timeout_experiment (void *cls) { struct Experiment *e = cls; e->experiment_timeout_task = NULL; - fprintf(stderr, "Experiment timeout!\n"); + fprintf (stderr, "Experiment timeout!\n"); if (NULL != e->episode_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->episode_timeout_task); - e->episode_timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (e->episode_timeout_task); + e->episode_timeout_task = NULL; + } - e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), - GNUNET_SYSERR); + e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time), + GNUNET_SYSERR); } static void -enforce_start_send(struct GNUNET_ATS_TEST_Operation *op) +enforce_start_send (struct GNUNET_ATS_TEST_Operation *op) { /* struct BenchmarkPeer *peer; @@ -498,7 +521,7 @@ enforce_start_send(struct GNUNET_ATS_TEST_Operation *op) } static void -enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op) +enforce_stop_send (struct GNUNET_ATS_TEST_Operation *op) { /* struct BenchmarkPartner *p; @@ -523,7 +546,7 @@ enforce_stop_send(struct GNUNET_ATS_TEST_Operation *op) static void -enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) +enforce_start_preference (struct GNUNET_ATS_TEST_Operation *op) { /* struct BenchmarkPeer *peer; @@ -560,7 +583,7 @@ enforce_start_preference(struct GNUNET_ATS_TEST_Operation *op) } static void -enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) +enforce_stop_preference (struct GNUNET_ATS_TEST_Operation *op) { /* struct BenchmarkPartner *p; @@ -583,264 +606,281 @@ enforce_stop_preference(struct GNUNET_ATS_TEST_Operation *op) */ } -static void enforce_episode(struct Episode *ep) +static void enforce_episode (struct Episode *ep) { struct GNUNET_ATS_TEST_Operation *cur; for (cur = ep->head; NULL != cur; cur = cur->next) + { + fprintf (stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", + print_op (cur->type), cur->src_id, cur->dest_id, cur->base_rate); + switch (cur->type) { - fprintf(stderr, "Enforcing operation: %s [%llu]->[%llu] == %llu\n", - print_op(cur->type), cur->src_id, cur->dest_id, cur->base_rate); - switch (cur->type) - { - case START_SEND: - enforce_start_send(cur); - break; + case START_SEND: + enforce_start_send (cur); + break; - case STOP_SEND: - enforce_stop_send(cur); - break; + case STOP_SEND: + enforce_stop_send (cur); + break; - case START_PREFERENCE: - enforce_start_preference(cur); - break; + case START_PREFERENCE: + enforce_start_preference (cur); + break; - case STOP_PREFERENCE: - enforce_stop_preference(cur); - break; + case STOP_PREFERENCE: + enforce_stop_preference (cur); + break; - default: - break; - } + default: + break; } + } } static void -timeout_episode(void *cls) +timeout_episode (void *cls) { struct Experiment *e = cls; e->episode_timeout_task = NULL; if (NULL != e->ep_done_cb) - e->ep_done_cb(e->cur); + e->ep_done_cb (e->cur); /* Scheduling next */ e->cur = e->cur->next; if (NULL == e->cur) + { + /* done */ + fprintf (stderr, "Last episode done!\n"); + if (NULL != e->experiment_timeout_task) { - /* done */ - fprintf(stderr, "Last episode done!\n"); - if (NULL != e->experiment_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); - e->experiment_timeout_task = NULL; - } - e->e_done_cb(e, GNUNET_TIME_absolute_get_duration(e->start_time), GNUNET_OK); - return; + GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); + e->experiment_timeout_task = NULL; } - - fprintf(stderr, "Running episode %u with timeout %s\n", - e->cur->id, - GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); - enforce_episode(e->cur); - - e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, - &timeout_episode, e); + e->e_done_cb (e, GNUNET_TIME_absolute_get_duration (e->start_time), + GNUNET_OK); + return; + } + + fprintf (stderr, "Running episode %u with timeout %s\n", + e->cur->id, + GNUNET_STRINGS_relative_time_to_string (e->cur->duration, + GNUNET_YES)); + enforce_episode (e->cur); + + e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, + &timeout_episode, e); } void -GNUNET_ATS_solvers_experimentation_run(struct Experiment *e, - GNUNET_ATS_TESTING_EpisodeDoneCallback ep_done_cb, - GNUNET_ATS_TESTING_ExperimentDoneCallback e_done_cb) +GNUNET_ATS_solvers_experimentation_run (struct Experiment *e, + GNUNET_ATS_TESTING_EpisodeDoneCallback + ep_done_cb, + GNUNET_ATS_TESTING_ExperimentDoneCallback + e_done_cb) { - fprintf(stderr, "Running experiment `%s' with timeout %s\n", e->name, - GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); + fprintf (stderr, "Running experiment `%s' with timeout %s\n", e->name, + GNUNET_STRINGS_relative_time_to_string (e->max_duration, + GNUNET_YES)); e->e_done_cb = e_done_cb; e->ep_done_cb = ep_done_cb; - e->start_time = GNUNET_TIME_absolute_get(); + e->start_time = GNUNET_TIME_absolute_get (); /* Start total time out */ - e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed(e->max_duration, - &timeout_experiment, e); + e->experiment_timeout_task = GNUNET_SCHEDULER_add_delayed (e->max_duration, + &timeout_experiment, + e); /* Start */ e->cur = e->start; - fprintf(stderr, "Running episode %u with timeout %s\n", - e->cur->id, - GNUNET_STRINGS_relative_time_to_string(e->cur->duration, GNUNET_YES)); - enforce_episode(e->cur); - e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed(e->cur->duration, - &timeout_episode, e); + fprintf (stderr, "Running episode %u with timeout %s\n", + e->cur->id, + GNUNET_STRINGS_relative_time_to_string (e->cur->duration, + GNUNET_YES)); + enforce_episode (e->cur); + e->episode_timeout_task = GNUNET_SCHEDULER_add_delayed (e->cur->duration, + &timeout_episode, e); } struct Experiment * -GNUNET_ATS_solvers_experimentation_load(char *filename) +GNUNET_ATS_solvers_experimentation_load (char *filename) { struct Experiment *e; struct GNUNET_CONFIGURATION_Handle *cfg; e = NULL; - cfg = GNUNET_CONFIGURATION_create(); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load(cfg, filename)) - { - fprintf(stderr, "Failed to load `%s'\n", filename); - GNUNET_CONFIGURATION_destroy(cfg); - return NULL; - } + cfg = GNUNET_CONFIGURATION_create (); + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_load (cfg, filename)) + { + fprintf (stderr, "Failed to load `%s'\n", filename); + GNUNET_CONFIGURATION_destroy (cfg); + return NULL; + } - e = create_experiment(); + e = create_experiment (); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string(cfg, "experiment", - "name", &e->name)) - { - fprintf(stderr, "Invalid %s", "name"); - free_experiment(e); - return NULL; - } + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_string (cfg, "experiment", + "name", &e->name)) + { + fprintf (stderr, "Invalid %s", "name"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment name: `%s'\n", e->name); + fprintf (stderr, "Experiment name: `%s'\n", e->name); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename(cfg, "experiment", - "cfg_file", &e->cfg_file)) - { - fprintf(stderr, "Invalid %s", "cfg_file"); - free_experiment(e); - return NULL; - } + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_filename (cfg, + "experiment", + "cfg_file", + &e->cfg_file)) + { + fprintf (stderr, "Invalid %s", "cfg_file"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment name: `%s'\n", e->cfg_file); + fprintf (stderr, "Experiment name: `%s'\n", e->cfg_file); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", - "masters", &e->num_masters)) - { - fprintf(stderr, "Invalid %s", "masters"); - free_experiment(e); - return NULL; - } + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment", + "masters", + &e->num_masters)) + { + fprintf (stderr, "Invalid %s", "masters"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment masters: `%llu'\n", - e->num_masters); + fprintf (stderr, "Experiment masters: `%llu'\n", + e->num_masters); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number(cfg, "experiment", - "slaves", &e->num_slaves)) - { - fprintf(stderr, "Invalid %s", "slaves"); - free_experiment(e); - return NULL; - } + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_number (cfg, "experiment", + "slaves", + &e->num_slaves)) + { + fprintf (stderr, "Invalid %s", "slaves"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment slaves: `%llu'\n", - e->num_slaves); + fprintf (stderr, "Experiment slaves: `%llu'\n", + e->num_slaves); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", - "log_freq", &e->log_freq)) - { - fprintf(stderr, "Invalid %s", "log_freq"); - free_experiment(e); - return NULL; - } + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment", + "log_freq", + &e->log_freq)) + { + fprintf (stderr, "Invalid %s", "log_freq"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment logging frequency: `%s'\n", - GNUNET_STRINGS_relative_time_to_string(e->log_freq, GNUNET_YES)); + fprintf (stderr, "Experiment logging frequency: `%s'\n", + GNUNET_STRINGS_relative_time_to_string (e->log_freq, GNUNET_YES)); - if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time(cfg, "experiment", - "max_duration", &e->max_duration)) - { - fprintf(stderr, "Invalid %s", "max_duration"); - free_experiment(e); - return NULL; - } + if (GNUNET_SYSERR == GNUNET_CONFIGURATION_get_value_time (cfg, "experiment", + "max_duration", + &e->max_duration)) + { + fprintf (stderr, "Invalid %s", "max_duration"); + free_experiment (e); + return NULL; + } else - fprintf(stderr, "Experiment duration: `%s'\n", - GNUNET_STRINGS_relative_time_to_string(e->max_duration, GNUNET_YES)); + fprintf (stderr, "Experiment duration: `%s'\n", + GNUNET_STRINGS_relative_time_to_string (e->max_duration, + GNUNET_YES)); - load_episodes(e, cfg); - fprintf(stderr, "Loaded %u episodes with total duration %s\n", - e->num_episodes, - GNUNET_STRINGS_relative_time_to_string(e->total_duration, GNUNET_YES)); + load_episodes (e, cfg); + fprintf (stderr, "Loaded %u episodes with total duration %s\n", + e->num_episodes, + GNUNET_STRINGS_relative_time_to_string (e->total_duration, + GNUNET_YES)); - GNUNET_CONFIGURATION_destroy(cfg); + GNUNET_CONFIGURATION_destroy (cfg); return e; } void -GNUNET_ATS_solvers_experimentation_stop(struct Experiment *e) +GNUNET_ATS_solvers_experimentation_stop (struct Experiment *e) { if (NULL != e->experiment_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->experiment_timeout_task); - e->experiment_timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (e->experiment_timeout_task); + e->experiment_timeout_task = NULL; + } if (NULL != e->episode_timeout_task) - { - GNUNET_SCHEDULER_cancel(e->episode_timeout_task); - e->episode_timeout_task = NULL; - } - free_experiment(e); + { + GNUNET_SCHEDULER_cancel (e->episode_timeout_task); + e->episode_timeout_task = NULL; + } + free_experiment (e); } /** * Solver */ -struct GNUNET_ATS_TESTING_SolverHandle { - char * plugin; +struct GNUNET_ATS_TESTING_SolverHandle +{ + char *plugin; struct GNUNET_ATS_PluginEnvironment env; void *solver; }; -enum GNUNET_ATS_Solvers { +enum GNUNET_ATS_Solvers +{ GNUNET_ATS_SOLVER_PROPORTIONAL, GNUNET_ATS_SOLVER_MLP, GNUNET_ATS_SOLVER_RIL, }; void -GNUNET_ATS_solvers_solver_stop(struct GNUNET_ATS_TESTING_SolverHandle *sh) +GNUNET_ATS_solvers_solver_stop (struct GNUNET_ATS_TESTING_SolverHandle *sh) { - GNUNET_PLUGIN_unload(sh->plugin, sh->solver); - GNUNET_free(sh->plugin); - GNUNET_free(sh); + GNUNET_PLUGIN_unload (sh->plugin, sh->solver); + GNUNET_free (sh->plugin); + GNUNET_free (sh); } struct GNUNET_ATS_TESTING_SolverHandle * -GNUNET_ATS_solvers_solver_start(enum GNUNET_ATS_Solvers type) +GNUNET_ATS_solvers_solver_start (enum GNUNET_ATS_Solvers type) { struct GNUNET_ATS_TESTING_SolverHandle *sh; - char * solver_str; + char *solver_str; switch (type) - { - case GNUNET_ATS_SOLVER_PROPORTIONAL: - solver_str = "proportional"; - break; - - case GNUNET_ATS_SOLVER_MLP: - solver_str = "mlp"; - break; - - case GNUNET_ATS_SOLVER_RIL: - solver_str = "ril"; - break; - - default: - GNUNET_break(0); - return NULL; - break; - } - - sh = GNUNET_new(struct GNUNET_ATS_TESTING_SolverHandle); - GNUNET_asprintf(&sh->plugin, "libgnunet_plugin_ats_%s", solver_str); - //sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env); + { + case GNUNET_ATS_SOLVER_PROPORTIONAL: + solver_str = "proportional"; + break; + + case GNUNET_ATS_SOLVER_MLP: + solver_str = "mlp"; + break; + + case GNUNET_ATS_SOLVER_RIL: + solver_str = "ril"; + break; + + default: + GNUNET_break (0); + return NULL; + break; + } + + sh = GNUNET_new (struct GNUNET_ATS_TESTING_SolverHandle); + GNUNET_asprintf (&sh->plugin, "libgnunet_plugin_ats_%s", solver_str); + // sh->solver = GNUNET_PLUGIN_load (sh->plugin, &sh->env); if (NULL == sh->solver) - { - fprintf(stderr, "Failed to load solver `%s'\n", sh->plugin); - exit(1); - } + { + fprintf (stderr, "Failed to load solver `%s'\n", sh->plugin); + exit (1); + } return sh; } @@ -872,56 +912,56 @@ static int opt_plot; static int opt_verbose; static void -run(void *cls, char * const *args, const char *cfgfile, - const struct GNUNET_CONFIGURATION_Handle *cfg) +run (void *cls, char *const *args, const char *cfgfile, + const struct GNUNET_CONFIGURATION_Handle *cfg) { enum GNUNET_ATS_Solvers solver; if (NULL == opt_exp_file) - { - fprintf(stderr, "No experiment given ...\n"); - exit(1); - } + { + fprintf (stderr, "No experiment given ...\n"); + exit (1); + } if (NULL == opt_solver) - { - fprintf(stderr, "No solver given ...\n"); - exit(1); - } + { + fprintf (stderr, "No solver given ...\n"); + exit (1); + } - if (0 == strcmp(opt_solver, "mlp")) - { - solver = GNUNET_ATS_SOLVER_MLP; - } - else if (0 == strcmp(opt_solver, "proportional")) - { - solver = GNUNET_ATS_SOLVER_PROPORTIONAL; - } - else if (0 == strcmp(opt_solver, "ril")) - { - solver = GNUNET_ATS_SOLVER_RIL; - } + if (0 == strcmp (opt_solver, "mlp")) + { + solver = GNUNET_ATS_SOLVER_MLP; + } + else if (0 == strcmp (opt_solver, "proportional")) + { + solver = GNUNET_ATS_SOLVER_PROPORTIONAL; + } + else if (0 == strcmp (opt_solver, "ril")) + { + solver = GNUNET_ATS_SOLVER_RIL; + } else - { - fprintf(stderr, "No solver given ..."); - return; - } + { + fprintf (stderr, "No solver given ..."); + return; + } /* load experiment */ - e = GNUNET_ATS_solvers_experimentation_load(opt_exp_file); + e = GNUNET_ATS_solvers_experimentation_load (opt_exp_file); if (NULL == e) - { - fprintf(stderr, "Failed to load experiment ...\n"); - return; - } + { + fprintf (stderr, "Failed to load experiment ...\n"); + return; + } /* load solver */ - sh = GNUNET_ATS_solvers_solver_start(solver); + sh = GNUNET_ATS_solvers_solver_start (solver); if (NULL == sh) - { - fprintf(stderr, "Failed to start solver ...\n"); - return; - } + { + fprintf (stderr, "Failed to start solver ...\n"); + return; + } /* start logging */ @@ -938,40 +978,39 @@ run(void *cls, char * const *args, const char *cfgfile, * @param argv argument values */ int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { opt_exp_file = NULL; opt_solver = NULL; opt_log = GNUNET_NO; opt_plot = GNUNET_NO; - struct GNUNET_GETOPT_CommandLineOption options[] = - { - GNUNET_GETOPT_option_string('s', - "solver", - NULL, - gettext_noop("solver to use"), - &opt_solver), - - GNUNET_GETOPT_option_string('e', - "experiment", - NULL, - gettext_noop("experiment to use"), - &opt_exp_file), - - GNUNET_GETOPT_option_flag('e', - "experiment", - gettext_noop("experiment to use"), - &opt_verbose), + struct GNUNET_GETOPT_CommandLineOption options[] = { + GNUNET_GETOPT_option_string ('s', + "solver", + NULL, + gettext_noop ("solver to use"), + &opt_solver), + + GNUNET_GETOPT_option_string ('e', + "experiment", + NULL, + gettext_noop ("experiment to use"), + &opt_exp_file), + + GNUNET_GETOPT_option_flag ('e', + "experiment", + gettext_noop ("experiment to use"), + &opt_verbose), GNUNET_GETOPT_OPTION_END }; if (GNUNET_OK != - GNUNET_PROGRAM_run(argc, - argv, argv[0], - NULL, - options, - &run, argv[0])) + GNUNET_PROGRAM_run (argc, + argv, argv[0], + NULL, + options, + &run, argv[0])) return 1; return 0; diff --git a/src/ats-tests/perf_ats.c b/src/ats-tests/perf_ats.c index c31e8a1c4..470c687fc 100644 --- a/src/ats-tests/perf_ats.c +++ b/src/ats-tests/perf_ats.c @@ -31,15 +31,20 @@ #include "ats-testing.h" -#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) +#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 1) #define TEST_ATS_PREFRENCE_START 1.0 #define TEST_ATS_PREFRENCE_DELTA 1.0 -#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) +#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 1) -#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) -#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) -#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) +#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + 120) +#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 10) +#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MILLISECONDS, 500) #define TESTNAME_PREFIX "perf_ats_" #define DEFAULT_SLAVES_NUM 2 #define DEFAULT_MASTERS_NUM 1 @@ -123,7 +128,7 @@ static struct LoggingHandle *l; static void -evaluate() +evaluate () { int c_m; int c_s; @@ -139,48 +144,49 @@ evaluate() duration = 1 + (perf_duration.rel_value_us / (1000 * 1000)); for (c_m = 0; c_m < num_masters; c_m++) + { + mp = &mps[c_m]; + fprintf (stderr, + "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n", + mp->no, mp->total_bytes_sent / 1024, duration, + (mp->total_bytes_sent / 1024) / duration, + mp->total_bytes_received / 1024, duration, + (mp->total_bytes_received / 1024) / duration); + + for (c_s = 0; c_s < num_slaves; c_s++) { - mp = &mps[c_m]; - fprintf(stderr, - "Master [%u]: sent: %u KiB in %u sec. = %u KiB/s, received: %u KiB in %u sec. = %u KiB/s\n", - mp->no, mp->total_bytes_sent / 1024, duration, - (mp->total_bytes_sent / 1024) / duration, - mp->total_bytes_received / 1024, duration, - (mp->total_bytes_received / 1024) / duration); - - for (c_s = 0; c_s < num_slaves; c_s++) - { - p = &mp->partners[c_s]; - kb_sent_sec = 0; - kb_recv_sec = 0; - kb_sent_percent = 0.0; - kb_recv_percent = 0.0; - rtt = 0; - - if (duration > 0) - { - kb_sent_sec = (p->bytes_sent / 1024) / duration; - kb_recv_sec = (p->bytes_received / 1024) / duration; - } - - if (mp->total_bytes_sent > 0) - kb_sent_percent = ((double)p->bytes_sent * 100) / mp->total_bytes_sent; - if (mp->total_bytes_received > 0) - kb_recv_percent = ((double)p->bytes_received * 100) / mp->total_bytes_received; - if (1000 * p->messages_sent > 0) - rtt = p->total_app_rtt / (1000 * p->messages_sent); - fprintf(stderr, - "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n", - (mp->pref_partner == p->dest) ? '*' : ' ', - mp->no, p->dest->no, - kb_sent_sec, kb_sent_percent, - kb_recv_sec, kb_recv_percent); - fprintf(stderr, - "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", - (mp->pref_partner == p->dest) ? '*' : ' ', - mp->no, p->dest->no, rtt); - } + p = &mp->partners[c_s]; + kb_sent_sec = 0; + kb_recv_sec = 0; + kb_sent_percent = 0.0; + kb_recv_percent = 0.0; + rtt = 0; + + if (duration > 0) + { + kb_sent_sec = (p->bytes_sent / 1024) / duration; + kb_recv_sec = (p->bytes_received / 1024) / duration; + } + + if (mp->total_bytes_sent > 0) + kb_sent_percent = ((double) p->bytes_sent * 100) / mp->total_bytes_sent; + if (mp->total_bytes_received > 0) + kb_recv_percent = ((double) p->bytes_received * 100) + / mp->total_bytes_received; + if (1000 * p->messages_sent > 0) + rtt = p->total_app_rtt / (1000 * p->messages_sent); + fprintf (stderr, + "%c Master [%u] -> Slave [%u]: sent %u KiB/s (%.2f %%), received %u KiB/s (%.2f %%)\n", + (mp->pref_partner == p->dest) ? '*' : ' ', + mp->no, p->dest->no, + kb_sent_sec, kb_sent_percent, + kb_recv_sec, kb_recv_percent); + fprintf (stderr, + "%c Master [%u] -> Slave [%u]: Average application layer RTT: %u ms\n", + (mp->pref_partner == p->dest) ? '*' : ' ', + mp->no, p->dest->no, rtt); } + } } @@ -190,24 +196,24 @@ evaluate() * @param cls NULL */ static void -do_shutdown(void *cls) +do_shutdown (void *cls) { if (GNUNET_YES == logging) - GNUNET_ATS_TEST_logging_clean_up(l); + GNUNET_ATS_TEST_logging_clean_up (l); if (NULL != timeout_task) - { - GNUNET_SCHEDULER_cancel(timeout_task); - timeout_task = NULL; - } + { + GNUNET_SCHEDULER_cancel (timeout_task); + timeout_task = NULL; + } if (NULL != progress_task) - { - fprintf(stderr, "0\n"); - GNUNET_SCHEDULER_cancel(progress_task); - progress_task = NULL; - } - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Benchmarking done\n"); - GNUNET_ATS_TEST_shutdown_topology(); + { + fprintf (stderr, "0\n"); + GNUNET_SCHEDULER_cancel (progress_task); + progress_task = NULL; + } + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Benchmarking done\n"); + GNUNET_ATS_TEST_shutdown_topology (); } @@ -217,163 +223,166 @@ do_shutdown(void *cls) * @param cls NULL */ static void -do_timeout(void *cls) +do_timeout (void *cls) { - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Terminating with timeout\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Terminating with timeout\n"); timeout_task = NULL; - evaluate(); - GNUNET_SCHEDULER_shutdown(); + evaluate (); + GNUNET_SCHEDULER_shutdown (); } static void -print_progress(void *cls) +print_progress (void *cls) { static int calls; progress_task = NULL; - fprintf(stderr, - "%llu..", - (long long unsigned)perf_duration.rel_value_us / (1000 * 1000) - calls); + fprintf (stderr, + "%llu..", + (long long unsigned) perf_duration.rel_value_us / (1000 * 1000) + - calls); calls++; - progress_task = GNUNET_SCHEDULER_add_delayed(GNUNET_TIME_UNIT_SECONDS, - &print_progress, - NULL); + progress_task = GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_SECONDS, + &print_progress, + NULL); } static void -ats_pref_task(void *cls) +ats_pref_task (void *cls) { struct BenchmarkPeer *me = cls; me->ats_task = NULL; - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, " Master [%u] set preference for slave [%u] to %f\n", - me->no, me->pref_partner->no, me->pref_value); - GNUNET_ATS_performance_change_preference(me->ats_perf_handle, - &me->pref_partner->id, - pref_val, me->pref_value, GNUNET_ATS_PREFERENCE_END); + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + " Master [%u] set preference for slave [%u] to %f\n", + me->no, me->pref_partner->no, me->pref_value); + GNUNET_ATS_performance_change_preference (me->ats_perf_handle, + &me->pref_partner->id, + pref_val, me->pref_value, + GNUNET_ATS_PREFERENCE_END); me->pref_value += TEST_ATS_PREFRENCE_DELTA; - me->ats_task = GNUNET_SCHEDULER_add_delayed(TEST_ATS_PREFRENCE_FREQUENCY, - &ats_pref_task, cls); + me->ats_task = GNUNET_SCHEDULER_add_delayed (TEST_ATS_PREFRENCE_FREQUENCY, + &ats_pref_task, cls); } static void -start_benchmark(void *cls) +start_benchmark (void *cls) { int c_m; int c_s; - progress_task = GNUNET_SCHEDULER_add_now(&print_progress, - NULL); + progress_task = GNUNET_SCHEDULER_add_now (&print_progress, + NULL); - GNUNET_log(GNUNET_ERROR_TYPE_INFO, - "Topology connected, start benchmarking...\n"); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Topology connected, start benchmarking...\n"); /* Start sending test messages */ for (c_m = 0; c_m < num_masters; c_m++) + { + for (c_s = 0; c_s < num_slaves; c_s++) { - for (c_s = 0; c_s < num_slaves; c_s++) - { - GNUNET_ATS_TEST_generate_traffic_start(&mps[c_m], - &mps[c_m].partners[c_s], - GNUNET_ATS_TEST_TG_LINEAR, - UINT32_MAX, - UINT32_MAX, - GNUNET_TIME_UNIT_MINUTES, - GNUNET_TIME_UNIT_FOREVER_REL); - } - if (pref_val != GNUNET_ATS_PREFERENCE_END) - mps[c_m].ats_task = GNUNET_SCHEDULER_add_now(&ats_pref_task, - &mps[c_m]); + GNUNET_ATS_TEST_generate_traffic_start (&mps[c_m], + &mps[c_m].partners[c_s], + GNUNET_ATS_TEST_TG_LINEAR, + UINT32_MAX, + UINT32_MAX, + GNUNET_TIME_UNIT_MINUTES, + GNUNET_TIME_UNIT_FOREVER_REL); } + if (pref_val != GNUNET_ATS_PREFERENCE_END) + mps[c_m].ats_task = GNUNET_SCHEDULER_add_now (&ats_pref_task, + &mps[c_m]); + } if (GNUNET_YES == logging) - l = GNUNET_ATS_TEST_logging_start(log_frequency, - testname, mps, - num_masters, num_slaves, - GNUNET_NO); + l = GNUNET_ATS_TEST_logging_start (log_frequency, + testname, mps, + num_masters, num_slaves, + GNUNET_NO); } static void -do_benchmark(void *cls, - struct BenchmarkPeer *masters, - struct BenchmarkPeer *slaves) +do_benchmark (void *cls, + struct BenchmarkPeer *masters, + struct BenchmarkPeer *slaves) { mps = masters; sps = slaves; - GNUNET_SCHEDULER_add_shutdown(&do_shutdown, - NULL); - timeout_task = GNUNET_SCHEDULER_add_delayed(perf_duration, - &do_timeout, - NULL); - progress_task = GNUNET_SCHEDULER_add_now(&start_benchmark, - NULL); + GNUNET_SCHEDULER_add_shutdown (&do_shutdown, + NULL); + timeout_task = GNUNET_SCHEDULER_add_delayed (perf_duration, + &do_timeout, + NULL); + progress_task = GNUNET_SCHEDULER_add_now (&start_benchmark, + NULL); } static struct BenchmarkPartner * -find_partner(struct BenchmarkPeer *me, - const struct GNUNET_PeerIdentity *peer) +find_partner (struct BenchmarkPeer *me, + const struct GNUNET_PeerIdentity *peer) { int c_m; - GNUNET_assert(NULL != me); - GNUNET_assert(NULL != peer); + GNUNET_assert (NULL != me); + GNUNET_assert (NULL != peer); for (c_m = 0; c_m < me->num_partners; c_m++) + { + /* Find a partner with other as destination */ + if (0 == GNUNET_memcmp (peer, &me->partners[c_m].dest->id)) { - /* Find a partner with other as destination */ - if (0 == GNUNET_memcmp(peer, &me->partners[c_m].dest->id)) - { - return &me->partners[c_m]; - } + return &me->partners[c_m]; } + } return NULL; } static void -log_request_cb(void *cls, - const struct GNUNET_HELLO_Address *address, - int address_active, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, - struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, - const struct GNUNET_ATS_Properties *ats) +log_request_cb (void *cls, + const struct GNUNET_HELLO_Address *address, + int address_active, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_out, + struct GNUNET_BANDWIDTH_Value32NBO bandwidth_in, + const struct GNUNET_ATS_Properties *ats) { struct BenchmarkPeer *me = cls; struct BenchmarkPartner *p; char *peer_id; - p = find_partner(me, &address->peer); + p = find_partner (me, &address->peer); if (NULL == p) - { - /* This is not one of my partners - * Will happen since the peers will connect to each other due to gossiping - */ - return; - } - peer_id = GNUNET_strdup(GNUNET_i2s(&me->id)); - - if ((p->bandwidth_in != ntohl(bandwidth_in.value__)) || - (p->bandwidth_out != ntohl(bandwidth_out.value__))) - p->bandwidth_in = ntohl(bandwidth_in.value__); - p->bandwidth_out = ntohl(bandwidth_out.value__); - - GNUNET_log(GNUNET_ERROR_TYPE_DEBUG, - "%s [%u] received ATS information for peers `%s'\n", - (GNUNET_YES == p->me->master) ? "Master" : "Slave", - p->me->no, - GNUNET_i2s(&p->dest->id)); - - GNUNET_free(peer_id); + { + /* This is not one of my partners + * Will happen since the peers will connect to each other due to gossiping + */ + return; + } + peer_id = GNUNET_strdup (GNUNET_i2s (&me->id)); + + if ((p->bandwidth_in != ntohl (bandwidth_in.value__)) || + (p->bandwidth_out != ntohl (bandwidth_out.value__))) + p->bandwidth_in = ntohl (bandwidth_in.value__); + p->bandwidth_out = ntohl (bandwidth_out.value__); + + GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, + "%s [%u] received ATS information for peers `%s'\n", + (GNUNET_YES == p->me->master) ? "Master" : "Slave", + p->me->no, + GNUNET_i2s (&p->dest->id)); + + GNUNET_free (peer_id); if (NULL != l) - GNUNET_ATS_TEST_logging_now(l); + GNUNET_ATS_TEST_logging_now (l); } @@ -381,7 +390,7 @@ log_request_cb(void *cls, * Start the performance test case */ int -main(int argc, char *argv[]) +main (int argc, char *argv[]) { char *tmp; char *tmp_sep; @@ -398,187 +407,192 @@ main(int argc, char *argv[]) * perf_ats_<solver>_<transport>_<preference>[.exe]*/ /* Find test prefix, store in temp */ - tmp = strstr(argv[0], TESTNAME_PREFIX); + tmp = strstr (argv[0], TESTNAME_PREFIX); if (NULL == tmp) - { - fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]); - return GNUNET_SYSERR; - } + { + fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]); + return GNUNET_SYSERR; + } /* Set tmp to end of test name prefix */ - tmp += strlen(TESTNAME_PREFIX); + tmp += strlen (TESTNAME_PREFIX); /* Determine solver name */ - solver = GNUNET_strdup(tmp); + solver = GNUNET_strdup (tmp); /* Remove .exe prefix */ - if (NULL != (dotexe = strstr(solver, ".exe")) && dotexe[4] == '\0') + if ((NULL != (dotexe = strstr (solver, ".exe")))&&(dotexe[4] == '\0')) dotexe[0] = '\0'; /* Determine first '_' after solver */ - tmp_sep = strchr(solver, '_'); + tmp_sep = strchr (solver, '_'); if (NULL == tmp_sep) - { - fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]); - GNUNET_free(solver); - return GNUNET_SYSERR; - } + { + fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]); + GNUNET_free (solver); + return GNUNET_SYSERR; + } tmp_sep[0] = '\0'; - comm_name = GNUNET_strdup(&tmp_sep[1]); - tmp_sep = strchr(comm_name, '_'); + comm_name = GNUNET_strdup (&tmp_sep[1]); + tmp_sep = strchr (comm_name, '_'); if (NULL == tmp_sep) - { - fprintf(stderr, "Unable to parse test name `%s'\n", argv[0]); - GNUNET_free(solver); - return GNUNET_SYSERR; - } + { + fprintf (stderr, "Unable to parse test name `%s'\n", argv[0]); + GNUNET_free (solver); + return GNUNET_SYSERR; + } tmp_sep[0] = '\0'; - for (c = 0; c <= strlen(comm_name); c++) - comm_name[c] = toupper(comm_name[c]); - if (0 == strcmp(comm_name, "CORE")) + for (c = 0; c <= strlen (comm_name); c++) + comm_name[c] = toupper (comm_name[c]); + if (0 == strcmp (comm_name, "CORE")) test_core = GNUNET_YES; - else if (0 == strcmp(comm_name, "TRANSPORT")) + else if (0 == strcmp (comm_name, "TRANSPORT")) test_core = GNUNET_NO; else - { - GNUNET_free(comm_name); - GNUNET_free(solver); - return GNUNET_SYSERR; - } + { + GNUNET_free (comm_name); + GNUNET_free (solver); + return GNUNET_SYSERR; + } - pref_str = GNUNET_strdup(tmp_sep + 1); + pref_str = GNUNET_strdup (tmp_sep + 1); - GNUNET_asprintf(&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver, - pref_str); - GNUNET_asprintf(&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str); + GNUNET_asprintf (&conf_name, "%s%s_%s.conf", TESTNAME_PREFIX, solver, + pref_str); + GNUNET_asprintf (&test_name, "%s%s_%s", TESTNAME_PREFIX, solver, pref_str); - for (c = 0; c <= strlen(pref_str); c++) - pref_str[c] = toupper(pref_str[c]); + for (c = 0; c <= strlen (pref_str); c++) + pref_str[c] = toupper (pref_str[c]); pref_val = -1; - if (0 != strcmp(pref_str, "NONE")) + if (0 != strcmp (pref_str, "NONE")) + { + for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) { - for (c = 0; c < GNUNET_ATS_PREFERENCE_END; c++) - { - if (0 == strcmp(pref_str, prefs[c])) - { - pref_val = c; - break; - } - } + if (0 == strcmp (pref_str, prefs[c])) + { + pref_val = c; + break; + } } + } else - { - /* abuse terminator to indicate no pref */ - pref_val = GNUNET_ATS_PREFERENCE_END; - } + { + /* abuse terminator to indicate no pref */ + pref_val = GNUNET_ATS_PREFERENCE_END; + } if (-1 == pref_val) - { - fprintf(stderr, "Unknown preference: `%s'\n", pref_str); - GNUNET_free(solver); - GNUNET_free(pref_str); - GNUNET_free(comm_name); - return -1; - } + { + fprintf (stderr, "Unknown preference: `%s'\n", pref_str); + GNUNET_free (solver); + GNUNET_free (pref_str); + GNUNET_free (comm_name); + return -1; + } for (c = 0; c < (argc - 1); c++) - { - if (0 == strcmp(argv[c], "-d")) - break; - } + { + if (0 == strcmp (argv[c], "-d")) + break; + } if (c < argc - 1) - { - if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &perf_duration)) - fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]); - } + { + if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], + &perf_duration)) + fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]); + } else - { - perf_duration = BENCHMARK_DURATION; - } - fprintf(stderr, "Running benchmark for %llu secs\n", (unsigned long long)(perf_duration.rel_value_us) / (1000 * 1000)); + { + perf_duration = BENCHMARK_DURATION; + } + fprintf (stderr, "Running benchmark for %llu secs\n", (unsigned long + long) (perf_duration. + rel_value_us) + / (1000 * 1000)); for (c = 0; c < (argc - 1); c++) - { - if (0 == strcmp(argv[c], "-s")) - break; - } + { + if (0 == strcmp (argv[c], "-s")) + break; + } if (c < argc - 1) - { - if ((0L != (num_slaves = strtol(argv[c + 1], NULL, 10))) - && (num_slaves >= 1)) - fprintf(stderr, "Starting %u slave peers\n", num_slaves); - else - num_slaves = DEFAULT_SLAVES_NUM; - } + { + if ((0L != (num_slaves = strtol (argv[c + 1], NULL, 10))) + && (num_slaves >= 1)) + fprintf (stderr, "Starting %u slave peers\n", num_slaves); + else + num_slaves = DEFAULT_SLAVES_NUM; + } else num_slaves = DEFAULT_SLAVES_NUM; for (c = 0; c < (argc - 1); c++) - { - if (0 == strcmp(argv[c], "-m")) - break; - } + { + if (0 == strcmp (argv[c], "-m")) + break; + } if (c < argc - 1) - { - if ((0L != (num_masters = strtol(argv[c + 1], NULL, 10))) - && (num_masters >= 2)) - fprintf(stderr, "Starting %u master peers\n", num_masters); - else - num_masters = DEFAULT_MASTERS_NUM; - } + { + if ((0L != (num_masters = strtol (argv[c + 1], NULL, 10))) + && (num_masters >= 2)) + fprintf (stderr, "Starting %u master peers\n", num_masters); + else + num_masters = DEFAULT_MASTERS_NUM; + } else num_masters = DEFAULT_MASTERS_NUM; logging = GNUNET_NO; for (c = 0; c < argc; c++) - { - if (0 == strcmp(argv[c], "-l")) - logging = GNUNET_YES; - } + { + if (0 == strcmp (argv[c], "-l")) + logging = GNUNET_YES; + } if (GNUNET_YES == logging) + { + for (c = 0; c < (argc - 1); c++) + { + if (0 == strcmp (argv[c], "-f")) + break; + } + if (c < argc - 1) + { + if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative (argv[c + 1], + &log_frequency)) + fprintf (stderr, "Failed to parse duration `%s'\n", argv[c + 1]); + } + else { - for (c = 0; c < (argc - 1); c++) - { - if (0 == strcmp(argv[c], "-f")) - break; - } - if (c < argc - 1) - { - if (GNUNET_OK != GNUNET_STRINGS_fancy_time_to_relative(argv[c + 1], &log_frequency)) - fprintf(stderr, "Failed to parse duration `%s'\n", argv[c + 1]); - } - else - { - log_frequency = LOGGING_FREQUENCY; - } - fprintf(stderr, "Using log frequency %llu ms\n", - (unsigned long long)(log_frequency.rel_value_us) / (1000)); + log_frequency = LOGGING_FREQUENCY; } + fprintf (stderr, "Using log frequency %llu ms\n", + (unsigned long long) (log_frequency.rel_value_us) / (1000)); + } - GNUNET_asprintf(&testname, "%s_%s_%s", solver, comm_name, pref_str); + GNUNET_asprintf (&testname, "%s_%s_%s", solver, comm_name, pref_str); if (num_slaves < num_masters) - { - fprintf(stderr, - "Number of master peers is lower than slaves! exit...\n"); - GNUNET_free(test_name); - GNUNET_free(solver); - GNUNET_free(pref_str); - GNUNET_free(comm_name); - return GNUNET_SYSERR; - } + { + fprintf (stderr, + "Number of master peers is lower than slaves! exit...\n"); + GNUNET_free (test_name); + GNUNET_free (solver); + GNUNET_free (pref_str); + GNUNET_free (comm_name); + return GNUNET_SYSERR; + } /** * Setup the topology */ - GNUNET_ATS_TEST_create_topology("perf-ats", - conf_name, - num_slaves, - num_masters, - test_core, - &do_benchmark, - NULL, - &log_request_cb); + GNUNET_ATS_TEST_create_topology ("perf-ats", + conf_name, + num_slaves, + num_masters, + test_core, + &do_benchmark, + NULL, + &log_request_cb); return result; } diff --git a/src/ats-tests/perf_ats.h b/src/ats-tests/perf_ats.h index 2d552a5d7..6460aa098 100644 --- a/src/ats-tests/perf_ats.h +++ b/src/ats-tests/perf_ats.h @@ -30,26 +30,32 @@ #include "gnunet_core_service.h" #include "ats-testing.h" -#define TEST_TIMEOUT GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 120) -#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 10) -#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_MILLISECONDS, 500) +#define TEST_TIMEOUT GNUNET_TIME_relative_multiply (GNUNET_TIME_UNIT_SECONDS, \ + 120) +#define BENCHMARK_DURATION GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 10) +#define LOGGING_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_MILLISECONDS, 500) #define TESTNAME_PREFIX "perf_ats_" #define DEFAULT_SLAVES_NUM 2 #define DEFAULT_MASTERS_NUM 1 -#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) +#define TEST_ATS_PREFRENCE_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 1) #define TEST_ATS_PREFRENCE_START 1.0 #define TEST_ATS_PREFRENCE_DELTA 1.0 #define TEST_MESSAGE_TYPE_PING 12345 #define TEST_MESSAGE_TYPE_PONG 12346 #define TEST_MESSAGE_SIZE 1000 -#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply(GNUNET_TIME_UNIT_SECONDS, 1) +#define TEST_MESSAGE_FREQUENCY GNUNET_TIME_relative_multiply ( \ + GNUNET_TIME_UNIT_SECONDS, 1) /** * Information about a benchmarking partner */ -struct BenchmarkPartner { +struct BenchmarkPartner +{ /** * The peer itself this partner belongs to */ @@ -127,7 +133,8 @@ struct BenchmarkPartner { /** * Information we track for a peer in the testbed. */ -struct BenchmarkPeer { +struct BenchmarkPeer +{ /** * Handle with testbed. */ @@ -194,7 +201,7 @@ struct BenchmarkPeer { * Masters only * Progress task */ - struct GNUNET_SCHEDULER_Task * ats_task; + struct GNUNET_SCHEDULER_Task *ats_task; /** * Masters only diff --git a/src/ats-tests/perf_ats_logging.c b/src/ats-tests/perf_ats_logging.c index e0f192ae4..41c50ea6e 100644 --- a/src/ats-tests/perf_ats_logging.c +++ b/src/ats-tests/perf_ats_logging.c @@ -72,7 +72,7 @@ /** * Logging task */ -static struct GNUNET_SCHEDULER_Task * log_task; +static struct GNUNET_SCHEDULER_Task *log_task; /** * Reference to perf_ats' masters @@ -85,7 +85,8 @@ static struct GNUNET_TIME_Relative frequency; /** * A single logging time step for a partner */ -struct PartnerLoggingTimestep { +struct PartnerLoggingTimestep +{ /** * Peer */ @@ -158,7 +159,8 @@ struct PartnerLoggingTimestep { /** * A single logging time step for a peer */ -struct PeerLoggingTimestep { +struct PeerLoggingTimestep +{ /** * Next in DLL */ @@ -213,7 +215,8 @@ struct PeerLoggingTimestep { /** * Entry for a benchmark peer */ -struct LoggingPeer { +struct LoggingPeer +{ /** * Peer */ @@ -242,164 +245,200 @@ static struct LoggingPeer *lp; static void -write_throughput_gnuplot_script(char * fn, struct LoggingPeer *lp) +write_throughput_gnuplot_script (char *fn, struct LoggingPeer *lp) { struct GNUNET_DISK_FileHandle *f; - char * gfn; + char *gfn; char *data; int c_s; int peer_index; - GNUNET_asprintf(&gfn, "gnuplot_throughput_%s", fn); - f = GNUNET_DISK_file_open(gfn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); + GNUNET_asprintf (&gfn, "gnuplot_throughput_%s", fn); + f = GNUNET_DISK_file_open (gfn, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_EXEC + | GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (NULL == f) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); - GNUNET_free(gfn); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", + gfn); + GNUNET_free (gfn); + return; + } /* Write header */ - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, THROUGHPUT_TEMPLATE, strlen(THROUGHPUT_TEMPLATE))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, THROUGHPUT_TEMPLATE, strlen ( + THROUGHPUT_TEMPLATE))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); /* Write master data */ peer_index = LOG_ITEMS_TIME; - GNUNET_asprintf(&data, "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \ - "'%s' using 2:%u with lines title 'Master %u receive total', \\\n", - fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, - fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); - GNUNET_free(data); + GNUNET_asprintf (&data, + "plot '%s' using 2:%u with lines title 'Master %u send total', \\\n" \ + "'%s' using 2:%u with lines title 'Master %u receive total', \\\n", + fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, + fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); + GNUNET_free (data); peer_index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER; for (c_s = 0; c_s < lp->peer->num_partners; c_s++) - { - GNUNET_asprintf(&data, "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \ - "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n", - fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, lp->peer->partners[c_s].dest->no, - fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no, lp->peer->partners[c_s].dest->no, - (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); - GNUNET_free(data); - peer_index += LOG_ITEMS_PER_PEER; - } - - if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); + { + GNUNET_asprintf (&data, + "'%s' using 2:%u with lines title 'Master %u - Slave %u send', \\\n" \ + "'%s' using 2:%u with lines title 'Master %u - Slave %u receive'%s\n", + fn, peer_index + LOG_ITEM_THROUGHPUT_SENT, lp->peer->no, + lp->peer->partners[c_s].dest->no, + fn, peer_index + LOG_ITEM_THROUGHPUT_RECV, lp->peer->no, + lp->peer->partners[c_s].dest->no, + (c_s < lp->peer->num_partners - 1) ? ", \\" : + "\n pause -1"); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); + GNUNET_free (data); + peer_index += LOG_ITEMS_PER_PEER; + } + + if (GNUNET_SYSERR == GNUNET_DISK_file_close (f)) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", + gfn); else - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Data successfully written to plot file `%s'\n", gfn); - GNUNET_free(gfn); + GNUNET_free (gfn); } static void -write_rtt_gnuplot_script(char * fn, struct LoggingPeer *lp) +write_rtt_gnuplot_script (char *fn, struct LoggingPeer *lp) { struct GNUNET_DISK_FileHandle *f; - char * gfn; + char *gfn; char *data; int c_s; int index; - GNUNET_asprintf(&gfn, "gnuplot_rtt_%s", fn); - f = GNUNET_DISK_file_open(gfn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); + GNUNET_asprintf (&gfn, "gnuplot_rtt_%s", fn); + f = GNUNET_DISK_file_open (gfn, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_EXEC + | GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (NULL == f) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); - GNUNET_free(gfn); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", + gfn); + GNUNET_free (gfn); + return; + } /* Write header */ - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, RTT_TEMPLATE, strlen(RTT_TEMPLATE))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, RTT_TEMPLATE, strlen ( + RTT_TEMPLATE))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER; for (c_s = 0; c_s < lp->peer->num_partners; c_s++) - { - GNUNET_asprintf(&data, "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n", - (0 == c_s) ? "plot " : "", - fn, index + LOG_ITEM_APP_RTT, lp->peer->no, lp->peer->partners[c_s].dest->no, - (c_s < lp->peer->num_partners - 1) ? ", \\" : "\n pause -1"); - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, data, strlen(data))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); - GNUNET_free(data); - index += LOG_ITEMS_PER_PEER; - } - - if (GNUNET_SYSERR == GNUNET_DISK_file_close(f)) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", gfn); + { + GNUNET_asprintf (&data, + "%s'%s' using 2:%u with lines title 'Master %u - Slave %u '%s\n", + (0 == c_s) ? "plot " : "", + fn, index + LOG_ITEM_APP_RTT, lp->peer->no, + lp->peer->partners[c_s].dest->no, + (c_s < lp->peer->num_partners - 1) ? ", \\" : + "\n pause -1"); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, data, strlen (data))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); + GNUNET_free (data); + index += LOG_ITEMS_PER_PEER; + } + + if (GNUNET_SYSERR == GNUNET_DISK_file_close (f)) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot close gnuplot file `%s'\n", + gfn); else - GNUNET_log(GNUNET_ERROR_TYPE_INFO, "Data successfully written to plot file `%s'\n", gfn); - GNUNET_free(gfn); + GNUNET_log (GNUNET_ERROR_TYPE_INFO, + "Data successfully written to plot file `%s'\n", gfn); + GNUNET_free (gfn); } static void -write_bw_gnuplot_script(char * fn, struct LoggingPeer *lp) +write_bw_gnuplot_script (char *fn, struct LoggingPeer *lp) { struct GNUNET_DISK_FileHandle *f; - char * gfn; + char *gfn; char *data; int c_s; int index; - GNUNET_asprintf(&gfn, "gnuplot_bw_%s", fn); - f = GNUNET_DISK_file_open(gfn, - GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, - GNUNET_DISK_PERM_USER_EXEC | GNUNET_DISK_PERM_USER_READ | GNUNET_DISK_PERM_USER_WRITE); + GNUNET_asprintf (&gfn, "gnuplot_bw_%s", fn); + f = GNUNET_DISK_file_open (gfn, + GNUNET_DISK_OPEN_WRITE | GNUNET_DISK_OPEN_CREATE, + GNUNET_DISK_PERM_USER_EXEC + | GNUNET_DISK_PERM_USER_READ + | GNUNET_DISK_PERM_USER_WRITE); if (NULL == f) - { - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", gfn); - GNUNET_free(gfn); - return; - } + { + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, "Cannot open gnuplot file `%s'\n", + gfn); + GNUNET_free (gfn); + return; + } /* Write header */ - if (GNUNET_SYSERR == GNUNET_DISK_file_write(f, BW_TEMPLATE, strlen(BW_TEMPLATE))) - GNUNET_log(GNUNET_ERROR_TYPE_ERROR, "Cannot write data to plot file `%s'\n", gfn); + if (GNUNET_SYSERR == GNUNET_DISK_file_write (f, BW_TEMPLATE, strlen ( + BW_TEMPLATE))) + GNUNET_log (GNUNET_ERROR_TYPE_ERROR, + "Cannot write data to plot file `%s'\n", gfn); index = LOG_ITEMS_TIME + LOG_ITEMS_PER_PEER; for (c_s = 0; c_s < lp->peer->num_partners; c_s++) - { - GNUNET_asprintf(&data, "%s" \ - "'%s' using 2:%u with lines title 'BW out master %u - Slave %u ', \\\n" \ - "'%s' using 2:%u with lines title 'BW in master %u - Slave %u '" \ - "%s\n", - (0 == c_s) ? "plot " : "", |