diff options
Diffstat (limited to 'ACE/examples/QOS')
56 files changed, 6050 insertions, 0 deletions
diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/Fill_ACE_QoS.cpp b/ACE/examples/QOS/Change_Receiver_FlowSpec/Fill_ACE_QoS.cpp new file mode 100644 index 00000000000..20c03f40fa6 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/Fill_ACE_QoS.cpp @@ -0,0 +1,99 @@ +// Fill_ACE_QoS.cpp +// $Id$ + +#include "Fill_ACE_QoS.h" + +ACE_RCSID(QOS, Fill_ACE_QoS,"$Id$") + +const iovec Fill_ACE_QoS::iov_ = {0,0}; + +Fill_ACE_QoS::Fill_ACE_QoS (void) +{ + ACE_NEW (this->default_traffic_, + ACE_Flow_Spec (ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_SERVICETYPE_NOTRAFFIC, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + 25, + 1)); +} + +// destructor. +Fill_ACE_QoS::~Fill_ACE_QoS (void) +{} + +int +Fill_ACE_QoS::fill_simplex_receiver_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name) +{ + ACE_Flow_Spec *recv_flow_spec = 0; + + if (this->map ().find (recv_flow_name, recv_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + recv_flow_name.c_str ()), + -1); + ace_qos.receiving_flowspec (recv_flow_spec); + ace_qos.sending_flowspec ((this->default_traffic_)); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + + +int +Fill_ACE_QoS::fill_simplex_sender_qos (ACE_QoS &ace_qos, + const ACE_CString &send_flow_name) +{ + ACE_Flow_Spec *send_flow_spec = 0; + + if (this->map ().find (send_flow_name, send_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + send_flow_name.c_str ()), + -1); + + ace_qos.receiving_flowspec ((this->default_traffic_)); + ace_qos.sending_flowspec (send_flow_spec); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + +int +Fill_ACE_QoS::fill_duplex_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name, + const ACE_CString &send_flow_name) +{ + ACE_Flow_Spec *send_flow_spec = 0; + ACE_Flow_Spec *recv_flow_spec = 0; + + if (this->map ().find (recv_flow_name, recv_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + recv_flow_name.c_str ()), + -1); + + if (this->map ().find (send_flow_name, send_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + send_flow_name.c_str ()), + -1); + + ace_qos.receiving_flowspec (recv_flow_spec); + ace_qos.sending_flowspec (send_flow_spec); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + +Fill_ACE_QoS::FLOW_SPEC_HASH_MAP& +Fill_ACE_QoS::map (void) +{ + return this->flow_spec_map_; +} + diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/Fill_ACE_QoS.h b/ACE/examples/QOS/Change_Receiver_FlowSpec/Fill_ACE_QoS.h new file mode 100644 index 00000000000..cdc06cea422 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/Fill_ACE_QoS.h @@ -0,0 +1,76 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Fill_ACE_QoS.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef FILL_ACE_QOS_H +#define FILL_ACE_QOS_H + +#include "ace/SString.h" +#include "ace/Hash_Map_Manager.h" +#include "ace/Synch_Traits.h" +#include "ace/Null_Mutex.h" +#include "ace/ACE.h" +#include "ace/OS_QoS.h" + +class Fill_ACE_QoS +{ + // TITLE + // This class helps users to add new flow specs and provides + // utility functions for filling up the flow specs for simplex/duplex + // sessions. + +public: + typedef ACE_Hash_Map_Manager <ACE_CString, ACE_Flow_Spec *, ACE_Null_Mutex> FLOW_SPEC_HASH_MAP; + + //Initialization and termination methods. + Fill_ACE_QoS (void); + // constructor. + + ~Fill_ACE_QoS (void); + // destructor. + + int fill_simplex_receiver_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name); + // To be used by receivers. Fills the receiver qos and sets the + // sender qos to NO_TRAFFIC. + + int fill_simplex_sender_qos (ACE_QoS &ace_qos, + const ACE_CString &send_flow_name); + // To be used by senders. Fills the sender qos and sets the receiver + // qos to NO_TRAFFIC. + + int fill_duplex_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name, + const ACE_CString &send_flow_name); + // To be used by applications that wish to be both receivers and + // senders. + + FLOW_SPEC_HASH_MAP& map (void); + // Returns the hash map of flowspecs indexed by flowspec name. + +private: + + // The Service Provider is currently set to NULL for all ACE_QoS. + static const iovec iov_; + + // A NO_TRAFFIC flow spec. Senders set the receiving qos to this + // while the receivers set the sending qos to this. + ACE_Flow_Spec *default_traffic_; + + // A list of flowspecs indexed by the flowspec name. + FLOW_SPEC_HASH_MAP flow_spec_map_; +}; + +#endif /* FILL_ACE_QOS_H */ diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/FlowSpec_Dbase.h b/ACE/examples/QOS/Change_Receiver_FlowSpec/FlowSpec_Dbase.h new file mode 100644 index 00000000000..fc382048c13 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/FlowSpec_Dbase.h @@ -0,0 +1,52 @@ +/* -*- C++ -*- */ +//$Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// FlowSpec_Dbase.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef FLOWSPEC_DBASE_H +#define FLOWSPEC_DBASE_H + +// This file contains the different FlowSpecs that the QoS enabled +// application uses. Its a good idea to list them all here so the +// application code is clean. + +ACE_Flow_Spec notraffic (ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_SERVICETYPE_NOTRAFFIC, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + 25, + 1); + +ACE_Flow_Spec g711 (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1); + +// The default session address is macarena.cs.wustl.edu. I am using macarena +// as my receiver for testing. +#define DEFAULT_QOS_SESSION_MACHINE "128.252.165.127" +#define DEFAULT_QOS_SESSION_PORT 8001 + +#endif /* FLOWSPEC_DBASE_H */ + diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/Makefile.am b/ACE/examples/QOS/Change_Receiver_FlowSpec/Makefile.am new file mode 100644 index 00000000000..c4d51897787 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/Makefile.am @@ -0,0 +1,76 @@ +## 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: +## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + +noinst_PROGRAMS = + +## Makefile.QOS_Change_Receiver_FlowSpec_Receiver.am + +if BUILD_QOS +noinst_PROGRAMS += receiver + +receiver_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +receiver_SOURCES = \ + Fill_ACE_QoS.cpp \ + QoS_Signal_Handler.cpp \ + QoS_Util.cpp \ + Receiver_QoS_Event_Handler.cpp \ + receiver.cpp \ + Fill_ACE_QoS.h \ + QoS_Signal_Handler.h \ + QoS_Util.h \ + Receiver_QoS_Event_Handler.h + +receiver_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_QOS + +## Makefile.QOS_Change_Receiver_FlowSpec_Sender.am + +if BUILD_QOS +noinst_PROGRAMS += sender + +sender_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +sender_SOURCES = \ + Fill_ACE_QoS.cpp \ + QoS_Signal_Handler.cpp \ + QoS_Util.cpp \ + Sender_QoS_Event_Handler.cpp \ + sender.cpp \ + Fill_ACE_QoS.h \ + QoS_Signal_Handler.h \ + QoS_Util.h \ + Sender_QoS_Event_Handler.h + +sender_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_QOS + +## 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/examples/QOS/Change_Receiver_FlowSpec/QOS_Change_Receiver_FlowSpec.mpc b/ACE/examples/QOS/Change_Receiver_FlowSpec/QOS_Change_Receiver_FlowSpec.mpc new file mode 100644 index 00000000000..9767bd6fdb9 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/QOS_Change_Receiver_FlowSpec.mpc @@ -0,0 +1,25 @@ +// -*- MPC -*- +// $Id$ + +project(*receiver) : aceexe, qos { + exename = receiver + requires += qos + Source_Files { + Fill_ACE_QoS.cpp + QoS_Signal_Handler.cpp + QoS_Util.cpp + receiver.cpp + Receiver_QoS_Event_Handler.cpp + } +} +project(*sender) : aceexe, qos { + exename = sender + requires += qos + Source_Files { + Fill_ACE_QoS.cpp + QoS_Signal_Handler.cpp + QoS_Util.cpp + sender.cpp + Sender_QoS_Event_Handler.cpp + } +} diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Signal_Handler.cpp b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Signal_Handler.cpp new file mode 100644 index 00000000000..9f07ad5b378 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Signal_Handler.cpp @@ -0,0 +1,34 @@ +// QoS_Signal_Handler.cpp +// $Id$ + +#include "ace/Log_Msg.h" +#include "QoS_Signal_Handler.h" + +ACE_RCSID(QOS, QoS_Signal_Handler,"$Id$") + +// constructor. +QoS_Signal_Handler::QoS_Signal_Handler (ACE_QoS_Session *qos_session) + : qos_session_ (qos_session) +{ +} + +// Releases the QoS sessions gracefully. +int +QoS_Signal_Handler::handle_signal (int signum, siginfo_t *, ucontext_t*) +{ + if (signum == SIGINT) + { + if (this->qos_session_->close () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to close the QoS session.\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS Session with id %d closed successfully.\n", + this->qos_session_->session_id ())); + } + else + ACE_DEBUG ((LM_DEBUG, + "A signal other than SIGINT received.\nIgnoring.\n")); + return 0; +} diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Signal_Handler.h b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Signal_Handler.h new file mode 100644 index 00000000000..35b9f3a19e7 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Signal_Handler.h @@ -0,0 +1,45 @@ +/* -*- C++ -*- */ +// $Id$ + +// ===================================================================== +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// QoS_Signal_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ===================================================================== + +#ifndef QOS_SIGNAL_HANDLER_H +#define QOS_SIGNAL_HANDLER_H + +#include "ace/Event_Handler.h" +#include "ace/QoS/QoS_Session.h" + +class QoS_Signal_Handler : public ACE_Event_Handler +{ + // TITLE + // This class Handles the SIGINT signal through the Reactor. + // Useful to gracefully release QoS sessions. + +public: + + QoS_Signal_Handler (ACE_QoS_Session *qos_session); + // constructor. + + int handle_signal(int signum, siginfo_t*,ucontext_t*); + // Override this method to implement graceful shutdown. + +private: + + ACE_QoS_Session *qos_session_; + // Session to be gracefully shutdown. + +}; + +#endif /* QOS_SIGNAL_HANDLER_H */ + diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Util.cpp b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Util.cpp new file mode 100644 index 00000000000..0ef3b353248 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Util.cpp @@ -0,0 +1,122 @@ +// QoS_Session_Impl.cpp +// $Id$ + +#define SENDER_PORT 10001 + +#include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" +#include "QoS_Util.h" +#include "ace/OS_NS_strings.h" + +ACE_RCSID(QOS, QoS_Util,"$Id$") + +// constructor. +QoS_Util::QoS_Util (int argc, + ACE_TCHAR *argv[]) + : argc_ (argc), + argv_ (argv), + source_port_ (SENDER_PORT), + protocol_ (IPPROTO_UDP), + multicast_flag_ (0) +{ + ACE_NEW (this->mult_session_addr_, + ACE_INET_Addr (ACE_DEFAULT_MULTICAST_PORT)); + + ACE_NEW (this->dest_addr_, + ACE_INET_Addr (ACE_DEFAULT_SERVER_PORT)); +} + +// destructor. +QoS_Util::~QoS_Util (void) +{ + delete this->mult_session_addr_; + delete this->dest_addr_; +} + +int +QoS_Util::parse_args (void) +{ + ACE_Get_Opt get_opts (this->argc_, this->argv_, ACE_TEXT("m:n:p:P:c")); + int c = 0; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'm': // multicast session address. + this->multicast_flag_ = 1; + this->mult_session_addr_->set (get_opts.opt_arg ()); + break; + case 'n': // to be used by Senders only to specify the destination. + this->dest_addr_->set (get_opts.opt_arg ()); + break; + case 'p': // protocol. + if (ACE_OS::strcasecmp (get_opts.opt_arg (), ACE_TEXT("tcp")) == 0) + this->protocol_ = IPPROTO_TCP; + else + if (ACE_OS::strcasecmp (get_opts.opt_arg (), ACE_TEXT("udp")) == 0) + this->protocol_ = IPPROTO_UDP; + else + ACE_DEBUG ((LM_DEBUG, + "Unknown protocol specified\n" + "UDP assumed\n")); + break; + case 'P': // sender source port. + this->source_port_ = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case 'h': // display help for different options. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-m host:port] QoS multicast session address" + " Overides the receiver address specified in the -n option" + " [-n host:port] Use for a unicast sender. " + " Follow by receiver addr" + " [-p tcp|udp] specify protocol to be used" + " [-P port] source sender port" + " [-h] <help>" + "\n", + argv_ [0]), + -1); + } + + // If multicast address is specified then ignore the unicast sender + // destination address and force the protocol to be UDP. + if (this->multicast_flag_ == 1) + { + this->dest_addr_ = this->mult_session_addr_; + this->protocol_ = IPPROTO_UDP; + } + + // Indicates successful parsing of command line. + return 0; +} + +ACE_INET_Addr * +QoS_Util::mult_session_addr (void) const +{ + return this->mult_session_addr_; +} + +ACE_INET_Addr * +QoS_Util::dest_addr (void) const +{ + return this->dest_addr_; +} + +u_short +QoS_Util::source_port (void) const +{ + return this->source_port_; +} + +ACE_Protocol_ID +QoS_Util::protocol (void) const +{ + return this->protocol_; +} + +int +QoS_Util::multicast_flag (void) const +{ + return this->multicast_flag_; +} diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Util.h b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Util.h new file mode 100644 index 00000000000..ae347de68f6 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/QoS_Util.h @@ -0,0 +1,75 @@ +/* -*- C++ -*- */ +// $Id$ + +// ===================================================================== +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// QoS_Util.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ===================================================================== + +#ifndef QOS_UTIL_H +#define QOS_UTIL_H + +#include "ace/INET_Addr.h" +#include "ace/QoS/QoS_Session.h" + +class QoS_Util +{ + // = TITLE + // This class provides the utility functions like parse_args () + // required by a QoS enabled application. + +public: + + // constructor. + QoS_Util (int argc, ACE_TCHAR *argv[]); + + // destructor. + ~QoS_Util (void); + + // Parse command-line arguments. + int parse_args (void); + + // GET methods. + ACE_INET_Addr *mult_session_addr (void) const; + + ACE_INET_Addr *dest_addr (void) const; + + u_short source_port (void) const; + + ACE_Protocol_ID protocol (void) const; + + int multicast_flag (void) const; + +private: + + // Command line arguments. + int argc_; + ACE_TCHAR **argv_; + + // Multicast session address. + ACE_INET_Addr *mult_session_addr_; + + // Unicast destination address of the receiver. + ACE_INET_Addr *dest_addr_; + + // Source port for the sender. + u_short source_port_; + + // Protocol. + ACE_Protocol_ID protocol_; + + // Multicast Flag. + int multicast_flag_; + +}; + +#endif /* QOS_UTIL_H */ + diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/README b/ACE/examples/QOS/Change_Receiver_FlowSpec/README new file mode 100644 index 00000000000..58320ef8def --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/README @@ -0,0 +1,127 @@ +$Id$ + +A Regression test for ACE QoS features. +--------------------------------------- + +This test implements a simple Receiver-Sender program that ensures +Quality of Service (QoS) guarantees on the underlying network before +transmitting data. The program tests the ACE QoS APIs/features. The +test works for Winsock2 APIs on Win2K as well as RAPI on Solaris. + +In addition it dynamically changes the receiver flow spec which in +turn changes the RESV messages sent. + + +------------------------------------------------------------------------ +WIN2K : + +Build Requirements : +-------------------- +1. Two Win2K machines. +2. June98 Platform SDK or later. +3. Link with ws2_32.lib + +The test consists of a server (which is the receiver) and a client + (which is the sender). + + The receiver is started first (though it is not mandatory) as : + + server -m merengue.cs.wustl.edu:9091 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +The sample Sender is started next as : + + client -m merengue.cs.wustl.edu:9091 -P 10004 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -n: Option to be used by senders only to specify the destination + address. This option is overriden if a multicast address is also + specified through the -m option. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +On Win2K the user must have administrative access to the machine to +run this program. It seems to be a pre-requisite to opening QoS +sockets. + +The sender and receiver should be run on different Win2K machines. + +The test demonstrates how to GQOS enable an application using the ACE QoS APIs. +It concentrates on the use of various ACE QoS APIs and their correctness. + +------------------------------------------------------------------------------- + +RAPI : + +0. The $ACE_ROOT/include/makeinclude/platform_macros.GNU should be the +following : + +include /project/doc/vishal/ACE_wrappers/include/makeinclude/platform_sunos5_sunc++.GNU +PLATFORM_RAPI_CPPFLAGS += -I/project/doc/vishal/rapi/rel4.2a4/rsvpd/ +PLATFORM_RAPI_LIBS += -lrsvp +PLATFORM_RAPI_LDFLAGS += -L/project/doc/vishal/rapi/rel4.2a4/rsvpd/ + +assuming that RAPI library is installed in /project/doc/vishal/rapi/rel4.2a4/ + +1. Compile ACE with + + make rapi=1 static_libs_only=1 + + Static library option is used because the RAPI library that we have + does not compile as a shared object. + +2. Run the RSVP Daemon on two machines: (merengue.cs and macarena.cs) + + /project/doc/vishal/rapi/rel4.2a4/rsvpd/rsvpd -D + + The current version of the daemon comes with an inbuilt rtap + application to test the various reservation commands and RAPI APIs. + + Typical values for rtap would be : + + sender merengue/5000 [ t 2000000 100000 2000000 512 1024 ] + reserve wf [ cl 4000000 200000 4000000 256 2024 ] + + + + From ACE: + dest udp macarena/5000 + sender ace/5000 [ t 2000000 100000 2000000 512 1024 ] + sender macarena/5022 [ t 2000000 100000 2000000 512 1024 ] + sender beguine/6000 [ t 2000000 100000 2000000 512 1024 ] + + From Macarena: + wait until done with ACE + dest udp macarena/5000 <session name> + reserve wf [ cl 2000000 100000 2000000 512 1024 ] + + + +3. If RTAP runs fine and the daemons show the debug messages about + RESV, PATH and other RSVP messages, run the QoS example, making sure + that rtap session is released on both machines. + +------------------------------------------------------------------------------- + +If you run into any problems with this test please contact Vishal +Kachroo <vishal@cs.wustl.edu>. + +This README last updated on 20th July, 2000. + +------------------------------------------------------------------------------- diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/Receiver_QoS_Event_Handler.cpp b/ACE/examples/QOS/Change_Receiver_FlowSpec/Receiver_QoS_Event_Handler.cpp new file mode 100644 index 00000000000..33176ba4da3 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/Receiver_QoS_Event_Handler.cpp @@ -0,0 +1,216 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Receiver_QoS_Event_Handler.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#include "Receiver_QoS_Event_Handler.h" +#include "ace/Log_Msg.h" +#include "ace/SString.h" +#include "Fill_ACE_QoS.h" + +// Constructor. +Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (void) +{ +} + +Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session) + : dgram_mcast_qos_ (dgram_mcast_qos), + qos_session_ (qos_session) +{ +} + +// Destructor. +Receiver_QoS_Event_Handler::~Receiver_QoS_Event_Handler (void) +{ +} + +// Return the handle of the Dgram_Mcast. This method is called +// internally by the reactor. +ACE_HANDLE +Receiver_QoS_Event_Handler::get_handle (void) const +{ + return this->dgram_mcast_qos_.get_handle (); +} + +// Called when there is a READ activity on the dgram_mcast_qos handle. +int +Receiver_QoS_Event_Handler::handle_input (ACE_HANDLE) +{ + char buf[BUFSIZ]; + + iovec iov; + iov.iov_base = buf; + iov.iov_len = BUFSIZ; + + ACE_OS::memset (iov.iov_base, + 0, + BUFSIZ); + + ACE_DEBUG ((LM_DEBUG, + "Inside handle_input () of Receiver_QoS_Event_Handler ()\n")); + + // Receive message from multicast group. + ssize_t result = + this->dgram_mcast_qos_.recv (&iov, + 1, + this->remote_addr_); + + if (result != -1) + { + ACE_DEBUG ((LM_DEBUG, + "Message Received : %s", + iov.iov_base)); + return 0; + } + else + return -1; +} + +// Called when there is a QoS Event. +int +Receiver_QoS_Event_Handler::handle_qos (ACE_HANDLE fd) +{ + ACE_UNUSED_ARG (fd); + + ACE_DEBUG ((LM_DEBUG, + "\nReceived a QOS event. Inside handle_qos ()\n")); + + // We have received an RSVP event. The following update_qos () call + // calls rapi_dispatch () in case of RAPI and WSAIoctl (GET_QOS) in + // case of W2K. It then does the QoS parameter translation and updates + // the QoS session object with the latest QoS. This call replaces the + // direct call that was being made to WSAIoctl (GET_QOS) here for the + // Win2K example. + + if (this->qos_session_->update_qos () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in updating QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + " Updating QOS succeeds.\n")); + + // Now proactively query the QoS object for QoS. + ACE_QoS ace_get_qos = this->qos_session_->qos (); + + ACE_DEBUG ((LM_DEBUG, + "\nReceiving Flowspec :\t\t\tSending Flowspec :\n\n" + "\tToken Rate = %d\t\t\tToken Rate = %d\n" + "\tToken Bucket Size = %d\t\t\tToken Bucket Size = %d\n" + "\tPeak Bandwidth = %d\t\t\tPeak Bandwidth = %d\n" + "\tLatency = %d\t\t\t\tLatency = %d\n" + "\tDelay Variation = %d\t\t\tDelay Variation = %d\n" + "\tService Type = %d\t\t\tService Type = %d\n" + "\tMax SDU Size = %d\t\t\tMax SDU Size = %d\n" + "\tMinimum Policed Size = %d\t\tMinimum Policed Size = %d\n\n", + ace_get_qos.receiving_flowspec ()->token_rate (), + ace_get_qos.sending_flowspec ()->token_rate (), + ace_get_qos.receiving_flowspec ()->token_bucket_size (), + ace_get_qos.sending_flowspec ()->token_bucket_size (), + ace_get_qos.receiving_flowspec ()->peak_bandwidth (), + ace_get_qos.sending_flowspec ()->peak_bandwidth (), + ace_get_qos.receiving_flowspec ()->latency (), + ace_get_qos.sending_flowspec ()->latency (), + ace_get_qos.receiving_flowspec ()->delay_variation (), + ace_get_qos.sending_flowspec ()->delay_variation (), + ace_get_qos.receiving_flowspec ()->service_type (), + ace_get_qos.sending_flowspec ()->service_type (), + ace_get_qos.receiving_flowspec ()->max_sdu_size (), + ace_get_qos.sending_flowspec ()->max_sdu_size (), + ace_get_qos.receiving_flowspec ()->minimum_policed_size (), + ace_get_qos.sending_flowspec ()->minimum_policed_size ())); + + + // + // create a dynamic flow spec on each callback to test QoS retransmits + // + ACE_CString flow_id ("flow_id"); + + Fill_ACE_QoS flow_spec_list; + ACE_DEBUG ((LM_DEBUG, + "\nA new flow spec! in QoS handler.")); + + static int token_rate = 9400; + ++token_rate; + static int peak_bw = 18500; + ++peak_bw; + switch (flow_spec_list.map ().bind (flow_id, + new ACE_Flow_Spec (token_rate, + 708, + peak_bw, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + // + // set up the new qos + // + ACE_QoS another_qos_receiver; + if (flow_spec_list.fill_simplex_receiver_qos (another_qos_receiver, + flow_id) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill handler-simplex receiver qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Successfully built a new flowspec in handle_qos!\n")); + + // + // change the qos for the current session + // + ACE_QoS_Manager qos_manager = this->dgram_mcast_qos_.qos_manager (); + + ACE_DEBUG ((LM_DEBUG, + "QoS Manager was built in handle_qos!\n")); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (this->qos_session_->qos (&this->dgram_mcast_qos_, + &qos_manager, + another_qos_receiver) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + +return 0; + +} + + + + + + diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/Receiver_QoS_Event_Handler.h b/ACE/examples/QOS/Change_Receiver_FlowSpec/Receiver_QoS_Event_Handler.h new file mode 100644 index 00000000000..874d628e3c1 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/Receiver_QoS_Event_Handler.h @@ -0,0 +1,61 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Receiver_QoS_Event_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef RECEIVER_QOS_EVENT_HANDLER_H +#define RECEIVER_QOS_EVENT_HANDLER_H + +#include "ace/Reactor.h" +#include "ace/INET_Addr.h" +#include "ace/Event_Handler.h" +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +ACE_RCSID(Receiver_QoS_Event_Handler, Receiver_QoS_Event_Handler, "$Id$") + + class Receiver_QoS_Event_Handler : public ACE_Event_Handler + { + public: + // = Initialization and Termination methods. + Receiver_QoS_Event_Handler (void); + // Constructor. + + Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS &dgram_mcast_qos, + ACE_QoS_Session *qos_session); + // Constructor. + + ~Receiver_QoS_Event_Handler (void); + // Destructor. + + virtual ACE_HANDLE get_handle (void) const; + // Override this to return the handle of the Dgram_Mcast + // that we are using. + + virtual int handle_input (ACE_HANDLE fd); + // Handles a READ event. + + virtual int handle_qos (ACE_HANDLE fd); + // Handles a QoS event. + + private: + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos_; + ACE_QoS_Session *qos_session_; + ACE_INET_Addr remote_addr_; + }; + +#endif /* RECEIVER_QOS_EVENT_HANDLER_H */ + + + diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/Sender_QoS_Event_Handler.cpp b/ACE/examples/QOS/Change_Receiver_FlowSpec/Sender_QoS_Event_Handler.cpp new file mode 100644 index 00000000000..561746a3641 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/Sender_QoS_Event_Handler.cpp @@ -0,0 +1,146 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Sender_QoS_Event_Handler.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#include "Sender_QoS_Event_Handler.h" +#include "ace/Log_Msg.h" + +#include "Fill_ACE_QoS.h" + +// Constructor. +Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (void) +{ +} + +// Constructor. +Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session) + : dgram_mcast_qos_ (dgram_mcast_qos), + qos_session_ (qos_session) +{ +} + +// Destructor. +Sender_QoS_Event_Handler::~Sender_QoS_Event_Handler (void) +{ +} + +// Return the handle of the Dgram_Mcast. This method is called +// internally by the reactor. + +ACE_HANDLE +Sender_QoS_Event_Handler::get_handle (void) const +{ + return this->dgram_mcast_qos_.get_handle (); +} + +// Handle the QoS Event. In this case send data to the receiver +// using WSASendTo() that uses overlapped I/O. + +int +Sender_QoS_Event_Handler::handle_qos (ACE_HANDLE) +{ + ACE_DEBUG ((LM_DEBUG, + "\nReceived a QOS event. Inside handle_qos ()\n")); + + // We have received an RSVP event. The following update_qos () call + // calls rapi_dispatch () in case of RAPI and WSAIoctl (GET_QOS) in + // case of W2K. It then does the QoS parameter translation and updates + // the QoS session object with the latest QoS. This call replaces the + // direct call that was being made to WSAIoctl (GET_QOS) here for the + // Win2K example. + + if (this->qos_session_->update_qos () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in updating QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + " Updating QOS succeeds.\n")); + + // Now proactively query the QoS object for QoS. + ACE_QoS ace_get_qos = this->qos_session_->qos (); + + ACE_DEBUG ((LM_DEBUG, + "\nReceiving Flowspec :\t\t\tSending Flowspec :\n\n" + "\tToken Rate = %d\t\t\tToken Rate = %d\n" + "\tToken Bucket Size = %d\t\t\tToken Bucket Size = %d\n" + "\tPeak Bandwidth = %d\t\t\tPeak Bandwidth = %d\n" + "\tLatency = %d\t\t\t\tLatency = %d\n" + "\tDelay Variation = %d\t\t\tDelay Variation = %d\n" + "\tService Type = %d\t\t\tService Type = %d\n" + "\tMax SDU Size = %d\t\t\tMax SDU Size = %d\n" + "\tMinimum Policed Size = %d\t\tMinimum Policed Size = %d\n\n", + ace_get_qos.receiving_flowspec ()->token_rate (), + ace_get_qos.sending_flowspec ()->token_rate (), + ace_get_qos.receiving_flowspec ()->token_bucket_size (), + ace_get_qos.sending_flowspec ()->token_bucket_size (), + ace_get_qos.receiving_flowspec ()->peak_bandwidth (), + ace_get_qos.sending_flowspec ()->peak_bandwidth (), + ace_get_qos.receiving_flowspec ()->latency (), + ace_get_qos.sending_flowspec ()->latency (), + ace_get_qos.receiving_flowspec ()->delay_variation (), + ace_get_qos.sending_flowspec ()->delay_variation (), + ace_get_qos.receiving_flowspec ()->service_type (), + ace_get_qos.sending_flowspec ()->service_type (), + ace_get_qos.receiving_flowspec ()->max_sdu_size (), + ace_get_qos.sending_flowspec ()->max_sdu_size (), + ace_get_qos.receiving_flowspec ()->minimum_policed_size (), + ace_get_qos.sending_flowspec ()->minimum_policed_size ())); + + // This is SPECIFIC TO WIN2K and should be done in the qos_update function. + +// ACE_QoS ace_get_qos; +// u_long dwBytes; + +// if (ACE_OS::ioctl (this->dgram_mcast_qos_.get_handle (), +// ACE_SIO_GET_QOS, +// ace_get_qos, +// &dwBytes) == -1) +// ACE_ERROR ((LM_ERROR, +// "Error in Qos get ACE_OS::ioctl ()\n" +// "Bytes Returned = %d\n", +// dwBytes)); +// else +// ACE_DEBUG ((LM_DEBUG, +// "Getting QOS using ACE_OS::ioctl () succeeds.\n")); + + char* msg = "Hello sent on a QoS enabled session !!\n"; + iovec iov[1]; + iov[0].iov_base = msg; + iov[0].iov_len = ACE_OS::strlen(msg); + + size_t bytes_sent = 0; + + // Send "Hello" to the QoS session address to which the receiver has + // subscribed. + if (this->dgram_mcast_qos_.send (iov, + 1, + bytes_sent, + 0, + this->qos_session_->dest_addr (), + 0, + 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in dgram_mcast.send ()\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Using ACE_OS::sendto () : Bytes sent : %d", + bytes_sent)); + + return 0; +} diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/Sender_QoS_Event_Handler.h b/ACE/examples/QOS/Change_Receiver_FlowSpec/Sender_QoS_Event_Handler.h new file mode 100644 index 00000000000..b691bbd0615 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/Sender_QoS_Event_Handler.h @@ -0,0 +1,61 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Sender_QoS_Event_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef SENDER_QOS_EVENT_HANDLER_H +#define SENDER_QOS_EVENT_HANDLER_H + +#include "ace/Event_Handler.h" +#include "ace/Reactor.h" +#include "ace/INET_Addr.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" +#include "ace/QoS/QoS_Session.h" + +//#define MY_DEFPORT 5001 +//#define DEFAULT_MULTICASTGROUP "234.5.6.7" + +ACE_RCSID(Sender_QoS_Event_Handler, Sender_QoS_Event_Handler, "$Id$") + +class Sender_QoS_Event_Handler : public ACE_Event_Handler +{ +public: + // = Initialization and Termination methods. + Sender_QoS_Event_Handler (void); + // Constructor. + + Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session + ); + // Constructor. + + ~Sender_QoS_Event_Handler (void); + // Destructor. + + virtual ACE_HANDLE get_handle (void) const; + // Override this to return the handle of the Dgram_Mcast + // that we are using. + + virtual int handle_qos (ACE_HANDLE fd); + // Handles a QoS event. Right now, just + // prints a message. + +private: + + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos_; + ACE_QoS_Session *qos_session_; +}; + +#endif /* SENDER_QOS_EVENT_HANDLER_H */ diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/receiver.cpp b/ACE/examples/QOS/Change_Receiver_FlowSpec/receiver.cpp new file mode 100644 index 00000000000..8ef43514e9b --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/receiver.cpp @@ -0,0 +1,300 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// server.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#define QOSEVENT_MAIN + +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/QoS_Session_Factory.h" +#include "ace/QoS/QoS_Decorator.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +#include "QoS_Util.h" +#include "Fill_ACE_QoS.h" +#include "QoS_Signal_Handler.h" +#include "Receiver_QoS_Event_Handler.h" + +// To open QOS sockets administrative access is required on the +// machine. Fill in default values for QoS structure. The default +// values were simply choosen from existing QOS templates available +// via WSAGetQosByName. Notice that ProviderSpecific settings are +// being allowed when picking the "default" template but not for +// "well-known" QOS templates. Also notice that since data is only +// flowing from sender to receiver, different flowspecs are filled in +// depending upon whether this application is acting as a sender or +// receiver. + + +// This function fills up the ACE_QoS_Params with the supplied iovec +// and ACE_QoS. + +int +FillQoSParams (ACE_QoS_Params &qos_params, + iovec* iov, + ACE_QoS* qos) +{ + qos_params.callee_data (iov); + qos_params.caller_data (0); + qos_params.socket_qos (qos); + qos_params.group_socket_qos (0); + qos_params.flags (ACE_JL_BOTH); + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + + QoS_Util qos_util(argc, argv); + + if (qos_util.parse_args () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in parsing args\n"), + -1); + + // This is a multicast application. + if (qos_util.multicast_flag ()) + { + Fill_ACE_QoS fill_ace_qos; + + // The application adds the flow specs that it wants into the + // Fill_ACE_QoS. The Fill_ACE_QoS indexes the flow specs by the + // flow spec names. Here the new flowspec being added is g_711. + ACE_CString g_711 ("g_711"); + + switch (fill_ace_qos.map ().bind (g_711, + new ACE_Flow_Spec (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + ACE_DEBUG ((LM_DEBUG, + "g_711 Flow Spec bound successfully\n")); + + // This is a receiver. So we fill in the receiving QoS parameters. + ACE_QoS ace_qos_receiver; + if (fill_ace_qos.fill_simplex_receiver_qos (ace_qos_receiver, + g_711) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill simplex receiver qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Filled up the Receiver QoS parameters\n")); + + // Opening a new Multicast Datagram. + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos; + + // Multicast Session Address specified by user at command line. + // If this address is not specified, + // <localhost:ACE_DEFAULT_MULTICAST_PORT> is assumed. + ACE_INET_Addr mult_addr (*(qos_util.mult_session_addr ())); + + // Fill the ACE_QoS_Params to be passed to the <ACE_OS::join_leaf> + // through subscribe. + + ACE_QoS_Params qos_params; + FillQoSParams (qos_params, 0, &ace_qos_receiver); + + // Create a QoS Session Factory. + ACE_QoS_Session_Factory session_factory; + + // Ask the factory to create a QoS session. + ACE_QoS_Session *qos_session = + session_factory.create_session (); + + // Create a destination address for the QoS session. The same + // address should be used for the subscribe call later. A copy + // is made below only to distinguish the two usages of the dest + // address. + + ACE_INET_Addr dest_addr (mult_addr); + + // A QoS session is defined by the 3-tuple [DestAddr, DestPort, + // Protocol]. Initialize the QoS session. + if (qos_session->open (mult_addr, + IPPROTO_UDP) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in opening the QoS session\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS session opened successfully\n")); + + // The following call opens the Dgram_Mcast and calls the + // <ACE_OS::join_leaf> with the qos_params supplied here. Note + // the QoS session object is passed into this call. This + // subscribes the underlying socket to the passed in QoS + // session. For joining multiple multicast sessions, the + // following subscribe call should be made with different + // multicast addresses and a new QoS session object should be + // passed in for each such call. The QoS session objects can be + // created only through the session factory. Care should be + // taken that the mult_addr for the subscribe() call matches the + // dest_addr of the QoS session object. If this is not done, the + // subscribe call will fail. A more abstract version of + // subscribe will be added that constrains the various features + // of GQoS like different flags etc. + + if (dgram_mcast_qos.subscribe (mult_addr, + qos_params, + 1, + 0, + AF_INET, + // ACE_FROM_PROTOCOL_INFO, + 0, + 0, // ACE_Protocol_Info, + 0, + ACE_OVERLAPPED_SOCKET_FLAG + | ACE_FLAG_MULTIPOINT_C_LEAF + | ACE_FLAG_MULTIPOINT_D_LEAF, + qos_session) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in subscribe\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Dgram_Mcast subscribe succeeds \n")); + + int nIP_TTL = 25; + char achInBuf [BUFSIZ]; + u_long dwBytes; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTICAST_SCOPE, // IO control code. + &nIP_TTL, // In buffer. + sizeof (nIP_TTL), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Multicast scope ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Setting TTL with Multicast scope ACE_OS::ioctl call succeeds \n")); + + int bFlag = 0; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTIPOINT_LOOPBACK, // IO control code. + &bFlag, // In buffer. + sizeof (bFlag), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Loopback ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Disable Loopback with ACE_OS::ioctl call succeeds \n")); + + // This is a receiver. + qos_session->flags (ACE_QoS_Session::ACE_QOS_RECEIVER); + + ACE_QoS_Manager qos_manager = dgram_mcast_qos.qos_manager (); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (qos_session->qos (&dgram_mcast_qos, + &qos_manager, + ace_qos_receiver) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + + // Register a signal handler that helps to gracefully close the + // open QoS sessions. + QoS_Signal_Handler qos_signal_handler (qos_session); + + // Register the usual SIGINT signal handler with the Reactor for + // the application to gracefully release the QoS session and + // shutdown. + if (ACE_Reactor::instance ()->register_handler + (SIGINT, &qos_signal_handler) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Signal Handler.\n"), + -1); + + // Handler to process QoS and Data events for the reciever. + Receiver_QoS_Event_Handler qos_event_handler (dgram_mcast_qos, + qos_session); + + // Decorate the above handler with QoS functionality. + ACE_QoS_Decorator qos_decorator (&qos_event_handler, + qos_session); + + // Initialize the Decorator. + if (qos_decorator.init () != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "QoS Decorator init () failed.\n"), + -1); + + // Register the decorated Event Handler with the Reactor. + if (ACE_Reactor::instance ()->register_handler (&qos_decorator, + ACE_Event_Handler::QOS_MASK | + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Decorator with the Reactor\n"), + -1); + + + // Start the event loop. + ACE_DEBUG ((LM_DEBUG, + "Running the Event Loop ... \n")); + + ACE_Reactor::instance ()->run_event_loop (); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) shutting down server logging daemon\n")); + } + else + ACE_DEBUG ((LM_DEBUG, + "Specify a -m option for multicast application\n")); + return 0; +} + + + diff --git a/ACE/examples/QOS/Change_Receiver_FlowSpec/sender.cpp b/ACE/examples/QOS/Change_Receiver_FlowSpec/sender.cpp new file mode 100644 index 00000000000..c721aa810c4 --- /dev/null +++ b/ACE/examples/QOS/Change_Receiver_FlowSpec/sender.cpp @@ -0,0 +1,316 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// client.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + + +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/QoS_Session_Factory.h" +#include "ace/QoS/QoS_Session_Impl.h" +#include "ace/QoS/QoS_Decorator.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +#include "QoS_Util.h" +#include "Fill_ACE_QoS.h" +#include "QoS_Signal_Handler.h" +#include "Sender_QoS_Event_Handler.h" + +// To open QOS sockets administrative access is required on the +// machine. Fill in default values for QoS structure. The default +// values were simply choosen from existing QOS templates available +// via WSAGetQosByName. Notice that ProviderSpecific settings are +// being allowed when picking the "default" template but not for +// "well-known" QOS templates. Also notice that since data is only +// flowing from sender to receiver, different flowspecs are filled in +// depending upon whether this application is acting as a sender or +// receiver. + +// This function fills up the ACE_QoS_Params with the supplied iovec and ACE_QoS. + +int +FillQoSParams (ACE_QoS_Params &qos_params, + iovec* iov, + ACE_QoS* qos) +{ + qos_params.callee_data (iov); + qos_params.caller_data (0); + qos_params.socket_qos (qos); + qos_params.group_socket_qos (0); + qos_params.flags (ACE_JL_BOTH); + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + + ACE_DEBUG ((LM_DEBUG, + "Sender\n")); + + QoS_Util qos_util(argc, argv); + + if (qos_util.parse_args () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in parsing args\n"), + -1); + + // This is a multicast application. + if (qos_util.multicast_flag ()) + { + Fill_ACE_QoS fill_ace_qos; + + // The application adds the flow specs that it wants into the + // Fill_ACE_QoS. The Fill_ACE_QoS indexes the flow specs by the flow + // spec names. Here the new flowspec being added is g_711. + ACE_CString g_711 ("g_711"); + + switch (fill_ace_qos.map ().bind (g_711, + new ACE_Flow_Spec (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + ACE_DEBUG ((LM_DEBUG, + "g_711 Flow Spec bound successfully\n")); + + // This is a sender. So we fill in the sending QoS parameters. + ACE_QoS ace_qos_sender; + + if (fill_ace_qos.fill_simplex_sender_qos (ace_qos_sender, + g_711) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill simplex sender qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Filled up the Sender QoS parameters\n")); + + // Opening a new Multicast Datagram. It is absolutely necessary that + // the sender and the receiver subscribe to the same multicast + // addresses to make sure the "multicast sessions" for the two are + // the same. This is used to match the RESV<->PATH states. + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos; + + // Multicast Session Address specified by user at command line. + // If this address is not specified, + // <localhost:ACE_DEFAULT_MULTICAST_PORT> is assumed. + ACE_INET_Addr mult_addr (*(qos_util.mult_session_addr ())); + + // Fill the ACE_QoS_Params to be passed to the <ACE_OS::join_leaf> + // through subscribe. + + ACE_QoS_Params qos_params; + FillQoSParams (qos_params, 0, &ace_qos_sender); + + // Create a QoS Session Factory. + ACE_QoS_Session_Factory session_factory; + + // Ask the factory to create a QoS session. + ACE_QoS_Session *qos_session = + session_factory.create_session (); + + // Create a destination address for the QoS session. The same + // address should be used for the subscribe call later. A copy is + // made below only to distinguish the two usages of the dest + // address. + + ACE_INET_Addr dest_addr (mult_addr); + + // A QoS session is defined by the 3-tuple [DestAddr, DestPort, + // Protocol]. Initialize the QoS session. + if (qos_session->open (mult_addr, + IPPROTO_UDP) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in opening the QoS session\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS session opened successfully\n")); + + // The following call opens the Dgram_Mcast and calls the + // <ACE_OS::join_leaf> with the qos_params supplied here. Note the + // QoS session object is passed into this call. This subscribes the + // underlying socket to the passed in QoS session. For joining + // multiple multicast sessions, the following subscribe call should + // be made with different multicast addresses and a new QoS session + // object should be passed in for each such call. The QoS session + // objects can be created only through the session factory. Care + // should be taken that the mult_addr for the subscribe() call + // matches the dest_addr of the QoS session object. If this is not + // done, the subscribe call will fail. A more abstract version of + // subscribe will be added that constrains the various features of + // GQoS like different flags etc. + + if (dgram_mcast_qos.subscribe (mult_addr, + qos_params, + 1, + 0, + AF_INET, + // ACE_FROM_PROTOCOL_INFO, + 0, + 0, // ACE_Protocol_Info, + 0, + ACE_OVERLAPPED_SOCKET_FLAG + | ACE_FLAG_MULTIPOINT_C_LEAF + | ACE_FLAG_MULTIPOINT_D_LEAF, + qos_session) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in subscribe\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Dgram_Mcast subscribe succeeds \n")); + + int nIP_TTL = 25; + char achInBuf [BUFSIZ]; + u_long dwBytes; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTICAST_SCOPE, // IO control code. + &nIP_TTL, // In buffer. + sizeof (nIP_TTL), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Multicast scope ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Setting TTL with Multicast scope ACE_OS::ioctl call succeeds \n")); + + int bFlag = 0; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTIPOINT_LOOPBACK, // IO control code. + &bFlag, // In buffer. + sizeof (bFlag), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Loopback ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Disable Loopback with ACE_OS::ioctl call succeeds \n")); + + // This is a sender. + qos_session->flags (ACE_QoS_Session::ACE_QOS_SENDER); + + ACE_QoS_Manager qos_manager = dgram_mcast_qos.qos_manager (); + + // Since we are using RSVP, it is imperative that the client + // application have the option of supplying the source sender + // port for the RSVP messages. A default will be chosen by the + // ACE API if this is not done. + qos_session->source_port (qos_util.source_port ()); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (qos_session->qos (&dgram_mcast_qos, + &qos_manager, + ace_qos_sender) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + + // Register a signal handler that helps to gracefully close the open + // QoS sessions. + QoS_Signal_Handler qos_signal_handler (qos_session); + + // Register the usual SIGINT signal handler with the Reactor for + // the application to gracefully release the QoS session and + // shutdown. + if (ACE_Reactor::instance ()->register_handler + (SIGINT, &qos_signal_handler) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Signal Handler.\n"), + -1); + + // Handler to process QoS and Data events for the reciever. + Sender_QoS_Event_Handler qos_event_handler (dgram_mcast_qos, + qos_session); + + // Decorate the above handler with QoS functionality. + ACE_QoS_Decorator qos_decorator (&qos_event_handler, + qos_session); + + // Initialize the Decorator. + if (qos_decorator.init () != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "QoS Decorator init () failed.\n"), + -1); + + // Register the decorated Event Handler with the Reactor. + if (ACE_Reactor::instance ()->register_handler (&qos_decorator, + ACE_Event_Handler::QOS_MASK | + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Decorator with the Reactor\n"), + -1); + + + + + // Start the event loop. + ACE_DEBUG ((LM_DEBUG, + "Running the Event Loop ... \n")); + + ACE_Reactor::instance ()->run_event_loop (); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) shutting down server logging daemon\n")); + } + else + ACE_DEBUG ((LM_DEBUG, + "Specify a -m option for multicast application\n")); + return 0; +} + + + + + + + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/Fill_ACE_QoS.cpp b/ACE/examples/QOS/Change_Sender_TSpec/Fill_ACE_QoS.cpp new file mode 100644 index 00000000000..20c03f40fa6 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/Fill_ACE_QoS.cpp @@ -0,0 +1,99 @@ +// Fill_ACE_QoS.cpp +// $Id$ + +#include "Fill_ACE_QoS.h" + +ACE_RCSID(QOS, Fill_ACE_QoS,"$Id$") + +const iovec Fill_ACE_QoS::iov_ = {0,0}; + +Fill_ACE_QoS::Fill_ACE_QoS (void) +{ + ACE_NEW (this->default_traffic_, + ACE_Flow_Spec (ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_SERVICETYPE_NOTRAFFIC, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + 25, + 1)); +} + +// destructor. +Fill_ACE_QoS::~Fill_ACE_QoS (void) +{} + +int +Fill_ACE_QoS::fill_simplex_receiver_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name) +{ + ACE_Flow_Spec *recv_flow_spec = 0; + + if (this->map ().find (recv_flow_name, recv_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + recv_flow_name.c_str ()), + -1); + ace_qos.receiving_flowspec (recv_flow_spec); + ace_qos.sending_flowspec ((this->default_traffic_)); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + + +int +Fill_ACE_QoS::fill_simplex_sender_qos (ACE_QoS &ace_qos, + const ACE_CString &send_flow_name) +{ + ACE_Flow_Spec *send_flow_spec = 0; + + if (this->map ().find (send_flow_name, send_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + send_flow_name.c_str ()), + -1); + + ace_qos.receiving_flowspec ((this->default_traffic_)); + ace_qos.sending_flowspec (send_flow_spec); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + +int +Fill_ACE_QoS::fill_duplex_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name, + const ACE_CString &send_flow_name) +{ + ACE_Flow_Spec *send_flow_spec = 0; + ACE_Flow_Spec *recv_flow_spec = 0; + + if (this->map ().find (recv_flow_name, recv_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + recv_flow_name.c_str ()), + -1); + + if (this->map ().find (send_flow_name, send_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + send_flow_name.c_str ()), + -1); + + ace_qos.receiving_flowspec (recv_flow_spec); + ace_qos.sending_flowspec (send_flow_spec); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + +Fill_ACE_QoS::FLOW_SPEC_HASH_MAP& +Fill_ACE_QoS::map (void) +{ + return this->flow_spec_map_; +} + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/Fill_ACE_QoS.h b/ACE/examples/QOS/Change_Sender_TSpec/Fill_ACE_QoS.h new file mode 100644 index 00000000000..776d713e5e5 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/Fill_ACE_QoS.h @@ -0,0 +1,75 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Fill_ACE_QoS.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef FILL_ACE_QOS_H +#define FILL_ACE_QOS_H + +#include "ace/SString.h" +#include "ace/Hash_Map_Manager.h" +#include "ace/Null_Mutex.h" +#include "ace/ACE.h" +#include "ace/OS_QoS.h" + +class Fill_ACE_QoS +{ + // TITLE + // This class helps users to add new flow specs and provides + // utility functions for filling up the flow specs for simplex/duplex + // sessions. + +public: + typedef ACE_Hash_Map_Manager <ACE_CString, ACE_Flow_Spec *, ACE_Null_Mutex> FLOW_SPEC_HASH_MAP; + + //Initialization and termination methods. + Fill_ACE_QoS (void); + // constructor. + + ~Fill_ACE_QoS (void); + // destructor. + + int fill_simplex_receiver_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name); + // To be used by receivers. Fills the receiver qos and sets the + // sender qos to NO_TRAFFIC. + + int fill_simplex_sender_qos (ACE_QoS &ace_qos, + const ACE_CString &send_flow_name); + // To be used by senders. Fills the sender qos and sets the receiver + // qos to NO_TRAFFIC. + + int fill_duplex_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name, + const ACE_CString &send_flow_name); + // To be used by applications that wish to be both receivers and + // senders. + + FLOW_SPEC_HASH_MAP& map (void); + // Returns the hash map of flowspecs indexed by flowspec name. + +private: + + // The Service Provider is currently set to NULL for all ACE_QoS. + static const iovec iov_; + + // A NO_TRAFFIC flow spec. Senders set the receiving qos to this + // while the receivers set the sending qos to this. + ACE_Flow_Spec *default_traffic_; + + // A list of flowspecs indexed by the flowspec name. + FLOW_SPEC_HASH_MAP flow_spec_map_; +}; + +#endif /* FILL_ACE_QOS_H */ diff --git a/ACE/examples/QOS/Change_Sender_TSpec/FlowSpec_Dbase.h b/ACE/examples/QOS/Change_Sender_TSpec/FlowSpec_Dbase.h new file mode 100644 index 00000000000..fc382048c13 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/FlowSpec_Dbase.h @@ -0,0 +1,52 @@ +/* -*- C++ -*- */ +//$Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// FlowSpec_Dbase.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef FLOWSPEC_DBASE_H +#define FLOWSPEC_DBASE_H + +// This file contains the different FlowSpecs that the QoS enabled +// application uses. Its a good idea to list them all here so the +// application code is clean. + +ACE_Flow_Spec notraffic (ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_SERVICETYPE_NOTRAFFIC, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + 25, + 1); + +ACE_Flow_Spec g711 (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1); + +// The default session address is macarena.cs.wustl.edu. I am using macarena +// as my receiver for testing. +#define DEFAULT_QOS_SESSION_MACHINE "128.252.165.127" +#define DEFAULT_QOS_SESSION_PORT 8001 + +#endif /* FLOWSPEC_DBASE_H */ + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/Makefile.am b/ACE/examples/QOS/Change_Sender_TSpec/Makefile.am new file mode 100644 index 00000000000..980d5cf3422 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/Makefile.am @@ -0,0 +1,76 @@ +## 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: +## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + +noinst_PROGRAMS = + +## Makefile.QOS_Change_Sender_TSpec_Receiver.am + +if BUILD_QOS +noinst_PROGRAMS += receiver + +receiver_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +receiver_SOURCES = \ + Fill_ACE_QoS.cpp \ + QoS_Signal_Handler.cpp \ + QoS_Util.cpp \ + Receiver_QoS_Event_Handler.cpp \ + receiver.cpp \ + Fill_ACE_QoS.h \ + QoS_Signal_Handler.h \ + QoS_Util.h \ + Receiver_QoS_Event_Handler.h + +receiver_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_QOS + +## Makefile.QOS_Change_Sender_TSpec_Sender.am + +if BUILD_QOS +noinst_PROGRAMS += sender + +sender_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +sender_SOURCES = \ + Fill_ACE_QoS.cpp \ + QoS_Signal_Handler.cpp \ + QoS_Util.cpp \ + Sender_QoS_Event_Handler.cpp \ + sender.cpp \ + Fill_ACE_QoS.h \ + QoS_Signal_Handler.h \ + QoS_Util.h \ + Sender_QoS_Event_Handler.h + +sender_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_QOS + +## 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/examples/QOS/Change_Sender_TSpec/QOS_Change_Sender_TSpec.mpc b/ACE/examples/QOS/Change_Sender_TSpec/QOS_Change_Sender_TSpec.mpc new file mode 100644 index 00000000000..9767bd6fdb9 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/QOS_Change_Sender_TSpec.mpc @@ -0,0 +1,25 @@ +// -*- MPC -*- +// $Id$ + +project(*receiver) : aceexe, qos { + exename = receiver + requires += qos + Source_Files { + Fill_ACE_QoS.cpp + QoS_Signal_Handler.cpp + QoS_Util.cpp + receiver.cpp + Receiver_QoS_Event_Handler.cpp + } +} +project(*sender) : aceexe, qos { + exename = sender + requires += qos + Source_Files { + Fill_ACE_QoS.cpp + QoS_Signal_Handler.cpp + QoS_Util.cpp + sender.cpp + Sender_QoS_Event_Handler.cpp + } +} diff --git a/ACE/examples/QOS/Change_Sender_TSpec/QoS_Signal_Handler.cpp b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Signal_Handler.cpp new file mode 100644 index 00000000000..9f07ad5b378 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Signal_Handler.cpp @@ -0,0 +1,34 @@ +// QoS_Signal_Handler.cpp +// $Id$ + +#include "ace/Log_Msg.h" +#include "QoS_Signal_Handler.h" + +ACE_RCSID(QOS, QoS_Signal_Handler,"$Id$") + +// constructor. +QoS_Signal_Handler::QoS_Signal_Handler (ACE_QoS_Session *qos_session) + : qos_session_ (qos_session) +{ +} + +// Releases the QoS sessions gracefully. +int +QoS_Signal_Handler::handle_signal (int signum, siginfo_t *, ucontext_t*) +{ + if (signum == SIGINT) + { + if (this->qos_session_->close () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to close the QoS session.\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS Session with id %d closed successfully.\n", + this->qos_session_->session_id ())); + } + else + ACE_DEBUG ((LM_DEBUG, + "A signal other than SIGINT received.\nIgnoring.\n")); + return 0; +} diff --git a/ACE/examples/QOS/Change_Sender_TSpec/QoS_Signal_Handler.h b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Signal_Handler.h new file mode 100644 index 00000000000..35b9f3a19e7 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Signal_Handler.h @@ -0,0 +1,45 @@ +/* -*- C++ -*- */ +// $Id$ + +// ===================================================================== +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// QoS_Signal_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ===================================================================== + +#ifndef QOS_SIGNAL_HANDLER_H +#define QOS_SIGNAL_HANDLER_H + +#include "ace/Event_Handler.h" +#include "ace/QoS/QoS_Session.h" + +class QoS_Signal_Handler : public ACE_Event_Handler +{ + // TITLE + // This class Handles the SIGINT signal through the Reactor. + // Useful to gracefully release QoS sessions. + +public: + + QoS_Signal_Handler (ACE_QoS_Session *qos_session); + // constructor. + + int handle_signal(int signum, siginfo_t*,ucontext_t*); + // Override this method to implement graceful shutdown. + +private: + + ACE_QoS_Session *qos_session_; + // Session to be gracefully shutdown. + +}; + +#endif /* QOS_SIGNAL_HANDLER_H */ + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/QoS_Util.cpp b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Util.cpp new file mode 100644 index 00000000000..0ef3b353248 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Util.cpp @@ -0,0 +1,122 @@ +// QoS_Session_Impl.cpp +// $Id$ + +#define SENDER_PORT 10001 + +#include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" +#include "QoS_Util.h" +#include "ace/OS_NS_strings.h" + +ACE_RCSID(QOS, QoS_Util,"$Id$") + +// constructor. +QoS_Util::QoS_Util (int argc, + ACE_TCHAR *argv[]) + : argc_ (argc), + argv_ (argv), + source_port_ (SENDER_PORT), + protocol_ (IPPROTO_UDP), + multicast_flag_ (0) +{ + ACE_NEW (this->mult_session_addr_, + ACE_INET_Addr (ACE_DEFAULT_MULTICAST_PORT)); + + ACE_NEW (this->dest_addr_, + ACE_INET_Addr (ACE_DEFAULT_SERVER_PORT)); +} + +// destructor. +QoS_Util::~QoS_Util (void) +{ + delete this->mult_session_addr_; + delete this->dest_addr_; +} + +int +QoS_Util::parse_args (void) +{ + ACE_Get_Opt get_opts (this->argc_, this->argv_, ACE_TEXT("m:n:p:P:c")); + int c = 0; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'm': // multicast session address. + this->multicast_flag_ = 1; + this->mult_session_addr_->set (get_opts.opt_arg ()); + break; + case 'n': // to be used by Senders only to specify the destination. + this->dest_addr_->set (get_opts.opt_arg ()); + break; + case 'p': // protocol. + if (ACE_OS::strcasecmp (get_opts.opt_arg (), ACE_TEXT("tcp")) == 0) + this->protocol_ = IPPROTO_TCP; + else + if (ACE_OS::strcasecmp (get_opts.opt_arg (), ACE_TEXT("udp")) == 0) + this->protocol_ = IPPROTO_UDP; + else + ACE_DEBUG ((LM_DEBUG, + "Unknown protocol specified\n" + "UDP assumed\n")); + break; + case 'P': // sender source port. + this->source_port_ = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case 'h': // display help for different options. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-m host:port] QoS multicast session address" + " Overides the receiver address specified in the -n option" + " [-n host:port] Use for a unicast sender. " + " Follow by receiver addr" + " [-p tcp|udp] specify protocol to be used" + " [-P port] source sender port" + " [-h] <help>" + "\n", + argv_ [0]), + -1); + } + + // If multicast address is specified then ignore the unicast sender + // destination address and force the protocol to be UDP. + if (this->multicast_flag_ == 1) + { + this->dest_addr_ = this->mult_session_addr_; + this->protocol_ = IPPROTO_UDP; + } + + // Indicates successful parsing of command line. + return 0; +} + +ACE_INET_Addr * +QoS_Util::mult_session_addr (void) const +{ + return this->mult_session_addr_; +} + +ACE_INET_Addr * +QoS_Util::dest_addr (void) const +{ + return this->dest_addr_; +} + +u_short +QoS_Util::source_port (void) const +{ + return this->source_port_; +} + +ACE_Protocol_ID +QoS_Util::protocol (void) const +{ + return this->protocol_; +} + +int +QoS_Util::multicast_flag (void) const +{ + return this->multicast_flag_; +} diff --git a/ACE/examples/QOS/Change_Sender_TSpec/QoS_Util.h b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Util.h new file mode 100644 index 00000000000..ae347de68f6 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/QoS_Util.h @@ -0,0 +1,75 @@ +/* -*- C++ -*- */ +// $Id$ + +// ===================================================================== +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// QoS_Util.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ===================================================================== + +#ifndef QOS_UTIL_H +#define QOS_UTIL_H + +#include "ace/INET_Addr.h" +#include "ace/QoS/QoS_Session.h" + +class QoS_Util +{ + // = TITLE + // This class provides the utility functions like parse_args () + // required by a QoS enabled application. + +public: + + // constructor. + QoS_Util (int argc, ACE_TCHAR *argv[]); + + // destructor. + ~QoS_Util (void); + + // Parse command-line arguments. + int parse_args (void); + + // GET methods. + ACE_INET_Addr *mult_session_addr (void) const; + + ACE_INET_Addr *dest_addr (void) const; + + u_short source_port (void) const; + + ACE_Protocol_ID protocol (void) const; + + int multicast_flag (void) const; + +private: + + // Command line arguments. + int argc_; + ACE_TCHAR **argv_; + + // Multicast session address. + ACE_INET_Addr *mult_session_addr_; + + // Unicast destination address of the receiver. + ACE_INET_Addr *dest_addr_; + + // Source port for the sender. + u_short source_port_; + + // Protocol. + ACE_Protocol_ID protocol_; + + // Multicast Flag. + int multicast_flag_; + +}; + +#endif /* QOS_UTIL_H */ + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/README b/ACE/examples/QOS/Change_Sender_TSpec/README new file mode 100644 index 00000000000..a8423774320 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/README @@ -0,0 +1,126 @@ +$Id$ + +A Regression test for ACE QoS features. +--------------------------------------- + +This test implements a simple Receiver-Sender program that ensures +Quality of Service (QoS) guarantees on the underlying network before +transmitting data. The program tests the ACE QoS APIs/features. The +test works for Winsock2 APIs on Win2K as well as RAPI on Solaris. + +In addition it dynamically changes the sender TSpec which in turn +changes the PATH messages. + +------------------------------------------------------------------------ +WIN2K : + +Build Requirements : +-------------------- +1. Two Win2K machines. +2. June98 Platform SDK or later. +3. Link with ws2_32.lib + +The test consists of a server (which is the receiver) and a client + (which is the sender). + + The receiver is started first (though it is not mandatory) as : + + server -m merengue.cs.wustl.edu:9091 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +The sample Sender is started next as : + + client -m merengue.cs.wustl.edu:9091 -P 10004 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -n: Option to be used by senders only to specify the destination + address. This option is overriden if a multicast address is also + specified through the -m option. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +On Win2K the user must have administrative access to the machine to +run this program. It seems to be a pre-requisite to opening QoS +sockets. + +The sender and receiver should be run on different Win2K machines. + +The test demonstrates how to GQOS enable an application using the ACE QoS APIs. +It concentrates on the use of various ACE QoS APIs and their correctness. + +------------------------------------------------------------------------------- + +RAPI : + +0. The $ACE_ROOT/include/makeinclude/platform_macros.GNU should be the +following : + +include /project/doc/vishal/ACE_wrappers/include/makeinclude/platform_sunos5_sunc++.GNU +PLATFORM_RAPI_CPPFLAGS += -I/project/doc/vishal/rapi/rel4.2a4/rsvpd/ +PLATFORM_RAPI_LIBS += -lrsvp +PLATFORM_RAPI_LDFLAGS += -L/project/doc/vishal/rapi/rel4.2a4/rsvpd/ + +assuming that RAPI library is installed in /project/doc/vishal/rapi/rel4.2a4/ + +1. Compile ACE with + + make rapi=1 static_libs_only=1 + + Static library option is used because the RAPI library that we have + does not compile as a shared object. + +2. Run the RSVP Daemon on two machines: (merengue.cs and macarena.cs) + + /project/doc/vishal/rapi/rel4.2a4/rsvpd/rsvpd -D + + The current version of the daemon comes with an inbuilt rtap + application to test the various reservation commands and RAPI APIs. + + Typical values for rtap would be : + + sender merengue/5000 [ t 2000000 100000 2000000 512 1024 ] + reserve wf [ cl 4000000 200000 4000000 256 2024 ] + + + + From ACE: + dest udp macarena/5000 + sender ace/5000 [ t 2000000 100000 2000000 512 1024 ] + sender macarena/5022 [ t 2000000 100000 2000000 512 1024 ] + sender beguine/6000 [ t 2000000 100000 2000000 512 1024 ] + + From Macarena: + wait until done with ACE + dest udp macarena/5000 <session name> + reserve wf [ cl 2000000 100000 2000000 512 1024 ] + + + +3. If RTAP runs fine and the daemons show the debug messages about + RESV, PATH and other RSVP messages, run the QoS example, making sure + that rtap session is released on both machines. + +------------------------------------------------------------------------------- + +If you run into any problems with this test please contact Vishal +Kachroo <vishal@cs.wustl.edu>. + +This README last updated on 20th July, 2000. + +------------------------------------------------------------------------------- diff --git a/ACE/examples/QOS/Change_Sender_TSpec/Receiver_QoS_Event_Handler.cpp b/ACE/examples/QOS/Change_Sender_TSpec/Receiver_QoS_Event_Handler.cpp new file mode 100644 index 00000000000..d6ece4d563c --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/Receiver_QoS_Event_Handler.cpp @@ -0,0 +1,145 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Receiver_QoS_Event_Handler.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#include "Receiver_QoS_Event_Handler.h" +#include "ace/Log_Msg.h" +#include "ace/SString.h" +#include "Fill_ACE_QoS.h" + +// Constructor. +Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (void) +{ +} + +Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session) + : dgram_mcast_qos_ (dgram_mcast_qos), + qos_session_ (qos_session) +{ +} + +// Destructor. +Receiver_QoS_Event_Handler::~Receiver_QoS_Event_Handler (void) +{ +} + +// Return the handle of the Dgram_Mcast. This method is called +// internally by the reactor. +ACE_HANDLE +Receiver_QoS_Event_Handler::get_handle (void) const +{ + return this->dgram_mcast_qos_.get_handle (); +} + +// Called when there is a READ activity on the dgram_mcast_qos handle. +int +Receiver_QoS_Event_Handler::handle_input (ACE_HANDLE) +{ + char buf[BUFSIZ]; + + iovec iov; + iov.iov_base = buf; + iov.iov_len = BUFSIZ; + + ACE_OS::memset (iov.iov_base, + 0, + BUFSIZ); + + ACE_DEBUG ((LM_DEBUG, + "Inside handle_input () of Receiver_QoS_Event_Handler ()\n")); + + // Receive message from multicast group. + ssize_t result = + this->dgram_mcast_qos_.recv (&iov, + 1, + this->remote_addr_); + + if (result != -1) + { + ACE_DEBUG ((LM_DEBUG, + "Message Received : %s", + iov.iov_base)); + return 0; + } + else + return -1; +} + +// Called when there is a QoS Event. +int +Receiver_QoS_Event_Handler::handle_qos (ACE_HANDLE fd) +{ + ACE_UNUSED_ARG (fd); + + ACE_DEBUG ((LM_DEBUG, + "\nReceived a QOS event. Inside handle_qos ()\n")); + + // We have received an RSVP event. The following update_qos () call + // calls rapi_dispatch () in case of RAPI and WSAIoctl (GET_QOS) in + // case of W2K. It then does the QoS parameter translation and updates + // the QoS session object with the latest QoS. This call replaces the + // direct call that was being made to WSAIoctl (GET_QOS) here for the + // Win2K example. + + if (this->qos_session_->update_qos () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in updating QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + " Updating QOS succeeds.\n")); + + // Now proactively query the QoS object for QoS. + ACE_QoS ace_get_qos = this->qos_session_->qos (); + + ACE_DEBUG ((LM_DEBUG, + "\nReceiving Flowspec :\t\t\tSending Flowspec :\n\n" + "\tToken Rate = %d\t\t\tToken Rate = %d\n" + "\tToken Bucket Size = %d\t\t\tToken Bucket Size = %d\n" + "\tPeak Bandwidth = %d\t\t\tPeak Bandwidth = %d\n" + "\tLatency = %d\t\t\t\tLatency = %d\n" + "\tDelay Variation = %d\t\t\tDelay Variation = %d\n" + "\tService Type = %d\t\t\tService Type = %d\n" + "\tMax SDU Size = %d\t\t\tMax SDU Size = %d\n" + "\tMinimum Policed Size = %d\t\tMinimum Policed Size = %d\n\n", + ace_get_qos.receiving_flowspec ()->token_rate (), + ace_get_qos.sending_flowspec ()->token_rate (), + ace_get_qos.receiving_flowspec ()->token_bucket_size (), + ace_get_qos.sending_flowspec ()->token_bucket_size (), + ace_get_qos.receiving_flowspec ()->peak_bandwidth (), + ace_get_qos.sending_flowspec ()->peak_bandwidth (), + ace_get_qos.receiving_flowspec ()->latency (), + ace_get_qos.sending_flowspec ()->latency (), + ace_get_qos.receiving_flowspec ()->delay_variation (), + ace_get_qos.sending_flowspec ()->delay_variation (), + ace_get_qos.receiving_flowspec ()->service_type (), + ace_get_qos.sending_flowspec ()->service_type (), + ace_get_qos.receiving_flowspec ()->max_sdu_size (), + ace_get_qos.sending_flowspec ()->max_sdu_size (), + ace_get_qos.receiving_flowspec ()->minimum_policed_size (), + ace_get_qos.sending_flowspec ()->minimum_policed_size ())); + + +return 0; + +} + + + + + + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/Receiver_QoS_Event_Handler.h b/ACE/examples/QOS/Change_Sender_TSpec/Receiver_QoS_Event_Handler.h new file mode 100644 index 00000000000..874d628e3c1 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/Receiver_QoS_Event_Handler.h @@ -0,0 +1,61 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Receiver_QoS_Event_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef RECEIVER_QOS_EVENT_HANDLER_H +#define RECEIVER_QOS_EVENT_HANDLER_H + +#include "ace/Reactor.h" +#include "ace/INET_Addr.h" +#include "ace/Event_Handler.h" +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +ACE_RCSID(Receiver_QoS_Event_Handler, Receiver_QoS_Event_Handler, "$Id$") + + class Receiver_QoS_Event_Handler : public ACE_Event_Handler + { + public: + // = Initialization and Termination methods. + Receiver_QoS_Event_Handler (void); + // Constructor. + + Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS &dgram_mcast_qos, + ACE_QoS_Session *qos_session); + // Constructor. + + ~Receiver_QoS_Event_Handler (void); + // Destructor. + + virtual ACE_HANDLE get_handle (void) const; + // Override this to return the handle of the Dgram_Mcast + // that we are using. + + virtual int handle_input (ACE_HANDLE fd); + // Handles a READ event. + + virtual int handle_qos (ACE_HANDLE fd); + // Handles a QoS event. + + private: + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos_; + ACE_QoS_Session *qos_session_; + ACE_INET_Addr remote_addr_; + }; + +#endif /* RECEIVER_QOS_EVENT_HANDLER_H */ + + + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/Sender_QoS_Event_Handler.cpp b/ACE/examples/QOS/Change_Sender_TSpec/Sender_QoS_Event_Handler.cpp new file mode 100644 index 00000000000..7688bc34373 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/Sender_QoS_Event_Handler.cpp @@ -0,0 +1,221 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Sender_QoS_Event_Handler.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#include "Sender_QoS_Event_Handler.h" +#include "ace/Log_Msg.h" + +#include "Fill_ACE_QoS.h" + +// Constructor. +Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (void) +{ +} + +// Constructor. +Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session) + : dgram_mcast_qos_ (dgram_mcast_qos), + qos_session_ (qos_session) +{ +} + +// Destructor. +Sender_QoS_Event_Handler::~Sender_QoS_Event_Handler (void) +{ +} + +// Return the handle of the Dgram_Mcast. This method is called +// internally by the reactor. + +ACE_HANDLE +Sender_QoS_Event_Handler::get_handle (void) const +{ + return this->dgram_mcast_qos_.get_handle (); +} + +// Handle the QoS Event. In this case send data to the receiver +// using WSASendTo() that uses overlapped I/O. + +int +Sender_QoS_Event_Handler::handle_qos (ACE_HANDLE) +{ + ACE_DEBUG ((LM_DEBUG, + "\nReceived a QOS event. Inside handle_qos ()\n")); + + // We have received an RSVP event. The following update_qos () call + // calls rapi_dispatch () in case of RAPI and WSAIoctl (GET_QOS) in + // case of W2K. It then does the QoS parameter translation and updates + // the QoS session object with the latest QoS. This call replaces the + // direct call that was being made to WSAIoctl (GET_QOS) here for the + // Win2K example. + + if (this->qos_session_->update_qos () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in updating QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + " Updating QOS succeeds.\n")); + + // Now proactively query the QoS object for QoS. + ACE_QoS ace_get_qos = this->qos_session_->qos (); + + ACE_DEBUG ((LM_DEBUG, + "\nReceiving Flowspec :\t\t\tSending Flowspec :\n\n" + "\tToken Rate = %d\t\t\tToken Rate = %d\n" + "\tToken Bucket Size = %d\t\t\tToken Bucket Size = %d\n" + "\tPeak Bandwidth = %d\t\t\tPeak Bandwidth = %d\n" + "\tLatency = %d\t\t\t\tLatency = %d\n" + "\tDelay Variation = %d\t\t\tDelay Variation = %d\n" + "\tService Type = %d\t\t\tService Type = %d\n" + "\tMax SDU Size = %d\t\t\tMax SDU Size = %d\n" + "\tMinimum Policed Size = %d\t\tMinimum Policed Size = %d\n\n", + ace_get_qos.receiving_flowspec ()->token_rate (), + ace_get_qos.sending_flowspec ()->token_rate (), + ace_get_qos.receiving_flowspec ()->token_bucket_size (), + ace_get_qos.sending_flowspec ()->token_bucket_size (), + ace_get_qos.receiving_flowspec ()->peak_bandwidth (), + ace_get_qos.sending_flowspec ()->peak_bandwidth (), + ace_get_qos.receiving_flowspec ()->latency (), + ace_get_qos.sending_flowspec ()->latency (), + ace_get_qos.receiving_flowspec ()->delay_variation (), + ace_get_qos.sending_flowspec ()->delay_variation (), + ace_get_qos.receiving_flowspec ()->service_type (), + ace_get_qos.sending_flowspec ()->service_type (), + ace_get_qos.receiving_flowspec ()->max_sdu_size (), + ace_get_qos.sending_flowspec ()->max_sdu_size (), + ace_get_qos.receiving_flowspec ()->minimum_policed_size (), + ace_get_qos.sending_flowspec ()->minimum_policed_size ())); + + // This is SPECIFIC TO WIN2K and should be done in the qos_update function. + +// ACE_QoS ace_get_qos; +// u_long dwBytes; + +// if (ACE_OS::ioctl (this->dgram_mcast_qos_.get_handle (), +// ACE_SIO_GET_QOS, +// ace_get_qos, +// &dwBytes) == -1) +// ACE_ERROR ((LM_ERROR, +// "Error in Qos get ACE_OS::ioctl ()\n" +// "Bytes Returned = %d\n", +// dwBytes)); +// else +// ACE_DEBUG ((LM_DEBUG, +// "Getting QOS using ACE_OS::ioctl () succeeds.\n")); + + char* msg = "Hello sent on a QoS enabled session !!\n"; + iovec iov[1]; + iov[0].iov_base = msg; + iov[0].iov_len = ACE_OS::strlen(msg); + + size_t bytes_sent = 0; + + // Send "Hello" to the QoS session address to which the receiver has + // subscribed. + if (this->dgram_mcast_qos_.send (iov, + 1, + bytes_sent, + 0, + this->qos_session_->dest_addr (), + 0, + 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in dgram_mcast.send ()\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Using ACE_OS::sendto () : Bytes sent : %d", + bytes_sent)); + + // + // create a dynamic flow spec on each callback to test QoS retransmits + // + ACE_CString flow_id ("flow_id"); + + Fill_ACE_QoS flow_spec_list; + ACE_DEBUG ((LM_DEBUG, + "\nA new flow spec! in QoS handler.")); + + static int token_rate = 9400; + ++token_rate; + static int peak_bw = 18500; + ++peak_bw; + switch (flow_spec_list.map ().bind (flow_id, + new ACE_Flow_Spec (token_rate, + 708, + peak_bw, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + // + // set up the new qos + // + ACE_QoS another_qos_sender; + if (flow_spec_list.fill_simplex_sender_qos (another_qos_sender, + flow_id) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill handler-simplex sender qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Successfully built a new flowspec in handle_qos!\n")); + + // + // change the qos for the current session + // + ACE_QoS_Manager qos_manager = this->dgram_mcast_qos_.qos_manager (); + + ACE_DEBUG ((LM_DEBUG, + "QoS Manager was built in handle_qos!\n")); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (this->qos_session_->qos (&this->dgram_mcast_qos_, + &qos_manager, + another_qos_sender) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + + + // ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos_; + // ACE_QoS_Session *qos_session_; + + return 0; +} diff --git a/ACE/examples/QOS/Change_Sender_TSpec/Sender_QoS_Event_Handler.h b/ACE/examples/QOS/Change_Sender_TSpec/Sender_QoS_Event_Handler.h new file mode 100644 index 00000000000..b691bbd0615 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/Sender_QoS_Event_Handler.h @@ -0,0 +1,61 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Sender_QoS_Event_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef SENDER_QOS_EVENT_HANDLER_H +#define SENDER_QOS_EVENT_HANDLER_H + +#include "ace/Event_Handler.h" +#include "ace/Reactor.h" +#include "ace/INET_Addr.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" +#include "ace/QoS/QoS_Session.h" + +//#define MY_DEFPORT 5001 +//#define DEFAULT_MULTICASTGROUP "234.5.6.7" + +ACE_RCSID(Sender_QoS_Event_Handler, Sender_QoS_Event_Handler, "$Id$") + +class Sender_QoS_Event_Handler : public ACE_Event_Handler +{ +public: + // = Initialization and Termination methods. + Sender_QoS_Event_Handler (void); + // Constructor. + + Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session + ); + // Constructor. + + ~Sender_QoS_Event_Handler (void); + // Destructor. + + virtual ACE_HANDLE get_handle (void) const; + // Override this to return the handle of the Dgram_Mcast + // that we are using. + + virtual int handle_qos (ACE_HANDLE fd); + // Handles a QoS event. Right now, just + // prints a message. + +private: + + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos_; + ACE_QoS_Session *qos_session_; +}; + +#endif /* SENDER_QOS_EVENT_HANDLER_H */ diff --git a/ACE/examples/QOS/Change_Sender_TSpec/receiver.cpp b/ACE/examples/QOS/Change_Sender_TSpec/receiver.cpp new file mode 100644 index 00000000000..e5702b90c1c --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/receiver.cpp @@ -0,0 +1,319 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// server.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#define QOSEVENT_MAIN + +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/QoS_Session_Factory.h" +#include "ace/QoS/QoS_Decorator.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +#include "QoS_Util.h" +#include "Fill_ACE_QoS.h" +#include "QoS_Signal_Handler.h" +#include "Receiver_QoS_Event_Handler.h" + +// To open QOS sockets administrative access is required on the +// machine. Fill in default values for QoS structure. The default +// values were simply choosen from existing QOS templates available +// via WSAGetQosByName. Notice that ProviderSpecific settings are +// being allowed when picking the "default" template but not for +// "well-known" QOS templates. Also notice that since data is only +// flowing from sender to receiver, different flowspecs are filled in +// depending upon whether this application is acting as a sender or +// receiver. + + +// This function fills up the ACE_QoS_Params with the supplied iovec +// and ACE_QoS. + +int +FillQoSParams (ACE_QoS_Params &qos_params, + iovec* iov, + ACE_QoS* qos) +{ + qos_params.callee_data (iov); + qos_params.caller_data (0); + qos_params.socket_qos (qos); + qos_params.group_socket_qos (0); + qos_params.flags (ACE_JL_BOTH); + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + + QoS_Util qos_util(argc, argv); + + if (qos_util.parse_args () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in parsing args\n"), + -1); + + // This is a multicast application. + if (qos_util.multicast_flag ()) + { + Fill_ACE_QoS fill_ace_qos; + + // The application adds the flow specs that it wants into the + // Fill_ACE_QoS. The Fill_ACE_QoS indexes the flow specs by the + // flow spec names. Here the new flowspec being added is g_711. + ACE_CString g_711 ("g_711"); + + switch (fill_ace_qos.map ().bind (g_711, + new ACE_Flow_Spec (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + ACE_DEBUG ((LM_DEBUG, + "g_711 Flow Spec bound successfully\n")); + + // This is a receiver. So we fill in the receiving QoS parameters. + ACE_QoS ace_qos_receiver; + if (fill_ace_qos.fill_simplex_receiver_qos (ace_qos_receiver, + g_711) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill simplex receiver qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Filled up the Receiver QoS parameters\n")); + + // Opening a new Multicast Datagram. + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos; + + // Multicast Session Address specified by user at command line. + // If this address is not specified, + // <localhost:ACE_DEFAULT_MULTICAST_PORT> is assumed. + ACE_INET_Addr mult_addr (*(qos_util.mult_session_addr ())); + + // Fill the ACE_QoS_Params to be passed to the <ACE_OS::join_leaf> + // through subscribe. + + ACE_QoS_Params qos_params; + FillQoSParams (qos_params, 0, &ace_qos_receiver); + + // Create a QoS Session Factory. + ACE_QoS_Session_Factory session_factory; + + // Ask the factory to create a QoS session. + ACE_QoS_Session *qos_session = + session_factory.create_session (); + + // Create a destination address for the QoS session. The same + // address should be used for the subscribe call later. A copy + // is made below only to distinguish the two usages of the dest + // address. + + ACE_INET_Addr dest_addr (mult_addr); + + // A QoS session is defined by the 3-tuple [DestAddr, DestPort, + // Protocol]. Initialize the QoS session. + if (qos_session->open (mult_addr, + IPPROTO_UDP) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in opening the QoS session\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS session opened successfully\n")); + + // The following call opens the Dgram_Mcast and calls the + // <ACE_OS::join_leaf> with the qos_params supplied here. Note + // the QoS session object is passed into this call. This + // subscribes the underlying socket to the passed in QoS + // session. For joining multiple multicast sessions, the + // following subscribe call should be made with different + // multicast addresses and a new QoS session object should be + // passed in for each such call. The QoS session objects can be + // created only through the session factory. Care should be + // taken that the mult_addr for the subscribe() call matches the + // dest_addr of the QoS session object. If this is not done, the + // subscribe call will fail. A more abstract version of + // subscribe will be added that constrains the various features + // of GQoS like different flags etc. + + if (dgram_mcast_qos.subscribe (mult_addr, + qos_params, + 1, + 0, + AF_INET, + // ACE_FROM_PROTOCOL_INFO, + 0, + 0, // ACE_Protocol_Info, + 0, + ACE_OVERLAPPED_SOCKET_FLAG + | ACE_FLAG_MULTIPOINT_C_LEAF + | ACE_FLAG_MULTIPOINT_D_LEAF, + qos_session) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in subscribe\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Dgram_Mcast subscribe succeeds \n")); + + int nIP_TTL = 25; + char achInBuf [BUFSIZ]; + u_long dwBytes; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTICAST_SCOPE, // IO control code. + &nIP_TTL, // In buffer. + sizeof (nIP_TTL), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Multicast scope ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Setting TTL with Multicast scope ACE_OS::ioctl call succeeds \n")); + + int bFlag = 0; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTIPOINT_LOOPBACK, // IO control code. + &bFlag, // In buffer. + sizeof (bFlag), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Loopback ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Disable Loopback with ACE_OS::ioctl call succeeds \n")); + + // This is a receiver. + qos_session->flags (ACE_QoS_Session::ACE_QOS_RECEIVER); + + ACE_QoS_Manager qos_manager = dgram_mcast_qos.qos_manager (); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (qos_session->qos (&dgram_mcast_qos, + &qos_manager, + ace_qos_receiver) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + + // Register a signal handler that helps to gracefully close the + // open QoS sessions. + QoS_Signal_Handler qos_signal_handler (qos_session); + + // Register the usual SIGINT signal handler with the Reactor for + // the application to gracefully release the QoS session and + // shutdown. + if (ACE_Reactor::instance ()->register_handler + (SIGINT, &qos_signal_handler) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Signal Handler.\n"), + -1); + + // Handler to process QoS and Data events for the reciever. + Receiver_QoS_Event_Handler qos_event_handler (dgram_mcast_qos, + qos_session); + + // Decorate the above handler with QoS functionality. + ACE_QoS_Decorator qos_decorator (&qos_event_handler, + qos_session); + + // Initialize the Decorator. + if (qos_decorator.init () != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "QoS Decorator init () failed.\n"), + -1); + + // Register the decorated Event Handler with the Reactor. + if (ACE_Reactor::instance ()->register_handler (&qos_decorator, + ACE_Event_Handler::QOS_MASK | + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Decorator with the Reactor\n"), + -1); + +// // Register the RAPI Event Handler with the Reactor. This +// // handles the QoS events. +// if (ACE_Reactor::instance ()->register_handler +// (&rapi_event_handler, +// ACE_Event_Handler::QOS_MASK | ACE_Event_Handler::READ_MASK) == -1) +// ACE_ERROR_RETURN ((LM_ERROR, +// "Error in registering the RAPI Event Handler\n"), +// -1); + +// // The following event handler handles the data. +// ACE_QoS_Event_Handler data_event_handler (dgram_mcast_qos, +// qos_session); + +// // Register the Data Event Handler with the Reactor. +// if (ACE_Reactor::instance ()->register_handler +// (&data_event_handler,ACE_Event_Handler::READ_MASK) == -1) +// ACE_ERROR_RETURN ((LM_ERROR, +// "Error in registering Data Event Handler\n"), +// -1); + + // Start the event loop. + ACE_DEBUG ((LM_DEBUG, + "Running the Event Loop ... \n")); + + ACE_Reactor::instance ()->run_event_loop (); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) shutting down server logging daemon\n")); + } + else + ACE_DEBUG ((LM_DEBUG, + "Specify a -m option for multicast application\n")); + return 0; +} + + + diff --git a/ACE/examples/QOS/Change_Sender_TSpec/sender.cpp b/ACE/examples/QOS/Change_Sender_TSpec/sender.cpp new file mode 100644 index 00000000000..68d8d1a5586 --- /dev/null +++ b/ACE/examples/QOS/Change_Sender_TSpec/sender.cpp @@ -0,0 +1,313 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// client.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + + +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/QoS_Session_Factory.h" +#include "ace/QoS/QoS_Session_Impl.h" +#include "ace/QoS/QoS_Decorator.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +#include "QoS_Util.h" +#include "Fill_ACE_QoS.h" +#include "QoS_Signal_Handler.h" +#include "Sender_QoS_Event_Handler.h" + +// To open QOS sockets administrative access is required on the +// machine. Fill in default values for QoS structure. The default +// values were simply choosen from existing QOS templates available +// via WSAGetQosByName. Notice that ProviderSpecific settings are +// being allowed when picking the "default" template but not for +// "well-known" QOS templates. Also notice that since data is only +// flowing from sender to receiver, different flowspecs are filled in +// depending upon whether this application is acting as a sender or +// receiver. + +// This function fills up the ACE_QoS_Params with the supplied iovec and ACE_QoS. + +int +FillQoSParams (ACE_QoS_Params &qos_params, + iovec* iov, + ACE_QoS* qos) +{ + qos_params.callee_data (iov); + qos_params.caller_data (0); + qos_params.socket_qos (qos); + qos_params.group_socket_qos (0); + qos_params.flags (ACE_JL_BOTH); + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + + ACE_DEBUG ((LM_DEBUG, + "Sender\n")); + + QoS_Util qos_util(argc, argv); + + if (qos_util.parse_args () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in parsing args\n"), + -1); + + // This is a multicast application. + if (qos_util.multicast_flag ()) + { + Fill_ACE_QoS fill_ace_qos; + + // The application adds the flow specs that it wants into the + // Fill_ACE_QoS. The Fill_ACE_QoS indexes the flow specs by the flow + // spec names. Here the new flowspec being added is g_711. + ACE_CString g_711 ("g_711"); + + switch (fill_ace_qos.map ().bind (g_711, + new ACE_Flow_Spec (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + ACE_DEBUG ((LM_DEBUG, + "g_711 Flow Spec bound successfully\n")); + + // This is a sender. So we fill in the sending QoS parameters. + ACE_QoS ace_qos_sender; + + if (fill_ace_qos.fill_simplex_sender_qos (ace_qos_sender, + g_711) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill simplex sender qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Filled up the Sender QoS parameters\n")); + + // Opening a new Multicast Datagram. It is absolutely necessary that + // the sender and the receiver subscribe to the same multicast + // addresses to make sure the "multicast sessions" for the two are + // the same. This is used to match the RESV<->PATH states. + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos; + + // Multicast Session Address specified by user at command line. + // If this address is not specified, + // <localhost:ACE_DEFAULT_MULTICAST_PORT> is assumed. + ACE_INET_Addr mult_addr (*(qos_util.mult_session_addr ())); + + // Fill the ACE_QoS_Params to be passed to the <ACE_OS::join_leaf> + // through subscribe. + + ACE_QoS_Params qos_params; + FillQoSParams (qos_params, 0, &ace_qos_sender); + + // Create a QoS Session Factory. + ACE_QoS_Session_Factory session_factory; + + // Ask the factory to create a QoS session. + ACE_QoS_Session *qos_session = + session_factory.create_session (); + + // Create a destination address for the QoS session. The same + // address should be used for the subscribe call later. A copy is + // made below only to distinguish the two usages of the dest + // address. + + ACE_INET_Addr dest_addr (mult_addr); + + // A QoS session is defined by the 3-tuple [DestAddr, DestPort, + // Protocol]. Initialize the QoS session. + if (qos_session->open (mult_addr, + IPPROTO_UDP) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in opening the QoS session\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS session opened successfully\n")); + + // The following call opens the Dgram_Mcast and calls the + // <ACE_OS::join_leaf> with the qos_params supplied here. Note the + // QoS session object is passed into this call. This subscribes the + // underlying socket to the passed in QoS session. For joining + // multiple multicast sessions, the following subscribe call should + // be made with different multicast addresses and a new QoS session + // object should be passed in for each such call. The QoS session + // objects can be created only through the session factory. Care + // should be taken that the mult_addr for the subscribe() call + // matches the dest_addr of the QoS session object. If this is not + // done, the subscribe call will fail. A more abstract version of + // subscribe will be added that constrains the various features of + // GQoS like different flags etc. + + if (dgram_mcast_qos.subscribe (mult_addr, + qos_params, + 1, + 0, + AF_INET, + // ACE_FROM_PROTOCOL_INFO, + 0, + 0, // ACE_Protocol_Info, + 0, + ACE_OVERLAPPED_SOCKET_FLAG + | ACE_FLAG_MULTIPOINT_C_LEAF + | ACE_FLAG_MULTIPOINT_D_LEAF, + qos_session) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in subscribe\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Dgram_Mcast subscribe succeeds \n")); + + int nIP_TTL = 25; + char achInBuf [BUFSIZ]; + u_long dwBytes; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTICAST_SCOPE, // IO control code. + &nIP_TTL, // In buffer. + sizeof (nIP_TTL), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Multicast scope ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Setting TTL with Multicast scope ACE_OS::ioctl call succeeds \n")); + + int bFlag = 0; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTIPOINT_LOOPBACK, // IO control code. + &bFlag, // In buffer. + sizeof (bFlag), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Loopback ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Disable Loopback with ACE_OS::ioctl call succeeds \n")); + + // This is a sender. + qos_session->flags (ACE_QoS_Session::ACE_QOS_SENDER); + + ACE_QoS_Manager qos_manager = dgram_mcast_qos.qos_manager (); + + // Since we are using RSVP, it is imperative that the client + // application have the option of supplying the source sender + // port for the RSVP messages. A default will be chosen by the + // ACE API if this is not done. + qos_session->source_port (qos_util.source_port ()); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (qos_session->qos (&dgram_mcast_qos, + &qos_manager, + ace_qos_sender) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + + // Register a signal handler that helps to gracefully close the open + // QoS sessions. + QoS_Signal_Handler qos_signal_handler (qos_session); + + // Register the usual SIGINT signal handler with the Reactor for + // the application to gracefully release the QoS session and + // shutdown. + if (ACE_Reactor::instance ()->register_handler + (SIGINT, &qos_signal_handler) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Signal Handler.\n"), + -1); + + // Handler to process QoS and Data events for the reciever. + Sender_QoS_Event_Handler qos_event_handler (dgram_mcast_qos, + qos_session); + + // Decorate the above handler with QoS functionality. + ACE_QoS_Decorator qos_decorator (&qos_event_handler, + qos_session); + + // Initialize the Decorator. + if (qos_decorator.init () != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "QoS Decorator init () failed.\n"), + -1); + + // Register the decorated Event Handler with the Reactor. + if (ACE_Reactor::instance ()->register_handler (&qos_decorator, + ACE_Event_Handler::QOS_MASK | + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Decorator with the Reactor\n"), + -1); + + // Start the event loop. + ACE_DEBUG ((LM_DEBUG, + "Running the Event Loop ... \n")); + + ACE_Reactor::instance ()->run_event_loop (); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) shutting down server logging daemon\n")); + } + else + ACE_DEBUG ((LM_DEBUG, + "Specify a -m option for multicast application\n")); + return 0; +} + + + + + + + diff --git a/ACE/examples/QOS/Diffserv/Makefile.am b/ACE/examples/QOS/Diffserv/Makefile.am new file mode 100644 index 00000000000..e94221278a2 --- /dev/null +++ b/ACE/examples/QOS/Diffserv/Makefile.am @@ -0,0 +1,62 @@ +## 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: +## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + +noinst_PROGRAMS = + +## Makefile.QOS_Diffserv_Client.am + +if BUILD_QOS +if !BUILD_ACE_FOR_TAO +noinst_PROGRAMS += client + +client_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +client_SOURCES = \ + diffserv_test.cpp + +client_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif !BUILD_ACE_FOR_TAO +endif BUILD_QOS + +## Makefile.QOS_Diffserv_Server.am + +if BUILD_QOS +noinst_PROGRAMS += server + +server_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +server_SOURCES = \ + server.cpp + +server_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_QOS + +## 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/examples/QOS/Diffserv/NOTES.txt b/ACE/examples/QOS/Diffserv/NOTES.txt new file mode 100644 index 00000000000..4e73c66af0f --- /dev/null +++ b/ACE/examples/QOS/Diffserv/NOTES.txt @@ -0,0 +1,58 @@ +# $Id$ + +Linux notes +=========== + +Under Linux kernel 2.4, the following DSCP values +could not be set with the setsockopt call +unless you run as root: + +EF, CS5, CS6, CS7 + +Also, under Linux 2.4.2 kernel, if I could successfully +set the 2 bits reserved for ECN in the Diffserv Field to +0x00 or 0x02. However, the setsockopt call would +fail if it was set to 0x01 or 0x03. + +According to the Linux Diffserv mailing list: +http://diffserv.sourceforge.net +http://www.geocrawler.com/archives/3/11111/2001/10/0/6761099/ + +=========================================================================== +On Fri, Oct 05, 2001 at 08:18:06AM +0300, Pekka Savola wrote: +> On Tue, 2 Oct 2001, Craig Rodrigues wrote: +> > Can someone shed some light as to why I got this +> > error under Linux? Is it configuration problem, +> > or is there some sort of policy decision in the kernel that +> > requires the process to be run as root when setting +> > those DSCP values? +> +> A part of DSCP field was previously Precedence. +> +> Linux has required that in order to use 'Critical' or higher Precedence, +> one must have CAP_NET_ADMIN capability, in most cases, root. +> +> I'm not one to say whether this restriction should be removed. Perhaps. +> +> -- +> Pekka Savola "Tell me of difficulties surmounted, +> Netcore Oy not those you stumble over and fall" +> Systems. Networks. Security. -- Robert Jordan: A Crown of Swords +> +=========================================================================== + +FreeBSD notes +============= +Under FreeBSD 4.3, I encountered no problems +setting DSCP or ECN values, and I could set all +these values without being root. +However, FreeBSD seems to be more fussy about the size of the parameter +you pass into the setsockopt call. Make sure you get the +size right, and cast it properly, ie. don't cast a short, or some +other size. + + +Solaris notes +============= +No problems setting DSCP or ECN values. + diff --git a/ACE/examples/QOS/Diffserv/QOS_Diffserv.mpc b/ACE/examples/QOS/Diffserv/QOS_Diffserv.mpc new file mode 100644 index 00000000000..3e66fbee34a --- /dev/null +++ b/ACE/examples/QOS/Diffserv/QOS_Diffserv.mpc @@ -0,0 +1,18 @@ +// -*- MPC -*- +// $Id$ + +project(*client) : aceexe, qos { + avoids += ace_for_tao + exename = client + requires += qos + Source_Files { + diffserv_test.cpp + } +} +project(*server) : aceexe, qos { + exename = server + requires += qos + Source_Files { + server.cpp + } +} diff --git a/ACE/examples/QOS/Diffserv/README b/ACE/examples/QOS/Diffserv/README new file mode 100644 index 00000000000..285d514ad12 --- /dev/null +++ b/ACE/examples/QOS/Diffserv/README @@ -0,0 +1,107 @@ +This directory contains an example which +tests the setting of the Diffserv Codepoint (DSCP) +values in the +IP TOS field of a stream of UDP packets. + +Running the example +=================== + +(1) On one host, run: + server [UDP port number] + + If port number is omitted, a default port number of 20002 + is used. + +(2) On a second host, run: + diffserv_test [destination host] [destination port] + + The host and port of where the server is running should + be specified. + + A stream of UDP packets will be sent from to the server, + with various codepoints set. + +(3) Look at the Diffserv Field (formerly known as the TOS field) + of your packets, using a protocol analyzer, such as Ethereal. + + + + +Introduction +============ +In RFC 2474, the Type of Service (TOS) field in +the IP header was renamed the Diffserv (DS) field. +The DS field is one octet (8 bits). + + 0 1 2 3 4 5 6 7 + +---+---+---+---+---+---+---+---+ + | DSCP | ECN | + +---+---+---+---+---+---+---+---+ + +The first 6 bits of the field are +reserved for the Diffserv Codepoint (DSCP). +There are 64 possible values (0-63) for the DSCP. + +Bits 6 and 7 of the DS field are reserved +for Explicit Congestion Notification (ECN). +ECN is defined in RFC 3168. + + +Per-Hop Behaviors (PHB) +======================= + +A Per-Hop Behavior (PHB) is a description of the externally +observable forwarding treatment applied at a differentiated +services compliant node. + +Certain PHB's are defined in RFC's and associated with +different DSCP values. Other values are undefined and left +for experimentation. Please refer to the RFC's for a full +explanation of the attributes of the various PHB's. + + +DSCP value PHB RFC +(binary) +----------------------------------------------------------- +000000 Default (Best Effort) 2474 +001000 Class Selector (CS1) 2474 +010000 Class Selector (CS2) 2474 +011000 Class Selector (CS3) 2474 +100000 Class Selector (CS4) 2474 +101000 Class Selector (CS5) 2474 +110000 Class Selector (CS6) 2474 +111000 Class Selector (CS7) 2474 +001010 Assured Forwarding (AF11) 2597 +001100 Assured Forwarding (AF12) 2597 +001110 Assured Forwarding (AF13) 2597 +010010 Assured Forwarding (AF21) 2597 +010100 Assured Forwarding (AF22) 2597 +010110 Assured Forwarding (AF23) 2597 +011010 Assured Forwarding (AF31) 2597 +011100 Assured Forwarding (AF32) 2597 +011110 Assured Forwarding (AF33) 2597 +100010 Assured Forwarding (AF41) 2597 +100100 Assured Forwarding (AF42) 2597 +100110 Assured Forwarding (AF43) 2597 +101110 Expedited Forwarding (EF) 2598 + + +References +========== +RFC 2474, "Definition of the Differentiated Services (DS Field) + in the IPv4 and IPv6 Headers", http://www.ietf.org/rfc/rfc2474.txt + +RFC 2475, "An Architecture for Differentiated Services", + http://www.ietf.org/rfc/rfc2475.txt + +RFC 2597, "Assured Forwarding PHB Group", http://www.ietf.org/rfc/rfc2597.txt + +RFC 3246, "An Expedited Forwarding PHB", http://www.ietf.org/rfc/rfc3246.txt + +RFC 3247, "Supplemental Information for the New Definition of the EF PHB", + http://www.ietf.org/rfc/rfc3247.txt + +RFC 3168, "The Addition of Explicit Congestion Notification (ECN) + to IP", http://www.ietf.org/rfc/rfc3168.txt + +Ethereal, http://www.ethereal.com diff --git a/ACE/examples/QOS/Diffserv/diffserv_test.cpp b/ACE/examples/QOS/Diffserv/diffserv_test.cpp new file mode 100644 index 00000000000..1969616ea32 --- /dev/null +++ b/ACE/examples/QOS/Diffserv/diffserv_test.cpp @@ -0,0 +1,136 @@ +//============================================================================= +/** + * @file diffserv_test.cpp + * + * $Id$ + * + * @author Craig Rodrigues <crodrigu@bbn.com> + * @brief Send UDP packets to a destination host and port. + * Change the Diffserv field to various values. + */ +//============================================================================= + +#include "ace/Log_Msg.h" +#include "ace/SOCK_CODgram.h" +#include "ace/INET_Addr.h" +#include "ace/OS_NS_string.h" +#include "ace/OS_NS_stdlib.h" +#include "ace/OS_NS_unistd.h" + +#define IPDSFIELD_DSCP_DEFAULT 0x00 +#define IPDSFIELD_DSCP_CS1 0x08 +#define IPDSFIELD_DSCP_CS2 0x10 +#define IPDSFIELD_DSCP_CS3 0x18 +#define IPDSFIELD_DSCP_CS4 0x20 +#define IPDSFIELD_DSCP_CS5 0x28 +#define IPDSFIELD_DSCP_CS6 0x30 +#define IPDSFIELD_DSCP_CS7 0x38 +#define IPDSFIELD_DSCP_AF11 0x0A +#define IPDSFIELD_DSCP_AF12 0x0C +#define IPDSFIELD_DSCP_AF13 0x0E +#define IPDSFIELD_DSCP_AF21 0x12 +#define IPDSFIELD_DSCP_AF22 0x14 +#define IPDSFIELD_DSCP_AF23 0x16 +#define IPDSFIELD_DSCP_AF31 0x1A +#define IPDSFIELD_DSCP_AF32 0x1C +#define IPDSFIELD_DSCP_AF33 0x1E +#define IPDSFIELD_DSCP_AF41 0x22 +#define IPDSFIELD_DSCP_AF42 0x24 +#define IPDSFIELD_DSCP_AF43 0x26 +#define IPDSFIELD_DSCP_EF 0x2E +#define IPDSFIELD_ECT_MASK 0x02 +#define IPDSFIELD_CE_MASK 0x01 + +int dscp [] = + { + IPDSFIELD_DSCP_DEFAULT , + IPDSFIELD_DSCP_CS1 , + IPDSFIELD_DSCP_CS2 , + IPDSFIELD_DSCP_CS3 , + IPDSFIELD_DSCP_CS4 , + IPDSFIELD_DSCP_CS5 , + IPDSFIELD_DSCP_CS6 , + IPDSFIELD_DSCP_CS7 , + IPDSFIELD_DSCP_AF11 , + IPDSFIELD_DSCP_AF12 , + IPDSFIELD_DSCP_AF13 , + IPDSFIELD_DSCP_AF21 , + IPDSFIELD_DSCP_AF22 , + IPDSFIELD_DSCP_AF23 , + IPDSFIELD_DSCP_AF31 , + IPDSFIELD_DSCP_AF32 , + IPDSFIELD_DSCP_AF33 , + IPDSFIELD_DSCP_AF41 , + IPDSFIELD_DSCP_AF42 , + IPDSFIELD_DSCP_AF43 , + IPDSFIELD_DSCP_EF + }; + +const char *dscp_char[]= + { + "Normal", + "CS1", + "CS2", + "CS3", + "CS4", + "CS5", + "CS6", + "CS7", + "Assured Forwarding 11", + "Assured Forwarding 12", + "Assured Forwarding 13", + "Assured Forwarding 21", + "Assured Forwarding 22", + "Assured Forwarding 23", + "Assured Forwarding 31", + "Assured Forwarding 32", + "Assured Forwarding 33", + "Assured Forwarding 41", + "Assured Forwarding 42", + "Assured Forwarding 43", + "Expedited Forwarding" + }; + +int +ACE_TMAIN (int argc , ACE_TCHAR *argv[]) +{ + + if(argc != 3) + { + ACE_DEBUG((LM_DEBUG, "Usage:\n %s [destination host] [destination port]\n\n", argv[0])); + ACE_OS::exit(1); + } + + + char *buf = (char *)ACE_OS::malloc(20 * sizeof(char)); + ACE_OS::strcpy(buf, "Hello"); + + ACE_SOCK_CODgram sock; + ACE_INET_Addr raddr(ACE_OS::atoi(argv[2]), argv[1]); + + sock.open( raddr, ACE_Addr::sap_any, PF_INET, 0, 1); + int opt=0; + int ret =0, ret2=0; + unsigned int i; + for(i=0; i < 21; i++) + { + opt = dscp[i] << 2; + ret = sock.set_option(IPPROTO_IP, IP_TOS, (int *)&opt, (int)sizeof(opt) ); + if(ret == -1){ + ACE_DEBUG((LM_DEBUG, "setsockopt error: %m\n")); + } + + for (int j=0; j<3; j++) + { + ret2 = sock.send(buf, ACE_OS::strlen(buf)); + if(ret2 == -1){ + ACE_DEBUG((LM_DEBUG, "send error: %m\n")); + } + printf("opt: %u dscp: %u, %s, setsockopt returned: %d, send returned: %d\n", opt, opt >> 2, dscp_char[i], ret, ret2); + ACE_OS::sleep(1); + } + } + + ACE_OS::free(buf); + return 0; +} diff --git a/ACE/examples/QOS/Diffserv/run_test.pl b/ACE/examples/QOS/Diffserv/run_test.pl new file mode 100755 index 00000000000..aef0765bac8 --- /dev/null +++ b/ACE/examples/QOS/Diffserv/run_test.pl @@ -0,0 +1,40 @@ +eval '(exit $?0)' && eval 'exec perl -S $0 ${1+"$@"}' + & eval 'exec perl -S $0 $argv:q' + if 0; + +# $Id$ +# -*- perl -*- + +use lib "$ENV{ACE_ROOT}/bin"; +use PerlACE::Run_Test; + +$iorfile = PerlACE::LocalFile ("ior"); + +unlink $iorfile; +$status = 0; + +$CL = new PerlACE::Process ("diffserv_test", "localhost 20002"); +$SV = new PerlACE::Process ("server"); + +$server = $SV->Spawn (); +$SV->TimedWait(2); + +$client = $CL->SpawnWaitKill (200); + +if ($client != 0) { + $time = localtime; + print STDERR "ERROR: client returned $client at $time\n"; + $status = 1; +} + +$server = $SV->WaitKill (400); + +if ($server != 0) { + $time = localtime; + print STDERR "ERROR: server returned $server at $time\n"; + $status = 1; +} + +unlink $iorfile; + +exit $status; diff --git a/ACE/examples/QOS/Diffserv/server.cpp b/ACE/examples/QOS/Diffserv/server.cpp new file mode 100644 index 00000000000..a1030d775e9 --- /dev/null +++ b/ACE/examples/QOS/Diffserv/server.cpp @@ -0,0 +1,163 @@ +//============================================================================= +/** + * @file server.cpp + * + * $Id$ + * + * @author Craig Rodrigues <crodrigu@bbn.com> + * @brief Start a server which listens for UDP packets on a specified port. + */ +//============================================================================= + +#include "ace/Reactor.h" +#include "ace/Process.h" +#include "ace/SOCK_Dgram.h" +#include "ace/INET_Addr.h" +#include "ace/Log_Msg.h" + +// Port used to receive for dgrams. +static u_short port1; + +class Dgram_Endpoint : public ACE_Event_Handler +{ +public: + Dgram_Endpoint (const ACE_INET_Addr &local_addr); + + // = Hook methods inherited from the <ACE_Event_Handler>. + virtual ACE_HANDLE get_handle (void) const; + virtual int handle_input (ACE_HANDLE handle); + virtual int handle_timeout (const ACE_Time_Value & tv, + const void *arg = 0); + virtual int handle_close (ACE_HANDLE handle, + ACE_Reactor_Mask close_mask); + + int send (const char *buf, size_t len, const ACE_INET_Addr &); + // Send the <buf> to the peer. + +private: + ACE_SOCK_Dgram endpoint_; + // Wrapper for sending/receiving dgrams. +}; + +int +Dgram_Endpoint::send (const char *buf, + size_t len, + const ACE_INET_Addr &addr) +{ + return this->endpoint_.send (buf, len, addr); +} + +Dgram_Endpoint::Dgram_Endpoint (const ACE_INET_Addr &local_addr) + : endpoint_ (local_addr) +{ +} + +ACE_HANDLE +Dgram_Endpoint::get_handle (void) const +{ + return this->endpoint_.get_handle (); +} + +int +Dgram_Endpoint::handle_close (ACE_HANDLE handle, + ACE_Reactor_Mask) +{ + ACE_UNUSED_ARG (handle); + + this->endpoint_.close (); + delete this; + return 0; +} + +int +Dgram_Endpoint::handle_input (ACE_HANDLE) +{ + char buf[BUFSIZ]; + ACE_INET_Addr from_addr; + + ssize_t n = this->endpoint_.recv (buf, + sizeof buf, + from_addr); + + if (n == -1) + ACE_ERROR ((LM_ERROR, + "%p\n", + "handle_input")); + else + { + buf[n] = 0; + ACE_DEBUG ((LM_DEBUG, + "Received buf of size %d = %s\n", + n, + buf)); + } + return 0; +} + +int +Dgram_Endpoint::handle_timeout (const ACE_Time_Value &, + const void *) +{ + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) timed out for endpoint\n")); + return 0; +} + +static int +run_test (u_short localport) +{ + ACE_INET_Addr local_addr (localport); + + Dgram_Endpoint *endpoint; + + ACE_NEW_RETURN (endpoint, + Dgram_Endpoint (local_addr), + -1); + + ACE_DEBUG((LM_DEBUG, "Starting server on port %d\n",port1)); + + // Read data from other side. + if (ACE_Reactor::instance ()->register_handler + (endpoint, + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "ACE_Reactor::register_handler"), + -1); + + int ret; + while(1){ + ACE_Time_Value tv(10, 0); + ret = ACE_Reactor::instance ()->handle_events (&tv); + /* Error occurred while handling event */ + if (ret < 0) + { + ACE_ERROR_RETURN ((LM_DEBUG, + "(%P|%t) %p\n", + "handle_events"), + -1); + } + /* We have timed out without handling an event, break out of loop */ + if(ret == 0) break; + } + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR *argv[]) +{ + // Estabish call backs and socket names. + + port1 = argc > 1 ? ACE_OS::atoi (argv[1]) : ACE_DEFAULT_SERVER_PORT; + + if(argc < 3) + { + run_test (port1); + } + else{ + ACE_DEBUG((LM_DEBUG, "\nUsage:\n %s [port number]\n", argv[0])); + return -1; + } + + return 0; +} diff --git a/ACE/examples/QOS/Makefile.am b/ACE/examples/QOS/Makefile.am new file mode 100644 index 00000000000..7b2d8a15844 --- /dev/null +++ b/ACE/examples/QOS/Makefile.am @@ -0,0 +1,16 @@ +## 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: +## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu + +SUBDIRS = \ + Change_Receiver_FlowSpec \ + Change_Sender_TSpec \ + Diffserv \ + Simple + diff --git a/ACE/examples/QOS/Simple/Fill_ACE_QoS.cpp b/ACE/examples/QOS/Simple/Fill_ACE_QoS.cpp new file mode 100644 index 00000000000..20c03f40fa6 --- /dev/null +++ b/ACE/examples/QOS/Simple/Fill_ACE_QoS.cpp @@ -0,0 +1,99 @@ +// Fill_ACE_QoS.cpp +// $Id$ + +#include "Fill_ACE_QoS.h" + +ACE_RCSID(QOS, Fill_ACE_QoS,"$Id$") + +const iovec Fill_ACE_QoS::iov_ = {0,0}; + +Fill_ACE_QoS::Fill_ACE_QoS (void) +{ + ACE_NEW (this->default_traffic_, + ACE_Flow_Spec (ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_SERVICETYPE_NOTRAFFIC, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + 25, + 1)); +} + +// destructor. +Fill_ACE_QoS::~Fill_ACE_QoS (void) +{} + +int +Fill_ACE_QoS::fill_simplex_receiver_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name) +{ + ACE_Flow_Spec *recv_flow_spec = 0; + + if (this->map ().find (recv_flow_name, recv_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + recv_flow_name.c_str ()), + -1); + ace_qos.receiving_flowspec (recv_flow_spec); + ace_qos.sending_flowspec ((this->default_traffic_)); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + + +int +Fill_ACE_QoS::fill_simplex_sender_qos (ACE_QoS &ace_qos, + const ACE_CString &send_flow_name) +{ + ACE_Flow_Spec *send_flow_spec = 0; + + if (this->map ().find (send_flow_name, send_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + send_flow_name.c_str ()), + -1); + + ace_qos.receiving_flowspec ((this->default_traffic_)); + ace_qos.sending_flowspec (send_flow_spec); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + +int +Fill_ACE_QoS::fill_duplex_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name, + const ACE_CString &send_flow_name) +{ + ACE_Flow_Spec *send_flow_spec = 0; + ACE_Flow_Spec *recv_flow_spec = 0; + + if (this->map ().find (recv_flow_name, recv_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + recv_flow_name.c_str ()), + -1); + + if (this->map ().find (send_flow_name, send_flow_spec) != 0) + ACE_ERROR_RETURN ((LM_DEBUG, + "Unable to find a FlowSpec with name %s", + send_flow_name.c_str ()), + -1); + + ace_qos.receiving_flowspec (recv_flow_spec); + ace_qos.sending_flowspec (send_flow_spec); + ace_qos.provider_specific (Fill_ACE_QoS::iov_); + + return 0; +} + +Fill_ACE_QoS::FLOW_SPEC_HASH_MAP& +Fill_ACE_QoS::map (void) +{ + return this->flow_spec_map_; +} + diff --git a/ACE/examples/QOS/Simple/Fill_ACE_QoS.h b/ACE/examples/QOS/Simple/Fill_ACE_QoS.h new file mode 100644 index 00000000000..281b9beb876 --- /dev/null +++ b/ACE/examples/QOS/Simple/Fill_ACE_QoS.h @@ -0,0 +1,75 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Fill_ACE_QoS.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef FILL_ACE_QOS_H +#define FILL_ACE_QOS_H + +#include "ace/SString.h" +#include "ace/Hash_Map_Manager.h" +#include "ace/ACE.h" +#include "ace/Null_Mutex.h" +#include "ace/OS_QoS.h" + +class Fill_ACE_QoS +{ + // TITLE + // This class helps users to add new flow specs and provides + // utility functions for filling up the flow specs for simplex/duplex + // sessions. + +public: + typedef ACE_Hash_Map_Manager <ACE_CString, ACE_Flow_Spec *, ACE_Null_Mutex> FLOW_SPEC_HASH_MAP; + + //Initialization and termination methods. + Fill_ACE_QoS (void); + // constructor. + + ~Fill_ACE_QoS (void); + // destructor. + + int fill_simplex_receiver_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name); + // To be used by receivers. Fills the receiver qos and sets the + // sender qos to NO_TRAFFIC. + + int fill_simplex_sender_qos (ACE_QoS &ace_qos, + const ACE_CString &send_flow_name); + // To be used by senders. Fills the sender qos and sets the receiver + // qos to NO_TRAFFIC. + + int fill_duplex_qos (ACE_QoS &ace_qos, + const ACE_CString &recv_flow_name, + const ACE_CString &send_flow_name); + // To be used by applications that wish to be both receivers and + // senders. + + FLOW_SPEC_HASH_MAP& map (void); + // Returns the hash map of flowspecs indexed by flowspec name. + +private: + + // The Service Provider is currently set to NULL for all ACE_QoS. + static const iovec iov_; + + // A NO_TRAFFIC flow spec. Senders set the receiving qos to this + // while the receivers set the sending qos to this. + ACE_Flow_Spec *default_traffic_; + + // A list of flowspecs indexed by the flowspec name. + FLOW_SPEC_HASH_MAP flow_spec_map_; +}; + +#endif /* FILL_ACE_QOS_H */ diff --git a/ACE/examples/QOS/Simple/FlowSpec_Dbase.h b/ACE/examples/QOS/Simple/FlowSpec_Dbase.h new file mode 100644 index 00000000000..fc382048c13 --- /dev/null +++ b/ACE/examples/QOS/Simple/FlowSpec_Dbase.h @@ -0,0 +1,52 @@ +/* -*- C++ -*- */ +//$Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// FlowSpec_Dbase.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef FLOWSPEC_DBASE_H +#define FLOWSPEC_DBASE_H + +// This file contains the different FlowSpecs that the QoS enabled +// application uses. Its a good idea to list them all here so the +// application code is clean. + +ACE_Flow_Spec notraffic (ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + ACE_SERVICETYPE_NOTRAFFIC, + ACE_QOS_NOT_SPECIFIED, + ACE_QOS_NOT_SPECIFIED, + 25, + 1); + +ACE_Flow_Spec g711 (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1); + +// The default session address is macarena.cs.wustl.edu. I am using macarena +// as my receiver for testing. +#define DEFAULT_QOS_SESSION_MACHINE "128.252.165.127" +#define DEFAULT_QOS_SESSION_PORT 8001 + +#endif /* FLOWSPEC_DBASE_H */ + diff --git a/ACE/examples/QOS/Simple/Makefile.am b/ACE/examples/QOS/Simple/Makefile.am new file mode 100644 index 00000000000..d86d7cd43eb --- /dev/null +++ b/ACE/examples/QOS/Simple/Makefile.am @@ -0,0 +1,76 @@ +## 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: +## /acebuilds/ACE_wrappers-repository/bin/mwc.pl -include /acebuilds/MPC/config -include /acebuilds/MPC/templates -feature_file /acebuilds/ACE_wrappers-repository/local.features -noreldefs -type automake -exclude build,Kokyu + +ACE_BUILDDIR = $(top_builddir) +ACE_ROOT = $(top_srcdir) + +noinst_PROGRAMS = + +## Makefile.QOS_Simple_Receiver.am + +if BUILD_QOS +noinst_PROGRAMS += receiver + +receiver_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +receiver_SOURCES = \ + Fill_ACE_QoS.cpp \ + QoS_Signal_Handler.cpp \ + QoS_Util.cpp \ + Receiver_QoS_Event_Handler.cpp \ + receiver.cpp \ + Fill_ACE_QoS.h \ + QoS_Signal_Handler.h \ + QoS_Util.h \ + Receiver_QoS_Event_Handler.h + +receiver_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_QOS + +## Makefile.QOS_Simple_Sender.am + +if BUILD_QOS +noinst_PROGRAMS += sender + +sender_CPPFLAGS = \ + -I$(ACE_ROOT) \ + -I$(ACE_BUILDDIR) \ + -DACE_HAS_QOS + +sender_SOURCES = \ + Fill_ACE_QoS.cpp \ + QoS_Signal_Handler.cpp \ + QoS_Util.cpp \ + Sender_QoS_Event_Handler.cpp \ + sender.cpp \ + Fill_ACE_QoS.h \ + QoS_Signal_Handler.h \ + QoS_Util.h \ + Sender_QoS_Event_Handler.h + +sender_LDADD = \ + $(ACE_BUILDDIR)/ace/QoS/libACE_QoS.la \ + $(ACE_BUILDDIR)/ace/libACE.la + +endif BUILD_QOS + +## 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/examples/QOS/Simple/QOS_Simple.mpc b/ACE/examples/QOS/Simple/QOS_Simple.mpc new file mode 100644 index 00000000000..9767bd6fdb9 --- /dev/null +++ b/ACE/examples/QOS/Simple/QOS_Simple.mpc @@ -0,0 +1,25 @@ +// -*- MPC -*- +// $Id$ + +project(*receiver) : aceexe, qos { + exename = receiver + requires += qos + Source_Files { + Fill_ACE_QoS.cpp + QoS_Signal_Handler.cpp + QoS_Util.cpp + receiver.cpp + Receiver_QoS_Event_Handler.cpp + } +} +project(*sender) : aceexe, qos { + exename = sender + requires += qos + Source_Files { + Fill_ACE_QoS.cpp + QoS_Signal_Handler.cpp + QoS_Util.cpp + sender.cpp + Sender_QoS_Event_Handler.cpp + } +} diff --git a/ACE/examples/QOS/Simple/QoS_Signal_Handler.cpp b/ACE/examples/QOS/Simple/QoS_Signal_Handler.cpp new file mode 100644 index 00000000000..a0533bacdbc --- /dev/null +++ b/ACE/examples/QOS/Simple/QoS_Signal_Handler.cpp @@ -0,0 +1,40 @@ +// QoS_Signal_Handler.cpp +// $Id$ + +#include "ace/Log_Msg.h" +#include "QoS_Signal_Handler.h" + +ACE_RCSID(QOS, QoS_Signal_Handler,"$Id$") + +// constructor. +QoS_Signal_Handler::QoS_Signal_Handler (ACE_QoS_Session *qos_session) + : qos_session_ (qos_session) +{ +} + +// Releases the QoS sessions gracefully. +int +QoS_Signal_Handler::handle_signal (int signum, siginfo_t *, ucontext_t*) +{ + + ACE_DEBUG ((LM_DEBUG, + "QoS_Signal_Handler::handle_signal\n")); + + if (signum == SIGINT) + { + ACE_DEBUG ((LM_DEBUG, + "QoS_Signal_Handler::handle_signal SIGINT called\n")); + if (this->qos_session_->close () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to close the QoS session.\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS Session with id %d closed successfully.\n", + this->qos_session_->session_id ())); + } + else + ACE_DEBUG ((LM_DEBUG, + "A signal other than SIGINT received.\nIgnoring.\n")); + return 0; +} diff --git a/ACE/examples/QOS/Simple/QoS_Signal_Handler.h b/ACE/examples/QOS/Simple/QoS_Signal_Handler.h new file mode 100644 index 00000000000..35b9f3a19e7 --- /dev/null +++ b/ACE/examples/QOS/Simple/QoS_Signal_Handler.h @@ -0,0 +1,45 @@ +/* -*- C++ -*- */ +// $Id$ + +// ===================================================================== +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// QoS_Signal_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ===================================================================== + +#ifndef QOS_SIGNAL_HANDLER_H +#define QOS_SIGNAL_HANDLER_H + +#include "ace/Event_Handler.h" +#include "ace/QoS/QoS_Session.h" + +class QoS_Signal_Handler : public ACE_Event_Handler +{ + // TITLE + // This class Handles the SIGINT signal through the Reactor. + // Useful to gracefully release QoS sessions. + +public: + + QoS_Signal_Handler (ACE_QoS_Session *qos_session); + // constructor. + + int handle_signal(int signum, siginfo_t*,ucontext_t*); + // Override this method to implement graceful shutdown. + +private: + + ACE_QoS_Session *qos_session_; + // Session to be gracefully shutdown. + +}; + +#endif /* QOS_SIGNAL_HANDLER_H */ + diff --git a/ACE/examples/QOS/Simple/QoS_Util.cpp b/ACE/examples/QOS/Simple/QoS_Util.cpp new file mode 100644 index 00000000000..0ef3b353248 --- /dev/null +++ b/ACE/examples/QOS/Simple/QoS_Util.cpp @@ -0,0 +1,122 @@ +// QoS_Session_Impl.cpp +// $Id$ + +#define SENDER_PORT 10001 + +#include "ace/Log_Msg.h" +#include "ace/Get_Opt.h" +#include "QoS_Util.h" +#include "ace/OS_NS_strings.h" + +ACE_RCSID(QOS, QoS_Util,"$Id$") + +// constructor. +QoS_Util::QoS_Util (int argc, + ACE_TCHAR *argv[]) + : argc_ (argc), + argv_ (argv), + source_port_ (SENDER_PORT), + protocol_ (IPPROTO_UDP), + multicast_flag_ (0) +{ + ACE_NEW (this->mult_session_addr_, + ACE_INET_Addr (ACE_DEFAULT_MULTICAST_PORT)); + + ACE_NEW (this->dest_addr_, + ACE_INET_Addr (ACE_DEFAULT_SERVER_PORT)); +} + +// destructor. +QoS_Util::~QoS_Util (void) +{ + delete this->mult_session_addr_; + delete this->dest_addr_; +} + +int +QoS_Util::parse_args (void) +{ + ACE_Get_Opt get_opts (this->argc_, this->argv_, ACE_TEXT("m:n:p:P:c")); + int c = 0; + + while ((c = get_opts ()) != -1) + switch (c) + { + case 'm': // multicast session address. + this->multicast_flag_ = 1; + this->mult_session_addr_->set (get_opts.opt_arg ()); + break; + case 'n': // to be used by Senders only to specify the destination. + this->dest_addr_->set (get_opts.opt_arg ()); + break; + case 'p': // protocol. + if (ACE_OS::strcasecmp (get_opts.opt_arg (), ACE_TEXT("tcp")) == 0) + this->protocol_ = IPPROTO_TCP; + else + if (ACE_OS::strcasecmp (get_opts.opt_arg (), ACE_TEXT("udp")) == 0) + this->protocol_ = IPPROTO_UDP; + else + ACE_DEBUG ((LM_DEBUG, + "Unknown protocol specified\n" + "UDP assumed\n")); + break; + case 'P': // sender source port. + this->source_port_ = ACE_OS::atoi (get_opts.opt_arg ()); + break; + case 'h': // display help for different options. + default: + ACE_ERROR_RETURN ((LM_ERROR, + "usage: %s" + " [-m host:port] QoS multicast session address" + " Overides the receiver address specified in the -n option" + " [-n host:port] Use for a unicast sender. " + " Follow by receiver addr" + " [-p tcp|udp] specify protocol to be used" + " [-P port] source sender port" + " [-h] <help>" + "\n", + argv_ [0]), + -1); + } + + // If multicast address is specified then ignore the unicast sender + // destination address and force the protocol to be UDP. + if (this->multicast_flag_ == 1) + { + this->dest_addr_ = this->mult_session_addr_; + this->protocol_ = IPPROTO_UDP; + } + + // Indicates successful parsing of command line. + return 0; +} + +ACE_INET_Addr * +QoS_Util::mult_session_addr (void) const +{ + return this->mult_session_addr_; +} + +ACE_INET_Addr * +QoS_Util::dest_addr (void) const +{ + return this->dest_addr_; +} + +u_short +QoS_Util::source_port (void) const +{ + return this->source_port_; +} + +ACE_Protocol_ID +QoS_Util::protocol (void) const +{ + return this->protocol_; +} + +int +QoS_Util::multicast_flag (void) const +{ + return this->multicast_flag_; +} diff --git a/ACE/examples/QOS/Simple/QoS_Util.h b/ACE/examples/QOS/Simple/QoS_Util.h new file mode 100644 index 00000000000..ae347de68f6 --- /dev/null +++ b/ACE/examples/QOS/Simple/QoS_Util.h @@ -0,0 +1,75 @@ +/* -*- C++ -*- */ +// $Id$ + +// ===================================================================== +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// QoS_Util.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ===================================================================== + +#ifndef QOS_UTIL_H +#define QOS_UTIL_H + +#include "ace/INET_Addr.h" +#include "ace/QoS/QoS_Session.h" + +class QoS_Util +{ + // = TITLE + // This class provides the utility functions like parse_args () + // required by a QoS enabled application. + +public: + + // constructor. + QoS_Util (int argc, ACE_TCHAR *argv[]); + + // destructor. + ~QoS_Util (void); + + // Parse command-line arguments. + int parse_args (void); + + // GET methods. + ACE_INET_Addr *mult_session_addr (void) const; + + ACE_INET_Addr *dest_addr (void) const; + + u_short source_port (void) const; + + ACE_Protocol_ID protocol (void) const; + + int multicast_flag (void) const; + +private: + + // Command line arguments. + int argc_; + ACE_TCHAR **argv_; + + // Multicast session address. + ACE_INET_Addr *mult_session_addr_; + + // Unicast destination address of the receiver. + ACE_INET_Addr *dest_addr_; + + // Source port for the sender. + u_short source_port_; + + // Protocol. + ACE_Protocol_ID protocol_; + + // Multicast Flag. + int multicast_flag_; + +}; + +#endif /* QOS_UTIL_H */ + diff --git a/ACE/examples/QOS/Simple/README b/ACE/examples/QOS/Simple/README new file mode 100644 index 00000000000..13255842932 --- /dev/null +++ b/ACE/examples/QOS/Simple/README @@ -0,0 +1,142 @@ +//$Id$ + +A Regression test for ACE QoS features. +--------------------------------------- + +This test implements a simple Receiver-Sender program that ensures +Quality of Service (QoS) guarantees on the underlying network before +transmitting data. The program tests the ACE QoS APIs/features. The +test works for Winsock2 APIs on Win2K as well as RAPI on Solaris. + + +------------------------------------------------------------------------ +WIN2K : + +Build Requirements : +-------------------- +1. Two Win2K machines. +2. June98 Platform SDK or later. +3. Link with ws2_32.lib + +The test consists of a receiver and a sender. + + The sender is started first (though it is not mandatory) as : + + sender -m merengue.cs.wustl.edu:9091 -P 10004 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +The sample Sender is started next as : + + receiver -m merengue.cs.wustl.edu:9091 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -n: Option to be used by senders only to specify the destination + address. This option is overriden if a multicast address is also + specified through the -m option. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +On Win2K the user must have administrative access to the machine to +run this program. It seems to be a pre-requisite to opening QoS +sockets. + +The sender and receiver should be run on different Win2K machines. + +The test demonstrates how to GQOS enable an application using the ACE QoS APIs. +It concentrates on the use of various ACE QoS APIs and their correctness. + +------------------------------------------------------------------------------- + +RAPI : + +0. The $ACE_ROOT/include/makeinclude/platform_macros.GNU should include the +following : + +include /project/doc/vishal/ACE_wrappers/include/makeinclude/<appropriate platform macros file eg.platform_sunos5_sunc++.GNU> +PLATFORM_RAPI_CPPFLAGS += -I/project/doc/vishal/rapi/rel4.2a4/rsvpd/ +PLATFORM_RAPI_LIBS += -lrsvp +PLATFORM_RAPI_LDFLAGS += -L/project/doc/vishal/rapi/rel4.2a4/rsvpd/ + +assuming that RAPI library is installed in /project/doc/vishal/rapi/rel4.2a4/ + +1. Compile ACE with + + make rapi=1 + +2. Run the RSVP Daemon on two machines: (merengue.cs and macarena.cs) + + /project/doc/vishal/rapi/rel4.2a4/rsvpd/rsvpd -D + + The current version of the daemon comes with an inbuilt rtap + application to test the various reservation commands and RAPI APIs. + + Typical values for rtap would be : + + dest udp macarena/5000 + sender merengue/5000 [ t 2000000 100000 2000000 512 1024 ] + + dest udp macarena/5000 + reserve wf [ cl 2000000 100000 2000000 512 1024 ] + +3. If RTAP runs fine and the daemons show the debug messages about + RESV, PATH and other RSVP messages, run the QoS example, making sure + that rtap session is released on both machines. + +The test consists of a receiver and a sender. + + The sender is started first (though it is not mandatory) as : + + sender -m macarena.cs.wustl.edu:9091 -P 10004 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +The sample Sender is started next as : + + receiver -m macarena.cs.wustl.edu:9091 + + -m: specifies the multicast session address that both client and + server subscribe to for QoS events. + + -n: Option to be used by senders only to specify the destination + address. This option is overriden if a multicast address is also + specified through the -m option. + + -p: Protocol to be used. Could be udp or tcp. Default is udp. + + -P: Sender source port. If not specified, DEFAULT_SOURCE_SENDER_PORT + (10001) will be used. + + -h: Displays the help on various options. + +------------------------------------------------------------------------------- + +If you run into any problems with this test please contact Vishal +Kachroo <vishal@cs.wustl.edu>. + +This README last updated on 20th July, 2000. + +------------------------------------------------------------------------------- diff --git a/ACE/examples/QOS/Simple/Receiver_QoS_Event_Handler.cpp b/ACE/examples/QOS/Simple/Receiver_QoS_Event_Handler.cpp new file mode 100644 index 00000000000..69258313420 --- /dev/null +++ b/ACE/examples/QOS/Simple/Receiver_QoS_Event_Handler.cpp @@ -0,0 +1,137 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Receiver_QoS_Event_Handler.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#include "Receiver_QoS_Event_Handler.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_string.h" + +// Constructor. +Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (void) +{ +} + +Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session) + : dgram_mcast_qos_ (dgram_mcast_qos), + qos_session_ (qos_session) +{ +} + +// Destructor. +Receiver_QoS_Event_Handler::~Receiver_QoS_Event_Handler (void) +{ +} + +// Return the handle of the Dgram_Mcast. This method is called +// internally by the reactor. +ACE_HANDLE +Receiver_QoS_Event_Handler::get_handle (void) const +{ + return this->dgram_mcast_qos_.get_handle (); +} + +// Called when there is a READ activity on the dgram_mcast_qos handle. +int +Receiver_QoS_Event_Handler::handle_input (ACE_HANDLE) +{ + char buf[BUFSIZ]; + + iovec iov; + iov.iov_base = buf; + iov.iov_len = BUFSIZ; + + ACE_OS::memset (iov.iov_base, + 0, + BUFSIZ); + + ACE_DEBUG ((LM_DEBUG, + "Inside handle_input () of Receiver_QoS_Event_Handler ()\n")); + + // Receive message from multicast group. + ssize_t result = + this->dgram_mcast_qos_.recv (&iov, + 1, + this->remote_addr_); + + if (result != -1) + { + ACE_DEBUG ((LM_DEBUG, + "Message Received : %s", + iov.iov_base)); + return 0; + } + else + return -1; +} + +// Called when there is a QoS Event. +int +Receiver_QoS_Event_Handler::handle_qos (ACE_HANDLE fd) +{ + ACE_UNUSED_ARG (fd); + + ACE_DEBUG ((LM_DEBUG, + "\nReceived a QOS event. Inside handle_qos ()\n")); + + // We have received an RSVP event. The following update_qos () call + // calls rapi_dispatch () in case of RAPI and WSAIoctl (GET_QOS) in + // case of W2K. It then does the QoS parameter translation and updates + // the QoS session object with the latest QoS. This call replaces the + // direct call that was being made to WSAIoctl (GET_QOS) here for the + // Win2K example. + + if (this->qos_session_->update_qos () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in updating QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + " Updating QOS succeeds.\n")); + + // Now proactively query the QoS object for QoS. + ACE_QoS ace_get_qos = this->qos_session_->qos (); + + ACE_DEBUG ((LM_DEBUG, + "\nReceiving Flowspec :\t\t\tSending Flowspec :\n\n" + "\tToken Rate = %d\t\t\tToken Rate = %d\n" + "\tToken Bucket Size = %d\t\t\tToken Bucket Size = %d\n" + "\tPeak Bandwidth = %d\t\t\tPeak Bandwidth = %d\n" + "\tLatency = %d\t\t\t\tLatency = %d\n" + "\tDelay Variation = %d\t\t\tDelay Variation = %d\n" + "\tService Type = %d\t\t\tService Type = %d\n" + "\tMax SDU Size = %d\t\t\tMax SDU Size = %d\n" + "\tMinimum Policed Size = %d\t\tMinimum Policed Size = %d\n\n", + ace_get_qos.receiving_flowspec ()->token_rate (), + ace_get_qos.sending_flowspec ()->token_rate (), + ace_get_qos.receiving_flowspec ()->token_bucket_size (), + ace_get_qos.sending_flowspec ()->token_bucket_size (), + ace_get_qos.receiving_flowspec ()->peak_bandwidth (), + ace_get_qos.sending_flowspec ()->peak_bandwidth (), + ace_get_qos.receiving_flowspec ()->latency (), + ace_get_qos.sending_flowspec ()->latency (), + ace_get_qos.receiving_flowspec ()->delay_variation (), + ace_get_qos.sending_flowspec ()->delay_variation (), + ace_get_qos.receiving_flowspec ()->service_type (), + ace_get_qos.sending_flowspec ()->service_type (), + ace_get_qos.receiving_flowspec ()->max_sdu_size (), + ace_get_qos.sending_flowspec ()->max_sdu_size (), + ace_get_qos.receiving_flowspec ()->minimum_policed_size (), + ace_get_qos.sending_flowspec ()->minimum_policed_size ())); + + return 0; + +} diff --git a/ACE/examples/QOS/Simple/Receiver_QoS_Event_Handler.h b/ACE/examples/QOS/Simple/Receiver_QoS_Event_Handler.h new file mode 100644 index 00000000000..874d628e3c1 --- /dev/null +++ b/ACE/examples/QOS/Simple/Receiver_QoS_Event_Handler.h @@ -0,0 +1,61 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Receiver_QoS_Event_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef RECEIVER_QOS_EVENT_HANDLER_H +#define RECEIVER_QOS_EVENT_HANDLER_H + +#include "ace/Reactor.h" +#include "ace/INET_Addr.h" +#include "ace/Event_Handler.h" +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +ACE_RCSID(Receiver_QoS_Event_Handler, Receiver_QoS_Event_Handler, "$Id$") + + class Receiver_QoS_Event_Handler : public ACE_Event_Handler + { + public: + // = Initialization and Termination methods. + Receiver_QoS_Event_Handler (void); + // Constructor. + + Receiver_QoS_Event_Handler::Receiver_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS &dgram_mcast_qos, + ACE_QoS_Session *qos_session); + // Constructor. + + ~Receiver_QoS_Event_Handler (void); + // Destructor. + + virtual ACE_HANDLE get_handle (void) const; + // Override this to return the handle of the Dgram_Mcast + // that we are using. + + virtual int handle_input (ACE_HANDLE fd); + // Handles a READ event. + + virtual int handle_qos (ACE_HANDLE fd); + // Handles a QoS event. + + private: + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos_; + ACE_QoS_Session *qos_session_; + ACE_INET_Addr remote_addr_; + }; + +#endif /* RECEIVER_QOS_EVENT_HANDLER_H */ + + + diff --git a/ACE/examples/QOS/Simple/Sender_QoS_Event_Handler.cpp b/ACE/examples/QOS/Simple/Sender_QoS_Event_Handler.cpp new file mode 100644 index 00000000000..5ee4ccf0f8e --- /dev/null +++ b/ACE/examples/QOS/Simple/Sender_QoS_Event_Handler.cpp @@ -0,0 +1,144 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Sender_QoS_Event_Handler.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#include "Sender_QoS_Event_Handler.h" +#include "ace/Log_Msg.h" +#include "ace/OS_NS_string.h" + +// Constructor. +Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (void) +{ +} + +// Constructor. +Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session) + : dgram_mcast_qos_ (dgram_mcast_qos), + qos_session_ (qos_session) +{ +} + +// Destructor. +Sender_QoS_Event_Handler::~Sender_QoS_Event_Handler (void) +{ +} + +// Return the handle of the Dgram_Mcast. This method is called +// internally by the reactor. + +ACE_HANDLE +Sender_QoS_Event_Handler::get_handle (void) const +{ + return this->dgram_mcast_qos_.get_handle (); +} + +// Handle the QoS Event. In this case send data to the receiver +// using WSASendTo() that uses overlapped I/O. + +int +Sender_QoS_Event_Handler::handle_qos (ACE_HANDLE) +{ + ACE_DEBUG ((LM_DEBUG, + "\nReceived a QOS event. Inside handle_qos ()\n")); + + // We have received an RSVP event. The following update_qos () call + // calls rapi_dispatch () in case of RAPI and WSAIoctl (GET_QOS) in + // case of W2K. It then does the QoS parameter translation and updates + // the QoS session object with the latest QoS. This call replaces the + // direct call that was being made to WSAIoctl (GET_QOS) here for the + // Win2K example. + + if (this->qos_session_->update_qos () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in updating QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + " Updating QOS succeeds.\n")); + + // Now proactively query the QoS object for QoS. + ACE_QoS ace_get_qos = this->qos_session_->qos (); + + ACE_DEBUG ((LM_DEBUG, + "\nReceiving Flowspec :\t\t\tSending Flowspec :\n\n" + "\tToken Rate = %d\t\t\tToken Rate = %d\n" + "\tToken Bucket Size = %d\t\t\tToken Bucket Size = %d\n" + "\tPeak Bandwidth = %d\t\t\tPeak Bandwidth = %d\n" + "\tLatency = %d\t\t\t\tLatency = %d\n" + "\tDelay Variation = %d\t\t\tDelay Variation = %d\n" + "\tService Type = %d\t\t\tService Type = %d\n" + "\tMax SDU Size = %d\t\t\tMax SDU Size = %d\n" + "\tMinimum Policed Size = %d\t\tMinimum Policed Size = %d\n\n", + ace_get_qos.receiving_flowspec ()->token_rate (), + ace_get_qos.sending_flowspec ()->token_rate (), + ace_get_qos.receiving_flowspec ()->token_bucket_size (), + ace_get_qos.sending_flowspec ()->token_bucket_size (), + ace_get_qos.receiving_flowspec ()->peak_bandwidth (), + ace_get_qos.sending_flowspec ()->peak_bandwidth (), + ace_get_qos.receiving_flowspec ()->latency (), + ace_get_qos.sending_flowspec ()->latency (), + ace_get_qos.receiving_flowspec ()->delay_variation (), + ace_get_qos.sending_flowspec ()->delay_variation (), + ace_get_qos.receiving_flowspec ()->service_type (), + ace_get_qos.sending_flowspec ()->service_type (), + ace_get_qos.receiving_flowspec ()->max_sdu_size (), + ace_get_qos.sending_flowspec ()->max_sdu_size (), + ace_get_qos.receiving_flowspec ()->minimum_policed_size (), + ace_get_qos.sending_flowspec ()->minimum_policed_size ())); + + // This is SPECIFIC TO WIN2K and should be done in the qos_update function. + +// ACE_QoS ace_get_qos; +// u_long dwBytes; + +// if (ACE_OS::ioctl (this->dgram_mcast_qos_.get_handle (), +// ACE_SIO_GET_QOS, +// ace_get_qos, +// &dwBytes) == -1) +// ACE_ERROR ((LM_ERROR, +// "Error in Qos get ACE_OS::ioctl ()\n" +// "Bytes Returned = %d\n", +// dwBytes)); +// else +// ACE_DEBUG ((LM_DEBUG, +// "Getting QOS using ACE_OS::ioctl () succeeds.\n")); + + char* msg = "Hello sent on a QoS enabled session !!\n"; + iovec iov[1]; + iov[0].iov_base = msg; + iov[0].iov_len = ACE_OS::strlen(msg); + + size_t bytes_sent = 0; + + // Send "Hello" to the QoS session address to which the receiver has + // subscribed. + if (this->dgram_mcast_qos_.send (iov, + 1, + bytes_sent, + 0, + this->qos_session_->dest_addr (), + 0, + 0) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in dgram_mcast.send ()\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Using ACE_OS::sendto () : Bytes sent : %d", + bytes_sent)); + return 0; +} diff --git a/ACE/examples/QOS/Simple/Sender_QoS_Event_Handler.h b/ACE/examples/QOS/Simple/Sender_QoS_Event_Handler.h new file mode 100644 index 00000000000..b691bbd0615 --- /dev/null +++ b/ACE/examples/QOS/Simple/Sender_QoS_Event_Handler.h @@ -0,0 +1,61 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// Sender_QoS_Event_Handler.h +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#ifndef SENDER_QOS_EVENT_HANDLER_H +#define SENDER_QOS_EVENT_HANDLER_H + +#include "ace/Event_Handler.h" +#include "ace/Reactor.h" +#include "ace/INET_Addr.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" +#include "ace/QoS/QoS_Session.h" + +//#define MY_DEFPORT 5001 +//#define DEFAULT_MULTICASTGROUP "234.5.6.7" + +ACE_RCSID(Sender_QoS_Event_Handler, Sender_QoS_Event_Handler, "$Id$") + +class Sender_QoS_Event_Handler : public ACE_Event_Handler +{ +public: + // = Initialization and Termination methods. + Sender_QoS_Event_Handler (void); + // Constructor. + + Sender_QoS_Event_Handler::Sender_QoS_Event_Handler (const ACE_SOCK_Dgram_Mcast_QoS + &dgram_mcast_qos, + ACE_QoS_Session *qos_session + ); + // Constructor. + + ~Sender_QoS_Event_Handler (void); + // Destructor. + + virtual ACE_HANDLE get_handle (void) const; + // Override this to return the handle of the Dgram_Mcast + // that we are using. + + virtual int handle_qos (ACE_HANDLE fd); + // Handles a QoS event. Right now, just + // prints a message. + +private: + + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos_; + ACE_QoS_Session *qos_session_; +}; + +#endif /* SENDER_QOS_EVENT_HANDLER_H */ diff --git a/ACE/examples/QOS/Simple/receiver.cpp b/ACE/examples/QOS/Simple/receiver.cpp new file mode 100644 index 00000000000..72381d64f69 --- /dev/null +++ b/ACE/examples/QOS/Simple/receiver.cpp @@ -0,0 +1,301 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// server.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + +#define QOSEVENT_MAIN + +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/QoS_Session_Factory.h" +#include "ace/QoS/QoS_Decorator.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +#include "QoS_Util.h" +#include "Fill_ACE_QoS.h" +#include "QoS_Signal_Handler.h" +#include "Receiver_QoS_Event_Handler.h" + +// To open QOS sockets administrative access is required on the +// machine. Fill in default values for QoS structure. The default +// values were simply choosen from existing QOS templates available +// via WSAGetQosByName. Notice that ProviderSpecific settings are +// being allowed when picking the "default" template but not for +// "well-known" QOS templates. Also notice that since data is only +// flowing from sender to receiver, different flowspecs are filled in +// depending upon whether this application is acting as a sender or +// receiver. + + +// This function fills up the ACE_QoS_Params with the supplied iovec +// and ACE_QoS. + +int +FillQoSParams (ACE_QoS_Params &qos_params, + iovec* iov, + ACE_QoS* qos) +{ + qos_params.callee_data (iov); + qos_params.caller_data (0); + qos_params.socket_qos (qos); + qos_params.group_socket_qos (0); + qos_params.flags (ACE_JL_BOTH); + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + + QoS_Util qos_util(argc, argv); + + if (qos_util.parse_args () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in parsing args\n"), + -1); + + // This is a multicast application. + if (qos_util.multicast_flag ()) + { + Fill_ACE_QoS fill_ace_qos; + + // The application adds the flow specs that it wants into the + // Fill_ACE_QoS. The Fill_ACE_QoS indexes the flow specs by the + // flow spec names. Here the new flowspec being added is g_711. + ACE_CString g_711 ("g_711"); + + switch (fill_ace_qos.map ().bind (g_711, + new ACE_Flow_Spec (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + ACE_DEBUG ((LM_DEBUG, + "g_711 Flow Spec bound successfully\n")); + + // This is a receiver. So we fill in the receiving QoS parameters. + ACE_QoS ace_qos_receiver; + if (fill_ace_qos.fill_simplex_receiver_qos (ace_qos_receiver, + g_711) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill simplex receiver qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Filled up the Receiver QoS parameters\n")); + + // Opening a new Multicast Datagram. + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos; + + // Multicast Session Address specified by user at command line. + // If this address is not specified, + // <localhost:ACE_DEFAULT_MULTICAST_PORT> is assumed. + ACE_INET_Addr mult_addr (*(qos_util.mult_session_addr ())); + + // Fill the ACE_QoS_Params to be passed to the <ACE_OS::join_leaf> + // through subscribe. + + ACE_QoS_Params qos_params; + FillQoSParams (qos_params, 0, &ace_qos_receiver); + + // Create a QoS Session Factory. + ACE_QoS_Session_Factory session_factory; + + // Ask the factory to create a QoS session. This could be RAPI or + // GQoS based on the parameter passed. + ACE_QoS_Session *qos_session = + session_factory.create_session (); + + // Create a destination address for the QoS session. The same + // address should be used for the subscribe call later. A copy + // is made below only to distinguish the two usages of the dest + // address. + + ACE_INET_Addr dest_addr (mult_addr); + + // A QoS session is defined by the 3-tuple [DestAddr, DestPort, + // Protocol]. Initialize the QoS session. + if (qos_session->open (mult_addr, + IPPROTO_UDP) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in opening the QoS session\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS session opened successfully\n")); + + // The following call opens the Dgram_Mcast and calls the + // <ACE_OS::join_leaf> with the qos_params supplied here. Note + // the QoS session object is passed into this call. This + // subscribes the underlying socket to the passed in QoS + // session. For joining multiple multicast sessions, the + // following subscribe call should be made with different + // multicast addresses and a new QoS session object should be + // passed in for each such call. The QoS session objects can be + // created only through the session factory. Care should be + // taken that the mult_addr for the subscribe() call matches the + // dest_addr of the QoS session object. If this is not done, the + // subscribe call will fail. A more abstract version of + // subscribe will be added that constrains the various features + // of GQoS like different flags etc. + + if (dgram_mcast_qos.subscribe (mult_addr, + qos_params, + 1, + 0, + AF_INET, + // ACE_FROM_PROTOCOL_INFO, + 0, + 0, // ACE_Protocol_Info, + 0, + ACE_OVERLAPPED_SOCKET_FLAG + | ACE_FLAG_MULTIPOINT_C_LEAF + | ACE_FLAG_MULTIPOINT_D_LEAF, + qos_session) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in subscribe\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Dgram_Mcast subscribe succeeds \n")); + + int nIP_TTL = 25; + char achInBuf [BUFSIZ]; + u_long dwBytes; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTICAST_SCOPE, // IO control code. + &nIP_TTL, // In buffer. + sizeof (nIP_TTL), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Multicast scope ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Setting TTL with Multicast scope ACE_OS::ioctl call succeeds \n")); + + int bFlag = 0; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTIPOINT_LOOPBACK, // IO control code. + &bFlag, // In buffer. + sizeof (bFlag), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Loopback ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Disable Loopback with ACE_OS::ioctl call succeeds \n")); + + // This is a receiver. + qos_session->flags (ACE_QoS_Session::ACE_QOS_RECEIVER); + + ACE_QoS_Manager qos_manager = dgram_mcast_qos.qos_manager (); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (qos_session->qos (&dgram_mcast_qos, + &qos_manager, + ace_qos_receiver) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + + // Register a signal handler that helps to gracefully close the + // open QoS sessions. + QoS_Signal_Handler qos_signal_handler (qos_session); + + // Register the usual SIGINT signal handler with the Reactor for + // the application to gracefully release the QoS session and + // shutdown. + if (ACE_Reactor::instance ()->register_handler + (SIGINT, &qos_signal_handler) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Signal Handler.\n"), + -1); + + // Handler to process QoS and Data events for the reciever. + Receiver_QoS_Event_Handler qos_event_handler (dgram_mcast_qos, + qos_session); + + // Decorate the above handler with QoS functionality. + ACE_QoS_Decorator qos_decorator (&qos_event_handler, + qos_session); + + // Initialize the Decorator. + if (qos_decorator.init () != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "QoS Decorator init () failed.\n"), + -1); + + // Register the decorated Event Handler with the Reactor. + if (ACE_Reactor::instance ()->register_handler (&qos_decorator, + ACE_Event_Handler::QOS_MASK | + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Decorator with the Reactor\n"), + -1); + + + // Start the event loop. + ACE_DEBUG ((LM_DEBUG, + "Running the Event Loop ... \n")); + + ACE_Reactor::instance ()->run_event_loop (); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) shutting down server logging daemon\n")); + } + else + ACE_DEBUG ((LM_DEBUG, + "Specify a -m option for multicast application\n")); + return 0; +} + + + diff --git a/ACE/examples/QOS/Simple/sender.cpp b/ACE/examples/QOS/Simple/sender.cpp new file mode 100644 index 00000000000..97e6aafa407 --- /dev/null +++ b/ACE/examples/QOS/Simple/sender.cpp @@ -0,0 +1,315 @@ +/* -*- C++ -*- */ +// $Id$ + +// ============================================================================ +// +// = LIBRARY +// ACE_wrappers/examples/QOS +// +// = FILENAME +// client.cpp +// +// = AUTHOR +// Vishal Kachroo <vishal@cs.wustl.edu> +// +// ============================================================================ + + +#include "ace/QoS/QoS_Session.h" +#include "ace/QoS/QoS_Session_Factory.h" +#include "ace/QoS/QoS_Session_Impl.h" +#include "ace/QoS/QoS_Decorator.h" +#include "ace/QoS/SOCK_Dgram_Mcast_QoS.h" + +#include "QoS_Util.h" +#include "Fill_ACE_QoS.h" +#include "QoS_Signal_Handler.h" +#include "Sender_QoS_Event_Handler.h" + +// To open QOS sockets administrative access is required on the +// machine. Fill in default values for QoS structure. The default +// values were simply choosen from existing QOS templates available +// via WSAGetQosByName. Notice that ProviderSpecific settings are +// being allowed when picking the "default" template but not for +// "well-known" QOS templates. Also notice that since data is only +// flowing from sender to receiver, different flowspecs are filled in +// depending upon whether this application is acting as a sender or +// receiver. + +// This function fills up the ACE_QoS_Params with the supplied iovec and ACE_QoS. + +int +FillQoSParams (ACE_QoS_Params &qos_params, + iovec* iov, + ACE_QoS* qos) +{ + qos_params.callee_data (iov); + qos_params.caller_data (0); + qos_params.socket_qos (qos); + qos_params.group_socket_qos (0); + qos_params.flags (ACE_JL_BOTH); + + return 0; +} + +int +ACE_TMAIN (int argc, ACE_TCHAR * argv[]) +{ + + ACE_DEBUG ((LM_DEBUG, + "Sender\n")); + + QoS_Util qos_util(argc, argv); + + if (qos_util.parse_args () == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in parsing args\n"), + -1); + + // This is a multicast application. + if (qos_util.multicast_flag ()) + { + Fill_ACE_QoS fill_ace_qos; + + // The application adds the flow specs that it wants into the + // Fill_ACE_QoS. The Fill_ACE_QoS indexes the flow specs by the flow + // spec names. Here the new flowspec being added is g_711. + ACE_CString g_711 ("g_711"); + + switch (fill_ace_qos.map ().bind (g_711, + new ACE_Flow_Spec (9200, + 708, + 18400, + 0, + 0, + ACE_SERVICETYPE_CONTROLLEDLOAD, + 368, + 368, + 25, + 1))) + { + case 1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n" + "The Flow Spec name already exists\n"), + -1); + break; + case -1 : + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to bind the new flow spec\n"), + -1); + break; + } + + ACE_DEBUG ((LM_DEBUG, + "g_711 Flow Spec bound successfully\n")); + + // This is a sender. So we fill in the sending QoS parameters. + ACE_QoS ace_qos_sender; + + if (fill_ace_qos.fill_simplex_sender_qos (ace_qos_sender, + g_711) !=0) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to fill simplex sender qos\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Filled up the Sender QoS parameters\n")); + + // Opening a new Multicast Datagram. It is absolutely necessary that + // the sender and the receiver subscribe to the same multicast + // addresses to make sure the "multicast sessions" for the two are + // the same. This is used to match the RESV<->PATH states. + ACE_SOCK_Dgram_Mcast_QoS dgram_mcast_qos; + + // Multicast Session Address specified by user at command line. + // If this address is not specified, + // <localhost:ACE_DEFAULT_MULTICAST_PORT> is assumed. + ACE_INET_Addr mult_addr (*(qos_util.mult_session_addr ())); + + // Fill the ACE_QoS_Params to be passed to the <ACE_OS::join_leaf> + // through subscribe. + + ACE_QoS_Params qos_params; + FillQoSParams (qos_params, 0, &ace_qos_sender); + + // Create a QoS Session Factory. + ACE_QoS_Session_Factory session_factory; + + // Ask the factory to create a QoS session. + ACE_QoS_Session *qos_session = + session_factory.create_session (); + + // Create a destination address for the QoS session. The same + // address should be used for the subscribe call later. A copy is + // made below only to distinguish the two usages of the dest + // address. + + ACE_INET_Addr dest_addr (mult_addr); + + // A QoS session is defined by the 3-tuple [DestAddr, DestPort, + // Protocol]. Initialize the QoS session. + if (qos_session->open (mult_addr, + IPPROTO_UDP) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in opening the QoS session\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "QoS session opened successfully\n")); + + // The following call opens the Dgram_Mcast and calls the + // <ACE_OS::join_leaf> with the qos_params supplied here. Note the + // QoS session object is passed into this call. This subscribes the + // underlying socket to the passed in QoS session. For joining + // multiple multicast sessions, the following subscribe call should + // be made with different multicast addresses and a new QoS session + // object should be passed in for each such call. The QoS session + // objects can be created only through the session factory. Care + // should be taken that the mult_addr for the subscribe() call + // matches the dest_addr of the QoS session object. If this is not + // done, the subscribe call will fail. A more abstract version of + // subscribe will be added that constrains the various features of + // GQoS like different flags etc. + + if (dgram_mcast_qos.subscribe (mult_addr, + qos_params, + 1, + 0, + AF_INET, + // ACE_FROM_PROTOCOL_INFO, + 0, + 0, // ACE_Protocol_Info, + 0, + ACE_OVERLAPPED_SOCKET_FLAG + | ACE_FLAG_MULTIPOINT_C_LEAF + | ACE_FLAG_MULTIPOINT_D_LEAF, + qos_session) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in subscribe\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Dgram_Mcast subscribe succeeds \n")); + + int nIP_TTL = 25; + char achInBuf [BUFSIZ]; + u_long dwBytes; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTICAST_SCOPE, // IO control code. + &nIP_TTL, // In buffer. + sizeof (nIP_TTL), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Multicast scope ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Setting TTL with Multicast scope ACE_OS::ioctl call succeeds \n")); + + int bFlag = 0; + + // Should this be abstracted into QoS objects ?? Doesnt seem to have + // to do anything directly with QoS. + if (ACE_OS::ioctl (dgram_mcast_qos.get_handle (), // Socket. + ACE_SIO_MULTIPOINT_LOOPBACK, // IO control code. + &bFlag, // In buffer. + sizeof (bFlag), // Length of in buffer. + achInBuf, // Out buffer. + BUFSIZ, // Length of Out buffer. + &dwBytes, // bytes returned. + 0, // Overlapped. + 0) == -1) // Func. + ACE_ERROR ((LM_ERROR, + "Error in Loopback ACE_OS::ioctl() \n")); + else + ACE_DEBUG ((LM_DEBUG, + "Disable Loopback with ACE_OS::ioctl call succeeds \n")); + + // This is a sender. + qos_session->flags (ACE_QoS_Session::ACE_QOS_SENDER); + + ACE_QoS_Manager qos_manager = dgram_mcast_qos.qos_manager (); + + // Since we are using RSVP, it is imperative that the client + // application have the option of supplying the source sender + // port for the RSVP messages. A default will be chosen by the + // ACE API if this is not done. + qos_session->source_port (qos_util.source_port ()); + + // Set the QoS for the session. Replaces the ioctl () call that + // was being made previously. + if (qos_session->qos (&dgram_mcast_qos, + &qos_manager, + ace_qos_sender) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Unable to set QoS\n"), + -1); + else + ACE_DEBUG ((LM_DEBUG, + "Setting QOS succeeds.\n")); + + // Register a signal handler that helps to gracefully close the open + // QoS sessions. + QoS_Signal_Handler qos_signal_handler (qos_session); + + // Register the usual SIGINT signal handler with the Reactor for + // the application to gracefully release the QoS session and + // shutdown. + if (ACE_Reactor::instance ()->register_handler + (SIGINT, &qos_signal_handler) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Signal Handler.\n"), + -1); + + // Handler to process QoS and Data events for the reciever. + Sender_QoS_Event_Handler qos_event_handler (dgram_mcast_qos, + qos_session); + + // Decorate the above handler with QoS functionality. + ACE_QoS_Decorator qos_decorator (&qos_event_handler, + qos_session); + + // Initialize the Decorator. + if (qos_decorator.init () != 0) + ACE_ERROR_RETURN ((LM_ERROR, + "QoS Decorator init () failed.\n"), + -1); + + // Register the decorated Event Handler with the Reactor. + if (ACE_Reactor::instance ()->register_handler (&qos_decorator, + ACE_Event_Handler::QOS_MASK | + ACE_Event_Handler::READ_MASK) == -1) + ACE_ERROR_RETURN ((LM_ERROR, + "Error in registering the Decorator with the Reactor\n"), + -1); + + + + // Start the event loop. + ACE_DEBUG ((LM_DEBUG, + "Running the Event Loop ... \n")); + + ACE_Reactor::instance ()->run_event_loop (); + + ACE_DEBUG ((LM_DEBUG, + "(%P|%t) shutting down server logging daemon\n")); + } + else + ACE_DEBUG ((LM_DEBUG, + "Specify a -m option for multicast application\n")); + return 0; +} + + + + + + + |