summaryrefslogtreecommitdiff
path: root/mac/sar/test/maximus_test/src/Maximus_sar.cpp
diff options
context:
space:
mode:
authorsave2008-04-07 14:17:42 +0000
committersave2008-04-07 14:17:42 +0000
commit3d58a62727346b7ac1a6cb36fed1a06ed72228dd (patch)
treed7788c3cf9f76426aef0286d0202e2097f0fa0eb /mac/sar/test/maximus_test/src/Maximus_sar.cpp
parent095dca4b0a8d4924093bab424f71f588fdd84613 (diff)
Moved the complete svn base into the cesar directory.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@1769 017c9cb6-072f-447c-8318-d5b54f68fe89
Diffstat (limited to 'mac/sar/test/maximus_test/src/Maximus_sar.cpp')
-rw-r--r--mac/sar/test/maximus_test/src/Maximus_sar.cpp431
1 files changed, 0 insertions, 431 deletions
diff --git a/mac/sar/test/maximus_test/src/Maximus_sar.cpp b/mac/sar/test/maximus_test/src/Maximus_sar.cpp
deleted file mode 100644
index adbc0f9b42..0000000000
--- a/mac/sar/test/maximus_test/src/Maximus_sar.cpp
+++ /dev/null
@@ -1,431 +0,0 @@
-/* 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 "Error.h"
-#include <iostream> // for 'cout', 'cerr' and 'clog'
-using namespace std;
-
-#include "mac/sar/test/maximus_test/inc/blk_t.h"
-#include "mac/sar/test/maximus_test/inc/max_job.h"
-
-typedef void (station_cb_t) (Msg &msg);
-
-/**
- * The station 1 callback
- *
- * \param msg the message
- */
-void station1_cb (Msg &msg);
-
-/**
- * The station 2 callback
- *
- * \param msg the message
- */
-void station2_cb (Msg &msg);
-
-/**
- * Launch the segmentation process on the sta with the packet provided given by
- * packet number.
- *
- * \param maximus the maximus object simulator
- * \param station the station on which the segmentation must be done
- * \param sta_cb the callback to call once the bridge dma had finished to
- * process a segmentation.
- * \param job the job to be processed
- *
- * \return a boolean set to true.
- */
-bool segmentation (Maximus *maximus, Sta *station, station_cb_t sta_cb,
- sar_max_job_t *job) throw();
-
-/**
- * Launch the segmentation process on the sta with the packet provided given by
- * packet number.
- *
- * \param maximus the maximus object simulator
- * \param station the station on which the segmentation must be done
- * \param sta_cb the callback to call once the bridge dma had finished to
- * process a segmentation.
- * \param job the job to be processed
- *
- *
- * \return a boolean set to true.
- */
-bool reassembly (Maximus *maximus, Sta *station, station_cb_t sta_cb,
- sar_max_job_t *sar_max_job) throw();
-
-/**
- * Launch the procedure with n segmentation and one reassembly
- *
- * \param argc the quantity of arguments provided
- * \param argv the char array containing the arguments
- * \param sar_max_job an array containing the list of the row's number of the
- * Ethernet packets.
- *
- * \return the end value
- */
-int launch_x_segs (int argc, char *argv[], sar_max_job_t *sar_max_job);
-
-bool station1_rsp;
-bool station2_rsp;
-bool test_fail;
-
-int fifo_blk[2];
-
-int max_jobs_qte;
-
-int main (int argc, char *argv[])
-{
- sar_max_job_t *sar_max_job = NULL;
-
- try
- {
- station1_rsp = 0;
- station2_rsp = 0;
-
- /* create the fifo */
- if (pipe (fifo_blk) < 0)
- {
- printf ("Can not create the pipe for the PBs communication\n");
- exit (-1);
- }
-
- sar_max_job = (sar_max_job_t *) malloc (sizeof (sar_max_job_t));
- sar_max_job->next = (sar_max_job_t *) malloc (sizeof (sar_max_job_t));
- sar_max_job->next->next = (sar_max_job_t *) malloc (sizeof (sar_max_job_t));
- sar_max_job->next->next->next = NULL;
-
- /* Init job 1 */
- sar_max_job->lid = 1;
- sar_max_job->tei_src = 1;
- sar_max_job->tei_dest = 2;
- sar_max_job->bcast = false;
- sar_max_job->mf_type = 2;
- sar_max_job->packet_id = 0;
-
- /* Init job 2 */
- sar_max_job->next->lid = 1;
- sar_max_job->next->tei_src = 1;
- sar_max_job->next->tei_dest = 2;
- sar_max_job->next->bcast = false;
- sar_max_job->next->mf_type = 2;
- sar_max_job->next->packet_id = 1;
-
- /* Init job 3 */
- sar_max_job->next->next->lid = 1;
- sar_max_job->next->next->tei_src = 1;
- sar_max_job->next->next->tei_dest = 2;
- sar_max_job->next->next->bcast = false;
- sar_max_job->next->next->mf_type = 2;
- sar_max_job->next->next->packet_id = 2;
-
- max_jobs_qte = 3;
-
- return launch_x_segs (argc, argv, sar_max_job);
- }
- catch (Error &e)
- {
- sar_max_job_t *sar_max_job_curr;
- while (sar_max_job)
- {
- sar_max_job_curr = sar_max_job;
- sar_max_job = sar_max_job->next;
- free (sar_max_job_curr);
- }
- }
-}
-
-/**
- * Launch the procedure with n segmentation and one reassembly
- *
- * \param argc the quantity of arguments provided
- * \param argv the char array containing the arguments
- * \param sar_max_job an array containing the list of the row's number of the
- * Ethernet packets.
- *
- * \return the end value
- */
-int launch_x_segs (int argc, char *argv[], sar_max_job_t *sar_max_job)
-{
- bool logs;
- int i;
- test_fail = false;
-
- Maximus maximus;
- maximus.init (argc, argv);
-
- Sta station1 = maximus.create_sta ();
- //station1.debug ();
- Sta station2 = maximus.create_sta ();
- //station2.debug ();
-
- // activate the sta 1 logs
- Msg fc = maximus.create_fc ("activate_logs");
- logs = true;
- fc.add_param ("rea", sizeof(unsigned char), (unsigned char *) &logs);
- //fc.send (station1);
- fc.send (station2);
-
- segmentation (&maximus, &station1, station1_cb, sar_max_job);
-
- i = 0;
- while (!station1_rsp && !test_fail)
- {
- if (i > 50)
- {
- test_fail = true;
- }
- i++;
-
- maximus.process ();
- }
-
- if (test_fail)
- return -1;
-
- reassembly (&maximus, &station2, &station2_cb, sar_max_job);
-
- i = 0;
- while (!station2_rsp && !test_fail)
- {
- if (i > 50)
- {
- test_fail = true;
- }
- i++;
-
- maximus.process ();
- }
-
- maximus.wait (100);
-
- if (test_fail)
- return -1;
- else
- return 0;
-}
-
-/**
- * The station 1 callback
- *
- * \param msg the message
- */
-void station1_cb (Msg &msg)
-{
- char value[2];
- char id [5];
- unsigned int val;
- void *msg_return;
- blk_t *blk;
-
- //char * buffer = new char [FUNCTION_CALL_PARAM_MAX_SIZE];
- char * buffer = new char [512];
- unsigned long length = 512*sizeof(char);
-
- // Try to get the error message if the segmentation fail.
- msg_return = msg.bind_param ("type", length, (unsigned char * &) buffer);
-
- if (strcmp (buffer, "SEG") != 0)
- {
- test_fail = true;
- }
- else
- {
- blk = (blk_t *) malloc (sizeof(blk_t));
- blk->qte = msg.bind_param<unsigned int> ("qte");
-
- for (val = 0; val < blk->qte; val++)
- {
- sprintf (value, "%d", val);
-
- strcpy (id, "pb");
- strcat (id, value);
-
- length = 512*sizeof(char);
- msg_return = msg.bind_param (id, length,
- (unsigned char * &) buffer);
-
- if (msg_return != NULL)
- {
- memcpy (blk->pbs[val], buffer, 512);
- }
-
- strcpy (id, "pbh");
- strcat (id, value);
- blk->header[val] = msg.bind_param<unsigned int> (id);
- }
-
- write (fifo_blk[1], blk, sizeof(blk_t));
- }
-
- delete [] buffer;
- buffer = NULL;
-
- station1_rsp = true;
-}
-
-/**
- * The station 2 callback
- *
- * \param msg the message
- */
-void station2_cb (Msg &msg)
-{
- station2_rsp = true;
-}
-
-/**
- * Launch the segmentation process on the sta with the packet provided given by
- * packet number.
- *
- * \param maximus the maximus object simulator
- * \param station the station on which the segmentation must be done
- * \param sta_cb the callback to call once the bridge dma had finished to
- * process a segmentation.
- * \param job the job to be processed
- *
- * \return a boolean set to true.
- */
-bool segmentation (Maximus *maximus, Sta *station, station_cb_t sta_cb,
- sar_max_job_t *job) throw()
-{
- sar_max_job_t *curr;
- unsigned char job_nb;
- char id[5];
- char val[2];
-
- if (!maximus || !station || !job)
- {
- throw Error (__PRETTY_FUNCTION__, "!maximus || !station || !job");
- }
-
- curr = job;
-
- //create the function call
- Msg fc_sta = maximus->create_fc ("segmentation");
-
- /* add the buffer address */
- job_nb = 0;
- for (curr = job; curr; curr = curr->next, job_nb++)
- {
- sprintf (val, "%d", job_nb);
- strcpy (id, "job");
- strcat (id, val);
- fc_sta.add_param (id, sizeof(sar_max_job_t), (unsigned char*) curr);
- printf ("[DEBUG - MAX] job id : %d\n", curr->packet_id);
- }
-
- fc_sta.add_param ("qte", sizeof(unsigned char), (unsigned char*) &job_nb);
-
- fc_sta.set_cb (sta_cb);
- fc_sta.send (*station);
-
- return true;
-}
-
-/**
- * Launch the segmentation process on the sta with the packet provided given by
- * packet number.
- *
- * \param maximus the maximus object simulator
- * \param station the station on which the segmentation must be done
- * \param sta_cb the callback to call once the bridge dma had finished to
- * process a segmentation.
- * \param job the job to be processed
- *
- *
- * \return a boolean set to true.
- */
-bool reassembly (Maximus *maximus, Sta *station, station_cb_t sta_cb,
- sar_max_job_t *sar_max_job) throw()
-{
- char value[3];
- char id[5];
- unsigned int i;
- sar_max_job_t *curr;
- blk_t blk;
- unsigned char job_nb;
-
- if (!maximus || !station || !sar_max_job)
- {
- throw Error (__PRETTY_FUNCTION__, "!maximus || !station || !job");
- }
-
- // take the first element of the fifo
- if (read (fifo_blk[0], &blk, sizeof(blk_t)) != sizeof(blk_t))
- {
- return false;
- }
-
- //create the function call
- Msg fc_sta = maximus->create_fc ("reassembly");
-
- job_nb = 0;
- for (curr = sar_max_job; curr; curr = curr->next, job_nb++)
- {
- sprintf (value, "%d", job_nb);
- strcpy (id, "job");
- strcat (id, value);
- fc_sta.add_param (id, sizeof(sar_max_job_t), (unsigned char*) curr);
- printf ("[DEBUG - MAX] job id : %d\n", curr->packet_id);
- }
-
- fc_sta.add_param ("job_qte", sizeof(unsigned char),
- (unsigned char*) &job_nb);
-
- /* add the buffer address */
- fc_sta.add_param ("pb_qte", sizeof(unsigned int),
- (unsigned char*) &blk.qte);
-
- for (i = 0; i < blk.qte; i++)
- {
- sprintf (value, "%d", i);
- strcpy (id, "pb");
- strcat (id, value);
-
- fc_sta.add_param (id, 1024 * sizeof(unsigned char),
- (unsigned char*) blk.pbs[i]);
-
- strcpy (id, "pbh");
- strcat (id, value);
- fc_sta.add_param (id, sizeof(unsigned int),
- (unsigned char*) &blk.header[i]);
- }
-
- fc_sta.set_cb (sta_cb);
- fc_sta.send (*station);
-
- return true;
-}
-