summaryrefslogtreecommitdiff
path: root/ACE/protocols/examples/RMCast/Send_Msg
diff options
context:
space:
mode:
Diffstat (limited to 'ACE/protocols/examples/RMCast/Send_Msg')
-rw-r--r--ACE/protocols/examples/RMCast/Send_Msg/Makefile.am72
-rw-r--r--ACE/protocols/examples/RMCast/Send_Msg/Protocol.h18
-rw-r--r--ACE/protocols/examples/RMCast/Send_Msg/README18
-rw-r--r--ACE/protocols/examples/RMCast/Send_Msg/Receiver.cpp206
-rw-r--r--ACE/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc17
-rw-r--r--ACE/protocols/examples/RMCast/Send_Msg/Sender.cpp53
6 files changed, 384 insertions, 0 deletions
diff --git a/ACE/protocols/examples/RMCast/Send_Msg/Makefile.am b/ACE/protocols/examples/RMCast/Send_Msg/Makefile.am
new file mode 100644
index 00000000000..eb9a09d771f
--- /dev/null
+++ b/ACE/protocols/examples/RMCast/Send_Msg/Makefile.am
@@ -0,0 +1,72 @@
+## Process this file with automake to create Makefile.in
+##
+## $Id$
+##
+## This file was generated by MPC. Any changes made directly to
+## this file will be lost the next time it is generated.
+##
+## MPC Command:
+## ./bin/mwc.pl -type automake -noreldefs ACE.mwc
+
+ACE_BUILDDIR = $(top_builddir)
+ACE_ROOT = $(top_srcdir)
+
+noinst_PROGRAMS =
+
+## Makefile.Send_Msg_Receiver.am
+
+if BUILD_EXCEPTIONS
+if BUILD_THREADS
+if !BUILD_ACE_FOR_TAO
+
+noinst_PROGRAMS += receiver
+
+receiver_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR) \
+ -I$(ACE_ROOT)/protocols
+
+receiver_SOURCES = \
+ Receiver.cpp \
+ Protocol.h
+
+receiver_LDADD = \
+ $(ACE_BUILDDIR)/protocols/ace/RMCast/libACE_RMCast.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+endif !BUILD_ACE_FOR_TAO
+endif BUILD_THREADS
+endif BUILD_EXCEPTIONS
+
+## Makefile.Send_Msg_Sender.am
+
+if BUILD_EXCEPTIONS
+if BUILD_THREADS
+if !BUILD_ACE_FOR_TAO
+
+noinst_PROGRAMS += sender
+
+sender_CPPFLAGS = \
+ -I$(ACE_ROOT) \
+ -I$(ACE_BUILDDIR) \
+ -I$(ACE_ROOT)/protocols
+
+sender_SOURCES = \
+ Sender.cpp \
+ Protocol.h
+
+sender_LDADD = \
+ $(ACE_BUILDDIR)/protocols/ace/RMCast/libACE_RMCast.la \
+ $(ACE_BUILDDIR)/ace/libACE.la
+
+endif !BUILD_ACE_FOR_TAO
+endif BUILD_THREADS
+endif BUILD_EXCEPTIONS
+
+## Clean up template repositories, etc.
+clean-local:
+ -rm -f *~ *.bak *.rpo *.sym lib*.*_pure_* core core.*
+ -rm -f gcctemp.c gcctemp so_locations *.ics
+ -rm -rf cxx_repository ptrepository ti_files
+ -rm -rf templateregistry ir.out
+ -rm -rf ptrepository SunWS_cache Templates.DB
diff --git a/ACE/protocols/examples/RMCast/Send_Msg/Protocol.h b/ACE/protocols/examples/RMCast/Send_Msg/Protocol.h
new file mode 100644
index 00000000000..88fdb4d6a51
--- /dev/null
+++ b/ACE/protocols/examples/RMCast/Send_Msg/Protocol.h
@@ -0,0 +1,18 @@
+// file : Protocol.h
+// author : Boris Kolpackov <boris@kolpackov.net>
+// cvs-id : $Id$
+
+#ifndef PROTOCOL_H
+#define PROTOCOL_H
+
+unsigned short const payload_size = 702;
+unsigned long const message_count = 80000;
+
+struct Message
+{
+ unsigned int sn;
+
+ unsigned short payload[payload_size];
+};
+
+#endif // PROTOCOL_H
diff --git a/ACE/protocols/examples/RMCast/Send_Msg/README b/ACE/protocols/examples/RMCast/Send_Msg/README
new file mode 100644
index 00000000000..b02056bf0cf
--- /dev/null
+++ b/ACE/protocols/examples/RMCast/Send_Msg/README
@@ -0,0 +1,18 @@
+In this example SENDER sends a number (defined in Protocol.h, 10000
+by default) of messages to the multicast group. Each message has
+an application-level sequence number. RECEIVER tries to receive them
+and checks for damaged, lost, and reordered messages. Since reliable
+multicast is used there should be no damaged or reordered messages.
+There could be some number of lost messages at the beginning,
+howevere (standard race condition).
+
+To run the example start a one or more RECEIVERS, e.g.,
+
+$ ./receiver 224.1.0.1:10000
+
+Then start one SENDER:
+
+$ ./sender 224.1.0.1:10000
+
+--
+Boris Kolpackov <boris@kolpackov.net>
diff --git a/ACE/protocols/examples/RMCast/Send_Msg/Receiver.cpp b/ACE/protocols/examples/RMCast/Send_Msg/Receiver.cpp
new file mode 100644
index 00000000000..c6378948fc8
--- /dev/null
+++ b/ACE/protocols/examples/RMCast/Send_Msg/Receiver.cpp
@@ -0,0 +1,206 @@
+// file : Receiver.cpp
+// author : Boris Kolpackov <boris@kolpackov.net>
+// cvs-id : $Id$
+
+#include "ace/Vector_T.h"
+#include "ace/Log_Msg.h"
+#include "ace/OS_NS_string.h"
+#include "ace/Time_Value.h" // ACE_Time_Value
+#include "ace/OS_NS_sys_time.h" // gettimeofday
+
+#include "ace/RMCast/Socket.h"
+
+#include "Protocol.h"
+
+typedef
+ACE_Vector<unsigned char, ACE_VECTOR_DEFAULT_SIZE>
+Status_List;
+
+class args {};
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR* argv[])
+{
+ try
+ {
+ if (argc < 2) throw args ();
+
+ ACE_INET_Addr addr (argv[1]);
+
+ //FUZZ: disable check_for_lack_ACE_OS
+ ACE_RMCast::Socket socket (addr, false);
+ //FUZZ: enable check_for_lack_ACE_OS
+
+ Message expected_msg;
+ expected_msg.sn = 0;
+
+ // VC6 does not know about the new rules.
+ //
+ {
+ for (unsigned short i = 0; i < payload_size; i++)
+ {
+ expected_msg.payload[i] = i;
+ }
+ }
+
+ Status_List received (message_count);
+ Status_List damaged (message_count);
+ Status_List duplicate (message_count);
+
+ // VC6 does not know about new rules.
+ //
+ {
+ for (unsigned int i = 0; i < message_count; ++i)
+ {
+ received.push_back (0);
+ damaged.push_back (0);
+ duplicate.push_back (0);
+ }
+ }
+
+
+ Message msg;
+ bool first (true);
+ ACE_Time_Value start_time, time;
+
+ while (true)
+ {
+ ssize_t s = socket.size ();
+
+ if (first)
+ {
+ start_time = ACE_OS::gettimeofday ();
+ first = false;
+ }
+
+ if (s == -1 && errno == ENOENT)
+ {
+ ACE_ERROR ((LM_ERROR, "unavailable message detected\n"));
+
+ // Receive it.
+ //
+ socket.recv (&msg, sizeof (msg));
+
+ continue;
+ }
+
+ if (s != sizeof (msg))
+ {
+ ACE_ERROR ((LM_ERROR, "unexpected message size %d, expected %d\n",
+ s, sizeof (msg)));
+ continue;
+ }
+
+ if (socket.recv (&msg, sizeof (msg)) != s)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "recv() reported different size than size()\n"));
+ continue;
+ }
+
+ if (received[msg.sn] == 1)
+ {
+ duplicate[msg.sn] = 1;
+ }
+ else
+ {
+ received[msg.sn] = 1;
+
+ if (ACE_OS::memcmp (expected_msg.payload,
+ msg.payload,
+ payload_size) != 0)
+ {
+ damaged[msg.sn] = 1;
+ }
+ }
+
+ if (msg.sn + 1 == message_count) break;
+ }
+
+ time = ACE_OS::gettimeofday () - start_time;
+
+ unsigned int lost_count (0), damaged_count (0), duplicate_count (0);
+
+ {
+ for (Status_List::Iterator i (received); !i.done (); i.advance ())
+ {
+ unsigned char* e;
+ i.next (e);
+
+ if (*e == 0) ++lost_count;
+ }
+ }
+
+
+ {
+ for (Status_List::Iterator i (damaged); !i.done (); i.advance ())
+ {
+ unsigned char* e;
+ i.next (e);
+
+ if (*e == 1) ++damaged_count;
+ }
+ }
+
+
+ {
+ for (Status_List::Iterator i (duplicate); !i.done (); i.advance ())
+ {
+ unsigned char* e;
+ i.next (e);
+
+ if (*e == 1) ++duplicate_count;
+ }
+ }
+
+ unsigned long tput =
+ (sizeof (msg) * message_count) / (time.msec () == 0 ? 1 : time.msec ());
+
+ ACE_DEBUG ((LM_DEBUG,
+ "lost : %d\n"
+ "damaged : %d\n"
+ "duplicate : %d\n"
+ "throughput : %d KB/sec\n",
+ lost_count,
+ damaged_count,
+ duplicate_count,
+ tput));
+
+ /*
+ cout << "lost message dump:" << endl;
+
+ unsigned long total = 0;
+
+ for (Status_List::iterator
+ begin (received.begin ()), i (begin), end (received.end ());
+ i != end;)
+ {
+ if (*i == 0)
+ {
+ unsigned long count = 1;
+
+ for (Status_List::iterator j = i + 1;
+ j < end && *j == 0;
+ j++, count++);
+
+ cout << '\t' << i - begin << " : " << count << endl;
+
+ i += count;
+ total += count;
+ }
+ else ++i;
+ }
+
+ if (total != lost_count) cerr << "trouble" << endl;
+ */
+
+ return 0;
+ }
+ catch (args const&)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "usage: %s <IPv4 multicast address>:<port>\n", argv[0]));
+ }
+
+ return 1;
+}
diff --git a/ACE/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc b/ACE/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc
new file mode 100644
index 00000000000..981df7ec8a7
--- /dev/null
+++ b/ACE/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc
@@ -0,0 +1,17 @@
+// -*- MPC -*-
+// $Id$
+
+project(*Sender) : aceexe, exceptions, rmcast {
+ avoids = ace_for_tao
+ exename = sender
+ Source_Files {
+ Sender.cpp
+ }
+}
+project(*Receiver) : aceexe, exceptions, rmcast {
+ avoids = ace_for_tao
+ exename = receiver
+ Source_Files {
+ Receiver.cpp
+ }
+}
diff --git a/ACE/protocols/examples/RMCast/Send_Msg/Sender.cpp b/ACE/protocols/examples/RMCast/Send_Msg/Sender.cpp
new file mode 100644
index 00000000000..5a1ed1674d6
--- /dev/null
+++ b/ACE/protocols/examples/RMCast/Send_Msg/Sender.cpp
@@ -0,0 +1,53 @@
+// file : Sender.cpp
+// author : Boris Kolpackov <boris@kolpackov.net>
+// cvs-id : $Id$
+
+#include "ace/OS.h"
+#include "ace/Log_Msg.h"
+
+#include "ace/RMCast/Socket.h"
+
+#include "Protocol.h"
+
+class args {};
+
+int
+ACE_TMAIN (int argc, ACE_TCHAR* argv[])
+{
+ try
+ {
+ if (argc < 2) throw args ();
+
+ ACE_INET_Addr addr (argv[1]);
+
+ //FUZZ: disable check_for_lack_ACE_OS
+ ACE_RMCast::Socket socket (addr, false);
+ //FUZZ: enable check_for_lack_ACE_OS
+
+ Message msg;
+ msg.sn = 0;
+
+ for (unsigned short i = 0; i < payload_size; i++)
+ {
+ msg.payload[i] = i;
+ }
+
+ for (; msg.sn < message_count; msg.sn++)
+ {
+ socket.send (&msg, sizeof (msg));
+ }
+
+ // Keep running in case retransmissions are needed.
+ //
+ ACE_OS::sleep (ACE_Time_Value (50, 0));
+
+ return 0;
+ }
+ catch (args const&)
+ {
+ ACE_ERROR ((LM_ERROR,
+ "usage: %s <IPv4 multicast address>:<port>\n", argv[0]));
+ }
+
+ return 1;
+}