summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--cesar/mac/sar/inc/sar.h6
-rw-r--r--cesar/mac/sar/src/sar.c3
-rw-r--r--cesar/mac/sar/test/unit_test/ecos/src/segmentation.c49
3 files changed, 57 insertions, 1 deletions
diff --git a/cesar/mac/sar/inc/sar.h b/cesar/mac/sar/inc/sar.h
index eb674b712a..f877c85795 100644
--- a/cesar/mac/sar/inc/sar.h
+++ b/cesar/mac/sar/inc/sar.h
@@ -19,6 +19,12 @@
#define SAR_MPDU_RX_REFILL 1
+/**
+ * Allow the SAR to segment or reassembly Ethernet packets to an MFS which
+ * contains less or equal PB than the define.
+ * MAC_SAR_EM_MAX_PB_ALLOWED: MAC SAR Exhausted Memory MAX PB allowed. */
+#define MAC_SAR_EM_MAX_PB_ALLOWED 5
+
BEGIN_DECLS
/**
diff --git a/cesar/mac/sar/src/sar.c b/cesar/mac/sar/src/sar.c
index c8582c3466..3168bdd4fc 100644
--- a/cesar/mac/sar/src/sar.c
+++ b/cesar/mac/sar/src/sar.c
@@ -826,7 +826,8 @@ sar_msdu_add (sar_t *ctx, u8 *buffer, u16 length, mfs_tx_t *mfs,
mfs->stats.octets += length;
/* Enough block available to send a frame and SAR is activated ? */
- if (blk_slack () && ctx->activate)
+ if (ctx->activate
+ && (blk_slack () || mfs->seg_nb <= MAC_SAR_EM_MAX_PB_ALLOWED))
{
if (mfs->fsm_state == MFS_FSM_CMD_RELEASE)
{
diff --git a/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c b/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c
index 3349e64463..3cfa678fb2 100644
--- a/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c
+++ b/cesar/mac/sar/test/unit_test/ecos/src/segmentation.c
@@ -19,6 +19,9 @@
#include "mac/sar/sar.h"
#include "mac/sar/inc/sar_context.h"
+#include "mac/sar/inc/sar.h"
+#include <string.h>
+#include "config.h"
/* Override context. */
#include "mac/pbproc/inc/context.h"
@@ -256,6 +259,51 @@ test_case_segmentation_mfs_release (test_t test)
}
void
+test_case_segmentation_em_max_pb_allowed_test (test_t test, sar_test_t ctx,
+ mfs_tx_t *mfs)
+{
+ u8 buffer[ETH_PACKET_MIN_SIZE_ALLOWED];
+ memset (buffer, 0xff, ETH_PACKET_MIN_SIZE_ALLOWED);
+ test_within (test);
+ sar_msdu_add (ctx.sar, buffer, ETH_PACKET_MIN_SIZE_ALLOWED, mfs,
+ NULL, 0x0);
+ sar_bridge_dma_free_head (ctx.sar);
+ test_fail_unless (mfs->seg_nb == MAC_SAR_EM_MAX_PB_ALLOWED + 1);
+}
+
+void
+test_case_segmentation_em_max_pb_allowed (test_t test)
+{
+ sar_test_t ctx;
+ bool added;
+ test_case_begin (test, "Test MAC_SAR_EM_MAX_PB_ALLOWED");
+ sar_test_init (&ctx, INVALID_PTR, INVALID_PTR);
+ mfs_tx_t *mfs = mac_store_mfs_add_tx (ctx.mac_store, false, false, 1,
+ 1, &added);
+ blk_t *head, *tail;
+ /* Allocate all available memory less some block under the slack value. */
+ head = blk_alloc_desc_range (CONFIG_BLK_NB - CONFIG_BLK_SLACK + 2, &tail);
+ sar_activate (ctx.sar, true);
+ test_begin (test, "TX > MAC_SAR_EM_MAX_PB_ALLOWED")
+ {
+ mfs->seg_nb = MAC_SAR_EM_MAX_PB_ALLOWED + 1;
+ test_case_segmentation_em_max_pb_allowed_test (test, ctx, mfs);
+ }
+ test_end;
+ test_begin (test, "TX <= MAC_SAR_EM_MAX_PB_ALLOWED")
+ {
+ mfs->seg_nb = MAC_SAR_EM_MAX_PB_ALLOWED;
+ test_case_segmentation_em_max_pb_allowed_test (test, ctx, mfs);
+ }
+ test_end;
+ blk_release_desc_range (head, tail);
+ sar_mfs_remove (ctx.sar, PARENT_OF (mfs_t, tx, mfs));
+ blk_release (mfs);
+ sar_sta_remove (ctx.sar, 1);
+ sar_test_uninit (&ctx);
+}
+
+void
test_suite_segmentation (test_t test)
{
test_suite_begin (test, "Segmentation");
@@ -263,6 +311,7 @@ test_suite_segmentation (test_t test)
test_case_segmentation_message_too_short (test);
test_case_segmentation (test);
test_case_segmentation_mfs_release (test);
+ test_case_segmentation_em_max_pb_allowed (test);
test_begin (test, "Memory")
{