MulticastInst.cpp

Go to the documentation of this file.
00001 /*
00002  *
00003  *
00004  * Distributed under the OpenDDS License.
00005  * See: http://www.opendds.org/license.html
00006  */
00007 
00008 #include "MulticastInst.h"
00009 #include "MulticastLoader.h"
00010 #include "MulticastTransport.h"
00011 
00012 #include "dds/DCPS/transport/framework/TransportDefs.h"
00013 #include "dds/DCPS/transport/framework/NetworkAddress.h"
00014 
00015 #include "ace/Configuration.h"
00016 
00017 #include <iostream>
00018 #include <sstream>
00019 
00020 namespace {
00021 
00022 const bool DEFAULT_TO_IPV6(false);
00023 
00024 const u_short DEFAULT_PORT_OFFSET(49152);
00025 
00026 const char* DEFAULT_IPV4_GROUP_ADDRESS("224.0.0.128");
00027 const char* DEFAULT_IPV6_GROUP_ADDRESS("FF01::80");
00028 
00029 const bool DEFAULT_RELIABLE(true);
00030 
00031 const double DEFAULT_SYN_BACKOFF(2.0);
00032 const long DEFAULT_SYN_INTERVAL(250);
00033 const long DEFAULT_SYN_TIMEOUT(30000);
00034 
00035 const size_t DEFAULT_NAK_DEPTH(32);
00036 const long DEFAULT_NAK_INTERVAL(500);
00037 const long DEFAULT_NAK_DELAY_INTERVALS(4);
00038 const long DEFAULT_NAK_MAX(3);
00039 const long DEFAULT_NAK_TIMEOUT(30000);
00040 
00041 const unsigned char DEFAULT_TTL(1);
00042 const bool DEFAULT_ASYNC_SEND(false);
00043 
00044 } // namespace
00045 
00046 namespace OpenDDS {
00047 namespace DCPS {
00048 
00049 MulticastInst::MulticastInst(const std::string& name)
00050   : TransportInst("multicast", name),
00051     default_to_ipv6_(DEFAULT_TO_IPV6),
00052     port_offset_(DEFAULT_PORT_OFFSET),
00053     reliable_(DEFAULT_RELIABLE),
00054     syn_backoff_(DEFAULT_SYN_BACKOFF),
00055     nak_depth_(DEFAULT_NAK_DEPTH),
00056     nak_delay_intervals_(DEFAULT_NAK_DELAY_INTERVALS),
00057     nak_max_(DEFAULT_NAK_MAX),
00058     ttl_(DEFAULT_TTL),
00059 #if defined (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00060     rcv_buffer_size_(ACE_DEFAULT_MAX_SOCKET_BUFSIZ),
00061 #else
00062     // Use system default values.
00063     rcv_buffer_size_(0),
00064 #endif
00065     async_send_(DEFAULT_ASYNC_SEND)
00066 {
00067   default_group_address(this->group_address_);
00068 
00069   this->syn_interval_.msec(DEFAULT_SYN_INTERVAL);
00070   this->syn_timeout_.msec(DEFAULT_SYN_TIMEOUT);
00071 
00072   this->nak_interval_.msec(DEFAULT_NAK_INTERVAL);
00073   this->nak_timeout_.msec(DEFAULT_NAK_TIMEOUT);
00074 }
00075 
00076 int
00077 MulticastInst::load(ACE_Configuration_Heap& cf,
00078                     ACE_Configuration_Section_Key& sect)
00079 {
00080   TransportInst::load(cf, sect); // delegate to parent
00081 
00082   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("default_to_ipv6"),
00083                    this->default_to_ipv6_, bool)
00084 
00085   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("port_offset"),
00086                    this->port_offset_, u_short)
00087 
00088   ACE_TString group_address_s;
00089   GET_CONFIG_TSTRING_VALUE(cf, sect, ACE_TEXT("group_address"),
00090                            group_address_s)
00091   if (group_address_s.is_empty()) {
00092     // TODO: Passing 0 instead of transport id.  Does this cause complications?
00093     default_group_address(this->group_address_);
00094   } else {
00095     this->group_address_.set(group_address_s.c_str());
00096   }
00097 
00098   GET_CONFIG_STRING_VALUE(cf, sect, ACE_TEXT("local_address"),
00099                           this->local_address_);
00100 
00101   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("reliable"), this->reliable_, bool)
00102 
00103   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("syn_backoff"),
00104                    this->syn_backoff_, double)
00105 
00106   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("syn_interval"), this->syn_interval_)
00107 
00108   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("syn_timeout"), this->syn_timeout_)
00109 
00110   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_depth"),
00111                    this->nak_depth_, size_t)
00112 
00113   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("nak_interval"), this->nak_interval_)
00114 
00115   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_delay_intervals"),
00116                         this->nak_delay_intervals_, size_t)
00117 
00118   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_max"), this->nak_max_, size_t)
00119 
00120   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("nak_timeout"), this->nak_timeout_)
00121 
00122   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("ttl"), this->ttl_, unsigned char)
00123 
00124   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("rcv_buffer_size"),
00125                    this->rcv_buffer_size_, size_t)
00126 
00127 #if defined (ACE_WIN32) && defined (ACE_HAS_WIN32_OVERLAPPED_IO)
00128   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("async_send"), this->async_send_, bool)
00129 #endif
00130 
00131   return 0;
00132 }
00133 
00134 void
00135 MulticastInst::default_group_address(ACE_INET_Addr& group_address)
00136 {
00137   if (this->default_to_ipv6_) {
00138     group_address.set(this->port_offset_, DEFAULT_IPV6_GROUP_ADDRESS);
00139   } else {
00140     group_address.set(this->port_offset_, DEFAULT_IPV4_GROUP_ADDRESS);
00141   }
00142 }
00143 
00144 MulticastTransport*
00145 MulticastInst::new_impl(const TransportInst_rch& inst)
00146 {
00147   return new MulticastTransport(inst);
00148 }
00149 
00150 OPENDDS_STRING
00151 MulticastInst::dump_to_str()
00152 {
00153   std::ostringstream os;
00154   os << TransportInst::dump_to_str() << std::endl;
00155 
00156   os << formatNameForDump("group_address")       << this->group_address_.get_host_addr()
00157                                                            << ":" << this->group_address_.get_port_number() << std::endl;
00158   os << formatNameForDump("local_address")       << this->local_address_ << std::endl;
00159   os << formatNameForDump("default_to_ipv6")     << (this->default_to_ipv6_ ? "true" : "false") << std::endl;
00160   os << formatNameForDump("port_offset")         << this->port_offset_ << std::endl;
00161   os << formatNameForDump("reliable")            << (this->reliable_ ? "true" : "false") << std::endl;
00162   os << formatNameForDump("syn_backoff")         << this->syn_backoff_ << std::endl;
00163   os << formatNameForDump("syn_interval")        << this->syn_interval_.msec() << std::endl;
00164   os << formatNameForDump("syn_timeout")         << this->syn_timeout_.msec() << std::endl;
00165   os << formatNameForDump("nak_depth")           << this->nak_depth_ << std::endl;
00166   os << formatNameForDump("nak_interval")        << this->nak_interval_.msec() << std::endl;
00167   os << formatNameForDump("nak_delay_intervals") << this->nak_delay_intervals_ << std::endl;
00168   os << formatNameForDump("nak_max")             << this->nak_max_ << std::endl;
00169   os << formatNameForDump("nak_timeout")         << this->nak_timeout_.msec() << std::endl;
00170   os << formatNameForDump("ttl")                 << int(this->ttl_) << std::endl;
00171   os << formatNameForDump("rcv_buffer_size");
00172 
00173   if (this->rcv_buffer_size_ == 0) {
00174     os << "System Default Value" << std::endl;
00175   } else {
00176     os << this->rcv_buffer_size_ << std::endl;
00177   }
00178 
00179   os << formatNameForDump("async_send");
00180 
00181 #if defined (ACE_WIN32) && defined (ACE_HAS_WIN32_OVERLAPPED_IO)
00182   os << (this->async_send_ ? "true" : "false") << std::endl;
00183 #else
00184   os << "Not Supported on this Platform" << std::endl;
00185 #endif
00186   return OPENDDS_STRING(os.str());
00187 }
00188 
00189 size_t
00190 MulticastInst::populate_locator(OpenDDS::DCPS::TransportLocator& info) const
00191 {
00192   if (this->group_address_ != ACE_INET_Addr()) {
00193     NetworkAddress network_address(this->group_address_);
00194 
00195     ACE_OutputCDR cdr;
00196     cdr << network_address;
00197     cdr << ACE_OutputCDR::from_boolean (ACE_CDR::Boolean (this->is_reliable ()));
00198 
00199     const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length());
00200     char* buffer = const_cast<char*>(cdr.buffer()); // safe
00201 
00202     info.transport_type = "multicast";
00203     info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer));
00204     return 1;
00205   } else {
00206     return 0;
00207   }
00208 }
00209 
00210 } // namespace DCPS
00211 } // namespace OpenDDS

Generated on Fri Feb 12 20:05:24 2016 for OpenDDS by  doxygen 1.4.7