summaryrefslogtreecommitdiff
path: root/mac/sar/test/maximus_test/src/Maximus_sar.cpp
blob: eeea77c282e7c03b1ce7f07449c03bc36967ff2e (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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* Cesar project {{{
 *
 * Copyright (C) 2007 Spidcom
 *
 * <<<Licence>>>
 *
 * }}} */
/**
 * \file    Maximus_sar.c
 * \brief   header of the segmentation test function on maximus.
 * \ingroup mac/sar/test/maximus_test/maximus/src
 * 
 * Maximus selects a packet to segment in a raw of Ethernet packets.
 * This packet is split in  packet of 1024 bytes long corresponding to the
 * maximum size of the maximus parameter.
 * 
 * Maximus send the segmentation request and provide the parameters for the 
 * segmentation module of the SAR.
 * 
 * The Station take the parameters and reconstitute the packet to segment 
 * ( simulate the CL or CP function ). It gives the data necessary for 
 * the SAR to segment the packet.
 * 
 * Once the segmentation is over, the Station answer the request by giving 
 * back the PBs filled with the Ethernet packet.
 * 
 * Maximus take the PBs and verify each byte comparing it with the Ethernet
 * packet data.
 */

#include "maximus/common/interfaces/Maximus.h"
#include "maximus/common/interfaces/Sta.h"
#include "maximus/common/interfaces/Msg.h"
#include <iostream> // for 'cout', 'cerr' and 'clog'
using namespace std;

#define debug_info false

unsigned char blk[3][1024]; // 3 PB received from the Segmentation STA, of with 
// the data and the header.

bool test_fail;

void stationA_cb (Msg &msg)
{
    char value[2];
    char id [5];
    int val;
    void *msg_return;

    char * buffer = new char [FUNCTION_CALL_PARAM_MAX_SIZE];
    unsigned long length = FUNCTION_CALL_PARAM_MAX_SIZE*sizeof(char);

    if (debug_info)
    {
        cout << "Hello I'am the station_cb"<< endl;
    }

    // Try to get the error message if the segmentation fail.
    msg_return = msg.bind_param ("err", length, (unsigned char * &) buffer);

    if (msg_return)
    {
        cout << "The segmentation fail : "<< buffer << endl;
        test_fail = true;
    }
    else
    {
        val = 0;
        do
        {
            strcpy (id, "pb");
            sprintf (value, "%d", val);
            strcat (id, value);

            msg_return = msg.bind_param (id, length,
                    (unsigned char * &) buffer);

            if (msg_return != NULL)
            {
                memcpy (blk[val], buffer, 516);
            }
        } while (val++, msg_return != NULL);
    }

    delete [] buffer;
    buffer = NULL;
}

void stationB_cb (Msg &msg)
{

}

int main (int argc, char *argv[])
{
    unsigned char lid;
    unsigned char tei;
    unsigned int i;
    char value[2];
    char id [5];

    test_fail = false;

    Maximus maximus;
    maximus.init (argc, argv);

    Sta stationA = maximus.create_sta ();
    Sta stationB = maximus.create_sta ();

    //create the function call
    Msg fc = maximus.create_fc ("segmentation");

    lid = 1;
    tei = 1;

    /* add the buffer address */
    fc.add_param ("lid", sizeof(unsigned char), (unsigned char*) &lid);
    fc.add_param ("tei", sizeof(unsigned char), (unsigned char*) &tei);

    fc.set_cb (&stationA_cb);
    fc.set_sta (stationA);
    // stationA.debug ();

    fc.send_async ();

    /* Wait during 10000 ticks before terminating the program. */
    maximus.wait (10000);

    if (test_fail)
    {
        return 0;
    }

    //create the function call
    Msg fc2 = maximus.create_fc ("reassembly");
    fc2.set_cb (&stationB_cb);
    fc2.set_sta (stationB);
    stationB.debug ();

    /* Send the pb for a segmentation */
    for (i = 0; i < 3; i++)
    {
        sprintf (value, "%d", i);
        strcpy (id, "pb");
        strcat (id, value);
        fc2.add_param (id, 1024 * sizeof(unsigned char), blk[i]);
        if (debug_info && i == 0)
            printf ("Length : %d\n", *((unsigned short*)(blk[i]
                    + sizeof(unsigned int))) >> 2);
    }

    fc2.send_async ();

    /* Wait during 10000 ticks before terminating the program. */
    maximus.wait (10000);
    return 0;
}