summaryrefslogtreecommitdiff
path: root/cesar/cp
diff options
context:
space:
mode:
authorNélio Laranjeiro2011-08-31 16:30:36 +0200
committerThierry Carré2011-10-20 10:37:47 +0200
commitc8271ff2d10f6b66922d8f5b6d7245c2177ed1a3 (patch)
treebfca67541a7e9d8f8b736e12dc604aee74495143 /cesar/cp
parent04e96dbe7bc52e60918267087f2582b578d5d763 (diff)
cesar/cp/msg: fmsn is handled by msg module, closes #2689
Diffstat (limited to 'cesar/cp')
-rw-r--r--cesar/cp/msg/inc/context.h2
-rw-r--r--cesar/cp/msg/msg.h3
-rw-r--r--cesar/cp/msg/src/msg.c21
-rw-r--r--cesar/cp/msg/src/msg_cc.c7
-rw-r--r--cesar/cp/msg/src/msg_cm.c2
-rw-r--r--cesar/cp/msg/stub/src/msg.c4
-rw-r--r--cesar/cp/msg/test/Makefile2
-rw-r--r--cesar/cp/msg/test/src/cc_discover_list.c4
-rw-r--r--cesar/cp/msg/test/src/msg.c23
-rw-r--r--cesar/cp/msg/test/src/relay.c2
10 files changed, 56 insertions, 14 deletions
diff --git a/cesar/cp/msg/inc/context.h b/cesar/cp/msg/inc/context.h
index d69afb1e5f..5bc4e3a786 100644
--- a/cesar/cp/msg/inc/context.h
+++ b/cesar/cp/msg/inc/context.h
@@ -22,6 +22,8 @@ struct cp_msg_t
slab_cache_t mme_tx_slab_cache;
/** Slab cache for the MME RX. */
slab_cache_t mme_rx_slab_cache;
+ /** Fragment sequence number message. */
+ uint fmsn;
};
typedef struct cp_msg_t cp_msg_t;
diff --git a/cesar/cp/msg/msg.h b/cesar/cp/msg/msg.h
index c4d3b48ccb..e54a07b501 100644
--- a/cesar/cp/msg/msg.h
+++ b/cesar/cp/msg/msg.h
@@ -123,7 +123,6 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
* \param mmtype the MME MMTYPE.
* \param fmi_nbFrag The number of fragments.
* \param fmi_nb the number of the fragment.
- * \param fmi_fmsn the sequence number of the fragment.
* \return the newly created message
*
* This function:
@@ -134,7 +133,7 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
*/
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_nb, uint fmi_fmsn);
+ uint fmi_nbFrag, uint fmi_nb);
/**
* Finalise and send a MME.
diff --git a/cesar/cp/msg/src/msg.c b/cesar/cp/msg/src/msg.c
index 6a42ce4c81..40c1619686 100644
--- a/cesar/cp/msg/src/msg.c
+++ b/cesar/cp/msg/src/msg.c
@@ -282,6 +282,20 @@ enum cp_msg_allowed_mme_t
};
/**
+ * Increase the FMSN value for the next fragmented MME transaction.
+ * \param ctx the module context.
+ *
+ * \warn fmsn with value 0 is forbidden.
+ */
+PRIVATE void
+cp_msg_mme_fmsn_increase (cp_msg_t *ctx)
+{
+ ctx->fmsn = (ctx->fmsn + 1) % 8;
+ if (ctx->fmsn == 0)
+ ctx->fmsn = 1;
+}
+
+/**
* Compute the current length of the MME fragmented or not.
* \param msg the MME to send.
* \return the length.
@@ -363,6 +377,7 @@ cp_msg_init (cp_t *ctx)
slab_cache_init (&ctx->msg.mme_rx_slab_cache, "MME RX",
sizeof (cp_mme_rx_t),
(slab_object_destructor_t) cp_msg_mme_rx_destructor);
+ ctx->msg.fmsn = 1;
}
/**
@@ -835,7 +850,7 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_nb, uint fmi_fmsn)
+ uint fmi_nbFrag, uint fmi_nb)
{
cp_mme_tx_t *msg;
@@ -855,9 +870,9 @@ cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
msg->fmi_nbfrag = fmi_nbFrag;
msg->fmi_nb = fmi_nb;
- msg->fmi_fmsn = fmi_fmsn;
+ msg->fmi_fmsn = ctx->msg.fmsn;
msg->mmtype = mmtype;
-
+ cp_msg_mme_fmsn_increase (&ctx->msg);
// Initialise the bitstream context and fill the MME header.
bitstream_write_init (&msg->bitstream, msg->p_mme, ETH_PACKET_MAX_SIZE);
cp_msg_mme_write_frag_header (ctx, msg, &msg->bitstream, mmtype);
diff --git a/cesar/cp/msg/src/msg_cc.c b/cesar/cp/msg/src/msg_cc.c
index 72c5697102..5de8174da0 100644
--- a/cesar/cp/msg/src/msg_cc.c
+++ b/cesar/cp/msg/src/msg_cc.c
@@ -525,7 +525,7 @@ cp_msg_cc_set_tei_map_ind_send_begin (
if (sta_nb * 8 > (peer->vlan_tag ? HPAV_MME_PAYLOAD_MAX_SIZE_WITH_VLAN :
HPAV_MME_PAYLOAD_MAX_SIZE) - 2)
{
- msg = cp_msg_mme_init_frag (ctx, peer, CC_SET_TEI_MAP_IND, 1, 0, 0);
+ msg = cp_msg_mme_init_frag (ctx, peer, CC_SET_TEI_MAP_IND, 1, 0);
bitstream_init_buffer_cb (
&msg->bitstream,
@@ -939,7 +939,8 @@ cp_msg_cc_discover_list_cnf_send_begin (cp_t *ctx, cp_mme_peer_t *peer,
uint nbFrag;
nbFrag = mme_length / ETH_PACKET_MAX_SIZE;
- mme = cp_msg_mme_init_frag (ctx, peer, CC_DISCOVER_LIST_CNF, nbFrag, 0, 0);
+ mme = cp_msg_mme_init_frag (
+ ctx, peer, CC_DISCOVER_LIST_CNF, nbFrag, 0);
bitstream_init_buffer_cb (
&mme->bitstream,
@@ -1296,7 +1297,7 @@ cp_msg_cc_handover_info_ind_send_begin (cp_t *ctx, cp_mme_peer_t *peer,
mme = cp_msg_mme_init (ctx, peer, CC_HANDOVER_INFO_IND);
else
{
- mme = cp_msg_mme_init_frag (ctx, peer, CC_HANDOVER_INFO_IND, 1, 0, 0);
+ mme = cp_msg_mme_init_frag (ctx, peer, CC_HANDOVER_INFO_IND, 1, 0);
bitstream_init_buffer_cb (
&mme->bitstream,
(bitstream_buffer_cb_t) cp_msg_mme_tx_change_buffer, mme);
diff --git a/cesar/cp/msg/src/msg_cm.c b/cesar/cp/msg/src/msg_cm.c
index ee17754ede..19bd9e47e0 100644
--- a/cesar/cp/msg/src/msg_cm.c
+++ b/cesar/cp/msg/src/msg_cm.c
@@ -1719,7 +1719,7 @@ cp_msg_cm_nw_stats_cnf_send_begin (cp_t *ctx, cp_mme_peer_t *peer_info,
if (mme_payload_length + mme_header_length > ETH_PACKET_MAX_SIZE)
{
- mme = cp_msg_mme_init_frag (ctx, peer_info, CM_NW_STATS_CNF, 1, 0, 0);
+ mme = cp_msg_mme_init_frag (ctx, peer_info, CM_NW_STATS_CNF, 1, 0);
bitstream_init_buffer_cb (
&mme->bitstream,
diff --git a/cesar/cp/msg/stub/src/msg.c b/cesar/cp/msg/stub/src/msg.c
index ba1647785f..b6406723ea 100644
--- a/cesar/cp/msg/stub/src/msg.c
+++ b/cesar/cp/msg/stub/src/msg.c
@@ -68,11 +68,11 @@ cp_msg_mme_write_frag_header (cp_t *ctx, cp_mme_tx_t *msg, bitstream_t *bs,
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_fnmi, uint fmi_ssn) __attribute__((weak));
+ uint fmi_nbFrag, uint fmi_fnmi) __attribute__((weak));
cp_mme_tx_t *
cp_msg_mme_init_frag (cp_t *ctx, cp_mme_peer_t *peer, cp_mmtype_t mmtype,
- uint fmi_nbFrag, uint fmi_fnmi, uint fmi_ssn)
+ uint fmi_nbFrag, uint fmi_fnmi)
{
return NULL;
}
diff --git a/cesar/cp/msg/test/Makefile b/cesar/cp/msg/test/Makefile
index a09ff9db54..cde7cac895 100644
--- a/cesar/cp/msg/test/Makefile
+++ b/cesar/cp/msg/test/Makefile
@@ -1,5 +1,7 @@
BASE = ../../..
+DEFS=-DNO_PRIVATE
+
INCLUDES = cp/msg/test/overide/ cp/sta/core/stub/
HOST_PROGRAMS = test-msg-read-header test-msg-cc test-msg-cm \
diff --git a/cesar/cp/msg/test/src/cc_discover_list.c b/cesar/cp/msg/test/src/cc_discover_list.c
index 4e98b90444..6268082da5 100644
--- a/cesar/cp/msg/test/src/cc_discover_list.c
+++ b/cesar/cp/msg/test/src/cc_discover_list.c
@@ -306,7 +306,7 @@ test_case__cc_discover_list_cnf_send (test_t test)
/* Verify. */
test_check_mme_header (test, &bitstream, buffer[0], peer.mac,
cp_sta_own_data_get_mac_address (&ctx.cp),
- peer.vlan_tag, CC_DISCOVER_LIST_CNF, 1, 0, 0);
+ peer.vlan_tag, CC_DISCOVER_LIST_CNF, 1, 0, 1);
test_fail_unless (bitstream_read (&bitstream, 8) == nb_sta);
bitstream_init_buffer_cb (
&bitstream,
@@ -354,7 +354,7 @@ test_case__cc_discover_list_cnf_send (test_t test)
/* check the header of the second MME. */
test_check_mme_header (test, &bitstream, buffer[1], peer.mac,
cp_sta_own_data_get_mac_address (&ctx.cp),
- peer.vlan_tag, CC_DISCOVER_LIST_CNF, 1, 1, 0);
+ peer.vlan_tag, CC_DISCOVER_LIST_CNF, 1, 1, 1);
test_cc_discover_list_uninit (&ctx);
}
diff --git a/cesar/cp/msg/test/src/msg.c b/cesar/cp/msg/test/src/msg.c
index 177c0aa68f..1161bfc148 100644
--- a/cesar/cp/msg/test/src/msg.c
+++ b/cesar/cp/msg/test/src/msg.c
@@ -22,6 +22,10 @@
/* Local includes. */
#include "cp/inc/context.h"
+
+void
+cp_msg_mme_fmsn_increase (cp_msg_t *ctx);
+
bool fsm_post;
void
@@ -309,6 +313,24 @@ test_case_msg_dispatch (test_t test)
}
+void
+test_case_msg_fmsn (test_t test)
+{
+ test_case_begin (test, "FMSN incrementation");
+ test_begin (test, "Increase FMSN, value 0 is forbiden")
+ {
+ cp_t cp;
+ uint i;
+ memset (&cp, 0, sizeof (cp_t));
+ for (i = 0; i < 16; i++)
+ {
+ cp_msg_mme_fmsn_increase (&cp.msg);
+ test_fail_unless (cp.msg.fmsn);
+ }
+ }
+ test_end;
+}
+
int
main (int argc, char** argv)
{
@@ -316,6 +338,7 @@ main (int argc, char** argv)
test_init (test, argc, argv);
test_case_msg_dispatch (test);
+ test_case_msg_fmsn (test);
test_case_begin (test, "Memory allocation");
test_begin (test, "memory leaks")
diff --git a/cesar/cp/msg/test/src/relay.c b/cesar/cp/msg/test/src/relay.c
index bf2dc7607f..b58f3daf3f 100644
--- a/cesar/cp/msg/test/src/relay.c
+++ b/cesar/cp/msg/test/src/relay.c
@@ -821,7 +821,7 @@ test_case_msg_mme_change_buffer_tx (test_t test)
test_this_test_init ();
- mme = cp_msg_mme_init_frag (&cp, &peer, CC_SET_TEI_MAP_REQ, 1, 0, 1);
+ mme = cp_msg_mme_init_frag (&cp, &peer, CC_SET_TEI_MAP_REQ, 1, 0);
test_fail_unless (mme->relay == true);
mme->bitstream.data_bits = 0;
mme->bitstream.data = NULL;