diff options
author | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-03-04 14:51:23 +0000 |
---|---|---|
committer | William R. Otte <wotte@dre.vanderbilt.edu> | 2008-03-04 14:51:23 +0000 |
commit | 99aa8c60282c7b8072eb35eb9ac815702f5bf586 (patch) | |
tree | bda96bf8c3a4c2875a083d7b16720533c8ffeaf4 /ACE/protocols/examples | |
parent | c4078c377d74290ebe4e66da0b4975da91732376 (diff) | |
download | ATCD-99aa8c60282c7b8072eb35eb9ac815702f5bf586.tar.gz |
undoing accidental deletion
Diffstat (limited to 'ACE/protocols/examples')
-rw-r--r-- | ACE/protocols/examples/Makefile.am | 14 | ||||
-rw-r--r-- | ACE/protocols/examples/RMCast/Makefile.am | 13 | ||||
-rw-r--r-- | ACE/protocols/examples/RMCast/Send_Msg/Makefile.am | 72 | ||||
-rw-r--r-- | ACE/protocols/examples/RMCast/Send_Msg/Protocol.h | 18 | ||||
-rw-r--r-- | ACE/protocols/examples/RMCast/Send_Msg/README | 18 | ||||
-rw-r--r-- | ACE/protocols/examples/RMCast/Send_Msg/Receiver.cpp | 206 | ||||
-rw-r--r-- | ACE/protocols/examples/RMCast/Send_Msg/Send_Msg.mpc | 17 | ||||
-rw-r--r-- | ACE/protocols/examples/RMCast/Send_Msg/Sender.cpp | 53 | ||||
-rw-r--r-- | ACE/protocols/examples/TMCast/Makefile.am | 13 | ||||
-rw-r--r-- | ACE/protocols/examples/TMCast/Member/Makefile.am | 45 | ||||
-rw-r--r-- | ACE/protocols/examples/TMCast/Member/Member.mpc | 7 | ||||
-rw-r--r-- | ACE/protocols/examples/TMCast/Member/README | 36 | ||||
-rw-r--r-- | ACE/protocols/examples/TMCast/Member/member.cpp | 93 | ||||
-rw-r--r-- | ACE/protocols/examples/examples.mwc | 5 |
14 files changed, 610 insertions, 0 deletions
diff --git a/ACE/protocols/examples/Makefile.am b/ACE/protocols/examples/Makefile.am new file mode 100644 index 00000000000..b435d1c3fe2 --- /dev/null +++ b/ACE/protocols/examples/Makefile.am @@ -0,0 +1,14 @@ +## 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 + +SUBDIRS = \ + RMCast \ + TMCast + diff --git a/ACE/protocols/examples/RMCast/Makefile.am b/ACE/protocols/examples/RMCast/Makefile.am new file mode 100644 index 00000000000..ef4f29c4f65 --- /dev/null +++ b/ACE/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 -type automake -noreldefs ACE.mwc + +SUBDIRS = \ + Send_Msg + 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; +} diff --git a/ACE/protocols/examples/TMCast/Makefile.am b/ACE/protocols/examples/TMCast/Makefile.am new file mode 100644 index 00000000000..358fc18ef31 --- /dev/null +++ b/ACE/protocols/examples/TMCast/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 -type automake -noreldefs ACE.mwc + +SUBDIRS = \ + Member + diff --git a/ACE/protocols/examples/TMCast/Member/Makefile.am b/ACE/protocols/examples/TMCast/Member/Makefile.am new file mode 100644 index 00000000000..c5c5c31c34f --- /dev/null +++ b/ACE/protocols/examples/TMCast/Member/Makefile.am @@ -0,0 +1,45 @@ +## 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) + + +## Makefile.Member.am + +if BUILD_EXCEPTIONS +if BUILD_THREADS +if !BUILD_ACE_FOR_TAO + +noinst_PROGRAMS = member + +member_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -I$(ACE_ROOT)/protocols + +member_SOURCES = \ + member.cpp + +member_LDADD = \ + $(ACE_BUILDDIR)/protocols/ace/TMCast/libACE_TMCast.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/TMCast/Member/Member.mpc b/ACE/protocols/examples/TMCast/Member/Member.mpc new file mode 100644 index 00000000000..29f274f51f3 --- /dev/null +++ b/ACE/protocols/examples/TMCast/Member/Member.mpc @@ -0,0 +1,7 @@ +// -*- MPC -*- +// $Id$ + +project: aceexe, tmcast { + exename = member +} + diff --git a/ACE/protocols/examples/TMCast/Member/README b/ACE/protocols/examples/TMCast/Member/README new file mode 100644 index 00000000000..6a62a107a77 --- /dev/null +++ b/ACE/protocols/examples/TMCast/Member/README @@ -0,0 +1,36 @@ +Member example shows how you can build a simple multicast group +using transactional multicast (TMCast). Each member can be either +a sender or a receiver. + +The sender sends small messages to the multicast group with a random +wait period in [0, 1] second range. The receiver is simply receiving +those messages and prints them out. + +To start the sender you can execute something like this: + +$ ./member s sender-1 239.255.0.1:10000 + +Here the first argument ('s') indicates that new member will be +a sender. The second argument ('sender-1') is an id of the new +member (each member of the group should have a unique id). And +the third argument ('239.255.0.1:10000') specifies IPv4 multicast +address and port (you can choose you own). + +To start the receiver you can execute similar command: + +$ ./member r receiver-1 239.255.0.1:10000 + +After you have started both the receiver and the sender you +should see a sequence of messages printed by the receiver. + +Note, since the group can exist with only one member for a +very short period of time you should start first two members +virtually at the same time. See TMCast documentation for more +information about why it behaves this way. + +You may want to add more than one sender to the group if you +want to see how TMCast operates in a totally-ordered mode. + + +-- +Boris Kolpackov <boris@dre.vanderbilt.edu> diff --git a/ACE/protocols/examples/TMCast/Member/member.cpp b/ACE/protocols/examples/TMCast/Member/member.cpp new file mode 100644 index 00000000000..7aad7736ccf --- /dev/null +++ b/ACE/protocols/examples/TMCast/Member/member.cpp @@ -0,0 +1,93 @@ +// file : TMCast/Member/member.cpp +// author : Boris Kolpackov <boris@dre.vanderbilt.edu> +// cvs-id : $Id$ + +#include "ace/Log_Msg.h" +#include "ace/Time_Value.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" +#include "ace/OS_NS_stdio.h" +#include "ace/OS_NS_time.h" +#include "ace/OS_NS_string.h" + +#include "ace/TMCast/Group.hpp" + +class Args {}; + +int +ACE_TMAIN (int argc, ACE_TCHAR* argv[]) +{ + int status = 0; + try + { + if (argc < 4) throw Args (); + + bool receiver (true); + + if (argv[1][0] == 'r') receiver = true; + else if (argv[1][0] == 's') receiver = false; + else throw Args (); + + if (!receiver) ACE_OS::srand ((u_int) ACE_OS::time ()); + + ACE_INET_Addr address (argv[3]); + + ACE_TMCast::Group group (address, ACE_TEXT_ALWAYS_CHAR (argv[2])); + + if (receiver) + { + for (char buffer[256];;) + { + group.recv (buffer, sizeof (buffer)); + + ACE_DEBUG ((LM_DEBUG, "%s\n", buffer)); + } + } + else + { + char buffer[256]; + + for (unsigned long i = 0; i < 1000; i++) + { + // Sleep some random time around 1 sec. + + ACE_UINT64 tmpl = 1000000U; + unsigned long t = + static_cast<unsigned long> (((tmpl * ACE_OS::rand ()) / RAND_MAX)); + + // ACE_DEBUG ((LM_DEBUG, "sleeping for %u\n", t)); + + ACE_OS::sleep (ACE_Time_Value (0, t)); + + ACE_OS::sprintf (buffer, "message # %lu", i); + + try + { + group.send (buffer, ACE_OS::strlen (buffer) + 1); + } + catch (ACE_TMCast::Group::Aborted const&) + { + ACE_ERROR ((LM_ERROR, "%s has been aborted\n", buffer)); + } + } + } + } + catch (Args const&) + { + ACE_ERROR ((LM_ERROR, + "Usage: member {r|s} <id> <IPv4 mcast address>:<port>\n")); + status++; + } + catch (ACE_TMCast::Group::Failed const&) + { + ACE_ERROR ((LM_ERROR, + "Group failure. Perhaps I am alone in the group.\n")); + status++; + } + catch (ACE_TMCast::Group::InsufficienSpace const&) + { + ACE_ERROR ((LM_ERROR, "Insufficient space in receive buffer.\n")); + status++; + } + return status; +} diff --git a/ACE/protocols/examples/examples.mwc b/ACE/protocols/examples/examples.mwc new file mode 100644 index 00000000000..dd297256b34 --- /dev/null +++ b/ACE/protocols/examples/examples.mwc @@ -0,0 +1,5 @@ +// -*- MPC -*- +// $Id$ + +workspace { +} |