summaryrefslogtreecommitdiff
path: root/cesar
diff options
context:
space:
mode:
authorThierry Carré2012-10-22 15:53:42 +0200
committerThierry Carré2012-11-05 10:59:40 +0100
commit9820c23b642d0580a9a93470287946abd6555341 (patch)
tree0270ec51b089439c44d91986b9e44510f0740ea3 /cesar
parentd4673464b15d46b5fd85c7cd68e3ecc6eaa68040 (diff)
cesar/cp/msg: fix nf_mi for vs mme, closes #3437
Factorize the header validation on unit tests for : - VS_GET_PB_STATS_CNF - VS_GET_MACTOTEI_CNF For this both mme, the condition is never satisfy to have the bug.
Diffstat (limited to 'cesar')
-rw-r--r--cesar/cp/av/msg/test/utest/src/msg_vs.c165
-rw-r--r--cesar/cp/msg/src/msg.c8
2 files changed, 100 insertions, 73 deletions
diff --git a/cesar/cp/av/msg/test/utest/src/msg_vs.c b/cesar/cp/av/msg/test/utest/src/msg_vs.c
index e4a7002b67..105333b001 100644
--- a/cesar/cp/av/msg/test/utest/src/msg_vs.c
+++ b/cesar/cp/av/msg/test/utest/src/msg_vs.c
@@ -99,39 +99,92 @@ test_write_header (bool vlan_present, mme_header_t *pheader,
bitstream_write (pstream, SPC_OUI, OUI_SIZE_BITS);
}
-
static void
-test_read_header (test_t test, bool vlan_present, mme_header_t *pheader,
+test_read_header (test_t test, bool vlan_present,
mme_header_t *pexpected, bitstream_t *pstream,
int header_idx)
{
+ mme_header_t header;
+
bitstream_init (pstream, GET_BUFFER(header_idx),
ETH_PACKET_MAX_NOVLAN_SIZE,
BITSTREAM_READ);
- pheader->oda = bitstream_read_large (pstream, 48);
- pheader->osa = bitstream_read_large (pstream, 48);
+ header.oda = bitstream_read_large (pstream, 48);
+ header.osa = bitstream_read_large (pstream, 48);
if (vlan_present)
- pheader->vlan = bitstream_read (pstream, 32);
- pheader->mtype = bitstream_read (pstream, 16);
- pheader->mmv = bitstream_read (pstream, 8);
- pheader->mmtype = bitstream_read (pstream, 16);
- pheader->fmi_inf = bitstream_read (pstream, 4);
- pheader->fmi_mi = bitstream_read (pstream, 4);
- pheader->fmi_ssn = bitstream_read (pstream, 8);
- pheader->oui = bitstream_read (pstream, OUI_SIZE_BITS);
+ header.vlan = bitstream_read (pstream, 32);
+ header.mtype = bitstream_read (pstream, 16);
+ header.mmv = bitstream_read (pstream, 8);
+ header.mmtype = bitstream_read (pstream, 16);
+ header.fmi_inf = bitstream_read (pstream, 4);
+ header.fmi_mi = bitstream_read (pstream, 4);
+ header.fmi_ssn = bitstream_read (pstream, 8);
+ header.oui = bitstream_read (pstream, OUI_SIZE_BITS);
test_begin (test, "Header")
{
- test_fail_if (pheader->oda != pexpected->oda);
- test_fail_if (pheader->osa != pexpected->osa);
- test_fail_if (pheader->mtype != HPAV_MTYPE_MME);
- test_fail_if (pheader->mmv != HPAV_MMV);
- test_fail_if (pheader->mmtype != pexpected->mmtype);
- test_fail_if (pheader->fmi_inf != pexpected->fmi_inf);
- test_fail_if (pheader->fmi_mi != pexpected->fmi_mi);
- test_fail_if (pheader->fmi_ssn != pexpected->fmi_ssn);
- test_fail_if (pheader->oui != SPC_OUI);
+ test_fail_if (header.oda != pexpected->oda);
+ test_fail_if (header.osa != pexpected->osa);
+ test_fail_if (header.mtype != HPAV_MTYPE_MME);
+ test_fail_if (header.mmv != HPAV_MMV);
+ test_fail_if (header.mmtype != pexpected->mmtype);
+ test_fail_if (header.fmi_inf != pexpected->fmi_inf);
+ test_fail_if (header.fmi_mi != pexpected->fmi_mi);
+ test_fail_if (header.fmi_ssn != pexpected->fmi_ssn);
+ test_fail_if (header.oui != SPC_OUI);
+ }
+ test_end;
+}
+
+static void
+check_vs_header (test_t test, int mmtype, uint size,
+ u8 *ssn, uint last_mme_size)
+{
+ const uint header_size = HPAV_MME_HEADER + OUI_SIZE;
+ const uint payload_capacity = ETH_PACKET_MAX_NOVLAN_SIZE - header_size;
+ bitstream_t stream;
+ mme_header_t h_expected;
+ unsigned int last_mme_size_expected;
+ uint mme_idx;
+
+ /* Build the number of fragment expected. */
+ h_expected.fmi_inf = size / payload_capacity;
+
+ if (size && 0 == (size % payload_capacity))
+ h_expected.fmi_inf --;
+
+ /* Set the sequence number expected. */
+ if (h_expected.fmi_inf)
+ h_expected.fmi_ssn = *ssn = (*ssn == 0xff) ? 1 : *ssn + 1;
+ else
+ h_expected.fmi_ssn = 0;
+
+ h_expected.oda = peer.mac;
+ h_expected.osa = own_mac_addr;
+ h_expected.mmtype = mmtype;
+
+ test_begin (test, "check_vs_header")
+ {
+ if (size)
+ last_mme_size_expected = ((size - 1) % payload_capacity) + 1;
+ else
+ last_mme_size_expected = 0;
+ last_mme_size_expected += header_size;
+
+ if (last_mme_size_expected < ETH_PACKET_MIN_SIZE)
+ last_mme_size_expected = ETH_PACKET_MIN_SIZE;
+
+ test_fail_unless (last_mme_size_expected == last_mme_size,
+ "Wrong length on last mme");
+
+ for (mme_idx=0; mme_idx <= h_expected.fmi_inf; mme_idx++)
+ {
+ h_expected.fmi_mi = mme_idx;
+
+ test_read_header (test, ETH_IS_VLANTAG (peer.eth_type),
+ &h_expected, &stream, mme_idx);
+ }
}
test_end;
}
@@ -147,7 +200,6 @@ test_case_msg_vs_get_tonemap (test_t test)
uint i;
/* Context. */
bitstream_t stream;
- mme_header_t header;
mme_header_t expected;
u64 data;
@@ -224,7 +276,7 @@ test_case_msg_vs_get_tonemap (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != result, "Wrong Result");
@@ -305,7 +357,7 @@ test_case_msg_vs_get_tonemap (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != result, "Wrong Result");
@@ -372,7 +424,7 @@ test_case_msg_vs_get_tonemap (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != result, "Wrong Result");
@@ -439,7 +491,7 @@ test_case_msg_vs_get_tonemap (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != result, "Wrong Result");
@@ -633,7 +685,6 @@ test_case_msg_vs_get_snr (test_t test)
uint i;
/* Context. */
bitstream_t stream;
- mme_header_t header;
mme_header_t expected;
u64 data;
@@ -678,7 +729,7 @@ test_case_msg_vs_get_snr (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != data_to_send.result, "Wrong Result");
@@ -731,7 +782,7 @@ test_case_msg_vs_get_snr (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != data_to_send.result, "Wrong Result");
@@ -953,7 +1004,6 @@ test_case_msg_vs_get_spectrum (test_t test)
uint i;
/* Context. */
bitstream_t stream;
- mme_header_t header;
mme_header_t expected;
u64 data;
@@ -992,7 +1042,7 @@ test_case_msg_vs_get_spectrum (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != result, "Wrong Result");
@@ -1149,7 +1199,6 @@ test_case_msg_vs_get_link_stats (test_t test)
{
/* Context. */
bitstream_t stream;
- mme_header_t header;
mme_header_t expected;
u64 data;
@@ -1179,7 +1228,7 @@ test_case_msg_vs_get_link_stats (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != ReqID, "Wrong ReqID");
@@ -1383,7 +1432,6 @@ test_case_msg_vs_get_amp_map (test_t test)
{
/* Context. */
bitstream_t stream;
- mme_header_t header;
mme_header_t expected;
cp_mme_tx_t *tx_mme;
@@ -1420,7 +1468,7 @@ test_case_msg_vs_get_amp_map (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
bitstream_access (&stream, &data, 8);
test_fail_if (data != result, "Wrong result");
@@ -1685,7 +1733,6 @@ test_case_msg_vs_get_ce_stats_cnf_send_test_case (test_t test,
u16 mod_array[CE_MOD_COUNT])
{
test_within (test);
- mme_header_t header;
mme_header_t expected;
int i;
@@ -1698,7 +1745,7 @@ test_case_msg_vs_get_ce_stats_cnf_send_test_case (test_t test,
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, stream, 0);
+ test_read_header (test, false, &expected, stream, 0);
test_fail_unless (bitstream_read (stream, 8) == version_id);
test_fail_unless (bitstream_read (stream, 8) == result);
@@ -1902,15 +1949,12 @@ test_case_msg_vs_get_pb_stats (test_t test)
{
int i;
bitstream_t stream;
- mme_header_t header;
- mme_header_t expected;
- const int header_size = HPAV_MME_HEADER + OUI_SIZE;
- const int payload_capacity = ETH_PACKET_MAX_NOVLAN_SIZE - header_size;
test_case_begin (test, "VS_GET_PB_STATS");
test_begin (test, "Check REQ")
{
+ mme_header_t header;
const cp_tei_t stei_filter_test = 0x25;
cp_mme_rx_t *rx_mme;
cp_tei_t found = MAC_TEI_UNASSOCIATED;
@@ -1956,43 +2000,16 @@ test_case_msg_vs_get_pb_stats (test_t test)
for (i = 0; i < PB_STATS_NB_ENTRY; i++)
{
- uint mme_idx;
static u8 ssn = 0;
const int payload_requested = PB_STATS_SIZE_WITH_DATA(i);
- unsigned int size_last_mme;
INIT_BUFFER();
tx_mme = cp_msg_vs_get_pb_stats_cnf_send_begin (&cp, &peer, i);
cp_msg_vs_get_pb_stats_cnf_send_measure (&cp, tx_mme, 0, i);
cp_msg_vs_get_pb_stats_cnf_send_end (&cp, tx_mme);
- size_last_mme = payload_requested % payload_capacity;
- size_last_mme += header_size;
-
- if (size_last_mme < ETH_PACKET_MIN_SIZE)
- size_last_mme = ETH_PACKET_MIN_SIZE;
-
- test_fail_unless (size_last_mme == tx_mme->length,
- "Wrong length on last mme");
-
- /* Expected header */
- expected.oda = peer.mac;
- expected.osa = own_mac_addr;
- expected.mmtype = VS_GET_PB_STATS_CNF;
- expected.fmi_inf = payload_requested / payload_capacity;
-
- if (expected.fmi_inf)
- expected.fmi_ssn = ssn = (ssn == 0xff) ? 1 : ssn + 1;
- else
- expected.fmi_ssn = 0;
-
- for (mme_idx=0; mme_idx<=expected.fmi_inf; mme_idx++)
- {
- expected.fmi_mi = mme_idx;
-
- test_read_header (test, ETH_IS_VLANTAG (peer.eth_type),
- &header, &expected, &stream, mme_idx);
- }
+ check_vs_header (test, VS_GET_PB_STATS_CNF, payload_requested,
+ &ssn, tx_mme->length);
/* Check Payload */
test_begin (test, "Payload")
@@ -2071,7 +2088,6 @@ test_case_msg_imac_get_discover_list (test_t test)
{
cp_mme_tx_t *tx_mme;
bitstream_t stream;
- mme_header_t header;
mme_header_t expected;
cp_msg_imac_get_discover_list_cnf_result_t result;
u8 version;
@@ -2106,7 +2122,7 @@ test_case_msg_imac_get_discover_list (test_t test)
expected.fmi_mi = 0;
expected.fmi_ssn = 0;
/* Read MME for Data comparison. */
- test_read_header (test, false, &header, &expected, &stream, 0);
+ test_read_header (test, false, &expected, &stream, 0);
test_fail_if (bitstream_read (&stream, 8) != result, "Wrong result");
test_fail_if (bitstream_read (&stream, 8) != version, "Wrong version");
@@ -2179,9 +2195,11 @@ test_case_msg_vs_get_mactotei (test_t test)
for (nb_entry=0; nb_entry<2000; nb_entry++)
{
cp_mme_tx_t *mme_tx;
+ u8 ssn;
INIT_BUFFER();
cp_msg_init (&cp);
+ ssn = 0;
mme_tx = cp_msg_vs_get_mactotei_cnf_send_begin (&cp, &peer,
nb_entry);
uint i;
@@ -2196,6 +2214,9 @@ test_case_msg_vs_get_mactotei (test_t test)
}
cp_msg_vs_get_mactotei_cnf_send_end (&cp, mme_tx);
+ check_vs_header (test, VS_GET_MACTOTEI_CNF,
+ 2 + nb_entry * 8, &ssn, mme_tx->length);
+
/* Test itself */
buffer_idx = 0;
bitstream_t stream;
diff --git a/cesar/cp/msg/src/msg.c b/cesar/cp/msg/src/msg.c
index b8038181ec..175532e834 100644
--- a/cesar/cp/msg/src/msg.c
+++ b/cesar/cp/msg/src/msg.c
@@ -612,7 +612,13 @@ cp_msg_mme_init (cp_t *ctx, cp_mme_peer_t *peer, mmtype_t mmtype,
else
p_capability = HPAV_MME_PAYLOAD_MAX_SIZE;
- nf_mi = mme_payload_length / p_capability;
+ /* nf_mi must not be incremented when mme_payload_length modulo
+ * p_capability is zero, in other words the last mme is full. */
+ if (mme_payload_length)
+ nf_mi = (mme_payload_length - 1) / p_capability;
+ else
+ nf_mi = 0;
+
dbg_assert (nf_mi < HPAV_MME_FRAG_MAX);
if (nf_mi == 0)