summaryrefslogtreecommitdiff
path: root/cesar/cl/test/utest_eoc/src/test_mactotei.c
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cl/test/utest_eoc/src/test_mactotei.c')
-rw-r--r--cesar/cl/test/utest_eoc/src/test_mactotei.c232
1 files changed, 232 insertions, 0 deletions
diff --git a/cesar/cl/test/utest_eoc/src/test_mactotei.c b/cesar/cl/test/utest_eoc/src/test_mactotei.c
new file mode 100644
index 0000000000..fbdcf67f13
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/src/test_mactotei.c
@@ -0,0 +1,232 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2009 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/test/utest_eoc/src/test_mactotei.c
+ * \brief Unit test for EoC mactotei table in the CL module.
+ * \ingroup cl
+ *
+ * This suite tests functions used for creating, refreshing and finding entries
+ * of EoC mactotei table.
+ */
+#include "common/std.h"
+
+#include "lib/test.h"
+#include "lib/stats.h"
+#include "cl/inc/context.h"
+#include "cl/cl_eoc_mactotei.h"
+
+static cl_t cl;
+static mac_config_t mac_config;
+
+extern void cl_eoc_time_update (cl_t *ctx);
+extern cl_eoc_mactotei_entry_t *cl_eoc_mactotei_entry_find (cl_t *ctx,
+ mac_t mac_addr);
+extern void cl_eoc_mactotei_remove_obsolete (cl_t *ctx);
+
+void
+test_entries (test_t test)
+{
+ cl.mac_config = &mac_config;
+ list_node_t *list_node = NULL;
+ cl_eoc_mactotei_entry_t *entry;
+ uint i,tei;
+ bool ok;
+
+ lib_stats_init ();
+ test_case_begin (test, "MACtoTEI table");
+ test_begin (test, "Initialize")
+ {
+ cl_eoc_mactotei_init (&cl);
+ i = 0;
+ list_node = list_next (&cl.cl_eoc_mactotei_table.ageing_list.nil);
+ do
+ {
+ entry = PARENT_OF (cl_eoc_mactotei_entry_t, l_age, list_node);
+ test_fail_unless (entry->timestamp == i);
+ i++;
+ list_node = list_next (list_node);
+ } while (list_node != &cl.cl_eoc_mactotei_table.ageing_list.nil);
+ test_fail_unless (i == MACTOTEI_NB_ENTRIES);
+ }
+ test_end;
+
+ test_begin (test, "Fill table")
+ {
+ cl.mac_config->tei = 1;
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445566ull, 4);
+ test_fail_if (!ok);
+ tei = cl_eoc_mactotei_find_tei (&cl, 0x0000112233445566ull);
+ test_fail_unless (tei == 4);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445577ull, 5);
+ test_fail_if (!ok);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445588ull, 10);
+ test_fail_if (!ok);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000122233445513ull, 5);
+ test_fail_if (!ok);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445599ull, 21);
+ test_fail_if (!ok);
+ tei = cl_eoc_mactotei_find_tei (&cl, 0x0000112233445588ull);
+ test_fail_unless (tei == 10);
+ cl_eoc_mactotei_entry_remove (&cl, 5);
+ cl_eoc_mactotei_entry_remove (&cl, 21);
+ cl_eoc_mactotei_entry_remove (&cl, 35);
+ tei = cl_eoc_mactotei_find_tei (&cl, 0x0000112233445577ull);
+ test_fail_unless (tei == MAC_TEI_UNASSOCIATED);
+
+ u64 mac_addr = 0x0000112233445512ull;
+ for (i = 0; i < 5 * MACTOTEI_NB_ENTRIES; i++)
+ {
+ mac_addr -= 0x1000000;
+ ok = cl_eoc_mactotei_entry_insert (&cl, mac_addr,
+ i % MACTOTEI_NB_ENTRIES);
+ test_fail_if (!ok);
+ }
+ cl_eoc_mactotei_entry_remove (&cl, 12);
+ }
+ test_end;
+
+ test_begin (test, "Obsoleteness & refresh")
+ {
+ list_node = list_prev (&cl.cl_eoc_mactotei_table.ageing_list.nil);
+ entry = PARENT_OF (cl_eoc_mactotei_entry_t, l_age, list_node);
+
+ /* increment time to exceed max age duration */
+ for (i = 0; i < 1.1*(cl.cl_eoc_mactotei_table.max_duration); i++)
+ cl_eoc_time_update (&cl);
+
+ tei = cl_eoc_mactotei_find_tei (&cl, entry->mac_addr);
+ test_fail_if (tei != MAC_TEI_UNASSOCIATED);
+
+ ok = cl_eoc_mactotei_entry_insert (&cl, entry->mac_addr, 111);
+ tei = cl_eoc_mactotei_find_tei (&cl, entry->mac_addr);
+ test_fail_if (tei != 111);
+ ok = cl_eoc_mactotei_entry_insert (&cl, entry->mac_addr, 111);
+ test_fail_if (!ok);
+
+ for (i = 0; i < 1234; i++)
+ {
+ ok = cl_eoc_mactotei_entry_insert (&cl, entry->mac_addr, 111);
+ test_fail_if (!ok);
+ }
+ }
+ test_end;
+
+ test_begin (test, "Removal of obsolete entries")
+ {
+ cl.mac_config->tei = 3;
+ cl_eoc_mactotei_init (&cl);
+ cl_eoc_mactotei_entry_insert (&cl, 0x0000030001D713ull, 6);
+ cl_eoc_mactotei_entry_insert (&cl, 0x0000050001D713ull, 8);
+ for (i = 0; i < cl.cl_eoc_mactotei_table.max_duration; i++)
+ cl_eoc_time_update (&cl);
+ cl_eoc_mactotei_entry_insert (&cl, 0x0000060001D713ull, 9);
+ cl_eoc_mactotei_entry_insert (&cl, 0x0000070001D713ull, 10);
+
+ cl_eoc_mactotei_remove_obsolete (&cl);
+
+ /* cl_eoc_mactotei_find_tei() hides obsolete entries.
+ * So use cl_eoc_mactotei_entry_find() instead. */
+ entry = cl_eoc_mactotei_entry_find (&cl, 0x0000030001D713ull);
+ test_fail_if (entry != NULL);
+ entry = cl_eoc_mactotei_entry_find (&cl, 0x0000050001D713ull);
+ test_fail_if (entry != NULL);
+ entry = cl_eoc_mactotei_entry_find (&cl, 0x0000060001D713ull);
+ test_fail_if (entry == NULL || entry->tei != 9);
+ entry = cl_eoc_mactotei_entry_find (&cl, 0x0000070001D713ull);
+ test_fail_if (entry == NULL || entry->tei != 10);
+ }
+ test_end;
+
+ test_begin (test, "Limitation of entries")
+ {
+ cl.mac_config->tei = 5;
+ cl_eoc_mactotei_init (&cl);
+ u64 mac_addr = 0x0000112233445566ull;
+ for (i = 0; i < cl.cl_eoc_mactotei_table.max_entries; i++)
+ {
+ mac_addr += 0x123456789ull;
+ ok = cl_eoc_mactotei_entry_insert (&cl, mac_addr, 5);
+ test_fail_if (!ok);
+ }
+ /* no new addresses allowed from sta side, as source addresses */
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000132233445588ull, 5);
+ test_fail_if (ok);
+ /* new addresses allowed as destination addresses*/
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000132233445511ull, 1);
+ test_fail_unless (ok);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000132233442511ull, 1);
+ test_fail_unless (ok);
+ test_fail_unless (cl.cl_eoc_mactotei_table.num_of_entries ==
+ cl.cl_eoc_mactotei_table.max_entries);
+
+ /* increment time to exceed max age duration */
+ for (i = 0; i < 1.1*(cl.cl_eoc_mactotei_table.max_duration); i++)
+ cl_eoc_time_update (&cl);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000132233445588ull, 5);
+ test_fail_unless (ok);
+ test_fail_unless (cl.cl_eoc_mactotei_table.num_of_entries == 1);
+ }
+ test_end;
+
+ test_begin (test, "Bridge info")
+ {
+ uint nb_entry;
+ mac_t mac, mac_ref;
+ uint tei_ref;
+ cl_eoc_mactotei_init (&cl);
+ cl.mac_config->tei = 1;
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445566ull, 4);
+ test_fail_if (!ok);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445577ull, 5);
+ test_fail_if (!ok);
+ for (i = 0; i < 0.9*(cl.cl_eoc_mactotei_table.max_duration); i++)
+ cl_eoc_time_update (&cl);
+ nb_entry = cl_eoc_mactotei_snapshot_create (&cl);
+ test_fail_unless (nb_entry == 2);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445512ull, 6);
+ test_fail_if (!ok);
+ nb_entry = cl_eoc_mactotei_snapshot_create (&cl);
+ test_fail_unless (nb_entry == 3);
+ for (i = 0; i < 0.3*(cl.cl_eoc_mactotei_table.max_duration); i++)
+ cl_eoc_time_update (&cl);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445513ull, 7);
+ test_fail_if (!ok);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445514ull, 8);
+ test_fail_if (!ok);
+ ok = cl_eoc_mactotei_entry_insert (&cl, 0x0000112233445515ull, 9);
+ test_fail_if (!ok);
+ nb_entry = cl_eoc_mactotei_snapshot_create (&cl);
+ test_fail_unless (nb_entry == 4);
+ mac_ref = 0x0000112233445515ull;
+ tei_ref = 9;
+ for (i = 0; i < nb_entry; i++)
+ {
+ mac = cl_eoc_mactotei_snapshot_get_mac (&cl, i);
+ test_fail_unless (mac == mac_ref - i);
+
+ uint tei = 0;
+ cl_eoc_mactotei_snapshot_get_mac_tei (&cl, i, &mac, &tei);
+ test_fail_if (mac != mac_ref - i);
+ test_fail_if (tei != tei_ref - i);
+ }
+ }
+ test_end;
+}
+
+int
+main (void)
+{
+ test_t test;
+ test_init (test, 0, NULL);
+
+ test_suite_begin (test, "Cl_EoC: MAC to Tei");
+ test_entries (test);
+
+ test_result (test);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}