diff options
author | boris <boris@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-05-16 09:29:52 +0000 |
---|---|---|
committer | boris <boris@ae88bc3d-4319-0410-8dbf-d08b4c9d3795> | 2005-05-16 09:29:52 +0000 |
commit | 448305d11062013cccdae6de8f168a9076d3dbe2 (patch) | |
tree | 5d989079f910c26cd6fa18e8add5552497fcc528 /protocols/examples/RMCast | |
parent | 264171248721ae5d224b91f1f85512b14c26248f (diff) | |
download | ATCD-448305d11062013cccdae6de8f168a9076d3dbe2.tar.gz |
ChangeLogTag:Mon May 16 11:22:09 2005 Boris Kolpackov <boris@kolpackov.net>
Diffstat (limited to 'protocols/examples/RMCast')
-rw-r--r-- | protocols/examples/RMCast/Makefile.am | 13 | ||||
-rw-r--r-- | protocols/examples/RMCast/Send_Msg/Makefile.am | 56 | ||||
-rw-r--r-- | protocols/examples/RMCast/Send_Msg/Protocol.h | 18 | ||||
-rw-r--r-- | protocols/examples/RMCast/Send_Msg/README | 18 | ||||
-rw-r--r-- | protocols/examples/RMCast/Send_Msg/Receiver.cpp | 188 | ||||
-rw-r--r-- | protocols/examples/RMCast/Send_Msg/Send_Msg.mpc | 15 | ||||
-rw-r--r-- | protocols/examples/RMCast/Send_Msg/Sender.cpp | 51 |
7 files changed, 359 insertions, 0 deletions
diff --git a/protocols/examples/RMCast/Makefile.am b/protocols/examples/RMCast/Makefile.am new file mode 100644 index 00000000000..3a8fba8cf07 --- /dev/null +++ b/protocols/examples/RMCast/Makefile.am @@ -0,0 +1,13 @@ +## 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 -include /home/jtc/ACE/ACE-config3/MPC/config -include /home/jtc/ACE/ACE-config3/MPC/templates -type automake ACE.mwc + +SUBDIRS = \ + Send_Msg + diff --git a/protocols/examples/RMCast/Send_Msg/Makefile.am b/protocols/examples/RMCast/Send_Msg/Makefile.am new file mode 100644 index 00000000000..a7c9874b08f --- /dev/null +++ b/protocols/examples/RMCast/Send_Msg/Makefile.am @@ -0,0 +1,56 @@ +## Process this file with automake to create Makefile.in + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + +noinst_PROGRAMS = + +## Makefile.Send_Msg_Receiver.am + +if BUILD_EXCEPTIONS + +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_EXCEPTIONS + +## Makefile.Send_Msg_Sender.am + +if BUILD_EXCEPTIONS + +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_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/protocols/examples/RMCast/Send_Msg/Protocol.h b/protocols/examples/RMCast/Send_Msg/Protocol.h new file mode 100644 index 00000000000..c3edf43b1fb --- /dev/null +++ b/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 = 256; +unsigned long const message_count = 10000; + +struct Message +{ + unsigned long sn; + + unsigned short payload[payload_size]; +}; + +#endif // PROTOCOL_H diff --git a/protocols/examples/RMCast/Send_Msg/README b/protocols/examples/RMCast/Send_Msg/README new file mode 100644 index 00000000000..b02056bf0cf --- /dev/null +++ b/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/protocols/examples/RMCast/Send_Msg/Receiver.cpp b/protocols/examples/RMCast/Send_Msg/Receiver.cpp new file mode 100644 index 00000000000..39808151fe9 --- /dev/null +++ b/protocols/examples/RMCast/Send_Msg/Receiver.cpp @@ -0,0 +1,188 @@ +// 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/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]); + + ACE_RMCast::Socket socket (addr, false); + + + 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 long i = 0; i < message_count; ++i) + { + received.push_back (0); + damaged.push_back (0); + duplicate.push_back (0); + } + } + + + Message msg; + + while (true) + { + ssize_t s = socket.size (); + + 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; + } + + unsigned long 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; + } + } + + ACE_DEBUG ((LM_DEBUG, + "lost : %d\n" + "damaged : %d\n" + "duplicate : %d\n", + lost_count, + damaged_count, + duplicate_count)); + + /* + 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/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc b/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc new file mode 100644 index 00000000000..12bd8174c4b --- /dev/null +++ b/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc @@ -0,0 +1,15 @@ +// -*- MPC -*- +// $Id$ + +project(*Sender) : aceexe, exceptions, rmcast { + exename = sender + Source_Files { + Sender.cpp + } +} +project(*Receiver) : aceexe, exceptions, rmcast { + exename = receiver + Source_Files { + Receiver.cpp + } +} diff --git a/protocols/examples/RMCast/Send_Msg/Sender.cpp b/protocols/examples/RMCast/Send_Msg/Sender.cpp new file mode 100644 index 00000000000..19d570f249c --- /dev/null +++ b/protocols/examples/RMCast/Send_Msg/Sender.cpp @@ -0,0 +1,51 @@ +// 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]); + + ACE_RMCast::Socket socket (addr, false); + + 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; +} |