summaryrefslogtreecommitdiff
path: root/mac/sar/test/maximus_test/src/Maximus_sar.cpp
diff options
context:
space:
mode:
authorlaranjeiro2007-09-10 08:51:26 +0000
committerlaranjeiro2007-09-10 08:51:26 +0000
commit7c41f10c67f526229f504d8a15968f3851635330 (patch)
treea286e7aafdbfbc04375aaa62c4a36170493df53f /mac/sar/test/maximus_test/src/Maximus_sar.cpp
parent510b07e79ed1c6ae2d6b41d44dba1cf97ac0f700 (diff)
SAR complete on maximus (not operational yet, use for the ecos interruption)
git-svn-id: svn+ssh://pessac/svn/cesar/trunk@681 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.cpp158
1 files changed, 158 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..eeea77c282
--- /dev/null
+++ b/mac/sar/test/maximus_test/src/Maximus_sar.cpp
@@ -0,0 +1,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;
+}