Commit f3c744fe authored by Lionel Gauthier's avatar Lionel Gauthier

New configs with libconfig

git-svn-id: http://svn.eurecom.fr/openair4G/trunk@5071 818b1a75-f10b-46b9-bf7c-635c3b92a50f
parent 01943bac
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
char* hashtble_rc_code2string(hashtbl_rc_t rcP) char* hashtable_rc_code2string(hashtable_rc_t rcP)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
{ {
switch (rcP) { switch (rcP) {
...@@ -17,15 +17,21 @@ char* hashtble_rc_code2string(hashtbl_rc_t rcP) ...@@ -17,15 +17,21 @@ char* hashtble_rc_code2string(hashtbl_rc_t rcP)
case HASH_TABLE_KEY_NOT_EXISTS: return "HASH_TABLE_KEY_NOT_EXISTS";break; case HASH_TABLE_KEY_NOT_EXISTS: return "HASH_TABLE_KEY_NOT_EXISTS";break;
case HASH_TABLE_KEY_ALREADY_EXISTS: return "HASH_TABLE_KEY_ALREADY_EXISTS";break; case HASH_TABLE_KEY_ALREADY_EXISTS: return "HASH_TABLE_KEY_ALREADY_EXISTS";break;
case HASH_TABLE_BAD_PARAMETER_HASHTABLE: return "HASH_TABLE_BAD_PARAMETER_HASHTABLE";break; case HASH_TABLE_BAD_PARAMETER_HASHTABLE: return "HASH_TABLE_BAD_PARAMETER_HASHTABLE";break;
default: return "UNKNOWN hashtbl_rc_t"; default: return "UNKNOWN hashtable_rc_t";
} }
} }
//-------------------------------------------------------------------------------------------------------------------------------
/*
* free int function
* hash_free_int_func() is used when this hashtable is used to store int values as data (pointer = value).
*/
void hash_free_int_func(void* memoryP){}
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
/* /*
* Default hash function * Default hash function
* def_hashfunc() is the default used by hashtbl_create() when the user didn't specify one. * def_hashfunc() is the default used by hashtable_create() when the user didn't specify one.
* This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables. * This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables.
*/ */
...@@ -37,11 +43,11 @@ static hash_size_t def_hashfunc(const uint64_t keyP) ...@@ -37,11 +43,11 @@ static hash_size_t def_hashfunc(const uint64_t keyP)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
/* /*
* Initialisation * Initialisation
* hashtbl_create() sets up the initial structure of the hash table. The user specified size will be allocated and initialized to NULL. * hashtable_create() sets up the initial structure of the hash table. The user specified size will be allocated and initialized to NULL.
* The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used. * The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used.
* If an error occurred, NULL is returned. All other values in the returned hash_table_t pointer should be released with hashtbl_destroy(). * If an error occurred, NULL is returned. All other values in the returned hash_table_t pointer should be released with hashtable_destroy().
*/ */
hash_table_t *hashtbl_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const uint64_t ), void (*freefuncP)(void*)) hash_table_t *hashtable_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const uint64_t ), void (*freefuncP)(void*))
{ {
hash_table_t *hashtbl; hash_table_t *hashtbl;
...@@ -65,9 +71,9 @@ hash_table_t *hashtbl_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const u ...@@ -65,9 +71,9 @@ hash_table_t *hashtbl_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const u
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
/* /*
* Cleanup * Cleanup
* The hashtbl_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the hash_table_t. * The hashtable_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the hash_table_t.
*/ */
hashtbl_rc_t hashtbl_destroy(hash_table_t *hashtblP) hashtable_rc_t hashtable_destroy(hash_table_t *hashtblP)
{ {
hash_size_t n; hash_size_t n;
hash_node_t *node, *oldnode; hash_node_t *node, *oldnode;
...@@ -92,7 +98,7 @@ hashtbl_rc_t hashtbl_destroy(hash_table_t *hashtblP) ...@@ -92,7 +98,7 @@ hashtbl_rc_t hashtbl_destroy(hash_table_t *hashtblP)
return HASH_TABLE_OK; return HASH_TABLE_OK;
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
hashtbl_rc_t hashtbl_is_key_exists (hash_table_t *hashtblP, const uint64_t keyP) hashtable_rc_t hashtable_is_key_exists (hash_table_t *hashtblP, const uint64_t keyP)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
{ {
hash_node_t *node; hash_node_t *node;
...@@ -113,7 +119,7 @@ hashtbl_rc_t hashtbl_is_key_exists (hash_table_t *hashtblP, const uint64_t keyP) ...@@ -113,7 +119,7 @@ hashtbl_rc_t hashtbl_is_key_exists (hash_table_t *hashtblP, const uint64_t keyP)
return HASH_TABLE_KEY_NOT_EXISTS; return HASH_TABLE_KEY_NOT_EXISTS;
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
hashtbl_rc_t hashtbl_apply_funct_on_elements (hash_table_t *hashtblP, void functP(uint64_t keyP, void* dataP, void* parameterP), void* parameterP) hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t *hashtblP, void functP(uint64_t keyP, void* dataP, void* parameterP), void* parameterP)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
{ {
hash_node_t *node = NULL; hash_node_t *node = NULL;
...@@ -140,7 +146,7 @@ hashtbl_rc_t hashtbl_apply_funct_on_elements (hash_table_t *hashtblP, void funct ...@@ -140,7 +146,7 @@ hashtbl_rc_t hashtbl_apply_funct_on_elements (hash_table_t *hashtblP, void funct
* Adding a new element * Adding a new element
* To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size. * To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size.
*/ */
hashtbl_rc_t hashtbl_insert(hash_table_t *hashtblP, const uint64_t keyP, void *dataP) hashtable_rc_t hashtable_insert(hash_table_t *hashtblP, const uint64_t keyP, void *dataP)
{ {
hash_node_t *node; hash_node_t *node;
hash_size_t hash; hash_size_t hash;
...@@ -177,7 +183,7 @@ hashtbl_rc_t hashtbl_insert(hash_table_t *hashtblP, const uint64_t keyP, void *d ...@@ -177,7 +183,7 @@ hashtbl_rc_t hashtbl_insert(hash_table_t *hashtblP, const uint64_t keyP, void *d
* To remove an element from the hash table, we just search for it in the linked list for that hash value, * To remove an element from the hash table, we just search for it in the linked list for that hash value,
* and remove it if it is found. If it was not found, it is an error and -1 is returned. * and remove it if it is found. If it was not found, it is an error and -1 is returned.
*/ */
hashtbl_rc_t hashtbl_remove(hash_table_t *hashtblP, const uint64_t keyP) hashtable_rc_t hashtable_remove(hash_table_t *hashtblP, const uint64_t keyP)
{ {
hash_node_t *node, *prevnode=NULL; hash_node_t *node, *prevnode=NULL;
hash_size_t hash; hash_size_t hash;
...@@ -208,7 +214,7 @@ hashtbl_rc_t hashtbl_remove(hash_table_t *hashtblP, const uint64_t keyP) ...@@ -208,7 +214,7 @@ hashtbl_rc_t hashtbl_remove(hash_table_t *hashtblP, const uint64_t keyP)
* Searching for an element is easy. We just search through the linked list for the corresponding hash value. * Searching for an element is easy. We just search through the linked list for the corresponding hash value.
* NULL is returned if we didn't find it. * NULL is returned if we didn't find it.
*/ */
hashtbl_rc_t hashtbl_get(hash_table_t *hashtblP, const uint64_t keyP, void** dataP) hashtable_rc_t hashtable_get(hash_table_t *hashtblP, const uint64_t keyP, void** dataP)
{ {
hash_node_t *node; hash_node_t *node;
hash_size_t hash; hash_size_t hash;
...@@ -218,7 +224,7 @@ hashtbl_rc_t hashtbl_get(hash_table_t *hashtblP, const uint64_t keyP, void** dat ...@@ -218,7 +224,7 @@ hashtbl_rc_t hashtbl_get(hash_table_t *hashtblP, const uint64_t keyP, void** dat
return HASH_TABLE_BAD_PARAMETER_HASHTABLE; return HASH_TABLE_BAD_PARAMETER_HASHTABLE;
} }
hash=hashtblP->hashfunc(keyP)%hashtblP->size; hash=hashtblP->hashfunc(keyP)%hashtblP->size;
/* fprintf(stderr, "hashtbl_get() key=%s, hash=%d\n", key, hash);*/ /* fprintf(stderr, "hashtable_get() key=%s, hash=%d\n", key, hash);*/
node=hashtblP->nodes[hash]; node=hashtblP->nodes[hash];
...@@ -240,11 +246,11 @@ hashtbl_rc_t hashtbl_get(hash_table_t *hashtblP, const uint64_t keyP, void** dat ...@@ -240,11 +246,11 @@ hashtbl_rc_t hashtbl_get(hash_table_t *hashtblP, const uint64_t keyP, void** dat
* If the number of elements are reduced, the hash table will waste memory. That is why we provide a function for resizing the table. * If the number of elements are reduced, the hash table will waste memory. That is why we provide a function for resizing the table.
* Resizing a hash table is not as easy as a realloc(). All hash values must be recalculated and each element must be inserted into its new position. * Resizing a hash table is not as easy as a realloc(). All hash values must be recalculated and each element must be inserted into its new position.
* We create a temporary hash_table_t object (newtbl) to be used while building the new hashes. * We create a temporary hash_table_t object (newtbl) to be used while building the new hashes.
* This allows us to reuse hashtbl_insert() and hashtbl_remove(), when moving the elements to the new table. * This allows us to reuse hashtable_insert() and hashtable_remove(), when moving the elements to the new table.
* After that, we can just free the old table and copy the elements from newtbl to hashtbl. * After that, we can just free the old table and copy the elements from newtbl to hashtbl.
*/ */
hashtbl_rc_t hashtbl_resize(hash_table_t *hashtblP, hash_size_t sizeP) hashtable_rc_t hashtable_resize(hash_table_t *hashtblP, hash_size_t sizeP)
{ {
hash_table_t newtbl; hash_table_t newtbl;
hash_size_t n; hash_size_t n;
...@@ -262,9 +268,9 @@ hashtbl_rc_t hashtbl_resize(hash_table_t *hashtblP, hash_size_t sizeP) ...@@ -262,9 +268,9 @@ hashtbl_rc_t hashtbl_resize(hash_table_t *hashtblP, hash_size_t sizeP)
for(n=0; n<hashtblP->size; ++n) { for(n=0; n<hashtblP->size; ++n) {
for(node=hashtblP->nodes[n]; node; node=next) { for(node=hashtblP->nodes[n]; node; node=next) {
next = node->next; next = node->next;
hashtbl_insert(&newtbl, node->key, node->data); hashtable_insert(&newtbl, node->key, node->data);
// Lionel GAUTHIER: BAD CODE TO BE REWRITTEN // Lionel GAUTHIER: BAD CODE TO BE REWRITTEN
hashtbl_remove(hashtblP, node->key); hashtable_remove(hashtblP, node->key);
} }
} }
......
#ifndef _HASH_TABLE_H_ #ifndef _UTILS_COLLECTION_HASH_TABLE_H_
#define _HASH_TABLE_H_ #define _UTILS_COLLECTION_HASH_TABLE_H_
#include<stdlib.h> #include<stdlib.h>
#include <stdint.h> #include <stdint.h>
#include <stddef.h> #include <stddef.h>
typedef size_t hash_size_t; typedef size_t hash_size_t;
typedef enum hashtbl_return_code_e { typedef enum hashtable_return_code_e {
HASH_TABLE_OK = 0, HASH_TABLE_OK = 0,
HASH_TABLE_INSERT_OVERWRITTEN_DATA = 1, HASH_TABLE_INSERT_OVERWRITTEN_DATA = 1,
HASH_TABLE_KEY_NOT_EXISTS = 2, HASH_TABLE_KEY_NOT_EXISTS = 2,
HASH_TABLE_KEY_ALREADY_EXISTS = 3, HASH_TABLE_KEY_ALREADY_EXISTS = 3,
HASH_TABLE_BAD_PARAMETER_HASHTABLE = 4, HASH_TABLE_BAD_PARAMETER_HASHTABLE = 4,
HASH_TABLE_SYSTEM_ERROR = 5,
HASH_TABLE_CODE_MAX HASH_TABLE_CODE_MAX
} hashtbl_rc_t; } hashtable_rc_t;
typedef struct hash_node_s { typedef struct hash_node_s {
...@@ -30,15 +31,16 @@ typedef struct hash_table_s { ...@@ -30,15 +31,16 @@ typedef struct hash_table_s {
void (*freefunc)(void*); void (*freefunc)(void*);
} hash_table_t; } hash_table_t;
char* hashtble_rc_code2string(hashtbl_rc_t rcP); char* hashtable_rc_code2string(hashtable_rc_t rcP);
hash_table_t *hashtbl_create (hash_size_t size, hash_size_t (*hashfunc)(const uint64_t ), void (*freefunc)(void*)); void hash_free_int_func(void* memoryP);
hashtbl_rc_t hashtbl_destroy(hash_table_t *hashtbl); hash_table_t *hashtable_create (hash_size_t size, hash_size_t (*hashfunc)(const uint64_t ), void (*freefunc)(void*));
hashtbl_rc_t hashtbl_is_key_exists (hash_table_t *hashtbl, const uint64_t key); hashtable_rc_t hashtable_destroy(hash_table_t *hashtbl);
hashtbl_rc_t hashtbl_apply_funct_on_elements (hash_table_t *hashtblP, void funct(uint64_t keyP, void* dataP, void* parameterP), void* parameterP); hashtable_rc_t hashtable_is_key_exists (hash_table_t *hashtbl, const uint64_t key);
hashtbl_rc_t hashtbl_insert (hash_table_t *hashtbl, const uint64_t key, void *data); hashtable_rc_t hashtable_apply_funct_on_elements (hash_table_t *hashtblP, void funct(uint64_t keyP, void* dataP, void* parameterP), void* parameterP);
hashtbl_rc_t hashtbl_remove (hash_table_t *hashtbl, const uint64_t key); hashtable_rc_t hashtable_insert (hash_table_t *hashtbl, const uint64_t key, void *data);
hashtbl_rc_t hashtbl_get (hash_table_t *hashtbl, const uint64_t key, void **dataP); hashtable_rc_t hashtable_remove (hash_table_t *hashtbl, const uint64_t key);
hashtbl_rc_t hashtbl_resize (hash_table_t *hashtbl, hash_size_t size); hashtable_rc_t hashtable_get (hash_table_t *hashtbl, const uint64_t key, void **dataP);
hashtable_rc_t hashtable_resize (hash_table_t *hashtbl, hash_size_t size);
......
...@@ -8,7 +8,7 @@ ...@@ -8,7 +8,7 @@
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
/* /*
* Default hash function * Default hash function
* def_hashfunc() is the default used by hashtbl_create() when the user didn't specify one. * def_hashfunc() is the default used by hashtable_create() when the user didn't specify one.
* This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables. * This is a simple/naive hash function which adds the key's ASCII char values. It will probably generate lots of collisions on large hash tables.
*/ */
...@@ -24,11 +24,11 @@ static hash_size_t def_hashfunc(const void *keyP, int key_sizeP) ...@@ -24,11 +24,11 @@ static hash_size_t def_hashfunc(const void *keyP, int key_sizeP)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
/* /*
* Initialisation * Initialisation
* hashtbl_create() sets up the initial structure of the hash table. The user specified size will be allocated and initialized to NULL. * hashtable_create() sets up the initial structure of the hash table. The user specified size will be allocated and initialized to NULL.
* The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used. * The user can also specify a hash function. If the hashfunc argument is NULL, a default hash function is used.
* If an error occurred, NULL is returned. All other values in the returned obj_hash_table_t pointer should be released with hashtbl_destroy(). * If an error occurred, NULL is returned. All other values in the returned obj_hash_table_t pointer should be released with hashtable_destroy().
*/ */
obj_hash_table_t *obj_hashtbl_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const void*, int ), void (*freekeyfuncP)(void*), void (*freedatafuncP)(void*)) obj_hash_table_t *obj_hashtable_create(hash_size_t sizeP, hash_size_t (*hashfuncP)(const void*, int ), void (*freekeyfuncP)(void*), void (*freedatafuncP)(void*))
{ {
obj_hash_table_t *hashtbl; obj_hash_table_t *hashtbl;
...@@ -55,9 +55,9 @@ obj_hash_table_t *obj_hashtbl_create(hash_size_t sizeP, hash_size_t (*hashfuncP) ...@@ -55,9 +55,9 @@ obj_hash_table_t *obj_hashtbl_create(hash_size_t sizeP, hash_size_t (*hashfuncP)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
/* /*
* Cleanup * Cleanup
* The hashtbl_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the obj_hash_table_t. * The hashtable_destroy() walks through the linked lists for each possible hash value, and releases the elements. It also releases the nodes array and the obj_hash_table_t.
*/ */
hashtbl_rc_t obj_hashtbl_destroy(obj_hash_table_t *hashtblP) hashtable_rc_t obj_hashtable_destroy(obj_hash_table_t *hashtblP)
{ {
hash_size_t n; hash_size_t n;
obj_hash_node_t *node, *oldnode; obj_hash_node_t *node, *oldnode;
...@@ -77,7 +77,7 @@ hashtbl_rc_t obj_hashtbl_destroy(obj_hash_table_t *hashtblP) ...@@ -77,7 +77,7 @@ hashtbl_rc_t obj_hashtbl_destroy(obj_hash_table_t *hashtblP)
return HASH_TABLE_OK; return HASH_TABLE_OK;
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
hashtbl_rc_t obj_hashtbl_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP) hashtable_rc_t obj_hashtable_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP)
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
{ {
obj_hash_node_t *node; obj_hash_node_t *node;
...@@ -91,6 +91,10 @@ hashtbl_rc_t obj_hashtbl_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, ...@@ -91,6 +91,10 @@ hashtbl_rc_t obj_hashtbl_is_key_exists (obj_hash_table_t *hashtblP, void* keyP,
while(node) { while(node) {
if(node->key == keyP) { if(node->key == keyP) {
return HASH_TABLE_OK; return HASH_TABLE_OK;
} else if (node->key_size == key_sizeP) {
if (memcmp(node->key, keyP, key_sizeP) == 0) {
return HASH_TABLE_OK;
}
} }
node=node->next; node=node->next;
} }
...@@ -101,7 +105,7 @@ hashtbl_rc_t obj_hashtbl_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, ...@@ -101,7 +105,7 @@ hashtbl_rc_t obj_hashtbl_is_key_exists (obj_hash_table_t *hashtblP, void* keyP,
* Adding a new element * Adding a new element
* To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size. * To make sure the hash value is not bigger than size, the result of the user provided hash function is used modulo size.
*/ */
hashtbl_rc_t obj_hashtbl_insert(obj_hash_table_t *hashtblP, void* keyP, int key_sizeP, void *dataP) hashtable_rc_t obj_hashtable_insert(obj_hash_table_t *hashtblP, void* keyP, int key_sizeP, void *dataP)
{ {
obj_hash_node_t *node; obj_hash_node_t *node;
hash_size_t hash; hash_size_t hash;
...@@ -138,7 +142,7 @@ hashtbl_rc_t obj_hashtbl_insert(obj_hash_table_t *hashtblP, void* keyP, int key_ ...@@ -138,7 +142,7 @@ hashtbl_rc_t obj_hashtbl_insert(obj_hash_table_t *hashtblP, void* keyP, int key_
* To remove an element from the hash table, we just search for it in the linked list for that hash value, * To remove an element from the hash table, we just search for it in the linked list for that hash value,
* and remove it if it is found. If it was not found, it is an error and -1 is returned. * and remove it if it is found. If it was not found, it is an error and -1 is returned.
*/ */
hashtbl_rc_t obj_hashtbl_remove(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP) hashtable_rc_t obj_hashtable_remove(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP)
{ {
obj_hash_node_t *node, *prevnode=NULL; obj_hash_node_t *node, *prevnode=NULL;
hash_size_t hash; hash_size_t hash;
...@@ -150,7 +154,7 @@ hashtbl_rc_t obj_hashtbl_remove(obj_hash_table_t *hashtblP, const void* keyP, in ...@@ -150,7 +154,7 @@ hashtbl_rc_t obj_hashtbl_remove(obj_hash_table_t *hashtblP, const void* keyP, in
hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size; hash=hashtblP->hashfunc(keyP, key_sizeP)%hashtblP->size;
node=hashtblP->nodes[hash]; node=hashtblP->nodes[hash];
while(node) { while(node) {
if(node->key == keyP) { if ((node->key == keyP) || ((node->key_size == key_sizeP) && (memcmp(node->key, keyP, key_sizeP) == 0))){
if(prevnode) { if(prevnode) {
prevnode->next=node->next; prevnode->next=node->next;
} else { } else {
...@@ -171,7 +175,7 @@ hashtbl_rc_t obj_hashtbl_remove(obj_hash_table_t *hashtblP, const void* keyP, in ...@@ -171,7 +175,7 @@ hashtbl_rc_t obj_hashtbl_remove(obj_hash_table_t *hashtblP, const void* keyP, in
* Searching for an element is easy. We just search through the linked list for the corresponding hash value. * Searching for an element is easy. We just search through the linked list for the corresponding hash value.
* NULL is returned if we didn't find it. * NULL is returned if we didn't find it.
*/ */
hashtbl_rc_t obj_hashtbl_get(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP, void** dataP) hashtable_rc_t obj_hashtable_get(obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP, void** dataP)
{ {
obj_hash_node_t *node; obj_hash_node_t *node;
hash_size_t hash; hash_size_t hash;
...@@ -186,6 +190,11 @@ hashtbl_rc_t obj_hashtbl_get(obj_hash_table_t *hashtblP, const void* keyP, int k ...@@ -186,6 +190,11 @@ hashtbl_rc_t obj_hashtbl_get(obj_hash_table_t *hashtblP, const void* keyP, int k
if(node->key == keyP) { if(node->key == keyP) {
*dataP = node->data; *dataP = node->data;
return HASH_TABLE_OK; return HASH_TABLE_OK;
} else if (node->key_size == key_sizeP) {
if (memcmp(node->key, keyP, key_sizeP) == 0) {
*dataP = node->data;
return HASH_TABLE_OK;
}
} }
node=node->next; node=node->next;
} }
...@@ -193,6 +202,29 @@ hashtbl_rc_t obj_hashtbl_get(obj_hash_table_t *hashtblP, const void* keyP, int k ...@@ -193,6 +202,29 @@ hashtbl_rc_t obj_hashtbl_get(obj_hash_table_t *hashtblP, const void* keyP, int k
return HASH_TABLE_KEY_NOT_EXISTS; return HASH_TABLE_KEY_NOT_EXISTS;
} }
//------------------------------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------------------------------
/*
* Function to return all keys of an object hash table
*/
hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void ** keysP, unsigned int *sizeP)
{
size_t n = 0;
obj_hash_node_t *node = NULL;
obj_hash_node_t *next = NULL;
*sizeP = 0;
keysP = calloc(hashtblP->num_elements, sizeof(void *));
if (keysP) {
for(n=0; n<hashtblP->size; ++n) {
for(node=hashtblP->nodes[n]; node; node=next) {
keysP[*sizeP++] = node->key;
next = node->next;
}
}
return HASH_TABLE_OK;
}
return HASH_TABLE_SYSTEM_ERROR;
}
//-------------------------------------------------------------------------------------------------------------------------------
/* /*
* Resizing * Resizing
* The number of elements in a hash table is not always known when creating the table. * The number of elements in a hash table is not always known when creating the table.
...@@ -200,10 +232,10 @@ hashtbl_rc_t obj_hashtbl_get(obj_hash_table_t *hashtblP, const void* keyP, int k ...@@ -200,10 +232,10 @@ hashtbl_rc_t obj_hashtbl_get(obj_hash_table_t *hashtblP, const void* keyP, int k
* If the number of elements are reduced, the hash table will waste memory. That is why we provide a function for resizing the table. * If the number of elements are reduced, the hash table will waste memory. That is why we provide a function for resizing the table.
* Resizing a hash table is not as easy as a realloc(). All hash values must be recalculated and each element must be inserted into its new position. * Resizing a hash table is not as easy as a realloc(). All hash values must be recalculated and each element must be inserted into its new position.
* We create a temporary obj_hash_table_t object (newtbl) to be used while building the new hashes. * We create a temporary obj_hash_table_t object (newtbl) to be used while building the new hashes.
* This allows us to reuse hashtbl_insert() and hashtbl_remove(), when moving the elements to the new table. * This allows us to reuse hashtable_insert() and hashtable_remove(), when moving the elements to the new table.
* After that, we can just free the old table and copy the elements from newtbl to hashtbl. * After that, we can just free the old table and copy the elements from newtbl to hashtbl.
*/ */
hashtbl_rc_t obj_hashtbl_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP) hashtable_rc_t obj_hashtable_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP)
{ {
obj_hash_table_t newtbl; obj_hash_table_t newtbl;
hash_size_t n; hash_size_t n;
...@@ -216,14 +248,13 @@ hashtbl_rc_t obj_hashtbl_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP) ...@@ -216,14 +248,13 @@ hashtbl_rc_t obj_hashtbl_resize(obj_hash_table_t *hashtblP, hash_size_t sizeP)
newtbl.size = sizeP; newtbl.size = sizeP;
newtbl.hashfunc = hashtblP->hashfunc; newtbl.hashfunc = hashtblP->hashfunc;
if(!(newtbl.nodes=calloc(sizeP, sizeof(obj_hash_node_t*)))) return -1; if(!(newtbl.nodes=calloc(sizeP, sizeof(obj_hash_node_t*)))) return HASH_TABLE_SYSTEM_ERROR;
for(n=0; n<hashtblP->size; ++n) { for(n=0; n<hashtblP->size; ++n) {
for(node=hashtblP->nodes[n]; node; node=next) { for(node=hashtblP->nodes[n]; node; node=next) {
next = node->next; next = node->next;
obj_hashtbl_insert(&newtbl, node->key, node->key_size, node->data); obj_hashtable_insert(&newtbl, node->key, node->key_size, node->data);
//WARNING Lionel GAUTHIER: BAD CODE TO BE REWRITTEN obj_hashtable_remove(hashtblP, node->key, node->key_size);
obj_hashtbl_remove(hashtblP, node->key, node->key_size);
} }
} }
......
...@@ -25,13 +25,14 @@ typedef struct obj_hash_table_s { ...@@ -25,13 +25,14 @@ typedef struct obj_hash_table_s {
void (*freedatafunc)(void*); void (*freedatafunc)(void*);
} obj_hash_table_t; } obj_hash_table_t;
obj_hash_table_t *obj_hashtbl_create (hash_size_t size, hash_size_t (*hashfunc)(const void*, int ), void (*freekeyfunc)(void*), void (*freedatafunc)(void*)); obj_hash_table_t *obj_hashtable_create (hash_size_t size, hash_size_t (*hashfunc)(const void*, int ), void (*freekeyfunc)(void*), void (*freedatafunc)(void*));
hashtbl_rc_t obj_hashtbl_destroy(obj_hash_table_t *hashtblP); hashtable_rc_t obj_hashtable_destroy (obj_hash_table_t *hashtblP);
hashtbl_rc_t obj_hashtbl_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP); hashtable_rc_t obj_hashtable_is_key_exists (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP);
hashtbl_rc_t obj_hashtbl_insert (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP, void *dataP); hashtable_rc_t obj_hashtable_insert (obj_hash_table_t *hashtblP, void* keyP, int key_sizeP, void *dataP);
hashtbl_rc_t obj_hashtbl_remove (obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP); hashtable_rc_t obj_hashtable_remove (obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP);
hashtbl_rc_t obj_hashtbl_get (obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP, void ** dataP); hashtable_rc_t obj_hashtable_get (obj_hash_table_t *hashtblP, const void* keyP, int key_sizeP, void ** dataP);
hashtbl_rc_t obj_hashtbl_resize (obj_hash_table_t *hashtblP, hash_size_t sizeP); hashtable_rc_t obj_hashtable_get_keys(obj_hash_table_t *hashtblP, void ** keysP, unsigned int *sizeP);
hashtable_rc_t obj_hashtable_resize (obj_hash_table_t *hashtblP, hash_size_t sizeP);
......
...@@ -4,6 +4,7 @@ AM_CFLAGS = @ADD_CFLAGS@ \ ...@@ -4,6 +4,7 @@ AM_CFLAGS = @ADD_CFLAGS@ \
-I$(top_srcdir)/COMMON \ -I$(top_srcdir)/COMMON \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \ -I$(top_srcdir)/NAS/EURECOM-NAS/src/api/network \
-I$(top_srcdir)/NAS/EURECOM-NAS/src/include \ -I$(top_srcdir)/NAS/EURECOM-NAS/src/include \
-I$(top_srcdir)/SGW-LITE \
-I$(top_srcdir)/INTERTASK_INTERFACE -I$(top_srcdir)/INTERTASK_INTERFACE
AM_YFLAGS = -d AM_YFLAGS = -d
...@@ -14,7 +15,6 @@ libutils_la_SOURCES = \ ...@@ -14,7 +15,6 @@ libutils_la_SOURCES = \
conversions.h conversions.c \ conversions.h conversions.c \
enum_string.h enum_string.c \ enum_string.h enum_string.c \
log.c log.h \ log.c log.h \
mme_parser.y mme_scanner.l \
mme_config.c mme_config.h \ mme_config.c mme_config.h \
mme_default_values.h \ mme_default_values.h \
queue.h tree.h queue.h tree.h
This diff is collapsed.
...@@ -36,6 +36,44 @@ ...@@ -36,6 +36,44 @@
#ifndef MME_CONFIG_H_ #ifndef MME_CONFIG_H_
#define MME_CONFIG_H_ #define MME_CONFIG_H_
#define MME_CONFIG_STRING_MME_CONFIG "MME"
#define MME_CONFIG_STRING_REALM "REALM"
#define MME_CONFIG_STRING_MAXENB "MAXENB"
#define MME_CONFIG_STRING_MAXUE "MAXUE"
#define MME_CONFIG_STRING_RELATIVE_CAPACITY "RELATIVE_CAPACITY"
#define MME_CONFIG_STRING_STATISTIC_TIMER "MME_STATISTIC_TIMER"
#define MME_CONFIG_STRING_EMERGENCY_ATTACH_SUPPORTED "EMERGENCY_ATTACH_SUPPORTED"
#define MME_CONFIG_STRING_UNAUTHENTICATED_IMSI_SUPPORTED "UNAUTHENTICATED_IMSI_SUPPORTED"
#define MME_CONFIG_STRING_INTERTASK_INTERFACE_CONFIG "INTERTASK_INTERFACE"
#define MME_CONFIG_STRING_INTERTASK_INTERFACE_QUEUE_SIZE "ITTI_QUEUE_SIZE"
#define MME_CONFIG_STRING_S6A_CONFIG "S6A"
#define MME_CONFIG_STRING_S6A_CONF_FILE_PATH "S6A_CONF"
#define MME_CONFIG_STRING_SCTP_CONFIG "SCTP"
#define MME_CONFIG_STRING_SCTP_INSTREAMS "SCTP_INSTREAMS"
#define MME_CONFIG_STRING_SCTP_OUTSTREAMS "SCTP_OUTSTREAMS"
#define MME_CONFIG_STRING_S1AP_CONFIG "S1AP"
#define MME_CONFIG_STRING_S1AP_OUTCOME_TIMER "S1AP_OUTCOME_TIMER"
#define MME_CONFIG_STRING_GUMMEI_CONFIG "GUMMEI"
#define MME_CONFIG_STRING_MME_CODE "MME_CODE"
#define MME_CONFIG_STRING_MME_GID "MME_GID"
#define MME_CONFIG_STRING_PLMN "PLMN"
#define MME_CONFIG_STRING_MCC "MCC"
#define MME_CONFIG_STRING_MNC "MNC"
#define MME_CONFIG_STRING_TAC "TAC"
#define MME_CONFIG_STRING_NETWORK_INTERFACES_CONFIG "NETWORK_INTERFACES"
#define MME_CONFIG_STRING_INTERFACE_NAME_FOR_S1_MME "MME_INTERFACE_NAME_FOR_S1_MME"
#define MME_CONFIG_STRING_IPV4_ADDRESS_FOR_S1_MME "MME_IPV4_ADDRESS_FOR_S1_MME"
#define MME_CONFIG_STRING_INTERFACE_NAME_FOR_S11_MME "MME_INTERFACE_NAME_FOR_S11_MME"
#define MME_CONFIG_STRING_IPV4_ADDRESS_FOR_S11_MME "MME_IPV4_ADDRESS_FOR_S11_MME"
typedef struct mme_config_s { typedef struct mme_config_s {
/* Reader/writer lock for this configuration */ /* Reader/writer lock for this configuration */
pthread_rwlock_t rw_lock; pthread_rwlock_t rw_lock;
...@@ -81,33 +119,15 @@ typedef struct mme_config_s { ...@@ -81,33 +119,15 @@ typedef struct mme_config_s {
uint8_t outcome_drop_timer_sec; uint8_t outcome_drop_timer_sec;
} s1ap_config; } s1ap_config;
struct { struct {
char *sgw_interface_name_for_S1u_S12_S4_up;
uint32_t sgw_ip_address_for_S1u_S12_S4_up; uint32_t sgw_ip_address_for_S1u_S12_S4_up;
int sgw_ip_netmask_for_S1u_S12_S4_up;
char *sgw_interface_name_for_S5_S8_up;
uint32_t sgw_ip_address_for_S5_S8_up;
int sgw_ip_netmask_for_S5_S8_up;
char *pgw_interface_name_for_S5_S8;
uint32_t pgw_ip_address_for_S5_S8;
int pgw_ip_netmask_for_S5_S8;
char *pgw_interface_name_for_SGI;
uint32_t pgw_ip_addr_for_SGI;
int pgw_ip_netmask_for_SGI;
char *mme_interface_name_for_S1_MME; char *mme_interface_name_for_S1_MME;
uint32_t mme_ip_address_for_S1_MME; uint32_t mme_ip_address_for_S1_MME;
int mme_ip_netmask_for_S1_MME;
char *mme_interface_name_for_S11; char *mme_interface_name_for_S11;
uint32_t mme_ip_address_for_S11; uint32_t mme_ip_address_for_S11;
int mme_ip_netmask_for_S11;
char *sgw_interface_name_for_S11;
uint32_t sgw_ip_address_for_S11; uint32_t sgw_ip_address_for_S11;
int sgw_ip_netmask_for_S11;
} ipv4; } ipv4;
struct { struct {
char *conf_file; char *conf_file;
...@@ -126,6 +146,6 @@ int config_parse_opt_line(int argc, char *argv[], mme_config_t *mme_config); ...@@ -126,6 +146,6 @@ int config_parse_opt_line(int argc, char *argv[], mme_config_t *mme_config);
#define config_write_lock(mMEcONFIG) pthread_rwlock_wrlock(&(mMEcONFIG)->rw_lock) #define config_write_lock(mMEcONFIG) pthread_rwlock_wrlock(&(mMEcONFIG)->rw_lock)
#define config_unlock(mMEcONFIG) pthread_rwlock_unlock(&(mMEcONFIG)->rw_lock) #define config_unlock(mMEcONFIG) pthread_rwlock_unlock(&(mMEcONFIG)->rw_lock)
int yyparse(struct mme_config_s *mme_config_p); //int yyparse(struct mme_config_s *mme_config_p);
#endif /* MME_CONFIG_H_ */ #endif /* MME_CONFIG_H_ */
...@@ -93,9 +93,13 @@ ...@@ -93,9 +93,13 @@
* | |cpenb0+------------------+cpmme0| | * | |cpenb0+------------------+cpmme0| |
* | +------+ |bridge| +------+ | * | +------+ |bridge| +------+ |
* | |upenb0+-------+ | | | * | |upenb0+-------+ | | |
* +-----------+------+ | | | +-----------+ * +-----------+------+ | | | +-+------+--+
* +---|--+ | * +---|--+ |s11mme|
* | +-----------+ * | +---+--+
* | VLAN3 | (optional)
* | +---+--+
* | |s11sgw|
* | +-+------+--+
* | | S+P-GW | * | | S+P-GW |
* | VLAN2 +------+ +--------+ * | VLAN2 +------+ +--------+
* +----------+upsgw0| |pgwsgi0 + * +----------+upsgw0| |pgwsgi0 +
...@@ -132,7 +136,5 @@ ...@@ -132,7 +136,5 @@
#define DEFAULT_MME_IP_ADDRESS_FOR_S1_MME ("192.168.11.1") ///< MME control plane IP address #define DEFAULT_MME_IP_ADDRESS_FOR_S1_MME ("192.168.11.1") ///< MME control plane IP address
#define DEFAULT_MME_IP_NETMASK_FOR_S1_MME 24; #define DEFAULT_MME_IP_NETMASK_FOR_S1_MME 24;
#define IPV4_UP_UE_SUBNET ("10.2.0.0")
#endif /* MME_DEFAULT_VALUES_H_ */ #endif /* MME_DEFAULT_VALUES_H_ */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment