summaryrefslogtreecommitdiff
path: root/cesar/bsu
diff options
context:
space:
mode:
authorlaranjeiro2010-06-04 07:46:38 +0000
committerlaranjeiro2010-06-04 07:46:38 +0000
commit2f19026fa8316c0e0ab32842950edf31aea44de5 (patch)
tree8dfcaa65400caef4899b8f0527130b219ed20953 /cesar/bsu
parentb07ca76109753d3648fb832f44400a2e4a508c91 (diff)
cesar/{cp, bsu}: fix discover procedure request
* BSU send a discover beacon when the CCo requests it. * Discover interval is recomputed each time the previous discover round is over. * cco/action will not call discover functions git-svn-id: svn+ssh://pessac/svn/cesar/trunk@7163 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'cesar/bsu')
-rw-r--r--cesar/bsu/beacon/beacon.h4
-rw-r--r--cesar/bsu/beacon/src/beacon.c6
-rw-r--r--cesar/bsu/beacon/test/utest/src/beacon.c6
-rw-r--r--cesar/bsu/src/bsu.c61
-rw-r--r--cesar/bsu/test/utest/src/bsut.c65
-rw-r--r--cesar/bsu/test/utest/src/tests.c2
6 files changed, 116 insertions, 28 deletions
diff --git a/cesar/bsu/beacon/beacon.h b/cesar/bsu/beacon/beacon.h
index c0d54692e4..d0142fae0f 100644
--- a/cesar/bsu/beacon/beacon.h
+++ b/cesar/bsu/beacon/beacon.h
@@ -197,10 +197,12 @@ bsu_beacon_write (bsu_beacon_t *beacon, bsu_beacon_type_t type,
* the CA.
* \param beacon the beacon received from the medium.
* \param schedules schedules structure to store the data.
+ * \param discover the discover structure to store discover data.
*/
void
bsu_beacon_read_schedules (pb_beacon_t *beacon,
- bsu_beacon_schedules_t *schedules);
+ bsu_beacon_schedules_t *schedules,
+ bsu_beacon_bmi_discover_t *discover);
/**
* Read the whole beacon and store the data into the beacon structure.
diff --git a/cesar/bsu/beacon/src/beacon.c b/cesar/bsu/beacon/src/beacon.c
index 43e70c0673..d29f63274a 100644
--- a/cesar/bsu/beacon/src/beacon.c
+++ b/cesar/bsu/beacon/src/beacon.c
@@ -1000,7 +1000,8 @@ bsu_beacon_countdown (bsu_beacon_t *beacon)
void
bsu_beacon_read_schedules (pb_beacon_t *beacon,
- bsu_beacon_schedules_t *schedules)
+ bsu_beacon_schedules_t *schedules,
+ bsu_beacon_bmi_discover_t *discover)
{
bitstream_t stream;
uint i, j, nbe, nb_persistent = 0;
@@ -1054,6 +1055,9 @@ bsu_beacon_read_schedules (pb_beacon_t *beacon,
for (j = hm.hmccd; j < COUNT (schedules->hm); j++)
schedules->hm[j] = hm.newhm;
break;
+ case BSU_BEACON_ENTRY_HEADER_DISCOVER:
+ bsu_beacon_read_bmi_discover (&stream, discover);
+ break;
default:
/* skip entry. */
bitstream_skip (&stream, length * 8);
diff --git a/cesar/bsu/beacon/test/utest/src/beacon.c b/cesar/bsu/beacon/test/utest/src/beacon.c
index 61e39dad50..28f806e0fb 100644
--- a/cesar/bsu/beacon/test/utest/src/beacon.c
+++ b/cesar/bsu/beacon/test/utest/src/beacon.c
@@ -58,8 +58,12 @@ test_case_beacon_write_read (test_t t)
test_end;
test_begin (t, "Read central beacon")
{
- bsu_beacon_read_schedules (pbbeacon, &schedules);
+ bsu_beacon_bmi_discover_t discover;
+ discover.present = false;
+ bsu_beacon_read_schedules (pbbeacon, &schedules, &discover);
bsu_beacon_test_beacon_check_read (t, &beacon, &schedules);
+ test_fail_unless (beacon.bmis.discover.present == discover.present);
+ test_fail_unless (beacon.bmis.discover.tei == discover.tei);
}
test_end;
test_begin (t, "Read completely")
diff --git a/cesar/bsu/src/bsu.c b/cesar/bsu/src/bsu.c
index a56f47b775..d8ddb5718c 100644
--- a/cesar/bsu/src/bsu.c
+++ b/cesar/bsu/src/bsu.c
@@ -347,6 +347,23 @@ bsu_avln_schedules_decrease_countdown (bsu_t *ctx, bsu_avln_t *avln)
}
/**
+ * Create the beacon to be send over the PLC.
+ * \param ctx the module context.
+ * \param type the beacon type.
+ */
+static void
+bsu_beacon_send_prepare (bsu_t *ctx, bsu_beacon_type_t type)
+{
+ pb_beacon_t *beacon;
+ pbproc_tx_beacon_params_t params;
+ bsu_aclf_bto (ctx->aclf, (s16*) params.bto, COUNT (params.bto));
+ beacon = bsu_beacon_write (&ctx->beacon, type,
+ ctx->mac_config, &params);
+ /* Send the beacon. */
+ bsu_beacon_send (ctx, type, beacon, &params);
+}
+
+/**
* BSU timer expires.
* \param ud the module context.
*
@@ -367,32 +384,21 @@ bsu_timer_event_process (void *ud)
bsu_avln_schedules_decrease_countdown (ctx, ctx->sta_avln);
else
{
- pb_beacon_t *beacon;
- pbproc_tx_beacon_params_t params;
- bsu_aclf_bto (ctx->aclf, (s16*) params.bto, COUNT (params.bto));
/* Are update data late ?. */
if (less_mod2p32 (ctx->beacon.beacon_period_start_date, bpsd[0]))
/* Create and send the beacon. */
bsu_beacon_countdown (&ctx->beacon);
if (ctx->is_sta == BSU_UPDATE_STA_TYPE_CCO)
- {
- beacon = bsu_beacon_write (&ctx->beacon,
- BSU_BEACON_TYPE_CENTRAL,
- ctx->mac_config, &params);
- /* Send the beacon. */
- bsu_beacon_send (ctx, BSU_BEACON_TYPE_CENTRAL, beacon,
- &params);
- }
+ bsu_beacon_send_prepare (ctx, BSU_BEACON_TYPE_CENTRAL);
if (ctx->is_sta == BSU_UPDATE_STA_TYPE_UCCO
|| (ctx->beacon.bmis.discover.present
&& ctx->beacon.bmis.discover.tei == ctx->mac_config->tei))
{
- beacon = bsu_beacon_write (&ctx->beacon,
- BSU_BEACON_TYPE_DISCOVER,
- ctx->mac_config, &params);
- /* Send the beacon. */
- bsu_beacon_send (ctx, BSU_BEACON_TYPE_DISCOVER, beacon,
- &params);
+ bsu_beacon_send_prepare (ctx, BSU_BEACON_TYPE_DISCOVER);
+ /* Not UCCo discover beacon had been sent set the flag to
+ * false to avoid to resend a discover beacon on next wake up. */
+ if (ctx->is_sta != BSU_UPDATE_STA_TYPE_UCCO)
+ ctx->beacon.bmis.discover.present = false;
}
}
bsu_ca_schedules (ctx, ctx->sta_avln);
@@ -479,6 +485,7 @@ bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon,
!((pb_t *) beacon)->phy_pb.pb_rx.pb_measurement.crc_error;
if (crc_ok)
{
+ bsu_beacon_bmi_discover_t discover;
bsu_beacon_track_info_t tinfo;
bsu_beacon_read_track_info (beacon, &tinfo);
/* It the beacon from our AVLN ? */
@@ -488,8 +495,10 @@ bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon,
&& ((ctx->tei_track == tinfo.tei
&& tinfo.bt == BSU_BEACON_TYPE_CENTRAL)
|| (ctx->tei_track == MAC_TEI_UNASSOCIATED
- && tinfo.bt == BSU_BEACON_TYPE_DISCOVER)))
+ && tinfo.bt == BSU_BEACON_TYPE_DISCOVER
+ && ctx->is_sta != BSU_UPDATE_STA_TYPE_CCO)))
{
+ discover.present = false;
dbg_assert (ctx->is_sta == BSU_UPDATE_STA_TYPE_STA);
dbg_assert ((tinfo.bt == BSU_BEACON_TYPE_DISCOVER
&& tinfo.tei == MAC_TEI_UNASSOCIATED)
@@ -500,7 +509,8 @@ bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon,
ctx->sta_avln->bs.snid = params->snid;
ctx->sta_avln->bs.schedules.bpsto.bpsto = 0;
ctx->sta_avln->bs.schedules.bpsto.present = false;
- bsu_beacon_read_schedules (beacon, &ctx->sta_avln->bs.schedules);
+ bsu_beacon_read_schedules (beacon, &ctx->sta_avln->bs.schedules,
+ &discover);
if (ctx->sta_avln->bs.schedules.bpsto.present)
bpsto = ctx->sta_avln->bs.schedules.bpsto.bpsto;
/* NTB synchronisation. */
@@ -520,22 +530,27 @@ bsu_beacon_process (bsu_t *ctx, pb_beacon_t *beacon,
ctx, bsu_aclf_beacon_period_start_date_next (ctx->aclf));
BSU_TRACE (BEACON_PROCESS, phy_date (), params->snid, tinfo.tei,
tinfo.bt, ctx->sta_avln->sync.ntb_offset_tck);
+ /* A discover beacon had been requested ? */
+ if (discover.present && discover.tei == ctx->mac_config->tei)
+ bsu_beacon_send_prepare (ctx, BSU_BEACON_TYPE_DISCOVER);
}
else
{
bsu_avln_t *avln;
avln = bsu_avln_add (ctx, tinfo.nid, params->snid);
- if (avln)
+ /* Other AVLN. */
+ if (avln && avln != ctx->sta_avln)
{
- bsu_beacon_read_schedules (beacon, &avln->bs.schedules);
+ bsu_beacon_read_schedules (beacon, &avln->bs.schedules,
+ &discover);
avln->bs.schedules.snid[0] = params->snid;
/* NTB synchronisation. */
bsu_ntb_clk_sync (&avln->sync, ctx->phy,
params->bts, params->preamble_sysdate,
params->preamble_date);
+ BSU_TRACE (BEACON_PROCESS, phy_date (), params->snid,
+ tinfo.tei, avln ? avln->sync.ntb_offset_tck : 0);
}
- BSU_TRACE (BEACON_PROCESS, phy_date (), params->snid, tinfo.tei,
- avln ? avln->sync.ntb_offset_tck : 0);
}
}
else
diff --git a/cesar/bsu/test/utest/src/bsut.c b/cesar/bsu/test/utest/src/bsut.c
index e78324c15f..616c9618e8 100644
--- a/cesar/bsu/test/utest/src/bsut.c
+++ b/cesar/bsu/test/utest/src/bsut.c
@@ -18,6 +18,7 @@
#include <string.h>
#include "bsu/inc/bsu.h"
#include "bsu/inc/context.h"
+#include "bsu/inc/interface.h"
void
bsu_timer_event_process (void *ud);
@@ -37,7 +38,6 @@ test_case_bsu_process (test_t test)
test_case_begin (test, "BSU process");
test_begin (test, "Process function on neighbour beacon")
{
- t.bsu->sta_avln = &t.bsu->avlns[0];
bsu_beacon_t beacon_neighbour;
pb_beacon_t *bneighbour;
bsu_beacon_t beacon;
@@ -82,6 +82,7 @@ test_case_bsu_process (test_t test)
test_fail_unless (t.bsu->avlns[0].sync.beacon_nb == 2);
blk_release_desc ((blk_t*) bneighbour);
/* Our AVLN. */
+ t.mac_config.tei = 1;
bsu_track_avln (0x2, 0x5, t.mac_config.tei,
MAC_COEXISTENCE_AV_ONLY_MODE);
bsu_test_create_beacon (&t, &beacon);
@@ -110,6 +111,67 @@ test_case_bsu_process (test_t test)
blk_release_desc ((blk_t*) b);
}
test_end;
+ test_begin (test, "Central beacon received with discover request")
+ {
+ bsu_beacon_t beacon;
+ bsu_test_create_beacon (&t, &beacon);
+ pb_beacon_t *b;
+ pbproc_tx_beacon_params_t btx;
+ pbproc_rx_beacon_params_t brx;
+ brx.snid = 0x2;
+ b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL, &t.mac_config,
+ &btx);
+ /* Change MAC config TEI for the test. */
+ bsu_beacon_track_info_t tinfo;
+ bsu_beacon_read_track_info (b, &tinfo);
+ bsu_track_avln (tinfo.nid, brx.snid, tinfo.tei, beacon.vf.hm);
+ t.mac_config.tei = beacon.bmis.discover.tei;
+ memset (&t.sar, 0, sizeof (bsu_test_sar_t));
+ bsu_test_upper_layer_beacon_received_init (&t);
+ bsu_beacon_recv (t.bsu, b, &brx);
+ /* Discover beacon sent ? */
+ test_fail_unless (t.sar.beacon != NULL);
+ test_fail_unless (t.sar.mfs != NULL);
+ test_fail_unless (t.sar.mfs->common.lid == MAC_LID_DISCOVER);
+ /* Upper layer receives it ? */
+ test_fail_unless (t.ul.beacon == t.sar.beacon);
+ test_fail_unless (t.ul.beacon->next);
+ blk_release_desc ((blk_t*) t.ul.beacon->next);
+ blk_release_desc ((blk_t*) t.ul.beacon);
+ }
+ test_end;
+ bsu_test_uninit (&t);
+}
+
+void
+test_case_bsu_process_sta_is_cco (test_t test)
+{
+ test_case_begin (test, "STA is CCO");
+ bsu_test_t t;
+ bsu_test_init (&t);
+ test_begin (test, "Receive Discover beacon")
+ {
+ bsu_beacon_t beacon;
+ bsu_test_create_beacon (&t, &beacon);
+ bsu_update (&beacon, BSU_UPDATE_STA_TYPE_CCO);
+ pb_beacon_t *b;
+ pbproc_tx_beacon_params_t btx;
+ pbproc_rx_beacon_params_t brx;
+ brx.snid = 0x2;
+ b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_CENTRAL, &t.mac_config,
+ &btx);
+ bool ok = bsu_beacon_process (t.bsu, b, &brx);
+ test_fail_unless (ok == true);
+ test_fail_unless (t.bsu->sta_avln->sync.init == false);
+ blk_release_desc ((blk_t*) b);
+ b = bsu_beacon_write (&beacon, BSU_BEACON_TYPE_DISCOVER,
+ &t.mac_config, &btx);
+ ok = bsu_beacon_process (t.bsu, b, &brx);
+ test_fail_unless (ok == true);
+ test_fail_unless (t.bsu->sta_avln->sync.init == false);
+ blk_release_desc ((blk_t*) b);
+ }
+ test_end;
bsu_test_uninit (&t);
}
@@ -541,6 +603,7 @@ test_suite_bsu (test_t t)
test_case_bsu_activate (t);
test_case_bsu_power_on (t);
test_case_bsu_process (t);
+ test_case_bsu_process_sta_is_cco (t);
test_case_bsu_update (t);
test_case_bsu_timer_event (t);
test_case_bsu_persistent_schedules_update (t);
diff --git a/cesar/bsu/test/utest/src/tests.c b/cesar/bsu/test/utest/src/tests.c
index 82fbf9a2ee..c185da0f8b 100644
--- a/cesar/bsu/test/utest/src/tests.c
+++ b/cesar/bsu/test/utest/src/tests.c
@@ -56,7 +56,7 @@ bsu_test_init (bsu_test_t *ctx)
bsu_init_beacon_cb (bsu_test_upper_layer_beacon_received, ctx);
/* Warn just for the test. */
memset (&ctx->bsu->beacon, 0, sizeof (bsu_beacon_t));
- ctx->bsu->sta_avln = &ctx->bsu->avlns[0];
+ ctx->bsu->sta_avln = &ctx->bsu->poweron;
bsu_test_upper_layer_beacon_received_init (ctx);
bsu_beacon_t beacon;
bsu_test_create_beacon (ctx, &beacon);