From 576b14caaa885df39fbdc3b813220135e60bd8d6 Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Thu, 25 Aug 2011 15:26:42 +0200 Subject: cesar/cp/test/mme: add missing dependency --- cesar/cp/test/mme/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/cp/test/mme/Makefile b/cesar/cp/test/mme/Makefile index 8876e7cfd3..798dd377e6 100644 --- a/cesar/cp/test/mme/Makefile +++ b/cesar/cp/test/mme/Makefile @@ -9,6 +9,6 @@ test_mme_SOURCES = test_mme.c test_mme_MODULES = lib test_mme_target_SOURCES = test_mme.c -test_mme_target_MODULES = lib +test_mme_target_MODULES = lib hal/arch include $(BASE)/common/make/top.mk -- cgit v1.2.3 From 8337a24bc9357350dbdf8e6b590bf20eec0195dd Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Thu, 25 Aug 2011 15:31:59 +0200 Subject: cesar/lib/test/mbox: replace blk_print_memory by a test_fail call --- cesar/lib/test/mbox/src/mbox.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/lib/test/mbox/src/mbox.c b/cesar/lib/test/mbox/src/mbox.c index eea3155bd5..84fb090f1b 100644 --- a/cesar/lib/test/mbox/src/mbox.c +++ b/cesar/lib/test/mbox/src/mbox.c @@ -87,11 +87,11 @@ thread2_entry_function(cyg_addrword_t data) mbox_nb = mbox_peek (&mbox); mbox_uninit (&mbox); - blk_print_memory (); test_init (test, 0, NULL); test_begin (test, "Mailbox") { + test_fail_if (blk_check_memory() == false, "Memory not freed"); test_fail_unless (nb_msg == 10); test_fail_unless (mbox_nb == 0); } -- cgit v1.2.3 From 99102ef0d1a4a5c0342db2989a7866f29756b37b Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Thu, 25 Aug 2011 15:43:13 +0200 Subject: cesar/cp/{sta/mgr, cco/action}: fix unit test since librnd change --- cesar/cp/cco/action/test/src/action_gen_nek.c | 22 ++++++++++------------ cesar/cp/sta/mgr/test/src/sta_mgr.c | 9 +++++---- 2 files changed, 15 insertions(+), 16 deletions(-) (limited to 'cesar') diff --git a/cesar/cp/cco/action/test/src/action_gen_nek.c b/cesar/cp/cco/action/test/src/action_gen_nek.c index 513d4f50a6..ea2f334c10 100644 --- a/cesar/cp/cco/action/test/src/action_gen_nek.c +++ b/cesar/cp/cco/action/test/src/action_gen_nek.c @@ -48,23 +48,21 @@ test_case_gen_nek (test_t test) /* Initialise the seed of the random generator. */ cp_cco_action_init (&cp); - lib_rnd_init (&cp.rnd, 0x12345678); test_begin (test, "Verify first shot") { uint i; - uint computed_keys [4] = {0xf48aa84f, 0xb3b084cb, 0xdf36c134, - 0xaa4010d2}; + cp_key_t computed_keys; + lib_rnd_init (&cp.rnd, 0x12345678); + cp_secu_generate_key(&cp, lib_rnd32 (&cp.rnd), + 5, &computed_keys); + lib_rnd_init (&cp.rnd, 0x12345678); cp_cco_action_cco__cco_nek_change (&cp); - - for (i = 0; i < 4; i++) - printf ("Keys : %x, computed : %x\n", cp.cco_action.nek_new.key[i], - computed_keys[i]); - - test_fail_unless (cp.cco_action.nek_new.key[0] == computed_keys[0]); - test_fail_unless (cp.cco_action.nek_new.key[1] == computed_keys[1]); - test_fail_unless (cp.cco_action.nek_new.key[2] == computed_keys[2]); - test_fail_unless (cp.cco_action.nek_new.key[3] == computed_keys[3]); + for (i = 0; i < COUNT (cp.cco_action.nek_new.key); i++) + { + test_fail_unless (cp.cco_action.nek_new.key[i] + == computed_keys.key[i]); + } } test_end; } diff --git a/cesar/cp/sta/mgr/test/src/sta_mgr.c b/cesar/cp/sta/mgr/test/src/sta_mgr.c index 2269be2a5d..3f49c6246c 100644 --- a/cesar/cp/sta/mgr/test/src/sta_mgr.c +++ b/cesar/cp/sta/mgr/test/src/sta_mgr.c @@ -1305,15 +1305,16 @@ test_case__cp_sta_mgr_partial_ack (test_t test) test_begin (test, "Two STA") { uint i; + bool teis[3] = {false, false, false}; cp_sta_t *sta = cp_sta_mgr_sta_add (&cp, net, 2, 2); - cp_tei_t tei_cmp[] = { 1, 1, 1, 2, 1, 2, 2, 1, 1, 2, 1, 1, 2, 1, 2, 1, - 1, 1, 2, 2 }; for (i = 0; i < 20; i++) { cp_sta_mgr_elects_sta_partial_ack (&cp); - test_fail_unless (cp.mac_config->partial_ack_tei_default == - tei_cmp[i]); + teis[cp.mac_config->partial_ack_tei_default] = true; } + test_fail_unless (teis[0] == false); + for (i = 1; i < COUNT (teis); i++) + test_fail_unless (teis[i] == true); slab_release (sta); } test_end; -- cgit v1.2.3 From 00dc31bae0ac19f1ceee62339e6d4f67e6ada353 Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Thu, 25 Aug 2011 17:08:45 +0200 Subject: cesar/cp/msg: fix cm_set_key unit tests --- cesar/cp/msg/test/src/msg_cm.c | 319 ++++++++++++++++------------------------- 1 file changed, 120 insertions(+), 199 deletions(-) (limited to 'cesar') diff --git a/cesar/cp/msg/test/src/msg_cm.c b/cesar/cp/msg/test/src/msg_cm.c index bb11a95775..0ab2470110 100644 --- a/cesar/cp/msg/test/src/msg_cm.c +++ b/cesar/cp/msg/test/src/msg_cm.c @@ -62,6 +62,95 @@ mac_t own_mac_addr = 0x123456789ABCull; mme_header_t expected; +void +test_case_cm_set_key_req_check (test_t t, + cp_msg_cm_set_key_req_t key_req_input, + cp_msg_cm_set_key_req_t key_req_output, + cp_secu_protocol_run_t prun_input, + cp_secu_protocol_run_t prun_output) +{ + test_within (t); + test_fail_unless (key_req_input.key_type == key_req_output.key_type); + test_fail_unless (key_req_input.cco_cap == key_req_output.cco_cap); + test_fail_unless (key_req_input.nid == key_req_output.nid); + test_fail_unless (prun_input.pid == prun_output.pid); + test_fail_unless (prun_input.prn == prun_output.prn); + test_fail_unless (prun_input.pmn == prun_output.pmn); + test_fail_unless (prun_input.your_nonce == prun_output.my_nonce); +} + +void +test_case_cm_set_key_req_run (test_t t, + cp_t *ctx, cp_mme_peer_t peer, + cp_mme_peks_t peks, + cp_msg_cm_set_key_req_t key_req_input, + cp_secu_protocol_run_t prun_input, + bool read_result, bool enc_result) +{ + bool ok; + cp_msg_cm_set_key_req_t key_req_output; + cp_mme_rx_t *msg; + uint fmi; + test_within (t); + cp_msg_cm_set_key_req_send (ctx, &peer, peks, &prun_input, + &key_req_input); + memset (&key_req_output, 0, sizeof (cp_msg_cm_set_key_req_t)); + msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, + false); + if (peks != CP_MME_PEKS_NONE) + { + ok = cp_msg_mme_read_header_enc (&cp, msg); + test_fail_unless (ok == enc_result); + } + ok = cp_msg_cm_set_key_req_receive (&cp, msg, &key_req_output); + test_fail_unless (ok == read_result); + test_case_cm_set_key_req_check ( + t, key_req_input, key_req_output, prun_input, msg->prun); + slab_release (msg); +} + +void +test_case_cm_set_key_cnf_check (test_t t, + cp_msg_cm_set_key_cnf_t key_cnf_input, + cp_msg_cm_set_key_cnf_t key_cnf_output, + cp_secu_protocol_run_t prun_input, + cp_secu_protocol_run_t prun_output) +{ + test_within (t); + test_fail_unless (key_cnf_input.result == key_cnf_output.result); + test_fail_unless (key_cnf_input.cco_cap == key_cnf_output.cco_cap); + test_fail_unless (prun_input.pid == prun_output.pid); + test_fail_unless (prun_input.prn == prun_output.prn); + test_fail_unless (prun_input.pmn == prun_output.pmn); + test_fail_unless (prun_input.your_nonce == prun_output.my_nonce); +} + +void +test_case_cm_set_key_cnf_run (test_t t, + cp_t *ctx, cp_mme_peer_t peer, + cp_mme_peks_t peks, + cp_msg_cm_set_key_cnf_t key_cnf_input, + cp_secu_protocol_run_t prun_input) +{ + bool ok; + cp_msg_cm_set_key_cnf_t key_cnf_output; + cp_mme_rx_t *msg; + uint fmi; + test_within (t); + cp_msg_cm_set_key_cnf_send (ctx, &peer, peks, &prun_input, + &key_cnf_input); + memset (&key_cnf_output, 0, sizeof (cp_msg_cm_set_key_cnf_t)); + msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, + false); + ok = cp_msg_mme_read_header_enc (&cp, msg); + test_fail_unless (ok == true); + ok = cp_msg_cm_set_key_cnf_receive (&cp, msg, &key_cnf_output); + test_fail_unless (ok == true); + test_case_cm_set_key_cnf_check ( + t, key_cnf_input, key_cnf_output, prun_input, msg->prun); + slab_release (msg); +} + void test_case_cm_set_key (test_t test) { @@ -70,8 +159,6 @@ test_case_cm_set_key (test_t test) cp_secu_protocol_run_t prun; cp_msg_cm_set_key_req_t key_req; cp_msg_cm_set_key_cnf_t key_cnf; - cp_mme_rx_t *msg; - uint fmi; cp_sta_own_data_t *own_data; cl_t cl; sar_t sar; @@ -113,140 +200,49 @@ test_case_cm_set_key (test_t test) test_begin (test, "Without encryption") { - cp_msg_cm_set_key_req_send (&cp, &peer, CP_MME_PEKS_NONE, &prun, - &key_req); - bool ok; - memset (&key_req, 0, sizeof (cp_msg_cm_set_key_req_t)); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, - false); - ok = cp_msg_cm_set_key_req_receive (&cp, msg, &key_req); - test_fail_unless (ok == true); - test_fail_unless (key_req.key_type == CP_MSG_KEY_TEK, "Wrong key type"); - test_fail_unless (key_req.cco_cap == CP_CCO_LEVEL, "Wrong CCo level"); - test_fail_unless (key_req.nid == nid, "Wrong NID"); - test_fail_unless (msg->prun.pid == prun.pid, "Wrong PID"); - test_fail_unless (msg->prun.prn == prun.prn, "Wrong PRN"); - test_fail_unless (msg->prun.pmn == prun.pmn, "Wrong PMN"); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce , "Wrong nonce"); - - slab_release (msg); + test_case_cm_set_key_req_run (test, &cp, peer, CP_MME_PEKS_NONE, + key_req, prun, true, true); } test_end; - - cp_msg_cm_set_key_req_send (&cp, &peer, CP_MME_PEKS_TEK_MIN + 1, &prun, &key_req); - // Read the MME. own_data = cp_sta_mgr_get_sta_own_data (&cp); cp_sta_own_data_set_mac_address (&cp, peer.mac); - test_begin (test, "Verify") { - bool ok; - memset (&key_req, 0, sizeof (cp_msg_cm_set_key_req_t)); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, - false); - ok = cp_msg_mme_read_header_enc (&cp, msg); - test_fail_unless (ok == true); - - ok = cp_msg_cm_set_key_req_receive (&cp, msg, &key_req); - - test_fail_unless (ok == true); - test_fail_unless (key_req.key_type == CP_MSG_KEY_TEK, "Wrong key type"); - test_fail_unless (key_req.cco_cap == CP_CCO_LEVEL, "Wrong CCo level"); - test_fail_unless (key_req.nid == nid, "Wrong NID"); - test_fail_unless (msg->prun.pid == prun.pid, "Wrong PID"); - test_fail_unless (msg->prun.prn == prun.prn, "Wrong PRN"); - test_fail_unless (msg->prun.pmn == prun.pmn, "Wrong PMN"); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce , "Wrong nonce"); - - slab_release (msg); + test_case_cm_set_key_req_run (test, &cp, peer, + CP_MME_PEKS_TEK_MIN + 1, key_req, prun, + true, true); } test_end; test_begin (test, "Wrong key type") { - bool ok; - - bitstream_direct_write (buffer, 68* 8, CP_MSG_KEY_NB, 8); - memset (&key_req, 0, sizeof (cp_msg_cm_set_key_req_t)); - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, - false); - bitstream_skip (&msg->bitstream, 49*8); - msg->length = 57; - - ok = cp_msg_cm_set_key_req_receive (&cp, msg, &key_req); - - test_fail_unless (ok == false); - test_fail_unless (key_req.key_type == CP_MSG_KEY_NB, "Wrong key type"); - test_fail_unless (key_req.cco_cap == CP_CCO_LEVEL, "Wrong CCo level"); - test_fail_unless (key_req.nid == nid, "Wrong NID"); - test_fail_unless (msg->prun.pid == prun.pid, "Wrong PID"); - test_fail_unless (msg->prun.prn == prun.prn, "Wrong PRN"); - test_fail_unless (msg->prun.pmn == prun.pmn, "Wrong PMN"); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce , "Wrong nonce"); - - bitstream_direct_write (buffer, 68 * 8, CP_MSG_KEY_TEK, 8); - - slab_release (msg); + key_req.key_type = CP_MSG_KEY_NB; + test_case_cm_set_key_req_run (test, &cp, peer, + CP_MME_PEKS_TEK_MIN + 1, key_req, prun, + false, true); + key_req.key_type = CP_MSG_KEY_TEK; } test_end; test_begin (test, "Wrong CCO cap") { - bool ok; - - bitstream_direct_write (buffer, 81* 8, CP_CCO_LEVEL_MAX + 1, 8); - memset (&key_req, 0, sizeof (cp_msg_cm_set_key_req_t)); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, - false); - bitstream_skip (&msg->bitstream, 49*8); - msg->length = 57; - - ok = cp_msg_cm_set_key_req_receive (&cp, msg, &key_req); - - test_fail_unless (ok == false); - test_fail_unless (key_req.key_type == CP_MSG_KEY_TEK, "Wrong key type"); - test_fail_unless (key_req.cco_cap == CP_CCO_LEVEL_MAX + 1, "Wrong CCo level"); - test_fail_unless (key_req.nid == nid, "Wrong NID"); - test_fail_unless (msg->prun.pid == prun.pid, "Wrong PID"); - test_fail_unless (msg->prun.prn == prun.prn, "Wrong PRN"); - test_fail_unless (msg->prun.pmn == prun.pmn, "Wrong PMN"); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce , "Wrong nonce"); - - bitstream_direct_write (buffer, 81 * 8, CP_CCO_LEVEL, 8); - - slab_release (msg); + key_req.cco_cap = CP_CCO_LEVEL_MAX + 1; + test_case_cm_set_key_req_run (test, &cp, peer, + CP_MME_PEKS_TEK_MIN + 1, key_req, prun, + false, true); + key_req.cco_cap = CP_CCO_LEVEL; } test_end; test_begin (test, "Wrong nid") { - bool ok; - - bitstream_direct_write_large (buffer, 82* 8, nid << 2, 56); - memset (&key_req, 0, sizeof (cp_msg_cm_set_key_req_t)); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, - false); - bitstream_skip (&msg->bitstream, 49*8); - - ok = cp_msg_cm_set_key_req_receive (&cp, msg, &key_req); - - test_fail_unless (ok == false); - test_fail_unless (key_req.key_type == CP_MSG_KEY_TEK, "Wrong key type"); - test_fail_unless (key_req.cco_cap == CP_CCO_LEVEL, "Wrong CCo level"); - test_fail_unless (key_req.nid == nid << 2, "Wrong NID"); - test_fail_unless (msg->prun.pid == prun.pid, "Wrong PID"); - test_fail_unless (msg->prun.prn == prun.prn, "Wrong PRN"); - test_fail_unless (msg->prun.pmn == prun.pmn, "Wrong PMN"); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce , "Wrong nonce"); - - bitstream_direct_write_large (buffer, 82* 8, nid, 56); - - slab_release (msg); + cp_nid_t nid = key_req.nid; + key_req.nid = 0xffffffffffffffll; + test_case_cm_set_key_req_run (test, &cp, peer, + CP_MME_PEKS_TEK_MIN + 1, key_req, prun, + false, true); + key_req.nid = nid; } test_end; @@ -276,98 +272,26 @@ test_case_cm_set_key (test_t test) test_begin (test, "Verify Encrypted payload.") { - bool ok; - memset (&key_cnf, 0, sizeof (cp_msg_cm_set_key_cnf_t)); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, buffer_len, 0xa, &fmi, - false); - ok = cp_msg_mme_read_header_enc (&cp, msg); - test_fail_unless (ok == true); - ok = cp_msg_cm_set_key_cnf_receive (&cp, msg, &key_cnf); - - test_fail_unless (ok == true); - test_fail_unless (key_cnf.result == CP_MSG_CM_SET_KEY_CNF_RESULT_SUCCESS); - test_fail_unless (key_cnf.cco_cap == CP_CCO_LEVEL); - test_fail_unless (msg->prun.pid == prun.pid); - test_fail_unless (msg->prun.prn == prun.prn); - test_fail_unless (msg->prun.pmn == prun.pmn); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce); - - slab_release (msg); - } - test_end; - - - cp_msg_cm_set_key_cnf_send (&cp, &peer, CP_MME_PEKS_NONE, &prun, &key_cnf); - - // Read the MME. - cp_sta_own_data_set_mac_address (&cp, peer.mac); - - test_begin (test, "Verify") - { - bool ok; - memset (&key_cnf, 0, sizeof (cp_msg_cm_set_key_cnf_t)); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, 60, 0xa, &fmi, false); - ok = cp_msg_cm_set_key_cnf_receive (&cp, msg, &key_cnf); - - test_fail_unless (ok == true); - test_fail_unless (key_cnf.result == CP_MSG_CM_SET_KEY_CNF_RESULT_SUCCESS); - test_fail_unless (key_cnf.cco_cap == CP_CCO_LEVEL); - test_fail_unless (msg->prun.pid == prun.pid); - test_fail_unless (msg->prun.prn == prun.prn); - test_fail_unless (msg->prun.pmn == prun.pmn); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce); - - slab_release (msg); + test_case_cm_set_key_cnf_run (test, &cp, peer, + CP_MME_PEKS_TEK_MIN + 1, key_cnf, prun); } test_end; test_begin (test, "Wrong Result") { - bool ok; - memset (&key_cnf, 0, sizeof (cp_msg_cm_set_key_cnf_t)); - - bitstream_direct_write (buffer, 19*8, CP_MSG_CM_SET_KEY_CNF_RESULT_NB, - 8); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, 60, 0xa, &fmi, false); - ok = cp_msg_cm_set_key_cnf_receive (&cp, msg, &key_cnf); - - test_fail_unless (ok == false); - test_fail_unless (key_cnf.result == CP_MSG_CM_SET_KEY_CNF_RESULT_NB); - test_fail_unless (key_cnf.cco_cap == CP_CCO_LEVEL); - test_fail_unless (msg->prun.pid == prun.pid); - test_fail_unless (msg->prun.prn == prun.prn); - test_fail_unless (msg->prun.pmn == prun.pmn); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce); - - bitstream_direct_write (buffer, 19*8, - CP_MSG_CM_SET_KEY_CNF_RESULT_SUCCESS, - 8); - slab_release (msg); + key_cnf.result = false; + test_case_cm_set_key_cnf_run (test, &cp, peer, + CP_MME_PEKS_TEK_MIN + 1, key_cnf, prun); + key_cnf.result = true; } test_end; test_begin (test, "Wrong CCo Level") { - bool ok; - memset (&key_cnf, 0, sizeof (cp_msg_cm_set_key_cnf_t)); - - bitstream_direct_write (buffer, 32*8, CP_CCO_LEVEL_MAX + 1, 8); - - msg = cp_msg_mme_read_header (&cp, (u8*)buffer, 60, 0xa, &fmi, false); - ok = cp_msg_cm_set_key_cnf_receive (&cp, msg, &key_cnf); - - test_fail_unless (ok == false); - test_fail_unless (key_cnf.result == - CP_MSG_CM_SET_KEY_CNF_RESULT_SUCCESS); - test_fail_unless (key_cnf.cco_cap == CP_CCO_LEVEL_MAX + 1); - test_fail_unless (msg->prun.pid == prun.pid); - test_fail_unless (msg->prun.prn == prun.prn); - test_fail_unless (msg->prun.pmn == prun.pmn); - test_fail_unless (msg->prun.your_nonce == prun.my_nonce); - slab_release (msg); + key_cnf.cco_cap = CP_CCO_LEVEL_MAX; + test_case_cm_set_key_cnf_run (test, &cp, peer, + CP_MME_PEKS_TEK_MIN + 1, key_cnf, prun); + key_cnf.cco_cap = CP_CCO_LEVEL; } test_end; @@ -408,9 +332,6 @@ test_case_cm_get_key (test_t test) data.nid = nid; cp_msg_cm_get_key_req_send (&cp, &peer, CP_MME_PEKS_TEK_MIN + 1, &prun, &data); - - // Read the MME. - own_data = cp_sta_mgr_get_sta_own_data (&cp); cp_sta_own_data_set_mac_address (&cp, peer.mac); test_begin (test, "Verify") -- cgit v1.2.3 From 378a17198f56b57a81e3f9c13dd78f2d28a427ad Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Thu, 25 Aug 2011 17:11:46 +0200 Subject: cesar/cp/secu: add missing dependency --- cesar/cp/secu/test/sparc-Makefile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cesar') diff --git a/cesar/cp/secu/test/sparc-Makefile b/cesar/cp/secu/test/sparc-Makefile index e53439ca02..b9c0e85845 100644 --- a/cesar/cp/secu/test/sparc-Makefile +++ b/cesar/cp/secu/test/sparc-Makefile @@ -8,13 +8,13 @@ INCLUDES = cp/secu/test/override TARGET_PROGRAMS = test-sha2 test-aes test-nmk test-sha2_SOURCES = test-sha2.c -test-sha2_MODULES = lib cp/secu cp/sta/core/stub +test-sha2_MODULES = lib cp/secu cp/sta/core/stub hal/arch test-aes_SOURCES = test-aes.c -test-aes_MODULES = lib cp/secu cp/sta/core/stub +test-aes_MODULES = lib cp/secu cp/sta/core/stub hal/arch test-nmk_SOURCES = test-nmk.c -test-nmk_MODULES = lib cp/secu cp/sta/core/stub +test-nmk_MODULES = lib cp/secu cp/sta/core/stub hal/arch VARIANT = sparc include $(BASE)/common/make/top.mk -- cgit v1.2.3 From 1954a93e129b58a5f979bb5d7405cbdb5b47e8c7 Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Fri, 26 Aug 2011 10:34:20 +0200 Subject: cesar/maximus: set class object is built-in python now, closes #1739 --- cesar/maximus/python/maximus/ethernet/scapy.py | 1 - 1 file changed, 1 deletion(-) (limited to 'cesar') diff --git a/cesar/maximus/python/maximus/ethernet/scapy.py b/cesar/maximus/python/maximus/ethernet/scapy.py index a7074d4f5c..df9bde3943 100644 --- a/cesar/maximus/python/maximus/ethernet/scapy.py +++ b/cesar/maximus/python/maximus/ethernet/scapy.py @@ -99,7 +99,6 @@ if __name__ == "__main__": import socket, sys, getopt, string, struct, random, code import cPickle, copy, types, gzip, base64, re, zlib, array -from sets import Set from select import select from glob import glob from fcntl import ioctl -- cgit v1.2.3 From baf3944da627c309f40ca2dc69e4cf1a84f73827 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 25 Aug 2011 17:29:19 +0200 Subject: cesar/hal/phy/maximus/test: fix PB test PB was allocated on the stack, then overwritten. --- cesar/hal/phy/maximus/test/src/test_phy_ctrl.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cesar') diff --git a/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c b/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c index 626ad6f86f..96b1382faf 100644 --- a/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c +++ b/cesar/hal/phy/maximus/test/src/test_phy_ctrl.c @@ -2090,10 +2090,10 @@ void phy_tx_frame_test_case(test_t t) } test_end; // test the fourth callback + phy_pb_t pb[PHY_PB_MAX_NB]; + u8 pb_data[PHY_PB_MAX_NB][MAC_PB520_BYTES]; test_begin(t, "maximus phy tx mpdu cb") { - phy_pb_t pb[PHY_PB_MAX_NB]; - u8 pb_data[PHY_PB_MAX_NB][MAC_PB520_BYTES]; int i = 0; char c = 'a'; -- cgit v1.2.3 From 405c984e03de3715fc7fa83f2bf3b88372fe2cc9 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 25 Aug 2011 18:01:29 +0200 Subject: cesar/common/tests/tests: fix mbox host test name --- cesar/common/tests/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/common/tests/tests b/cesar/common/tests/tests index 26b9ec8c53..3a138ddf5a 100644 --- a/cesar/common/tests/tests +++ b/cesar/common/tests/tests @@ -80,7 +80,7 @@ cov test_mac_lookup_table: ./obj/test_mac_lookup_table lib/test/mbox: make: make COV=y -cov test_mbox_host: ./obj/host +cov test_mbox_host: ./obj/mbox_host cov test_mbox_ecos: ./obj/mbox.elf lib/test/perf: -- cgit v1.2.3 From 89bf83a66cee4f69ae71016700faf8d0d84fd798 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 26 Aug 2011 11:07:02 +0200 Subject: cesar/maximus/python/test: fix bad bits/symbol test --- cesar/maximus/python/test/test_lib_cesar.py | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'cesar') diff --git a/cesar/maximus/python/test/test_lib_cesar.py b/cesar/maximus/python/test/test_lib_cesar.py index bdcb694c23..d3340925d7 100644 --- a/cesar/maximus/python/test/test_lib_cesar.py +++ b/cesar/maximus/python/test/test_lib_cesar.py @@ -98,10 +98,7 @@ class TestMaximusDurFunctions(unittest.TestCase): # Maximum modulations tonemap = '' for i in range (0, PHY_CARRIER_NB / 2): - if PHY_CARRIER_NB % 2 == 0: - tonemap += pack('B', 0x07) - else: - tonemap += pack('B', 0x77) + tonemap += pack('B', 0x77) bits_ref = 917 * 10 bits = maximus_dur_bits_per_symbol(self.maximus, self.station.get(), 3, # PHY_MOD_TM self.station.get_tonemask(), tonemap, 917) -- cgit v1.2.3 From 06d2b5ca2ead0a91dbedfa363232814e4ae927bc Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 26 Aug 2011 11:33:03 +0200 Subject: cesar/maximus/prototest: malloc is in stdlib.h --- cesar/maximus/prototest/fcall/src/test_fcall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/maximus/prototest/fcall/src/test_fcall.c b/cesar/maximus/prototest/fcall/src/test_fcall.c index a09b7b66a7..58815ff939 100644 --- a/cesar/maximus/prototest/fcall/src/test_fcall.c +++ b/cesar/maximus/prototest/fcall/src/test_fcall.c @@ -14,7 +14,7 @@ */ #include #include -#include +#include #include #include "common/std.h" #include "interface/fcall/interface_fcall.h" -- cgit v1.2.3 From 483f7fd9d5206f03139ed4e8825490e003302985 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 26 Aug 2011 14:45:21 +0200 Subject: cesar/maximus/prototest/fcall: fix read from fd --- cesar/maximus/prototest/fcall/src/test_fcall.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) (limited to 'cesar') diff --git a/cesar/maximus/prototest/fcall/src/test_fcall.c b/cesar/maximus/prototest/fcall/src/test_fcall.c index 58815ff939..878170d44d 100644 --- a/cesar/maximus/prototest/fcall/src/test_fcall.c +++ b/cesar/maximus/prototest/fcall/src/test_fcall.c @@ -22,6 +22,7 @@ #include "lib/swap.h" // for 'swap16()' and 'swap32()' #include "lib/read_word.h" // for 'read_u16_from_word()' #include "maximus/prototest/fcall/inc/syscall.h" +#include "common/defs/ethernet.h" #define MY_THREAD_STACK_SIZE (8192 / sizeof(int)) @@ -47,10 +48,14 @@ void my_thread(cyg_addrword_t index) memset(my_mme, '\0', SCI_MSG_MAX_SIZE); while (INTERFACE_FCALL_PAYLOAD_OFFSET != len) { - len = read(proto_in_fd, my_mme, INTERFACE_FCALL_PAYLOAD_OFFSET); + int r = read (proto_in_fd, my_mme + len, + INTERFACE_FCALL_PAYLOAD_OFFSET - len); + dbg_assert (r != -1 || errno == EINTR); + if (r > 0) + len += r; } - dbg_assert(INTERFACE_FCALL_PAYLOAD_OFFSET == len); data_length = swap16(read_u16_from_word(my_mme + INTERFACE_FCALL_PAYLOAD_OFFSET - sizeof(u16))); + data_length = MAX (ETH_PACKET_MIN_SIZE - len, data_length); if ((len = read(proto_in_fd, my_mme + INTERFACE_FCALL_PAYLOAD_OFFSET, data_length)) < 0) { diag_printf("errno = %d: error when reading proto in file (data_length = %d)\n", errno, data_length); -- cgit v1.2.3 From c80250683ea116883003953fc33908fa1502cee4 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 26 Aug 2011 16:14:30 +0200 Subject: cesar/maximus/stationtest: fix short PPDU reception --- cesar/maximus/stationtest/src/test_send.c | 7 +++++-- cesar/maximus/stationtest/src/test_tx_rx.c | 7 +++++-- 2 files changed, 10 insertions(+), 4 deletions(-) (limited to 'cesar') diff --git a/cesar/maximus/stationtest/src/test_send.c b/cesar/maximus/stationtest/src/test_send.c index 70a03398ee..bcb264b163 100644 --- a/cesar/maximus/stationtest/src/test_send.c +++ b/cesar/maximus/stationtest/src/test_send.c @@ -40,8 +40,11 @@ bool phy_rx_fc_cb (void *user, u32 rx_date, const u32 *fc_av) diag_write_string("=> phy_rx_fc_cb\n"); // When the FC is received, prepare RX - phy_rx_prepare(ctx, 1, PHY_COMBO_PARAMS (mod, fecrate, pb_size), - (phy_gil_t)gil, 0, 1); + if (short_ppdu) + phy_rx_prepare_short (ctx); + else + phy_rx_prepare(ctx, 1, PHY_COMBO_PARAMS (mod, fecrate, pb_size), + (phy_gil_t)gil, 0, 1); return true; } diff --git a/cesar/maximus/stationtest/src/test_tx_rx.c b/cesar/maximus/stationtest/src/test_tx_rx.c index 9abcf09218..dcbcc23e71 100644 --- a/cesar/maximus/stationtest/src/test_tx_rx.c +++ b/cesar/maximus/stationtest/src/test_tx_rx.c @@ -132,8 +132,11 @@ bool phy_rx_fc_cb (void *user, u32 rx_date, const u32 *fc_av) maximus_pending_isrs &= (0 << PHY_HAL_INTERRUPT_PHY); // When the FC is received, prepare RX - phy_rx_prepare(ctx, 1, PHY_COMBO_PARAMS (mod, fecrate, pb_size), - (phy_gil_t)gil, 0, 1); + if (short_ppdu) + phy_rx_prepare_short (ctx); + else + phy_rx_prepare(ctx, 1, PHY_COMBO_PARAMS (mod, fecrate, pb_size), + (phy_gil_t)gil, 0, 1); return true; } -- cgit v1.2.3 From 67d9a6f4eaa398c1b3cfcf9c170fe5c7b3204a44 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 26 Aug 2011 16:36:23 +0200 Subject: cesar/mac/common/test/mfs: fix window size test --- cesar/mac/common/test/mfs/src/test_mfs.c | 55 ++++++++++---------------------- 1 file changed, 17 insertions(+), 38 deletions(-) (limited to 'cesar') diff --git a/cesar/mac/common/test/mfs/src/test_mfs.c b/cesar/mac/common/test/mfs/src/test_mfs.c index 2e06a22c70..e6c2f20f54 100644 --- a/cesar/mac/common/test/mfs/src/test_mfs.c +++ b/cesar/mac/common/test/mfs/src/test_mfs.c @@ -20,45 +20,24 @@ void mfs_window_size_test_case (test_t t) { test_case_begin (t, "window_size"); - test_begin (t, "encode") + test_begin (t, "decode") { - test_fail_unless (mfs_rx_window_size_encode (4) == 0x0); - test_fail_unless (mfs_rx_window_size_encode (5) == 0x0); - test_fail_unless (mfs_rx_window_size_encode (6) == 0x0); - test_fail_unless (mfs_rx_window_size_encode (8) == 0x1); - test_fail_unless (mfs_rx_window_size_encode (15) == 0x1); - test_fail_unless (mfs_rx_window_size_encode (16) == 0x2); - test_fail_unless (mfs_rx_window_size_encode (17) == 0x2); - test_fail_unless (mfs_rx_window_size_encode (24) == 0x3); - test_fail_unless (mfs_rx_window_size_encode (25) == 0x3); - test_fail_unless (mfs_rx_window_size_encode (26) == 0x3); - test_fail_unless (mfs_rx_window_size_encode (31) == 0x3); - test_fail_unless (mfs_rx_window_size_encode (32) == 0x4); - test_fail_unless (mfs_rx_window_size_encode (33) == 0x4); - test_fail_unless (mfs_rx_window_size_encode (47) == 0x4); - test_fail_unless (mfs_rx_window_size_encode (48) == 0x5); - test_fail_unless (mfs_rx_window_size_encode (49) == 0x5); - test_fail_unless (mfs_rx_window_size_encode (63) == 0x5); - test_fail_unless (mfs_rx_window_size_encode (64) == 0x6); - test_fail_unless (mfs_rx_window_size_encode (65) == 0x6); - test_fail_unless (mfs_rx_window_size_encode (79) == 0x6); - test_fail_unless (mfs_rx_window_size_encode (80) == 0x7); - test_fail_unless (mfs_rx_window_size_encode (81) == 0x7); - test_fail_unless (mfs_rx_window_size_encode (95) == 0x7); - test_fail_unless (mfs_rx_window_size_encode (96) == 0x8); - test_fail_unless (mfs_rx_window_size_encode (97) == 0x8); - test_fail_unless (mfs_rx_window_size_encode (111) == 0x8); - test_fail_unless (mfs_rx_window_size_encode (112) == 0x9); - test_fail_unless (mfs_rx_window_size_encode (113) == 0x9); - test_fail_unless (mfs_rx_window_size_encode (128) == 0xA); - test_fail_unless (mfs_rx_window_size_encode (144) == 0xB); - test_fail_unless (mfs_rx_window_size_encode (160) == 0xC); - test_fail_unless (mfs_rx_window_size_encode (192) == 0xD); - test_fail_unless (mfs_rx_window_size_encode (223) == 0xD); - test_fail_unless (mfs_rx_window_size_encode (224) == 0xE); - test_fail_unless (mfs_rx_window_size_encode (225) == 0xE); - test_fail_unless (mfs_rx_window_size_encode (255) == 0xE); - test_fail_unless (mfs_rx_window_size_encode (256) == 0xF); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_4] == 4); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_8] == 8); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_16] == 16); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_24] == 24); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_32] == 32); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_48] == 48); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_64] == 64); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_80] == 80); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_96] == 96); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_112] == 112); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_128] == 128); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_144] == 144); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_160] == 160); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_192] == 192); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_224] == 224); + test_fail_unless (mfs_window_size[MFS_WINDOW_SIZE_256] == 256); } test_end; } -- cgit v1.2.3 From 54c617e390fbaa70de402b5caf3581e28d1e6c0a Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 26 Aug 2011 18:05:19 +0200 Subject: cesar/ce/rx/test: fix uninitialised rx parameters --- cesar/ce/rx/test/src/test_rx.c | 1 + 1 file changed, 1 insertion(+) (limited to 'cesar') diff --git a/cesar/ce/rx/test/src/test_rx.c b/cesar/ce/rx/test/src/test_rx.c index 9bc9d3162c..f01deb8e65 100644 --- a/cesar/ce/rx/test/src/test_rx.c +++ b/cesar/ce/rx/test/src/test_rx.c @@ -143,6 +143,7 @@ test_ce_rx_measure_suite (test_t t) { pbproc_rx_params_t rx_params; rx_params.tei = 1; + rx_params.multi_net_bcast = false; rx_params.preamble_ntb = 0; rx_params.beacon_period_start_ntb = 42; mac_store_t *mac_store = mac_store_init (); -- cgit v1.2.3 From 4f47f7001602f6a046d997220c3291d51394dd93 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 29 Aug 2011 15:55:02 +0200 Subject: cesar/test_general/maximus/integration/sar-pbproc: fix test --- cesar/test_general/maximus/integration/sar-pbproc/src/station.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'cesar') diff --git a/cesar/test_general/maximus/integration/sar-pbproc/src/station.c b/cesar/test_general/maximus/integration/sar-pbproc/src/station.c index 2dbf28ceda..bd2116e325 100644 --- a/cesar/test_general/maximus/integration/sar-pbproc/src/station.c +++ b/cesar/test_general/maximus/integration/sar-pbproc/src/station.c @@ -39,6 +39,7 @@ #include "mac/ca/ca.h" #include "mac/sar/inc/trace.h" +#include "mac/common/timings.h" struct tei_node_t { @@ -255,7 +256,7 @@ void create_schedule_csma_only (station_test_t *int_sta, uint beacon_period_nb) for (i = 0; i < beacon_period_nb; i++) { beacons_periods[i].start_date = 1000000 * i - + my_station.current_tick_tck; + + my_station.current_tick_tck - MAC_MS_TO_TCK (30); beacons_periods[i].schedule_index = int_sta->sched_index; } @@ -282,10 +283,11 @@ void create_schedule_csma_only (station_test_t *int_sta, uint beacon_period_nb) void pbproc_sched (cyg_addrword_t int_sta) { station_test_t *station_test = (station_test_t *) int_sta; + cyg_thread_delay (3); while (true) { create_schedule_csma_only (station_test, CA_SCHEDULE_NB / 2); - cyg_thread_delay (1); + cyg_thread_delay (4); } } @@ -628,7 +630,7 @@ int fc_station_init_config (fcall_ctx_t *fcall, fcall_param_t **param, uint tei; uint snid; uint beacon_period_auto; - mac_t mac; + mac_t mac = 0; tei = 0; snid = 0; -- cgit v1.2.3 From 5d9d4c245f19787f333a685f6f3727ede7034804 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 29 Aug 2011 16:05:11 +0200 Subject: cesar/test_general/maximus/integration/interface-dp: fix test --- cesar/test_general/maximus/integration/interface-dp/src/station.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cesar') diff --git a/cesar/test_general/maximus/integration/interface-dp/src/station.c b/cesar/test_general/maximus/integration/interface-dp/src/station.c index 06b59016d4..b62a7363ee 100644 --- a/cesar/test_general/maximus/integration/interface-dp/src/station.c +++ b/cesar/test_general/maximus/integration/interface-dp/src/station.c @@ -79,9 +79,9 @@ ce_measurement_cb (void *data, pbproc_rx_params_t *rx_params, } static void -cp_beacon_recv (void *ul, pb_beacon_t * beacon, bsu_params_t *params) +cp_beacon_recv (void *ul, bsu_beacon_t *beacon) { - blk_release_desc ((blk_t*) beacon); + blk_release (beacon); } static void @@ -157,7 +157,7 @@ cp_mme_recv (void *user_data, uint tei, u8 *buffer, mytei == 1 ? BSU_UPDATE_STA_TYPE_CCO : BSU_UPDATE_STA_TYPE_STA); bsu_power_on (station_test.bsu, 0); - bsu_activate (true); + bsu_activate (station_test.bsu, true); sar_activate (station_test.sar, true); pbproc_activate (station_test.pbproc, true); } @@ -266,7 +266,6 @@ cyg_user_start (void) beacon->vf.rtsbf = false; beacon->vf.nm = BSU_BEACON_NM_CSMA_ONLY; beacon->vf.ccocap = 0; - beacon->vf.rsvd = 0; /* Regions. */ beacon->bmis.region.nb = 1; beacon->bmis.region.region[0].rt = BSU_BEACON_REGION_SHARED_CSMA; -- cgit v1.2.3 From eda03c7b27143790f141c539c80d39750b30e65e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 30 Aug 2011 14:16:09 +0200 Subject: cesar/test_general/station/maximus: add missing module --- cesar/test_general/station/maximus/Makefile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/test_general/station/maximus/Makefile b/cesar/test_general/station/maximus/Makefile index ffcb021416..82ceb3d3fc 100644 --- a/cesar/test_general/station/maximus/Makefile +++ b/cesar/test_general/station/maximus/Makefile @@ -8,7 +8,7 @@ TARGET_PROGRAMS= sta_maximus sta_maximus_SOURCES = sta_maximus_MODULES = lib mac/common mac cl hle interface cp hal station host \ - cp/av \ + cp/av bsu \ test_general/station/fcall \ test_general/station/common ce/stub -- cgit v1.2.3 From f3edc71ef773ca6f4acecbcd16a544194b46e2e9 Mon Sep 17 00:00:00 2001 From: Celine Buret Date: Tue, 30 Aug 2011 14:31:29 +0200 Subject: cesar/test_general: removing station works, closes #137 --- cesar/test_general/station/cco0/s1/py/sc9_cco_leaving.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cesar') diff --git a/cesar/test_general/station/cco0/s1/py/sc9_cco_leaving.py b/cesar/test_general/station/cco0/s1/py/sc9_cco_leaving.py index f75b01cca9..48ab2443a4 100644 --- a/cesar/test_general/station/cco0/s1/py/sc9_cco_leaving.py +++ b/cesar/test_general/station/cco0/s1/py/sc9_cco_leaving.py @@ -40,10 +40,10 @@ csi.process_wait_association (15) csi.process_wait_authentication (15) csi.authentication_status (avln1) -# Deactivate the CCo. +# Remove the CCo. stas[0].get_sta_cesar().stop() csi.process_wait_sec (1) -csi.process_sta_deactivate (stas[0]) +csi.process_sta_remove (avln1, stas[0]) csi.process_wait_sec (1) # Activate the sniffer on the second station. -- cgit v1.2.3 From 0fcef984a8bdf2718d777a1a84c0cdbb9d487c0f Mon Sep 17 00:00:00 2001 From: Celine Buret Date: Tue, 30 Aug 2011 17:44:11 +0200 Subject: cesar/{maximus,test}: close tap at unitialization, closes #244 - Create an uninitialization python function in csi, - Unitialize maximus at the end of the python scripts, - Set tap as non persistent, - Close tap at uninitialization. --- cesar/maximus/coreengine/src/Maximus.cpp | 1 + cesar/maximus/ethernet/src/EthernetProcessor.cpp | 6 ++++++ cesar/maximus/python/src/interface_module.cpp | 2 +- cesar/maximus/python/tools/csi/csicore.py | 4 ++++ cesar/test_general/station/cco0/s1/py/sc12_five_stations.py | 2 ++ cesar/test_general/station/cco0/s1/py/sc13_10stations.py | 2 ++ 6 files changed, 16 insertions(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/maximus/coreengine/src/Maximus.cpp b/cesar/maximus/coreengine/src/Maximus.cpp index 2dc2068d1b..8a885d6c69 100644 --- a/cesar/maximus/coreengine/src/Maximus.cpp +++ b/cesar/maximus/coreengine/src/Maximus.cpp @@ -1317,6 +1317,7 @@ void Maximus::stop ( ) if (0 <= mEtherLogFileDescriptor) { close(mEtherLogFileDescriptor); + mEtherLogFileDescriptor = -1; } // Warning: delete the Core Engine is the last task to do! diff --git a/cesar/maximus/ethernet/src/EthernetProcessor.cpp b/cesar/maximus/ethernet/src/EthernetProcessor.cpp index b318fc89f3..2afb9396b2 100644 --- a/cesar/maximus/ethernet/src/EthernetProcessor.cpp +++ b/cesar/maximus/ethernet/src/EthernetProcessor.cpp @@ -202,6 +202,12 @@ File_Descriptor EthernetProcessor::allocTap ( char * dev ) const } else { + /* Remove persistent status */ + if (0 > ioctl(etherLogFileDescriptor, TUNSETPERSIST, 0)) + { + throw Error(__PRETTY_FUNCTION__, "disabling TUNSETPERSIST failed", errno); + } + /* We don't need checksums calculated for packets coming in this device */ ioctl(etherLogFileDescriptor, TUNSETNOCSUM, 1); diff --git a/cesar/maximus/python/src/interface_module.cpp b/cesar/maximus/python/src/interface_module.cpp index 5b4e976ffb..33c66156d1 100644 --- a/cesar/maximus/python/src/interface_module.cpp +++ b/cesar/maximus/python/src/interface_module.cpp @@ -294,7 +294,7 @@ void init_wrap ( Maximus & m, object args ) void uninit_wrap ( Maximus & m ) { /* Free all resources. */ - delete (&m); + m.stop(); } diff --git a/cesar/maximus/python/tools/csi/csicore.py b/cesar/maximus/python/tools/csi/csicore.py index 7b37988982..c11f387170 100644 --- a/cesar/maximus/python/tools/csi/csicore.py +++ b/cesar/maximus/python/tools/csi/csicore.py @@ -222,6 +222,10 @@ class csiCore: self.__test = csiTest() + def process_uninit (self): + """Unitialise Maximus, stop it, free resources.""" + self.__maximus.uninit () + def process_sta_start (self, station = None): """Start a station which was not launched yet.""" if station == None: diff --git a/cesar/test_general/station/cco0/s1/py/sc12_five_stations.py b/cesar/test_general/station/cco0/s1/py/sc12_five_stations.py index 3189b85583..3fe8b6a166 100644 --- a/cesar/test_general/station/cco0/s1/py/sc12_five_stations.py +++ b/cesar/test_general/station/cco0/s1/py/sc12_five_stations.py @@ -52,5 +52,7 @@ csi.process_wait_sec (1) #csi.process_avlns_stop () result = csi.process_end_get_result () +csi.process_uninit () + # For nightly build errors sys.exit ((1, 0)[result]) diff --git a/cesar/test_general/station/cco0/s1/py/sc13_10stations.py b/cesar/test_general/station/cco0/s1/py/sc13_10stations.py index 499e1c2c88..76ef84c079 100644 --- a/cesar/test_general/station/cco0/s1/py/sc13_10stations.py +++ b/cesar/test_general/station/cco0/s1/py/sc13_10stations.py @@ -67,5 +67,7 @@ csi.process_avlns_remove() sys.stderr.write("Ending\n") result = csi.process_end_get_result () +csi.process_uninit () + # For nightly build errors sys.exit ((1, 0)[result]) -- cgit v1.2.3 From 95b30d8740512fdfd44ade6b4df729233efd4245 Mon Sep 17 00:00:00 2001 From: Celine Buret Date: Wed, 31 Aug 2011 14:43:21 +0200 Subject: cesar/maximus/python: add a function to get the oda, closes #311 What was done before by Nélio is correct: - OSA must always be the default mac address, - ODA must be the STA mac address if set, the default mac address otherwise. Note that the station mac address is the first parameter to be set. The only exception is to set the mac address itself: OSA and ODA must both equal the default mac address. --- cesar/maximus/python/maximus/station/sta.py | 94 ++++++++--------------------- 1 file changed, 24 insertions(+), 70 deletions(-) (limited to 'cesar') diff --git a/cesar/maximus/python/maximus/station/sta.py b/cesar/maximus/python/maximus/station/sta.py index 2f49b80861..167c9d4a11 100644 --- a/cesar/maximus/python/maximus/station/sta.py +++ b/cesar/maximus/python/maximus/station/sta.py @@ -157,15 +157,8 @@ class STA: .send(self.get()) else: # we need to build an MME - # Use the OSA with a default mac address. - osa = DEFAULT_MAC_ADDRESS - - # Get the mac address provided in the Station configuration. - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_START + MME_TYPES['REQ']) + # Computes MM Header + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_START + MME_TYPES['REQ']) # Create the MME data = '' @@ -191,12 +184,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_STOP + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_STOP + MME_TYPES['REQ']) # Create the MME mme = MME(MMHeader=mmheader) @@ -525,6 +513,17 @@ class STA: """ return self.__maximus + def __get_oda(self): + """Get the ODA to be used to send DRV MME-s. + The ODA is a Python tuple of 6 Python integers or a Python long. + """ + # Get the mac address provided in the STA config if any + if self.get_mac_address() is not None: + oda = self.get_mac_address() + else: + oda = DEFAULT_MAC_ADDRESS + return oda + def get(self): """Get the station. The station is a Sta object. @@ -653,7 +652,7 @@ class STA: else: # we need to build an MME # Computes MM Header - mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=self.get_mac_address(), MMV=0x01, MMTYPE = DRV_STA_SET_MAC_ADDR + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=DEFAULT_MAC_ADDRESS, OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_MAC_ADDR + MME_TYPES['REQ']) # Computes MM Entry: Mac address of the station # Octet Number = 0 - 5 @@ -686,12 +685,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_CCO_PREF + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_CCO_PREF + MME_TYPES['REQ']) # Computes MM Entry: # - 0x00 = Station is not CCo @@ -728,12 +722,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = self.get_mac_address() - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_WAS_CCO + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_WAS_CCO + MME_TYPES['REQ']) # Computes MM Entry: # - 0x00 = Station was not CCo @@ -770,12 +759,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_NPW + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_NPW + MME_TYPES['REQ']) # Computes MM Entry: Human-Readable (ASCII) Station Network Password # Octet Number = 0 - 63 @@ -808,12 +792,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_DPW + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_DPW + MME_TYPES['REQ']) # Computes MM Entry: Human-Readable (ASCII) Station Device Password # Octet Number = 0 - 63 @@ -846,12 +825,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_M_STA_HFID + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_M_STA_HFID + MME_TYPES['REQ']) # Computes MM Entry: Manufacturer Station Human-Friendly ID in ASCII format # Octet Number = 0 - 63 @@ -884,12 +858,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_U_STA_HFID + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_U_STA_HFID + MME_TYPES['REQ']) # Computes MM Entry: User Station Human-Friendly ID in ASCII format # Octet Number = 0 - 63 @@ -922,12 +891,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_AVLN_HFID + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_AVLN_HFID + MME_TYPES['REQ']) # Computes MM Entry: AVLN Station Human-Readable ID in ASCII format # Octet Number = 0 - 63 @@ -960,12 +924,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_SL + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_SL + MME_TYPES['REQ']) # Computes MM Entry: Security Level for New NMK # Octet Number = 0 @@ -996,12 +955,7 @@ class STA: else: # we need to build an MME # Computes MM Header - osa = DEFAULT_MAC_ADDRESS - if self.get_mac_address() is not None: - oda = self.get_mac_address() - else: - oda = DEFAULT_MAC_ADDRESS - mmheader = MMHeader(ODA=oda, OSA=osa, MMV=0x01, MMTYPE = DRV_STA_SET_TONEMASK + MME_TYPES['REQ']) + mmheader = MMHeader(ODA=self.__get_oda(), OSA=DEFAULT_MAC_ADDRESS, MMV=0x01, MMTYPE = DRV_STA_SET_TONEMASK + MME_TYPES['REQ']) # Computes MM Entry: Station Tonemask bitfield # Octet Number = 0 - 191 -- cgit v1.2.3 From 6fb1fedbca2a3bc5d0ca8452a5c4fa6f215c7214 Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Tue, 30 Aug 2011 17:22:35 +0200 Subject: cesar/cp/beacon: initialise RND lib in tests, closes #2694 --- cesar/cp/beacon/test/src/beacon.c | 987 ++++++++++++++++---------------------- 1 file changed, 403 insertions(+), 584 deletions(-) (limited to 'cesar') diff --git a/cesar/cp/beacon/test/src/beacon.c b/cesar/cp/beacon/test/src/beacon.c index 1716547d1d..0e4b83c116 100644 --- a/cesar/cp/beacon/test/src/beacon.c +++ b/cesar/cp/beacon/test/src/beacon.c @@ -35,7 +35,47 @@ cp_beacon_receive (cp_t *ctx, bsu_beacon_t *beacon); void cp_beacon_sta_compute_schedules (cp_t *ctx, bsu_beacon_t *beacon_data); -static cp_t cp; +struct test_beacon_t +{ + cp_t cp; + mac_config_t mac_config; + cl_t cl; + sar_t sar; + bsu_aclf_t aclf; + uint ca; +}; +typedef struct test_beacon_t test_beacon_t; + +void +test_beacon_init (test_beacon_t *ctx) +{ + memset (ctx, 0, sizeof (test_beacon_t)); + lib_rnd_init (&ctx->cp.rnd, 0x1234); + ctx->cp.mac_config = &ctx->mac_config; + ctx->cp.sar = &ctx->sar; + ctx->cp.cl = &ctx->cl; + ctx->cp.bsu_aclf = &ctx->aclf; + *((bsu_aclf_frequency_t*) &ctx->aclf.frequency) = BSU_ACLF_FREQ_50HZ; + *((bsu_aclf_bp_t*) &ctx->aclf.beacon_period_theo_tck) = + BSU_ACLF_BP_50HZ_TCK; + ctx->aclf.beacon_period_tck = ctx->aclf.beacon_period_theo_tck; + ctx->cp.mac_store = mac_store_init(); + ctx->cp.ca = (ca_t*) &ctx->ca; + cp_sta_mgr_init (&ctx->cp); + cp_cco_bw_init (&ctx->cp); + cp_cco_region_init (&ctx->cp); + cp_beacon_init (&ctx->cp); +} + +void +test_beacon_uninit (test_beacon_t *ctx) +{ + cp_beacon_uninit (&ctx->cp); + cp_cco_bw_uninit (&ctx->cp); + cp_cco_region_uninit (&ctx->cp); + cp_sta_mgr_uninit (&ctx->cp); + mac_store_uninit (ctx->cp.mac_store); +} bsu_beacon_t* test_new_beacon (void) @@ -75,21 +115,6 @@ test_new_beacon (void) return beacon; } - -/** Initialise - * - * At the end of this test, all the variables present in the beacon context - * shall be equal to zero or null for the pointers. - */ -void -test_case_beacon_init (test_t test) -{ - - cp_beacon_init (&cp); - - test_case_begin (test, "beacon init"); -} - /** Uninitialise * \param test the test object. * @@ -118,8 +143,8 @@ test_case_beacon_uninit (test_t test) test_case_begin (test, "Beacon uninit"); test_begin (test, "remove beacons received") { - cp_beacon_init (&cp); - cp.mac_store = mac_store_init (); + test_beacon_t ctx; + test_beacon_init (&ctx); bsu_beacon_t *b; uint i; for (i = 0; i < 2; i++) @@ -127,10 +152,10 @@ test_case_beacon_uninit (test_t test) b = blk_alloc (); b->next = NULL; b->params.direction = BSU_BEACON_DIRECTION_FROM_PLC; - cp_beacon_receive (&cp, b); + cp_beacon_receive (&ctx.cp, b); } - cp_beacon_uninit (&cp); - test_fail_unless (slist_empty (cp.beacon.list., bare)); + test_beacon_uninit (&ctx); + test_fail_unless (slist_empty (ctx.cp.beacon.list., bare)); } test_end; } @@ -139,35 +164,25 @@ void test_case_beacon__deactivate (test_t test) { test_case_begin (test, "Deactivate"); - test_begin (test, "Deactivate beacon module") { + test_beacon_t ctx; uint nb_beacons = 2; - mac_store_t *mac_store = mac_store_init(); - uint ca; - - /* Configure the test. */ - memset (&cp, 0, sizeof (cp_t)); - cp.mac_store = mac_store; - cp.ca = (ca_t *) &ca; - - cp_beacon_init (&cp); - + test_beacon_init (&ctx); /* Still configuring the test... */ - cp.beacon.leon_timer.status = true; - + ctx.cp.beacon.leon_timer.status = true; /* Allocate some beacons. */ uint i; for (i = 0; i < nb_beacons; i++) { bsu_beacon_t *beacon = blk_alloc (); beacon->next = NULL; - slist_push_back (cp.beacon.list., beacon, bare); + slist_push_back (ctx.cp.beacon.list., beacon, bare); } /* test. */ - cp_beacon_deactivate (&cp); - test_fail_unless (slist_empty (cp.beacon.list., bare)); - mac_store_uninit (mac_store); + cp_beacon_deactivate (&ctx.cp); + test_fail_unless (slist_empty (ctx.cp.beacon.list., bare)); + test_beacon_uninit (&ctx); test_fail_if (blk_check_memory () != true, "Memory leaks"); } test_end; @@ -287,30 +302,9 @@ test_beacon_bentries (test_t test, bsu_beacon_t *beacon, void test_suite_beacon__beacon_generation (test_t test) { + test_beacon_t ctx; bsu_beacon_t beacon; - - mac_config_t mac_config; - cl_t cl; - sar_t sar; - bsu_aclf_t aclf; - - /* Configure the context. */ - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - memset (&aclf, 0, sizeof (bsu_aclf_t)); - - cp.mac_config = &mac_config; - cp.cl = &cl; - cp.sar = &sar; - cp.bsu_aclf = &aclf; - aclf.beacon_period_tck = BSU_ACLF_BP_50HZ_TCK; - - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - cp_cco_bw_init (&cp); - cp_cco_region_init (&cp); - cp.mac_store = mac_store_init(); + test_beacon_init (&ctx); /* Data set one */ const cp_nid_t nid_1 = 0x001456789ABCDEF0ull; @@ -331,39 +325,39 @@ test_suite_beacon__beacon_generation (test_t test) const u8 snid_cd = 0xA; const cp_snid_t new_snid = 0xF; - cp_net_t *net_1 = cp_sta_mgr_add_avln (&cp, snid_1, nid_1); - cp_sta_own_data_set_tei (&cp, tei_1); - cp_net_set_slot_id_and_usage (&cp, net_1, slot_id_1, 0); - cp_sta_mgr_set_our_avln (&cp, net_1); - cp_beacon_handover_hoipflag (&cp, hoip_flag_1); - cp_sta_own_data_set_cco_status (&cp, cco_flag_1); - cp_sta_own_data_set_pco_status (&cp, pco_flag_1); - cp_sta_own_data_set_authenticated_status (&cp, authen_1); - cp.beacon.discover.discover_interval_bp = 10; - ((cp_sta_own_data_t *)&cp.sta_mgr.sta_own_data)->hybrid_mode = hm_1; - - cp_beacon_change_hm (&cp, new_hm); - cp.beacon.eks.kccd = kc_cd; - cp.beacon.eks.kbc = kbc; - cp.beacon.eks.new_eks = eks; - cp.beacon.hoip.hoipcd = hoip_cd; - cp.beacon.hoip.cco = hoip_tei; - cp.beacon.snids.snidcd = snid_cd; - cp.beacon.snids.snid = new_snid; - cp.beacon.discover.countdown_bp = 0; // so that the flag is true + cp_net_t *net_1 = cp_sta_mgr_add_avln (&ctx.cp, snid_1, nid_1); + cp_sta_own_data_set_tei (&ctx.cp, tei_1); + cp_net_set_slot_id_and_usage (&ctx.cp, net_1, slot_id_1, 0); + cp_sta_mgr_set_our_avln (&ctx.cp, net_1); + cp_beacon_handover_hoipflag (&ctx.cp, hoip_flag_1); + cp_sta_own_data_set_cco_status (&ctx.cp, cco_flag_1); + cp_sta_own_data_set_pco_status (&ctx.cp, pco_flag_1); + cp_sta_own_data_set_authenticated_status (&ctx.cp, authen_1); + ctx.cp.beacon.discover.discover_interval_bp = 10; + ((cp_sta_own_data_t *)&ctx.cp.sta_mgr.sta_own_data)->hybrid_mode = hm_1; + + cp_beacon_change_hm (&ctx.cp, new_hm); + ctx.cp.beacon.eks.kccd = kc_cd; + ctx.cp.beacon.eks.kbc = kbc; + ctx.cp.beacon.eks.new_eks = eks; + ctx.cp.beacon.hoip.hoipcd = hoip_cd; + ctx.cp.beacon.hoip.cco = hoip_tei; + ctx.cp.beacon.snids.snidcd = snid_cd; + ctx.cp.beacon.snids.snid = new_snid; + ctx.cp.beacon.discover.countdown_bp = 0; // so that the flag is true /* Regions. */ cp_cco_region_alloc_t *region; uint end_time_atu = 3907; - region = cp_cco_region_alloc_init (&cp); + region = cp_cco_region_alloc_init (&ctx.cp); region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA; region->end_time_atu = end_time_atu; - cp_cco_region_alloc_add (&cp, &cp.region.region_list, region); + cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region); slab_release (region); /* Fill the beacon data share memory */ - cp_beacon_fill (&cp, &beacon); + cp_beacon_fill (&ctx.cp, &beacon); test_suite_begin (test, "Beacon generation"); test_case_begin (test, "fill share memory"); @@ -412,32 +406,32 @@ test_suite_beacon__beacon_generation (test_t test) const bool authen_2 = false; const mac_coexistence_mode_t hm_2 = MAC_COEXISTENCE_NB - 1; - cp_net_t *net_2 = cp_sta_mgr_add_avln (&cp, snid_2, nid_2); - cp_sta_own_data_set_tei (&cp, tei_2); - cp_net_set_slot_id_and_usage (&cp, net_2, slot_id_2, 0); - cp_sta_mgr_set_our_avln (&cp, net_2); - cp_beacon_handover_hoipflag (&cp, hoip_flag_2); - cp_sta_own_data_set_cco_status (&cp, cco_flag_2); - cp_sta_own_data_set_pco_status (&cp, pco_flag_2); - cp_sta_own_data_set_authenticated_status (&cp, authen_2); - ((cp_sta_own_data_t *)&cp.sta_mgr.sta_own_data)->hybrid_mode = hm_2; - - cp.beacon.eks.kccd = 0; - cp.beacon.hoip.hoipcd = 0; - cp.beacon.snids.snidcd = 0; - cp.beacon.hm.hmcd = 0; + cp_net_t *net_2 = cp_sta_mgr_add_avln (&ctx.cp, snid_2, nid_2); + cp_sta_own_data_set_tei (&ctx.cp, tei_2); + cp_net_set_slot_id_and_usage (&ctx.cp, net_2, slot_id_2, 0); + cp_sta_mgr_set_our_avln (&ctx.cp, net_2); + cp_beacon_handover_hoipflag (&ctx.cp, hoip_flag_2); + cp_sta_own_data_set_cco_status (&ctx.cp, cco_flag_2); + cp_sta_own_data_set_pco_status (&ctx.cp, pco_flag_2); + cp_sta_own_data_set_authenticated_status (&ctx.cp, authen_2); + ((cp_sta_own_data_t *)&ctx.cp.sta_mgr.sta_own_data)->hybrid_mode = hm_2; + + ctx.cp.beacon.eks.kccd = 0; + ctx.cp.beacon.hoip.hoipcd = 0; + ctx.cp.beacon.snids.snidcd = 0; + ctx.cp.beacon.hm.hmcd = 0; /* Regions. */ - region = cp_cco_region_alloc_init (&cp); + region = cp_cco_region_alloc_init (&ctx.cp); region->type = CP_BEACON_REGION_TYPE_BEACON; region->end_time_atu = end_time_atu - 10; - cp_cco_region_alloc_add (&cp, &cp.region.region_list, region); + cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region); slab_release (region); - region = cp_cco_region_alloc_init (&cp); + region = cp_cco_region_alloc_init (&ctx.cp); region->type = CP_BEACON_REGION_TYPE_STAYOUT; region->end_time_atu = end_time_atu + 10; - cp_cco_region_alloc_add (&cp, &cp.region.region_list, region); + cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region); slab_release (region); /* Schedules. */ @@ -449,7 +443,7 @@ test_suite_beacon__beacon_generation (test_t test) { for (ns=0; ns < 2; ns++) { - sched = cp_cco_bw_alloc_init (&cp); + sched = cp_cco_bw_alloc_init (&ctx.cp); sched->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_PERSISTENT; sched->pscd = i; sched->cscd = i; @@ -457,14 +451,14 @@ test_suite_beacon__beacon_generation (test_t test) sched->glid = 0x55 + nb; sched->end_time_atu = end_time_atu + nb * 10 + ns * 5; sched->start_time_atu = end_time_atu + nb * 10 + ns * 5 -4; - cp_cco_bw_alloc_add (&cp, &cp.bw.alloc_list, sched); + cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, sched); slab_release (sched); } } for (ns = 0; ns < BSU_BEACON_BMIS_SCHEDULES_SAI_MAX; ns++) { - sched = cp_cco_bw_alloc_init (&cp); + sched = cp_cco_bw_alloc_init (&ctx.cp); sched->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT; sched->pscd = ns; sched->cscd = ns; @@ -472,12 +466,12 @@ test_suite_beacon__beacon_generation (test_t test) sched->glid = 0x45 + ns; sched->start_time_atu = end_time_atu - 10 * (ns + 1) -9; sched->end_time_atu = end_time_atu - 10 * (ns + 1); - cp_cco_bw_alloc_add (&cp, &cp.bw.alloc_list, sched); + cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, sched); slab_release (sched); } /* Fill the beacon data share memory */ - cp_beacon_fill (&cp, &beacon); + cp_beacon_fill (&ctx.cp, &beacon); test_suite_begin (test, "Beacon generation 2"); test_case_begin (test, "fill share memory 2"); @@ -554,9 +548,7 @@ test_suite_beacon__beacon_generation (test_t test) test_fail_unless (beacon.bmis.nps.ns == ns); } test_end; - - cp_cco_bw_uninit (&cp); - cp_cco_region_uninit (&cp); + test_beacon_uninit (&ctx); } void @@ -564,53 +556,32 @@ test_case_beacon_snid_change_cco (test_t test) { uint snid; cp_net_t *net; - mac_config_t mac_config; - cl_t cl; - sar_t sar; - bsu_aclf_t aclf; + test_beacon_t ctx; test_case_begin (test, "CCo"); + test_beacon_init (&ctx); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; - /* Configure the test. */ - memset (&cp, 0, sizeof (cp_t)); - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - - *((bsu_aclf_frequency_t*) &aclf.frequency) = BSU_ACLF_FREQ_50HZ; - *((bsu_aclf_bp_t*) &aclf.beacon_period_theo_tck) = BSU_ACLF_BP_50HZ_TCK; - aclf.beacon_period_tck = aclf.beacon_period_theo_tck; - cp.bsu_aclf = &aclf; - - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - - cp.mac_config = &mac_config; - cp.cl = &cl; - cp.sar = &sar; - cp.mac_store = mac_store_init(); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; - - net = cp_sta_mgr_add_avln (&cp, 0xA, 1); - cp_sta_own_data_set_snid (&cp, 0xA); - cp_sta_own_data_set_tei (&cp, 1); - cp_sta_mgr_set_our_avln (&cp, net); - cp_sta_own_data_set_cco_status (&cp, true); - cp_sta_own_data_set_mac_address (&cp, 0x123456789ABCull); + net = cp_sta_mgr_add_avln (&ctx.cp, 0xA, 1); + cp_sta_own_data_set_snid (&ctx.cp, 0xA); + cp_sta_own_data_set_tei (&ctx.cp, 1); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + cp_sta_own_data_set_cco_status (&ctx.cp, true); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x123456789ABCull); test_begin (test, "Change SNID") { /* Process the test. */ - test_fail_unless (cp.beacon.snids.snid == 0); - test_fail_unless (cp.beacon.snids.snidcd == 0); + test_fail_unless (ctx.cp.beacon.snids.snid == 0); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 0); snid = 1; - cp_beacon_change_snid (&cp, snid); + cp_beacon_change_snid (&ctx.cp, snid); - test_fail_unless (cp.beacon.snids.snid == snid); - test_fail_unless (cp.beacon.snids.snidcd == CP_BEACON_COUNTDOWN_SNID); + test_fail_unless (ctx.cp.beacon.snids.snid == snid); + test_fail_unless (ctx.cp.beacon.snids.snidcd == CP_BEACON_COUNTDOWN_SNID); } test_end; @@ -624,53 +595,51 @@ test_case_beacon_snid_change_cco (test_t test) set_init (&set_schedules, cp_cco_bw_alloc_less); set_init (&set_regions, cp_cco_region_alloc_less); - cp_cco_region_init (&cp); - cp_cco_bw_init (&cp); + cp_cco_region_init (&ctx.cp); + cp_cco_bw_init (&ctx.cp); /* Regions. */ - region = cp_cco_region_alloc_init (&cp); + region = cp_cco_region_alloc_init (&ctx.cp); region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA; region->end_time_atu = 3907; - cp_cco_region_alloc_add (&cp, &cp.region.region_list, region); + cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region); slab_release (region); /* Schedules. */ - alloc = cp_cco_bw_alloc_init (&cp); + alloc = cp_cco_bw_alloc_init (&ctx.cp); alloc->pscd = 7; alloc->cscd = 7; alloc->stpf = false; alloc->glid = 0x45; alloc->end_time_atu = 3907; alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_PERSISTENT; - cp_cco_bw_alloc_add (&cp, &cp.bw.alloc_list, alloc); + cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc); slab_release (alloc); - cp_beacon_fill (&cp, &beacon); + cp_beacon_fill (&ctx.cp, &beacon); test_fail_unless (beacon.bmis.change_snid.present == true); - test_fail_unless (beacon.bmis.change_snid.snidccd == cp.beacon.snids.snidcd); - test_fail_unless (beacon.bmis.change_snid.new_snid == cp.beacon.snids.snid); + test_fail_unless (beacon.bmis.change_snid.snidccd == ctx.cp.beacon.snids.snidcd); + test_fail_unless (beacon.bmis.change_snid.new_snid == ctx.cp.beacon.snids.snid); - cp_cco_bw_alloc_clean (&cp, &set_schedules); - cp_cco_region_alloc_clean (&cp, &set_regions); + cp_cco_bw_alloc_clean (&ctx.cp, &set_schedules); + cp_cco_region_alloc_clean (&ctx.cp, &set_regions); - cp_beacon_sta_compute_schedules (&cp, &beacon); - alloc = cp_cco_bw_alloc_get_first (&cp, &cp.bw.alloc_list); + cp_beacon_sta_compute_schedules (&ctx.cp, &beacon); + alloc = cp_cco_bw_alloc_get_first (&ctx.cp, &ctx.cp.bw.alloc_list); test_fail_unless (alloc->persistence == CP_CCO_BW_ALLOC_PERSISTENCE_PERSISTENT); - alloc = cp_cco_bw_alloc_get_next (&cp, &cp.bw.alloc_list, alloc); + alloc = cp_cco_bw_alloc_get_next (&ctx.cp, &ctx.cp.bw.alloc_list, alloc); test_fail_unless (!alloc); - cp_cco_region_alloc_clean (&cp, &set_regions); - cp_cco_bw_alloc_clean (&cp, &set_schedules); - cp_cco_bw_uninit (&cp); - cp_cco_region_uninit (&cp); + cp_cco_region_alloc_clean (&ctx.cp, &set_regions); + cp_cco_bw_alloc_clean (&ctx.cp, &set_schedules); + cp_cco_bw_uninit (&ctx.cp); + cp_cco_region_uninit (&ctx.cp); } test_end; /* Uninit all the data. */ - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - mac_store_uninit (cp.mac_store); + test_beacon_uninit (&ctx); } @@ -682,172 +651,137 @@ test_case_beacon_snid_change_sta (test_t test) test_begin (test, "Beacon reception") { bsu_beacon_t *beacon; - mac_config_t mac_config; - cl_t cl; - sar_t sar; cp_net_t *net; - bsu_aclf_t aclf; cp_sta_own_data_t *own; - uint phy = 0; + test_beacon_t ctx; + test_beacon_init (&ctx); /** Init the context. */ - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - cp.mac_config = &mac_config; - cp.cl = &cl; - cp.sar = &sar; - cp.phy = (phy_t *) &phy; - cp.bsu_aclf = &aclf; - cp.mac_store = mac_store_init (); - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - cp_cco_bw_init (&cp); - cp_cco_region_init (&cp); - cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* Configure station own data. */ - net = cp_sta_mgr_add_avln (&cp, 0, 1); - cp_sta_own_data_set_tei (&cp, 2); - cp_sta_own_data_set_mac_address (&cp, 0x23456789abcull); - cp_sta_mgr_set_our_avln (&cp, net); - own = cp_sta_mgr_get_sta_own_data (&cp); + net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1); + cp_sta_own_data_set_tei (&ctx.cp, 2); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); own->nid_track = 1; own->tei_track = 1; /** Check snid default values. */ - test_fail_unless (cp.beacon.snids.snid == 0); - test_fail_unless (cp.beacon.snids.snidcd == 0); - test_fail_unless (cp_net_get_snid (&cp, net) == 0x0); - test_fail_unless (cp_sta_own_data_get_snid (&cp) == 0x0); + test_fail_unless (ctx.cp.beacon.snids.snid == 0); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 0); + test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0); + test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0); /** Create a central beacon. */ beacon = test_new_beacon (); beacon->bmis.change_snid.present = true; beacon->bmis.change_snid.new_snid = 0xC; beacon->bmis.change_snid.snidccd = 3; - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); /** Check snid values are taken. */ - test_fail_unless (cp.beacon.snids.snid == 0xC); - test_fail_unless (cp.beacon.snids.snidcd == 3); - test_fail_unless (cp_net_get_snid (&cp, net) == 0x0); - test_fail_unless (cp_sta_own_data_get_snid (&cp) == 0x0); + test_fail_unless (ctx.cp.beacon.snids.snid == 0xC); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 3); + test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0); + test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0); /** Create the next beacon (countdown decreased). */ beacon = test_new_beacon (); beacon->bmis.change_snid.snidccd = 2; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /** launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); /** Check countdown. */ - test_fail_unless (cp.beacon.snids.snid == 0xC); - test_fail_unless (cp.beacon.snids.snidcd == 2); - test_fail_unless (cp_net_get_snid (&cp, net) == 0x0); - test_fail_unless (cp_sta_own_data_get_snid (&cp) == 0x0); + test_fail_unless (ctx.cp.beacon.snids.snid == 0xC); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 2); + test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0); + test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0); /** Create the next beacon (countdown decreased). */ beacon = test_new_beacon (); beacon->bmis.change_snid.snidccd = 1; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /** launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); /** Check countdown. */ - test_fail_unless (cp.beacon.snids.snid == 0xC); - test_fail_unless (cp.beacon.snids.snidcd == 1); - test_fail_unless (cp_net_get_snid (&cp, net) == 0x0); - test_fail_unless (cp_sta_own_data_get_snid (&cp) == 0x0); + test_fail_unless (ctx.cp.beacon.snids.snid == 0xC); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 1); + test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0x0); + test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0x0); /* Create the beacon. */ beacon = test_new_beacon (); beacon->bmis.change_snid.present = false; beacon->bmis.nbe--; beacon->params.rx_parameters.snid = 0xC; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); /** Check new snid is 0xC. */ - test_fail_unless (cp.beacon.snids.snid == 0xC); - test_fail_unless (cp.beacon.snids.snidcd == 0); - test_fail_unless (cp_net_get_snid (&cp, net) == 0xC); - test_fail_unless (cp_sta_own_data_get_snid (&cp) == 0xC); + test_fail_unless (ctx.cp.beacon.snids.snid == 0xC); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 0); + test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0xC); + test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0xC); - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - cp_cco_bw_uninit (&cp); - cp_cco_region_uninit (&cp); - dbg_check (mac_store_sta_remove (cp.mac_store, 1)); - mac_store_uninit (cp.mac_store); + dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1)); + test_beacon_uninit (&ctx); } test_end; test_begin (test, "Beacon missed") { - mac_config_t mac_config; - cl_t cl; - sar_t sar; + test_beacon_t ctx; cp_net_t *net; cp_cco_region_alloc_t *region; cp_cco_bw_alloc_t *alloc; - - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - - cp_cco_region_init (&cp); - cp_cco_bw_init (&cp); - + test_beacon_init (&ctx); /* Regions. */ - region = cp_cco_region_alloc_init (&cp); + region = cp_cco_region_alloc_init (&ctx.cp); region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA; region->end_time_atu = 3907; - cp_cco_region_alloc_add (&cp, &cp.region.region_list, region); + cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region); slab_release (region); /* Schedules. */ - alloc = cp_cco_bw_alloc_init (&cp); + alloc = cp_cco_bw_alloc_init (&ctx.cp); alloc->stpf = false; alloc->glid = 0x45; alloc->end_time_atu = 3907; alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT; - cp_cco_bw_alloc_add (&cp, &cp.bw.alloc_list, alloc); + cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc); slab_release (alloc); - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - /* Configure station own data. */ - net = cp_sta_mgr_add_avln (&cp, 1, 1); - cp_sta_own_data_set_tei (&cp, 2); - cp_sta_own_data_set_mac_address (&cp, 0x23456789abcull); - cp_sta_mgr_set_our_avln (&cp, net); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + net = cp_sta_mgr_add_avln (&ctx.cp, 1, 1); + cp_sta_own_data_set_tei (&ctx.cp, 2); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* Configure the test. */ - cp.beacon.snids.snidcd = 2; - cp.beacon.snids.snid = 0xc; + ctx.cp.beacon.snids.snidcd = 2; + ctx.cp.beacon.snids.snid = 0xc; - cp_beacon_beacon_not_received (&cp); + cp_beacon_beacon_not_received (&ctx.cp); - test_fail_unless (cp.beacon.snids.snidcd == 1); - test_fail_unless (cp.beacon.snids.snid == 0xc); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 1); + test_fail_unless (ctx.cp.beacon.snids.snid == 0xc); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; - cp_beacon_beacon_not_received (&cp); + cp_beacon_beacon_not_received (&ctx.cp); - test_fail_unless (cp.beacon.snids.snidcd == 0); - test_fail_unless (cp.beacon.snids.snid == 0xc); - test_fail_unless (cp_net_get_snid (&cp, net) == 0xC); - test_fail_unless (cp_sta_own_data_get_snid (&cp) == 0xC); + test_fail_unless (ctx.cp.beacon.snids.snidcd == 0); + test_fail_unless (ctx.cp.beacon.snids.snid == 0xc); + test_fail_unless (cp_net_get_snid (&ctx.cp, net) == 0xC); + test_fail_unless (cp_sta_own_data_get_snid (&ctx.cp) == 0xC); - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - cp_cco_region_uninit (&cp); - cp_cco_bw_uninit (&cp); + test_beacon_uninit (&ctx); } test_end; } @@ -868,38 +802,22 @@ test_case_beacon_hm_change_sta (test_t test) test_begin (test, "Beacon reception") { + test_beacon_t ctx; bsu_beacon_t *beacon; - mac_config_t mac_config; - cl_t cl; - sar_t sar; cp_net_t *net; - uint phy = 0; - bsu_aclf_t aclf; cp_sta_own_data_t *own; /** Init the context. */ - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - cp.mac_config = &mac_config; - cp.cl = &cl; - cp.sar = &sar; - cp.phy = (phy_t *) &phy; - cp.mac_store = mac_store_init (); - cp.bsu_aclf = &aclf; - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - cp_cco_bw_init (&cp); - cp_cco_region_init (&cp); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + test_beacon_init (&ctx); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /** Configure station own data. */ - own = cp_sta_mgr_get_sta_own_data (&cp); - net = cp_sta_mgr_add_avln (&cp, 0, 1); - cp_sta_own_data_set_tei (&cp, 2); - cp_sta_own_data_set_mac_address (&cp, 0x23456789abcull); - cp_sta_mgr_set_our_avln (&cp, net); - own = cp_sta_mgr_get_sta_own_data (&cp); + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); + net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1); + cp_sta_own_data_set_tei (&ctx.cp, 2); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); own->nid_track = 1; own->tei_track = 1; own->hybrid_mode = 0; @@ -910,126 +828,110 @@ test_case_beacon_hm_change_sta (test_t test) beacon->bmis.change_hm.hmccd = 3; beacon->bmis.nbe = 4; /** Check default values. */ - test_fail_unless (cp.beacon.hm.hm == 0); - test_fail_unless (cp.beacon.hm.hmcd == 0); + test_fail_unless (ctx.cp.beacon.hm.hm == 0); + test_fail_unless (ctx.cp.beacon.hm.hmcd == 0); test_fail_unless (own->hybrid_mode == 0); /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); /** Check values are taken. */ - test_fail_unless (cp.beacon.hm.hm == 0x1); - test_fail_unless (cp.beacon.hm.hmcd == 3); + test_fail_unless (ctx.cp.beacon.hm.hm == 0x1); + test_fail_unless (ctx.cp.beacon.hm.hmcd == 3); test_fail_unless (own->hybrid_mode == 0); /** Create the new beacon. */ beacon = test_new_beacon (); beacon->bmis.change_hm.hmccd = 2; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /** launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); /** Check values are taken. */ - test_fail_unless (cp.beacon.hm.hm == 0x1); - test_fail_unless (cp.beacon.hm.hmcd == 2); + test_fail_unless (ctx.cp.beacon.hm.hm == 0x1); + test_fail_unless (ctx.cp.beacon.hm.hmcd == 2); test_fail_unless (own->hybrid_mode == 0); /** Create the new beacon. */ beacon = test_new_beacon (); beacon->bmis.change_hm.hmccd = 1; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (cp.beacon.hm.hm == 0x1); - test_fail_unless (cp.beacon.hm.hmcd == 1); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (ctx.cp.beacon.hm.hm == 0x1); + test_fail_unless (ctx.cp.beacon.hm.hmcd == 1); test_fail_unless (own->hybrid_mode == 0); /* Create the beacon. */ beacon = test_new_beacon (); beacon->bmis.change_hm.present = false; beacon->bmis.nbe = 3; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (cp.beacon.hm.hm == 0x1); - test_fail_unless (cp.beacon.hm.hmcd == 0); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (ctx.cp.beacon.hm.hm == 0x1); + test_fail_unless (ctx.cp.beacon.hm.hmcd == 0); test_fail_unless (own->hybrid_mode == 0x1); - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - cp_cco_bw_uninit (&cp); - cp_cco_region_uninit (&cp); - dbg_check (mac_store_sta_remove (cp.mac_store, 1)); - mac_store_uninit (cp.mac_store); + dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1)); + test_beacon_uninit (&ctx); } test_end; test_begin (test, "Beacon missed") { - mac_config_t mac_config; - cl_t cl; - sar_t sar; + test_beacon_t ctx; cp_net_t *net; cp_cco_region_alloc_t *region; cp_cco_bw_alloc_t *alloc; cp_sta_own_data_t *own; - - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - - cp_cco_region_init (&cp); - cp_cco_bw_init (&cp); - + test_beacon_init (&ctx); /* Regions. */ - region = cp_cco_region_alloc_init (&cp); + region = cp_cco_region_alloc_init (&ctx.cp); region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA; region->end_time_atu = 3907; - cp_cco_region_alloc_add (&cp, &cp.region.region_list, region); + cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region); slab_release (region); /* Schedules. */ - alloc = cp_cco_bw_alloc_init (&cp); + alloc = cp_cco_bw_alloc_init (&ctx.cp); alloc->stpf = false; alloc->glid = 0x45; alloc->end_time_atu = 3907; alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT; - cp_cco_bw_alloc_add (&cp, &cp.bw.alloc_list, alloc); + cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc); slab_release (alloc); - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); + cp_sta_mgr_init (&ctx.cp); + cp_beacon_init (&ctx.cp); /* Configure station own data. */ - own = cp_sta_mgr_get_sta_own_data (&cp); - net = cp_sta_mgr_add_avln (&cp, 0, 1); - cp_sta_own_data_set_tei (&cp, 2); - cp_sta_own_data_set_mac_address (&cp, 0x23456789abcull); - cp_sta_mgr_set_our_avln (&cp, net); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); + net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1); + cp_sta_own_data_set_tei (&ctx.cp, 2); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* Configure the test. */ - cp.beacon.hm.hmcd = 2; - cp.beacon.hm.hm = 0x1; + ctx.cp.beacon.hm.hmcd = 2; + ctx.cp.beacon.hm.hm = 0x1; - cp_beacon_beacon_not_received (&cp); + cp_beacon_beacon_not_received (&ctx.cp); - test_fail_unless (cp.beacon.hm.hmcd == 1); - test_fail_unless (cp.beacon.hm.hm == 0x1); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + test_fail_unless (ctx.cp.beacon.hm.hmcd == 1); + test_fail_unless (ctx.cp.beacon.hm.hm == 0x1); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; - cp_beacon_beacon_not_received (&cp); + cp_beacon_beacon_not_received (&ctx.cp); - test_fail_unless (cp.beacon.hm.hmcd == 0); - test_fail_unless (cp.beacon.hm.hm == 0x1); + test_fail_unless (ctx.cp.beacon.hm.hmcd == 0); + test_fail_unless (ctx.cp.beacon.hm.hm == 0x1); test_fail_unless (own->hybrid_mode == 0x1); - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - cp_cco_region_uninit (&cp); - cp_cco_bw_uninit (&cp); + test_beacon_uninit (&ctx); } test_end; } @@ -1047,58 +949,43 @@ test_case_beacon_eks_change_cco (test_t test) { cp_key_t nek; cp_net_t *net; - mac_config_t mac_config; - cl_t cl; - sar_t sar; - + test_beacon_t ctx; test_case_begin (test, "CCo"); /** Configure the context. */ - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - - cp.mac_config = &mac_config; - cp.cl = &cl; - cp.sar = &sar; - cp.mac_store = mac_store_init(); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + test_beacon_init (&ctx); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /** Configure our station. */ - net = cp_sta_mgr_add_avln (&cp, 0xA, 1); - cp_sta_own_data_set_tei (&cp, 1); - cp_sta_mgr_set_our_avln (&cp, net); - cp_sta_own_data_set_cco_status (&cp, true); - cp_sta_own_data_set_mac_address (&cp, 0x123456789ABCull); + net = cp_sta_mgr_add_avln (&ctx.cp, 0xA, 1); + cp_sta_own_data_set_tei (&ctx.cp, 1); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + cp_sta_own_data_set_cco_status (&ctx.cp, true); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x123456789ABCull); test_begin (test, "Change EKS") { uint i; /** Check default values. */ - test_fail_unless (cp.beacon.eks.kccd == 0); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); - test_fail_unless (cp.beacon.eks.new_eks == 0); + test_fail_unless (ctx.cp.beacon.eks.kccd == 0); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); + test_fail_unless (ctx.cp.beacon.eks.new_eks == 0); /** Change nek. */ for (i = 0; i < COUNT (nek.key); i++) nek.key[i] = i; - cp_beacon_change_nek (&cp, MAC_EKS_MIN, nek, false /* not now*/); + cp_beacon_change_nek (&ctx.cp, MAC_EKS_MIN, nek, false /* not now*/); /** Check new values. */ - test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); - test_fail_unless (cp.beacon.eks.kccd == CP_BEACON_COUNTDOWN_EKS); + test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); + test_fail_unless (ctx.cp.beacon.eks.kccd == CP_BEACON_COUNTDOWN_EKS); } test_end; /* Uninit all the data. */ - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - mac_store_uninit (cp.mac_store); + test_beacon_uninit (&ctx); } void @@ -1109,37 +996,18 @@ test_case_beacon_eks_change_sta (test_t test) test_begin (test, "Beacon reception") { bsu_beacon_t *beacon; - mac_config_t mac_config; - cl_t cl; - sar_t sar; cp_net_t *net; - uint phy = 0; - bsu_aclf_t aclf; cp_sta_own_data_t *own; + test_beacon_t ctx; /** Init the context. */ - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - cp.mac_config = &mac_config; - cp.cl = &cl; - cp.sar = &sar; - cp.phy = (phy_t *) &phy; - cp.bsu_aclf = &aclf; - cp.mac_store = mac_store_init (); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - cp_cco_bw_init (&cp); - cp_cco_region_init (&cp); + test_beacon_init (&ctx); /** Configure station own data. */ - own = cp_sta_mgr_get_sta_own_data (&cp); - net = cp_sta_mgr_add_avln (&cp, 0, 1); - cp_sta_own_data_set_tei (&cp, 2); - cp_sta_own_data_set_mac_address (&cp, 0x23456789abcull); - cp_sta_mgr_set_our_avln (&cp, net); - own = cp_sta_mgr_get_sta_own_data (&cp); + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); + net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1); + cp_sta_own_data_set_tei (&ctx.cp, 2); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); own->nid_track = 1; own->tei_track = 1; /** Create a central beacon. */ @@ -1150,134 +1018,118 @@ test_case_beacon_eks_change_sta (test_t test) beacon->bmis.eks.new_eks = MAC_EKS_MIN + 1; mac_eks_t ref_eks_current = MAC_EKS_MIN + 2; mac_eks_t ref_eks_next = MAC_EKS_MIN + 3; - mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks = + ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks = ref_eks_current; - mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks = ref_eks_next; + ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks = ref_eks_next; /** Check default values. */ - test_fail_unless (cp.beacon.eks.kccd == 0); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); - test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN); + test_fail_unless (ctx.cp.beacon.eks.kccd == 0); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); + test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN); /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (cp.beacon.eks.kccd == 2); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); - test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (ctx.cp.beacon.eks.kccd == 2); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); + test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); test_fail_unless ( - mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks == + ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks == ref_eks_current); - test_fail_unless (mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks == + test_fail_unless (ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks == ref_eks_next); /* Create the beacon. */ beacon = test_new_beacon (); beacon->bmis.eks.kccd = 1; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (cp.beacon.eks.kccd == 1); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); - test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (ctx.cp.beacon.eks.kccd == 1); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); + test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); test_fail_unless ( - mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks == + ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks == ref_eks_current); - test_fail_unless (mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks == + test_fail_unless (ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks == ref_eks_next); /* Create the beacon. */ beacon = test_new_beacon (); beacon->bmis.eks.present = false; beacon->bmis.nbe--; - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (cp.beacon.eks.kccd == 0); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NB); - test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (ctx.cp.beacon.eks.kccd == 0); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NB); + test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); test_fail_unless ( - mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks == + ctx.mac_config.nek[bsu_nek_index_current (INVALID_PTR)].eks == ref_eks_current); - test_fail_unless (mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks == + test_fail_unless (ctx.mac_config.nek[bsu_nek_index_next (INVALID_PTR)].eks == MAC_EKS_CLEAR); - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - dbg_check (mac_store_sta_remove (cp.mac_store, 1)); - mac_store_uninit (cp.mac_store); - cp_cco_region_uninit (&cp); - cp_cco_bw_uninit (&cp); + dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1)); + test_beacon_uninit (&ctx); } test_end; test_begin (test, "Beacon missed") { - mac_config_t mac_config; - cl_t cl; - sar_t sar; cp_net_t *net; cp_cco_region_alloc_t *region; cp_cco_bw_alloc_t *alloc; cp_sta_own_data_t *own; - - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - - cp_cco_region_init (&cp); - cp_cco_bw_init (&cp); - + test_beacon_t ctx; + test_beacon_init (&ctx); /* Regions. */ - region = cp_cco_region_alloc_init (&cp); + region = cp_cco_region_alloc_init (&ctx.cp); region->type = CP_BEACON_REGION_TYPE_SHARED_CSMA; region->end_time_atu = 3907; - cp_cco_region_alloc_add (&cp, &cp.region.region_list, region); + cp_cco_region_alloc_add (&ctx.cp, &ctx.cp.region.region_list, region); slab_release (region); /* Schedules. */ - alloc = cp_cco_bw_alloc_init (&cp); + alloc = cp_cco_bw_alloc_init (&ctx.cp); alloc->stpf = false; alloc->glid = 0x45; alloc->end_time_atu = 3907; alloc->persistence = CP_CCO_BW_ALLOC_PERSISTENCE_NOT_PERSISTENT; - cp_cco_bw_alloc_add (&cp, &cp.bw.alloc_list, alloc); + cp_cco_bw_alloc_add (&ctx.cp, &ctx.cp.bw.alloc_list, alloc); slab_release (alloc); - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); + cp_sta_mgr_init (&ctx.cp); + cp_beacon_init (&ctx.cp); /* Configure station own data. */ - own = cp_sta_mgr_get_sta_own_data (&cp); - net = cp_sta_mgr_add_avln (&cp, 0, 1); - cp_sta_own_data_set_tei (&cp, 2); - cp_sta_own_data_set_mac_address (&cp, 0x23456789abcull); - cp_sta_mgr_set_our_avln (&cp, net); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); + net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1); + cp_sta_own_data_set_tei (&ctx.cp, 2); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull); + cp_sta_mgr_set_our_avln (&ctx.cp, net); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; /* Configure the test. */ - cp.beacon.eks.kccd = 2; - cp.beacon.eks.kbc = BSU_BEACON_EKS_KBC_NEK; - cp.beacon.eks.new_eks = MAC_EKS_MIN + 1; + ctx.cp.beacon.eks.kccd = 2; + ctx.cp.beacon.eks.kbc = BSU_BEACON_EKS_KBC_NEK; + ctx.cp.beacon.eks.new_eks = MAC_EKS_MIN + 1; - cp_beacon_beacon_not_received (&cp); + cp_beacon_beacon_not_received (&ctx.cp); - test_fail_unless (cp.beacon.eks.kccd == 1); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); - test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; + test_fail_unless (ctx.cp.beacon.eks.kccd == 1); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NEK); + test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); + ctx.cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; + ctx.cp.beacon.last_countdown_date = 0; - cp_beacon_beacon_not_received (&cp); + cp_beacon_beacon_not_received (&ctx.cp); - test_fail_unless (cp.beacon.eks.kccd == 0); - test_fail_unless (cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NB); - test_fail_unless (cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); + test_fail_unless (ctx.cp.beacon.eks.kccd == 0); + test_fail_unless (ctx.cp.beacon.eks.kbc == BSU_BEACON_EKS_KBC_NB); + test_fail_unless (ctx.cp.beacon.eks.new_eks == MAC_EKS_MIN + 1); - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - cp_cco_region_uninit (&cp); - cp_cco_bw_uninit (&cp); + test_beacon_uninit (&ctx); } test_end; } @@ -1300,38 +1152,17 @@ test_suite_beacon_mac_address_bentry (test_t test) test_begin (test, "Beacon reception") { bsu_beacon_t *beacon; - mac_config_t mac_config; - cl_t cl; - sar_t sar; cp_net_t *net; - uint phy = 0; - bsu_aclf_t aclf; cp_sta_own_data_t *own; + test_beacon_t ctx; /** Init the context. */ - memset (&mac_config, 0, sizeof (mac_config_t)); - memset (&cl, 0, sizeof (cl_t)); - memset (&sar, 0, sizeof (sar_t)); - - cp.mac_config = &mac_config; - cp.cl = &cl; - cp.sar = &sar; - cp.phy = (phy_t *) &phy; - cp.bsu_aclf = &aclf; - cp.mac_store = mac_store_init (); - cp.beacon.countdown_limit_date = BSU_ACLF_BP_60HZ_TCK; - cp.bsu_aclf->beacon_period_tck = BSU_ACLF_BP_60HZ_TCK; - cp.beacon.last_countdown_date = 0; - cp_sta_mgr_init (&cp); - cp_beacon_init (&cp); - cp_cco_bw_init (&cp); - cp_cco_region_init (&cp); - + test_beacon_init (&ctx); /** Configure station own data. */ - own = cp_sta_mgr_get_sta_own_data (&cp); - net = cp_sta_mgr_add_avln (&cp, 0, 1); - cp_sta_own_data_set_tei (&cp, 2); - cp_sta_own_data_set_mac_address (&cp, 0x23456789abcull); - cp_sta_mgr_set_our_avln (&cp, net); + own = cp_sta_mgr_get_sta_own_data (&ctx.cp); + net = cp_sta_mgr_add_avln (&ctx.cp, 0, 1); + cp_sta_own_data_set_tei (&ctx.cp, 2); + cp_sta_own_data_set_mac_address (&ctx.cp, 0x23456789abcull); + cp_sta_mgr_set_our_avln (&ctx.cp, net); own->nid_track = 1; own->tei_track = 1; own->cco_mac_addr_track = MAC_ZERO; @@ -1339,9 +1170,9 @@ test_suite_beacon_mac_address_bentry (test_t test) beacon = test_new_beacon (); beacon->bmis.mac_address.present = false; /* launch the test. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - cp_sta_t *cco = cp_net_get_cco (&cp, net); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + cp_sta_t *cco = cp_net_get_cco (&ctx.cp, net); test_fail_unless (cco); test_fail_unless (cp_sta_get_mac_address (cco) == MAC_BROADCAST); test_fail_unless (cp_sta_get_cco_status (cco) == true); @@ -1351,9 +1182,9 @@ test_suite_beacon_mac_address_bentry (test_t test) beacon = test_new_beacon (); beacon->bmis.mac_address.present = true; beacon->bmis.mac_address.mac_address = 0x12345678abcull; - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - cco = cp_net_get_cco (&cp, net); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + cco = cp_net_get_cco (&ctx.cp, net); test_fail_unless (cco); /* The beacon is not processed. */ test_fail_unless (cp_sta_get_mac_address (cco) @@ -1364,9 +1195,9 @@ test_suite_beacon_mac_address_bentry (test_t test) beacon = test_new_beacon (); beacon->bmis.mac_address.present = true; beacon->bmis.mac_address.mac_address = 0x0013d7000001ull; - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - cco = cp_net_get_cco (&cp, net); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + cco = cp_net_get_cco (&ctx.cp, net); test_fail_unless (cco); test_fail_unless (cp_sta_get_mac_address (cco) != beacon->bmis.mac_address.mac_address); @@ -1378,9 +1209,9 @@ test_suite_beacon_mac_address_bentry (test_t test) beacon = test_new_beacon (); beacon->bmis.mac_address.present = true; beacon->bmis.mac_address.mac_address = 0x0013d7000001ull; - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - cco = cp_net_get_cco (&cp, net); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + cco = cp_net_get_cco (&ctx.cp, net); test_fail_unless (cco); test_fail_unless (cp_sta_get_mac_address (cco) == beacon->bmis.mac_address.mac_address); @@ -1391,23 +1222,17 @@ test_suite_beacon_mac_address_bentry (test_t test) beacon = test_new_beacon (); beacon->bmis.mac_address.present = true; beacon->bmis.mac_address.mac_address = 0x12345678abcull; - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - cco = cp_net_get_cco (&cp, net); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + cco = cp_net_get_cco (&ctx.cp, net); test_fail_unless (cco); test_fail_unless (cp_sta_get_mac_address (cco) == 0x0013d7000001ull); test_fail_unless (cp_sta_get_cco_status (cco) == true); slab_release (cco); - cp_beacon_uninit (&cp); - cp_sta_mgr_uninit (&cp); - dbg_check (mac_store_sta_remove (cp.mac_store, 1)); - mac_store_uninit (cp.mac_store); - - cp_cco_region_uninit (&cp); - cp_cco_bw_uninit (&cp); + dbg_check (mac_store_sta_remove (ctx.cp.mac_store, 1)); + test_beacon_uninit (&ctx); } test_end; - } void @@ -1466,53 +1291,48 @@ test_suite_beacon_no_net (test_t t) void test_suite_beacon_spoc_update (test_t test) { - cp_t cp; - mac_config_t mc; - cp.mac_config = &mc; - mac_config_init (cp.mac_config); - cp_beacon_init (&cp); - cp_sta_mgr_init (&cp); - cp_cco_region_init (&cp); - cp_cco_bw_init (&cp); + test_beacon_t ctx; + test_beacon_init (&ctx); test_suite_begin (test, "SPOC update"); test_case_begin (test, "Frequency error invalid and valid"); test_begin (test, "SPOC only updated if F.E. is valid") { - cp_sta_own_data_t *own = cp_sta_mgr_get_sta_own_data (&cp); - cp.beacon.spoc_update_interval_ms = 1; + cp_sta_own_data_t *own = cp_sta_mgr_get_sta_own_data (&ctx.cp); + ctx.cp.beacon.spoc_update_interval_ms = 1; bsu_beacon_t *beacon = test_new_beacon (); - cp_sta_mgr_add_avln (&cp, beacon->params.rx_parameters.snid, + cp_sta_mgr_add_avln (&ctx.cp, beacon->params.rx_parameters.snid, beacon->vf.nid); - cp.beacon.spoc_update_date = phy_date () - 1; - cp_sta_own_data_set_nid (&cp, beacon->vf.nid); + ctx.cp.beacon.spoc_update_date = phy_date () - 1; + cp_sta_own_data_set_nid (&ctx.cp, beacon->vf.nid); own->nid_track = beacon->vf.nid; own->tei_track = beacon->vf.stei; + beacon->params.rx_parameters.snid = + cp_sta_own_data_get_snid (&ctx.cp); /* Process a received beacon with a frequency error invalid. */ - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (!cp.beacon.spoc_updated); + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (!ctx.cp.beacon.spoc_updated); /* This received beacon has a valid frequency error, SPOC should be * updated. */ beacon = test_new_beacon (); beacon->params.frequency_error_valid = true; - cp.beacon.spoc_update_date = phy_date () - 1; - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (cp.beacon.spoc_updated); + beacon->params.rx_parameters.snid = + cp_sta_own_data_get_snid (&ctx.cp); + ctx.cp.beacon.spoc_update_date = phy_date () - 1; + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (ctx.cp.beacon.spoc_updated); /* This received beacon has a invalid frequency error. SPOC updated * flag stay at true. */ beacon = test_new_beacon (); beacon->params.frequency_error_valid = false; - cp.beacon.spoc_update_date = phy_date () - 1; - cp_beacon_receive (&cp, beacon); - cp_beacon_get_and_process_beacon (&cp); - test_fail_unless (cp.beacon.spoc_updated); + ctx.cp.beacon.spoc_update_date = phy_date () - 1; + cp_beacon_receive (&ctx.cp, beacon); + cp_beacon_get_and_process_beacon (&ctx.cp); + test_fail_unless (ctx.cp.beacon.spoc_updated); } test_end; - cp_cco_region_uninit (&cp); - cp_cco_bw_uninit (&cp); - cp_sta_mgr_uninit (&cp); - cp_beacon_uninit (&cp); + test_beacon_uninit (&ctx); } int @@ -1521,7 +1341,6 @@ main (void) test_t test; test_init (test, 0, NULL); - test_case_beacon_init (test); test_case_beacon_uninit (test); test_case_beacon__deactivate (test); test_suite_beacon__beacon_generation (test); -- cgit v1.2.3 From 2d4edc7a7963b4fbd5f10420b8492ad5d50c309e Mon Sep 17 00:00:00 2001 From: Celine Buret Date: Thu, 1 Sep 2011 16:58:07 +0200 Subject: cesar/maximus: set tap10 interface as persistent, refs #244 --- cesar/maximus/ethernet/src/EthernetProcessor.cpp | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cesar') diff --git a/cesar/maximus/ethernet/src/EthernetProcessor.cpp b/cesar/maximus/ethernet/src/EthernetProcessor.cpp index 2afb9396b2..1d7c7267ef 100644 --- a/cesar/maximus/ethernet/src/EthernetProcessor.cpp +++ b/cesar/maximus/ethernet/src/EthernetProcessor.cpp @@ -202,10 +202,10 @@ File_Descriptor EthernetProcessor::allocTap ( char * dev ) const } else { - /* Remove persistent status */ - if (0 > ioctl(etherLogFileDescriptor, TUNSETPERSIST, 0)) + /* Set persistent status */ + if (0 > ioctl(etherLogFileDescriptor, TUNSETPERSIST, 1)) { - throw Error(__PRETTY_FUNCTION__, "disabling TUNSETPERSIST failed", errno); + throw Error(__PRETTY_FUNCTION__, "enabling TUNSETPERSIST failed", errno); } /* We don't need checksums calculated for packets coming in this device */ -- cgit v1.2.3 From 88223f26b836a3eb7e694e9e6af1d67f6cc7c68d Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 30 Aug 2011 16:14:34 +0200 Subject: cesar/test_general/station/tonemap: fix tests --- cesar/common/tests/tests | 7 ++----- cesar/test_general/station/tonemap/py/sc01_bl_initial.py | 9 ++++++++- cesar/test_general/station/tonemap/py/sc02_vs_get_tonemap.py | 11 ++++++++--- 3 files changed, 18 insertions(+), 9 deletions(-) (limited to 'cesar') diff --git a/cesar/common/tests/tests b/cesar/common/tests/tests index 3a138ddf5a..fd70b83081 100644 --- a/cesar/common/tests/tests +++ b/cesar/common/tests/tests @@ -461,7 +461,8 @@ sc01_long_simu: python py/sc01_long_simu.py -d false -t 25000000000 sc02_long_simu_data: python py/sc02_long_simu_data.py -d false -t 25000000000 test_general/station/tonemap: -make +make -f host-Makefile +sc01_bl_initial: python py/sc01_bl_initial.py --maximus sc02_vs_get_tonemap: python py/sc02_vs_get_tonemap.py --maximus cp/cco/bw/test: @@ -480,10 +481,6 @@ test_general/station/compliance: make 6.2.1-dut_as_a_cco: python py/sc01_dut_as_a_cco.py --maximus -test_general/station/tonemap: -make -f host-Makefile -tone_map_exchange_no_snr: python py/sc01_bl_initial.py --maximus - bsu/beacon/test/utest: make beacon: ./obj/beacon diff --git a/cesar/test_general/station/tonemap/py/sc01_bl_initial.py b/cesar/test_general/station/tonemap/py/sc01_bl_initial.py index 9605b4d314..3a22ef624e 100644 --- a/cesar/test_general/station/tonemap/py/sc01_bl_initial.py +++ b/cesar/test_general/station/tonemap/py/sc01_bl_initial.py @@ -32,9 +32,16 @@ class TestBitloadingInitial (unittest.TestCase): # Wait for association and authentication. self.failUnless (csi.process_wait_association () == True) self.failUnless (csi.process_wait_authentication () == True) + # Send traffic to initiate tonemap negociation. + packets = [ csiPacket (100, avln, sta_src = txsta, sta_dest = rxsta) + for txsta, rxsta in ((csista[0], csista[1]), + (csista[1], csista[0])) ] + csi.process_data_send_traffic (packets) + csi.process_wait_sec (1) + csi.process_verify_transmission () + # For each STA tmi_list_rx = [] tmi_list_tx = [] - # For each STA for i in range (sta_count): # Get TEI and peer TEI. sta_own = Station_own_data () diff --git a/cesar/test_general/station/tonemap/py/sc02_vs_get_tonemap.py b/cesar/test_general/station/tonemap/py/sc02_vs_get_tonemap.py index 6bf0c56e06..d4e7c2031d 100644 --- a/cesar/test_general/station/tonemap/py/sc02_vs_get_tonemap.py +++ b/cesar/test_general/station/tonemap/py/sc02_vs_get_tonemap.py @@ -167,8 +167,13 @@ class TestVsGetTonemap (unittest.TestCase): # Wait for association and authentication. self.failUnless (csi.process_wait_association () == True) self.failUnless (csi.process_wait_authentication () == True) - # Wait a little bit. - csi.process_wait_sec (3) + # Send traffic to initiate tonemap negociation. + packets = [ csiPacket (100, avln, sta_src = txsta, sta_dest = rxsta) + for txsta, rxsta in ((csista[0], csista[1]), + (csista[1], csista[0])) ] + csi.process_data_send_traffic (packets) + csi.process_wait_sec (1) + csi.process_verify_transmission () print "\nGet valid tonemap indexes and intervals lists only" req_tmi = 0xFF @@ -208,7 +213,7 @@ class TestVsGetTonemap (unittest.TestCase): #Check results self.failUnless (result == 2) # 2 is bad version print "\nTry to get a tonemap not available" - req_tmi = 0 + req_tmi = 0x1f version = int_id (result, int_id, tmi_dflt, tmi_length, tmis, int_length, int_ets, int_tmis, tmi, tm_fec, tm_gi, mods) = send_vs_get_tonemap_req (self, req_tmi, version, 1, csista[0], csista[1]) #Check results -- cgit v1.2.3 From 45b55156008c829d66f02da230093020b360cdef Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 30 Aug 2011 17:46:27 +0200 Subject: cesar/test_general/station/maximus: fix tests --- cesar/test_general/station/maximus/py/sc01_long_simu.py | 2 +- cesar/test_general/station/maximus/py/sc02_long_simu_data.py | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) (limited to 'cesar') diff --git a/cesar/test_general/station/maximus/py/sc01_long_simu.py b/cesar/test_general/station/maximus/py/sc01_long_simu.py index 1c5357612c..c91c282dc3 100644 --- a/cesar/test_general/station/maximus/py/sc01_long_simu.py +++ b/cesar/test_general/station/maximus/py/sc01_long_simu.py @@ -44,7 +44,7 @@ for i in range(avln_sta_count): 1, False, 0) # Start the simulation. -csi.process_init(sys.path[0] + '/../obj/sta_maximus.elf') +csi.process_init(sys.argv + ['-e', sys.path[0] + '/../obj/sta_maximus.elf']) # Start the AVLN and STA. csi.process_avlns_launch() # Wait for association. diff --git a/cesar/test_general/station/maximus/py/sc02_long_simu_data.py b/cesar/test_general/station/maximus/py/sc02_long_simu_data.py index ab20db1174..945471e5b5 100644 --- a/cesar/test_general/station/maximus/py/sc02_long_simu_data.py +++ b/cesar/test_general/station/maximus/py/sc02_long_simu_data.py @@ -50,7 +50,7 @@ for i in range(avln_sta_count): 1, False, 0) # Start the simulation. -csi.process_init(sys.path[0] + '/../obj/sta_maximus.elf') +csi.process_init(sys.argv + ['-e', sys.path[0] + '/../obj/sta_maximus.elf']) # Start the AVLN and STA. csi.process_avlns_launch() # Wait for association. -- cgit v1.2.3 From 5e798d3a84666e2074960d636f9946de2f609eb5 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 31 Aug 2011 09:46:53 +0200 Subject: cesar/common/tests: fix cov-target usage --- cesar/common/tests/tests | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/common/tests/tests b/cesar/common/tests/tests index fd70b83081..3851e1e17d 100644 --- a/cesar/common/tests/tests +++ b/cesar/common/tests/tests @@ -81,7 +81,7 @@ cov test_mac_lookup_table: ./obj/test_mac_lookup_table lib/test/mbox: make: make COV=y cov test_mbox_host: ./obj/mbox_host -cov test_mbox_ecos: ./obj/mbox.elf +cov-target test_mbox_ecos: ./obj/mbox.elf lib/test/perf: make: make -- cgit v1.2.3 From 717d9fde359132462e44e8b61f7712be9ae2f81f Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 31 Aug 2011 16:51:46 +0200 Subject: cesar/lib: add almost_eqf This is used to compare floating point numbers for equality. --- cesar/lib/Module | 2 +- cesar/lib/src/utils.c | 42 +++++++++++++++++++++++++++++ cesar/lib/test/utils/src/test_utils.c | 50 +++++++++++++++++++++++++++++++++++ cesar/lib/utils.h | 12 +++++++++ 4 files changed, 105 insertions(+), 1 deletion(-) create mode 100644 cesar/lib/src/utils.c (limited to 'cesar') diff --git a/cesar/lib/Module b/cesar/lib/Module index 0c9d1aa51b..69d03af8a3 100644 --- a/cesar/lib/Module +++ b/cesar/lib/Module @@ -1,7 +1,7 @@ SOURCES := crc.c dbg.c heap.c test.c blk.c slab.c list.c \ aatree.c try.c fixed.c blk_table.c \ swap.c read_word.c bitstream.c circular_buffer.c mbox.c \ - mac_lookup_table.c init.c rnd.c + mac_lookup_table.c init.c rnd.c utils.c ifeq ($(CONFIG_HEAP_SKEW),y) SOURCES += skewheap.c endif diff --git a/cesar/lib/src/utils.c b/cesar/lib/src/utils.c new file mode 100644 index 0000000000..4ca7b39654 --- /dev/null +++ b/cesar/lib/src/utils.c @@ -0,0 +1,42 @@ +/* Cesar project {{{ + * + * Copyright (C) 2011 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file lib/src/utils.c + * \brief Common utilities. + * \ingroup lib + */ +#include "common/std.h" + +/* See + * http://www.cygnus-software.com/papers/comparingfloats/comparingfloats.htm + */ +bool +almost_eqf (float a, float b, int max_ulps) +{ + union + { + float f; + s32 i; + } aInt, bInt; + /* Make sure max_ulps is non-negative and small enough that the default + * NAN won't compare as equal to anything. */ + dbg_assert (max_ulps > 0 && max_ulps < 4 * 1024 * 1024); + aInt.f = a; + /* Make aInt lexicographically ordered as a twos-complement int. */ + if (aInt.i < 0) + aInt.i = 0x80000000 - aInt.i; + /* Make bInt lexicographically ordered as a twos-complement int. */ + bInt.f = b; + if (bInt.i < 0) + bInt.i = 0x80000000 - bInt.i; + s32 intDiff = ABS (aInt.i - bInt.i); + if (intDiff <= max_ulps) + return true; + return false; +} + diff --git a/cesar/lib/test/utils/src/test_utils.c b/cesar/lib/test/utils/src/test_utils.c index 8b7beab993..751a518b65 100644 --- a/cesar/lib/test/utils/src/test_utils.c +++ b/cesar/lib/test/utils/src/test_utils.c @@ -13,6 +13,55 @@ #include "common/std.h" #include "lib/test.h" +#include "float.h" +#include "math.h" + +void +eq_test_case (test_t t) +{ + test_case_begin (t, "eq"); + test_begin (t, "almost_eqf basic") + { + test_fail_unless (almost_eqf (1.0f, 1.0f, 1)); + test_fail_unless (!almost_eqf (1.0f, 2.0f, 1)); + test_fail_unless (!almost_eqf (1000.0f, 2000.0f, 1)); + /* FLT_EPSILON is the smallest number for which: + * 1.0f != 1.0f + FLT_EPSILON. */ + test_fail_unless (almost_eqf (1.0f, 1.0f + FLT_EPSILON, 1)); + test_fail_unless (!almost_eqf (1.0f, 1.0f + FLT_EPSILON * 2, 1)); + test_fail_unless (almost_eqf (1.0f, 1.0f + FLT_EPSILON * 2, 2)); + test_fail_unless (almost_eqf (512.f, 512.f + 512 * FLT_EPSILON, 1)); + test_fail_unless (!almost_eqf (512.f, 512.f + 1024 * FLT_EPSILON, 1)); + test_fail_unless (almost_eqf (512.f, 512.f + 1024 * FLT_EPSILON, 2)); + } test_end; + test_begin (t, "almost_eqf zeroes") + { + /* IEEE floats are ordered. Compute the smallest non-zero positive and + * negative number. Those are subnormals. */ + float ep = 0.0f; + s32 epb = *(s32 *)&ep + 1; + ep = *(float *) &epb; + float em = -0.0f; + s32 emb = *(s32 *)&em + 1; + em = *(float *) &emb; + /* Test around zero. */ + test_fail_unless (almost_eqf (0.0f, -0.0f, 1)); + test_fail_unless (almost_eqf (ep, em, 2)); + test_fail_unless (!almost_eqf (ep, em, 1)); + } test_end; + test_begin (t, "almost_eqf infinity") + { + /* Accepted complication. */ + test_fail_unless (almost_eqf (INFINITY, FLT_MAX, 1)); + test_fail_unless (almost_eqf (-INFINITY, -FLT_MAX, 1)); + } test_end; + test_begin (t, "almost_eqf NaN") + { + test_fail_unless (!almost_eqf (NAN, 1.0f, 1)); + /* Accepted complication. */ + test_fail_unless (almost_eqf (NAN, NAN, 1)); + } test_end; +} void bits_test_case (test_t t) @@ -229,6 +278,7 @@ void utils_test_suite (test_t t) { test_suite_begin (t, "utils"); + eq_test_case (t); bits_test_case (t); bf_test_case (t); rot_test_case (t); diff --git a/cesar/lib/utils.h b/cesar/lib/utils.h index 4d87d90515..fc1e689a75 100644 --- a/cesar/lib/utils.h +++ b/cesar/lib/utils.h @@ -333,4 +333,16 @@ lesseq_mod2p16 (u16 a, u16 b) index = a_; \ } while (0) +BEGIN_DECLS + +/** Compare floating point numbers, return true if they are almost equal. + * \param a first number to compare + * \param b second number to compare + * \param max_ulps maximum error as unit in the last place + */ +bool +almost_eqf (float a, float b, int max_ulps); + +END_DECLS + #endif /* lib_utils_h */ -- cgit v1.2.3 From dc7fdf8144e9497e82450343a33dc7c85d0a10d4 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 31 Aug 2011 16:52:26 +0200 Subject: cesar/maximus: fix unit test --- cesar/maximus/channel/src/ChannelComputerTest.cpp | 38 +++++++++++------------ 1 file changed, 19 insertions(+), 19 deletions(-) (limited to 'cesar') diff --git a/cesar/maximus/channel/src/ChannelComputerTest.cpp b/cesar/maximus/channel/src/ChannelComputerTest.cpp index 31e980c5f8..fead652382 100644 --- a/cesar/maximus/channel/src/ChannelComputerTest.cpp +++ b/cesar/maximus/channel/src/ChannelComputerTest.cpp @@ -145,69 +145,69 @@ void ChannelComputerTest::protectedTest (void) // Test PowerScale Channel_Mod modulation = MAXIMUS_CHANNEL_MOD_BPSK; float powerScale = channelComputer.getPowerScaleTest(modulation); - CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", 1 == powerScale); + CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", almost_eqf (1, powerScale, 5)); modulation = MAXIMUS_CHANNEL_MOD_QPSK; powerScale = channelComputer.getPowerScaleTest(modulation); - CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", 2 == powerScale); + CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", almost_eqf (2, powerScale, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM8; powerScale = channelComputer.getPowerScaleTest(modulation); - CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", (float)(5+pow(1.29,2)) == powerScale); + CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", almost_eqf (5 + pow (1.29, 2), powerScale, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM16; powerScale = channelComputer.getPowerScaleTest(modulation); - CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", 10 == powerScale); + CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", almost_eqf (10, powerScale, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM64; powerScale = channelComputer.getPowerScaleTest(modulation); - CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", 42 == powerScale); + CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", almost_eqf (42, powerScale, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM256; powerScale = channelComputer.getPowerScaleTest(modulation); - CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", 170 == powerScale); + CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", almost_eqf (170, powerScale, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM1024; powerScale = channelComputer.getPowerScaleTest(modulation); - CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", 682 == powerScale); + CPPUNIT_ASSERT_MESSAGE ( "getPowerScale failed", almost_eqf (682, powerScale, 5)); // Test linear SNR float snr = 10; // in dB double linearSnr = channelComputer.getLinearSnrTest(snr); - CPPUNIT_ASSERT_MESSAGE ( "getLinearSnr failed", 10 == linearSnr); + CPPUNIT_ASSERT_MESSAGE ( "getLinearSnr failed", almost_eqf (10, linearSnr, 5)); snr = 16; // in dB linearSnr = channelComputer.getLinearSnrTest(snr); - CPPUNIT_ASSERT_MESSAGE ( "getLinearSnr failed", (float)pow(10, 1.6) == linearSnr); + CPPUNIT_ASSERT_MESSAGE ( "getLinearSnr failed", almost_eqf (pow (10, 1.6), linearSnr, 5)); snr = 15.55555; // in dB linearSnr = channelComputer.getLinearSnrTest(snr); - CPPUNIT_ASSERT_MESSAGE ( "getLinearSnr failed", (float)pow(10, 1.555555) == linearSnr); + CPPUNIT_ASSERT_MESSAGE ( "getLinearSnr failed", almost_eqf (pow (10, 1.555555), linearSnr, 5)); // Test sigma factor modulation = MAXIMUS_CHANNEL_MOD_BPSK; snr = 10; // in dB double sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt(1/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt(1/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); modulation = MAXIMUS_CHANNEL_MOD_QPSK; snr = 11.1; // in dB sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt(2/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt(2/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM8; snr = 12.2; // in dB sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt((float)(5+pow(1.29, 2))/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt((5+pow(1.29, 2))/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM16; snr = 13.3; // in dB sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt(10/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt(10/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM64; snr = 14.4; // in dB sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt(42/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt(42/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM256; snr = 15.5; // in dB sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt(170/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt(170/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); modulation = MAXIMUS_CHANNEL_MOD_QAM1024; snr = 16.6; // in dB sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt(682/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt(682/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); snr = 0; // in dB sigma = channelComputer.getSigmaTest(modulation, snr); - CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", (double)sqrt(682/(2*channelComputer.getLinearSnrTest(snr))) == sigma); + CPPUNIT_ASSERT_MESSAGE ( "getSigma failed", almost_eqf (sqrt(682/(2*channelComputer.getLinearSnrTest(snr))), sigma, 5)); // Test noise point ChannelPoint point(1, 0); @@ -268,7 +268,7 @@ void ChannelComputerTest::protectedTest (void) modulation = MAXIMUS_CHANNEL_MOD_BPSK; float fer = channelComputer.computeFerTest(ber, n, modulation); float expectedFer = pow(10, 1-(unsigned short int)100*exp(-pow((unsigned short int)50*ber, 2)))/10; - CPPUNIT_ASSERT_MESSAGE ( "computeFer 1 failed", expectedFer == fer); + CPPUNIT_ASSERT_MESSAGE ( "computeFer 1 failed", almost_eqf (expectedFer, fer, 5)); modulation = MAXIMUS_CHANNEL_MOD_QPSK; fer = channelComputer.computeFerTest(ber, n, modulation); expectedFer = pow(10, 1-(unsigned short int)100*exp(-pow((unsigned short int)50*(ber-0.01*(float)4.6), 2)))/10; -- cgit v1.2.3 From 35f098546dc0c47b006975c2c0f821fa99c2884b Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 22 Aug 2011 16:18:23 +0200 Subject: cesar/common/make: add check for old build system leftovers, closes #2688 --- cesar/common/make/config.mk | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'cesar') diff --git a/cesar/common/make/config.mk b/cesar/common/make/config.mk index ac46989db0..c5dbc829ff 100644 --- a/cesar/common/make/config.mk +++ b/cesar/common/make/config.mk @@ -64,6 +64,10 @@ $$($2_OBJ_INC_DIR)/build_info.h: $$($2_OBJ_INC_DIR_STAMP) BUILD_INFO_FORCE endef $(call foreach_type,CONFIG_RULES_template) +# Check for old build system leftovers. +$(if $(wildcard $(OBJ_INC_DIR)/build_info.h),\ +$(error old build system leftovers detected, please rm -r obj)) + $(DEFAULT_PROJECT_CONFIG): $(OBJ_DIR_STAMP) touch $@ -- cgit v1.2.3 From 0fe91480bca31711e5edffd195eeeddc860857bc Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Wed, 13 Jul 2011 16:18:50 +0200 Subject: cesar/lib: add library to check sequence number in data packets, refs #2644 By default, this library is disabled (at compilation) for performance reasons. --- cesar/common/tests/tests | 4 + cesar/lib/Config | 2 + cesar/lib/Module | 3 + cesar/lib/seq_check.h | 170 +++++++++++++++++++++ cesar/lib/src/seq_check.c | 154 +++++++++++++++++++ cesar/lib/test/seq_check/Config | 2 + cesar/lib/test/seq_check/Makefile | 8 + cesar/lib/test/seq_check/src/seq_check.c | 250 +++++++++++++++++++++++++++++++ cesar/station/src/station.c | 4 + 9 files changed, 597 insertions(+) create mode 100644 cesar/lib/seq_check.h create mode 100644 cesar/lib/src/seq_check.c create mode 100644 cesar/lib/test/seq_check/Config create mode 100644 cesar/lib/test/seq_check/Makefile create mode 100644 cesar/lib/test/seq_check/src/seq_check.c (limited to 'cesar') diff --git a/cesar/common/tests/tests b/cesar/common/tests/tests index 3851e1e17d..b83bb8d1ff 100644 --- a/cesar/common/tests/tests +++ b/cesar/common/tests/tests @@ -134,6 +134,10 @@ lib/scenario/test: make: make COV=y cov test_scenario: ./obj/test_scenario +lib/test/seq_check: +make: make COV=y +cov test_seq_check: ./obj/test_seq_check + maximus/stationtest: make diff --git a/cesar/lib/Config b/cesar/lib/Config index f8dfbbd3a3..bb13fd5ab8 100644 --- a/cesar/lib/Config +++ b/cesar/lib/Config @@ -26,3 +26,5 @@ CONFIG_GPIO_FATAL_BLINK_DELAY = 10000000 CONFIG_SLAB_ALLOC_SCRAMBLE = n CONFIG_RND_MT19937 = n CONFIG_RND_TT800 = y +CONFIG_SEQ_CHECK = n +CONFIG_SEQ_CHECK_VLAN_MAX = 64 diff --git a/cesar/lib/Module b/cesar/lib/Module index 69d03af8a3..e57586f636 100644 --- a/cesar/lib/Module +++ b/cesar/lib/Module @@ -26,3 +26,6 @@ endif ifeq ($(CONFIG_RND_TT800),y) SOURCES += tt800.c endif +ifeq ($(CONFIG_SEQ_CHECK),y) +SOURCES += seq_check.c +endif diff --git a/cesar/lib/seq_check.h b/cesar/lib/seq_check.h new file mode 100644 index 0000000000..5e0916ce29 --- /dev/null +++ b/cesar/lib/seq_check.h @@ -0,0 +1,170 @@ +#ifndef lib_seq_check_h +#define lib_seq_check_h +/* Cesar project {{{ + * + * Copyright (C) 2011 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file lib/seq_check.h + * \brief Check sequence number in data packets + * \ingroup lib + * + * This lib is used to check sequence number in data packets generated by + * IPerf or Ixia. It supports VLAN if packets are tagged. + * + * De-sequence is stored in traces (no assert is done). + * + * You can configure: + * - position of the sequence number in the packet, + * - Ethernet type to inspect. + * + * This lib has some limitations: + * - you can not ignore some packets: for example during an IPerf traffic, if + * they are some pings, they will be inspected. If there is video traffic, it + * will be inspected too, + * - having different kind of throughput at the same time is not possible: an + * IPerf, an Ixia and video. You can only configure for one throughput, + * - you can not specify the first sequence number value, + * - you can not specify the size/length of the sequence number, + * - it can not support VLAN and non VLAN traffic at the same time (sequence + * position is the same for both). + * + * This lib should only be enabled when needed as it will probably impact + * performance (it needs to inspect packets). + */ + +#include "config/seq/check.h" + +#if CONFIG_SEQ_CHECK + +/** + * Callback used when there is a de-sequencing in the packets. + * \param user an user pointer + * \param vlan the VLAN id which in the packet or 0 if there is none + * \param seq_expected the sequence number expected + * \param seq_actual the sequence actually in the packet + * + * This function is called by lib_seq_check_packet when there the sequence + * number is not the one expected. + */ +typedef void +(*lib_seq_check_error_cb_t) (void *user, uint vlan, uint seq_expected, + uint seq_actual); + +/** + * Ethernet type IP. + */ +#define SEQ_CHECK_ET_IP 0x8000 + +/** + * Sequence counters. + * This structure is used to store states of the sequence counter. There is + * one for each VLAN. + */ +typedef struct lib_seq_check_t +{ + /** + * Sequence counters, for each VLAN id. + * \note if no VLAN is present on frames, first index of the table is + * used. There should be no problem, as VLAN 0 is for management. + */ + uint seq[CONFIG_SEQ_CHECK_VLAN_MAX]; + /** + * Callback when sequence is wrong. + */ + lib_seq_check_error_cb_t cb; + /** + * The user pointer used when calling the callback. + */ + void *cb_user; +} lib_seq_check_t; + +/** + * Configuration structure. + */ +typedef struct lib_seq_check_config_t +{ + /** + * Sequence number size. + * It only support 16 for the moment. + */ + u8 seq_size; + /** + * Position of the sequence number in the packet. + * The position start at first bit of the Ethernet frame. + * This counter is expressed in byte. + */ + uint seq_pos; + /** + * Ethernet type the packet has to have. + */ + uint ethertype; +} lib_seq_check_config_t; + +BEGIN_DECLS + +/** + * Configure lib sequencer check. + * \param config the new configuration structure to use. + * + * All fields are copied to the configuration. If you only want to setup one + * field, you need to use lib_seq_check_config_get before. + */ +void +lib_seq_check_config_set (lib_seq_check_config_t *config); + +/** + * Get current configuration. + * \param config a configuration which will be set to the current one of the + * sequencer check of the lib. + */ +void +lib_seq_check_config_get (lib_seq_check_config_t *config); + +/** + * Initialize lib sequencer check configuration. + * You need to do this only one time in the life of the station. + */ +void +lib_seq_check_config_init (void); + +/** + * Initialize lib sequencer check. + * \param ctx the context to initialize + * \param cb the callback to use when there is an problem of sequence in the + * packet + * \param user an user pointer used when calling the callback + * + * This need to be done for each entry point to inspect. + */ +void +lib_seq_check_init (lib_seq_check_t *ctx, lib_seq_check_error_cb_t cb, + void *user); + +/** + * Data packet to inspect. + * \param ctx the context of lib seq check + * \param buffer the packet buffer + * \param len the packet length (in byte) + * \return true if there is a de-sequencing in the packet and callback was + * called, false otherwise (this include packets which can not be inspected). + */ +bool +lib_seq_check_packet (lib_seq_check_t *ctx, u8 *buffer, uint len); + +END_DECLS + +#else /* !CONFIG_SEQ_CHECK */ + +# define lib_seq_check_config_get() ((void) 0) +# define lib_seq_check_config_set() ((void) 0) +# define lib_seq_check_config_init() ((void) 0) +# define lib_seq_check_init(args...) ((void) 0) +# define lib_seq_check_packet(args...) ((void) 0) + +#endif /* !CONFIG_SEQ_CHECK */ + +#endif /* lib_seq_check_h */ diff --git a/cesar/lib/src/seq_check.c b/cesar/lib/src/seq_check.c new file mode 100644 index 0000000000..5b7d0a1e01 --- /dev/null +++ b/cesar/lib/src/seq_check.c @@ -0,0 +1,154 @@ +/* Cesar project {{{ + * + * Copyright (C) 2011 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file lib/src/seq_check.c + * \brief Check sequence number in data packets + * \ingroup lib + * + * + */ +#include "common/std.h" +#include "lib/bitstream.h" +#include "lib/swap.h" +#include "lib/stats.h" + +#include "config/seq/check/vlan/max.h" + +#include "lib/seq_check.h" + +/** + * Ethernet type VLAN ID. + */ +#define SEQ_CHECK_ET_VLAN 0x8100 + +lib_seq_check_config_t lib_seq_check_config; + +void +lib_seq_check_config_set (lib_seq_check_config_t *config) +{ + dbg_assert (config); + /* Set configuration. */ + lib_seq_check_config = *config; +} + +void +lib_seq_check_config_get (lib_seq_check_config_t *config) +{ + dbg_assert (config); + /* Get configuration. */ + *config = lib_seq_check_config; +} + +void +lib_seq_check_config_init (void) +{ + /* Set default configuration. */ + lib_seq_check_config_t config = + { + .seq_size = 16, + .seq_pos = 44, /* For IPerf. */ + .ethertype = SEQ_CHECK_ET_IP, /* No check for Ethernet type. */ + }; + lib_seq_check_config_set (&config); + + /* Register our configuration item. */ + lib_stats_set_stat_value_notype ("SEQ_CHECK_SEQ_POS", + &lib_seq_check_config.seq_pos, + LIB_STATS_ACCESS_READ_WRITE, + LIB_STATS_DEBUG); + lib_stats_set_stat_value_notype ("SEQ_CHECK_ETHERTYPE", + &lib_seq_check_config.ethertype, + LIB_STATS_ACCESS_READ_WRITE, + LIB_STATS_DEBUG); +} + +void +lib_seq_check_init (lib_seq_check_t *ctx, lib_seq_check_error_cb_t cb, + void *user) +{ + /* Check parameters. */ + dbg_assert (ctx); + dbg_assert (cb); + + uint i; + /* Initialize sequence number to 0. */ + for (i = 0; i < CONFIG_SEQ_CHECK_VLAN_MAX; i++) + { + ctx->seq[i] = 0; + } + ctx->cb = cb; + ctx->cb_user = user; +} + +bool +lib_seq_check_packet (lib_seq_check_t *ctx, u8 *buffer, uint len) +{ + /* Check parameter. */ + dbg_assert (ctx); + + bool result = false; + + /* Get Ethernet type (after SRC & DST MAC (6 bytes each)). */ + uint ethertype = swap16 (bitstream_direct_read (buffer, 6 * 8 * 2, 2 * + 8)); + + /* Position of sequence counter index in the table. */ + uint seq_index = 0; + + /* VLAN in used? */ + if (ethertype == SEQ_CHECK_ET_VLAN) + { + /* VLAN id on 12 bits. VLAN id is located after SRC & DST (6 bytes + * each) & VLAN/IEEE_802.1Q fields (TPID + PCP + CFI = 20 bits). But + * we can only get on 2 bytes. We need to get TCI field (PCP, CFI & + * VID). */ + seq_index = swap16 (bitstream_direct_read (buffer, (6 * 2 + 2) * 8, + 16)); + /* Remove PCP & CFI. */ + seq_index &= (0xFFFF >> 4); + dbg_assert (seq_index < CONFIG_SEQ_CHECK_VLAN_MAX); + + /* Get real Ethernet type, located after SRC & DST (6 bytes each) and + * VLAN/IEEE_802.1Q fields (4 bytes). */ + ethertype = swap16 (bitstream_direct_read (buffer, (6 + 6 + 4) * 8, + 2 * 8)); + } + + /* If this is the expected ethertype. */ + if (lib_seq_check_config.ethertype + && ethertype == lib_seq_check_config.ethertype) + { + + /* Get sequence value. */ + dbg_assert (lib_seq_check_config.seq_size == 16); + uint received_seq = swap16 ( + bitstream_direct_read (buffer, lib_seq_check_config.seq_pos * 8, + lib_seq_check_config.seq_size)); + + /* Handle overflow. */ + ctx->seq[seq_index] &= BITS_ONES (lib_seq_check_config.seq_size); + + /* Check. */ + if (ctx->seq[seq_index] != received_seq) + { + /* Call callback. */ + dbg_assert (ctx->cb); + (*ctx->cb) (ctx->cb_user, seq_index, ctx->seq[seq_index], + received_seq); + /* Reset. */ + ctx->seq[seq_index] = received_seq; + result = true; + } + + /* Increment. */ + ctx->seq[seq_index]++; + } + + /* Return result. */ + return result; +} diff --git a/cesar/lib/test/seq_check/Config b/cesar/lib/test/seq_check/Config new file mode 100644 index 0000000000..aab2ba7dab --- /dev/null +++ b/cesar/lib/test/seq_check/Config @@ -0,0 +1,2 @@ +CONFIG_SEQ_CHECK = y +CONFIG_STATS = n diff --git a/cesar/lib/test/seq_check/Makefile b/cesar/lib/test/seq_check/Makefile new file mode 100644 index 0000000000..a74fa304d6 --- /dev/null +++ b/cesar/lib/test/seq_check/Makefile @@ -0,0 +1,8 @@ +BASE = ../../.. + +HOST_PROGRAMS = test_seq_check + +test_seq_check_SOURCES = seq_check.c +test_seq_check_MODULES = lib + +include $(BASE)/common/make/top.mk diff --git a/cesar/lib/test/seq_check/src/seq_check.c b/cesar/lib/test/seq_check/src/seq_check.c new file mode 100644 index 0000000000..574f98f017 --- /dev/null +++ b/cesar/lib/test/seq_check/src/seq_check.c @@ -0,0 +1,250 @@ +/* Cesar project {{{ + * + * Copyright (C) 2011 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file lib/test/seq_check/src/seq_check.c + * \brief Sequence check test + * \ingroup test + * + * Test sequencer check. + */ +#include "common/std.h" + +#include "lib/test.h" +#include "lib/seq_check.h" +#include "common/defs/ethernet.h" +#include "lib/rnd.h" +#include "lib/bitstream.h" +#include "lib/swap.h" + +/* Test structure to use with the callback. */ +typedef struct test_seq_check_callback_t +{ + struct test_t *test; + bool cb_called; + uint vlan; + uint seq_expected; + uint seq_actual; +} test_seq_check_callback_t; + +void +test_seq_check_write_ethertype (u8 *p, u16 ethertype, bool vlan) +{ + /* Store ethertype. */ + uint pos = 6 * 2 * 8; + if (vlan) + { + bitstream_direct_write (p, pos, swap16 (0x8100), 16); + pos += 4 * 8; + } + bitstream_direct_write (p, pos, swap16 (ethertype), 16); +} + +void +test_seq_check_cb (void *user, uint vlan, uint seq_expected, uint seq_actual) +{ + dbg_assert (user); + test_seq_check_callback_t *test_seq_check_callback_values + = (test_seq_check_callback_t *) user; + + test_within (test_seq_check_callback_values->test); + test_fail_if (test_seq_check_callback_values->vlan != vlan); + test_fail_if (test_seq_check_callback_values->seq_expected != + seq_expected); + test_fail_if (test_seq_check_callback_values->seq_actual != seq_actual); + test_seq_check_callback_values->cb_called = true; +} + +void +test_seq_check_packet (test_t t, lib_rnd_t *rnd, uint pos, u16 ethertype) +{ + lib_seq_check_t s; + uint i; + u32 p[ETH_PACKET_MAX_SIZE]; + bool res; + test_seq_check_callback_t test_seq_check_callback_values; + test_seq_check_callback_values.test = t; + + /* Set configuration. */ + lib_seq_check_config_t conf; + lib_seq_check_config_get (&conf); + conf.seq_pos = pos; + conf.ethertype = ethertype; + lib_seq_check_config_set (&conf); + + test_begin (t, "config") + { + lib_seq_check_config_get (&conf); + test_fail_if (conf.seq_pos != pos); + test_fail_if (conf.ethertype != ethertype); + } test_end; + + test_begin (t, "init") + { + lib_seq_check_init (&s, test_seq_check_cb, + &test_seq_check_callback_values); + + for (i = 0; i < CONFIG_SEQ_CHECK_VLAN_MAX; i++) + { + test_fail_if (s.seq[i] != 0); + } + } test_end; + + test_begin (t, "good sequence") + { + /* Store ethertype. */ + test_seq_check_write_ethertype ((u8 *) p, ethertype, false); + for (i = 0; i < 1 << 16; i++) + { + bitstream_direct_write (p, pos * 8, swap16 (i), 16); + test_seq_check_callback_values.cb_called = false; + lib_seq_check_packet (&s, (u8 *) p, ETH_PACKET_MAX_SIZE); + test_fail_if (test_seq_check_callback_values.cb_called == true); + } + } test_end; + + test_begin (t, "good and bad sequence") + { + u16 seq, prev; + + /* Re-init. */ + lib_seq_check_init (&s, test_seq_check_cb, + &test_seq_check_callback_values); + /* Store ethertype. */ + test_seq_check_write_ethertype ((u8 *) p, ethertype, false); + for (seq = 0, i = 0; i < 1 << 16; i++, seq++) + { + if (lib_rnd_uniform (rnd, 2)) + res = true; + else + { + prev = seq; + seq = lib_rnd_uniform (rnd, 1 << 16); + if (seq == prev) + seq++; + test_seq_check_callback_values.vlan = 0; + test_seq_check_callback_values.seq_expected = prev; + test_seq_check_callback_values.seq_actual = seq; + res = false; + } + test_seq_check_callback_values.cb_called = false; + bitstream_direct_write (p, pos * 8, swap16 (seq), 16); + lib_seq_check_packet (&s, (u8 *) p, ETH_PACKET_MAX_SIZE); + test_fail_if (test_seq_check_callback_values.cb_called == res); + } + } test_end; + + test_begin (t, "good sequence with VLAN") + { + u16 seq[CONFIG_SEQ_CHECK_VLAN_MAX]; + + /* Re-init. */ + lib_seq_check_init (&s, test_seq_check_cb, + &test_seq_check_callback_values); + /* Store ethertype. */ + test_seq_check_write_ethertype ((u8 *) p, ethertype, true); + + for (i = 0; i < CONFIG_SEQ_CHECK_VLAN_MAX; i ++) + { + seq[i] = 0; + } + + for (i = 0; i < (1 << 16) * CONFIG_SEQ_CHECK_VLAN_MAX ; i++) + { + /* Get a random VLAN. */ + uint vlan = lib_rnd_uniform (rnd, CONFIG_SEQ_CHECK_VLAN_MAX); + /* Write VLAN. */ + bitstream_direct_write ((u8 *) p, 6 * 2 * 8 + 16, swap16 (vlan), + 16); + + test_seq_check_callback_values.cb_called = false; + bitstream_direct_write (p, pos * 8, swap16 (seq[vlan]), 16); + lib_seq_check_packet (&s, (u8 *) p, ETH_PACKET_MAX_SIZE); + test_fail_if (test_seq_check_callback_values.cb_called == true); + seq[vlan]++; + } + } test_end; + + test_begin (t, "good and bad sequence with VLAN") + { + u16 seq[CONFIG_SEQ_CHECK_VLAN_MAX], prev; + + /* Re-init. */ + lib_seq_check_init (&s, test_seq_check_cb, + &test_seq_check_callback_values); + /* Store ethertype. */ + test_seq_check_write_ethertype ((u8 *) p, ethertype, true); + + for (i = 0; i < CONFIG_SEQ_CHECK_VLAN_MAX; i ++) + { + seq[i] = 0; + } + + for (i = 0; i < (1 << 16) * CONFIG_SEQ_CHECK_VLAN_MAX ; i++) + { + /* Get a random VLAN. */ + uint vlan = lib_rnd_uniform (rnd, CONFIG_SEQ_CHECK_VLAN_MAX); + /* Write VLAN. */ + bitstream_direct_write ((u8 *) p, 6 * 2 * 8 + 16, swap16 (vlan), + 16); + + if (lib_rnd_uniform (rnd, 2)) + res = true; + else + { + prev = seq[vlan]; + seq[vlan] = lib_rnd_uniform (rnd, 1 << 16); + if (seq[vlan] == prev) + seq[vlan]++; + test_seq_check_callback_values.vlan = vlan; + test_seq_check_callback_values.seq_expected = prev; + test_seq_check_callback_values.seq_actual = seq[vlan]; + res = false; + } + test_seq_check_callback_values.cb_called = false; + bitstream_direct_write (p, pos * 8, swap16 (seq[vlan]), 16); + lib_seq_check_packet (&s, (u8 *) p, ETH_PACKET_MAX_SIZE); + test_fail_if (test_seq_check_callback_values.cb_called == res); + seq[vlan]++; + } + } test_end; +} + +int +main (int argc, char **argv) +{ + lib_rnd_t rnd; + test_t test; + + lib_rnd_init (&rnd, 0x42); + test_init (test, argc, argv); + + test_suite_begin (test, "sequence check"); + + lib_seq_check_config_init (); + + test_begin (test, "default config") + { + lib_seq_check_config_t conf; + lib_seq_check_config_get (&conf); + test_fail_if (conf.seq_size != 16); + test_fail_if (conf.seq_pos != 44); + test_fail_if (conf.ethertype != 0x8000); + } test_end; + + test_case_begin (test, "IPerf"); + /* Iperf position is at 44 and we check only IP packet. */ + test_seq_check_packet (test, &rnd, 44, 0x8000); + + test_case_begin (test, "Other"); + /* Iperf position is at 44 and we check only IP packet. */ + test_seq_check_packet (test, &rnd, 50, 0x8042); + + test_result (test); + return test_nb_failed (test); +} + diff --git a/cesar/station/src/station.c b/cesar/station/src/station.c index b4f9de332d..699ce01c53 100644 --- a/cesar/station/src/station.c +++ b/cesar/station/src/station.c @@ -24,6 +24,8 @@ # include "hal/leon/fatal_button.h" #endif +#include "lib/seq_check.h" + #include "lib/init.h" /** Static declaration. */ @@ -44,6 +46,8 @@ cesar_init (void) lib_stats_init (); + lib_seq_check_config_init (); + /* Initialise the mac store. */ cesar.mac_store = mac_store_init (); -- cgit v1.2.3 From 6fc4e40d0cc77bee4b28f7100221cc222a865aef Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Wed, 13 Jul 2011 16:18:28 +0200 Subject: cesar/{cl,hle,mac/sar}: integrate lib seq_check in i/o points, refs #2644 Sequences numbers are checked when data packets enter in Cesar from PLC or Linux and when exit from Cesar by PLC or Linux. --- cesar/cl/inc/context.h | 4 ++++ cesar/cl/inc/trace.h | 1 + cesar/cl/src/cl.c | 27 +++++++++++++++++++++ cesar/cl/src/trace.c | 2 ++ cesar/hle/inc/context.h | 6 +++++ cesar/hle/inc/trace.h | 4 +++- cesar/hle/src/hle.c | 53 +++++++++++++++++++++++++++++++++++++++++ cesar/hle/src/trace.c | 4 ++++ cesar/mac/sar/inc/sar_context.h | 4 ++++ cesar/mac/sar/inc/trace.h | 1 + cesar/mac/sar/src/sar.c | 26 ++++++++++++++++++++ cesar/mac/sar/src/trace.c | 2 ++ 12 files changed, 133 insertions(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/cl/inc/context.h b/cesar/cl/inc/context.h index 954e101e08..9372864dea 100644 --- a/cesar/cl/inc/context.h +++ b/cesar/cl/inc/context.h @@ -17,6 +17,7 @@ #include "common/defs/ethernet.h" #include "lib/slab.h" +#include "lib/seq_check.h" #include "mac/common/mfs.h" #include "mac/common/store.h" #include "mac/common/config.h" @@ -161,6 +162,9 @@ struct cl_t /** cl Trace */ trace_buffer_t trace; #endif /* !CONFIG_TRACE */ +#if CONFIG_SEQ_CHECK + lib_seq_check_t seq_check_rx_ctx; +#endif }; #endif /* CL_INC_CONTEXT_H_ */ diff --git a/cesar/cl/inc/trace.h b/cesar/cl/inc/trace.h index e312a292f6..7192677e7c 100644 --- a/cesar/cl/inc/trace.h +++ b/cesar/cl/inc/trace.h @@ -47,6 +47,7 @@ enum CL_TRACE_DATA_RECV, CL_TRACE_DATA_BUFFER_ADD, CL_TRACE_BRIDGE_ADD, + CL_TRACE_SEQ_CHECK, }; BEGIN_DECLS diff --git a/cesar/cl/src/cl.c b/cesar/cl/src/cl.c index 2bf20c5798..09cb93aa33 100644 --- a/cesar/cl/src/cl.c +++ b/cesar/cl/src/cl.c @@ -15,6 +15,7 @@ #include "common/std.h" #include "common/defs/ethernet.h" #include "lib/bitstream.h" +#include "lib/seq_check.h" #include "config/cl.h" #include "cl/cl.h" @@ -40,6 +41,26 @@ static struct cl_t cl_global; +/** + * Callback when the lib sequencer detect a wrong sequencing. + * \param user user data + * \param vlan the VLAN id + * \param seq_expected the sequence number expected + * \param seq_actual the actual sequence number found in the packet + */ +void +cl_lib_seq_check_cb (void *user, uint vlan, uint seq_expected, + uint seq_actual); + +void +cl_lib_seq_check_cb (void *user, uint vlan, uint seq_expected, + uint seq_actual) +{ + dbg_assert (user); + trace_do (cl_t *ctx = (cl_t *) user); + CL_TRACE (SEQ_CHECK, vlan, seq_expected, seq_actual); +} + /** * Search for the lid in the classifier * @@ -287,6 +308,9 @@ cl_init (mac_store_t *mac_store, sar_t *sar, mac_config_t *mac_config) CL_TRACE (INIT, phy_date ()); + /* Initialise packet sequence check. */ + lib_seq_check_init (&ctx->seq_check_rx_ctx, cl_lib_seq_check_cb, ctx); + /* Debug leds. */ GPIO_SETUP (LED_CL_RX, GPIO_DIRECTION_OUT); GPIO_SET (LED_CL_RX, 0); @@ -917,6 +941,9 @@ void cl_data_recv (cl_t *ctx, u8 *buffer, uint length, mfs_rx_t *mfs) && (length <= ETH_PACKET_MAX_SIZE)); dbg_assert (mfs); + /* Check sequence number of throughput. */ + lib_seq_check_packet (&ctx->seq_check_rx_ctx, buffer, length); + dbg_assert (ctx->data_rx.cb); mac_t smac, dmac; diff --git a/cesar/cl/src/trace.c b/cesar/cl/src/trace.c index 9ad0392a54..758caa7561 100644 --- a/cesar/cl/src/trace.c +++ b/cesar/cl/src/trace.c @@ -52,6 +52,8 @@ cl_trace_init (cl_t *ctx) TRACE_EVENT (CL_TRACE_DATA_RECV, "CL_DATA_RECV buffer @ : %x, destination : %m, source : %m, length : %d", TIMESTAMP), TRACE_EVENT (CL_TRACE_DATA_BUFFER_ADD, "CL_DATA_BUFFER_ADD buffer @ : %x", TIMESTAMP), TRACE_EVENT (CL_TRACE_BRIDGE_ADD, "Bridging MAC %m"), + TRACE_EVENT (CL_TRACE_SEQ_CHECK, "[SeqCheck] input from PLC: " + "[%02d] expected=%04X, actual=%04X"), }; dbg_assert (ctx); trace_namespace_init (&namespace, event_ids, COUNT (event_ids)); diff --git a/cesar/hle/inc/context.h b/cesar/hle/inc/context.h index 9c8fb18893..8681744177 100644 --- a/cesar/hle/inc/context.h +++ b/cesar/hle/inc/context.h @@ -15,6 +15,7 @@ */ #include "lib/trace.h" +#include "lib/seq_check.h" #include "cl/cl.h" @@ -51,6 +52,11 @@ struct hle_t /** HLE Trace */ trace_buffer_t trace; #endif /* !CONFIG_TRACE */ +#if CONFIG_SEQ_CHECK + /** Sequence check. */ + lib_seq_check_t seq_in; + lib_seq_check_t seq_out; +#endif }; #endif /* hle_inc_context_h */ diff --git a/cesar/hle/inc/trace.h b/cesar/hle/inc/trace.h index 29ba7ec8c1..185b9be4d9 100644 --- a/cesar/hle/inc/trace.h +++ b/cesar/hle/inc/trace.h @@ -34,7 +34,9 @@ enum HLE_TRACE_MME_SEND, HLE_TRACE_MME_RECV, HLE_TRACE_IPMBOX, - HLE_TRACE_DROPPED + HLE_TRACE_DROPPED, + HLE_TRACE_SEQ_CHECK_IN, + HLE_TRACE_SEQ_CHECK_OUT, }; BEGIN_DECLS diff --git a/cesar/hle/src/hle.c b/cesar/hle/src/hle.c index 6daf46ff00..c324365518 100644 --- a/cesar/hle/src/hle.c +++ b/cesar/hle/src/hle.c @@ -20,12 +20,55 @@ #include "hle/inc/context.h" #include "hle/inc/trace.h" #include "mac/common/ntb.h" +#include "lib/seq_check.h" #include "common/module.h" /** Hle global context */ static hle_t hle_global; +/** + * Callback when the lib sequencer detect a wrong sequencing, input from + * Linux. + * \param user user data + * \param vlan the VLAN id + * \param seq_expected the sequence number expected + * \param seq_actual the actual sequence number found in the packet + */ +void +hle_lib_seq_check_cb_in (void *user, uint vlan, uint seq_expected, + uint seq_actual); + +/** + * Callback when the lib sequencer detect a wrong sequencing, output to + * Linux. + * \param user user data + * \param vlan the VLAN id + * \param seq_expected the sequence number expected + * \param seq_actual the actual sequence number found in the packet + */ +void +hle_lib_seq_check_cb_out (void *user, uint vlan, uint seq_expected, + uint seq_actual); + +void +hle_lib_seq_check_cb_in (void *user, uint vlan, uint seq_expected, + uint seq_actual) +{ + dbg_assert (user); + trace_do (hle_t *ctx = (hle_t *) user); + HLE_TRACE (SEQ_CHECK_IN, vlan, seq_expected, seq_actual); +} + +void +hle_lib_seq_check_cb_out (void *user, uint vlan, uint seq_expected, + uint seq_actual) +{ + dbg_assert (user); + trace_do (hle_t *ctx = (hle_t *) user); + HLE_TRACE (SEQ_CHECK_OUT, vlan, seq_expected, seq_actual); +} + /** * Send a data to the Convergence Layer to be sent over the PWL. * \param hle the hle context. @@ -41,6 +84,10 @@ hle_data_send (hle_t *ctx, u8 *buffer, uint length, uint tag, dbg_assert (ctx); dbg_assert (buffer); dbg_assert (length <= ETH_PACKET_MAX_SIZE); + + /* Check sequence. */ + lib_seq_check_packet (&ctx->seq_in, buffer, length); + if (length < ETH_PACKET_MIN_SIZE_ALLOWED) { hle_send_done (ctx, buffer); @@ -70,6 +117,9 @@ hle_data_recv (hle_t *ctx, u8 *buffer, uint length) /* Tracing data. */ HLE_TRACE (DATA_RECV, phy_date (), length, buffer); + /* Check sequence. */ + lib_seq_check_packet (&ctx->seq_out, buffer, length); + word[0] = BF_FILL (IPMBOX_REG, (MSG_TYPE, HLE_MSG_TYPE_DATA), (MSG_LENGTH, 1), (PARAM_MSG_TYPE, 0), (PARAM_MSG_LENGTH, length)); @@ -250,6 +300,9 @@ hle_init (cl_t *cl) #endif /* Tracing */ HLE_TRACE (INIT, phy_date ()); + /* Sequence check initialization. */ + lib_seq_check_init (&ctx->seq_in, hle_lib_seq_check_cb_in, &hle_global); + lib_seq_check_init (&ctx->seq_out, hle_lib_seq_check_cb_out, &hle_global); return &hle_global; } diff --git a/cesar/hle/src/trace.c b/cesar/hle/src/trace.c index 0945e876b4..630d4500e2 100644 --- a/cesar/hle/src/trace.c +++ b/cesar/hle/src/trace.c @@ -38,6 +38,10 @@ hle_trace_init (hle_t *ctx) TRACE_EVENT (HLE_TRACE_MME_RECV, "HLE_MME_RECV length : %d, buffer @ : %x", TIMESTAMP), TRACE_EVENT (HLE_TRACE_IPMBOX, "HLE_IPMBOX_ACTIVATE avctive : %d", TIMESTAMP), TRACE_EVENT (HLE_TRACE_DROPPED, "HLE_MSG DROPPED data: %d, length: %d, buffer: %x", TIMESTAMP), + TRACE_EVENT (HLE_TRACE_SEQ_CHECK_IN, "[SeqCheck] input from linux: " + "[%02d] expected=%04X, actual=%04X"), + TRACE_EVENT (HLE_TRACE_SEQ_CHECK_OUT, "[SeqCheck] output to linux: " + "[%02d] expected=%04X, actual=%04X"), }; dbg_assert (ctx); trace_namespace_init (&namespace, event_ids, COUNT (event_ids)); diff --git a/cesar/mac/sar/inc/sar_context.h b/cesar/mac/sar/inc/sar_context.h index d7d85586bd..4c0f8b6fd9 100644 --- a/cesar/mac/sar/inc/sar_context.h +++ b/cesar/mac/sar/inc/sar_context.h @@ -17,6 +17,7 @@ #include "mac/pbproc/pbproc.h" #include "lib/slist.h" #include "lib/rnd.h" +#include "lib/seq_check.h" #include "hal/phy/bridgedma.h" #ifdef STATION_H_ @@ -191,6 +192,9 @@ struct sar_t #if CONFIG_STATS sar_stats_t stats; #endif +#if CONFIG_SEQ_CHECK + lib_seq_check_t seq; +#endif }; #endif /*SAR_CONTEXT_H_*/ diff --git a/cesar/mac/sar/inc/trace.h b/cesar/mac/sar/inc/trace.h index 93ce021c61..ebd8af078c 100644 --- a/cesar/mac/sar/inc/trace.h +++ b/cesar/mac/sar/inc/trace.h @@ -43,6 +43,7 @@ enum SAR_TRACE_PB_TX_RELEASE, SAR_TRACE_PB_RX_RELEASE, SAR_TRACE_EXHAUSTED_MEMORY, + SAR_TRACE_SEQ_CHECK, }; BEGIN_DECLS diff --git a/cesar/mac/sar/src/sar.c b/cesar/mac/sar/src/sar.c index f3c122df17..4edf0ccb52 100644 --- a/cesar/mac/sar/src/sar.c +++ b/cesar/mac/sar/src/sar.c @@ -24,6 +24,7 @@ #include "mac/sar/inc/sar_context.h" #include "mac/sar/inc/sar.h" #include "mac/sar/inc/sar_expiration.h" +#include "lib/seq_check.h" #include "hal/arch/arch.h" #include "common/defs/priority.h" @@ -51,6 +52,26 @@ static struct sar_t sar_global; +/** + * Callback when the lib sequencer detect a wrong sequencing. + * \param user user data + * \param vlan the VLAN id + * \param seq_expected the sequence number expected + * \param seq_actual the actual sequence number found in the packet + */ +void +sar_lib_seq_check_cb (void *user, uint vlan, uint seq_expected, + uint seq_actual); + +void +sar_lib_seq_check_cb (void *user, uint vlan, uint seq_expected, + uint seq_actual) +{ + dbg_assert (user); + trace_do (sar_t *ctx = (sar_t *) user); + SAR_TRACE (SEQ_CHECK, vlan, seq_expected, seq_actual); +} + /** * Compute the gap between two SSNs. * \param a the first SSN, @@ -493,6 +514,8 @@ sar_init (mac_store_t *mac_store, pbproc_t *pbproc, ca_t *ca, u32 seed) /** Trace system. */ ctx = &sar_global; sar_trace_init(ctx); + /* Initialize sequence checker. */ + lib_seq_check_init (&ctx->seq, sar_lib_seq_check_cb, &sar_global); #if CONFIG_STATS sar_stats_init (&ctx->stats); #endif @@ -812,6 +835,9 @@ sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length, mfs_tx_t *mfs, mfs->stats.num_msdus ++; mfs->stats.octets += length; + /* Check sequence. */ + lib_seq_check_packet (&ctx->seq, buffer, length); + /* Enough block available to send a frame and SAR is activated ? */ if (ctx->activate && (blk_slack () || mfs->seg_nb <= MAC_SAR_EM_MAX_PB_ALLOWED)) diff --git a/cesar/mac/sar/src/trace.c b/cesar/mac/sar/src/trace.c index 43ea366ac2..ea2b4aad26 100644 --- a/cesar/mac/sar/src/trace.c +++ b/cesar/mac/sar/src/trace.c @@ -51,6 +51,8 @@ sar_trace_init (sar_t *ctx) "PB expire ssn %d in mfs : %x"), TRACE_EVENT (SAR_TRACE_EXHAUSTED_MEMORY, "exhausted memory, Frame drop from SSN %d to %d"), + TRACE_EVENT (SAR_TRACE_SEQ_CHECK, "[SeqCheck] output to PLC: " + "[%02d] expected=%04X, actual=%04X"), }; dbg_assert (ctx); trace_namespace_init (&namespace, event_ids, COUNT (event_ids)); -- cgit v1.2.3 From 312e093208777de66cbc084c3bfc3dd710cfcd61 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Thu, 12 May 2011 14:23:18 +0200 Subject: cesar/cp, cesar/hal/phy, cesar/mac/pbproc: use delta external, refs #572 When frequency error is known, use external delta. This means: - RESYS program must be patched, - change delta accumulation coefficients register, - store computed delta in hardware register. --- cesar/cp/beacon/src/beacon.c | 8 ++-- cesar/cp/beacon/test/src/phy_stub.c | 2 +- cesar/hal/phy/Module | 59 +++++++++++++++++------- cesar/hal/phy/inc/context.h | 2 + cesar/hal/phy/inc/phy_params.txt | 3 +- cesar/hal/phy/inc/regs.h | 1 + cesar/hal/phy/inc/resys.h | 8 ++++ cesar/hal/phy/phy.h | 12 +++++ cesar/hal/phy/src/phy.c | 37 ++++++++++++++- cesar/hal/phy/src/resys.c | 34 ++++++++++++++ cesar/hal/phy/src/resys/Hex.pm | 34 ++++++++++++++ cesar/hal/phy/src/resys/hex2c.pl | 27 ++--------- cesar/hal/phy/src/resys/hexpatch2c.pl | 22 +++++++++ cesar/hal/phy/src/resys/prog_resys.txt | 30 ++++++------ cesar/hal/phy/src/resys/resys_compil.pl | 12 +++++ cesar/mac/pbproc/inc/context.h | 2 + cesar/mac/pbproc/pbproc.h | 6 ++- cesar/mac/pbproc/src/pbproc.c | 10 ++-- cesar/mac/pbproc/src/trace.c | 2 +- cesar/mac/pbproc/test/pbproc/inc/scenario_defs.h | 7 +++ cesar/mac/pbproc/test/pbproc/src/phy.c | 8 ++++ cesar/mac/pbproc/test/pbproc/src/tx_data.c | 5 +- 22 files changed, 262 insertions(+), 69 deletions(-) create mode 100644 cesar/hal/phy/src/resys/Hex.pm create mode 100644 cesar/hal/phy/src/resys/hexpatch2c.pl (limited to 'cesar') diff --git a/cesar/cp/beacon/src/beacon.c b/cesar/cp/beacon/src/beacon.c index c8bbff9e15..1ca8b03c64 100644 --- a/cesar/cp/beacon/src/beacon.c +++ b/cesar/cp/beacon/src/beacon.c @@ -88,13 +88,13 @@ cp_beacon_fill_discover_info (cp_t *ctx, } static void -cp_beacon_clk_sync_call_spoc (cp_t *ctx, u32 fe) +cp_beacon_clk_sync_call_spoc (cp_t *ctx, bool sync, u32 fe) { dbg_assert (ctx); phy_spoc_coeff_t *coeff = blk_alloc (); coeff->part2 = blk_alloc(); phy_spoc_compute_all (fe, coeff); - pbproc_spoc_coeff_set (ctx->pbproc, coeff); + pbproc_spoc_coeff_set (ctx->pbproc, sync, coeff); } void @@ -654,7 +654,7 @@ cp_beacon_process_beacon_central ( ctx->beacon.spoc_update_date, phy_date ())) { cp_beacon_clk_sync_call_spoc ( - ctx, beacon->params.frequency_error); + ctx, true, beacon->params.frequency_error); ctx->beacon.spoc_update_date = phy_date () + MAC_MS_TO_TCK (ctx->beacon.spoc_update_interval_ms); ctx->beacon.spoc_updated = true; @@ -902,7 +902,7 @@ cp_beacon_process_untracked_avln (cp_t *ctx) own->cco_mac_addr_track = MAC_ZERO; /* Reset SPOC. */ ctx->beacon.spoc_updated = false; - cp_beacon_clk_sync_call_spoc (ctx, 0); + cp_beacon_clk_sync_call_spoc (ctx, false, 0); /* Inform BSU. */ bsu_untrack_avln (ctx->bsu); } diff --git a/cesar/cp/beacon/test/src/phy_stub.c b/cesar/cp/beacon/test/src/phy_stub.c index 0e04f43ff8..cfd499e743 100644 --- a/cesar/cp/beacon/test/src/phy_stub.c +++ b/cesar/cp/beacon/test/src/phy_stub.c @@ -31,7 +31,7 @@ phy_date () } void -pbproc_spoc_coeff_set (pbproc_t *pbproc, phy_spoc_coeff_t *coeff) +pbproc_spoc_coeff_set (pbproc_t *pbproc, bool sync, phy_spoc_coeff_t *coeff) { dbg_assert (coeff); diff --git a/cesar/hal/phy/Module b/cesar/hal/phy/Module index 3b26f31c6d..f408a8bf65 100644 --- a/cesar/hal/phy/Module +++ b/cesar/hal/phy/Module @@ -9,54 +9,81 @@ ifndef $(MODULE_VAR)_ONCE $(MODULE_VAR)_ONCE = 1 hal_phy_resys_prog_h = $(OBJ_DIR)/inc/hal_phy_resys_prog.h +hal_phy_resys_prog_patch_h = $(OBJ_DIR)/inc/hal_phy_resys_prog_patch.h hal_phy_resys_offsettable_h = $(OBJ_DIR)/inc/hal_phy_resys_offsettable.h hal_phy_resys_labels_h = $(OBJ_DIR)/inc/hal_phy_resys_labels.h hal_phy_params_h = $(OBJ_DIR)/inc/hal_phy_params.h -CLEAN_FILES += $(hal_phy_resys_prog_h) $(hal_phy_resys_offsettable_h) \ +CLEAN_FILES += $(hal_phy_resys_prog_h) $(hal_phy_resys_prog_patch_h) \ + $(hal_phy_resys_offsettable_h) \ $(hal_phy_resys_labels_h) $(hal_phy_params_h) COMPILE_DEPS += $(hal_phy_resys_labels_h) $(hal_phy_params_h) -hal_phy_resys_prog_hex = $(OBJ_DIR)/resys_mem.hex -hal_phy_resys_prog_dis = $(OBJ_DIR)/resys_mem.dis +hal_phy_resys_prog_di_hex = $(OBJ_DIR)/resys_mem_di.hex +hal_phy_resys_prog_di_dis = $(OBJ_DIR)/resys_mem_di.dis +hal_phy_resys_prog_de_hex = $(OBJ_DIR)/resys_mem_de.hex +hal_phy_resys_prog_de_dis = $(OBJ_DIR)/resys_mem_de.dis hal_phy_resys_offsettable_hex = $(OBJ_DIR)/offsettable_mem.hex hal_phy_hex2c = $(call src2src,hex2c.pl,hal/phy/src/resys) +hal_phy_hexpatch2c = $(call src2src,hexpatch2c.pl,hal/phy/src/resys) hal_phy_resys_labels = $(call src2src,resys_labels.pl,hal/phy/src/resys) -CLEAN_FILES += $(hal_phy_resys_prog_hex) $(hal_phy_resys_prog_dis) \ +hal_phy_perl_lib = -I$(BASE)/$(call src2src,src/resys,hal/phy) +CLEAN_FILES += $(hal_phy_resys_prog_di_hex) $(hal_phy_resys_prog_di_dis) \ + $(hal_phy_resys_prog_de_hex) $(hal_phy_resys_prog_de_dis) \ $(hal_phy_resys_offsettable_hex) vpath $(hal_phy_hex2c) $(BASE) +vpath $(hal_phy_hexpatch2c) $(BASE) vpath $(hal_phy_resys_labels) $(BASE) -$(hal_phy_resys_prog_h): $(hal_phy_hex2c) $(hal_phy_resys_prog_hex) \ +$(hal_phy_resys_prog_h): $(hal_phy_hex2c) \ + $(hal_phy_resys_prog_di_hex) | $(OBJ_INC_DIR_STAMP) + perl $(hal_phy_perl_lib) $^ > $@ + +$(hal_phy_resys_prog_patch_h): $(hal_phy_hexpatch2c) \ + $(hal_phy_resys_prog_di_hex) $(hal_phy_resys_prog_de_hex) \ | $(OBJ_INC_DIR_STAMP) - perl $^ > $@ + perl $(hal_phy_perl_lib) $^ > $@ $(hal_phy_resys_offsettable_h): $(hal_phy_hex2c) \ $(hal_phy_resys_offsettable_hex) | $(OBJ_INC_DIR_STAMP) - perl $^ > $@ + perl $(hal_phy_perl_lib) $^ > $@ -$(hal_phy_resys_labels_h): $(hal_phy_resys_labels) $(hal_phy_resys_prog_dis) \ - | $(OBJ_INC_DIR_STAMP) +$(hal_phy_resys_labels_h): $(hal_phy_resys_labels) \ + $(hal_phy_resys_prog_di_dis) | $(OBJ_INC_DIR_STAMP) perl $^ > $@ -hal_phy_parasites = $(OBJ_DIR)/resys_mem.tsmc \ - $(OBJ_DIR)/resys_mem.readmemh \ +hal_phy_parasites = $(OBJ_DIR)/resys_mem_di.tsmc \ + $(OBJ_DIR)/resys_mem_di.readmemh \ + $(OBJ_DIR)/resys_mem_de.tsmc \ + $(OBJ_DIR)/resys_mem_de.readmemh \ $(OBJ_DIR)/offsettable_mem.tsmc \ $(OBJ_DIR)/offsettable_mem.dis \ - $(OBJ_DIR)/offsettable_mem.readmemh + $(OBJ_DIR)/offsettable_mem.readmemh \ + $(OBJ_DIR)/offsettable_mem_de.hex \ + $(OBJ_DIR)/offsettable_mem_de.tsmc \ + $(OBJ_DIR)/offsettable_mem_de.dis \ + $(OBJ_DIR)/offsettable_mem_de.readmemh CLEAN_FILES += $(hal_phy_parasites) vpath %/resys_compil.pl $(BASE) vpath %/prog_resys.txt $(BASE) vpath %/resys_offsettable.txt $(BASE) -$(hal_phy_resys_prog_hex) $(hal_phy_resys_offsettable_hex): \ +$(hal_phy_resys_prog_di_hex): \ + $(call src2src,resys_compil.pl prog_resys.txt \ + resys_offsettable.txt,hal/phy/src/resys) + perl $^ --delta-internal -B $(OBJ_DIR) -D $(OBJ_DIR) \ + resys_mem_di offsettable_mem > /dev/null + +$(hal_phy_resys_prog_de_hex): \ $(call src2src,resys_compil.pl prog_resys.txt \ resys_offsettable.txt,hal/phy/src/resys) - perl $^ -B $(OBJ_DIR) -D $(OBJ_DIR) > /dev/null + perl $^ --delta-external -B $(OBJ_DIR) -D $(OBJ_DIR) \ + resys_mem_de offsettable_mem_de > /dev/null -$(hal_phy_resys_prog_dis): $(hal_phy_resys_prog_hex) +$(hal_phy_resys_prog_di_dis): $(hal_phy_resys_prog_di_hex) +$(hal_phy_resys_offsettable_hex): $(hal_phy_resys_prog_di_hex) hal_phy_params_txt = $(call src2src,phy_params.txt,hal/phy/inc) @@ -70,4 +97,4 @@ $(hal_phy_params_h): $(call src2src,phy_params.pl,hal/phy/src) \ endif $(call src2obj,hal/phy/src/resys.c,$(BUILD_TYPE)): $(hal_phy_resys_prog_h) \ -$(hal_phy_resys_offsettable_h) +$(hal_phy_resys_prog_patch_h) $(hal_phy_resys_offsettable_h) diff --git a/cesar/hal/phy/inc/context.h b/cesar/hal/phy/inc/context.h index ee999c7f54..0a21e76b77 100644 --- a/cesar/hal/phy/inc/context.h +++ b/cesar/hal/phy/inc/context.h @@ -70,6 +70,8 @@ struct phy_t uint resys_gil_table[PHY_GIL_NB]; /** Start PBDMA on RESYS interrupt. */ bool pbdma_start_on_resys_it; + /** Whether frequency error is synchronised. */ + bool freq_error_sync; /** CAP activation mask. */ u8 cap_mask; /** Phy stats. */ diff --git a/cesar/hal/phy/inc/phy_params.txt b/cesar/hal/phy/inc/phy_params.txt index a82fd6a67d..81b7e02324 100644 --- a/cesar/hal/phy/inc/phy_params.txt +++ b/cesar/hal/phy/inc/phy_params.txt @@ -10,7 +10,8 @@ rx_fec_param__tcc_dyn_stop = 1 rx_fec_param__tcc_ber_period = 1 rx_fec_param__tcc_threshold = 0 channel_estim_coef__coef_preamble = 0 -channel_estim_coef__coef_res_delta = 32 +channel_estim_coef__coef_res_delta_internal = 32 +channel_estim_coef__coef_res_delta_external = 26 resys_threshold__nb_syncp_1 = 1995 resys_threshold__nb_syncp_2 = 2379 detect_param_1__lambda = 49152 diff --git a/cesar/hal/phy/inc/regs.h b/cesar/hal/phy/inc/regs.h index 8d5934a609..fb38df84ae 100644 --- a/cesar/hal/phy/inc/regs.h +++ b/cesar/hal/phy/inc/regs.h @@ -272,6 +272,7 @@ typedef u32 uint32_t; /* PHY_DSPSS_MACACKE_DELTA_USED */ #define PHY_DSPSS_MACACKE_DELTA_USED__VALUE 16, 0 #define PHY_DSPSS_MACACKE_DELTA_USED__INTERNAL 24, 24 +# define PHY_DSPSS_MACACKE_DELTA_USED__VALUE__RHO_Q 27 /* TX_GUARD_LENGTH */ # define PHY_DSPSS_TX_GUARD_LENGTH__VALUE_FC_10 192 diff --git a/cesar/hal/phy/inc/resys.h b/cesar/hal/phy/inc/resys.h index f40037accc..dc29b21228 100644 --- a/cesar/hal/phy/inc/resys.h +++ b/cesar/hal/phy/inc/resys.h @@ -20,4 +20,12 @@ void phy_resys_load (phy_t *ctx); +/** + * Patch RESYS program to switch between internal or external program. + * \param ctx phy context + * \param external true for external program + */ +void +phy_resys_patch (phy_t *ctx, bool external); + #endif /* hal_phy_inc_resys_h */ diff --git a/cesar/hal/phy/phy.h b/cesar/hal/phy/phy.h index 161dafb24f..66f1a3156b 100644 --- a/cesar/hal/phy/phy.h +++ b/cesar/hal/phy/phy.h @@ -189,6 +189,18 @@ phy_clock_get_zero_cross_captured_sysdate (phy_t *ctx); void phy_set_tonemap (phy_t *ctx, blk_t *tonemap); +/** + * Set frequency error in hardware. + * \param ctx phy context + * \param sync whether error is synchronised + * \param rho_q30 frequency error, see SPOC + * + * If error is synchronised, delta used by hardware will be fixed for preamble + * and FC. In the other case, hardware will try to determine it itself. + */ +void +phy_freq_error_set (phy_t *ctx, bool sync, s32 rho_q30); + /** * Start Homeplug 1.0 frame control encoding. * \param ctx phy context diff --git a/cesar/hal/phy/src/phy.c b/cesar/hal/phy/src/phy.c index c8e1ee5dcb..f4ce010a2f 100644 --- a/cesar/hal/phy/src/phy.c +++ b/cesar/hal/phy/src/phy.c @@ -31,6 +31,7 @@ #include "config/phy/cap.h" #include "lib/stats.h" +#include "lib/fixed.h" #include @@ -550,7 +551,10 @@ phy_init (void *user_data, phy_rx_fc_cb_t rx_fc_cb, phy_access_cb_t access_cb, (TCC_HALF_IT_DATA, PHY_PARAM_RX_FEC_PARAM__TCC_HALF_IT_DATA_LAST_PB)); PHY_DSPSS_CHANNEL_ESTIM_COEF = PHY_PARAMS (PHY_DSPSS, CHANNEL_ESTIM_COEF, - COEF_PREAMBLE, COEF_RES_DELTA); + COEF_PREAMBLE) + | BF_FILL (PHY_DSPSS_CHANNEL_ESTIM_COEF, + (COEF_RES_DELTA, + PHY_PARAM_CHANNEL_ESTIM_COEF__COEF_RES_DELTA_INTERNAL)); PHY_DSPSS_RESYS_THRESHOLD = PHY_PARAMS (PHY_DSPSS, RESYS_THRESHOLD, NB_SYNCP_1, NB_SYNCP_2); PHY_DSPSS_OSYSEQ_CONFIG = @@ -965,3 +969,34 @@ phy_set_tonemap (phy_t *ctx, blk_t *tonemap) dbg_assert (timeout); } +void +phy_freq_error_set (phy_t *ctx, bool sync, s32 rho_q30) +{ + dbg_claim (ctx); + if (sync != ctx->freq_error_sync) + { + if (sync) + { + PHY_DSPSS_CHANNEL_ESTIM_COEF = + PHY_PARAMS (PHY_DSPSS, CHANNEL_ESTIM_COEF, COEF_PREAMBLE) + | BF_FILL ( + PHY_DSPSS_CHANNEL_ESTIM_COEF, + (COEF_RES_DELTA, + PHY_PARAM_CHANNEL_ESTIM_COEF__COEF_RES_DELTA_EXTERNAL)); + } + else + { + PHY_DSPSS_CHANNEL_ESTIM_COEF = + PHY_PARAMS (PHY_DSPSS, CHANNEL_ESTIM_COEF, COEF_PREAMBLE) + | BF_FILL ( + PHY_DSPSS_CHANNEL_ESTIM_COEF, + (COEF_RES_DELTA, + PHY_PARAM_CHANNEL_ESTIM_COEF__COEF_RES_DELTA_INTERNAL)); + } + phy_resys_patch (ctx, sync); + ctx->freq_error_sync = sync; + } + PHY_DSPSS_MACACKE_DELTA_USED = fixed_round ( + -rho_q30, 30 - PHY_DSPSS_MACACKE_DELTA_USED__VALUE__RHO_Q); +} + diff --git a/cesar/hal/phy/src/resys.c b/cesar/hal/phy/src/resys.c index bb954fdf7b..95c280bb13 100644 --- a/cesar/hal/phy/src/resys.c +++ b/cesar/hal/phy/src/resys.c @@ -16,6 +16,8 @@ #include "inc/regs.h" #include "inc/resys.h" +#include "hal_phy_resys_labels.h" + /** RESYS program. */ static const u16 resys_prog[] = { #include "hal_phy_resys_prog.h" @@ -26,6 +28,12 @@ static const u16 resys_offsettable[] = { #include "hal_phy_resys_offsettable.h" }; +/** RESYS program patch for internal/external switch. */ +static const u16 resys_prog_patch[][3] = { + /* { index, internal value, external value } */ +#include "hal_phy_resys_prog_patch.h" +}; + /** * Load RESYS memories. * \param ctx phy context @@ -42,3 +50,29 @@ phy_resys_load (phy_t *ctx) for (i = 0; i < COUNT (resys_offsettable); i++) reg[i] = resys_offsettable[i]; } + +void +phy_resys_patch (phy_t *ctx, bool external) +{ + uint i; + volatile u32 *reg; + dbg_assert (ctx); + uint col = external ? 2 : 1; + /* Freeze RESYS. */ + PHY_DSPSS_RESYS_PARAM = BF_FILL (PHY_DSPSS_RESYS_PARAM, + (RESYS_COND, 0), + (RESYS_ON, 1), + (RESYS_FREEZE, 1)); + dbg_assert (PHY_DSPSS_RESYS_EXE_INSTR_ADDR + == PHY_RESYS_LABEL_WAIT_PRE); + /* Patch RESYS code. */ + reg = &PHY_BASE_ADDR_RESYS_PROG; + for (i = 0; i < COUNT (resys_prog_patch); i++) + reg[resys_prog_patch[i][0]] = resys_prog_patch[i][col]; + /* Unfreeze RESYS. */ + PHY_DSPSS_RESYS_PARAM = BF_FILL (PHY_DSPSS_RESYS_PARAM, + (RESYS_COND, 0), + (RESYS_ON, 1), + (RESYS_FREEZE, 0)); +} + diff --git a/cesar/hal/phy/src/resys/Hex.pm b/cesar/hal/phy/src/resys/Hex.pm new file mode 100644 index 0000000000..c4896ada28 --- /dev/null +++ b/cesar/hal/phy/src/resys/Hex.pm @@ -0,0 +1,34 @@ +package Hex; +use Exporter; +@ISA = qw(Exporter); +@EXPORT_OK = qw(read); + +sub read +{ + my $addr = 0; + my @data; + local $_; + for (@_) + { + chomp; + # Check format. + s/^:((?:[0-9a-fA-F]{2})*)$/$1/ or die "bad input line"; + # Check sum. + my @hexes = map { hex } /[0-9a-fA-F]{2}/g; + my $sum = 0; + $sum += $_ for @hexes; + die "bad checksum" unless $sum % 0x100 == 0; + # Decode. + /^02(....)00(....)..$/ and do { + my ($a, $d) = map { hex } ($1, $2); + die "bad address" unless $a == $addr++; + push @data, $d; + next; + }; + /^00000001ff$/ and next; + die "bad input line"; + } + return @data; +} + +1; diff --git a/cesar/hal/phy/src/resys/hex2c.pl b/cesar/hal/phy/src/resys/hex2c.pl index 6432f95271..676e7882b1 100644 --- a/cesar/hal/phy/src/resys/hex2c.pl +++ b/cesar/hal/phy/src/resys/hex2c.pl @@ -4,30 +4,9 @@ # use strict; use warnings; +use Hex; -my $addr = 0; -my @data; - -while (<>) -{ - chomp; - # Check format. - s/^:((?:[0-9a-fA-F]{2})*)$/$1/ or die "bad input line"; - # Check sum. - my @hexes = map { hex } /[0-9a-fA-F]{2}/g; - my $sum = 0; - $sum += $_ for @hexes; - die "bad checksum" unless $sum % 0x100 == 0; - # Decode. - /^02(....)00(....)..$/ and do { - my ($a, $d) = map { hex } ($1, $2); - die "bad address" unless $a == $addr++; - push @data, $d; - next; - }; - /^00000001ff$/ and next; - die "bad input line"; -} - +my @hex = <>; +my @data = Hex::read (@hex); print "/* Autogenerated file, do not edit. */\n"; printf "0x%04x,\n", $_ for @data; diff --git a/cesar/hal/phy/src/resys/hexpatch2c.pl b/cesar/hal/phy/src/resys/hexpatch2c.pl new file mode 100644 index 0000000000..fc6671c9eb --- /dev/null +++ b/cesar/hal/phy/src/resys/hexpatch2c.pl @@ -0,0 +1,22 @@ +#!/usr/bin/perl +# +# Make a patch to convert first hex file to second one. +# +use strict; +use warnings; +use Hex; + +open HEX, "<$ARGV[0]" or die; +my @data1 = Hex::read (); +close HEX; +open HEX, "<$ARGV[1]" or die; +my @data2 = Hex::read (); +close HEX; + +print "/* Autogenerated file, do not edit. */\n"; +die unless $#data1 == $#data2; +for my $i (0 .. $#data1) +{ + my ($d1, $d2) = ($data1[$i], $data2[$i]); + $d1 != $d2 and printf "{ 0x%02x, 0x%04x, 0x%04x },\n", $i, $d1, $d2; +} diff --git a/cesar/hal/phy/src/resys/prog_resys.txt b/cesar/hal/phy/src/resys/prog_resys.txt index ffc5288f54..d2a4cbe17c 100644 --- a/cesar/hal/phy/src/resys/prog_resys.txt +++ b/cesar/hal/phy/src/resys/prog_resys.txt @@ -48,8 +48,8 @@ MuftiReady macacke_start estim_channel_preamble first_iter MacackeDone macacke_start estim_delta_preamble MacackeDone macacke_start estim_channel_preamble MacackeDone macacke_start estim_delta_preamble -MacackeDone macacke_start estim_channel_preamble_end delta_internal -MacackeDone macacke_start estim_delta_preamble delta_internal +MacackeDone macacke_start estim_channel_preamble_end DELTA_CHOICE +MacackeDone macacke_start estim_delta_preamble DELTA_CHOICE label preamble_estim_end # Wiener phase correction @@ -57,7 +57,7 @@ wiener_activate goto wiener_phase_correction # interpolation label interpolation_step -MacackeDone macacke_start interpolation delta_internal +MacackeDone macacke_start interpolation DELTA_CHOICE TrueCond IncrMuftiAdd 2 # TrueCond InitD 9 TrueCond IncrD 2 @@ -103,13 +103,13 @@ MuftiReady IncrSymbolCount # END FC 1.0 RECEPTION label label_receive_FC_10 -MacackeDone macacke_start receive_10_Symbol delta_internal +MacackeDone macacke_start receive_10_Symbol DELTA_CHOICE MacackeDone IncrD 7 -TrueCond macacke_start receive_10_Symbol delta_internal +TrueCond macacke_start receive_10_Symbol DELTA_CHOICE MacackeDone IncrD 7 -TrueCond macacke_start receive_10_Symbol delta_internal +TrueCond macacke_start receive_10_Symbol DELTA_CHOICE MacackeDone IncrD 7 -TrueCond macacke_start receive_10_Symbol delta_internal last_copy +TrueCond macacke_start receive_10_Symbol DELTA_CHOICE last_copy MacackeDone IncrD 11 @@ -137,10 +137,10 @@ NextSymb IncrNextSymb 13 TrueCond rxwindowing windowing_3072 rxwindowingrdy fft_start FFT3072 MuftiReady nop -MacackeDone macacke_start receive_av_fc_1 delta_internal overwrite_snr last_copy +MacackeDone macacke_start receive_av_fc_1 DELTA_CHOICE overwrite_snr last_copy MacackeDone interrupt system -TrueCond macacke_start estim_delta_data delta_internal -MacackeDone macacke_start estim_channel_av delta_internal +TrueCond macacke_start estim_delta_data DELTA_CHOICE +MacackeDone macacke_start estim_channel_av DELTA_CHOICE TrueCond IncrSymbolCount soft nop nop # end of frame for short PPDU or continue for long PPDU @@ -156,8 +156,8 @@ NextSymb IncrNextSymb 12 TrueCond rxwindowing windowing_3072 rxwindowingrdy fft_start FFT3072 MuftiReady nop -MacackeDone macacke_start receive_av_fc_1 delta_internal overwrite_snr -MacackeDone macacke_start estim_delta_data delta_internal +MacackeDone macacke_start receive_av_fc_1 DELTA_CHOICE overwrite_snr +MacackeDone macacke_start estim_delta_data DELTA_CHOICE MacackeDone IncrSymbolCount NextSymb IncrNextSymb 13 @@ -166,10 +166,10 @@ TrueCond IncrD 12 TrueCond rxwindowing windowing_3072 rxwindowingrdy fft_start FFT3072 MuftiReady nop -MacackeDone macacke_start receive_av_fc_2 delta_internal last_copy +MacackeDone macacke_start receive_av_fc_2 DELTA_CHOICE last_copy MacackeDone interrupt system -TrueCond macacke_start estim_delta_data delta_internal -MacackeDone macacke_start estim_channel_av delta_internal +TrueCond macacke_start estim_delta_data DELTA_CHOICE +MacackeDone macacke_start estim_channel_av DELTA_CHOICE TrueCond IncrSymbolCount soft nop nop # end of frame for short PPDU or continue for long PPDU diff --git a/cesar/hal/phy/src/resys/resys_compil.pl b/cesar/hal/phy/src/resys/resys_compil.pl index 701bdfa436..b23ca6f560 100644 --- a/cesar/hal/phy/src/resys/resys_compil.pl +++ b/cesar/hal/phy/src/resys/resys_compil.pl @@ -106,12 +106,24 @@ my $PRINT_OPTS = 0; use Getopt::Long qw(:config gnu_getopt); my $bindir; my $disdir = '.'; +my $delta = ''; GetOptions ( 'bindir|B=s' => \$bindir, 'disdir|D=s' => \$disdir, + 'delta-internal' => sub { $delta = 'internal' }, + 'delta-external' => sub { $delta = 'external' }, ) or die; $bindir = "$ENV{WORKING_DIR}/modules/resys/src" unless defined $bindir; +if ($delta eq 'internal') +{ + $argument_bis{'delta_choice'} = $argument_bis{'delta_internal'}; +} +elsif ($delta eq 'external') +{ + $argument_bis{'delta_choice'} = $argument_bis{'nop'}; +} + # source files if (exists $ARGV[0]) { diff --git a/cesar/mac/pbproc/inc/context.h b/cesar/mac/pbproc/inc/context.h index d8752ebd53..c83cd6ce06 100644 --- a/cesar/mac/pbproc/inc/context.h +++ b/cesar/mac/pbproc/inc/context.h @@ -145,6 +145,8 @@ struct pbproc_spoc_update_t * - create PRS (PHY_PREPARE_TYPE_PRS). * Set to PHY_PREPARE_TYPE_NB if no update pending. */ phy_prepare_type_t step; + /** Whether frequency error is synchronised. */ + bool sync; /** SPOC coefficients, to be released once updated. */ phy_spoc_coeff_t *coeff; }; diff --git a/cesar/mac/pbproc/pbproc.h b/cesar/mac/pbproc/pbproc.h index ef15e7b1b4..0cf54548a4 100644 --- a/cesar/mac/pbproc/pbproc.h +++ b/cesar/mac/pbproc/pbproc.h @@ -266,12 +266,14 @@ pbproc_set_chandata_conf (pbproc_t *ctx, phy_chandata_conf_t *conf, uint nb, bool data); /** - * Set the coefficients of SPOC in SPOC registers when possible. + * Set the coefficients of SPOC in SPOC registers when possible, also set + * delta used. * \param ctx pbproc context + * \param sync whether frequency error is synchronised * \param coeff the SPOC coefficients */ void -pbproc_spoc_coeff_set (pbproc_t *ctx, phy_spoc_coeff_t *coeff); +pbproc_spoc_coeff_set (pbproc_t *ctx, bool sync, phy_spoc_coeff_t *coeff); /** * Extract the last segment from an MFS in order to segment more data. diff --git a/cesar/mac/pbproc/src/pbproc.c b/cesar/mac/pbproc/src/pbproc.c index dffe114325..188be35426 100644 --- a/cesar/mac/pbproc/src/pbproc.c +++ b/cesar/mac/pbproc/src/pbproc.c @@ -224,6 +224,7 @@ pbproc_init (mac_config_t *config, mac_store_t *store) pbproc_prep_mpdu_init (ctx); ctx->detect.beacon_detected = false; ctx->spoc_update.step = PHY_PREPARE_TYPE_NB; + ctx->spoc_update.sync = false; ctx->spoc_update.coeff = NULL; /* Initialise precomputed times. */ pbproc_times_init (config, ctx->times_array); @@ -390,11 +391,11 @@ pbproc_set_chandata_conf (pbproc_t *ctx, phy_chandata_conf_t *conf, uint nb, } void -pbproc_spoc_coeff_set (pbproc_t *ctx, phy_spoc_coeff_t *coeff) +pbproc_spoc_coeff_set (pbproc_t *ctx, bool sync, phy_spoc_coeff_t *coeff) { dbg_assert (ctx); dbg_assert (coeff); - PBPROC_TRACE (SPOC_COEFF_SET, coeff->rho_q30); + PBPROC_TRACE (SPOC_COEFF_SET, sync, coeff->rho_q30); /* Update pending SPOC coefficients. */ uint flags = arch_isr_lock (); if (ctx->spoc_update.coeff) @@ -403,6 +404,7 @@ pbproc_spoc_coeff_set (pbproc_t *ctx, phy_spoc_coeff_t *coeff) blk_release (ctx->spoc_update.coeff); } ctx->spoc_update.step = PHY_PREPARE_TYPE_PREAMBLE; + ctx->spoc_update.sync = sync; ctx->spoc_update.coeff = coeff; arch_isr_unlock (flags); } @@ -423,10 +425,12 @@ pbproc_spoc_update_cb (void *user) } /* Create preamble or PRS. */ phy_prepare (ctx->phy, ctx->spoc_update.step, false); - /* Update RX coefficients, and release. */ + /* Update RX coefficients and delta used, and release. */ if (ctx->spoc_update.step == PHY_PREPARE_TYPE_PREAMBLE) { phy_spoc_rx_set (ctx->phy, ctx->spoc_update.coeff); + phy_freq_error_set (ctx->phy, ctx->spoc_update.sync, + ctx->spoc_update.coeff->rho_q30); blk_release (ctx->spoc_update.coeff->part2); blk_release (ctx->spoc_update.coeff); ctx->spoc_update.coeff = NULL; diff --git a/cesar/mac/pbproc/src/trace.c b/cesar/mac/pbproc/src/trace.c index b2f09b27ea..21a1e5edb4 100644 --- a/cesar/mac/pbproc/src/trace.c +++ b/cesar/mac/pbproc/src/trace.c @@ -265,7 +265,7 @@ pbproc_trace_init (pbproc_t *ctx) TRACE_EVENT (PBPROC_TRACE_RX_CB, "rx cb pb_nb=%d"), TRACE_EVENT (PBPROC_TRACE_RX_BEACON_CB, "rx beacon cb"), TRACE_EVENT (PBPROC_TRACE_SPOC_COEFF_SET, - "spoc coeff set rho_q30=%x"), + "spoc coeff set sync=%b rho_q30=%x"), TRACE_EVENT (PBPROC_TRACE_SPOC_UPDATE, "spoc update step=%d", TIMESTAMP), TRACE_EVENT (PBPROC_TRACE_FSM_RX_FC, "fsm RX FC pre_date=%x %F", diff --git a/cesar/mac/pbproc/test/pbproc/inc/scenario_defs.h b/cesar/mac/pbproc/test/pbproc/inc/scenario_defs.h index 41503741b1..d2785dc494 100644 --- a/cesar/mac/pbproc/test/pbproc/inc/scenario_defs.h +++ b/cesar/mac/pbproc/test/pbproc/inc/scenario_defs.h @@ -105,6 +105,7 @@ scenario_action_pbproc_activate_cb (scenario_globals_t *globals, phy_prepare, \ phy_deferred_schedule, \ phy_set_tonemap, \ + phy_freq_error_set, \ phy_tx_fc10, \ phy_tx_param, \ phy_tx_param_short, \ @@ -150,6 +151,12 @@ typedef scenario_empty_t scenario_event_phy_deferred_schedule_t; typedef scenario_empty_t scenario_event_phy_set_tonemap_t; +typedef struct +{ + bool sync; + s32 rho_q30; +} scenario_event_phy_freq_error_set_t; + typedef struct { u32 date; diff --git a/cesar/mac/pbproc/test/pbproc/src/phy.c b/cesar/mac/pbproc/test/pbproc/src/phy.c index 0873037d00..2c98a5d337 100644 --- a/cesar/mac/pbproc/test/pbproc/src/phy.c +++ b/cesar/mac/pbproc/test/pbproc/src/phy.c @@ -88,6 +88,14 @@ phy_set_tonemap (phy_t *ctx, blk_t *tonemap) /* Test tonemap? */ } +void +phy_freq_error_set (phy_t *ctx, bool sync, s32 rho_q30) +{ + scenario_event (phy_freq_error_set, params); + test_fail_unless (sync == params->sync); + test_fail_unless (rho_q30 == params->rho_q30); +} + void phy_tx_fc10 (phy_t *ctx, u32 date, u32 fc_10) { diff --git a/cesar/mac/pbproc/test/pbproc/src/tx_data.c b/cesar/mac/pbproc/test/pbproc/src/tx_data.c index ec5b3f7493..f0d533fa0a 100644 --- a/cesar/mac/pbproc/test/pbproc/src/tx_data.c +++ b/cesar/mac/pbproc/test/pbproc/src/tx_data.c @@ -102,6 +102,8 @@ tx_data_test (test_t t, test_pbproc_t *tp, u32 date, uint mfs_seg_nb, .wait = false), SCENARIO_EVENT_COND (spoc_update_step == PHY_PREPARE_TYPE_PREAMBLE, phy_spoc_rx_set), + SCENARIO_EVENT_COND (spoc_update_step == PHY_PREPARE_TYPE_PREAMBLE, + phy_freq_error_set, .sync = true, .rho_q30 = 42), SCENARIO_ACTION (phy_rx_fc, .rx_date = date + pre_fc_fl_tck, .fc_av = (u32 *) &sack_fc), SCENARIO_EVENT (phy_rx_prepare_short), @@ -892,7 +894,8 @@ tx_data_spoc_test_case (test_t t) test_pbproc_init (&tp); phy_spoc_coeff_t *coeff = blk_alloc (); coeff->part2 = blk_alloc (); - pbproc_spoc_coeff_set (tp.pbproc, coeff); + coeff->rho_q30 = 42; + pbproc_spoc_coeff_set (tp.pbproc, true, coeff); test_begin (t, "preamble") { tx_data_test (t, &tp, 5462132, 30, -- cgit v1.2.3 From 49604838ce51ad0664519444c2f63ad1dd0db3a8 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 8 Aug 2011 15:25:30 +0200 Subject: cesar/hal/phy: negate rho to be used for delta, refs #572 --- cesar/hal/phy/src/phy.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/hal/phy/src/phy.c b/cesar/hal/phy/src/phy.c index f4ce010a2f..fb6553a1e9 100644 --- a/cesar/hal/phy/src/phy.c +++ b/cesar/hal/phy/src/phy.c @@ -997,6 +997,6 @@ phy_freq_error_set (phy_t *ctx, bool sync, s32 rho_q30) ctx->freq_error_sync = sync; } PHY_DSPSS_MACACKE_DELTA_USED = fixed_round ( - -rho_q30, 30 - PHY_DSPSS_MACACKE_DELTA_USED__VALUE__RHO_Q); + rho_q30, 30 - PHY_DSPSS_MACACKE_DELTA_USED__VALUE__RHO_Q); } -- cgit v1.2.3 From 7acaa2f3e42fd73e7af0a73ac9b43413c8c89c80 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Mon, 8 Aug 2011 15:27:39 +0200 Subject: cesar/hal/phy: add delta update coefficients tunable parameters, refs #572 --- cesar/hal/phy/src/phy.c | 45 ++++++++++++++++++++++++++------------------- 1 file changed, 26 insertions(+), 19 deletions(-) (limited to 'cesar') diff --git a/cesar/hal/phy/src/phy.c b/cesar/hal/phy/src/phy.c index fb6553a1e9..c02b2249cf 100644 --- a/cesar/hal/phy/src/phy.c +++ b/cesar/hal/phy/src/phy.c @@ -107,6 +107,10 @@ struct phy_tunable_t int mafadese_coef_filter_band1[26]; /** SPOC initial setting. */ s32 spoc_rho_initial_q30; + /** Internal delta accumulation coefficient. */ + uint delta_res_coef_internal; + /** External delta accumulation coefficient. */ + uint delta_res_coef_external; }; typedef struct phy_tunable_t phy_tunable_t; @@ -132,7 +136,9 @@ static phy_tunable_t phy_tunable = { PHY_PARAM_MAFADESE_COEF_FILTER_BAND0, PHY_PARAM_MAFADESE_COEF_FILTER_BAND1, - 0 + 0, + PHY_PARAM_CHANNEL_ESTIM_COEF__COEF_RES_DELTA_INTERNAL, + PHY_PARAM_CHANNEL_ESTIM_COEF__COEF_RES_DELTA_EXTERNAL, }; #if DEBUG @@ -456,6 +462,14 @@ phy_init_tunable_param (phy_t *ctx) &phy_tunable.spoc_rho_initial_q30, LIB_STATS_ACCESS_WRITE_ONLY, LIB_STATS_DEBUG); + lib_stats_set_stat_value_notype ("DELTA_RES_COEF_INTERNAL", + &phy_tunable.delta_res_coef_internal, + LIB_STATS_ACCESS_WRITE_ONLY, + LIB_STATS_DEBUG); + lib_stats_set_stat_value_notype ("DELTA_RES_COEF_EXTERNAL", + &phy_tunable.delta_res_coef_external, + LIB_STATS_ACCESS_WRITE_ONLY, + LIB_STATS_DEBUG); lib_stats_set_stat_value_notype ("CAP_MASK", &ctx->cap_mask, LIB_STATS_ACCESS_WRITE_ONLY, @@ -743,6 +757,11 @@ phy_set_tunable_param (phy_t *ctx, const u32 *tonemask, uint carrier_nb) phy_tunable.mafadese_coef_filter_band1[i]; phy_spoc_init (ctx, phy_tunable.spoc_rho_initial_q30, tonemask, carrier_nb); + PHY_DSPSS_CHANNEL_ESTIM_COEF = + PHY_PARAMS (PHY_DSPSS, CHANNEL_ESTIM_COEF, COEF_PREAMBLE) + | BF_FILL ( + PHY_DSPSS_CHANNEL_ESTIM_COEF, + (COEF_RES_DELTA, phy_tunable.delta_res_coef_internal)); } static void @@ -975,24 +994,12 @@ phy_freq_error_set (phy_t *ctx, bool sync, s32 rho_q30) dbg_claim (ctx); if (sync != ctx->freq_error_sync) { - if (sync) - { - PHY_DSPSS_CHANNEL_ESTIM_COEF = - PHY_PARAMS (PHY_DSPSS, CHANNEL_ESTIM_COEF, COEF_PREAMBLE) - | BF_FILL ( - PHY_DSPSS_CHANNEL_ESTIM_COEF, - (COEF_RES_DELTA, - PHY_PARAM_CHANNEL_ESTIM_COEF__COEF_RES_DELTA_EXTERNAL)); - } - else - { - PHY_DSPSS_CHANNEL_ESTIM_COEF = - PHY_PARAMS (PHY_DSPSS, CHANNEL_ESTIM_COEF, COEF_PREAMBLE) - | BF_FILL ( - PHY_DSPSS_CHANNEL_ESTIM_COEF, - (COEF_RES_DELTA, - PHY_PARAM_CHANNEL_ESTIM_COEF__COEF_RES_DELTA_INTERNAL)); - } + uint delta_res_coef = sync ? phy_tunable.delta_res_coef_external + : phy_tunable.delta_res_coef_internal; + PHY_DSPSS_CHANNEL_ESTIM_COEF = + PHY_PARAMS (PHY_DSPSS, CHANNEL_ESTIM_COEF, COEF_PREAMBLE) + | BF_FILL (PHY_DSPSS_CHANNEL_ESTIM_COEF, + (COEF_RES_DELTA, delta_res_coef)); phy_resys_patch (ctx, sync); ctx->freq_error_sync = sync; } -- cgit v1.2.3 From e56cc9e78763d383e51e4b66f21a761826c3f305 Mon Sep 17 00:00:00 2001 From: Nélio Laranjeiro Date: Thu, 16 Jun 2011 09:41:36 +0200 Subject: cesar/bsu: add tunable NTB smooth coefficient, closes #2680 --- cesar/bsu/inc/context.h | 2 ++ cesar/bsu/ntb/ntb.h | 5 ++++- cesar/bsu/ntb/src/ntb.c | 15 +++++++-------- cesar/bsu/ntb/test/utest/src/ntb_compute.c | 9 +++++---- cesar/bsu/src/bsu.c | 9 +++++++-- 5 files changed, 25 insertions(+), 15 deletions(-) (limited to 'cesar') diff --git a/cesar/bsu/inc/context.h b/cesar/bsu/inc/context.h index 0139c156a8..a814254e4c 100644 --- a/cesar/bsu/inc/context.h +++ b/cesar/bsu/inc/context.h @@ -120,6 +120,8 @@ struct bsu_t uint nek_switch; /** Station's discover info updated by CP. */ bsu_beacon_bmi_discover_info_t discover_info; + /** NTB clock synchronization weight configuration. k is for 1/2^k. */ + uint ntb_clk_sync_weight_k; #if CONFIG_TRACE /** Trace system. */ trace_buffer_t trace; diff --git a/cesar/bsu/ntb/ntb.h b/cesar/bsu/ntb/ntb.h index a71b9861d2..ce01f409da 100644 --- a/cesar/bsu/ntb/ntb.h +++ b/cesar/bsu/ntb/ntb.h @@ -16,6 +16,8 @@ #include "mac/common/config.h" #include "hal/phy/phy.h" +#define BSU_NTB_CLK_SYNC_WEIGHT_K_DEFAULT 2 + BEGIN_DECLS /* @@ -25,10 +27,11 @@ BEGIN_DECLS * \param phy the phy context. * \param beacon_bts beacon time stamp * \param beacon_sta_ltmr STA local time captured when receiving beacon + * \param weight_k the coefficient weight to use to smooth the NTB clock */ void bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts, - u32 beacon_sys_ltmr, u32 beacon_sta_ltmr); + u32 beacon_sys_ltmr, u32 beacon_sta_ltmr, uint weight_k); /** * Configure the clock frequency. diff --git a/cesar/bsu/ntb/src/ntb.c b/cesar/bsu/ntb/src/ntb.c index 1111597960..fe4a49a7f0 100644 --- a/cesar/bsu/ntb/src/ntb.c +++ b/cesar/bsu/ntb/src/ntb.c @@ -25,10 +25,6 @@ * keep a good synchronisation on the medium without reseting history. */ #define BSU_NTB_NO_RECEPTION_MS 400 -#define BSU_NTB_WEIGHT 0.25 -#define BSU_NTB_WF BSU_NTB_WEIGHT -#define BSU_NTB_WO BSU_NTB_WEIGHT - #define BSU_NTB_FE_PPM(fe) \ ((double) ((fe) * 1000000.0)) @@ -38,12 +34,14 @@ * \param bts the last beacon time stamp received in the last beacon. * \param preamble_sysdate the system date preamble corresponding to the * last beacon received. + * \param weight_k the coefficient weight to use to smooth the NTB clock */ PRIVATE void bsu_ntb_frequency_error (bsu_ntb_sync_t *ctx, double freq_err, u32 bts, - u32 preamble_sysdate) + u32 preamble_sysdate, uint weight_k) { dbg_assert (ctx); + double bsu_ntb_wf = 1.0 / (1 << weight_k); if (ctx->init) { double num = bts - ctx->bts; @@ -56,7 +54,7 @@ bsu_ntb_frequency_error (bsu_ntb_sync_t *ctx, double freq_err, u32 bts, else { double part2 = num / denum - 1 - freq_err; - ctx->fe = freq_err + BSU_NTB_WF * part2; + ctx->fe = freq_err + bsu_ntb_wf * part2; } } } @@ -112,7 +110,7 @@ bsu_ntb_uninit (bsu_ntb_sync_t *ctx) void bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts, - u32 beacon_sys_ltmr, u32 beacon_sta_ltmr) + u32 beacon_sys_ltmr, u32 beacon_sta_ltmr, uint weight_k) { double freq_error; dbg_assert (ctx); @@ -126,7 +124,8 @@ bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts, && less_mod2p32 (beacon_bts, ctx->bts + MAC_MS_TO_TCK (BSU_NTB_NO_RECEPTION_MS))) { - bsu_ntb_frequency_error (ctx, freq_error, beacon_bts, beacon_sys_ltmr); + bsu_ntb_frequency_error (ctx, freq_error, beacon_bts, beacon_sys_ltmr, + weight_k); /** Frequency error is too high reset data. */ if (ABS (ctx->fe) > BSU_FREQ_ERR_SECURITY) { diff --git a/cesar/bsu/ntb/test/utest/src/ntb_compute.c b/cesar/bsu/ntb/test/utest/src/ntb_compute.c index b5ff7a220a..19745c4c65 100644 --- a/cesar/bsu/ntb/test/utest/src/ntb_compute.c +++ b/cesar/bsu/ntb/test/utest/src/ntb_compute.c @@ -12,6 +12,7 @@ */ #include "common/std.h" #include "lib/test.h" +#include "lib/fixed.h" #include "bsu/ntb/test/utest/tests.h" #include "bsu/ntb/ntb.h" #include "mac/common/timings.h" @@ -78,7 +79,7 @@ test_case_ntb_ntb_sync (test_t test, bsu_ntb_test_type_t type) /* In this test the sys_date_preamble is the same as the station * date preamble. */ bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, bts[i], - preamble_sysdate[i], preamble_stadate[i]); + preamble_sysdate[i], preamble_stadate[i], 2); test_fail_unless (ABS(sync.fe - freqerr[i]) < 1.0e-12, "Freq different in loop %d", i); test_fail_unless (sync.ntb_offset_tck == offset[i], @@ -118,7 +119,7 @@ test_case_freq_error (test_t test) sync.preamble_stadate = 0x6f04181; /* Compute new Frequency error. */ bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, 0x21e04ad, - 0x1ddf30d3, 0x1ddf30d3); + 0x1ddf30d3, 0x1ddf30d3, 2); test_fail_unless (sync.fe == 0); test_fail_unless (sync.init == true); test_fail_unless (sync.second_shoot == false); @@ -134,7 +135,7 @@ test_case_freq_error (test_t test) sync.preamble_stadate = 0x6f04181; /* Compute new Frequency error. */ bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, sync.bts + 1, - sync.preamble_sysdate + 1, 0x1ddf30d3); + sync.preamble_sysdate + 1, 0x1ddf30d3, 2); test_fail_unless (sync.fe == 0); test_fail_unless (sync.init == true); test_fail_unless (sync.second_shoot == false); @@ -160,7 +161,7 @@ test_case_freq_error (test_t test) /* Compute new Frequency error. */ bsu_ntb_clk_sync ( &sync, (phy_t*) &t.phy, scmp.bts, scmp.preamble_sysdate, - scmp.preamble_stadate); + scmp.preamble_stadate, 2); test_fail_unless (sync.fe == scmp.fe); test_fail_unless (scmp.bts == sync.bts); test_fail_unless (scmp.preamble_sysdate == sync.preamble_sysdate); diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c index 6cc35920d4..aeeb268b6a 100644 --- a/cesar/bsu/src/bsu.c +++ b/cesar/bsu/src/bsu.c @@ -870,6 +870,10 @@ bsu_stats_init (bsu_t *ctx) &ctx->stats.frequency_error_q30, LIB_STATS_ACCESS_READ_ONLY, LIB_STATS_USER); + lib_stats_set_stat_value_notype ("CLK_SYNC_WEIGHT_K", + &ctx->ntb_clk_sync_weight_k, + LIB_STATS_ACCESS_WRITE_ONLY, + LIB_STATS_USER); #endif } @@ -923,6 +927,7 @@ bsu_init (bsu_aclf_t *aclf, mac_config_t *mac_config, phy_t *phy, ctx->beacon_nb_sent[i] = 0; for (i = 0; i < COUNT (ctx->ca_schedules_in_use); i++) ctx->ca_schedules_in_use[i] = CA_SCHEDULE_NB; + ctx->ntb_clk_sync_weight_k = BSU_NTB_CLK_SYNC_WEIGHT_K_DEFAULT; /* Trace. */ bsu_trace_init (ctx); bsu_stats_init (ctx); @@ -969,7 +974,7 @@ bsu_beacon_process__avln_tracked (bsu_t *ctx, bsu_beacon_t *beacon, /* NTB synchronisation. */ bsu_ntb_clk_sync (&ctx->sta_avln->sync, ctx->phy, params->bts, params->preamble_sysdate, - params->preamble_date); + params->preamble_date, ctx->ntb_clk_sync_weight_k); /* Configure the clock frequency. */ bsu_ntb_clock_configure ( &ctx->sta_avln->sync, ctx->mac_config, ctx->phy); @@ -1032,7 +1037,7 @@ bsu_beacon_process__avln_not_tracked (bsu_t *ctx, bsu_beacon_t *beacon, /* NTB synchronisation. */ bsu_ntb_clk_sync (&avln->sync, ctx->phy, params->bts, params->preamble_sysdate, - params->preamble_date); + params->preamble_date, ctx->ntb_clk_sync_weight_k); avln->beacon.beacon_period_start_date = params->bts - avln->sync.ntb_offset_tck; BSU_TRACE (BEACON_PROCESS, phy_date (), params->snid, beacon->vf.stei, -- cgit v1.2.3 From 5abe923a4e56cb5627eb0c378f67939b5565eef9 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 16 Aug 2011 15:31:22 +0200 Subject: cesar/bsu/test/utest: document test process --- cesar/bsu/test/utest/src/bsut.c | 48 ++++++++++++++++++++++++----------------- 1 file changed, 28 insertions(+), 20 deletions(-) (limited to 'cesar') diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c index b25a9cbd60..4ad6722117 100644 --- a/cesar/bsu/test/utest/src/bsut.c +++ b/cesar/bsu/test/utest/src/bsut.c @@ -51,10 +51,11 @@ test_case_bsu_process (test_t test) pbproc_tx_beacon_params_t bp_tx; pbproc_rx_beacon_params_t bpneighbour_rx; pbproc_rx_beacon_params_t bp_rx; - bsu_test_create_beacon (&t, &beacon_neighbour); memset (&bp_rx, 0, sizeof (pbproc_rx_beacon_params_t)); memset (&bpneighbour_rx, 0, sizeof (pbproc_rx_beacon_params_t)); t.mac_config.tei = 4; + /* => Neighbour beacon with bad CRC. */ + bsu_test_create_beacon (&t, &beacon_neighbour); bpneighbour_rx.snid = 0x4; bpneighbour_rx.bts = 0; bneighbour = bsu_beacon_write (&beacon_neighbour, @@ -64,80 +65,87 @@ test_case_bsu_process (test_t test) bneighbour->phy_pb.pb_rx.pb_measurement.crc_error = true; bprocessed = bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx); blk_release_desc ((blk_t*) bneighbour); - /* Central beacon processed ? */ + /* Central beacon processed? */ test_fail_unless (!bprocessed); test_fail_unless (t.bsu->avlns[0].snid == 0); test_fail_unless (t.bsu->avlns[0].beacon.vf.nid == 0); test_fail_unless (t.bsu->beacon_nb_sent [BSU_BEACON_TYPE_CENTRAL] == 0); - /* NTB called ? */ + /* NTB called? */ test_fail_unless (t.bsu->avlns[0].sync.init == false); + /* => First neighbour beacon reception. */ bneighbour = bsu_beacon_write (&beacon_neighbour, BSU_BEACON_TYPE_CENTRAL, &t.mac_config, &bpneighbour_tx); bneighbour->phy_pb.pb_rx.pb_measurement.crc_error = false; bprocessed = bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx); - /* Central beacon processed ? */ + /* Central beacon processed? */ test_fail_unless (bprocessed); - test_fail_unless (!bprocessed->params.frequency_error_valid); test_fail_unless (t.bsu->avlns[0].snid == bpneighbour_rx.snid); test_fail_unless (t.bsu->avlns[0].beacon.vf.nid == beacon_neighbour.vf.nid); test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] == 1); - blk_release (bprocessed); - /* NTB called ? */ + /* NTB called? */ test_fail_unless (t.bsu->avlns[0].sync.init == true); - /* Second shoot... */ + test_fail_unless (!bprocessed->params.frequency_error_valid); + /* Cleanup. */ + blk_release (bprocessed); + /* => Second neighbour beacon reception. */ bprocessed = bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx); - /* Central beacon processed ? */ + /* Central beacon processed? */ test_fail_unless (bprocessed); test_fail_unless (t.bsu->avlns[0].snid == bpneighbour_rx.snid); test_fail_unless (t.bsu->avlns[0].beacon.vf.nid == beacon_neighbour.vf.nid); - /* NTB called ? */ + test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] + == 2); + /* NTB called? */ test_fail_unless (t.bsu->avlns[0].sync.init == true); test_fail_unless (bprocessed->params.frequency_error_valid); + /* Cleanup. */ blk_release_desc ((blk_t*) bneighbour); - test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] - == 2); blk_release (bprocessed); - /* Our AVLN. */ + /* => Our AVLN. */ bsu_track_avln (t.bsu, beacon_neighbour.vf.nid, 0x4, beacon_neighbour.vf.stei, beacon_neighbour.bmis.mac_address.mac_address); + /* Reset synchronisation. */ t.bsu->sta_avln->sync.init = false; + /* => Beacon with bad CRC. */ bsu_test_create_beacon (&t, &beacon); + bp_rx.snid = 0x4; + bp_rx.bts = 0; b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL, &t.mac_config, &bp_tx); b->phy_pb.pb_rx.pb_measurement.crc_error = true; bprocessed = bsu_beacon_process (t.bsu, b, &bp_rx); - /* Central beacon processed ? */ + blk_release_desc ((blk_t*) b); + /* Central beacon processed? */ test_fail_unless (!bprocessed); test_fail_unless (t.bsu->sta_avln->snid == t.bsu->snid_track); test_fail_unless (t.bsu->sta_avln->beacon.vf.nid == t.bsu->nid_track); test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] == 2); - blk_release_desc ((blk_t*) b); - /* NTB called ? */ + /* NTB called? */ test_fail_unless (t.bsu->sta_avln->sync.init == false); - bp_rx.snid = 0x4; - bp_rx.bts = 0; + /* => First beacon reception. */ b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL, &t.mac_config, &bp_tx); b->phy_pb.pb_rx.pb_measurement.crc_error = false; bprocessed = bsu_beacon_process (t.bsu, b, &bp_rx); - /* Central beacon processed ? */ + /* Central beacon processed? */ test_fail_unless (bprocessed); test_fail_unless (t.bsu->sta_avln->snid == bp_rx.snid); test_fail_unless (t.bsu->sta_avln->beacon.vf.nid == beacon.vf.nid); test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] == 3); - /* NTB called ? */ + /* NTB called? */ test_fail_unless (t.bsu->sta_avln->sync.init == true); test_fail_unless (t.bsu->sta_avln->sync.second_shoot); test_fail_unless (bprocessed->params.frequency_error_valid); + /* Cleanup. */ blk_release_desc ((blk_t*) b); blk_release (bprocessed); } -- cgit v1.2.3 From d8bf835826891120685d2976e734327e122ee755 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 17 Aug 2011 11:44:43 +0200 Subject: cesar/bsu/ntb: remove unused delay_systck field --- cesar/bsu/ntb/ntb_sync.h | 2 -- cesar/bsu/ntb/src/ntb.c | 10 ++++------ cesar/bsu/ntb/test/utest/src/ntb_compute.c | 1 - 3 files changed, 4 insertions(+), 9 deletions(-) (limited to 'cesar') diff --git a/cesar/bsu/ntb/ntb_sync.h b/cesar/bsu/ntb/ntb_sync.h index e515ab3897..9bdf7ad93a 100644 --- a/cesar/bsu/ntb/ntb_sync.h +++ b/cesar/bsu/ntb/ntb_sync.h @@ -36,8 +36,6 @@ struct bsu_ntb_sync_t u32 sta_numerator; /** NTB clock tick offset. */ u32 ntb_offset_tck; - /** Delay before processing the beacon. */ - u32 delay_systck; }; typedef struct bsu_ntb_sync_t bsu_ntb_sync_t; diff --git a/cesar/bsu/ntb/src/ntb.c b/cesar/bsu/ntb/src/ntb.c index fe4a49a7f0..a78a1999d1 100644 --- a/cesar/bsu/ntb/src/ntb.c +++ b/cesar/bsu/ntb/src/ntb.c @@ -78,11 +78,10 @@ bsu_ntb_offset (bsu_ntb_sync_t *ctx, phy_t *phy, double freq_error, offset = bts - preamble_stadate; if (ctx->init) { - /* Get the delay in system ticks. */ - ctx->delay_systck = phy_sysdate () - preamble_sysdate; - dbg_assert ((s32) ctx->delay_systck >= 0); - offset += ((ctx->fe * ctx->delay_systck) - - (freq_error * ctx->delay_systck)); + /* Add offset for the update delay. */ + int delay_systck = phy_sysdate () - preamble_sysdate; + dbg_assert (delay_systck >= 0); + offset += ctx->fe * delay_systck - freq_error * delay_systck; } return offset; } @@ -99,7 +98,6 @@ bsu_ntb_init (bsu_ntb_sync_t *ctx) ctx->preamble_stadate = 0; ctx->sta_numerator = 0; ctx->ntb_offset_tck = 0; - ctx->delay_systck = 0; } void diff --git a/cesar/bsu/ntb/test/utest/src/ntb_compute.c b/cesar/bsu/ntb/test/utest/src/ntb_compute.c index 19745c4c65..618563212f 100644 --- a/cesar/bsu/ntb/test/utest/src/ntb_compute.c +++ b/cesar/bsu/ntb/test/utest/src/ntb_compute.c @@ -71,7 +71,6 @@ test_case_ntb_ntb_sync (test_t test, bsu_ntb_test_type_t type) sync.bts = bts[0]; sync.preamble_sysdate = preamble_sysdate[0]; sync.preamble_stadate = preamble_stadate[0]; - sync.delay_systck = delay_systck [0]; for (i = 1; i < bts_nb; i++) { t.phy.preamble_sysdate = preamble_sysdate[i]; -- cgit v1.2.3 From b5eaec6151f503e194cba549b46f877a34ee89fa Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 17 Aug 2011 14:58:30 +0200 Subject: cesar/bsu: remove unused phy parameter --- cesar/bsu/ntb/ntb.h | 5 ++--- cesar/bsu/ntb/src/ntb.c | 12 +++++------- cesar/bsu/ntb/test/utest/src/ntb_compute.c | 16 +++++++--------- cesar/bsu/src/bsu.c | 9 ++++----- 4 files changed, 18 insertions(+), 24 deletions(-) (limited to 'cesar') diff --git a/cesar/bsu/ntb/ntb.h b/cesar/bsu/ntb/ntb.h index ce01f409da..cd8dc08426 100644 --- a/cesar/bsu/ntb/ntb.h +++ b/cesar/bsu/ntb/ntb.h @@ -24,14 +24,13 @@ BEGIN_DECLS * Synchronize local clock to be as close as possible to estimated value * of the NTB clock reference. * \param ctx the module context data. - * \param phy the phy context. * \param beacon_bts beacon time stamp * \param beacon_sta_ltmr STA local time captured when receiving beacon * \param weight_k the coefficient weight to use to smooth the NTB clock */ void -bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts, - u32 beacon_sys_ltmr, u32 beacon_sta_ltmr, uint weight_k); +bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, u32 beacon_bts, u32 beacon_sys_ltmr, + u32 beacon_sta_ltmr, uint weight_k); /** * Configure the clock frequency. diff --git a/cesar/bsu/ntb/src/ntb.c b/cesar/bsu/ntb/src/ntb.c index a78a1999d1..3cb4574b46 100644 --- a/cesar/bsu/ntb/src/ntb.c +++ b/cesar/bsu/ntb/src/ntb.c @@ -61,7 +61,6 @@ bsu_ntb_frequency_error (bsu_ntb_sync_t *ctx, double freq_err, u32 bts, /** Compute the current offset from the NTB clock and the phy clock. * \param ctx module context. - * \param phy the phy context. * \param freq_error last frequency error computed. * \param bts the last beacon time stamp received in the last beacon. * \param preamble_stadata the sta date preamble corresponding to the last @@ -70,8 +69,8 @@ bsu_ntb_frequency_error (bsu_ntb_sync_t *ctx, double freq_err, u32 bts, * last beacon received. */ PRIVATE u32 -bsu_ntb_offset (bsu_ntb_sync_t *ctx, phy_t *phy, double freq_error, - u32 bts, u32 preamble_stadate, u32 preamble_sysdate) +bsu_ntb_offset (bsu_ntb_sync_t *ctx, double freq_error, u32 bts, + u32 preamble_stadate, u32 preamble_sysdate) { u32 offset; dbg_assert (ctx); @@ -107,12 +106,11 @@ bsu_ntb_uninit (bsu_ntb_sync_t *ctx) } void -bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts, - u32 beacon_sys_ltmr, u32 beacon_sta_ltmr, uint weight_k) +bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, u32 beacon_bts, u32 beacon_sys_ltmr, + u32 beacon_sta_ltmr, uint weight_k) { double freq_error; dbg_assert (ctx); - dbg_assert (phy); freq_error = ctx->fe; /** * Check the beacon received is not received N MS after the previous one, @@ -133,7 +131,7 @@ bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, phy_t *phy, u32 beacon_bts, ctx->second_shoot = false; } } - ctx->ntb_offset_tck= bsu_ntb_offset (ctx, phy, freq_error, beacon_bts, + ctx->ntb_offset_tck= bsu_ntb_offset (ctx, freq_error, beacon_bts, beacon_sta_ltmr, beacon_sys_ltmr); ctx->preamble_sysdate = beacon_sys_ltmr; ctx->preamble_stadate = beacon_sta_ltmr; diff --git a/cesar/bsu/ntb/test/utest/src/ntb_compute.c b/cesar/bsu/ntb/test/utest/src/ntb_compute.c index 618563212f..f2a8f266ab 100644 --- a/cesar/bsu/ntb/test/utest/src/ntb_compute.c +++ b/cesar/bsu/ntb/test/utest/src/ntb_compute.c @@ -77,8 +77,8 @@ test_case_ntb_ntb_sync (test_t test, bsu_ntb_test_type_t type) t.phy.sys_date = t.phy.preamble_sysdate + delay_systck[i]; /* In this test the sys_date_preamble is the same as the station * date preamble. */ - bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, bts[i], - preamble_sysdate[i], preamble_stadate[i], 2); + bsu_ntb_clk_sync (&sync, bts[i], preamble_sysdate[i], + preamble_stadate[i], 2); test_fail_unless (ABS(sync.fe - freqerr[i]) < 1.0e-12, "Freq different in loop %d", i); test_fail_unless (sync.ntb_offset_tck == offset[i], @@ -117,8 +117,7 @@ test_case_freq_error (test_t test) sync.preamble_sysdate = 0x6f04181; sync.preamble_stadate = 0x6f04181; /* Compute new Frequency error. */ - bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, 0x21e04ad, - 0x1ddf30d3, 0x1ddf30d3, 2); + bsu_ntb_clk_sync (&sync, 0x21e04ad, 0x1ddf30d3, 0x1ddf30d3, 2); test_fail_unless (sync.fe == 0); test_fail_unless (sync.init == true); test_fail_unless (sync.second_shoot == false); @@ -133,8 +132,8 @@ test_case_freq_error (test_t test) sync.preamble_sysdate = 0x6f04181; sync.preamble_stadate = 0x6f04181; /* Compute new Frequency error. */ - bsu_ntb_clk_sync (&sync, (phy_t*) &t.phy, sync.bts + 1, - sync.preamble_sysdate + 1, 0x1ddf30d3, 2); + bsu_ntb_clk_sync (&sync, sync.bts + 1, sync.preamble_sysdate + 1, + 0x1ddf30d3, 2); test_fail_unless (sync.fe == 0); test_fail_unless (sync.init == true); test_fail_unless (sync.second_shoot == false); @@ -158,9 +157,8 @@ test_case_freq_error (test_t test) scmp.preamble_sysdate = sync.preamble_sysdate + MAC_MS_TO_TCK (500); scmp.preamble_stadate = sync.preamble_stadate + MAC_MS_TO_TCK (500); /* Compute new Frequency error. */ - bsu_ntb_clk_sync ( - &sync, (phy_t*) &t.phy, scmp.bts, scmp.preamble_sysdate, - scmp.preamble_stadate, 2); + bsu_ntb_clk_sync (&sync, scmp.bts, scmp.preamble_sysdate, + scmp.preamble_stadate, 2); test_fail_unless (sync.fe == scmp.fe); test_fail_unless (scmp.bts == sync.bts); test_fail_unless (scmp.preamble_sysdate == sync.preamble_sysdate); diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c index aeeb268b6a..16140269dc 100644 --- a/cesar/bsu/src/bsu.c +++ b/cesar/bsu/src/bsu.c @@ -972,9 +972,9 @@ bsu_beacon_process__avln_tracked (bsu_t *ctx, bsu_beacon_t *beacon, + bsu_aclf_beacon_period_tck (ctx->aclf)); memcpy (&ctx->sta_avln->beacon, beacon, sizeof (bsu_beacon_t)); /* NTB synchronisation. */ - bsu_ntb_clk_sync (&ctx->sta_avln->sync, ctx->phy, - params->bts, params->preamble_sysdate, - params->preamble_date, ctx->ntb_clk_sync_weight_k); + bsu_ntb_clk_sync (&ctx->sta_avln->sync, params->bts, + params->preamble_sysdate, params->preamble_date, + ctx->ntb_clk_sync_weight_k); /* Configure the clock frequency. */ bsu_ntb_clock_configure ( &ctx->sta_avln->sync, ctx->mac_config, ctx->phy); @@ -1035,8 +1035,7 @@ bsu_beacon_process__avln_not_tracked (bsu_t *ctx, bsu_beacon_t *beacon, avln->bto[i] = params->bto[i]; memcpy (&avln->beacon, beacon, sizeof (bsu_beacon_t)); /* NTB synchronisation. */ - bsu_ntb_clk_sync (&avln->sync, ctx->phy, - params->bts, params->preamble_sysdate, + bsu_ntb_clk_sync (&avln->sync, params->bts, params->preamble_sysdate, params->preamble_date, ctx->ntb_clk_sync_weight_k); avln->beacon.beacon_period_start_date = params->bts - avln->sync.ntb_offset_tck; -- cgit v1.2.3 From 99fcfc8a9eb9dc4c37c8b5dabd6a7f893c3c7f20 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 17 Aug 2011 16:39:17 +0200 Subject: cesar/bsu: add clock error precision estimation, closes #2679 --- cesar/bsu/inc/context.h | 2 ++ cesar/bsu/ntb/ntb.h | 2 ++ cesar/bsu/ntb/ntb_sync.h | 6 ++-- cesar/bsu/ntb/src/ntb.c | 10 +++--- cesar/bsu/ntb/test/utest/src/ntb_compute.c | 15 ++++---- cesar/bsu/src/bsu.c | 9 +++-- cesar/bsu/test/utest/src/bsut.c | 58 +++++++++++++++++++----------- 7 files changed, 65 insertions(+), 37 deletions(-) (limited to 'cesar') diff --git a/cesar/bsu/inc/context.h b/cesar/bsu/inc/context.h index a814254e4c..02f64e30a2 100644 --- a/cesar/bsu/inc/context.h +++ b/cesar/bsu/inc/context.h @@ -122,6 +122,8 @@ struct bsu_t bsu_beacon_bmi_discover_info_t discover_info; /** NTB clock synchronization weight configuration. k is for 1/2^k. */ uint ntb_clk_sync_weight_k; + /** Number of NTB clock synchronizations for stable error measure. */ + uint ntb_clk_sync_nb_stable; #if CONFIG_TRACE /** Trace system. */ trace_buffer_t trace; diff --git a/cesar/bsu/ntb/ntb.h b/cesar/bsu/ntb/ntb.h index cd8dc08426..52d1a0c397 100644 --- a/cesar/bsu/ntb/ntb.h +++ b/cesar/bsu/ntb/ntb.h @@ -18,6 +18,8 @@ #define BSU_NTB_CLK_SYNC_WEIGHT_K_DEFAULT 2 +#define BSU_NTB_CLK_SYNC_NB_STABLE_DEFAULT 1 + BEGIN_DECLS /* diff --git a/cesar/bsu/ntb/ntb_sync.h b/cesar/bsu/ntb/ntb_sync.h index 9bdf7ad93a..4eafa76268 100644 --- a/cesar/bsu/ntb/ntb_sync.h +++ b/cesar/bsu/ntb/ntb_sync.h @@ -20,10 +20,8 @@ struct bsu_ntb_sync_t { /** Initialised ? */ bool init; - /** First time it computes the Frequency error. This bool is useful - * because the first computation of the frequency error is not equal to - * the others. */ - bool second_shoot; + /** Number of clock synchronisations, will saturate at UINT_MAX. */ + uint sync_nb; /** Frequency error. */ double fe; /** beacon time stamp. */ diff --git a/cesar/bsu/ntb/src/ntb.c b/cesar/bsu/ntb/src/ntb.c index 3cb4574b46..e5fe84bd28 100644 --- a/cesar/bsu/ntb/src/ntb.c +++ b/cesar/bsu/ntb/src/ntb.c @@ -14,6 +14,7 @@ #include "lib/fixed.h" #include "bsu/ntb/ntb.h" #include "mac/common/timings.h" +#include "limits.h" /** Define a security level for frequency error. * If frequency error is greater then re-initialise freq error. */ @@ -46,16 +47,17 @@ bsu_ntb_frequency_error (bsu_ntb_sync_t *ctx, double freq_err, u32 bts, { double num = bts - ctx->bts; double denum = preamble_sysdate - ctx->preamble_sysdate; - if (!ctx->second_shoot) + if (!ctx->sync_nb) { ctx->fe = num / denum - 1; - ctx->second_shoot = true; } else { double part2 = num / denum - 1 - freq_err; ctx->fe = freq_err + bsu_ntb_wf * part2; } + if (ctx->sync_nb < UINT_MAX) + ctx->sync_nb++; } } @@ -90,7 +92,7 @@ bsu_ntb_init (bsu_ntb_sync_t *ctx) { dbg_assert (ctx); ctx->init = false; - ctx->second_shoot = false; + ctx->sync_nb = 0; ctx->fe = 0.0; ctx->bts = 0; ctx->preamble_sysdate = 0; @@ -128,7 +130,7 @@ bsu_ntb_clk_sync (bsu_ntb_sync_t * ctx, u32 beacon_bts, u32 beacon_sys_ltmr, freq_error = 0; ctx->fe = 0; ctx->init = false; - ctx->second_shoot = false; + ctx->sync_nb = 0; } } ctx->ntb_offset_tck= bsu_ntb_offset (ctx, freq_error, beacon_bts, diff --git a/cesar/bsu/ntb/test/utest/src/ntb_compute.c b/cesar/bsu/ntb/test/utest/src/ntb_compute.c index f2a8f266ab..1612ddbae4 100644 --- a/cesar/bsu/ntb/test/utest/src/ntb_compute.c +++ b/cesar/bsu/ntb/test/utest/src/ntb_compute.c @@ -65,7 +65,8 @@ test_case_ntb_ntb_sync (test_t test, bsu_ntb_test_type_t type) bsu_ntb_test_init (&t); bsu_ntb_init (&sync); /* Initialise the values. */ - sync.second_shoot = sync.init = true; + sync.init = true; + sync.sync_nb = 1; sync.fe = freqerr [0]; sync.ntb_offset_tck = offset[0]; sync.bts = bts[0]; @@ -111,7 +112,7 @@ test_case_freq_error (test_t test) bsu_ntb_init (&sync); /* Configure with real data. */ sync.init = true; - sync.second_shoot = true; + sync.sync_nb = 1; sync.fe = -1.074e-05; sync.bts = 0x8a1ad69; sync.preamble_sysdate = 0x6f04181; @@ -120,13 +121,13 @@ test_case_freq_error (test_t test) bsu_ntb_clk_sync (&sync, 0x21e04ad, 0x1ddf30d3, 0x1ddf30d3, 2); test_fail_unless (sync.fe == 0); test_fail_unless (sync.init == true); - test_fail_unless (sync.second_shoot == false); + test_fail_unless (sync.sync_nb == 0); test_fail_unless ( sync.ntb_offset_tck == sync.bts - sync.preamble_stadate); /* Negative one. */ bsu_ntb_init (&sync); sync.init = true; - sync.second_shoot = true; + sync.sync_nb = 1; sync.fe = -2.04; sync.bts = 0x8a1ad69; sync.preamble_sysdate = 0x6f04181; @@ -136,7 +137,7 @@ test_case_freq_error (test_t test) 0x1ddf30d3, 2); test_fail_unless (sync.fe == 0); test_fail_unless (sync.init == true); - test_fail_unless (sync.second_shoot == false); + test_fail_unless (sync.sync_nb == 0); test_fail_unless ( sync.ntb_offset_tck == sync.bts - sync.preamble_stadate); } @@ -147,7 +148,7 @@ test_case_freq_error (test_t test) bsu_ntb_init (&sync); /* Configure with real data. */ sync.init = true; - sync.second_shoot = true; + sync.sync_nb = 1; sync.fe = -1.074e-05; sync.bts = 0x8a1ad69; sync.preamble_sysdate = 0x6f04181; @@ -164,7 +165,7 @@ test_case_freq_error (test_t test) test_fail_unless (scmp.preamble_sysdate == sync.preamble_sysdate); test_fail_unless (scmp.preamble_stadate == sync.preamble_stadate); test_fail_unless (sync.init == true); - test_fail_unless (sync.second_shoot == true); + test_fail_unless (sync.sync_nb == 1); } test_end; } diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c index 16140269dc..ccbf601f35 100644 --- a/cesar/bsu/src/bsu.c +++ b/cesar/bsu/src/bsu.c @@ -56,7 +56,7 @@ bsu_stats_store (bsu_t *ctx) { #if CONFIG_STATS ctx->stats.ntb_offset_tck = ctx->sta_avln->sync.ntb_offset_tck; - if (ctx->sta_avln->sync.second_shoot) + if (ctx->sta_avln->sync.sync_nb >= ctx->ntb_clk_sync_nb_stable) ctx->stats.frequency_error_q30 = FIXED (ctx->sta_avln->sync.fe, BSU_NTB_FIXED_POINT); else @@ -874,6 +874,10 @@ bsu_stats_init (bsu_t *ctx) &ctx->ntb_clk_sync_weight_k, LIB_STATS_ACCESS_WRITE_ONLY, LIB_STATS_USER); + lib_stats_set_stat_value_notype ("CLK_SYNC_NB_STABLE", + &ctx->ntb_clk_sync_nb_stable, + LIB_STATS_ACCESS_WRITE_ONLY, + LIB_STATS_USER); #endif } @@ -928,6 +932,7 @@ bsu_init (bsu_aclf_t *aclf, mac_config_t *mac_config, phy_t *phy, for (i = 0; i < COUNT (ctx->ca_schedules_in_use); i++) ctx->ca_schedules_in_use[i] = CA_SCHEDULE_NB; ctx->ntb_clk_sync_weight_k = BSU_NTB_CLK_SYNC_WEIGHT_K_DEFAULT; + ctx->ntb_clk_sync_nb_stable = BSU_NTB_CLK_SYNC_NB_STABLE_DEFAULT; /* Trace. */ bsu_trace_init (ctx); bsu_stats_init (ctx); @@ -1084,7 +1089,7 @@ bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon, FIXED (avln->sync.fe, BSU_NTB_FIXED_POINT); bsu_beacon->params.ntb_offset_tck = avln->sync.ntb_offset_tck; bsu_beacon->params.frequency_error_valid = - avln->sync.second_shoot; + avln->sync.sync_nb >= ctx->ntb_clk_sync_nb_stable; } } else diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c index 4ad6722117..8dfe19384b 100644 --- a/cesar/bsu/test/utest/src/bsut.c +++ b/cesar/bsu/test/utest/src/bsut.c @@ -20,6 +20,7 @@ #include "bsu/inc/bsu.h" #include "bsu/inc/context.h" #include "bsu/inc/interface.h" +#include "bsu/ntb/ntb.h" bsu_avln_t* bsu_avln_add (bsu_t *ctx, u64 nid, u8 snid, mac_t mac, bool *added); @@ -36,6 +37,8 @@ bsu_update__persistent_schedules (bsu_t *ctx, bsu_beacon_t *beacon); void test_case_bsu_process (test_t test) { + uint i; + uint central_beacon_nb_recv = 0; bsu_test_t t; bsu_test_init (&t); bsu_activate (t.bsu, true); @@ -73,6 +76,7 @@ test_case_bsu_process (test_t test) == 0); /* NTB called? */ test_fail_unless (t.bsu->avlns[0].sync.init == false); + test_fail_unless (t.bsu->avlns[0].sync.sync_nb == 0); /* => First neighbour beacon reception. */ bneighbour = bsu_beacon_write (&beacon_neighbour, BSU_BEACON_TYPE_CENTRAL, @@ -85,34 +89,46 @@ test_case_bsu_process (test_t test) test_fail_unless (t.bsu->avlns[0].snid == bpneighbour_rx.snid); test_fail_unless (t.bsu->avlns[0].beacon.vf.nid == beacon_neighbour.vf.nid); + central_beacon_nb_recv++; test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] - == 1); + == central_beacon_nb_recv); /* NTB called? */ test_fail_unless (t.bsu->avlns[0].sync.init == true); + test_fail_unless (t.bsu->avlns[0].sync.sync_nb == 0); test_fail_unless (!bprocessed->params.frequency_error_valid); /* Cleanup. */ blk_release (bprocessed); - /* => Second neighbour beacon reception. */ - bprocessed = bsu_beacon_process (t.bsu, bneighbour, &bpneighbour_rx); - /* Central beacon processed? */ - test_fail_unless (bprocessed); - test_fail_unless (t.bsu->avlns[0].snid == bpneighbour_rx.snid); - test_fail_unless (t.bsu->avlns[0].beacon.vf.nid - == beacon_neighbour.vf.nid); - test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] - == 2); - /* NTB called? */ - test_fail_unless (t.bsu->avlns[0].sync.init == true); - test_fail_unless (bprocessed->params.frequency_error_valid); + /* => Next neighbour beacon receptions. */ + for (i = 1; i <= BSU_NTB_CLK_SYNC_NB_STABLE_DEFAULT; i++) + { + bprocessed = bsu_beacon_process (t.bsu, bneighbour, + &bpneighbour_rx); + /* Central beacon processed? */ + test_fail_unless (bprocessed); + test_fail_unless (t.bsu->avlns[0].snid == bpneighbour_rx.snid); + test_fail_unless (t.bsu->avlns[0].beacon.vf.nid + == beacon_neighbour.vf.nid); + central_beacon_nb_recv++; + test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] + == central_beacon_nb_recv); + /* NTB called? */ + test_fail_unless (t.bsu->avlns[0].sync.init == true); + test_fail_unless (t.bsu->avlns[0].sync.sync_nb == i); + if (i == BSU_NTB_CLK_SYNC_NB_STABLE_DEFAULT) + test_fail_unless (bprocessed->params.frequency_error_valid); + else + test_fail_unless (!bprocessed->params.frequency_error_valid); + /* Cleanup. */ + blk_release (bprocessed); + } /* Cleanup. */ blk_release_desc ((blk_t*) bneighbour); - blk_release (bprocessed); /* => Our AVLN. */ bsu_track_avln (t.bsu, beacon_neighbour.vf.nid, 0x4, beacon_neighbour.vf.stei, beacon_neighbour.bmis.mac_address.mac_address); /* Reset synchronisation. */ - t.bsu->sta_avln->sync.init = false; + bsu_ntb_init (&t.bsu->sta_avln->sync); /* => Beacon with bad CRC. */ bsu_test_create_beacon (&t, &beacon); bp_rx.snid = 0x4; @@ -127,7 +143,7 @@ test_case_bsu_process (test_t test) test_fail_unless (t.bsu->sta_avln->snid == t.bsu->snid_track); test_fail_unless (t.bsu->sta_avln->beacon.vf.nid == t.bsu->nid_track); test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] - == 2); + == central_beacon_nb_recv); /* NTB called? */ test_fail_unless (t.bsu->sta_avln->sync.init == false); /* => First beacon reception. */ @@ -139,12 +155,13 @@ test_case_bsu_process (test_t test) test_fail_unless (bprocessed); test_fail_unless (t.bsu->sta_avln->snid == bp_rx.snid); test_fail_unless (t.bsu->sta_avln->beacon.vf.nid == beacon.vf.nid); + central_beacon_nb_recv++; test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] - == 3); + == central_beacon_nb_recv); /* NTB called? */ test_fail_unless (t.bsu->sta_avln->sync.init == true); - test_fail_unless (t.bsu->sta_avln->sync.second_shoot); - test_fail_unless (bprocessed->params.frequency_error_valid); + test_fail_unless (t.bsu->sta_avln->sync.sync_nb == 0); + test_fail_unless (!bprocessed->params.frequency_error_valid); /* Cleanup. */ blk_release_desc ((blk_t*) b); blk_release (bprocessed); @@ -179,8 +196,9 @@ test_case_bsu_process (test_t test) test_fail_unless (t.sar.mfs->common.lid == MAC_LID_DISCOVER); test_fail_unless (t.bsu->beacon_nb_sent [BSU_BEACON_TYPE_DISCOVER] == 1); + central_beacon_nb_recv += 2; test_fail_unless (t.bsu->beacon_nb_recv [BSU_BEACON_TYPE_CENTRAL] - == 5); + == central_beacon_nb_recv); /* Upper layer receives it ? */ test_fail_unless (t.ul.beacon); test_fail_unless (t.ul.beacon->next); -- cgit v1.2.3 From ec21f21c6c3c10d6ff72c8f5f04742ed3f815854 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 17 Aug 2011 17:04:28 +0200 Subject: cesar/bsu: change weight and sync_nb_stable, closes #572 According to http://stestephe/svn/spidcom_digital_svn/projects/DSP_350/DSP_chain/SW/Clock_Offset/Documentation/Specification/. --- cesar/bsu/ntb/ntb.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'cesar') diff --git a/cesar/bsu/ntb/ntb.h b/cesar/bsu/ntb/ntb.h index 52d1a0c397..3b1ff5e778 100644 --- a/cesar/bsu/ntb/ntb.h +++ b/cesar/bsu/ntb/ntb.h @@ -16,9 +16,9 @@ #include "mac/common/config.h" #include "hal/phy/phy.h" -#define BSU_NTB_CLK_SYNC_WEIGHT_K_DEFAULT 2 +#define BSU_NTB_CLK_SYNC_WEIGHT_K_DEFAULT 6 -#define BSU_NTB_CLK_SYNC_NB_STABLE_DEFAULT 1 +#define BSU_NTB_CLK_SYNC_NB_STABLE_DEFAULT 64 BEGIN_DECLS -- cgit v1.2.3 From 1da91abe7066745e4bacdcb34332bc2c543b5571 Mon Sep 17 00:00:00 2001 From: Cyril Jourdan Date: Thu, 1 Sep 2011 09:57:14 +0200 Subject: cesar/cp: change CP init sequence, closes #2693 Lib random was initialised at the end of the function whereas some previously executed functions needed it. --- cesar/cp/src/cp.c | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'cesar') diff --git a/cesar/cp/src/cp.c b/cesar/cp/src/cp.c index 372bbdeac3..7cdf39b7c9 100644 --- a/cesar/cp/src/cp.c +++ b/cesar/cp/src/cp.c @@ -61,6 +61,9 @@ cp_init (bsu_t *bsu, bsu_aclf_t* aclf, mac_config_t * mac_config, cp_global.bsu = bsu; cp_global.bsu_aclf = aclf; + /* Init the random generator. */ + lib_rnd_init (&cp_global.rnd, seed ^ 0x87543571); + /* Initialise traces. */ cp_trace_init (&cp_global); @@ -97,9 +100,6 @@ cp_init (bsu_t *bsu, bsu_aclf_t* aclf, mac_config_t * mac_config, /* Initialise the FSM. */ cp_fsm_init (&cp_global); - /* Init the random generator. */ - lib_rnd_init (&cp_global.rnd, seed ^ 0x87543571); - /* Init CE in TX. */ ce_tx_init (&cp_global); -- cgit v1.2.3 From ab462c20e326e0ab62a3e8b1e396862f0e6e8a77 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 24 Aug 2011 16:40:20 +0200 Subject: cesar/cl: fix bridge table replacement, closes #2664 Replacement should be atomic because it is done in CP context which can be interrupted by DSR. --- cesar/cl/src/bridge_table.c | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) (limited to 'cesar') diff --git a/cesar/cl/src/bridge_table.c b/cesar/cl/src/bridge_table.c index 21598d9f38..163919bd01 100644 --- a/cesar/cl/src/bridge_table.c +++ b/cesar/cl/src/bridge_table.c @@ -136,12 +136,11 @@ bridge_table_update (cl_t *ctx) /* The temporary local bridge is now empty. */ ctx->bridge_table.table_tmp_entry_count = 0; - /* Remove old table. */ - if (ctx->bridge_table.table) - mac_lookup_table_release (ctx->bridge_table.table); - - /* Affect new local bridge table. */ + /* Atomically replace local bridge table. */ + mac_lookup_table_t *old_table = ctx->bridge_table.table; ctx->bridge_table.table = mac_lookup_table_convert (new_bridge_table); + if (old_table) + mac_lookup_table_release (old_table); /* Bridge table has been modified. */ return true; @@ -163,12 +162,11 @@ bridge_table_update (cl_t *ctx) 0xFFFF, ctx->bridge_table.cycle_counter); - /* Remove old table. */ - mac_lookup_table_release (ctx->bridge_table.table); - /* Affect new local bridge table. */ + mac_lookup_table_t *old_table = ctx->bridge_table.table; ctx->bridge_table.table = mac_lookup_table_convert (new_bridge_table); + mac_lookup_table_release (old_table); /* Bridge table has been modified. */ return true; -- cgit v1.2.3 From b850ddd69b08e5564eedddfe393c7f2e833f71c2 Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Wed, 31 Aug 2011 17:32:09 +0200 Subject: cesar/ce/rx/bl: move NSR rescale define in a public header, refs #2619 --- cesar/ce/rx/bitloading/inc/ber.h | 6 ------ cesar/ce/rx/bitloading/nsr.h | 24 ++++++++++++++++++++++++ cesar/ce/rx/bitloading/src/nsr.c | 3 ++- cesar/ce/rx/bitloading/test/src/test_bl.c | 3 ++- 4 files changed, 28 insertions(+), 8 deletions(-) create mode 100644 cesar/ce/rx/bitloading/nsr.h (limited to 'cesar') diff --git a/cesar/ce/rx/bitloading/inc/ber.h b/cesar/ce/rx/bitloading/inc/ber.h index d1182233f9..3184bbac4c 100644 --- a/cesar/ce/rx/bitloading/inc/ber.h +++ b/cesar/ce/rx/bitloading/inc/ber.h @@ -50,12 +50,6 @@ */ #define CE_RX_BL_BPT_QUANT_FACTOR (1ull << 8) -/** - * NSR must be rescaled before used by BER vs polynomials. - * Rescaling is not the same if NSR is based on sound or data. - */ -#define CE_RX_BL_BER_NSR_SOUND_RESCALE (2) - /** * Polynomials for each modulation to compute BER. */ diff --git a/cesar/ce/rx/bitloading/nsr.h b/cesar/ce/rx/bitloading/nsr.h new file mode 100644 index 0000000000..6d4a9a824c --- /dev/null +++ b/cesar/ce/rx/bitloading/nsr.h @@ -0,0 +1,24 @@ +#ifndef ce_rx_bitloading_nsr_h +#define ce_rx_bitloading_nsr_h +/* Cesar project {{{ + * + * Copyright (C) 2011 Spidcom + * + * <<>> + * + * }}} */ +/** + * \file ce/rx/bitloading/nsr.h + * \brief Public data + * \ingroup ce_rx_bl + * + * This file contains the information related to NSR. + */ + +/** + * NSR must be rescaled before used by BER vs polynomials. + * Rescaling is not the same if NSR is based on sound or data. + */ +#define CE_RX_BL_NSR_SOUND_RESCALE (2) + +#endif /* ce_rx_bitloading_nsr_h */ diff --git a/cesar/ce/rx/bitloading/src/nsr.c b/cesar/ce/rx/bitloading/src/nsr.c index 8d2cae1d19..4b4c2b14ba 100644 --- a/cesar/ce/rx/bitloading/src/nsr.c +++ b/cesar/ce/rx/bitloading/src/nsr.c @@ -13,6 +13,7 @@ #include "common/std.h" #include "ce/rx/bitloading/inc/nsr.h" +#include "ce/rx/bitloading/nsr.h" #include "ce/rx/bitloading/inc/ber.h" #include "hal/phy/defs.h" @@ -168,7 +169,7 @@ ce_rx_bl_nsr_compute_mean (ce_rx_bitloading_t *bl) /* Compute mean and rescale (for NSR dynamics). */ cur_sum_nsr[j] = ce_rx_bl_nsr_mean (cur_sum_nsr[j], bl->mean_count) - * CE_RX_BL_BER_NSR_SOUND_RESCALE + * CE_RX_BL_NSR_SOUND_RESCALE * ce_rx_bl_nsr_margin_ / CE_RX_BL_NSR_MARGIN_QUANT_FACTOR; } /* Next block. */ diff --git a/cesar/ce/rx/bitloading/test/src/test_bl.c b/cesar/ce/rx/bitloading/test/src/test_bl.c index 5a1e410d5d..0fabe28917 100644 --- a/cesar/ce/rx/bitloading/test/src/test_bl.c +++ b/cesar/ce/rx/bitloading/test/src/test_bl.c @@ -22,6 +22,7 @@ #include "ce/rx/bitloading/inc/bitloading.h" #include "ce/rx/bitloading/bitloading.h" #include "ce/rx/bitloading/inc/common.h" +#include "ce/rx/bitloading/nsr.h" #include "lib/rnd.h" /* Test vectors. */ @@ -1936,7 +1937,7 @@ main (int argc, char **argv) uint i; for (i = 0; i < mean_on_sound_nsr_height; i++) - mean_on_sound_nsr[i][0] *= CE_RX_BL_BER_NSR_SOUND_RESCALE; + mean_on_sound_nsr[i][0] *= CE_RX_BL_NSR_SOUND_RESCALE; /* BER target margin. */ test_suite_ce_rx_bl_ber_target_margin (t); -- cgit v1.2.3 From 76fc594b7be3d657b8440f4fa2aa2e3f461f3ba6 Mon Sep 17 00:00:00 2001 From: Jérémy Dufour Date: Wed, 31 Aug 2011 17:40:15 +0200 Subject: cesar/cp/sta/action: rescale SNR in VS_GET_SNR, refs #2619 --- cesar/cp/sta/action/src/vs.c | 5 +++-- cesar/cp/sta/action/test/utest/src/vs.c | 2 ++ 2 files changed, 5 insertions(+), 2 deletions(-) (limited to 'cesar') diff --git a/cesar/cp/sta/action/src/vs.c b/cesar/cp/sta/action/src/vs.c index 1daf2482af..29c5216e82 100644 --- a/cesar/cp/sta/action/src/vs.c +++ b/cesar/cp/sta/action/src/vs.c @@ -19,6 +19,7 @@ #include "cp/inc/context.h" #include "mac/common/tonemap.h" #include "cp/sta/action/misc.h" +#include "ce/rx/bitloading/nsr.h" /** * Handle STARTED => VS_GET_TONEMAP.REQ. @@ -229,8 +230,8 @@ cp_sta_action_vs__started__vs_get_snr_req (cp_t *ctx, cp_mme_rx_t *mme) carrier_gr) { data_to_send.snr[grp_snr_index] = - data[(all_snr_index - PHY_CARRIER_OFFSET) % - (BLK_SIZE/4)]; + (data[(all_snr_index - PHY_CARRIER_OFFSET) % + (BLK_SIZE/4)]) / CE_RX_BL_NSR_SOUND_RESCALE; grp_snr_index++; } } diff --git a/cesar/cp/sta/action/test/utest/src/vs.c b/cesar/cp/sta/action/test/utest/src/vs.c index 279d0e8205..a1b2f4dc0f 100644 --- a/cesar/cp/sta/action/test/utest/src/vs.c +++ b/cesar/cp/sta/action/test/utest/src/vs.c @@ -13,6 +13,7 @@ #include "common/std.h" #include "lib/scenario/scenario.h" #include "inc/test_sta_action.h" +#include "ce/rx/bitloading/nsr.h" blk_t* nsr_block; @@ -171,6 +172,7 @@ vs_get_snr_test_case (test_t t) { snr[i] = -(i * CP_MSG_VS_GET_SNR_REQ_CARRIER_GR_NB + group - PHY_CARRIER_OFFSET); + snr[i] /= CE_RX_BL_NSR_SOUND_RESCALE; } else snr[i] = 0; -- cgit v1.2.3 From 5d283aa7b734eadd27d14adf5c5b51b90ab5bd28 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Fri, 9 Sep 2011 11:59:30 +0200 Subject: cesar/hal/phy/maximus: add phy_freq_error_set empty stub, refs #572 --- cesar/hal/phy/maximus/src/maximus_phy_ctrl.c | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'cesar') diff --git a/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c b/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c index ea7bdc61fc..f9d6b3fcb8 100644 --- a/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c +++ b/cesar/hal/phy/maximus/src/maximus_phy_ctrl.c @@ -2311,6 +2311,14 @@ phy_clock_get_zero_cross_captured_sysdate (phy_t *ctx) } +void +phy_freq_error_set (phy_t *ctx, bool sync, s32 rho_q30) +{ + dbg_assert_ptr (ctx); + /* Ignored. */ +} + + /** * set errno to: * - EINVAL if ctx is null -- cgit v1.2.3 From b861dc5f94370f3d29e5c5b3bf182a62fc5a63da Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 31 Aug 2011 17:25:17 +0200 Subject: cesar/lib/test/fixed: fix compiler warning --- cesar/lib/test/fixed/src/test_fixed.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'cesar') diff --git a/cesar/lib/test/fixed/src/test_fixed.c b/cesar/lib/test/fixed/src/test_fixed.c index 9b3ff3a8c8..15fe7ca3e0 100644 --- a/cesar/lib/test/fixed/src/test_fixed.c +++ b/cesar/lib/test/fixed/src/test_fixed.c @@ -36,30 +36,30 @@ void asm_fixed_mul (void) { - volatile s32 a, b, r; - volatile uint shift; + volatile s32 a = 0, b = 0, r; + volatile uint shift = 0; r = fixed_mul (a, b, shift); } void asm_fixed_mul_2 (void) { - volatile s32 a, b, r; + volatile s32 a = 0, b = 0, r; r = fixed_mul (a, b, 24); } void asm_fixed_div (void) { - volatile s32 a, b, r; - volatile uint shift; + volatile s32 a = 0, b = 0, r; + volatile uint shift = 0; r = fixed_div (a, b, shift); } void asm_fixed_div_2 (void) { - volatile s32 a, b, r; + volatile s32 a = 0, b = 0, r; r = fixed_div (a, b, 24); } -- cgit v1.2.3 From bd14de951af05fc41c4fb01dcb148bd87faf203a Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 31 Aug 2011 17:26:53 +0200 Subject: cesar/lib/test/head: fix compiler warning --- cesar/lib/test/heap/src/test_heap.c | 2 ++ 1 file changed, 2 insertions(+) (limited to 'cesar') diff --git a/cesar/lib/test/heap/src/test_heap.c b/cesar/lib/test/heap/src/test_heap.c index 20e0d9ac14..b9be79feff 100644 --- a/cesar/lib/test/heap/src/test_heap.c +++ b/cesar/lib/test/heap/src/test_heap.c @@ -94,7 +94,9 @@ heap_check (test_t t, heap_t *heap) static void heap_stats (test_t t, heap_t *heap, uint *min, uint *max, unsigned long long *sum) { +#if CONFIG_HEAP_LEFTIST test_within (t); +#endif heap_node_t *n; uint path_length; #if CONFIG_HEAP_LEFTIST -- cgit v1.2.3 From f452a51eb890b0e8c80b0c8075d40d417d55286e Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 31 Aug 2011 17:28:53 +0200 Subject: cesar/mac/design/test/mfs_tx2: fix compiler warning --- cesar/mac/design/test/mfs_tx2/src/test_mfs.c | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'cesar') diff --git a/cesar/mac/design/test/mfs_tx2/src/test_mfs.c b/cesar/mac/design/test/mfs_tx2/src/test_mfs.c index 7336db2b9b..6031799420 100644 --- a/cesar/mac/design/test/mfs_tx2/src/test_mfs.c +++ b/cesar/mac/design/test/mfs_tx2/src/test_mfs.c @@ -72,7 +72,7 @@ void random_test() test.when_to_free=lib_rnd_uniform(&rnd,0x2000); } -mfs_t +void init_mfs () { mfs.head = NULL; @@ -87,7 +87,6 @@ init_mfs () total_pb_released=0; pbproc.head_tx=NULL; pbproc.tail_tx=NULL; - return (mfs); } @@ -546,7 +545,7 @@ tst(void) { int n=0; int zadded=0; - mfs=init_mfs(); + init_mfs(); printf("take:%x free: %x\n", test.when_to_take,test.when_to_free); for(n=0; n<10; n++) { @@ -569,7 +568,7 @@ int main (void) { lib_rnd_init (&rnd, 456); - mfs_t mfs = init_mfs(); + init_mfs(); test.when_to_take=0; test.when_to_free=0; int t=0; -- cgit v1.2.3 From 5451bf66bdcb8d60af93adf389c807d9abfafe9d Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Wed, 31 Aug 2011 17:33:05 +0200 Subject: cesar/ce/rx/bitloading: fix duplicate const --- cesar/ce/rx/bitloading/inc/poly.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'cesar') diff --git a/cesar/ce/rx/bitloading/inc/poly.h b/cesar/ce/rx/bitloading/inc/poly.h index 5b56bc8c85..ae35acbea9 100644 --- a/cesar/ce/rx/bitloading/inc/poly.h +++ b/cesar/ce/rx/bitloading/inc/poly.h @@ -36,7 +36,7 @@ BEGIN_DECLS * Therefore, implementation uses the second forms of the polynomial. */ extern inline s64 -ce_rx_bl_poly (const u8 degree, const s64 const *coef, const u32 x) +ce_rx_bl_poly (const u8 degree, const s64 * const coef, const u32 x) { /* Check parameter. */ dbg_assert (coef); -- cgit v1.2.3 From 6d0e61c1c87970f99ce433b3a409f72bbebefca0 Mon Sep 17 00:00:00 2001 From: Nicolas Schodet Date: Tue, 23 Aug 2011 14:45:36 +0200 Subject: cesar: add easy trace compilation thanks to ilram priority, refs #2613 Priority is used to evict selected functions from ilram when code size is too large. To compile project/plc with traces, do: make PROJECT_CONFIG=Config.traces --- cesar/common/tests/tests | 4 ++++ cesar/hal/arch/Config | 1 + cesar/hal/arch/arch.h | 10 ++++++++++ cesar/hal/arch/inc/sparc.h | 26 ++++++++++++++++++++++++++ cesar/mac/pbproc/src/fsm_rx_sound.c | 6 +++--- cesar/mac/pbproc/src/fsm_tx_sound.c | 6 +++--- cesar/mac/pbproc/src/prep_mpdu.c | 2 +- cesar/mac/pbproc/test/int/sparc-Config | 1 + cesar/mac/sar/src/sar.c | 2 +- cesar/projects/plc/Config.traces | 10 ++++++++++ 10 files changed, 60 insertions(+), 8 deletions(-) create mode 100644 cesar/hal/arch/Config create mode 100644 cesar/projects/plc/Config.traces (limited to 'cesar') diff --git a/cesar/common/tests/tests b/cesar/common/tests/tests index b83bb8d1ff..83a7fe56b5 100644 --- a/cesar/common/tests/tests +++ b/cesar/common/tests/tests @@ -500,3 +500,7 @@ bsu/ntb: ./obj/ntb bsu/aclf/test/utest: make bsu/aclf: ./obj/aclf + +projects/plc: +make +make traces: make PROJECT_CONFIG=Config.traces diff --git a/cesar/hal/arch/Config b/cesar/hal/arch/Config new file mode 100644 index 0000000000..5d46bd1570 --- /dev/null +++ b/cesar/hal/arch/Config @@ -0,0 +1 @@ +CONFIG_ARCH_ILRAM_PRIO = 5 diff --git a/cesar/hal/arch/arch.h b/cesar/hal/arch/arch.h index 81aae83a8e..a1ad0d96fa 100644 --- a/cesar/hal/arch/arch.h +++ b/cesar/hal/arch/arch.h @@ -20,6 +20,16 @@ */ #define ARCH_ILRAM +/** + * Put in the instruction local ram section, with lower priority. + * \param prio function priority + * + * Should be put between function return type and function name. Function + * will be included in local ram only if priority is lower than or equal to + * configured limit. + */ +#define ARCH_ILRAM_PRIO(prio) + /** * Put in the data local ram section. */ diff --git a/cesar/hal/arch/inc/sparc.h b/cesar/hal/arch/inc/sparc.h index 03f8dcab86..beafd42c3b 100644 --- a/cesar/hal/arch/inc/sparc.h +++ b/cesar/hal/arch/inc/sparc.h @@ -17,9 +17,35 @@ #if defined (ECOS) && ECOS +# include "config/arch/ilram.h" + # undef ARCH_ILRAM # define ARCH_ILRAM __attribute__ ((section (".ilram"))) +# undef ARCH_ILRAM_PRIO +# define ARCH_ILRAM_PRIO(prio) PASTE (ARCH_ILRAM_PRIO_, prio) + +# if CONFIG_ARCH_ILRAM_PRIO >= 3 +# define ARCH_ILRAM_PRIO_3 ARCH_ILRAM +# else +# define ARCH_ILRAM_PRIO_3 +# endif +# if CONFIG_ARCH_ILRAM_PRIO >= 2 +# define ARCH_ILRAM_PRIO_2 ARCH_ILRAM +# else +# define ARCH_ILRAM_PRIO_2 +# endif +# if CONFIG_ARCH_ILRAM_PRIO >= 1 +# define ARCH_ILRAM_PRIO_1 ARCH_ILRAM +# else +# define ARCH_ILRAM_PRIO_1 +# endif +# if CONFIG_ARCH_ILRAM_PRIO >= 0 +# define ARCH_ILRAM_PRIO_0 ARCH_ILRAM +# else +# define ARCH_ILRAM_PRIO_0 +# endif + # undef ARCH_DLRAM_DATA # define ARCH_DLRAM_DATA __attribute__ ((section (".dlram_data"))) diff --git a/cesar/mac/pbproc/src/fsm_rx_sound.c b/cesar/mac/pbproc/src/fsm_rx_sound.c index 1bdf4548b9..7f2cc83846 100644 --- a/cesar/mac/pbproc/src/fsm_rx_sound.c +++ b/cesar/mac/pbproc/src/fsm_rx_sound.c @@ -33,7 +33,7 @@ pbproc_frso_init (pbproc_t *ctx) pbproc_frso__rx_sound__pbdma; } -void ARCH_ILRAM +void ARCH_ILRAM_PRIO (2) pbproc_frso__handle (pbproc_t *ctx, u32 rx_date, const pbproc_fc_sound_t *sound) { @@ -170,7 +170,7 @@ pbproc_frso__handle (pbproc_t *ctx, u32 rx_date, pbproc_frso__rx_sound__pbdma (ctx); } -void ARCH_ILRAM +void ARCH_ILRAM_PRIO (2) pbproc_frso__rx_sound__pbdma (pbproc_t *ctx) { dbg_claim (ctx); @@ -235,7 +235,7 @@ pbproc_frso__rx_sound__pbdma (pbproc_t *ctx) pbproc_fsm_change_state (ctx, PBPROC_FSM_STATE_IDLE); } -static void ARCH_ILRAM +static void ARCH_ILRAM_PRIO (2) pbproc_frso_vcs_restart (pbproc_t *ctx) { dbg_claim (ctx); diff --git a/cesar/mac/pbproc/src/fsm_tx_sound.c b/cesar/mac/pbproc/src/fsm_tx_sound.c index 3a694cffdc..4308b71749 100644 --- a/cesar/mac/pbproc/src/fsm_tx_sound.c +++ b/cesar/mac/pbproc/src/fsm_tx_sound.c @@ -32,7 +32,7 @@ pbproc_ftso_init (pbproc_t *ctx) pbproc_ftso__tx_sound_wait_ack__access; } -void ARCH_ILRAM +void ARCH_ILRAM_PRIO (2) pbproc_ftso__handle (pbproc_t *ctx) { dbg_claim (ctx); @@ -50,7 +50,7 @@ pbproc_ftso__handle (pbproc_t *ctx) ctx->stats.tx_sound++; } -void ARCH_ILRAM +void ARCH_ILRAM_PRIO (2) pbproc_ftso__tx_sound_wait_ack__rx_fc (pbproc_t *ctx, u32 rx_date, const pbproc_fc_t *fc_av) { @@ -98,7 +98,7 @@ pbproc_ftso__tx_sound_wait_ack__rx_fc (pbproc_t *ctx, u32 rx_date, } } -void ARCH_ILRAM +void ARCH_ILRAM_PRIO (2) pbproc_ftso__tx_sound_wait_ack__access (pbproc_t *ctx) { dbg_claim (ctx); diff --git a/cesar/mac/pbproc/src/prep_mpdu.c b/cesar/mac/pbproc/src/prep_mpdu.c index 5bf45befb1..411ba4707d 100644 --- a/cesar/mac/pbproc/src/prep_mpdu.c +++ b/cesar/mac/pbproc/src/prep_mpdu.c @@ -85,7 +85,7 @@ pbproc_prep_mpdu_init (pbproc_t *ctx) slist_init (prep->main_commit_return_); } -void ARCH_ILRAM +void ARCH_ILRAM_PRIO (1) pbproc_prep_beacon (pbproc_t *ctx, mfs_tx_t *mfs) { ca_access_param_t *access; diff --git a/cesar/mac/pbproc/test/int/sparc-Config b/cesar/mac/pbproc/test/int/sparc-Config index fc03d019b6..c9c832ab38 100644 --- a/cesar/mac/pbproc/test/int/sparc-Config +++ b/cesar/mac/pbproc/test/int/sparc-Config @@ -2,3 +2,4 @@ CONFIG_TRACE = y CONFIG_DEBUG_CLAIM = n CONFIG_STATS = n CONFIG_INTERFACE_SNIFFER = n +CONFIG_ARCH_ILRAM_PRIO = 0 diff --git a/cesar/mac/sar/src/sar.c b/cesar/mac/sar/src/sar.c index 4edf0ccb52..7849e22ad1 100644 --- a/cesar/mac/sar/src/sar.c +++ b/cesar/mac/sar/src/sar.c @@ -1818,7 +1818,7 @@ sar_tx_mac_framing (sar_t *ctx, sar_msdu_t *md_data) &ctx->job_tx->job); } -pb_t * ARCH_ILRAM +pb_t * ARCH_ILRAM_PRIO (1) sar_tx_job_desc_create (sar_t *ctx, sar_msdu_t *md_data, mfs_tx_t * mfs, sar_job_mfs_t *job_mfs) { diff --git a/cesar/projects/plc/Config.traces b/cesar/projects/plc/Config.traces new file mode 100644 index 0000000000..cb793a0b04 --- /dev/null +++ b/cesar/projects/plc/Config.traces @@ -0,0 +1,10 @@ +CONFIG_DEBUG_CLAIM = n +CONFIG_BLK_NB = 6144 +CONFIG_GPIO_LED_TRAFFIC = y +CONFIG_BLK_SLACK = 512 +CONFIG_STATS_ON_FATAL = y + +CONFIG_TRACE = y +CONFIG_TRACE_ON_FATAL = y +CONFIG_TRACE_ALL_FAST = y +CONFIG_ARCH_ILRAM_PRIO = 0 -- cgit v1.2.3