RtpsUdpInst.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 "RtpsUdpInst.h"
00009 #include "RtpsUdpLoader.h"
00010 #include "RtpsUdpTransport.h"
00011 
00012 #include "dds/DCPS/transport/framework/TransportDefs.h"
00013 #include "ace/Configuration.h"
00014 #include "dds/DCPS/RTPS/BaseMessageUtils.h"
00015 #include "dds/DCPS/transport/framework/NetworkAddress.h"
00016 #include "dds/DCPS/Service_Participant.h"
00017 
00018 #include <cstring>
00019 
00020 OPENDDS_BEGIN_VERSIONED_NAMESPACE_DECL
00021 
00022 namespace OpenDDS {
00023 namespace DCPS {
00024 
00025 RtpsUdpInst::RtpsUdpInst(const OPENDDS_STRING& name)
00026   : TransportInst("rtps_udp", name)
00027 #if defined (ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00028   , send_buffer_size_(ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00029   , rcv_buffer_size_(ACE_DEFAULT_MAX_SOCKET_BUFSIZ)
00030 #else
00031   , send_buffer_size_(0)
00032   , rcv_buffer_size_(0)
00033 #endif
00034   , use_multicast_(true)
00035   , ttl_(1)
00036   , multicast_group_address_(7401, "239.255.0.2")
00037   , nak_depth_(32) // default nak_depth in OpenDDS_Multicast
00038   , nak_response_delay_(0, 200*1000 /*microseconds*/) // default from RTPS
00039   , heartbeat_period_(1) // no default in RTPS spec
00040   , heartbeat_response_delay_(0, 500*1000 /*microseconds*/) // default from RTPS
00041   , handshake_timeout_(30) // default syn_timeout in OpenDDS_Multicast
00042   , durable_data_timeout_(60)
00043   , opendds_discovery_guid_(GUID_UNKNOWN)
00044 {
00045 }
00046 
00047 TransportImpl_rch
00048 RtpsUdpInst::new_impl()
00049 {
00050   return make_rch<RtpsUdpTransport>(ref(*this));
00051 }
00052 
00053 int
00054 RtpsUdpInst::load(ACE_Configuration_Heap& cf,
00055                   ACE_Configuration_Section_Key& sect)
00056 {
00057   TransportInst::load(cf, sect); // delegate to parent
00058 
00059   ACE_TString local_address_s;
00060   GET_CONFIG_TSTRING_VALUE(cf, sect, ACE_TEXT("local_address"),
00061                            local_address_s);
00062   if (!local_address_s.is_empty()) {
00063     local_address(ACE_TEXT_ALWAYS_CHAR(local_address_s.c_str()));
00064   }
00065 
00066   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("send_buffer_size"), this->send_buffer_size_, ACE_UINT32);
00067 
00068   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("rcv_buffer_size"), this->rcv_buffer_size_, ACE_UINT32);
00069 
00070 
00071   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("use_multicast"), use_multicast_, bool);
00072 
00073   ACE_TString group_address_s;
00074   GET_CONFIG_TSTRING_VALUE(cf, sect, ACE_TEXT("multicast_group_address"),
00075                            group_address_s);
00076   if (!group_address_s.is_empty()) {
00077     if (group_address_s.rfind(':') == group_address_s.npos) {
00078       // Concatenate a port number if the user does not supply one.
00079       group_address_s += ACE_TEXT(":7401");
00080     }
00081     multicast_group_address_.set(group_address_s.c_str());
00082   }
00083 
00084   GET_CONFIG_STRING_VALUE(cf, sect, ACE_TEXT("multicast_interface"),
00085                           multicast_interface_);
00086 
00087   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("nak_depth"), nak_depth_, size_t);
00088 
00089   GET_CONFIG_VALUE(cf, sect, ACE_TEXT("ttl"), ttl_, unsigned char);
00090 
00091   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("nak_response_delay"),
00092                         nak_response_delay_);
00093   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("heartbeat_period"),
00094                         heartbeat_period_);
00095   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("heartbeat_response_delay"),
00096                         heartbeat_response_delay_);
00097   GET_CONFIG_TIME_VALUE(cf, sect, ACE_TEXT("handshake_timeout"),
00098                         handshake_timeout_);
00099   return 0;
00100 }
00101 
00102 OPENDDS_STRING
00103 RtpsUdpInst::dump_to_str() const
00104 {
00105   OPENDDS_STRING ret;
00106   // ACE_INET_Addr uses a static buffer for get_host_addr() so we can't
00107   // directly call it on both local_address_ and multicast_group_address_,
00108   // since the second call could overwrite the result of the first before the
00109   // OPENDDS_STRING gets a chance to see it.
00110   OPENDDS_STRING local;
00111   OPENDDS_STRING multi;
00112   const char* loc = local_address().get_host_addr();
00113   if (loc) {
00114     local = loc;
00115   } else {
00116     local = "NOT_SUPPORTED";
00117   }
00118   const char* mul = multicast_group_address_.get_host_addr();
00119   if (mul) {
00120     multi = mul;
00121   } else {
00122     multi = "NOT_SUPPORTED";
00123   }
00124   ret += TransportInst::dump_to_str();
00125   ret += formatNameForDump("local_address") + local;
00126   ret += ':' + to_dds_string(local_address().get_port_number()) + '\n';
00127   ret += formatNameForDump("use_multicast") + (use_multicast_ ? "true" : "false") + '\n';
00128   ret += formatNameForDump("multicast_group_address") + multi
00129       + ':' + to_dds_string(multicast_group_address_.get_port_number()) + '\n';
00130   ret += formatNameForDump("multicast_interface") + multicast_interface_ + '\n';
00131   ret += formatNameForDump("nak_depth") + to_dds_string(unsigned(nak_depth_)) + '\n';
00132   ret += formatNameForDump("nak_response_delay") + to_dds_string(nak_response_delay_.msec()) + '\n';
00133   ret += formatNameForDump("heartbeat_period") + to_dds_string(heartbeat_period_.msec()) + '\n';
00134   ret += formatNameForDump("heartbeat_response_delay") + to_dds_string(heartbeat_response_delay_.msec()) + '\n';
00135   ret += formatNameForDump("handshake_timeout") + to_dds_string(handshake_timeout_.msec()) + '\n';
00136   return ret;
00137 }
00138 
00139 size_t
00140 RtpsUdpInst::populate_locator(OpenDDS::DCPS::TransportLocator& info) const
00141 {
00142   using namespace OpenDDS::RTPS;
00143 
00144   LocatorSeq locators;
00145   CORBA::ULong idx = 0;
00146 
00147   // multicast first so it's preferred by remote peers
00148   if (this->use_multicast_ && this->multicast_group_address_ != ACE_INET_Addr()) {
00149     idx = locators.length();
00150     locators.length(idx + 1);
00151     locators[idx].kind = address_to_kind(this->multicast_group_address_);
00152     locators[idx].port = this->multicast_group_address_.get_port_number();
00153     RTPS::address_to_bytes(locators[idx].address,
00154                            this->multicast_group_address_);
00155   }
00156 
00157   //if local_address_string is empty, or only the port has been set
00158   //need to get interface addresses to populate into the locator
00159   if (this->local_address_string().empty() ||
00160       this->local_address_string().rfind(':') == 0) {
00161     typedef OPENDDS_VECTOR(ACE_INET_Addr) AddrVector;
00162     AddrVector addrs;
00163     if (TheServiceParticipant->default_address ().empty ()) {
00164       get_interface_addrs(addrs);
00165     } else {
00166       addrs.push_back (ACE_INET_Addr (static_cast<u_short> (0), TheServiceParticipant->default_address ().c_str ()));
00167     }
00168     for (AddrVector::iterator adr_it = addrs.begin(); adr_it != addrs.end(); ++adr_it) {
00169       idx = locators.length();
00170       locators.length(idx + 1);
00171       locators[idx].kind = address_to_kind(*adr_it);
00172       locators[idx].port = this->local_address().get_port_number();
00173       RTPS::address_to_bytes(locators[idx].address, *adr_it);
00174     }
00175   } else {
00176     idx = locators.length();
00177     locators.length(idx + 1);
00178     locators[idx].kind = address_to_kind(this->local_address());
00179     locators[idx].port = this->local_address().get_port_number();
00180     RTPS::address_to_bytes(locators[idx].address,
00181                            this->local_address());
00182   }
00183 
00184   info.transport_type = "rtps_udp";
00185   RTPS::locators_to_blob(locators, info.data);
00186 
00187   return locators.length();
00188 }
00189 
00190 const TransportBLOB*
00191 RtpsUdpInst::get_blob(const OpenDDS::DCPS::TransportLocatorSeq& trans_info) const
00192 {
00193   for (CORBA::ULong idx = 0, limit = trans_info.length(); idx != limit; ++idx) {
00194     if (std::strcmp(trans_info[idx].transport_type, "rtps_udp") == 0) {
00195       return &trans_info[idx].data;
00196     }
00197   }
00198 
00199   return 0;
00200 }
00201 
00202 } // namespace DCPS
00203 } // namespace OpenDDS
00204 
00205 OPENDDS_END_VERSIONED_NAMESPACE_DECL
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines

Generated on 10 Aug 2018 for OpenDDS by  doxygen 1.6.1