00001
00002
00003
00004
00005
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 }
00045
00046 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00047
00048 namespace OpenDDS {
00049 namespace DCPS {
00050
00051 MulticastInst::MulticastInst(const std::string& name)
00052 : TransportInst("multicast", name),
00053 default_to_ipv6_(DEFAULT_TO_IPV6),
00054 port_offset_(DEFAULT_PORT_OFFSET),
00055 reliable_(DEFAULT_RELIABLE),
00056 syn_backoff_(DEFAULT_SYN_BACKOFF),
00057 nak_depth_(DEFAULT_NAK_DEPTH),
00058 nak_delay_intervals_(DEFAULT_NAK_DELAY_INTERVALS),
00059 nak_max_(DEFAULT_NAK_MAX),
00060 ttl_(DEFAULT_TTL),
00061 #if defined (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00062 rcv_buffer_size_(ACE_DEFAULT_MAX_SOCKET_BUFSIZ),
00063 #else
00064
00065 rcv_buffer_size_(0),
00066 #endif
00067 async_send_(DEFAULT_ASYNC_SEND)
00068 {
00069 default_group_address(this->group_address_);
00070
00071 this->syn_interval_.msec(DEFAULT_SYN_INTERVAL);
00072 this->syn_timeout_.msec(DEFAULT_SYN_TIMEOUT);
00073
00074 this->nak_interval_.msec(DEFAULT_NAK_INTERVAL);
00075 this->nak_timeout_.msec(DEFAULT_NAK_TIMEOUT);
00076 }
00077
00078 int
00079 MulticastInst::load(ACE_Configuration_Heap& cf,
00080 ACE_Configuration_Section_Key& sect)
00081 {
00082 TransportInst::load(cf, sect);
00083
00084 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("default_to_ipv6"),
00085 this->default_to_ipv6_, bool)
00086
00087 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("port_offset"),
00088 this->port_offset_, u_short)
00089
00090 ACE_TString group_address_s;
00091 GET_CONFIG_TSTRING_VALUE(cf, sect, ACE_TEXT("group_address"),
00092 group_address_s)
00093 if (group_address_s.is_empty()) {
00094
00095 default_group_address(this->group_address_);
00096 } else {
00097 this->group_address_.set(group_address_s.c_str());
00098 }
00099
00100 GET_CONFIG_STRING_VALUE(cf, sect, ACE_TEXT("local_address"),
00101 this->local_address_);
00102
00103 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("reliable"), this->reliable_, bool)
00104
00105 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("syn_backoff"),
00106 this->syn_backoff_, double)
00107
00108 GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("syn_interval"), this->syn_interval_)
00109
00110 GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("syn_timeout"), this->syn_timeout_)
00111
00112 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_depth"),
00113 this->nak_depth_, size_t)
00114
00115 GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("nak_interval"), this->nak_interval_)
00116
00117 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_delay_intervals"),
00118 this->nak_delay_intervals_, size_t)
00119
00120 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_max"), this->nak_max_, size_t)
00121
00122 GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("nak_timeout"), this->nak_timeout_)
00123
00124 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("ttl"), this->ttl_, unsigned char)
00125
00126 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("rcv_buffer_size"),
00127 this->rcv_buffer_size_, size_t)
00128
00129 #if defined (ACE_WIN32) && defined (ACE_HAS_WIN32_OVERLAPPED_IO)
00130 GET_CONFIG_VALUE(cf, sect, ACE_TEXT("async_send"), this->async_send_, bool)
00131 #endif
00132
00133 return 0;
00134 }
00135
00136 void
00137 MulticastInst::default_group_address(ACE_INET_Addr& group_address)
00138 {
00139 if (this->default_to_ipv6_) {
00140 group_address.set(this->port_offset_, DEFAULT_IPV6_GROUP_ADDRESS);
00141 } else {
00142 group_address.set(this->port_offset_, DEFAULT_IPV4_GROUP_ADDRESS);
00143 }
00144 }
00145
00146 TransportImpl_rch
00147 MulticastInst::new_impl()
00148 {
00149 return make_rch<MulticastTransport>(ref(*this));
00150 }
00151
00152 OPENDDS_STRING
00153 MulticastInst::dump_to_str() const
00154 {
00155 std::ostringstream os;
00156 os << TransportInst::dump_to_str() << std::endl;
00157
00158 os << formatNameForDump("group_address") << this->group_address_.get_host_addr()
00159 << ":" << this->group_address_.get_port_number() << std::endl;
00160 os << formatNameForDump("local_address") << this->local_address_ << std::endl;
00161 os << formatNameForDump("default_to_ipv6") << (this->default_to_ipv6_ ? "true" : "false") << std::endl;
00162 os << formatNameForDump("port_offset") << this->port_offset_ << std::endl;
00163 os << formatNameForDump("reliable") << (this->reliable_ ? "true" : "false") << std::endl;
00164 os << formatNameForDump("syn_backoff") << this->syn_backoff_ << std::endl;
00165 os << formatNameForDump("syn_interval") << this->syn_interval_.msec() << std::endl;
00166 os << formatNameForDump("syn_timeout") << this->syn_timeout_.msec() << std::endl;
00167 os << formatNameForDump("nak_depth") << this->nak_depth_ << std::endl;
00168 os << formatNameForDump("nak_interval") << this->nak_interval_.msec() << std::endl;
00169 os << formatNameForDump("nak_delay_intervals") << this->nak_delay_intervals_ << std::endl;
00170 os << formatNameForDump("nak_max") << this->nak_max_ << std::endl;
00171 os << formatNameForDump("nak_timeout") << this->nak_timeout_.msec() << std::endl;
00172 os << formatNameForDump("ttl") << int(this->ttl_) << std::endl;
00173 os << formatNameForDump("rcv_buffer_size");
00174
00175 if (this->rcv_buffer_size_ == 0) {
00176 os << "System Default Value" << std::endl;
00177 } else {
00178 os << this->rcv_buffer_size_ << std::endl;
00179 }
00180
00181 os << formatNameForDump("async_send");
00182
00183 #if defined (ACE_WIN32) && defined (ACE_HAS_WIN32_OVERLAPPED_IO)
00184 os << (this->async_send_ ? "true" : "false") << std::endl;
00185 #else
00186 os << "Not Supported on this Platform" << std::endl;
00187 #endif
00188 return OPENDDS_STRING(os.str());
00189 }
00190
00191 size_t
00192 MulticastInst::populate_locator(OpenDDS::DCPS::TransportLocator& info) const
00193 {
00194 if (this->group_address_ != ACE_INET_Addr()) {
00195 NetworkAddress network_address(this->group_address_);
00196
00197 ACE_OutputCDR cdr;
00198 cdr << network_address;
00199 cdr << ACE_OutputCDR::from_boolean (ACE_CDR::Boolean (this->is_reliable ()));
00200
00201 const CORBA::ULong len = static_cast<CORBA::ULong>(cdr.total_length());
00202 char* buffer = const_cast<char*>(cdr.buffer());
00203
00204 info.transport_type = "multicast";
00205 info.data = TransportBLOB(len, len, reinterpret_cast<CORBA::Octet*>(buffer));
00206 return 1;
00207 } else {
00208 return 0;
00209 }
00210 }
00211
00212 }
00213 }
00214
00215 OPENDDS_END_VERSIONED_NAMESPACE_DECL