summaryrefslogtreecommitdiff
path: root/mac/pbproc/test/maximus/src/add_seg.c
blob: 3c7e746e92e9ef6ee1f1413c95c52ea67093a172 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    src/add_seg.c
 * \brief   Add segments fcall.
 * \ingroup test
 */
#include "common/std.h"

#include "host/fcall.h"
#include "mac/common/mfs.h"
#include "mac/common/store.h"

#include "inc/test_pbproc.h"
#include "inc/add_seg.h"
#include "inc/context.h"

static int
test_pbproc_add_seg_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
                           sci_msg_t **msg, void *data);

void
test_pbproc_add_seg_init (test_pbproc_t *ctx)
{
    dbg_assert (ctx);
    fcall_register (my_station.fcall, "add_seg", test_pbproc_add_seg_fcall,
                    ctx);
}

static void
test_pbproc_add_seg (test_pbproc_t *ctx, bool mme, uint lid, uint tei,
                     uint seg_nb, uint gen)
{
    mfs_tx_t *mfs;
    bool added;
    dbg_assert (ctx);
    dbg_assert (seg_nb > 0);
    /* Locate the MFS. */
    mfs = mac_store_mfs_add_tx (ctx->store, tei == MAC_TEI_BCAST, mme,
                                mme ? MAC_LID_NONE : lid, tei, &added);
    if (added)
        ca_mfs_add (ctx->ca, mfs);
    /* Generate segments. */
    blk_t *blk_first, *blk_last;
    blk_first = blk_alloc_desc_range (seg_nb, &blk_last);
    pb_t *seg_first = PB_FROM_BLK (blk_first);
    pb_t *seg_last = PB_FROM_BLK (blk_last);
    pb_t *seg, *lseg;
    uint i;
    for (lseg = NULL, seg = seg_first, i = 0;
         lseg != seg_last;
         lseg = seg, seg = seg->next, i++)
    {
        /* Fill header. */
        seg->header.ssn = mfs->next_ssn++;
        seg->header.mfbo = 0;
        seg->header.vpbf = true;
        seg->header.mmqf = mme;
        seg->header.mfbf = false;
        seg->header.opsf = false;
        seg->header.rsvd = 0;
        /* Generate pattern. */
        seg->data[0] = 0x42;
        seg->data[1] = 0x5a;
        seg->data[2] = gen;
        seg->data[3] = i;
    }
    /* Insert them. */
    pbproc_mfs_insert (mfs, seg_first, seg_last, seg_nb, mfs->cap);
    pbproc_mfs_provide (mfs, seg_nb);
    /* Update CA. */
    ca_mfs_update (ctx->ca, mfs);
    /* Release the MFS reference. */
    blk_release (mfs);
}

static int
test_pbproc_add_seg_fcall (fcall_ctx_t *fcall, fcall_param_t **param,
                           sci_msg_t **msg, void *data)
{
    dbg_assert (fcall);
    dbg_assert (param && *param);
    dbg_assert (msg && *msg);
    test_pbproc_t *ctx = (void *) data;
    dbg_assert (ctx);
    /* Read message. */
    uint seg_nb, tei, lid, gen;
    bool mme;
    if (!test_pbproc_fcall_bind ("mme", mme))
        return -1;
    if (!test_pbproc_fcall_bind_long ("lid", lid) || !MAC_LID_IS_XLID (lid))
        return -1;
    if (!test_pbproc_fcall_bind_long ("tei", tei)
        || !(MAC_TEI_IS_STA (tei) || tei == MAC_TEI_BCAST))
        return -1;
    if (!test_pbproc_fcall_bind_long ("seg_nb", seg_nb))
        return -1;
    if (!test_pbproc_fcall_bind_long ("gen", gen))
        return -1;
    /* Add segments. */
    test_pbproc_add_seg (ctx, mme, lid, tei, seg_nb, gen);
    /* Return. */
    fcall_param_reset (*param);
    return 0;
}