summaryrefslogtreecommitdiff
path: root/mac/sar/test/maximus_test/src/Maximus_sar.cpp
diff options
context:
space:
mode:
authorlaranjeiro2007-09-17 08:52:00 +0000
committerlaranjeiro2007-09-17 08:52:00 +0000
commit3e4a2e23e1ee516b784fc81a4010c8908fb50d1c (patch)
tree35e355fc279c96bf85b5a930aa393fa083672068 /mac/sar/test/maximus_test/src/Maximus_sar.cpp
parent09ff5bb0759bcb54a29d7b45583f18c8be49436b (diff)
Removing the old sar tests on maximus.
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@711 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.cpp340
1 files changed, 340 insertions, 0 deletions
diff --git a/mac/sar/test/maximus_test/src/Maximus_sar.cpp b/mac/sar/test/maximus_test/src/Maximus_sar.cpp
new file mode 100644
index 0000000000..8d425dccf9
--- /dev/null
+++ b/mac/sar/test/maximus_test/src/Maximus_sar.cpp
@@ -0,0 +1,340 @@
+/* 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 true
+
+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 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 lid the lid of the MFS.
+ * \param tei the tei of the destination sta
+ * \param bcast if it is a bcast message
+ * \param mf_type the type of the message, will be verified with the lid on the
+ * station.
+ * \param packet the packet row number of the Ethernet packet array in the sta,
+ * see the eth_packets.h in mac/sar/test/inc.
+ *
+ * \return a boolean set to true.
+ */
+bool segmentation (Sta *station, station_cb_t sta_cb, unsigned char lid,
+ unsigned char tei, bool bcast, unsigned char mf_type,
+ unsigned char packet);
+
+/**
+ * Launch the reassembly process on the sta with the packets previously
+ * segmented by another sta.
+ *
+ * \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 reassembly.
+ * \param lid the lid of the MFS.
+ * \param tei the tei of the destination sta
+ * \param bcast if it is a bcast message
+ * \param mf_type the type of the message, will be verified with the lid on the
+ * station.
+ * \param packet the packet row number of the Ethernet packet array in the sta,
+ * see the eth_packets.h in mac/sar/test/inc.
+ *
+ * \return a boolean set to true.
+ */
+bool reassembly (Sta *station, station_cb_t sta_cb, unsigned char lid,
+ unsigned char tei, bool bcast, unsigned char mf_type,
+ unsigned char packet);
+
+/**
+ * Launch the test on one shoot mode.
+ *
+ * \param argc the quantity of arguments provided
+ * \param argv the char array containing the arguments
+ *
+ * \return the end value
+ */
+int one_shoot (int argc, char *argv[]);
+
+unsigned char blk[5][1024];
+unsigned int blk_header[5];
+unsigned int nb_data_received;
+
+bool station1_rsp;
+bool station2_rsp;
+bool test_fail;
+
+Maximus maximus;
+
+int main (int argc, char *argv[])
+{
+ return one_shoot(argc, argv);
+}
+
+/**
+ * Launch the test on one shoot mode.
+ *
+ * \param argc the quantity of arguments provided
+ * \param argv the char array containing the arguments
+ *
+ * \return the end value
+ */
+int one_shoot (int argc, char *argv[])
+{
+ unsigned char lid;
+ unsigned char tei;
+ bool bcast;
+ unsigned char mf_type;
+ unsigned char packet;
+ bool logs;
+
+ test_fail = false;
+ station1_rsp = false;
+ station2_rsp = false;
+
+ 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 ("debug", sizeof(unsigned char), (unsigned char *) &logs);
+ fc.send (station2);
+ //fc.send (station1);
+
+ lid = 1;
+ tei = 2;
+ bcast = true;
+ mf_type = 2;
+ packet = 0;
+ segmentation (&station1, station1_cb, lid, tei, bcast, mf_type, packet);
+
+ while (!station1_rsp)
+ {
+ maximus.process ();
+ }
+
+ if (test_fail)
+ return 0;
+
+ tei = 1;
+ reassembly (&station2, station2_cb, lid, tei, bcast, mf_type, packet);
+
+ while (!station2_rsp)
+ {
+ maximus.process ();
+ }
+
+ maximus.wait (10000);
+
+ 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;
+
+ char * buffer = new char [FUNCTION_CALL_PARAM_MAX_SIZE];
+ unsigned long length = FUNCTION_CALL_PARAM_MAX_SIZE*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
+ {
+ nb_data_received = msg.bind_param<unsigned int> ("qte");
+
+ for (val = 0; val < nb_data_received; val++)
+ {
+ sprintf (value, "%d", val);
+
+ strcpy (id, "pb");
+ strcat (id, value);
+ msg_return = msg.bind_param (id, length,
+ (unsigned char * &) buffer);
+
+ if (msg_return != NULL)
+ {
+ memcpy (blk[val], buffer, 512);
+ }
+
+ strcpy (id, "pbh");
+ strcat (id, value);
+ blk_header[val] = msg.bind_param<unsigned int> (id);
+ }
+ }
+
+ 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 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 lid the lid of the MFS.
+ * \param tei the tei of the destination sta
+ * \param bcast if it is a bcast message
+ * \param mf_type the type of the message, will be verified with the lid on the
+ * station.
+ * \param packet the packet row number of the Ethernet packet array in the sta,
+ * see the eth_packets.h in mac/sar/test/inc.
+ *
+ * \return a boolean set to true.
+ */
+bool segmentation (Sta *station, station_cb_t sta_cb, unsigned char lid,
+ unsigned char tei, bool bcast, unsigned char mf_type,
+ unsigned char packet)
+{
+ //create the function call
+ Msg fc_sta = maximus.create_fc ("segmentation");
+
+ /* add the buffer address */
+ fc_sta.add_param ("lid", sizeof(unsigned char), &lid);
+ fc_sta.add_param ("tei", sizeof(unsigned char), &tei);
+ fc_sta.add_param ("packet", sizeof(unsigned char), &packet);
+ fc_sta.add_param ("bcast", sizeof(unsigned char), (unsigned char*) &bcast);
+ fc_sta.add_param ("mf_type", sizeof(unsigned char), &mf_type);
+
+ fc_sta.set_cb (sta_cb);
+ fc_sta.send (*station);
+
+ return true;
+}
+
+/**
+ * Launch the reassembly process on the sta with the packets previously
+ * segmented by another sta.
+ *
+ * \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 reassembly.
+ * \param lid the lid of the MFS.
+ * \param tei the tei of the destination sta
+ * \param bcast if it is a bcast message
+ * \param mf_type the type of the message, will be verified with the lid on the
+ * station.
+ * \param packet the packet row number of the Ethernet packet array in the sta,
+ * see the eth_packets.h in mac/sar/test/inc.
+ *
+ * \return a boolean set to true.
+ */
+bool reassembly (Sta *station, station_cb_t sta_cb, unsigned char lid,
+ unsigned char tei, bool bcast, unsigned char mf_type,
+ unsigned char packet)
+{
+ char value[3];
+ char id[5];
+ unsigned int i;
+
+ //create the function call
+ Msg fc_sta = maximus.create_fc ("reassembly");
+
+ /* add the buffer address */
+ fc_sta.add_param ("lid", sizeof(unsigned char), &lid);
+ fc_sta.add_param ("tei", sizeof(unsigned char), &tei);
+ fc_sta.add_param ("bcast", sizeof(unsigned char), (unsigned char*) &bcast);
+ fc_sta.add_param ("packet", sizeof(unsigned char), &packet);
+ fc_sta.add_param ("qte", sizeof(unsigned int),
+ (unsigned char*) &nb_data_received);
+
+ for (i = 0; i < nb_data_received; i++)
+ {
+ sprintf (value, "%d", i);
+ strcpy (id, "pb");
+ strcat (id, value);
+
+ fc_sta.add_param (id, 1024 * sizeof(unsigned char),
+ (unsigned char*) blk[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;
+}
+