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

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