From 2e6a7bc917d676748250ce4282e89e559a1a1725 Mon Sep 17 00:00:00 2001 From: dufour Date: Wed, 24 Dec 2008 14:54:07 +0000 Subject: * cl (see #180 & #166): - make the bridge table update function return a boolean to know if the bridge table has been changed or not, - update test and stub. git-svn-id: svn+ssh://pessac/svn/cesar/trunk@3704 017c9cb6-072f-447c-8318-d5b54f68fe89 --- cesar/cl/bridge_table.h | 6 +++++- cesar/cl/src/bridge_table.c | 11 ++++++++++- cesar/cl/stub/src/bridge_table.c | 4 ++-- cesar/cl/test/bridge_table/src/bridge_table.c | 24 +++++++++++++++--------- 4 files changed, 32 insertions(+), 13 deletions(-) (limited to 'cesar') diff --git a/cesar/cl/bridge_table.h b/cesar/cl/bridge_table.h index b20deca83d..3e969a3cff 100644 --- a/cesar/cl/bridge_table.h +++ b/cesar/cl/bridge_table.h @@ -58,6 +58,10 @@ bridge_table_add (cl_t *ctx, mac_t src_mac); /** * Update the local bridge table. * \param ctx the CL context structure. + * \return + * - true if the bridge table has been modified, + * - false is the bridge table has not been modified (no expired entry or no + * new entry to add). * * \attention You must call this function every one second. * @@ -65,7 +69,7 @@ bridge_table_add (cl_t *ctx, mac_t src_mac); * are expired and add the new one (because the add function only copy them to * a temporary table). */ -void +bool bridge_table_update (cl_t *ctx); /** diff --git a/cesar/cl/src/bridge_table.c b/cesar/cl/src/bridge_table.c index 0799245dff..893108b934 100644 --- a/cesar/cl/src/bridge_table.c +++ b/cesar/cl/src/bridge_table.c @@ -82,7 +82,7 @@ bridge_table_add (cl_t *ctx, mac_t src_mac) } } -void +bool bridge_table_update (cl_t *ctx) { /* Check parameter. */ @@ -124,6 +124,9 @@ bridge_table_update (cl_t *ctx) /* Affect new local bridge table. */ ctx->bridge_table.table = mac_lookup_table_convert (new_bridge_table); + + /* Bridge table has been modified. */ + return true; } else { @@ -148,8 +151,14 @@ bridge_table_update (cl_t *ctx) /* Affect new local bridge table. */ ctx->bridge_table.table = mac_lookup_table_convert (new_bridge_table); + + /* Bridge table has been modified. */ + return true; } } + + /* The bridge table has not been modified. */ + return false; } uint diff --git a/cesar/cl/stub/src/bridge_table.c b/cesar/cl/stub/src/bridge_table.c index 82f914251a..26915869b2 100644 --- a/cesar/cl/stub/src/bridge_table.c +++ b/cesar/cl/stub/src/bridge_table.c @@ -22,7 +22,7 @@ bridge_table_deinit (cl_t *ctx) __attribute__((weak)); void bridge_table_add (cl_t *ctx, mac_t src_mac) __attribute__((weak)); -void +bool bridge_table_update (cl_t *ctx) __attribute__((weak)); uint @@ -46,7 +46,7 @@ bridge_table_add (cl_t *ctx, mac_t src_mac) { } -void +bool bridge_table_update (cl_t *ctx) { } diff --git a/cesar/cl/test/bridge_table/src/bridge_table.c b/cesar/cl/test/bridge_table/src/bridge_table.c index 6e01921d3d..cf6672c3db 100644 --- a/cesar/cl/test/bridge_table/src/bridge_table.c +++ b/cesar/cl/test/bridge_table/src/bridge_table.c @@ -39,7 +39,7 @@ bridge_table_test_public_api (test_t test, cl_t *ctx) bridge_table_init (ctx); /* Call update without new entry to add. */ - bridge_table_update (ctx); + test_fail_unless (bridge_table_update (ctx) == false); /* Add some entries. */ for (count = 0; count < (BRIDGE_TABLE_MAX_TMP_ENTRY / 2); count ++) @@ -53,7 +53,7 @@ bridge_table_test_public_api (test_t test, cl_t *ctx) test_fail_if (bridge_table_size (ctx) != 0); /* Update table. */ - bridge_table_update (ctx); + test_fail_unless (bridge_table_update (ctx) == true); /* There should be 3 entries because of previous update. */ test_fail_if (bridge_table_size (ctx) != table_size); @@ -67,7 +67,7 @@ bridge_table_test_public_api (test_t test, cl_t *ctx) table_size += BRIDGE_TABLE_MAX_TMP_ENTRY; /* Update table. */ - bridge_table_update (ctx); + test_fail_unless (bridge_table_update (ctx) == true); /* Check if table has been correctly update with new entries coming * from the temporary table. */ @@ -88,13 +88,13 @@ bridge_table_test_public_api (test_t test, cl_t *ctx) /* Update many times. */ for (count = 0; count < (BRIDGE_TABLE_ENTRY_TIMEOUT - 2); count++) - bridge_table_update (ctx); + test_fail_unless (bridge_table_update (ctx) == false); /* There should be no entry removed for the moment. */ test_fail_if (bridge_table_size (ctx) != table_size); /* Next update should remove the first added entries. */ - bridge_table_update (ctx); + test_fail_unless (bridge_table_update (ctx) == true); table_size -= (BRIDGE_TABLE_MAX_TMP_ENTRY / 2); test_fail_if (bridge_table_size (ctx) != table_size); @@ -110,7 +110,7 @@ bridge_table_test_public_api (test_t test, cl_t *ctx) bridge_table_add (ctx, 0x003001 + BRIDGE_TABLE_MAX_TMP_ENTRY / 2); /* Update. */ - bridge_table_update (ctx); + test_fail_unless (bridge_table_update (ctx) == true); /* There should be only the last added entry remaining. */ table_size = 1; @@ -119,13 +119,19 @@ bridge_table_test_public_api (test_t test, cl_t *ctx) != (0x003001 + BRIDGE_TABLE_MAX_TMP_ENTRY / 2)); /* Update many times until the entry is removed. */ - for (count = 0; count < BRIDGE_TABLE_ENTRY_TIMEOUT; count++) - bridge_table_update (ctx); + for (count = 0; count < BRIDGE_TABLE_ENTRY_TIMEOUT - 1; count++) + { + if (count != (BRIDGE_TABLE_ENTRY_TIMEOUT - 2)) + test_fail_unless (bridge_table_update (ctx) == false); + else + test_fail_unless (bridge_table_update (ctx) == true); + } + table_size = 0; test_fail_if (bridge_table_size (ctx) != table_size); /* Update one last time. */ - bridge_table_update (ctx); + test_fail_unless (bridge_table_update (ctx) == false); /* Clean. */ bridge_table_deinit (ctx); -- cgit v1.2.3