summaryrefslogtreecommitdiff
path: root/cesar/cl/test
diff options
context:
space:
mode:
Diffstat (limited to 'cesar/cl/test')
-rw-r--r--cesar/cl/test/bridge_table/Makefile1
-rw-r--r--cesar/cl/test/data_rate/Makefile1
-rw-r--r--cesar/cl/test/functional/host-Config2
-rw-r--r--cesar/cl/test/functional/src/cl.c4
-rw-r--r--cesar/cl/test/utest/src/cl.c3
-rw-r--r--cesar/cl/test/utest/src/misc.c3
-rw-r--r--cesar/cl/test/utest_eoc/Config9
-rw-r--r--cesar/cl/test/utest_eoc/Makefile17
-rw-r--r--cesar/cl/test/utest_eoc/src/cl.c50
-rw-r--r--cesar/cl/test/utest_eoc/src/hle_tools.c37
-rw-r--r--cesar/cl/test/utest_eoc/src/mcast.c69
-rw-r--r--cesar/cl/test/utest_eoc/src/receive.c83
-rw-r--r--cesar/cl/test/utest_eoc/src/send.c261
-rw-r--r--cesar/cl/test/utest_eoc/src/test.c88
-rw-r--r--cesar/cl/test/utest_eoc/src/test_mactotei.c232
-rw-r--r--cesar/cl/test/utest_eoc/test.h124
16 files changed, 983 insertions, 1 deletions
diff --git a/cesar/cl/test/bridge_table/Makefile b/cesar/cl/test/bridge_table/Makefile
index 2a2de34cc1..53e865768c 100644
--- a/cesar/cl/test/bridge_table/Makefile
+++ b/cesar/cl/test/bridge_table/Makefile
@@ -4,6 +4,7 @@ HOST_PROGRAMS = test_bridge_table
test_bridge_table_SOURCES = test_bridge_table.c
test_bridge_table_MODULES = lib cl hal/ipmbox/stub
+test_bridge_table_CONFIG_MODULES = mac/common
# Overrides source of the cl module.
cl_MODULE_SOURCES = bridge_table.c
diff --git a/cesar/cl/test/data_rate/Makefile b/cesar/cl/test/data_rate/Makefile
index 3156b1d874..8cbb78f51e 100644
--- a/cesar/cl/test/data_rate/Makefile
+++ b/cesar/cl/test/data_rate/Makefile
@@ -7,6 +7,7 @@ INCLUDES = cl/test/data_rate/override
HOST_PROGRAMS = data_rate
data_rate_SOURCES = data_rate_test.c
data_rate_MODULES = lib cl hal/ipmbox/stub
+data_rate_CONFIG_MODULES = mac/common
# Overrides source of the cl module.
cl_MODULE_SOURCES = data_rate.c
diff --git a/cesar/cl/test/functional/host-Config b/cesar/cl/test/functional/host-Config
new file mode 100644
index 0000000000..fdbfb45e5a
--- /dev/null
+++ b/cesar/cl/test/functional/host-Config
@@ -0,0 +1,2 @@
+CONFIG_STATS = n
+CONFIG_BLK_NB = 2048
diff --git a/cesar/cl/test/functional/src/cl.c b/cesar/cl/test/functional/src/cl.c
index 636b6bb1a7..2945b6f5a2 100644
--- a/cesar/cl/test/functional/src/cl.c
+++ b/cesar/cl/test/functional/src/cl.c
@@ -64,6 +64,10 @@ cl_test_init (cl_test_t *test)
mac_ntb_init (&test->mac_config);
test->cl = cl_init (test->mac_store, (sar_t*) test, &test->mac_config,
(ipmbox_t*) test, INVALID_PTR);
+ /* Force blk initialization. */
+ pb_t *pb = blk_alloc ();
+ dbg_assert (pb);
+ blk_release (pb);
}
void
diff --git a/cesar/cl/test/utest/src/cl.c b/cesar/cl/test/utest/src/cl.c
index 031f8ea520..eafa5cd2fe 100644
--- a/cesar/cl/test/utest/src/cl.c
+++ b/cesar/cl/test/utest/src/cl.c
@@ -15,6 +15,7 @@
#include "lib/test.h"
#include "lib/blk.h"
#include "lib/trace.h"
+#include "lib/stats.h"
void
cl_test_suite_send (test_t test);
@@ -34,11 +35,13 @@ main (int argc, char **argv)
test_t test;
test_init (test, argc, argv);
trace_init ();
+ lib_stats_init();
cl_test_suite_send (test);
cl_test_suite_receive (test);
cl_test_suite_misc (test);
cl_test_brg_rx (test);
trace_uninit ();
+ lib_stats_uninit();
test_begin (test, "Memory")
{
test_fail_if (blk_check_memory() == false, "Memory not freed");
diff --git a/cesar/cl/test/utest/src/misc.c b/cesar/cl/test/utest/src/misc.c
index 0032ecaa73..ed86e7a0ad 100644
--- a/cesar/cl/test/utest/src/misc.c
+++ b/cesar/cl/test/utest/src/misc.c
@@ -14,8 +14,9 @@
#include "lib/test.h"
#include "cl/test/utest/test.h"
#include "cl/cl_mactotei.h"
-#include <stdio.h>
+#include "cl/mcast.h"
#include "cl/inc/context.h"
+#include <stdio.h>
uint
cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
diff --git a/cesar/cl/test/utest_eoc/Config b/cesar/cl/test/utest_eoc/Config
new file mode 100644
index 0000000000..63734d7175
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/Config
@@ -0,0 +1,9 @@
+CONFIG_TRACE = y
+CONFIG_MAC_COMMON_EOC_TEI = y
+CONFIG_CL_EOC_ROUTE = y
+CONFIG_MAC_COMMON_EOC_MFS = y
+CONFIG_MAC_COMMON_EOC_SCHED = y
+CONFIG_CL_EOC_CLASSIFY = y
+CONFIG_MAC_PBPROC_EOC_FC = y
+CONFIG_CL_MCAST = y
+
diff --git a/cesar/cl/test/utest_eoc/Makefile b/cesar/cl/test/utest_eoc/Makefile
new file mode 100644
index 0000000000..56ba1c605b
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/Makefile
@@ -0,0 +1,17 @@
+BASE = ../../..
+
+DEFS = -DNO_PRIVATE
+HOST_PROGRAMS = test_cl test_cl_mactotei
+
+test_cl_SOURCES = cl.c test.c mcast.c hle_tools.c send.c receive.c
+test_cl_MODULES = lib cl mac/common \
+ mac/sar/stub bufmgr/stub hal/ipmbox/stub hle/tools
+test_cl_CONFIG_MODULES = mac/sar
+
+test_cl_mactotei_SOURCES = test_mactotei.c hle_tools.c
+test_cl_mactotei_MODULES = lib cl mac/common \
+ mac/sar/stub bufmgr/stub hal/ipmbox/stub
+
+hle_tools_MODULE_SOURCES =
+
+include $(BASE)/common/make/top.mk
diff --git a/cesar/cl/test/utest_eoc/src/cl.c b/cesar/cl/test/utest_eoc/src/cl.c
new file mode 100644
index 0000000000..ff315780d8
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/src/cl.c
@@ -0,0 +1,50 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/test/utest_eoc/src/cl.c
+ * \brief « brief description »
+ * \ingroup « module »
+ *
+ * « long description »
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "lib/blk.h"
+#include "lib/trace.h"
+#include "lib/stats.h"
+
+void
+cl_test_suite_mcast (test_t test);
+
+void
+cl_test_suite_send (test_t test);
+
+void
+cl_test_suite_receive (test_t test);
+
+int
+main (int argc, char **argv)
+{
+ test_t test;
+ test_init (test, argc, argv);
+ trace_init ();
+ lib_stats_init ();
+ cl_test_suite_send (test);
+ cl_test_suite_mcast (test);
+ cl_test_suite_receive (test);
+ lib_stats_uninit ();
+ trace_uninit ();
+ test_begin (test, "Memory")
+ {
+ test_fail_if (blk_check_memory() == false, "Memory not freed");
+ }
+ test_end;
+ trace_uninit ();
+ test_result (test);
+ return test_nb_failed (test) == 0 ? 0 : 1;
+}
diff --git a/cesar/cl/test/utest_eoc/src/hle_tools.c b/cesar/cl/test/utest_eoc/src/hle_tools.c
new file mode 100644
index 0000000000..eba7086609
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/src/hle_tools.c
@@ -0,0 +1,37 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/test/utest_eoc/src/hle_tools.c
+ * \brief Stub hle tools.
+ * \ingroup cl
+ */
+#include "common/std.h"
+#include "hle/tools/tools.h"
+
+#include "cl/test/utest_eoc/test.h"
+#include "config/hle.h"
+
+hle_tools_t *
+hle_tools_init (ipmbox_t *ipmbox)
+{
+ static hle_tools_test_t hle_tools;
+ hle_tools.msg = NULL;
+ return (hle_tools_t *) &hle_tools;
+}
+
+void
+hle_tools_uninit (hle_tools_t *ctx)
+{
+}
+
+void
+hle_tools_msg_recv (hle_tools_t *ctx, const ipmbox_msg_mbx_t *msg)
+{
+ hle_tools_test_t *t = (hle_tools_test_t*) ctx;
+ t->msg = (ipmbox_msg_mbx_t*) msg;
+}
diff --git a/cesar/cl/test/utest_eoc/src/mcast.c b/cesar/cl/test/utest_eoc/src/mcast.c
new file mode 100644
index 0000000000..097b37c426
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/src/mcast.c
@@ -0,0 +1,69 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2011 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/test/utest_eoc/src/mcast.c
+ * \brief Multicast test.
+ * \ingroup cl
+ */
+#include "common/std.h"
+#include "lib/test.h"
+#include "cl/test/utest_eoc/test.h"
+#include "config/cl/eoc.h"
+#include "cl/inc/context.h"
+#include "cl/mcast.h"
+
+#if (!CONFIG_CL_EOC_ROUTE)
+# error (!CONFIG_CL_EOC_ROUTE)
+#endif
+
+void
+cl_test_case_mcast_master (test_t test)
+{
+ test_case_begin (test, "Master");
+ cl_test_t ctx;
+ cl_test_init (&ctx, 0x4354);
+ mac_t mac_group = MAC_ADDRESS (0x01, 0x00, 0x5E, 0x00, 0x00, 0x01);
+ mac_t mac_member = 0xe03708b65000ll;
+ test_begin (test, "No group")
+ {
+ igmp_groups_t *igmp = cl_get_igmp_groups (ctx.cl);
+ igmp->nb = 0;
+ cl_update_igmp_groups (ctx.cl);
+ test_fail_unless (igmp->nb == 0);
+ }
+ test_end;
+ test_begin (test, "Groups")
+ {
+ bool ok = false;
+ ok = cl_eoc_mactotei_entry_insert (ctx.cl, mac_member, 3);
+ test_fail_unless (ok);
+ /* Add a group. */
+ igmp_groups_t *igmp = cl_get_igmp_groups (ctx.cl);
+ igmp->nb = 1;
+ igmp->group_mac[0] = mac_group;
+ igmp->nb_total_members[0] = 1;
+ igmp->member_mac[0][0] = mac_member;
+ /* Update the igmp group. */
+ cl_update_igmp_groups (ctx.cl);
+ test_fail_unless (igmp->nb == 1);
+ test_fail_unless (igmp->group_mac[0]);
+ test_fail_unless (igmp->nb_total_members[0] == 1);
+ test_fail_unless (igmp->nb_actual_members[0] == 1);
+ test_fail_unless (igmp->member_mac[0][0] == mac_member);
+ test_fail_unless (igmp->member_tei[0][0] == 3);
+ }
+ test_end;
+ cl_test_uninit (&ctx);
+}
+
+void
+cl_test_suite_mcast (test_t test)
+{
+ test_suite_begin (test, "Multicast");
+ cl_test_case_mcast_master (test);
+}
diff --git a/cesar/cl/test/utest_eoc/src/receive.c b/cesar/cl/test/utest_eoc/src/receive.c
new file mode 100644
index 0000000000..eb2f70e96d
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/src/receive.c
@@ -0,0 +1,83 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+
+/**
+ * \file cl/test/utest_eoc/src/receive.c
+ * \brief CL RX unit tests.
+ * \ingroup cl/test/utest_eoc
+ */
+
+#include <string.h>
+#include "common/std.h"
+#include "common/defs/ethernet.h"
+#include "lib/test.h"
+#include "cl/test/utest_eoc/test.h"
+#include "cl/inc/receive.h"
+#include "cl/inc/context.h"
+
+void
+test_case__cl_sar_data_recv (test_t test)
+{
+ test_case_begin (test, "Receive DATA");
+
+ u8 buffer[ETH_PACKET_MAX_SIZE];
+ cl_test_t t;
+ uint length = 500;
+ bool added = false;
+ uint j = 0;
+ uint rx_data = 0;
+ uint rx_data_bytes = 0;
+ uint rx_data_multicast = 0;
+ mac_t sta_mac [] = {0x123456789abcull, 0x23456789abceull,
+ 0x0100005E0001ull};
+ mfs_rx_t *mfs[COUNT(sta_mac)];
+ cl_test_init (&t, 0x9999432);
+
+ test_begin (test, "From SAR")
+ {
+ for (j = 0; j < COUNT (sta_mac); j++)
+ {
+ mfs[j] = mac_store_mfs_add_rx (t.mac_store, false, false,
+ MAC_LLID_MIN + 1, j + 100, &added);
+ dbg_assert (added);
+ cl_test_prepare_buffer (&t, buffer, length, sta_mac[j], 0);
+ rx_data_bytes = t.cl->stats.rx_data_bytes;
+ rx_data = t.cl->stats.rx_data;
+ cl_sar_data_recv (t.cl, buffer, length, mfs[j]);
+ test_fail_unless (t.cl->stats.rx_data_bytes
+ == rx_data_bytes + length);
+ if (!mac_is_multicast(sta_mac[j]))
+ {
+ test_fail_unless (t.cl->stats.rx_data == rx_data + 1);
+ test_fail_unless (t.cl->stats.rx_data_multicast
+ == rx_data_multicast);
+ }
+ else
+ {
+ test_fail_unless (t.cl->stats.rx_data == rx_data);
+ test_fail_unless (t.cl->stats.rx_data_multicast
+ == rx_data_multicast + 1);
+ }
+ test_fail_unless (t.pwl_recv.buffer == buffer);
+ test_fail_unless (t.pwl_recv.length == length);
+
+ mac_store_mfs_remove (t.mac_store, PARENT_OF (mfs_t, rx, mfs[j]));
+ blk_release (mfs [j]);
+ dbg_check (mac_store_sta_remove (t.mac_store, j + 100));
+ }
+ }
+ test_end;
+ cl_test_uninit (&t);
+}
+
+void
+cl_test_suite_receive (test_t test)
+{
+ test_suite_begin (test, "CL receive");
+ test_case__cl_sar_data_recv (test);
+}
diff --git a/cesar/cl/test/utest_eoc/src/send.c b/cesar/cl/test/utest_eoc/src/send.c
new file mode 100644
index 0000000000..58af73dd68
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/src/send.c
@@ -0,0 +1,261 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/test/utest_eoc/src/send.c
+ * \brief CL TX unit tests.
+ * \ingroup cl/test/utest_eoc
+ */
+#include <string.h>
+
+#include "common/std.h"
+#include "lib/test.h"
+
+#include "cl/test/utest_eoc/test.h"
+#include "cl/inc/send.h"
+#include "cl/inc/context.h"
+#include "lib/bitstream.h"
+
+uint
+cl_classifer_get_lid (cl_t *ctx, uint tei, uint tag,
+ bool *bcast, bool *acs,
+ bool *drop);
+
+void
+sar_msdu_process (sar_t *ctx, u8 *buffer, u16 length,
+ mfs_tx_t *mfs, u32 arrival_time_ntb)
+{
+ sar_test_t *t = (sar_test_t*) ctx;
+ dbg_assert (ctx);
+ dbg_assert (t->nb <= TEST_BUFFER_MAX_NB);
+
+ t->buffer[t->nb] = buffer;
+ t->length[t->nb] = length;
+ t->mfs[t->nb] = mfs;
+ t->nb++;
+}
+
+void
+cl_test_case__cl_data_send_prepare (test_t test)
+{
+ test_case_begin (test, "Data send");
+
+ u8 buffer [1024];
+ cl_test_t t;
+ cl_data_send_link_t expected;
+ mac_t sta_mac [] = {0x123456789abcull, 0x23456789abceull};
+ mfs_tx_t *mfs[COUNT(sta_mac)];
+ uint i, j;
+ uint start_time_ntb = 0;
+ uint tag = 0;
+ uint tx_data = 0;
+ uint tx_data_bytes = 0;
+ uint sar_nb = 0;
+ uint length = 123;
+ bool added = false;
+
+ cl_test_init (&t, 0x95490d);
+ cl_test_prepare_mactotei (&t, sta_mac, COUNT (sta_mac));
+
+ test_begin (test, "To SAR")
+ for (j = 0; j < COUNT (sta_mac); j++)
+ {
+ mfs[j] = mac_store_mfs_add_tx (t.mac_store, false, false,
+ MAC_LLID_MIN + 1, j + 100, &added);
+ dbg_assert (added);
+ t.sar.nb = 0;
+ cl_test_prepare_buffer (&t, buffer, length, sta_mac[j], 0);
+ expected.mfs = mfs[j];
+ expected.last_update_date_ntb = start_time_ntb;
+ expected.dmac = sta_mac[j];
+ for (i = start_time_ntb; i < 500000; i+= 100000)
+ {
+ if (i == MAC_MS_TO_TCK (CL_DATA_SEND_EXCEED_TIME_MS))
+ expected.last_update_date_ntb = i;
+ tx_data_bytes = t.cl->stats.tx_data_bytes;
+ tx_data = t.cl->stats.tx_data;
+ sar_nb = t.sar.nb;
+ cl_data_send (t.cl, buffer, length, tag, i);
+ test_fail_unless (t.cl->data_send_link.mfs == expected.mfs);
+ test_fail_unless (t.cl->data_send_link.last_update_date_ntb
+ == expected.last_update_date_ntb);
+ test_fail_unless (t.cl->stats.tx_data_bytes
+ == tx_data_bytes + length);
+ test_fail_unless (t.cl->stats.tx_data == tx_data + 1);
+ test_fail_unless (t.sar.nb == sar_nb + 1);
+ test_fail_unless (t.cl->data_send_link.dmac
+ == bitstream_direct_read_large (buffer, 0, 48));
+ }
+ mac_store_mfs_remove (t.mac_store, PARENT_OF (mfs_t, tx, mfs[j]));
+ blk_release (mfs [j]);
+ dbg_check (mac_store_sta_remove (t.mac_store, j + 100));
+ }
+ test_end;
+
+ cl_test_uninit (&t);
+}
+
+void
+cl_test_case__cl_data_send_mcast (test_t test)
+{
+ test_case_begin (test, "Multicast send");
+
+ u8 buffer [1024];
+ cl_test_t t;
+ mfs_tx_t *mfs_ref, *mfs_mcast[MCAST_GROUP_MAX_NB][MCAST_MEMBER_MAX_NB];
+ uint i, j;
+ uint start_time_ntb = 0;
+ uint tx_data_multicast = 0;
+ uint tx_data = 0;
+ uint tx_data_bytes = 0;
+ uint length = 123;
+ bool added = false;
+ bool bcast = false;
+ bool acs = false;
+ bool drop = false;
+
+ cl_test_init (&t, 0x95490d);
+
+ test_begin (test, "Multicast data.")
+ {
+ /** Prepare the groups and the mactotei table. */
+ for (j = 0; j < MCAST_GROUP_MAX_NB; j++)
+ {
+ t.cl->groups.group_mac[j] =
+ MAC_ADDRESS (0x01, 0x00, 0x5E, 0x00, j + 1, 0x01);
+ t.cl->groups.nb_actual_members[j] = j % (MCAST_MEMBER_MAX_NB + 1);
+ t.cl->groups.member_tei[j][0] = MAC_TEI_UNASSOCIATED;
+
+ for (i = 0; i < t.cl->groups.nb_actual_members[j]; i++)
+ {
+ t.cl->groups.member_tei[j][i]
+ = 100 + j * MCAST_MEMBER_MAX_NB + i;
+ mfs_mcast[j][i] = mac_store_mfs_add_tx (t.mac_store, false,
+ false, MAC_LLID_MIN + 1,
+ t.cl->groups.member_tei[j][i], &added);
+ dbg_assert (added);
+ }
+ cl_eoc_mactotei_entry_insert (t.cl, t.cl->groups.group_mac[j],
+ MAC_TEI_BCAST);
+ }
+ t.cl->groups.nb = MCAST_GROUP_MAX_NB;
+
+ for (j = 0; j < MCAST_GROUP_MAX_NB; j++)
+ {
+ cl_test_prepare_buffer (&t, buffer, length,
+ MAC_ADDRESS (0x01, 0x00, 0x5E, 0x00, j + 1, 0x01),
+ 0);
+
+ /** Send the multicast message */
+ t.sar.nb = 0;
+ tx_data_bytes = t.cl->stats.tx_data_bytes;
+ tx_data_multicast = t.cl->stats.tx_data_multicast;
+ tx_data = t.cl->stats.tx_data;
+
+ cl_data_send (t.cl, buffer, length, 0, start_time_ntb);
+
+ test_fail_unless (t.cl->stats.tx_data_bytes
+ == tx_data_bytes + length);
+ test_fail_unless (t.cl->stats.tx_data_multicast
+ == tx_data_multicast + 1);
+ test_fail_unless (t.cl->stats.tx_data == tx_data);
+
+ if (t.cl->groups.nb_actual_members[j] == 0)
+ {
+ test_fail_unless (t.sar.nb == 0);
+ }
+ else
+ {
+ test_fail_unless (t.sar.nb
+ == t.cl->groups.nb_actual_members[j]);
+
+ for (i = 0; i < t.cl->groups.nb_actual_members[j]; i++)
+ {
+ uint tei = 100 + j * MCAST_MEMBER_MAX_NB + i;
+ uint lid = cl_classifer_get_lid (t.cl, tei, 0, &bcast,
+ &acs, &drop);
+ mfs_ref = mac_store_mfs_get_tx (t.cl->mac_store, bcast,
+ false, lid, tei);
+
+ test_fail_unless (mfs_ref == t.sar.mfs[i]);
+ test_fail_unless (buffer == t.sar.buffer[i]);
+ test_fail_unless (mfs_ref->common.tei == tei);
+ test_fail_unless (bcast == false);
+
+ mac_store_mfs_remove (t.mac_store,
+ PARENT_OF (mfs_t, tx, mfs_ref));
+ blk_release (mfs_ref);
+ dbg_check (mac_store_sta_remove (t.mac_store, tei));
+ }
+ }
+ for (i = 0; i < t.cl->groups.nb_actual_members[j]; i++)
+ {
+ mac_store_mfs_remove (t.mac_store,
+ PARENT_OF (mfs_t, tx, mfs_mcast[j][i]));
+ blk_release (mfs_mcast[j][i]);
+ }
+ }
+ cl_mactotei_release_table (t.cl);
+ }
+ test_end;
+
+ test_begin (test, "Multicast not IGMP members")
+ {
+ /*
+ * From Wikipedia
+ * http://en.wikipedia.org/wiki/Multicast_address#Ethernet
+ *
+ * 01-00-0C-CC-CC-CC 0x0802 CDP, VTP
+ * 01-00-0C-CC-CC-CD 0x0802 Cisco Shared Spanning Tree Protocol Address
+ * 01-80-C2-00-00-00 0x0802 Spanning Tree Protocol IEEE 802.1D
+ * 01-80-C2-00-00-08 0x0802 Spanning Tree Protocol IEEE 802.1AD
+ * 01-80-C2-00-00-02 0x8809 Ethernet OAM Protocol IEEE 802.3ah
+ * 01-00-5E-xx-xx-xx 0x0800 IPv4 Multicast (RFC 1112)
+ */
+ mac_t mcast_mac_addr[] = {
+ MAC_ADDRESS (0x01, 0x00, 0x0C, 0xCC, 0xCC, 0xCC),
+ MAC_ADDRESS (0x01, 0x00, 0x0C, 0xCC, 0xCC, 0xCD),
+ MAC_ADDRESS (0x01, 0x80, 0xC2, 0x00, 0x00, 0x00),
+ MAC_ADDRESS (0x01, 0x80, 0xC2, 0x00, 0x00, 0x08),
+ MAC_ADDRESS (0x01, 0x80, 0xC2, 0x00, 0x00, 0x02),
+ MCAST_MAC_IGMP_GENERAL_QUERY,
+ };
+
+ uint i;
+ uint tag = 0;
+ for (i = 0; i < COUNT (mcast_mac_addr); i++)
+ {
+ mfs_t *mfs;
+ cl_test_prepare_buffer (&t, buffer, length, mcast_mac_addr[i],
+ tag);
+ cl_data_send (t.cl, buffer, length, tag, 0x0);
+ mfs = PARENT_OF_OR_NULL (mfs_t, tx, t.sar.mfs[0]);
+ test_fail_unless (mfs && mfs->common.bcast);
+ /* Release the MFS from:
+ * - the CL ("fast path") i.e. data_send_link,
+ * - the overridden SAR layer which contains a pointer to it,
+ * - the mac store which has initialised it.
+ */
+ t.cl->data_send_link.mfs = NULL;
+ t.sar.nb = 0;
+ t.sar.mfs[0] = NULL;
+ mac_store_mfs_remove (t.mac_store, mfs);
+ blk_release (mfs);
+ }
+ }
+ test_end;
+
+ cl_test_uninit (&t);
+}
+
+void
+cl_test_suite_send (test_t test)
+{
+ test_suite_begin (test, "CL send");
+ cl_test_case__cl_data_send_prepare (test);
+ cl_test_case__cl_data_send_mcast (test);
+}
diff --git a/cesar/cl/test/utest_eoc/src/test.c b/cesar/cl/test/utest_eoc/src/test.c
new file mode 100644
index 0000000000..57eb6ad58c
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/src/test.c
@@ -0,0 +1,88 @@
+/* Cesar project {{{
+ *
+ * Copyright (C) 2010 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/test/utest_eoc/src/test.c
+ * \brief CL environment test.
+ * \ingroup cl
+ */
+#include "common/std.h"
+#include "lib/bitstream.h"
+#include "cl/test/utest_eoc/test.h"
+#include "mac/common/ntb.h"
+#include "cl/inc/context.h"
+#include <string.h>
+
+void
+ipmbox_tx_data (ipmbox_t *ctx, u32 *first_msg, uint length)
+{
+ dbg_assert (ctx);
+ cl_test_recv_t *test_ctx = (cl_test_recv_t*) ctx;
+ test_ctx->buffer = (u8 *) first_msg[1];
+ test_ctx->length = ipmbox_msg_get_data_length (first_msg[0]);
+}
+
+static int
+cl_trace_buffer_dbg_dump_callback (void *user, const char *text,
+ uint text_size)
+{
+ return 0;
+}
+
+void
+cl_test_init (cl_test_t *ctx, u32 seed)
+{
+ dbg_assert (ctx);
+ ctx->mac_store = mac_store_init ();
+ mac_config_init (&ctx->mac_config);
+ mac_ntb_init (&ctx->mac_config);
+ ctx->mac_config.authenticated = true;
+ ctx->mac_config.tei = MAC_TEI_CCO_DEF;
+ ctx->mac_config.sta_mac_address = 0xfeffffd71300ull;
+ ctx->cl = cl_init (ctx->mac_store, (sar_t*) &ctx->sar, &ctx->mac_config,
+ (ipmbox_t *) &ctx->pwl_recv, (bufmgr_t*) &ctx->bufmgr);
+ lib_rnd_init (&ctx->rnd, seed);
+}
+
+void
+cl_test_uninit (cl_test_t *ctx)
+{
+ dbg_assert (ctx);
+ trace_bundle_dump_all ("dbg", cl_trace_buffer_dbg_dump_callback, NULL);
+ cl_uninit (ctx->cl);
+ mac_store_uninit (ctx->mac_store);
+}
+
+void
+cl_test_prepare_mactotei (cl_test_t *ctx, mac_t *dmacs, uint nb)
+{
+ uint i;
+ dbg_assert (ctx);
+ for (i = 0; i < nb; i++)
+ {
+ dbg_assert (!mac_is_multicast (dmacs[i]));
+ cl_eoc_mactotei_entry_insert (ctx->cl, dmacs[i], i + 100);
+ }
+}
+
+void
+cl_test_prepare_buffer (cl_test_t *ctx, u8 *buffer, u16 length, mac_t dmac,
+ uint tag)
+{
+ u8 data;
+ u16 i;
+ bitstream_t stream;
+ dbg_assert (ctx);
+ data = lib_rnd32 (&ctx->rnd) & 0xff;
+ bitstream_write_init (&stream, buffer, length);
+ bitstream_write_large (&stream, dmac, 48);
+ bitstream_write_large (&stream, ctx->mac_config.sta_mac_address, 48);
+ bitstream_write (&stream, tag, 16);
+ for (i = 0; i < length - 14; i++)
+ bitstream_write (&stream, data, 8);
+ bitstream_finalise (&stream);
+}
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;
+}
diff --git a/cesar/cl/test/utest_eoc/test.h b/cesar/cl/test/utest_eoc/test.h
new file mode 100644
index 0000000000..6d4b94b78d
--- /dev/null
+++ b/cesar/cl/test/utest_eoc/test.h
@@ -0,0 +1,124 @@
+#ifndef cl_test_test_h
+#define cl_test_test_h
+/* Cesar project {{{
+ *
+ * Copyright (C) 2012 Spidcom
+ *
+ * <<<Licence>>>
+ *
+ * }}} */
+/**
+ * \file cl/test/utest_eoc/test.h
+ * \brief CL environment test.
+ * \ingroup cl
+ */
+#include "cl/cl.h"
+#include "lib/rnd.h"
+
+#include "common/ipmbox/msg.h"
+#include "cl/mbx/mbx.h"
+
+#define TEST_BUFFER_MAX_NB 4
+
+struct sar_test_t
+{
+ /** buffer received. */
+ u8 *buffer[TEST_BUFFER_MAX_NB];
+ /** MFS used for TX. */
+ mfs_tx_t *mfs[TEST_BUFFER_MAX_NB];
+ /** Data length. */
+ uint length[TEST_BUFFER_MAX_NB];
+ /** User data. */
+ void *ud[MCAST_MEMBER_MAX_NB];
+ /** Number of calls. */
+ uint nb;
+};
+typedef struct sar_test_t sar_test_t;
+
+struct cl_test_recv_t
+{
+ /** Source TEI. */
+ uint stei;
+ /** Buffer. */
+ u8 *buffer;
+ /** length */
+ uint length;
+ /** NEK Encrypted ?*/
+ bool nek_enc;
+};
+typedef struct cl_test_recv_t cl_test_recv_t;
+
+struct hle_tools_test_t
+{
+ ipmbox_msg_mbx_t *msg;
+};
+typedef struct hle_tools_test_t hle_tools_test_t;
+
+struct cl_test_t
+{
+ /** CL context. */
+ cl_t *cl;
+ /** Mac config context. */
+ mac_config_t mac_config;
+ /** Mac store context. */
+ mac_store_t *mac_store;
+ /** Random context. */
+ lib_rnd_t rnd;
+ /** SAR test context. */
+ sar_test_t sar;
+ /** PWL receive MME or DATA. */
+ cl_test_recv_t pwl_recv;
+ /** Ipmbox context. */
+ void *ipmbox;
+ /** Buffer manager context. */
+ void *bufmgr;
+ /** Hle tools stubbed context. */
+ hle_tools_test_t *hle_tools;
+ /** Mbox context. */
+ cl_mbx_t *mbx;
+};
+typedef struct cl_test_t cl_test_t;
+
+BEGIN_DECLS
+
+/**
+ * Initialise test context.
+ * \param ctx the test context.
+ * \param seed the seed to initialise the random generator.
+ */
+void
+cl_test_init (cl_test_t *ctx, u32 seed);
+
+/**
+ * Uninitialise the CL context.
+ * \param ctx the test context.
+ */
+void
+cl_test_uninit (cl_test_t *ctx);
+
+/**
+ * Prepare the mac to tei table of the CL.
+ * \param ctx the CL context.
+ * \param dmacs destination mac tables.
+ * \param nb the number of entries.
+ *
+ * First entry corresponds to TEI 1 and so on.
+ */
+void
+cl_test_prepare_mactotei (cl_test_t *ctx, mac_t *dmacs, uint nb);
+
+/**
+ * Prepare a buffer to be sent by the Cl.
+ * \param ctx the test context.
+ * \param buffer the buffer to use.
+ * \param length the MF length.
+ * \param dmac the destination mac address.
+ * \param tag the linux priority tag for the classifier.
+ */
+void
+cl_test_prepare_buffer (cl_test_t *ctx, u8 *buffer, u16 length, mac_t dmac,
+ uint tag);
+
+END_DECLS
+
+#endif /* cl_test_test_h */